Commit 722c975a authored by Armin Krezović's avatar Armin Krezović Committed by Jonas Ådahl

Move alarm and xids management to MetaX11Display

https://bugzilla.gnome.org/show_bug.cgi?id=759538
parent 937a9853
......@@ -97,7 +97,7 @@ _meta_barrier_impl_x11_destroy (MetaBarrierImpl *impl)
return;
XFixesDestroyPointerBarrier (dpy, priv->xbarrier);
g_hash_table_remove (display->xids, &priv->xbarrier);
g_hash_table_remove (display->x11_display->xids, &priv->xbarrier);
priv->xbarrier = 0;
}
......@@ -134,7 +134,7 @@ meta_barrier_impl_x11_new (MetaBarrier *barrier)
allowed_motion_dirs,
0, NULL);
g_hash_table_insert (display->xids, &priv->xbarrier, barrier);
g_hash_table_insert (display->x11_display->xids, &priv->xbarrier, barrier);
return META_BARRIER_IMPL (self);
}
......@@ -174,8 +174,8 @@ meta_barrier_fire_xevent (MetaBarrier *barrier,
}
gboolean
meta_display_process_barrier_xevent (MetaDisplay *display,
XIEvent *event)
meta_x11_display_process_barrier_xevent (MetaX11Display *x11_display,
XIEvent *event)
{
MetaBarrier *barrier;
XIBarrierEvent *xev;
......@@ -193,7 +193,7 @@ meta_display_process_barrier_xevent (MetaDisplay *display,
}
xev = (XIBarrierEvent *) event;
barrier = g_hash_table_lookup (display->xids, &xev->barrier);
barrier = g_hash_table_lookup (x11_display->xids, &xev->barrier);
if (barrier != NULL)
{
meta_barrier_fire_xevent (barrier, xev);
......
......@@ -758,7 +758,7 @@ meta_compositor_process_event (MetaCompositor *compositor,
if (window == NULL)
{
Window xwin = ((XDamageNotifyEvent *) event)->drawable;
window = meta_display_lookup_x_window (compositor->display, xwin);
window = meta_x11_display_lookup_x_window (x11_display, xwin);
}
if (window)
......
......@@ -29,6 +29,7 @@
#include <meta/errors.h>
#include "util-private.h"
#include "x11/meta-x11-display-private.h"
#include "x11/window-x11.h"
#include "x11/window-x11-private.h"
......@@ -51,7 +52,7 @@ get_window (Display *xdisplay,
MetaWindow *window;
display = meta_display_for_x_display (xdisplay);
window = meta_display_lookup_x_window (display, frame_xwindow);
window = meta_x11_display_lookup_x_window (display->x11_display, frame_xwindow);
if (window == NULL || window->frame == NULL)
{
......
......@@ -102,10 +102,6 @@ typedef enum {
META_EVENT_ROUTE_FRAME_BUTTON,
} MetaEventRoute;
typedef gboolean (*MetaAlarmFilter) (MetaDisplay *display,
XSyncAlarmNotifyEvent *event,
gpointer data);
typedef void (* MetaDisplayWindowFunc) (MetaWindow *window,
gpointer user_data);
......@@ -165,7 +161,6 @@ struct _MetaDisplay
/*< private-ish >*/
MetaScreen *screen;
GHashTable *xids;
GHashTable *stamps;
GHashTable *wayland_windows;
......@@ -257,9 +252,6 @@ struct _MetaDisplay
MetaGestureTracker *gesture_tracker;
ClutterEventSequence *pointer_emulating_sequence;
MetaAlarmFilter alarm_filter;
gpointer alarm_filter_data;
ClutterActor *current_pad_osd;
MetaStartupNotification *startup_notification;
......@@ -299,17 +291,6 @@ void meta_display_unmanage_windows (MetaDisplay *display,
int meta_display_stack_cmp (const void *a,
const void *b);
/* A given MetaWindow may have various X windows that "belong"
* to it, such as the frame window.
*/
MetaWindow* meta_display_lookup_x_window (MetaDisplay *display,
Window xwindow);
void meta_display_register_x_window (MetaDisplay *display,
Window *xwindowp,
MetaWindow *window);
void meta_display_unregister_x_window (MetaDisplay *display,
Window xwindow);
/* Each MetaWindow is uniquely identified by a 64-bit "stamp"; unlike a
* a MetaWindow *, a stamp will never be recycled
*/
......@@ -338,14 +319,6 @@ void meta_display_register_wayland_window (MetaDisplay *display,
void meta_display_unregister_wayland_window (MetaDisplay *display,
MetaWindow *window);
MetaWindow* meta_display_lookup_sync_alarm (MetaDisplay *display,
XSyncAlarm alarm);
void meta_display_register_sync_alarm (MetaDisplay *display,
XSyncAlarm *alarmp,
MetaWindow *window);
void meta_display_unregister_sync_alarm (MetaDisplay *display,
XSyncAlarm alarm);
void meta_display_notify_window_created (MetaDisplay *display,
MetaWindow *window);
......@@ -412,11 +385,6 @@ void meta_display_accelerator_activate (MetaDisplay *display,
ClutterKeyEvent *event);
gboolean meta_display_modifiers_accelerator_activate (MetaDisplay *display);
#ifdef HAVE_XI23
gboolean meta_display_process_barrier_xevent (MetaDisplay *display,
XIEvent *event);
#endif /* HAVE_XI23 */
void meta_display_set_input_focus_xwindow (MetaDisplay *display,
MetaScreen *screen,
Window window,
......@@ -456,10 +424,6 @@ void meta_display_cancel_touch (MetaDisplay *display);
gboolean meta_display_windows_are_interactable (MetaDisplay *display);
void meta_display_set_alarm_filter (MetaDisplay *display,
MetaAlarmFilter filter,
gpointer data);
void meta_display_show_tablet_mapping_notification (MetaDisplay *display,
ClutterInputDevice *pad,
const gchar *pretty_name);
......
......@@ -732,9 +732,6 @@ meta_display_open (void)
meta_display_init_events_x11 (display);
display->xids = g_hash_table_new (meta_unsigned_long_hash,
meta_unsigned_long_equal);
/* Create the leader window here. Set its properties and
* use the timestamp from one of the PropertyNotify events
* that will follow.
......@@ -847,7 +844,9 @@ meta_display_open (void)
if (old_active_xwindow != None)
{
MetaWindow *old_active_window = meta_display_lookup_x_window (display, old_active_xwindow);
MetaWindow *old_active_window;
old_active_window = meta_x11_display_lookup_x_window (display->x11_display,
old_active_xwindow);
if (old_active_window)
meta_window_focus (old_active_window, timestamp);
else
......@@ -898,17 +897,20 @@ meta_display_list_windows (MetaDisplay *display,
winlist = NULL;
g_hash_table_iter_init (&iter, display->xids);
while (g_hash_table_iter_next (&iter, &key, &value))
if (display->x11_display)
{
MetaWindow *window = value;
g_hash_table_iter_init (&iter, display->x11_display->xids);
while (g_hash_table_iter_next (&iter, &key, &value))
{
MetaWindow *window = value;
if (!META_IS_WINDOW (window) || window->unmanaging)
continue;
if (!META_IS_WINDOW (window) || window->unmanaging)
continue;
if (!window->override_redirect ||
(flags & META_LIST_INCLUDE_OVERRIDE_REDIRECT) != 0)
winlist = g_slist_prepend (winlist, window);
if (!window->override_redirect ||
(flags & META_LIST_INCLUDE_OVERRIDE_REDIRECT) != 0)
winlist = g_slist_prepend (winlist, window);
}
}
g_hash_table_iter_init (&iter, display->wayland_windows);
......@@ -1015,11 +1017,6 @@ meta_display_close (MetaDisplay *display,
/* Stop caring about events */
meta_display_free_events_x11 (display);
/* Must be after all calls to meta_window_unmanage() since they
* unregister windows
*/
g_hash_table_destroy (display->xids);
if (display->leader_window != None)
XDestroyWindow (display->x11_display->xdisplay, display->leader_window);
......@@ -1459,32 +1456,6 @@ request_xserver_input_focus_change (MetaDisplay *display,
meta_display_remove_autoraise_callback (display);
}
MetaWindow*
meta_display_lookup_x_window (MetaDisplay *display,
Window xwindow)
{
return g_hash_table_lookup (display->xids, &xwindow);
}
void
meta_display_register_x_window (MetaDisplay *display,
Window *xwindowp,
MetaWindow *window)
{
g_return_if_fail (g_hash_table_lookup (display->xids, xwindowp) == NULL);
g_hash_table_insert (display->xids, xwindowp, window);
}
void
meta_display_unregister_x_window (MetaDisplay *display,
Window xwindow)
{
g_return_if_fail (g_hash_table_lookup (display->xids, &xwindow) != NULL);
g_hash_table_remove (display->xids, &xwindow);
}
void
meta_display_register_wayland_window (MetaDisplay *display,
MetaWindow *window)
......@@ -1530,7 +1501,8 @@ meta_display_lookup_stack_id (MetaDisplay *display,
guint64 stack_id)
{
if (META_STACK_ID_IS_X11 (stack_id))
return meta_display_lookup_x_window (display, (Window)stack_id);
return meta_x11_display_lookup_x_window (display->x11_display,
(Window)stack_id);
else
return meta_display_lookup_stamp (display, stack_id);
}
......@@ -1561,37 +1533,6 @@ meta_display_describe_stack_id (MetaDisplay *display,
return result;
}
/* 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*
meta_display_lookup_sync_alarm (MetaDisplay *display,
XSyncAlarm alarm)
{
return g_hash_table_lookup (display->xids, &alarm);
}
void
meta_display_register_sync_alarm (MetaDisplay *display,
XSyncAlarm *alarmp,
MetaWindow *window)
{
g_return_if_fail (g_hash_table_lookup (display->xids, alarmp) == NULL);
g_hash_table_insert (display->xids, alarmp, window);
}
void
meta_display_unregister_sync_alarm (MetaDisplay *display,
XSyncAlarm alarm)
{
g_return_if_fail (g_hash_table_lookup (display->xids, &alarm) != NULL);
g_hash_table_remove (display->xids, &alarm);
}
void
meta_display_notify_window_created (MetaDisplay *display,
MetaWindow *window)
......@@ -3044,17 +2985,6 @@ meta_display_is_pointer_emulating_sequence (MetaDisplay *display,
return display->pointer_emulating_sequence == sequence;
}
void
meta_display_set_alarm_filter (MetaDisplay *display,
MetaAlarmFilter filter,
gpointer data)
{
g_return_if_fail (filter == NULL || display->alarm_filter == NULL);
display->alarm_filter = filter;
display->alarm_filter_data = data;
}
void
meta_display_request_pad_osd (MetaDisplay *display,
ClutterInputDevice *pad,
......
......@@ -85,7 +85,7 @@ meta_window_ensure_frame (MetaWindow *window)
XChangeWindowAttributes (x11_display->xdisplay,
frame->xwindow, CWEventMask, &attrs);
meta_display_register_x_window (window->display, &frame->xwindow, window);
meta_x11_display_register_x_window (x11_display, &frame->xwindow, window);
meta_error_trap_push (x11_display);
if (window->mapped)
......@@ -201,8 +201,7 @@ meta_window_destroy_frame (MetaWindow *window)
meta_ui_frame_unmanage (frame->ui_frame);
meta_display_unregister_x_window (window->display,
frame->xwindow);
meta_x11_display_unregister_x_window (x11_display, frame->xwindow);
window->frame = NULL;
if (window->frame_bounds)
......
......@@ -851,8 +851,9 @@ meta_stack_tracker_sync_stack (MetaStackTracker *tracker)
if (META_STACK_ID_IS_X11 (window))
{
MetaX11Display *x11_display = tracker->screen->display->x11_display;
MetaWindow *meta_window =
meta_display_lookup_x_window (tracker->screen->display, (Window)window);
meta_x11_display_lookup_x_window (x11_display, (Window)window);
/* When mapping back from xwindow to MetaWindow we have to be a bit careful;
* children of the root could include unmapped windows created by toolkits
......
......@@ -7488,8 +7488,8 @@ meta_window_get_transient_for (MetaWindow *window)
if (window->transient_for)
return window->transient_for;
else if (window->xtransient_for)
return meta_display_lookup_x_window (window->display,
window->xtransient_for);
return meta_x11_display_lookup_x_window (window->display->x11_display,
window->xtransient_for);
else
return NULL;
}
......@@ -8050,24 +8050,24 @@ window_has_pointer_wayland (MetaWindow *window)
static gboolean
window_has_pointer_x11 (MetaWindow *window)
{
MetaDisplay *display = window->display;
MetaX11Display *x11_display = window->display->x11_display;
Window root, child;
double root_x, root_y, x, y;
XIButtonState buttons;
XIModifierState mods;
XIGroupState group;
meta_error_trap_push (display->x11_display);
XIQueryPointer (display->x11_display->xdisplay,
meta_error_trap_push (x11_display);
XIQueryPointer (x11_display->xdisplay,
META_VIRTUAL_CORE_POINTER_ID,
display->x11_display->xroot,
x11_display->xroot,
&root, &child,
&root_x, &root_y, &x, &y,
&buttons, &mods, &group);
meta_error_trap_pop (display->x11_display);
meta_error_trap_pop (x11_display);
free (buttons.mask);
return meta_display_lookup_x_window (display, child) == window;
return meta_x11_display_lookup_x_window (x11_display, child) == window;
}
gboolean
......
......@@ -41,7 +41,7 @@ typedef struct {
} TestCase;
static gboolean
test_case_alarm_filter (MetaDisplay *display,
test_case_alarm_filter (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event,
gpointer data)
{
......@@ -49,12 +49,12 @@ test_case_alarm_filter (MetaDisplay *display,
GHashTableIter iter;
gpointer key, value;
if (async_waiter_alarm_filter (test->waiter, display, event))
if (async_waiter_alarm_filter (test->waiter, x11_display, event))
return TRUE;
g_hash_table_iter_init (&iter, test->clients);
while (g_hash_table_iter_next (&iter, &key, &value))
if (test_client_alarm_filter (value, display, event))
if (test_client_alarm_filter (value, x11_display, event))
return TRUE;
return FALSE;
......@@ -103,8 +103,8 @@ test_case_new (void)
test_case_log_func,
test);
meta_display_set_alarm_filter (meta_get_display (),
test_case_alarm_filter, test);
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
test_case_alarm_filter, test);
test->clients = g_hash_table_new (g_str_hash, g_str_equal);
test->waiter = async_waiter_new ();
......@@ -501,7 +501,8 @@ test_case_destroy (TestCase *test,
async_waiter_destroy (test->waiter);
meta_display_set_alarm_filter (meta_get_display (), NULL, NULL);
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
NULL, NULL);
g_hash_table_destroy (test->clients);
g_free (test);
......
......@@ -162,7 +162,7 @@ async_waiter_set_and_wait (AsyncWaiter *waiter)
gboolean
async_waiter_alarm_filter (AsyncWaiter *waiter,
MetaDisplay *display,
MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event)
{
if (event->alarm != waiter->alarm)
......@@ -335,11 +335,11 @@ test_client_find_window (TestClient *client,
gboolean
test_client_alarm_filter (TestClient *client,
MetaDisplay *display,
MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event)
{
if (client->waiter)
return async_waiter_alarm_filter (client->waiter, display, event);
return async_waiter_alarm_filter (client->waiter, x11_display, event);
else
return FALSE;
}
......
......@@ -44,7 +44,7 @@ void test_init (int argc,
char **argv);
gboolean async_waiter_alarm_filter (AsyncWaiter *waiter,
MetaDisplay *display,
MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event);
void async_waiter_set_and_wait (AsyncWaiter *waiter);
......@@ -56,7 +56,7 @@ void async_waiter_destroy (AsyncWaiter *waiter);
char * test_client_get_id (TestClient *client);
gboolean test_client_alarm_filter (TestClient *client,
MetaDisplay *display,
MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event);
gboolean test_client_wait (TestClient *client,
......
......@@ -610,8 +610,8 @@ wayland_selection_data_new (XSelectionRequestEvent *request_event,
data->cancellable = g_cancellable_new ();
data->stream = g_unix_input_stream_new (p[0], TRUE);
data->window = meta_display_lookup_x_window (display,
data->request_event.requestor);
data->window = meta_x11_display_lookup_x_window (x11_display,
data->request_event.requestor);
/* Do *not* change the event mask on the root window, bugger! */
if (!data->window && data->request_event.requestor != x11_display->xroot)
......
......@@ -856,7 +856,9 @@ handle_input_xevent (MetaDisplay *display,
}
modified = xievent_get_modified_window (display, input_event);
window = modified != None ? meta_display_lookup_x_window (display, modified) : NULL;
window = modified != None ?
meta_x11_display_lookup_x_window (display->x11_display, modified) :
NULL;
/* If this is an event for a GTK+ widget, let GTK+ handle it. */
if (meta_ui_window_is_widget (display->screen->ui, modified))
......@@ -1173,7 +1175,8 @@ notify_bell (MetaDisplay *display,
XkbBellNotifyEvent *xkb_bell_event = (XkbBellNotifyEvent*) xkb_ev;
MetaWindow *window;
window = meta_display_lookup_x_window (display, xkb_bell_event->window);
window = meta_x11_display_lookup_x_window (display->x11_display,
xkb_bell_event->window);
if (!window && display->focus_window && display->focus_window->frame)
window = display->focus_window;
......@@ -1202,7 +1205,7 @@ handle_other_xevent (MetaDisplay *display,
gboolean bypass_gtk = FALSE;
modified = event_get_modified_window (display, event);
window = modified != None ? meta_display_lookup_x_window (display, modified) : NULL;
window = modified != None ? meta_x11_display_lookup_x_window (x11_display, modified) : NULL;
frame_was_receiver = (window && window->frame && modified == window->frame->xwindow);
/* We only want to respond to _NET_WM_USER_TIME property notify
......@@ -1219,8 +1222,8 @@ handle_other_xevent (MetaDisplay *display,
if (META_X11_DISPLAY_HAS_XSYNC (x11_display) &&
event->type == (x11_display->xsync_event_base + XSyncAlarmNotify))
{
MetaWindow *alarm_window = meta_display_lookup_sync_alarm (display,
((XSyncAlarmNotifyEvent*)event)->alarm);
MetaWindow *alarm_window = meta_x11_display_lookup_sync_alarm (x11_display,
((XSyncAlarmNotifyEvent*)event)->alarm);
if (alarm_window != NULL)
{
......@@ -1232,10 +1235,10 @@ handle_other_xevent (MetaDisplay *display,
}
else
{
if (display->alarm_filter &&
display->alarm_filter (display,
(XSyncAlarmNotifyEvent*)event,
display->alarm_filter_data))
if (x11_display->alarm_filter &&
x11_display->alarm_filter (x11_display,
(XSyncAlarmNotifyEvent*)event,
x11_display->alarm_filter_data))
bypass_gtk = TRUE;
}
......@@ -1748,7 +1751,8 @@ meta_display_handle_xevent (MetaDisplay *display,
meta_topic (META_DEBUG_FOCUS, "Earlier attempt to focus %s failed\n",
display->focus_window->desc);
meta_display_update_focus_window (display,
meta_display_lookup_x_window (display, display->server_focus_window),
meta_x11_display_lookup_x_window (display->x11_display,
display->server_focus_window),
display->server_focus_window,
display->server_focus_serial,
FALSE);
......@@ -1780,7 +1784,7 @@ meta_display_handle_xevent (MetaDisplay *display,
}
#ifdef HAVE_XI23
if (meta_display_process_barrier_xevent (display, input_event))
if (meta_x11_display_process_barrier_xevent (display->x11_display, input_event))
{
bypass_gtk = bypass_compositor = TRUE;
goto out;
......@@ -1814,7 +1818,9 @@ meta_display_handle_xevent (MetaDisplay *display,
out:
if (!bypass_compositor)
{
MetaWindow *window = modified != None ? meta_display_lookup_x_window (display, modified) : NULL;
MetaWindow *window = modified != None ?
meta_x11_display_lookup_x_window (display->x11_display, modified) :
NULL;
if (meta_compositor_process_event (display->compositor, event, window))
bypass_gtk = TRUE;
......
......@@ -33,6 +33,10 @@
#include "meta/types.h"
#include "meta/meta-x11-display.h"
typedef gboolean (*MetaAlarmFilter) (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event,
gpointer data);
struct _MetaX11Display
{
GObject parent;
......@@ -54,6 +58,11 @@ struct _MetaX11Display
#include "x11/atomnames.h"
#undef item
GHashTable *xids;
MetaAlarmFilter alarm_filter;
gpointer alarm_filter_data;
int composite_event_base;
int composite_error_base;
int composite_major_version;
......@@ -96,4 +105,29 @@ Cursor meta_x11_display_create_x_cursor (MetaX11Display *x11_display,
void meta_x11_display_reload_cursor (MetaX11Display *x11_display);
MetaWindow *meta_x11_display_lookup_x_window (MetaX11Display *x11_display,
Window xwindow);
void meta_x11_display_register_x_window (MetaX11Display *x11_display,
Window *xwindowp,
MetaWindow *window);
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);
void meta_x11_display_unregister_sync_alarm (MetaX11Display *x11_display,
XSyncAlarm alarm);
#ifdef HAVE_XI23
gboolean meta_x11_display_process_barrier_xevent (MetaX11Display *x11_display,
XIEvent *event);
#endif /* HAVE_XI23 */
void meta_x11_display_set_alarm_filter (MetaX11Display *x11_display,
MetaAlarmFilter filter,
gpointer data);
#endif /* META_X11_DISPLAY_PRIVATE_H */
......@@ -68,6 +68,15 @@ meta_x11_display_dispose (GObject *object)
{
MetaX11Display *x11_display = META_X11_DISPLAY (object);
if (x11_display->xids)
{
/* Must be after all calls to meta_window_unmanage() since they
* unregister windows
*/