mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
tests/test-client: Handle alarm event processing automatically
Instead of having users of the test client manually deal with alarm filters, let the test client automatically add itself as filters. This changes the MetaX11Display a bit, to handle an array of filters instead of a single filter. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2704>
This commit is contained in:
parent
770a72f446
commit
dec3c49e5a
@ -48,6 +48,7 @@ struct _MetaTestClient
|
||||
GError **error;
|
||||
|
||||
MetaAsyncWaiter *waiter;
|
||||
MetaX11AlarmFilter *alarm_filter;
|
||||
};
|
||||
|
||||
struct _MetaAsyncWaiter
|
||||
@ -454,7 +455,7 @@ meta_test_client_wait_for_window_shown (MetaTestClient *client,
|
||||
g_main_loop_unref (data.loop);
|
||||
}
|
||||
|
||||
gboolean
|
||||
static gboolean
|
||||
meta_test_client_process_x11_event (MetaTestClient *client,
|
||||
MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event)
|
||||
@ -543,6 +544,16 @@ ensure_process_handler (MetaContext *context)
|
||||
return process_handler;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
alarm_filter (MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
MetaTestClient *client = user_data;
|
||||
|
||||
return meta_test_client_process_x11_event (client, x11_display, event);
|
||||
}
|
||||
|
||||
MetaTestClient *
|
||||
meta_test_client_new (MetaContext *context,
|
||||
const char *id,
|
||||
@ -629,6 +640,10 @@ meta_test_client_new (MetaContext *context,
|
||||
x11_display = meta_display_get_x11_display (display);
|
||||
g_assert_nonnull (x11_display);
|
||||
|
||||
client->alarm_filter = meta_x11_display_add_alarm_filter (x11_display,
|
||||
alarm_filter,
|
||||
client);
|
||||
|
||||
client->waiter = meta_async_waiter_new (x11_display);
|
||||
}
|
||||
|
||||
@ -651,8 +666,17 @@ meta_test_client_quit (MetaTestClient *client,
|
||||
void
|
||||
meta_test_client_destroy (MetaTestClient *client)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
MetaX11Display *x11_display;
|
||||
GError *error = NULL;
|
||||
|
||||
x11_display = meta_display_get_x11_display (display);
|
||||
if (client->alarm_filter && x11_display)
|
||||
{
|
||||
meta_x11_display_remove_alarm_filter (x11_display,
|
||||
client->alarm_filter);
|
||||
}
|
||||
|
||||
if (client->waiter)
|
||||
meta_async_waiter_destroy (client->waiter);
|
||||
|
||||
|
@ -65,11 +65,6 @@ void meta_async_waiter_destroy (MetaAsyncWaiter *waiter);
|
||||
META_EXPORT
|
||||
char * meta_test_client_get_id (MetaTestClient *client);
|
||||
|
||||
META_EXPORT
|
||||
gboolean meta_test_client_process_x11_event (MetaTestClient *client,
|
||||
MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event);
|
||||
|
||||
META_EXPORT
|
||||
gboolean meta_test_client_wait (MetaTestClient *client,
|
||||
GError **error);
|
||||
|
@ -169,15 +169,6 @@ static MetaTestClient *x11_monitor_test_client = NULL;
|
||||
#define X11_TEST_CLIENT_NAME "x11_monitor_test_client"
|
||||
#define X11_TEST_CLIENT_WINDOW "window1"
|
||||
|
||||
static gboolean
|
||||
monitor_tests_alarm_filter (MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
return meta_test_client_process_x11_event (x11_monitor_test_client,
|
||||
x11_display, event);
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitors_changed (gboolean *monitors_changed)
|
||||
{
|
||||
@ -203,9 +194,6 @@ create_monitor_test_clients (MetaContext *context)
|
||||
if (!x11_monitor_test_client)
|
||||
g_error ("Failed to launch X11 test client: %s", error->message);
|
||||
|
||||
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
|
||||
monitor_tests_alarm_filter, NULL);
|
||||
|
||||
if (!meta_test_client_do (wayland_monitor_test_client, &error,
|
||||
"create", WAYLAND_TEST_CLIENT_WINDOW,
|
||||
NULL))
|
||||
@ -259,9 +247,6 @@ destroy_monitor_test_clients (void)
|
||||
|
||||
meta_test_client_destroy (wayland_monitor_test_client);
|
||||
meta_test_client_destroy (x11_monitor_test_client);
|
||||
|
||||
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1094,16 +1094,6 @@ ensure_view_count (int n_views)
|
||||
g_assert_cmpuint (g_list_length (stage_views), ==, n_views);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
tests_alarm_filter (MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
MetaTestClient *test_client = user_data;
|
||||
return meta_test_client_process_x11_event (test_client,
|
||||
x11_display, event);
|
||||
}
|
||||
|
||||
static void
|
||||
check_test_client_state (MetaTestClient *test_client)
|
||||
{
|
||||
@ -1124,8 +1114,6 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaMonitorManagerTest *monitor_manager_test =
|
||||
META_MONITOR_MANAGER_TEST (monitor_manager);
|
||||
MetaDisplay *display;
|
||||
MetaX11Display *x11_display;
|
||||
ClutterActor *stage = meta_backend_get_stage (backend);
|
||||
MetaTestClient *x11_test_client;
|
||||
MonitorTestCaseSetup hotplug_test_case_setup = initial_test_case_setup;
|
||||
@ -1140,11 +1128,6 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
|
||||
&error);
|
||||
if (!x11_test_client)
|
||||
g_error ("Failed to launch X11 test client: %s", error->message);
|
||||
display = meta_context_get_display (test_context);
|
||||
x11_display = meta_display_get_x11_display (display);
|
||||
meta_x11_display_set_alarm_filter (x11_display,
|
||||
tests_alarm_filter,
|
||||
x11_test_client);
|
||||
|
||||
if (!meta_test_client_do (x11_test_client, &error,
|
||||
"create", X11_TEST_CLIENT_WINDOW,
|
||||
@ -1210,7 +1193,6 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
|
||||
if (!meta_test_client_quit (x11_test_client, &error))
|
||||
g_error ("Failed to quit X11 test client: %s", error->message);
|
||||
meta_test_client_destroy (x11_test_client);
|
||||
meta_x11_display_set_alarm_filter (x11_display, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -38,6 +38,7 @@
|
||||
typedef struct {
|
||||
MetaContext *context;
|
||||
GHashTable *clients;
|
||||
MetaX11AlarmFilter *alarm_filter;
|
||||
MetaAsyncWaiter *waiter;
|
||||
GString *warning_messages;
|
||||
GMainLoop *loop;
|
||||
@ -51,21 +52,10 @@ test_case_alarm_filter (MetaX11Display *x11_display,
|
||||
gpointer data)
|
||||
{
|
||||
TestCase *test = data;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
if (meta_async_waiter_process_x11_event (test->waiter, x11_display, event))
|
||||
return TRUE;
|
||||
|
||||
g_hash_table_iter_init (&iter, test->clients);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
MetaTestClient *client = value;
|
||||
|
||||
if (meta_test_client_process_x11_event (client, x11_display, event))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -73,8 +63,12 @@ static void
|
||||
on_x11_display_opened (MetaDisplay *display,
|
||||
TestCase *test)
|
||||
{
|
||||
meta_x11_display_set_alarm_filter (display->x11_display,
|
||||
test_case_alarm_filter, test);
|
||||
MetaX11Display *x11_display = meta_display_get_x11_display (display);
|
||||
|
||||
test->alarm_filter =
|
||||
meta_x11_display_add_alarm_filter (x11_display,
|
||||
test_case_alarm_filter,
|
||||
test);
|
||||
test->waiter = meta_async_waiter_new (display->x11_display);
|
||||
}
|
||||
|
||||
@ -1223,8 +1217,11 @@ test_case_destroy (TestCase *test,
|
||||
|
||||
display = meta_get_display ();
|
||||
g_clear_signal_handler (&test->x11_display_opened_handler_id, display);
|
||||
if (display->x11_display)
|
||||
meta_x11_display_set_alarm_filter (display->x11_display, NULL, NULL);
|
||||
if (display->x11_display && test->alarm_filter)
|
||||
{
|
||||
meta_x11_display_remove_alarm_filter (display->x11_display,
|
||||
test->alarm_filter);
|
||||
}
|
||||
|
||||
g_hash_table_destroy (test->clients);
|
||||
g_object_unref (test->virtual_monitor);
|
||||
|
@ -69,16 +69,6 @@ transfer_ready_cb (GObject *source_object,
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
tests_alarm_filter (MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
MetaTestClient *test_client = user_data;
|
||||
return meta_test_client_process_x11_event (test_client,
|
||||
x11_display, event);
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_xwayland (MetaContext *context)
|
||||
{
|
||||
@ -118,9 +108,6 @@ meta_test_xwayland_restart_selection (void)
|
||||
|
||||
ensure_xwayland (test_context);
|
||||
x11_display = meta_display_get_x11_display (display);
|
||||
meta_x11_display_set_alarm_filter (x11_display,
|
||||
tests_alarm_filter,
|
||||
test_client);
|
||||
|
||||
g_assert_null (x11_display->selection.owners[META_SELECTION_CLIPBOARD]);
|
||||
|
||||
|
@ -1360,13 +1360,23 @@ handle_other_xevent (MetaX11Display *x11_display,
|
||||
meta_window_x11_update_sync_request_counter (alarm_window, new_counter_value);
|
||||
bypass_gtk = TRUE; /* GTK doesn't want to see this really */
|
||||
}
|
||||
else
|
||||
else if (x11_display->alarm_filters)
|
||||
{
|
||||
if (x11_display->alarm_filter &&
|
||||
x11_display->alarm_filter (x11_display,
|
||||
(XSyncAlarmNotifyEvent*)event,
|
||||
x11_display->alarm_filter_data))
|
||||
bypass_gtk = TRUE;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < x11_display->alarm_filters->len; i++)
|
||||
{
|
||||
MetaX11AlarmFilter *alarm_filter =
|
||||
x11_display->alarm_filters->pdata[i];
|
||||
|
||||
if (alarm_filter->filter (x11_display,
|
||||
(XSyncAlarmNotifyEvent *) event,
|
||||
alarm_filter->user_data))
|
||||
{
|
||||
bypass_gtk = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
goto out;
|
||||
|
@ -45,6 +45,12 @@ typedef gboolean (*MetaAlarmFilter) (MetaX11Display *x11_display,
|
||||
XSyncAlarmNotifyEvent *event,
|
||||
gpointer data);
|
||||
|
||||
typedef struct _MetaX11AlarmFilter
|
||||
{
|
||||
MetaAlarmFilter filter;
|
||||
gpointer user_data;
|
||||
} MetaX11AlarmFilter;
|
||||
|
||||
struct _MetaX11Display
|
||||
{
|
||||
GObject parent;
|
||||
@ -120,8 +126,7 @@ struct _MetaX11Display
|
||||
int xkb_base_event_type;
|
||||
guint32 last_bell_time;
|
||||
|
||||
MetaAlarmFilter alarm_filter;
|
||||
gpointer alarm_filter_data;
|
||||
GPtrArray *alarm_filters;
|
||||
|
||||
MetaUI *ui;
|
||||
|
||||
@ -212,9 +217,13 @@ void meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
|
||||
XSyncAlarm alarm);
|
||||
|
||||
META_EXPORT
|
||||
void meta_x11_display_set_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaAlarmFilter filter,
|
||||
gpointer data);
|
||||
MetaX11AlarmFilter * meta_x11_display_add_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaAlarmFilter filter,
|
||||
gpointer user_data);
|
||||
|
||||
META_EXPORT
|
||||
void meta_x11_display_remove_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaX11AlarmFilter *alarm_filter);
|
||||
|
||||
void meta_x11_display_create_guard_window (MetaX11Display *x11_display);
|
||||
|
||||
|
@ -120,6 +120,8 @@ meta_x11_display_dispose (GObject *object)
|
||||
|
||||
x11_display->closing = TRUE;
|
||||
|
||||
g_clear_pointer (&x11_display->alarm_filters, g_ptr_array_unref);
|
||||
|
||||
if (x11_display->empty_region != None)
|
||||
{
|
||||
XFixesDestroyRegion (x11_display->xdisplay,
|
||||
@ -1677,15 +1679,29 @@ meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
|
||||
g_hash_table_remove (x11_display->xids, &alarm);
|
||||
}
|
||||
|
||||
void
|
||||
meta_x11_display_set_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaAlarmFilter filter,
|
||||
gpointer data)
|
||||
MetaX11AlarmFilter *
|
||||
meta_x11_display_add_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaAlarmFilter filter,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (filter == NULL || x11_display->alarm_filter == NULL);
|
||||
MetaX11AlarmFilter *alarm_filter;
|
||||
|
||||
x11_display->alarm_filter = filter;
|
||||
x11_display->alarm_filter_data = data;
|
||||
if (!x11_display->alarm_filters)
|
||||
x11_display->alarm_filters = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
alarm_filter = g_new0 (MetaX11AlarmFilter, 1);
|
||||
alarm_filter->filter = filter;
|
||||
alarm_filter->user_data = user_data;
|
||||
g_ptr_array_add (x11_display->alarm_filters, alarm_filter);
|
||||
|
||||
return alarm_filter;
|
||||
}
|
||||
|
||||
void
|
||||
meta_x11_display_remove_alarm_filter (MetaX11Display *x11_display,
|
||||
MetaX11AlarmFilter *alarm_filter)
|
||||
{
|
||||
g_ptr_array_remove (x11_display->alarm_filters, alarm_filter);
|
||||
}
|
||||
|
||||
/* The guard window allows us to leave minimized windows mapped so
|
||||
|
Loading…
Reference in New Issue
Block a user