Remove gdk_window_add_filter

Drop the public filtering API. The x11 backend already has
the ::xevent signal as replacement. The win32 backend needs
a similar signal to replace filtering.

Reshuffle header inclusions in the x11 backend a little bit
to avoid a cyclic inclusion between gdkprivate-x11.h and
gdkdisplay-x11.h that is otherwise causing problems.
This commit is contained in:
Matthias Clasen 2018-02-07 00:00:01 -05:00
parent 65beb0fc22
commit 89f6b8751e
19 changed files with 81 additions and 363 deletions

View File

@ -148,56 +148,6 @@ typedef union _GdkEvent GdkEvent;
typedef void (*GdkEventFunc) (GdkEvent *event,
gpointer data);
/* Event filtering */
/**
* GdkXEvent:
*
* Used to represent native events (XEvents for the X11
* backend, MSGs for Win32).
*/
typedef void GdkXEvent; /* Can be cast to window system specific
* even type, XEvent on X11, MSG on Win32.
*/
/**
* GdkFilterReturn:
* @GDK_FILTER_CONTINUE: event not handled, continue processing.
* @GDK_FILTER_TRANSLATE: native event translated into a GDK event and stored
* in the `event` structure that was passed in.
* @GDK_FILTER_REMOVE: event handled, terminate processing.
*
* Specifies the result of applying a #GdkFilterFunc to a native event.
*/
typedef enum {
GDK_FILTER_CONTINUE, /* Event not handled, continue processesing */
GDK_FILTER_TRANSLATE, /* Native event translated into a GDK event and
stored in the "event" structure that was
passed in */
GDK_FILTER_REMOVE /* Terminate processing, removing event */
} GdkFilterReturn;
/**
* GdkFilterFunc:
* @xevent: the native event to filter.
* @event: the GDK event to which the X event will be translated.
* @data: (closure): user data set when the filter was installed.
*
* Specifies the type of function used to filter native events before they are
* converted to GDK events.
*
* When a filter is called, @event is unpopulated, except for
* `event->window`. The filter may translate the native
* event to a GDK event and store the result in @event, or handle it without
* translation. If the filter translates the event and processing should
* continue, it should return %GDK_FILTER_TRANSLATE.
*
* Returns: a #GdkFilterReturn value.
*/
typedef GdkFilterReturn (*GdkFilterFunc) (GdkXEvent *xevent,
GdkEvent *event,
gpointer data);
/**
* GdkEventType:
* @GDK_NOTHING: a special code to indicate a null event.

View File

@ -42,20 +42,8 @@ G_BEGIN_DECLS
/* Debugging support */
typedef struct _GdkEventFilter GdkEventFilter;
typedef struct _GdkWindowAttr GdkWindowAttr;
typedef enum {
GDK_EVENT_FILTER_REMOVED = 1 << 0
} GdkEventFilterFlags;
struct _GdkEventFilter {
GdkFilterFunc function;
gpointer data;
GdkEventFilterFlags flags;
guint ref_count;
};
typedef enum {
GDK_DEBUG_MISC = 1 << 0,
GDK_DEBUG_EVENTS = 1 << 1,
@ -80,7 +68,6 @@ typedef enum {
GDK_DEBUG_CAIRO_IMAGE = 1 << 19
} GdkDebugFlags;
extern GList *_gdk_default_filters;
extern GdkWindow *_gdk_parent_root;
extern guint _gdk_debug_flags;
@ -173,7 +160,6 @@ struct _GdkWindow
gint8 toplevel_window_type;
GList *filters;
GList *children;
GList children_list_node;
@ -267,9 +253,6 @@ extern gint _gdk_screen_number;
GdkEvent* _gdk_event_unqueue (GdkDisplay *display);
void _gdk_event_filter_unref (GdkWindow *window,
GdkEventFilter *filter);
void gdk_event_set_pointer_emulated (GdkEvent *event,
gboolean emulated);

View File

@ -1109,58 +1109,6 @@ gdk_window_new_child (GdkWindow *parent,
return gdk_window_new (gdk_window_get_display (parent), parent, &attr);
}
/**
* _gdk_event_filter_unref:
* @window: (allow-none): A #GdkWindow, or %NULL to be the global window
* @filter: A window filter
*
* Release a reference to @filter. Note this function may
* mutate the list storage, so you need to handle this
* if iterating over a list of filters.
*/
void
_gdk_event_filter_unref (GdkWindow *window,
GdkEventFilter *filter)
{
GList **filters;
GList *tmp_list;
if (window == NULL)
filters = &_gdk_default_filters;
else
filters = &window->filters;
tmp_list = *filters;
while (tmp_list)
{
GdkEventFilter *iter_filter = tmp_list->data;
GList *node;
node = tmp_list;
tmp_list = tmp_list->next;
if (iter_filter != filter)
continue;
g_assert (iter_filter->ref_count > 0);
filter->ref_count--;
if (filter->ref_count != 0)
continue;
*filters = g_list_remove_link (*filters, node);
g_free (filter);
g_list_free_1 (node);
}
}
static void
window_remove_filters (GdkWindow *window)
{
while (window->filters)
_gdk_event_filter_unref (window, window->filters->data);
}
static void
update_pointer_info_foreach (GdkDisplay *display,
GdkDevice *device,
@ -1253,12 +1201,6 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
case GDK_WINDOW_SUBSURFACE:
if (window->window_type == GDK_WINDOW_FOREIGN && !foreign_destroy)
{
/* For historical reasons, we remove any filters
* on a foreign window when it or a parent is destroyed;
* this likely causes problems if two separate portions
* of code are maintaining filter lists on a foreign window.
*/
window_remove_filters (window);
}
else
{
@ -1328,8 +1270,6 @@ _gdk_window_destroy_hierarchy (GdkWindow *window,
window->parent = NULL;
window->destroyed = TRUE;
window_remove_filters (window);
window_remove_from_pointer_info (window, display);
if (window->clip_region)
@ -1651,110 +1591,6 @@ gdk_window_get_children_with_user_data (GdkWindow *window,
}
/**
* gdk_window_add_filter: (skip)
* @window: (allow-none): a #GdkWindow
* @function: filter callback
* @data: data to pass to filter callback
*
* Adds an event filter to @window, allowing you to intercept events
* before they reach GDK. This is a low-level operation and makes it
* easy to break GDK and/or GTK+, so you have to know what you're
* doing. Pass %NULL for @window to get all events for all windows,
* instead of events for a specific window.
*
* If you are interested in X GenericEvents, bear in mind that
* XGetEventData() has been already called on the event, and
* XFreeEventData() must not be called within @function.
**/
void
gdk_window_add_filter (GdkWindow *window,
GdkFilterFunc function,
gpointer data)
{
GList *tmp_list;
GdkEventFilter *filter;
g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
if (window && GDK_WINDOW_DESTROYED (window))
return;
/* Filters are for the native events on the native window, so
ensure there is a native window. */
if (window && !gdk_window_has_impl (window))
{
g_warning ("Filters only work on toplevel windows");
return;
}
if (window)
tmp_list = window->filters;
else
tmp_list = _gdk_default_filters;
while (tmp_list)
{
filter = (GdkEventFilter *)tmp_list->data;
if ((filter->function == function) && (filter->data == data))
{
filter->ref_count++;
return;
}
tmp_list = tmp_list->next;
}
filter = g_new (GdkEventFilter, 1);
filter->function = function;
filter->data = data;
filter->ref_count = 1;
filter->flags = 0;
if (window)
window->filters = g_list_append (window->filters, filter);
else
_gdk_default_filters = g_list_append (_gdk_default_filters, filter);
}
/**
* gdk_window_remove_filter: (skip)
* @window: a #GdkWindow
* @function: previously-added filter function
* @data: user data for previously-added filter function
*
* Remove a filter previously added with gdk_window_add_filter().
*/
void
gdk_window_remove_filter (GdkWindow *window,
GdkFilterFunc function,
gpointer data)
{
GList *tmp_list;
GdkEventFilter *filter;
g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
if (window)
tmp_list = window->filters;
else
tmp_list = _gdk_default_filters;
while (tmp_list)
{
filter = (GdkEventFilter *)tmp_list->data;
tmp_list = tmp_list->next;
if ((filter->function == function) && (filter->data == data))
{
filter->flags |= GDK_EVENT_FILTER_REMOVED;
_gdk_event_filter_unref (window, filter);
return;
}
}
}
/**
* gdk_window_is_visible:
* @window: a #GdkWindow

View File

@ -514,14 +514,6 @@ GDK_AVAILABLE_IN_ALL
void gdk_window_set_focus_on_map (GdkWindow *window,
gboolean focus_on_map);
GDK_AVAILABLE_IN_ALL
void gdk_window_add_filter (GdkWindow *window,
GdkFilterFunc function,
gpointer data);
GDK_AVAILABLE_IN_ALL
void gdk_window_remove_filter (GdkWindow *window,
GdkFilterFunc function,
gpointer data);
GDK_AVAILABLE_IN_ALL
void gdk_window_scroll (GdkWindow *window,
gint dx,
gint dy);

View File

@ -24,6 +24,7 @@
#include "gdkapplaunchcontextprivate.h"
#include "gdkintl.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include <glib.h>
#include <gio/gdesktopappinfo.h>

View File

@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
#include "gdkasync.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#ifdef NEED_XIPROTO_H_FOR_XREPLY
#include <X11/extensions/XIproto.h>

View File

@ -21,6 +21,7 @@
#include "gdkclipboard-x11.h"
#include "gdkintl.h"
#include "gdkdisplay-x11.h"
#include "gdkprivate-x11.h"
#include "gdkselectioninputstream-x11.h"
#include "gdkselectionoutputstream-x11.h"

View File

@ -24,6 +24,7 @@
#include "gdkinternals.h"
#include "gdkwindow.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include "gdkasync.h"
#include <math.h>

View File

@ -23,6 +23,7 @@
#include "gdkintl.h"
#include "gdkasync.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include <stdlib.h>
#include <X11/Xlib.h>

View File

@ -26,6 +26,7 @@
#include "gdkdisplayprivate.h"
#include "gdkeventtranslator.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include "gdkkeysyms.h"

View File

@ -24,6 +24,7 @@
#endif
#include "gdkinternals.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
/* Defines for VCP/VCK, to be used too
* for the core protocol device manager

View File

@ -27,6 +27,7 @@
#include "gdkdisplayprivate.h"
#include "gdkeventtranslator.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include "gdkintl.h"
#include "gdkkeysyms.h"
#include "gdkinternals.h"

View File

@ -1197,11 +1197,10 @@ server_time_to_monotonic_time (GdkX11Display *display_x11,
}
GdkFilterReturn
_gdk_wm_protocols_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
_gdk_wm_protocols_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)xev;
GdkWindow *win = event->any.window;
GdkDisplay *display;
Atom atom;

View File

@ -29,6 +29,7 @@
#include "gdkx11devicemanager.h"
#include "gdkx11display.h"
#include "gdkx11screen.h"
#include "gdkprivate-x11.h"
#include <X11/X.h>
#include <X11/Xlib.h>
@ -180,9 +181,9 @@ gsize gdk_x11_display_get_max_request_size (GdkDisplay
gboolean gdk_x11_display_request_selection_notification (GdkDisplay *display,
const char *selection);
GdkFilterReturn _gdk_wm_protocols_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
GdkFilterReturn _gdk_wm_protocols_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
G_END_DECLS

View File

@ -170,24 +170,24 @@ static GrabKey grab_keys[] = {
static GdkWindowCache *gdk_window_cache_ref (GdkWindowCache *cache);
static void gdk_window_cache_unref (GdkWindowCache *cache);
static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_enter_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_leave_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_position_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_status_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_finished_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn xdnd_drop_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
static void xdnd_manage_source_filter (GdkDragContext *context,
GdkWindow *window,
@ -1059,12 +1059,11 @@ xdnd_action_to_atom (GdkDisplay *display,
/* Source side */
static GdkFilterReturn
xdnd_status_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_status_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
GdkDisplay *display;
XEvent *xevent = (XEvent *)xev;
guint32 dest_window = xevent->xclient.data.l[0];
guint32 flags = xevent->xclient.data.l[1];
Atom action = xevent->xclient.data.l[4];
@ -1107,12 +1106,11 @@ xdnd_status_filter (GdkXEvent *xev,
}
static GdkFilterReturn
xdnd_finished_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_finished_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
GdkDisplay *display;
XEvent *xevent = (XEvent *)xev;
guint32 dest_window = xevent->xclient.data.l[0];
GdkDragContext *context;
GdkX11DragContext *context_x11;
@ -1620,11 +1618,10 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
* and add this filter.
*/
GdkFilterReturn
xdnd_source_window_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_source_window_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)xev;
GdkX11DragContext *context_x11;
GdkDisplay *display;
@ -1729,13 +1726,12 @@ xdnd_precache_atoms (GdkDisplay *display)
}
static GdkFilterReturn
xdnd_enter_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer cb_data)
xdnd_enter_filter (const XEvent *xevent,
GdkEvent *event,
gpointer cb_data)
{
GdkDisplay *display;
GdkX11Display *display_x11;
XEvent *xevent = (XEvent *)xev;
GdkDragContext *context;
GdkX11DragContext *context_x11;
GdkSeat *seat;
@ -1859,11 +1855,10 @@ xdnd_enter_filter (GdkXEvent *xev,
}
static GdkFilterReturn
xdnd_leave_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_leave_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)xev;
guint32 source_window = xevent->xclient.data.l[0];
GdkDisplay *display;
GdkX11Display *display_x11;
@ -1899,12 +1894,11 @@ xdnd_leave_filter (GdkXEvent *xev,
}
static GdkFilterReturn
xdnd_position_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_position_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
GdkWindowImplX11 *impl;
XEvent *xevent = (XEvent *)xev;
guint32 source_window = xevent->xclient.data.l[0];
gint16 x_root = xevent->xclient.data.l[2] >> 16;
gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
@ -1963,11 +1957,10 @@ xdnd_position_filter (GdkXEvent *xev,
}
static GdkFilterReturn
xdnd_drop_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
xdnd_drop_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)xev;
guint32 source_window = xevent->xclient.data.l[0];
guint32 time = xevent->xclient.data.l[2];
GdkDisplay *display;
@ -2014,11 +2007,10 @@ xdnd_drop_filter (GdkXEvent *xev,
}
GdkFilterReturn
_gdk_x11_dnd_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data)
_gdk_x11_dnd_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *) xev;
GdkDisplay *display;
int i;
@ -2035,7 +2027,7 @@ _gdk_x11_dnd_filter (GdkXEvent *xev,
if (xevent->xclient.message_type != gdk_x11_get_xatom_by_name_for_display (display, xdnd_filters[i].atom_name))
continue;
return xdnd_filters[i].func (xev, event, data);
return xdnd_filters[i].func (xevent, event, data);
}
return GDK_FILTER_CONTINUE;

