~muktupavels/metacity/adwaita-icon-theme-lp-1414613

« back to all changes in this revision

Viewing changes to src/eventqueue.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-10-03 22:44:28 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051003224428-ft31gkmz12qpzohj
Tags: 1:2.12.1-0ubuntu1
* New upstream release:
  - Thanks to Ray Strode, Havoc Pennington, and Elijah Newren for
    improvements in this release.
  - Truncate ridiculously long titles to avoid crashing or letting the
    pager crash (Ray, Havoc, Elijah) [#315070] (Ubuntu: #15995)
  - Get the tabbing window outline to work with gtk+ 2.8.4 again
    (Elijah) [#317528] (Ubuntu: #16589)
  - Translations: Mahay Alam Khan (bn), Francisco Javier F. Serrador (es), 
    Ivar Smolin (et), I\uffffaki Larra\uffffaga Murgoitio (eu), Luca 
    Ferretti (it), Christian Rose (sv), Clytie Siddall (vi), Funda 
    Wang (zh_CN)
* debian/control.in:
  - Bumped Standards-Version.
* debian/patches/003_bordersdrawingfix.patch:
  - dropped, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Metacity X event source for main loop */
 
2
 
 
3
/* 
 
4
 * Copyright (C) 2001 Havoc Pennington (based on GDK code (C) Owen
 
5
 * Taylor, Red Hat Inc.)
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU General Public License as
 
9
 * published by the Free Software Foundation; either version 2 of the
 
10
 * License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
 * 02111-1307, USA.  */
 
21
 
 
22
#include "eventqueue.h"
 
23
#include <X11/Xlib.h>
 
24
 
 
25
static gboolean eq_prepare  (GSource     *source,
 
26
                             gint        *timeout);
 
27
static gboolean eq_check    (GSource     *source);
 
28
static gboolean eq_dispatch (GSource     *source,
 
29
                             GSourceFunc  callback,
 
30
                             gpointer     user_data);
 
31
static void     eq_destroy  (GSource     *source);
 
32
 
 
33
static GSourceFuncs eq_funcs = {
 
34
  eq_prepare,
 
35
  eq_check,
 
36
  eq_dispatch,
 
37
  eq_destroy
 
38
};
 
39
 
 
40
struct _MetaEventQueue
 
41
{
 
42
  GSource source;
 
43
 
 
44
  Display *display;
 
45
  GPollFD poll_fd;
 
46
  int connection_fd;
 
47
  GQueue *events;
 
48
};
 
49
 
 
50
MetaEventQueue*
 
51
meta_event_queue_new (Display *display, MetaEventQueueFunc func, gpointer data)
 
52
{
 
53
  GSource *source;
 
54
  MetaEventQueue *eq;
 
55
 
 
56
  source = g_source_new (&eq_funcs, sizeof (MetaEventQueue));
 
57
  eq = (MetaEventQueue*) source;
 
58
  
 
59
  eq->connection_fd = ConnectionNumber (display);
 
60
  eq->poll_fd.fd = eq->connection_fd;
 
61
  eq->poll_fd.events = G_IO_IN;
 
62
 
 
63
  eq->events = g_queue_new ();
 
64
 
 
65
  eq->display = display;
 
66
  
 
67
  g_source_set_priority (source, G_PRIORITY_DEFAULT);
 
68
  g_source_add_poll (source, &eq->poll_fd);
 
69
  g_source_set_can_recurse (source, TRUE);
 
70
 
 
71
  g_source_set_callback (source, (GSourceFunc) func, data, NULL);
 
72
  
 
73
  g_source_attach (source, NULL);
 
74
  
 
75
  return eq;
 
76
}
 
77
 
 
78
void
 
79
meta_event_queue_free (MetaEventQueue *eq)
 
80
{
 
81
  GSource *source;
 
82
 
 
83
  source = (GSource*) eq;
 
84
  
 
85
  g_source_destroy (source);
 
86
}
 
87
 
 
88
static gboolean
 
89
eq_events_pending (MetaEventQueue *eq)
 
90
{
 
91
  return eq->events->length > 0 || XPending (eq->display);
 
92
}
 
93
 
 
94
static void
 
95
eq_queue_events (MetaEventQueue *eq)
 
96
{
 
97
  XEvent xevent;
 
98
 
 
99
  while (XPending (eq->display))
 
100
    {
 
101
      XEvent *copy;
 
102
      
 
103
      XNextEvent (eq->display, &xevent);
 
104
 
 
105
      copy = g_new (XEvent, 1);
 
106
      *copy = xevent;
 
107
 
 
108
      g_queue_push_tail (eq->events, copy);
 
109
    }
 
110
}
 
111
 
 
112
static gboolean  
 
113
eq_prepare (GSource *source, gint *timeout)
 
114
{
 
115
  MetaEventQueue *eq;
 
116
 
 
117
  eq = (MetaEventQueue*) source;
 
118
  
 
119
  *timeout = -1;
 
120
 
 
121
  return eq_events_pending (eq);
 
122
}
 
123
 
 
124
static gboolean  
 
125
eq_check (GSource  *source) 
 
126
{
 
127
  MetaEventQueue *eq;
 
128
 
 
129
  eq = (MetaEventQueue*) source;
 
130
 
 
131
  if (eq->poll_fd.revents & G_IO_IN)
 
132
    return eq_events_pending (eq);
 
133
  else
 
134
    return FALSE;
 
135
}
 
136
 
 
137
static gboolean  
 
138
eq_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
 
139
{
 
140
  MetaEventQueue *eq;
 
141
 
 
142
  eq = (MetaEventQueue*) source;
 
143
  
 
144
  eq_queue_events (eq);
 
145
 
 
146
  if (eq->events->length > 0)
 
147
    {
 
148
      XEvent *event;
 
149
      MetaEventQueueFunc func;
 
150
 
 
151
      event = g_queue_pop_head (eq->events);
 
152
      func = (MetaEventQueueFunc) callback;
 
153
      
 
154
      (* func) (event, user_data);
 
155
 
 
156
      g_free (event);
 
157
    }
 
158
  
 
159
  return TRUE;
 
160
}
 
161
 
 
162
static void
 
163
eq_destroy (GSource *source)
 
164
{
 
165
  MetaEventQueue *eq;
 
166
 
 
167
  eq = (MetaEventQueue*) source;
 
168
 
 
169
  while (eq->events->length > 0)
 
170
    {
 
171
      XEvent *event;
 
172
      
 
173
      event = g_queue_pop_head (eq->events);
 
174
 
 
175
      g_free (event);
 
176
    }
 
177
 
 
178
  g_queue_free (eq->events);
 
179
 
 
180
  /* source itself is freed by glib */
 
181
}