mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 10:50:10 +00:00
x11: keep track of the screen pixel size by calculating the bounding box of monitors
This is so we always have the latest information given by XRandR (or other), and not rely on Core protocol information that might not have been updated yet. This is specially visible when a monitor is connected (less frequent) or disconnected (much more frequent), callbacks on GdkScreen::monitors-changed that call gdk_screen_get_width/height() could get the screen size previous to the monitor rearrangement. So in order to fix this, keep track of the latest monitors information, and calculate the bounding box in order to know the screen size. https://bugzilla.gnome.org/show_bug.cgi?id=715029
This commit is contained in:
parent
118b09c68c
commit
d1414211bf
@ -96,13 +96,13 @@ gdk_x11_screen_get_display (GdkScreen *screen)
|
|||||||
static gint
|
static gint
|
||||||
gdk_x11_screen_get_width (GdkScreen *screen)
|
gdk_x11_screen_get_width (GdkScreen *screen)
|
||||||
{
|
{
|
||||||
return WidthOfScreen (GDK_X11_SCREEN (screen)->xscreen) / GDK_X11_SCREEN (screen)->window_scale;
|
return GDK_X11_SCREEN (screen)->width / GDK_X11_SCREEN (screen)->window_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
gdk_x11_screen_get_height (GdkScreen *screen)
|
gdk_x11_screen_get_height (GdkScreen *screen)
|
||||||
{
|
{
|
||||||
return HeightOfScreen (GDK_X11_SCREEN (screen)->xscreen) / GDK_X11_SCREEN (screen)->window_scale;
|
return GDK_X11_SCREEN (screen)->height / GDK_X11_SCREEN (screen)->window_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@ -916,8 +916,8 @@ _gdk_x11_screen_get_edge_monitors (GdkScreen *screen,
|
|||||||
gint *right)
|
gint *right)
|
||||||
{
|
{
|
||||||
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
|
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
|
||||||
gint top_most_pos = HeightOfScreen (GDK_X11_SCREEN (screen)->xscreen);
|
gint top_most_pos = x11_screen->height;
|
||||||
gint left_most_pos = WidthOfScreen (GDK_X11_SCREEN (screen)->xscreen);
|
gint left_most_pos = x11_screen->width;
|
||||||
gint bottom_most_pos = 0;
|
gint bottom_most_pos = 0;
|
||||||
gint right_most_pos = 0;
|
gint right_most_pos = 0;
|
||||||
gint monitor_num;
|
gint monitor_num;
|
||||||
@ -1046,6 +1046,30 @@ init_multihead (GdkScreen *screen)
|
|||||||
HeightOfScreen (x11_screen->xscreen));
|
HeightOfScreen (x11_screen->xscreen));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_bounding_box (GdkScreen *screen)
|
||||||
|
{
|
||||||
|
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
|
||||||
|
gint i, x1, y1, x2, y2;
|
||||||
|
|
||||||
|
x1 = y1 = G_MAXINT;
|
||||||
|
x2 = y2 = G_MININT;
|
||||||
|
|
||||||
|
for (i = 0; i < x11_screen->n_monitors; i++)
|
||||||
|
{
|
||||||
|
GdkX11Monitor *monitor;
|
||||||
|
|
||||||
|
monitor = &x11_screen->monitors[i];
|
||||||
|
x1 = MIN (x1, monitor->geometry.x);
|
||||||
|
y1 = MIN (y1, monitor->geometry.y);
|
||||||
|
x2 = MAX (x2, monitor->geometry.x + monitor->geometry.width);
|
||||||
|
y2 = MAX (y2, monitor->geometry.y + monitor->geometry.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
x11_screen->width = x2 - x1;
|
||||||
|
x11_screen->height = y2 - y1;
|
||||||
|
}
|
||||||
|
|
||||||
GdkScreen *
|
GdkScreen *
|
||||||
_gdk_x11_screen_new (GdkDisplay *display,
|
_gdk_x11_screen_new (GdkDisplay *display,
|
||||||
gint screen_number)
|
gint screen_number)
|
||||||
@ -1087,7 +1111,8 @@ _gdk_x11_screen_new (GdkDisplay *display,
|
|||||||
|
|
||||||
_gdk_x11_screen_init_visuals (screen);
|
_gdk_x11_screen_init_visuals (screen);
|
||||||
_gdk_x11_screen_init_root_window (screen);
|
_gdk_x11_screen_init_root_window (screen);
|
||||||
|
update_bounding_box (screen);
|
||||||
|
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1186,11 +1211,13 @@ process_monitors_change (GdkScreen *screen)
|
|||||||
x11_screen->monitors, x11_screen->n_monitors) ||
|
x11_screen->monitors, x11_screen->n_monitors) ||
|
||||||
x11_screen->primary_monitor != primary_monitor;
|
x11_screen->primary_monitor != primary_monitor;
|
||||||
|
|
||||||
|
|
||||||
free_monitors (monitors, n_monitors);
|
free_monitors (monitors, n_monitors);
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
g_signal_emit_by_name (screen, "monitors-changed");
|
{
|
||||||
|
update_bounding_box (screen);
|
||||||
|
g_signal_emit_by_name (screen, "monitors-changed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -47,6 +47,9 @@ struct _GdkX11Screen
|
|||||||
GdkX11Monitor *monitors;
|
GdkX11Monitor *monitors;
|
||||||
gint primary_monitor;
|
gint primary_monitor;
|
||||||
|
|
||||||
|
gint width;
|
||||||
|
gint height;
|
||||||
|
|
||||||
gint window_scale;
|
gint window_scale;
|
||||||
gboolean fixed_window_scale;
|
gboolean fixed_window_scale;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user