mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
gdk: Add _gdk_x11_event_translator_get_window()
This method can be implemented by event translators so they return the right window from XGenericEventCookie events, as ev->xany.window isn't meaningful for these. GdkEventSource now also uses this to find out the right window filters to apply.
This commit is contained in:
parent
53d77a829a
commit
55cc9f3339
@ -97,11 +97,30 @@ gdk_event_apply_filters (XEvent *xevent,
|
||||
}
|
||||
|
||||
static GdkWindow *
|
||||
gdk_event_source_get_filter_window (GdkEventSource *event_source,
|
||||
XEvent *xevent)
|
||||
gdk_event_source_get_filter_window (GdkEventSource *event_source,
|
||||
XEvent *xevent,
|
||||
GdkEventTranslator **event_translator)
|
||||
{
|
||||
GList *list = event_source->translators;
|
||||
GdkWindow *window;
|
||||
|
||||
*event_translator = NULL;
|
||||
|
||||
while (list)
|
||||
{
|
||||
GdkEventTranslator *translator = list->data;
|
||||
|
||||
list = list->next;
|
||||
window = _gdk_x11_event_translator_get_window (translator,
|
||||
event_source->display,
|
||||
xevent);
|
||||
if (window)
|
||||
{
|
||||
*event_translator = translator;
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
window = gdk_x11_window_lookup_for_display (event_source->display,
|
||||
xevent->xany.window);
|
||||
|
||||
@ -151,8 +170,8 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
|
||||
XEvent *xevent)
|
||||
{
|
||||
GdkEvent *event = gdk_event_new (GDK_NOTHING);
|
||||
GList *list = event_source->translators;
|
||||
GdkFilterReturn result = GDK_FILTER_CONTINUE;
|
||||
GdkEventTranslator *event_translator;
|
||||
GdkWindow *filter_window;
|
||||
Display *dpy;
|
||||
|
||||
@ -164,7 +183,8 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
|
||||
if (xevent->type == GenericEvent)
|
||||
XGetEventData (dpy, &xevent->xcookie);
|
||||
|
||||
filter_window = gdk_event_source_get_filter_window (event_source, xevent);
|
||||
filter_window = gdk_event_source_get_filter_window (event_source, xevent,
|
||||
&event_translator);
|
||||
if (filter_window)
|
||||
event->any.window = g_object_ref (filter_window);
|
||||
|
||||
@ -199,15 +219,27 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
|
||||
gdk_event_free (event);
|
||||
event = NULL;
|
||||
|
||||
while (list && !event)
|
||||
if (event_translator)
|
||||
{
|
||||
GdkEventTranslator *translator = list->data;
|
||||
|
||||
list = list->next;
|
||||
event = _gdk_x11_event_translator_translate (translator,
|
||||
/* Event translator was gotten before in get_filter_window() */
|
||||
event = _gdk_x11_event_translator_translate (event_translator,
|
||||
event_source->display,
|
||||
xevent);
|
||||
}
|
||||
else
|
||||
{
|
||||
GList *list = event_source->translators;
|
||||
|
||||
while (list && !event)
|
||||
{
|
||||
GdkEventTranslator *translator = list->data;
|
||||
|
||||
list = list->next;
|
||||
event = _gdk_x11_event_translator_translate (translator,
|
||||
event_source->display,
|
||||
xevent);
|
||||
}
|
||||
}
|
||||
|
||||
if (event &&
|
||||
(event->type == GDK_ENTER_NOTIFY ||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gdkeventtranslator.h"
|
||||
|
||||
#include "gdkwindow-x11.h"
|
||||
|
||||
typedef GdkEventTranslatorIface GdkEventTranslatorInterface;
|
||||
G_DEFINE_INTERFACE (GdkEventTranslator, _gdk_x11_event_translator, G_TYPE_OBJECT);
|
||||
@ -87,3 +87,24 @@ _gdk_x11_event_translator_select_window_events (GdkEventTranslator *translator,
|
||||
if (iface->select_window_events)
|
||||
iface->select_window_events (translator, window, event_mask);
|
||||
}
|
||||
|
||||
GdkWindow *
|
||||
_gdk_x11_event_translator_get_window (GdkEventTranslator *translator,
|
||||
GdkDisplay *display,
|
||||
XEvent *xevent)
|
||||
{
|
||||
GdkEventTranslatorIface *iface;
|
||||
GdkWindow *window = NULL;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_EVENT_TRANSLATOR (translator), NULL);
|
||||
|
||||
iface = GDK_EVENT_TRANSLATOR_GET_IFACE (translator);
|
||||
|
||||
if (iface->get_window)
|
||||
window = iface->get_window (translator, xevent);
|
||||
|
||||
if (!window)
|
||||
window = gdk_x11_window_lookup_for_display (display, xevent->xany.window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ struct _GdkEventTranslatorIface
|
||||
void (* select_window_events) (GdkEventTranslator *translator,
|
||||
Window window,
|
||||
GdkEventMask event_mask);
|
||||
GdkWindow * (* get_window) (GdkEventTranslator *translator,
|
||||
XEvent *xevent);
|
||||
};
|
||||
|
||||
GType _gdk_x11_event_translator_get_type (void) G_GNUC_CONST;
|
||||
@ -60,6 +62,9 @@ GdkEventMask _gdk_x11_event_translator_get_handled_events (GdkEventTranslator
|
||||
void _gdk_x11_event_translator_select_window_events (GdkEventTranslator *translator,
|
||||
Window window,
|
||||
GdkEventMask event_mask);
|
||||
GdkWindow * _gdk_x11_event_translator_get_window (GdkEventTranslator *translator,
|
||||
GdkDisplay *display,
|
||||
XEvent *xevent);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user