From cfcd1189e497be74033ee2ce20dc80c553d777f9 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 2 Jan 2010 09:09:57 +0000 Subject: [PATCH] Fix bug where cow would be spliced across multiple monitors Also add option for specifying a monitor. --- ChangeLog | 14 +++++++++++--- src/display_cow.c | 18 +++++++++++++++--- src/xcowsay.c | 7 +++++++ xcowsay.6 | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d1444b..e8995db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,16 @@ +2010-01-04 Nick Gasson + + * src/display_cow.c (display_cow): Fix splicing of cow across + multiple monitors. Now picks a random monitor and then a random + location within that monitor. + * src/xcowsay.c (main): Add --monitor option to specify a + particular montior for the cow to appear on. + 2008-06-04 Nick Gasson - * src/display_cow.c (display_cow): Fix bug where cow would appear - off the side of the screen and fix a floating point exception in - rare circumstances. + * src/display_cow.c (display_cow): Fix bug where cow would + appear off the side of the screen and fix a floating point + exception in rare circumstances. 2008-05-23 gettextize diff --git a/src/display_cow.c b/src/display_cow.c index f66d440..362b401 100644 --- a/src/display_cow.c +++ b/src/display_cow.c @@ -247,8 +247,18 @@ void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode) int bubble_off = max((xcowsay.bubble_height - shape_height(xcowsay.cow))/2, 0); GdkScreen *screen = gdk_screen_get_default(); - int area_w = gdk_screen_get_width(screen) - total_width; - int area_h = gdk_screen_get_height(screen) - total_height; + + gint n_monitors = gdk_screen_get_n_monitors(screen); + + gint pick = get_int_option("monitor"); + if (pick < 0 || pick >= n_monitors) + pick = rand() % n_monitors; + + GdkRectangle geom; + gdk_screen_get_monitor_geometry(screen, pick, &geom); + + int area_w = geom.width - total_width; + int area_h = geom.height - total_height; // Fit the cow on the screen as best as we can // The area can't be be zero or we'd get an FPE @@ -257,7 +267,9 @@ void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode) if (area_h < 1) area_h = 1; - move_shape(xcowsay.cow, rand()%area_w, bubble_off + rand()%area_h); + move_shape(xcowsay.cow, + geom.x + rand()%area_w, + geom.y + bubble_off + rand()%area_h); show_shape(xcowsay.cow); xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf); diff --git a/src/xcowsay.c b/src/xcowsay.c index 6bc1ce1..a658e22 100644 --- a/src/xcowsay.c +++ b/src/xcowsay.c @@ -62,6 +62,7 @@ static struct option long_options[] = { {"reading-speed", required_argument, 0, 'r'}, {"daemon", no_argument, &daemon_flag, 1}, {"image", required_argument, 0, 'i'}, + {"monitor", required_argument, 0, 'm'}, {"debug", no_argument, &debug, 1}, {0, 0, 0, 0} }; @@ -96,6 +97,7 @@ static void usage() " --daemon\t\t%s\n" " --cow-size=SIZE\t%s\n" " --image=FILE\t%s\n" + " --monitor=N\t%s\n" " --debug\t\t%s\n\n" "%s\n\n" "%s\n\n" @@ -113,6 +115,7 @@ static void usage() i18n("Run xcowsay in daemon mode."), i18n("Size of the cow (small, med, large)."), i18n("Use a different image instead of the cow."), + i18n("Display cow on monitor N."), i18n("Keep daemon attached to terminal."), i18n("Default values for these options can be specified in the " "xcowsay config\nfile. See the man page for more information."), @@ -191,6 +194,7 @@ int main(int argc, char **argv) add_string_option("cow_size", DEF_COW_SIZE); add_string_option("image_base", DEF_IMAGE_BASE); add_string_option("alt_image", DEF_ALT_IMAGE); + add_int_option("monitor", -1); parse_config_file(); @@ -226,6 +230,9 @@ int main(int argc, char **argv) case 'i': set_string_option("alt_image", optarg); break; + case 'm': + set_int_option("monitor", parse_int_option(optarg)); + break; case '?': // getopt_long already printed an error message failure = 1; diff --git a/xcowsay.6 b/xcowsay.6 index a4f496f..da89776 100644 --- a/xcowsay.6 +++ b/xcowsay.6 @@ -113,6 +113,9 @@ Use a different image instead of the cow. The corresponding config file option is .IR alt_image . .TP +.BI "--monitor=" N +Make the cow appear on monitor N. +.TP .B "--debug" Print messages about what .B xcowsay -- 2.39.2