x11: Directly notify surfaces of monitor changes

Do not use signals.
This commit is contained in:
Benjamin Otte 2020-05-17 05:35:14 +02:00
parent e81a1db48c
commit 972276436f
3 changed files with 26 additions and 39 deletions

View File

@ -385,6 +385,26 @@ gdk_x11_screen_get_screen_number (GdkX11Screen *screen)
return screen->screen_num;
}
static void
notify_surface_monitor_change (GdkX11Display *display,
GdkMonitor *monitor)
{
GHashTableIter iter;
GdkSurface *surface;
/* We iterate the surfaces via the hash table here because it's the only
* thing that contains all the surfaces.
*/
if (display->xid_ht == NULL)
return;
g_hash_table_iter_init (&iter, display->xid_ht);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&surface))
{
gdk_x11_surface_check_monitor (surface, monitor);
}
}
static GdkX11Monitor *
find_monitor_by_output (GdkX11Display *x11_display, XID output)
{
@ -590,6 +610,7 @@ init_randr15 (GdkX11Screen *x11_screen)
for (i = g_list_model_get_n_items (G_LIST_MODEL (x11_display->monitors)) - 1; i >= 0; i--)
{
GdkX11Monitor *monitor = g_list_model_get_item (G_LIST_MODEL (x11_display->monitors), i);
notify_surface_monitor_change (x11_display, GDK_MONITOR (monitor));
if (monitor->add)
{
gdk_display_monitor_added (display, GDK_MONITOR (monitor));
@ -744,6 +765,7 @@ init_randr13 (GdkX11Screen *x11_screen)
for (i = g_list_model_get_n_items (G_LIST_MODEL (x11_display->monitors)) - 1; i >= 0; i--)
{
GdkX11Monitor *monitor = g_list_model_get_item (G_LIST_MODEL (x11_display->monitors), i);
notify_surface_monitor_change (x11_display, GDK_MONITOR (monitor));
if (monitor->add)
{
gdk_display_monitor_added (display, GDK_MONITOR (monitor));
@ -835,6 +857,7 @@ init_no_multihead (GdkX11Screen *x11_screen)
for (i = g_list_model_get_n_items (G_LIST_MODEL (x11_display->monitors)) - 1; i >= 0; i--)
{
monitor = g_list_model_get_item (G_LIST_MODEL (x11_display->monitors), i);
notify_surface_monitor_change (x11_display, GDK_MONITOR (monitor));
if (monitor->add)
{
gdk_display_monitor_added (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor));

View File

@ -106,10 +106,6 @@ static void set_wm_name (GdkDisplay *display,
const gchar *name);
static void move_to_current_desktop (GdkSurface *surface);
static void gdk_x11_toplevel_state_callback (GdkSurface *surface);
static void gdk_x11_surface_on_monitor_added (GdkSurface *surface,
GdkMonitor *monitor);
static void gdk_x11_surface_on_monitor_removed (GdkSurface *surface,
GdkMonitor *monitor);
/* Return whether time1 is considered later than time2 as far as xserver
* time is concerned. Accounts for wraparound.
@ -463,13 +459,6 @@ gdk_x11_surface_finalize (GObject *object)
_gdk_x11_display_remove_window (display, impl->xid);
if (impl->toplevel && impl->toplevel->focus_window)
_gdk_x11_display_remove_window (display, impl->toplevel->focus_window);
g_signal_handlers_disconnect_by_func (display,
gdk_x11_surface_on_monitor_added,
GDK_SURFACE (object));
g_signal_handlers_disconnect_by_func (display,
gdk_x11_surface_on_monitor_removed,
GDK_SURFACE (object));
}
g_clear_pointer (&impl->surface_is_on_monitor, g_list_free);
@ -984,13 +973,6 @@ _gdk_x11_display_create_surface (GdkDisplay *display,
gdk_surface_freeze_updates (surface);
g_signal_connect_swapped (surface->display, "monitor-added",
G_CALLBACK (gdk_x11_surface_on_monitor_added),
surface);
g_signal_connect_swapped (surface->display, "monitor-removed",
G_CALLBACK (gdk_x11_surface_on_monitor_removed),
surface);
return surface;
}
@ -1597,7 +1579,7 @@ gdk_x11_surface_set_is_on_monitor (GdkSurface *surface,
}
}
static void
void
gdk_x11_surface_check_monitor (GdkSurface *surface,
GdkMonitor *monitor)
{
@ -1633,26 +1615,6 @@ gdk_x11_surface_enter_leave_monitors (GdkSurface *surface)
}
}
static void
gdk_x11_surface_on_monitor_added (GdkSurface *surface,
GdkMonitor *monitor)
{
gdk_x11_surface_check_monitor (surface, monitor);
g_signal_connect_swapped (G_OBJECT (monitor), "notify::geometry",
G_CALLBACK (gdk_x11_surface_check_monitor),
surface);
}
static void
gdk_x11_surface_on_monitor_removed (GdkSurface *surface,
GdkMonitor *monitor)
{
gdk_x11_surface_check_monitor (surface, monitor);
g_signal_handlers_disconnect_by_func (G_OBJECT (monitor),
gdk_x11_surface_check_monitor,
monitor);
}
static void gdk_x11_surface_set_geometry_hints (GdkSurface *surface,
const GdkGeometry *geometry,
GdkSurfaceHints geom_mask);

View File

@ -182,6 +182,8 @@ void gdk_x11_surface_pre_damage (GdkSurface *surface);
void gdk_x11_surface_move (GdkSurface *surface,
gint x,
gint y);
void gdk_x11_surface_check_monitor (GdkSurface *surface,
GdkMonitor *monitor);
G_END_DECLS