~noskcaj/ubuntu/trusty/gnome-documents/3.10.2

« back to all changes in this revision

Viewing changes to src/lib/gd-fullscreen-filter.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson, Thomas Bechtold
  • Date: 2013-04-04 13:32:08 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130404133208-n19gqczi05z31ogb
Tags: 3.8.0-1
[ Thomas Bechtold ]
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2011 Red Hat, Inc.
3
 
 *
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.
8
 
 *
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.
13
 
 *
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
17
 
 *
18
 
 * Author: Cosimo Cecchi <cosimoc@redhat.com>
19
 
 *
20
 
 */
21
 
 
22
 
#include "gd-fullscreen-filter.h"
23
 
 
24
 
#include <gdk/gdk.h>
25
 
#include <gdk/gdkx.h>
26
 
 
27
 
#include <X11/extensions/XInput2.h>
28
 
 
29
 
G_DEFINE_TYPE (GdFullscreenFilter, gd_fullscreen_filter, G_TYPE_OBJECT)
30
 
 
31
 
enum {
32
 
  MOTION_EVENT = 1,
33
 
  NUM_SIGNALS
34
 
};
35
 
 
36
 
static guint signals[NUM_SIGNALS] = { 0, };
37
 
 
38
 
struct _GdFullscreenFilterPrivate {
39
 
  gboolean is_filtering;
40
 
};
41
 
 
42
 
static void
43
 
gd_fullscreen_filter_dispose (GObject *object)
44
 
{
45
 
  GdFullscreenFilter *self = GD_FULLSCREEN_FILTER (object);
46
 
 
47
 
  gd_fullscreen_filter_stop (self);
48
 
 
49
 
  G_OBJECT_CLASS (gd_fullscreen_filter_parent_class)->dispose (object);
50
 
}
51
 
 
52
 
static void
53
 
gd_fullscreen_filter_init (GdFullscreenFilter *self)
54
 
{
55
 
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_FULLSCREEN_FILTER,
56
 
                                            GdFullscreenFilterPrivate);
57
 
}
58
 
 
59
 
static void
60
 
gd_fullscreen_filter_class_init (GdFullscreenFilterClass *klass)
61
 
{
62
 
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
63
 
 
64
 
  oclass->dispose = gd_fullscreen_filter_dispose;
65
 
 
66
 
  signals[MOTION_EVENT] =
67
 
    g_signal_new ("motion-event",
68
 
                  GD_TYPE_FULLSCREEN_FILTER,
69
 
                  G_SIGNAL_RUN_LAST,
70
 
                  0, NULL, NULL, NULL,
71
 
                  G_TYPE_NONE, 0);
72
 
 
73
 
  g_type_class_add_private (klass, sizeof (GdFullscreenFilterPrivate));
74
 
}
75
 
 
76
 
static GdkFilterReturn
77
 
event_filter_func (GdkXEvent *gdk_xevent,
78
 
                   GdkEvent *event,
79
 
                   gpointer user_data)
80
 
{
81
 
  GdFullscreenFilter *self = user_data;
82
 
  XEvent *xevent = (XEvent *) gdk_xevent;
83
 
 
84
 
  if (xevent->xany.type == ButtonPress ||
85
 
      xevent->xany.type == ButtonRelease ||
86
 
      xevent->xany.type == MotionNotify)
87
 
    {
88
 
      g_signal_emit (self, signals[MOTION_EVENT], 0);
89
 
    }
90
 
  else if (xevent->xany.type == GenericEvent)
91
 
    {
92
 
        /* we just assume this is an XI2 event */
93
 
        XIEvent *ev = (XIEvent *) xevent->xcookie.data;
94
 
 
95
 
        if (ev->evtype == XI_Motion ||
96
 
            ev->evtype == XI_ButtonRelease ||
97
 
            ev->evtype == XI_ButtonPress)
98
 
          {
99
 
            g_signal_emit (self, signals[MOTION_EVENT], 0);
100
 
          }
101
 
    }
102
 
 
103
 
  return GDK_FILTER_CONTINUE;
104
 
}
105
 
 
106
 
void
107
 
gd_fullscreen_filter_start (GdFullscreenFilter *self)
108
 
{
109
 
  if (self->priv->is_filtering)
110
 
    return;
111
 
 
112
 
  self->priv->is_filtering = TRUE;
113
 
  gdk_window_add_filter (NULL,
114
 
                         event_filter_func, self);
115
 
}
116
 
 
117
 
void
118
 
gd_fullscreen_filter_stop (GdFullscreenFilter *self)
119
 
{
120
 
  if (!self->priv->is_filtering)
121
 
    return;
122
 
 
123
 
  self->priv->is_filtering = FALSE;
124
 
  gdk_window_remove_filter (NULL,
125
 
                            event_filter_func, self);
126
 
}
127
 
 
128
 
GdFullscreenFilter *
129
 
gd_fullscreen_filter_new (void)
130
 
{
131
 
  return g_object_new (GD_TYPE_FULLSCREEN_FILTER, NULL);
132
 
}