From 94d8a4131be467e0d2cc7a2099ab7b4fa492ad44 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 20 Apr 2006 18:41:38 +0000 Subject: [PATCH] New helper function. Same functionality as 2006-04-20 Tor Lillqvist * app/widgets/gimpsessioninfo.c (get_appropriate_monitor): New helper function. Same functionality as gdk_screen_get_monitor_at_window(), except that it takes a window geometry as parameter and not the window itself. (gimp_session_info_set_geometry): Make sure the window is completely inside a monitor. (#339099, #324254) --- ChangeLog | 9 +++++ app/widgets/gimpsessioninfo.c | 71 +++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 505af13c86..11c92c221a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-04-20 Tor Lillqvist + + * app/widgets/gimpsessioninfo.c (get_appropriate_monitor): New + helper function. Same functionality as + gdk_screen_get_monitor_at_window(), except that it takes a window + geometry as parameter and not the window itself. + (gimp_session_info_set_geometry): Make sure the window is + completely inside a monitor. (#339099, #324254) + 2006-04-20 Simon Budig * plug-ins/common/convmatrix.c: only access existing toggle buttons. diff --git a/app/widgets/gimpsessioninfo.c b/app/widgets/gimpsessioninfo.c index 35f5788eea..519257d499 100644 --- a/app/widgets/gimpsessioninfo.c +++ b/app/widgets/gimpsessioninfo.c @@ -828,24 +828,79 @@ gimp_session_info_restore (GimpSessionInfo *info, info->aux_info = NULL; } +/* This function mostly lifted from + * gtk+/gdk/gdkscreen.c:gdk_screen_get_monitor_at_window() + */ +static gint +get_appropriate_monitor (GdkScreen *screen, + gint x, + gint y, + gint w, + gint h) +{ + gint num_monitors, i, area = 0, monitor = -1; + GdkRectangle rect; + + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + + num_monitors = gdk_screen_get_n_monitors (screen); + + for (i = 0; i < num_monitors; i++) + { + GdkRectangle tmp_monitor, intersect; + + gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor); + gdk_rectangle_intersect (&rect, &tmp_monitor, &intersect); + + if (intersect.width * intersect.height > area) + { + area = intersect.width * intersect.height; + monitor = i; + } + } + if (monitor >= 0) + return monitor; + else + return gdk_screen_get_monitor_at_point (screen, + rect.x + rect.width / 2, + rect.y + rect.height / 2); +} + void gimp_session_info_set_geometry (GimpSessionInfo *info) { - GdkScreen *screen; - gint screen_width; - gint screen_height; - gchar geom[32]; + GdkScreen *screen; + GdkRectangle monitor; + gchar geom[32]; g_return_if_fail (info != NULL); g_return_if_fail (GTK_IS_WINDOW (info->widget)); screen = gtk_widget_get_screen (info->widget); - screen_width = gdk_screen_get_width (screen); - screen_height = gdk_screen_get_height (screen); + if ((!info->toplevel_entry || info->toplevel_entry->remember_size) && + info->width > 0 && info->height > 0) + { + gdk_screen_get_monitor_geometry (screen, + get_appropriate_monitor (screen, + info->x, info->y, + info->width, info->height), + &monitor); + info->x = CLAMP (info->x, monitor.x, monitor.x + monitor.width - info->width); + info->y = CLAMP (info->y, monitor.y, monitor.y + monitor.height - info->height); + } + else + { + gdk_screen_get_monitor_geometry (screen, + gdk_screen_get_monitor_at_point (screen, info->x, info->y), + &monitor); - info->x = CLAMP (info->x, 0, screen_width - 128); - info->y = CLAMP (info->y, 0, screen_height - 128); + info->x = CLAMP (info->x, monitor.x, monitor.x + monitor.width - 128); + info->y = CLAMP (info->y, monitor.y, monitor.y + monitor.height - 128); + } g_snprintf (geom, sizeof (geom), "+%d+%d", info->x, info->y);