2
* Copyright (c) 2011 Red Hat, Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* Author: Cosimo Cecchi <cosimoc@redhat.com>
22
#include "gd-fullscreen-filter.h"
27
#include <X11/extensions/XInput2.h>
29
G_DEFINE_TYPE (GdFullscreenFilter, gd_fullscreen_filter, G_TYPE_OBJECT)
36
static guint signals[NUM_SIGNALS] = { 0, };
38
struct _GdFullscreenFilterPrivate {
39
gboolean is_filtering;
43
gd_fullscreen_filter_dispose (GObject *object)
45
GdFullscreenFilter *self = GD_FULLSCREEN_FILTER (object);
47
gd_fullscreen_filter_stop (self);
49
G_OBJECT_CLASS (gd_fullscreen_filter_parent_class)->dispose (object);
53
gd_fullscreen_filter_init (GdFullscreenFilter *self)
55
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_FULLSCREEN_FILTER,
56
GdFullscreenFilterPrivate);
60
gd_fullscreen_filter_class_init (GdFullscreenFilterClass *klass)
62
GObjectClass *oclass = G_OBJECT_CLASS (klass);
64
oclass->dispose = gd_fullscreen_filter_dispose;
66
signals[MOTION_EVENT] =
67
g_signal_new ("motion-event",
68
GD_TYPE_FULLSCREEN_FILTER,
73
g_type_class_add_private (klass, sizeof (GdFullscreenFilterPrivate));
76
static GdkFilterReturn
77
event_filter_func (GdkXEvent *gdk_xevent,
81
GdFullscreenFilter *self = user_data;
82
XEvent *xevent = (XEvent *) gdk_xevent;
84
if (xevent->xany.type == ButtonPress ||
85
xevent->xany.type == ButtonRelease ||
86
xevent->xany.type == MotionNotify)
88
g_signal_emit (self, signals[MOTION_EVENT], 0);
90
else if (xevent->xany.type == GenericEvent)
92
/* we just assume this is an XI2 event */
93
XIEvent *ev = (XIEvent *) xevent->xcookie.data;
95
if (ev->evtype == XI_Motion ||
96
ev->evtype == XI_ButtonRelease ||
97
ev->evtype == XI_ButtonPress)
99
g_signal_emit (self, signals[MOTION_EVENT], 0);
103
return GDK_FILTER_CONTINUE;
107
gd_fullscreen_filter_start (GdFullscreenFilter *self)
109
if (self->priv->is_filtering)
112
self->priv->is_filtering = TRUE;
113
gdk_window_add_filter (NULL,
114
event_filter_func, self);
118
gd_fullscreen_filter_stop (GdFullscreenFilter *self)
120
if (!self->priv->is_filtering)
123
self->priv->is_filtering = FALSE;
124
gdk_window_remove_filter (NULL,
125
event_filter_func, self);
129
gd_fullscreen_filter_new (void)
131
return g_object_new (GD_TYPE_FULLSCREEN_FILTER, NULL);