After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 583879 - The implementation of gdk_screen_get_monitor_at_window function does not correspond to standard's requirements
The implementation of gdk_screen_get_monitor_at_window function does not corr...
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Backend: X11
2.19.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-05-26 10:56 UTC by Eduard Bagrov
Modified: 2018-02-10 03:33 UTC
See Also:
GNOME target: ---
GNOME version: 2.7/2.8


Attachments
Test for gdk_screen_get_monitor_at_window (1.19 KB, text/plain)
2009-06-01 05:47 UTC, Eduard Bagrov
Details

Description Eduard Bagrov 2009-05-26 10:56:31 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);
 }
Comment 1 Eduard Bagrov 2009-05-27 09:59:01 UTC
Also reported at 
http://linuxtesting.ru/results/impl_reports_admin?action=details&num=D0129
Comment 2 Eduard Bagrov 2009-05-29 13:21:20 UTC
Above link is not correct.
You can view it at http://linuxtesting.org/results/report?num=D0129
Comment 3 Matthias Clasen 2009-05-30 06:29:22 UTC
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.
Comment 4 Eduard Bagrov 2009-05-30 13:53:05 UTC
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.
Comment 5 Matthias Clasen 2009-05-31 03:11:13 UTC
Just attach your test program, then I will have a look.
Comment 6 Eduard Bagrov 2009-06-01 05:47:10 UTC
Created attachment 135700 [details]
Test for gdk_screen_get_monitor_at_window
Comment 7 Matthias Clasen 2018-02-10 03:33:12 UTC
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.