View File

@ -22,6 +22,7 @@
#include "gdkinternals.h"
#include "gdkwindow-x11.h"
#include "gdkprivate-x11.h"
#include "gdkdisplay-x11.h"
#include "xsettings-client.h"
@ -54,47 +55,6 @@ static GSourceFuncs event_funcs = {
gdk_event_source_finalize
};
static gint
gdk_event_apply_filters (const XEvent *xevent,
GdkEvent *event,
GdkWindow *window)
{
GList *tmp_list;
GdkFilterReturn result;
if (window == NULL)
tmp_list = _gdk_default_filters;
else
tmp_list = window->filters;
while (tmp_list)
{
GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
GList *node;
if ((filter->flags & GDK_EVENT_FILTER_REMOVED) != 0)
{
tmp_list = tmp_list->next;
continue;
}
filter->ref_count++;
result = filter->function ((GdkXEvent *) xevent, event, filter->data);
/* Protect against unreffing the filter mutating the list */
node = tmp_list->next;
_gdk_event_filter_unref (window, filter);
tmp_list = node;
if (result != GDK_FILTER_CONTINUE)
return result;
}
return GDK_FILTER_CONTINUE;
}
static GdkWindow *
gdk_event_source_get_filter_window (GdkEventSource *event_source,
const XEvent *xevent,
@ -307,31 +267,16 @@ gdk_event_source_translate_event (GdkX11Display *x11_display,
if (result == GDK_FILTER_CONTINUE &&
xevent->xany.window == XRootWindow (dpy, 0))
result = _gdk_wm_protocols_filter ((GdkXEvent *)xevent, event, NULL);
result = _gdk_wm_protocols_filter (xevent, event, NULL);
if (result == GDK_FILTER_CONTINUE &&
xevent->xany.window == XRootWindow (dpy, 0))
result = _gdk_x11_dnd_filter ((GdkXEvent *)xevent, event, NULL);
/* Run default filters */
if (result == GDK_FILTER_CONTINUE &&
_gdk_default_filters)
{
/* Apply global filters */
result = gdk_event_apply_filters (xevent, event, NULL);
}
result = _gdk_x11_dnd_filter (xevent, event, NULL);
if (result == GDK_FILTER_CONTINUE && filter_window)
{
gpointer context = g_object_get_data (G_OBJECT (filter_window), "xdnd-source-context");
result = xdnd_source_window_filter ((GdkXEvent *)xevent, event, context);
}
if (result == GDK_FILTER_CONTINUE &&
filter_window && filter_window->filters)
{
/* Apply per-window filters */
result = gdk_event_apply_filters (xevent, event, filter_window);
result = xdnd_source_window_filter (xevent, event, context);
}
if (result != GDK_FILTER_CONTINUE)

View File

@ -34,7 +34,6 @@
#include "gdkx.h"
#include "gdkwindow-x11.h"
#include "gdkscreen-x11.h"
#include "gdkdisplay-x11.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@ -44,6 +43,17 @@
#include <cairo-xlib.h>
typedef enum {
GDK_FILTER_CONTINUE,
GDK_FILTER_TRANSLATE,
GDK_FILTER_REMOVE
} GdkFilterReturn;
typedef GdkFilterReturn (*GdkFilterFunc) (const XEvent *xevent,
GdkEvent *event,
gpointer data);
void _gdk_x11_error_handler_push (void);
void _gdk_x11_error_handler_pop (void);
@ -202,14 +212,14 @@ Atom _gdk_x11_get_xatom_for_display_printf (GdkDisplay *display,
...) G_GNUC_PRINTF (2, 3);
GdkFilterReturn
_gdk_x11_dnd_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
_gdk_x11_dnd_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
GdkFilterReturn
xdnd_source_window_filter (GdkXEvent *xev,
GdkEvent *event,
gpointer data);
xdnd_source_window_filter (const XEvent *xevent,
GdkEvent *event,
gpointer data);
typedef struct _GdkWindowCache GdkWindowCache;

View File

@ -30,6 +30,7 @@
#include <gdk/x11/gdkx11screen.h>
#include <gdk/x11/gdkx11window.h>
#include <gdk/x11/gdkprivate-x11.h>
#include <gdk/x11/gdkdisplay-x11.h>
#include <gdk/x11/gdkscreen-x11.h>
#include <gdkinternals.h>

View File

@ -23,6 +23,7 @@
#ifndef XSETTINGS_CLIENT_H
#define XSETTINGS_CLIENT_H
#include <gdk/x11/gdkprivate-x11.h>
#include <gdk/x11/gdkx11screen.h>
void _gdk_x11_xsettings_init (GdkX11Screen *x11_screen);