tests/utils: Add helper to flush the input thread
Add a helper function that ensures any queued virtual input events have been flushed from the input thread. This works by posting a task to the input thread, which will itself queue another callback back to the main thread. Once the main thread callback is invoked, the flush call is unblocked and the function returns. Upon this, any previously emitted virtual input event should have already passed through the input thread back into the main thread, however not necessarily fully processed. For making sure it has been processed, one also have to make sure the stage has been updated, e.g. via `meta_wait_for_paint()`. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2727>
This commit is contained in:
parent
bd72b671fc
commit
489bc65381
@ -133,6 +133,7 @@ MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native,
|
||||
|
||||
void meta_seat_impl_destroy (MetaSeatImpl *seat_impl);
|
||||
|
||||
META_EXPORT_TEST
|
||||
void meta_seat_impl_run_input_task (MetaSeatImpl *seat_impl,
|
||||
GTask *task,
|
||||
GSourceFunc dispatch_func);
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "backends/native/meta-pointer-constraint-native.h"
|
||||
#include "backends/native/meta-xkb-utils.h"
|
||||
#include "clutter/clutter.h"
|
||||
#include "core/util-private.h"
|
||||
|
||||
typedef struct _MetaSeatNative MetaSeatNative;
|
||||
|
||||
@ -66,6 +67,7 @@ struct _MetaSeatNative
|
||||
};
|
||||
|
||||
#define META_TYPE_SEAT_NATIVE meta_seat_native_get_type ()
|
||||
META_EXPORT_TEST
|
||||
G_DECLARE_FINAL_TYPE (MetaSeatNative, meta_seat_native,
|
||||
META, SEAT_NATIVE, ClutterSeat)
|
||||
|
||||
|
@ -27,6 +27,9 @@
|
||||
|
||||
#include "backends/meta-monitor-config-store.h"
|
||||
#include "backends/meta-virtual-monitor.h"
|
||||
#include "backends/native/meta-backend-native.h"
|
||||
#include "backends/native/meta-input-thread.h"
|
||||
#include "backends/native/meta-seat-native.h"
|
||||
#include "core/display-private.h"
|
||||
#include "core/window-private.h"
|
||||
#include "meta-test/meta-context-test.h"
|
||||
@ -795,3 +798,47 @@ meta_create_test_monitor (MetaContext *context,
|
||||
|
||||
return virtual_monitor;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NATIVE_BACKEND
|
||||
static gboolean
|
||||
callback_idle (gpointer user_data)
|
||||
{
|
||||
GMainLoop *loop = user_data;
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
queue_callback (GTask *task)
|
||||
{
|
||||
g_idle_add (callback_idle, g_task_get_task_data (task));
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
meta_flush_input (MetaContext *context)
|
||||
{
|
||||
#ifdef HAVE_NATIVE_BACKEND
|
||||
MetaBackend *backend = meta_context_get_backend (context);
|
||||
ClutterSeat *seat;
|
||||
MetaSeatNative *seat_native;
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (GMainLoop) loop = NULL;
|
||||
|
||||
g_assert_true (META_IS_BACKEND_NATIVE (backend));
|
||||
|
||||
seat = meta_backend_get_default_seat (backend);
|
||||
seat_native = META_SEAT_NATIVE (seat);
|
||||
|
||||
task = g_task_new (backend, NULL, NULL, NULL);
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_task_set_task_data (task, loop, NULL);
|
||||
|
||||
meta_seat_impl_run_input_task (seat_native->impl, task,
|
||||
(GSourceFunc) queue_callback);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
#endif
|
||||
}
|
||||
|
@ -122,4 +122,7 @@ MetaVirtualMonitor * meta_create_test_monitor (MetaContext *context,
|
||||
int height,
|
||||
float refresh_rate);
|
||||
|
||||
META_EXPORT
|
||||
void meta_flush_input (MetaContext *context);
|
||||
|
||||
#endif /* TEST_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user