GNOME Bugzilla – Bug 583879
The implementation of gdk_screen_get_monitor_at_window function does not correspond to standard's requirements
Last modified: 2018-02-10 03:33:12 UTC
Please describe the problem: gint gdk_screen_get_monitor_at_window (GdkScreen *screen, GdkWindow *window) { ... gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width, &win_rect.height, NULL); gdk_window_get_origin (window, &win_rect.x, &win_rect.y); ... gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect); ... } The implementation has a call gdk_window_get_origin(window, &win_rect.x, &win_rect.y) with just the same parameters win_rect, which are used above for another purpose, to keep window's coordinates. These coordinates are being overrided. Steps to reproduce: The test was developed under OpenSuse 10.2 with 2 monitors (number 0, number 1), which are connected horizontally. Monitor number 0 is on the left, number 1 is on the right side. The most part of the window lies on the second monitor, i.e. expected return value is 1. Actual results: Here gdk_screen_get_monitor_at_window returns 0. Expected results: The expected value is 1. Does this happen every time? Yes Other information: I think this problem may be solved with the patch below described. @@ -1,13 +1,13 @@ gint gdk_screen_get_monitor_at_window (GdkScreen *screen, GdkWindow *window) { gint num_monitors, i, area = 0, screen_num = -1; - GdkRectangle win_rect; + GdkRectangle win_rect, orig_rect; g_return_val_if_fail (GDK_IS_SCREEN (screen), -1); gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width, &win_rect.height, NULL); - gdk_window_get_origin (window, &win_rect.x, &win_rect.y); + gdk_window_get_origin (window, &orig_rect.x, &orig_rect.y); num_monitors = gdk_screen_get_n_monitors (screen); @@ -27,6 +27,6 @@ if (screen_num >= 0) return screen_num; else - return get_nearest_monitor (screen, win_rect.x + win_rect.width / 2, - win_rect.y + win_rect.height / 2); + return get_nearest_monitor (screen, orig_rect.x + win_rect.width / 2, + orig_rect.y + win_rect.height / 2); }
Also reported at http://linuxtesting.ru/results/impl_reports_admin?action=details&num=D0129
Above link is not correct. You can view it at http://linuxtesting.org/results/report?num=D0129
I can't reproduce your problem, with GDK_DEBUG=xinerama ./testxinerama And the code that you are looking at is fine; gdk_window_get_geometry returns the position of the window relative to its parent window (ie the wm frame). We need to instead call gdk_window_get_origin to get the position relative to the root window, which is also the coordinate system in which monitor geometries are reported.
Try the next one. Create a window with gdk_window_new(NULL, ...), it means that your window will be a child of the default root window.
Just attach your test program, then I will have a look.
Created attachment 135700 [details] Test for gdk_screen_get_monitor_at_window
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.