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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2175>
This commit is contained in:
Carlos Garnacho 2022-09-09 12:45:52 +02:00 committed by Marge Bot
parent f5cb8a73d5
commit 6a80bc3a54
6 changed files with 29 additions and 37 deletions

View File

@ -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,
MetaSyncCounter *sync_counter;
sync_counter = meta_x11_display_lookup_sync_alarm (x11_display,
((XSyncAlarmNotifyEvent*)event)->alarm);
if (alarm_window != NULL)
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)

View File

@ -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
{

View File

@ -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,
MetaSyncCounter * 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 *sync_counter);
void meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
XSyncAlarm alarm);

View File

@ -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)
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 *

View File

@ -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)
{

View File

@ -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);