Move keyboard grab info to common code
This is the first stage in tracking keyboard grabs in the common code. This lets us handle destroying or unmapping virtual window with a keyboard grab.
This commit is contained in:
committed by
Alexander Larsson
parent
c0ad534d81
commit
e60af9d315
@ -58,6 +58,17 @@ typedef struct
|
|||||||
GdkWindow *grab_one_pointer_release_event;
|
GdkWindow *grab_one_pointer_release_event;
|
||||||
} GdkPointerGrabInfo;
|
} GdkPointerGrabInfo;
|
||||||
|
|
||||||
|
/* Tracks information about the keyboard grab on this display */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GdkWindow *window;
|
||||||
|
GdkWindow *native_window;
|
||||||
|
gulong serial;
|
||||||
|
gboolean owner_events;
|
||||||
|
guint32 time;
|
||||||
|
} GdkKeyboardGrabInfo;
|
||||||
|
|
||||||
|
|
||||||
/* Tracks information about which window and position the pointer last was in.
|
/* Tracks information about which window and position the pointer last was in.
|
||||||
* This is useful when we need to synthesize events later.
|
* This is useful when we need to synthesize events later.
|
||||||
* Note that we track toplevel_under_pointer using enter/leave events,
|
* Note that we track toplevel_under_pointer using enter/leave events,
|
||||||
@ -102,6 +113,7 @@ struct _GdkDisplay
|
|||||||
gint button_y[2];
|
gint button_y[2];
|
||||||
|
|
||||||
GdkPointerGrabInfo pointer_grab;
|
GdkPointerGrabInfo pointer_grab;
|
||||||
|
GdkKeyboardGrabInfo keyboard_grab;
|
||||||
GdkPointerWindowInfo pointer_info;
|
GdkPointerWindowInfo pointer_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -650,9 +650,9 @@ gdk_display_keyboard_ungrab (GdkDisplay *display,
|
|||||||
XFlush (xdisplay);
|
XFlush (xdisplay);
|
||||||
|
|
||||||
if (time == GDK_CURRENT_TIME ||
|
if (time == GDK_CURRENT_TIME ||
|
||||||
display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
|
display->keyboard_grab.time == GDK_CURRENT_TIME ||
|
||||||
!XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
|
!XSERVER_TIME_IS_LATER (display->keyboard_grab.time, time))
|
||||||
display_x11->keyboard_xgrab_window = NULL;
|
display->keyboard_grab.window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -94,18 +94,6 @@ struct _GdkDisplayX11
|
|||||||
* (grabs, properties etc.) Otherwise always TRUE. */
|
* (grabs, properties etc.) Otherwise always TRUE. */
|
||||||
gboolean trusted_client;
|
gboolean trusted_client;
|
||||||
|
|
||||||
/* Information about current keyboard grabs held by this
|
|
||||||
* client. If gdk_keyboard_xgrab_window
|
|
||||||
* window is NULL, then the other associated fields are ignored
|
|
||||||
* Pointer grab info is stored in GdkDisplay.
|
|
||||||
*/
|
|
||||||
|
|
||||||
GdkWindowObject *keyboard_xgrab_window;
|
|
||||||
GdkWindowObject *keyboard_xgrab_native_window;
|
|
||||||
gulong keyboard_xgrab_serial;
|
|
||||||
gboolean keyboard_xgrab_owner_events;
|
|
||||||
guint32 keyboard_xgrab_time;
|
|
||||||
|
|
||||||
/* drag and drop information */
|
/* drag and drop information */
|
||||||
GdkDragContext *current_dest_drag;
|
GdkDragContext *current_dest_drag;
|
||||||
|
|
||||||
|
|||||||
@ -984,17 +984,17 @@ gdk_event_translate (GdkDisplay *display,
|
|||||||
if (/* Is key event */
|
if (/* Is key event */
|
||||||
(xevent->type == KeyPress || xevent->type == KeyRelease) &&
|
(xevent->type == KeyPress || xevent->type == KeyRelease) &&
|
||||||
/* And we have a grab */
|
/* And we have a grab */
|
||||||
display_x11->keyboard_xgrab_window != NULL &&
|
display->keyboard_grab.window != NULL &&
|
||||||
(
|
(
|
||||||
/* The window is not a descendant of the grabbed window */
|
/* The window is not a descendant of the grabbed window */
|
||||||
!is_parent_of ((GdkWindow *)display_x11->keyboard_xgrab_window, window) ||
|
!is_parent_of ((GdkWindow *)display->keyboard_grab.window, window) ||
|
||||||
/* Or owner event is false */
|
/* Or owner event is false */
|
||||||
!display_x11->keyboard_xgrab_owner_events
|
!display->keyboard_grab.owner_events
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/* Report key event against grab window */
|
/* Report key event against grab window */
|
||||||
window_private = display_x11->keyboard_xgrab_window;
|
window_private = display->keyboard_grab.window;
|
||||||
window = (GdkWindow *) window_private;
|
window = (GdkWindow *) window_private;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -316,6 +316,7 @@ gdk_keyboard_grab (GdkWindow * window,
|
|||||||
{
|
{
|
||||||
gint return_val;
|
gint return_val;
|
||||||
unsigned long serial;
|
unsigned long serial;
|
||||||
|
GdkDisplay *display;
|
||||||
GdkDisplayX11 *display_x11;
|
GdkDisplayX11 *display_x11;
|
||||||
GdkWindow *native;
|
GdkWindow *native;
|
||||||
|
|
||||||
@ -327,8 +328,9 @@ gdk_keyboard_grab (GdkWindow * window,
|
|||||||
/* TODO: What do we do for offscreens and children? We need to proxy the grab somehow */
|
/* TODO: What do we do for offscreens and children? We need to proxy the grab somehow */
|
||||||
if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl))
|
if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl))
|
||||||
return GDK_GRAB_SUCCESS;
|
return GDK_GRAB_SUCCESS;
|
||||||
|
|
||||||
display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (native));
|
display = GDK_WINDOW_DISPLAY (native);
|
||||||
|
display_x11 = GDK_DISPLAY_X11 (display);
|
||||||
|
|
||||||
serial = NextRequest (GDK_WINDOW_XDISPLAY (native));
|
serial = NextRequest (GDK_WINDOW_XDISPLAY (native));
|
||||||
|
|
||||||
@ -354,16 +356,16 @@ gdk_keyboard_grab (GdkWindow * window,
|
|||||||
|
|
||||||
if (return_val == GrabSuccess)
|
if (return_val == GrabSuccess)
|
||||||
{
|
{
|
||||||
if (display_x11->keyboard_xgrab_window != NULL &&
|
if (display->keyboard_grab.window != NULL &&
|
||||||
display_x11->keyboard_xgrab_window != (GdkWindowObject *)window)
|
display->keyboard_grab.window != window)
|
||||||
generate_grab_broken_event (GDK_WINDOW (display_x11->keyboard_xgrab_window),
|
generate_grab_broken_event (GDK_WINDOW (display->keyboard_grab.window),
|
||||||
TRUE, FALSE, window);
|
TRUE, FALSE, window);
|
||||||
|
|
||||||
display_x11->keyboard_xgrab_window = (GdkWindowObject *)window;
|
display->keyboard_grab.window = window;
|
||||||
display_x11->keyboard_xgrab_native_window = (GdkWindowObject *)native;
|
display->keyboard_grab.native_window = native;
|
||||||
display_x11->keyboard_xgrab_serial = serial;
|
display->keyboard_grab.serial = serial;
|
||||||
display_x11->keyboard_xgrab_owner_events = owner_events;
|
display->keyboard_grab.owner_events = owner_events;
|
||||||
display_x11->keyboard_xgrab_time = time;
|
display->keyboard_grab.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gdk_x11_convert_grab_status (return_val);
|
return gdk_x11_convert_grab_status (return_val);
|
||||||
@ -405,18 +407,14 @@ gdk_keyboard_grab_info_libgtk_only (GdkDisplay *display,
|
|||||||
GdkWindow **grab_window,
|
GdkWindow **grab_window,
|
||||||
gboolean *owner_events)
|
gboolean *owner_events)
|
||||||
{
|
{
|
||||||
GdkDisplayX11 *display_x11;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_DISPLAY (display), False);
|
g_return_val_if_fail (GDK_IS_DISPLAY (display), False);
|
||||||
|
|
||||||
display_x11 = GDK_DISPLAY_X11 (display);
|
if (display->keyboard_grab.window)
|
||||||
|
|
||||||
if (display_x11->keyboard_xgrab_window)
|
|
||||||
{
|
{
|
||||||
if (grab_window)
|
if (grab_window)
|
||||||
*grab_window = (GdkWindow *)display_x11->keyboard_xgrab_window;
|
*grab_window = display->keyboard_grab.window;
|
||||||
if (owner_events)
|
if (owner_events)
|
||||||
*owner_events = display_x11->keyboard_xgrab_owner_events;
|
*owner_events = display->keyboard_grab.owner_events;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -439,7 +437,6 @@ _gdk_xgrab_check_unmap (GdkWindow *window,
|
|||||||
gulong serial)
|
gulong serial)
|
||||||
{
|
{
|
||||||
GdkDisplay *display = gdk_drawable_get_display (window);
|
GdkDisplay *display = gdk_drawable_get_display (window);
|
||||||
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
|
|
||||||
|
|
||||||
if (display->pointer_grab.window &&
|
if (display->pointer_grab.window &&
|
||||||
serial >= display->pointer_grab.serial)
|
serial >= display->pointer_grab.serial)
|
||||||
@ -454,21 +451,20 @@ _gdk_xgrab_check_unmap (GdkWindow *window,
|
|||||||
_gdk_display_unset_has_pointer_grab (display, TRUE, FALSE, GDK_CURRENT_TIME);
|
_gdk_display_unset_has_pointer_grab (display, TRUE, FALSE, GDK_CURRENT_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display_x11->keyboard_xgrab_window &&
|
if (display->keyboard_grab.window &&
|
||||||
serial >= display_x11->keyboard_xgrab_serial)
|
serial >= display->keyboard_grab.serial)
|
||||||
{
|
{
|
||||||
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
|
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
|
||||||
GdkWindowObject *tmp = display_x11->keyboard_xgrab_window;
|
GdkWindowObject *tmp = GDK_WINDOW_OBJECT (display->keyboard_grab.window);
|
||||||
|
|
||||||
|
|
||||||
while (tmp && tmp != private)
|
while (tmp && tmp != private)
|
||||||
tmp = tmp->parent;
|
tmp = tmp->parent;
|
||||||
|
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
generate_grab_broken_event (GDK_WINDOW (display_x11->keyboard_xgrab_window),
|
generate_grab_broken_event (GDK_WINDOW (display->keyboard_grab.window),
|
||||||
TRUE, FALSE, NULL);
|
TRUE, FALSE, NULL);
|
||||||
display_x11->keyboard_xgrab_window = NULL;
|
display->keyboard_grab.window = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,12 +486,12 @@ _gdk_xgrab_check_destroy (GdkWindow *window)
|
|||||||
display->pointer_grab.window != NULL)
|
display->pointer_grab.window != NULL)
|
||||||
_gdk_display_unset_has_pointer_grab (display, TRUE, FALSE, GDK_CURRENT_TIME);
|
_gdk_display_unset_has_pointer_grab (display, TRUE, FALSE, GDK_CURRENT_TIME);
|
||||||
|
|
||||||
if ((GdkWindowObject *)window == display_x11->keyboard_xgrab_native_window &&
|
if (window == display->keyboard_grab.native_window &&
|
||||||
display_x11->keyboard_xgrab_window != NULL)
|
display->keyboard_grab.window != NULL)
|
||||||
{
|
{
|
||||||
generate_grab_broken_event (GDK_WINDOW (display_x11->keyboard_xgrab_window),
|
generate_grab_broken_event (GDK_WINDOW (display->keyboard_grab.window),
|
||||||
TRUE, FALSE, NULL);
|
TRUE, FALSE, NULL);
|
||||||
display_x11->keyboard_xgrab_window = NULL;
|
display->keyboard_grab.window = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user