From 6a80bc3a54c157517bfe0d2f0ff5154797ec3cb3 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 9 Sep 2022 12:45:52 +0200 Subject: [PATCH] x11: Decouple sync alarms from window XIDs Store the alarms in a different hashtable, and look up the MetaSyncCounter right away. It so far avoids the MetaWindow middle man, but will also be simpler when each window can possibly have more than one active alarms. Part-of: --- src/x11/events.c | 10 ++++++---- src/x11/meta-sync-counter.c | 2 +- src/x11/meta-x11-display-private.h | 14 +++++++++----- src/x11/meta-x11-display.c | 28 +++++++++++++--------------- src/x11/window-x11.c | 10 ---------- src/x11/window-x11.h | 2 -- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/x11/events.c b/src/x11/events.c index ef1301c1a..dc12b6e09 100644 --- a/src/x11/events.c +++ b/src/x11/events.c @@ -1314,15 +1314,17 @@ handle_other_xevent (MetaX11Display *x11_display, if (META_X11_DISPLAY_HAS_XSYNC (x11_display) && event->type == (x11_display->xsync_event_base + XSyncAlarmNotify)) { - MetaWindow *alarm_window = meta_x11_display_lookup_sync_alarm (x11_display, - ((XSyncAlarmNotifyEvent*)event)->alarm); + MetaSyncCounter *sync_counter; - if (alarm_window != NULL) + sync_counter = meta_x11_display_lookup_sync_alarm (x11_display, + ((XSyncAlarmNotifyEvent*)event)->alarm); + + if (sync_counter != NULL) { XSyncValue value = ((XSyncAlarmNotifyEvent*)event)->counter_value; gint64 new_counter_value; new_counter_value = XSyncValueLow32 (value) + ((gint64)XSyncValueHigh32 (value) << 32); - meta_window_x11_update_sync_request_counter (alarm_window, new_counter_value); + meta_sync_counter_update (sync_counter, new_counter_value); bypass_gtk = TRUE; /* GTK doesn't want to see this really */ } else if (x11_display->alarm_filters) diff --git a/src/x11/meta-sync-counter.c b/src/x11/meta-sync-counter.c index 610035248..71bd89dbc 100644 --- a/src/x11/meta-sync-counter.c +++ b/src/x11/meta-sync-counter.c @@ -152,7 +152,7 @@ meta_sync_counter_create_sync_alarm (MetaSyncCounter *sync_counter) { meta_x11_display_register_sync_alarm (x11_display, &sync_counter->sync_request_alarm, - window); + sync_counter); } else { diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index f9a9f6203..1030a2947 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -37,6 +37,7 @@ #include "meta-startup-notification-x11.h" #include "meta-x11-stack-private.h" #include "ui/ui.h" +#include "x11/meta-sync-counter.h" typedef struct _MetaGroupPropHooks MetaGroupPropHooks; typedef struct _MetaWindowPropHooks MetaWindowPropHooks; @@ -109,6 +110,7 @@ struct _MetaX11Display Window composite_overlay_window; GHashTable *xids; + GHashTable *alarms; gboolean has_xinerama_indices; @@ -211,11 +213,13 @@ void meta_x11_display_register_x_window (MetaX11Display *x11_display, void meta_x11_display_unregister_x_window (MetaX11Display *x11_display, Window xwindow); -MetaWindow *meta_x11_display_lookup_sync_alarm (MetaX11Display *x11_display, - XSyncAlarm alarm); -void meta_x11_display_register_sync_alarm (MetaX11Display *x11_display, - XSyncAlarm *alarmp, - MetaWindow *window); +MetaSyncCounter * meta_x11_display_lookup_sync_alarm (MetaX11Display *x11_display, + XSyncAlarm alarm); + +void meta_x11_display_register_sync_alarm (MetaX11Display *x11_display, + XSyncAlarm *alarmp, + MetaSyncCounter *sync_counter); + void meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display, XSyncAlarm alarm); diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 69f9f901d..27e017de6 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -217,6 +217,8 @@ meta_x11_display_dispose (GObject *object) x11_display->xids = NULL; } + g_clear_pointer (&x11_display->alarms, g_hash_table_unref); + if (x11_display->xroot != None) { unset_wm_check_hint (x11_display); @@ -1311,6 +1313,8 @@ meta_x11_display_new (MetaDisplay *display, x11_display->xids = g_hash_table_new (meta_unsigned_long_hash, meta_unsigned_long_equal); + x11_display->alarms = g_hash_table_new (meta_unsigned_long_hash, + meta_unsigned_long_equal); x11_display->groups_by_leader = NULL; x11_display->composite_overlay_window = None; @@ -1700,36 +1704,30 @@ meta_x11_display_unregister_x_window (MetaX11Display *x11_display, g_hash_table_remove (x11_display->xids, &xwindow); } - -/* We store sync alarms in the window ID hash table, because they are - * just more types of XIDs in the same global space, but we have - * typesafe functions to register/unregister for readability. - */ - -MetaWindow * +MetaSyncCounter * meta_x11_display_lookup_sync_alarm (MetaX11Display *x11_display, XSyncAlarm alarm) { - return g_hash_table_lookup (x11_display->xids, &alarm); + return g_hash_table_lookup (x11_display->alarms, &alarm); } void -meta_x11_display_register_sync_alarm (MetaX11Display *x11_display, - XSyncAlarm *alarmp, - MetaWindow *window) +meta_x11_display_register_sync_alarm (MetaX11Display *x11_display, + XSyncAlarm *alarmp, + MetaSyncCounter *sync_counter) { - g_return_if_fail (g_hash_table_lookup (x11_display->xids, alarmp) == NULL); + g_return_if_fail (g_hash_table_lookup (x11_display->alarms, alarmp) == NULL); - g_hash_table_insert (x11_display->xids, alarmp, window); + g_hash_table_insert (x11_display->alarms, alarmp, sync_counter); } void meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display, XSyncAlarm alarm) { - g_return_if_fail (g_hash_table_lookup (x11_display->xids, &alarm) != NULL); + g_return_if_fail (g_hash_table_lookup (x11_display->alarms, &alarm) != NULL); - g_hash_table_remove (x11_display->xids, &alarm); + g_hash_table_remove (x11_display->alarms, &alarm); } MetaX11AlarmFilter * diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 6b82d16b8..738e28780 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -4123,16 +4123,6 @@ meta_window_x11_destroy_sync_request_alarm (MetaWindow *window) meta_sync_counter_destroy_sync_alarm (&priv->sync_counter); } -void -meta_window_x11_update_sync_request_counter (MetaWindow *window, - gint64 new_counter_value) -{ - MetaWindowX11 *window_x11 = META_WINDOW_X11 (window); - MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11); - - meta_sync_counter_update (&priv->sync_counter, new_counter_value); -} - Window meta_window_x11_get_toplevel_xwindow (MetaWindow *window) { diff --git a/src/x11/window-x11.h b/src/x11/window-x11.h index 8193fea3a..5581747ff 100644 --- a/src/x11/window-x11.h +++ b/src/x11/window-x11.h @@ -62,8 +62,6 @@ void meta_window_x11_set_allowed_actions_hint (MetaWindow *window); void meta_window_x11_create_sync_request_alarm (MetaWindow *window); void meta_window_x11_destroy_sync_request_alarm (MetaWindow *window); -void meta_window_x11_update_sync_request_counter (MetaWindow *window, - gint64 new_counter_value); void meta_window_x11_update_input_region (MetaWindow *window); void meta_window_x11_update_shape_region (MetaWindow *window);