~ubuntu-branches/ubuntu/wily/freerdp/wily-proposed

« back to all changes in this revision

Viewing changes to X11/xf_event.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, Jeremy Bicha, Jean-Louis Dupond, Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120131100214-jaok3uwvni7sqxth
Tags: 1.0.0-0git1
Upload current Debian packaging git to get this rolling for precise.

[ Jeremy Bicha ]
* New upstream release. Closes: #647498.
* Updated symbols and bumped soname
* debian/control:
  - Added new build dependencies
  - Bump Standards-Version to 3.9.2
* debian/source/format: Set to 3.0 (quilt)
* debian/rules: Turn on strict symbols checking
* debian/watch: Watch github

[ Jean-Louis Dupond ]
* debian/control: Updated homepage
* debian/copyright: Reflect upstream switch to the Apache license

[ Martin Pitt ]
* debian/libfreerdp0.symbols: Fix version number, should
  be 1.0~beta5, not 1.0-beta5.
* debian/control: Add libavcodec-dev build dependency, upstream build system
  checks for that. Thanks Jean-Louis Dupond!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include <X11/Xlib.h>
3
 
#include <X11/Xutil.h>
4
 
#include <stdio.h>
5
 
#include <stdlib.h>
6
 
#include <string.h>
7
 
#include <freerdp/freerdp.h>
8
 
#include "xf_types.h"
9
 
#include "xf_event.h"
10
 
#include "xf_keyboard.h"
11
 
 
12
 
static int
13
 
xf_handle_event_Expose(xfInfo * xfi, XEvent * xevent)
14
 
{
15
 
        int x;
16
 
        int y;
17
 
        int cx;
18
 
        int cy;
19
 
 
20
 
        if (xevent->xexpose.window == xfi->wnd)
21
 
        {
22
 
                x = xevent->xexpose.x;
23
 
                y = xevent->xexpose.y;
24
 
                cx = xevent->xexpose.width;
25
 
                cy = xevent->xexpose.height;
26
 
                XCopyArea(xfi->display, xfi->backstore, xfi->wnd, xfi->gc_default,
27
 
                        x, y, cx, cy, x, y);
28
 
        }
29
 
        return 0;
30
 
}
31
 
 
32
 
static int
33
 
xf_handle_event_VisibilityNotify(xfInfo * xfi, XEvent * xevent)
34
 
{
35
 
        if (xevent->xvisibility.window == xfi->wnd)
36
 
        {
37
 
                xfi->unobscured = xevent->xvisibility.state == VisibilityUnobscured;
38
 
        }
39
 
        return 0;
40
 
}
41
 
 
42
 
static int
43
 
xf_handle_event_MotionNotify(xfInfo * xfi, XEvent * xevent)
44
 
{
45
 
        int x;
46
 
        int y;
47
 
 
48
 
        if (xevent->xmotion.window == xfi->wnd)
49
 
        {
50
 
                x = xevent->xmotion.x;
51
 
                y = xevent->xmotion.y;
52
 
                xfi->inst->rdp_send_input(xfi->inst, RDP_INPUT_MOUSE, PTRFLAGS_MOVE, x, y);
53
 
        }
54
 
 
55
 
        if (xfi->fullscreen)
56
 
                XSetInputFocus(xfi->display, xfi->wnd, RevertToPointerRoot, CurrentTime);
57
 
 
58
 
        return 0;
59
 
}
60
 
 
61
 
static int
62
 
xf_handle_event_ButtonPress(xfInfo * xfi, XEvent * xevent)
63
 
{
64
 
        int device_flags;
65
 
        int param1;
66
 
        int param2;
67
 
 
68
 
        if (xevent->xbutton.window == xfi->wnd)
69
 
        {
70
 
                device_flags = 0;
71
 
                param1 = 0;
72
 
                param2 = 0;
73
 
                switch (xevent->xbutton.button)
74
 
                {
75
 
                        case 1:
76
 
                                device_flags = PTRFLAGS_DOWN | PTRFLAGS_BUTTON1;
77
 
                                param1 = xevent->xbutton.x;
78
 
                                param2 = xevent->xbutton.y;
79
 
                                break;
80
 
                        case 2:
81
 
                                device_flags = PTRFLAGS_DOWN | PTRFLAGS_BUTTON3;
82
 
                                param1 = xevent->xbutton.x;
83
 
                                param2 = xevent->xbutton.y;
84
 
                                break;
85
 
                        case 3:
86
 
                                device_flags = PTRFLAGS_DOWN | PTRFLAGS_BUTTON2;
87
 
                                param1 = xevent->xbutton.x;
88
 
                                param2 = xevent->xbutton.y;
89
 
                                break;
90
 
                        case 4:
91
 
                                device_flags = PTRFLAGS_WHEEL | 0x0078;
92
 
                                break;
93
 
                        case 5:
94
 
                                device_flags = PTRFLAGS_WHEEL | PTRFLAGS_WHEEL_NEGATIVE | 0x0088;
95
 
                                break;
96
 
                }
97
 
                if (device_flags != 0)
98
 
                {
99
 
                        xfi->inst->rdp_send_input(xfi->inst, RDP_INPUT_MOUSE, device_flags,
100
 
                                param1, param2);
101
 
                }
102
 
        }
103
 
        return 0;
104
 
}
105
 
 
106
 
static int
107
 
xf_handle_event_ButtonRelease(xfInfo * xfi, XEvent * xevent)
108
 
{
109
 
        int device_flags;
110
 
        int param1;
111
 
        int param2;
112
 
 
113
 
        if (xevent->xbutton.window == xfi->wnd)
114
 
        {
115
 
                device_flags = 0;
116
 
                param1 = 0;
117
 
                param2 = 0;
118
 
                switch (xevent->xbutton.button)
119
 
                {
120
 
                        case 1:
121
 
                                device_flags = PTRFLAGS_BUTTON1;
122
 
                                param1 = xevent->xbutton.x;
123
 
                                param2 = xevent->xbutton.y;
124
 
                                break;
125
 
                        case 2:
126
 
                                device_flags = PTRFLAGS_BUTTON3;
127
 
                                param1 = xevent->xbutton.x;
128
 
                                param2 = xevent->xbutton.y;
129
 
                                break;
130
 
                        case 3:
131
 
                                device_flags = PTRFLAGS_BUTTON2;
132
 
                                param1 = xevent->xbutton.x;
133
 
                                param2 = xevent->xbutton.y;
134
 
                                break;
135
 
                }
136
 
                if (device_flags != 0)
137
 
                {
138
 
                        xfi->inst->rdp_send_input(xfi->inst, RDP_INPUT_MOUSE, device_flags,
139
 
                                param1, param2);
140
 
                }
141
 
        }
142
 
        return 0;
143
 
}
144
 
 
145
 
static int
146
 
xf_handle_event_KeyPress(xfInfo * xfi, XEvent * xevent)
147
 
{
148
 
        KeySym keysym;
149
 
        char str[256];
150
 
 
151
 
        XLookupString((XKeyEvent *) xevent, str, sizeof(str), &keysym, NULL);
152
 
 
153
 
        xf_kb_set_keypress(xevent->xkey.keycode, keysym);
154
 
        if (xfi->fs_toggle && xf_kb_handle_special_keys(xfi, keysym))
155
 
                return 0;
156
 
 
157
 
        xf_kb_send_key(xfi, RDP_KEYPRESS, xevent->xkey.keycode);
158
 
        return 0;
159
 
}
160
 
 
161
 
static RD_BOOL
162
 
xf_skip_key_release(xfInfo * xfi, XEvent * xevent)
163
 
{
164
 
        XEvent next_event;
165
 
 
166
 
        if (XPending(xfi->display))
167
 
        {
168
 
                memset(&next_event, 0, sizeof(next_event));
169
 
                XPeekEvent(xfi->display, &next_event);
170
 
                if (next_event.type == KeyPress)
171
 
                {
172
 
                        if (next_event.xkey.keycode == xevent->xkey.keycode)
173
 
                        {
174
 
                                return True;
175
 
                        }
176
 
                }
177
 
        }
178
 
        return False;
179
 
}
180
 
 
181
 
static int
182
 
xf_handle_event_KeyRelease(xfInfo * xfi, XEvent * xevent)
183
 
{
184
 
        if (xf_skip_key_release(xfi, xevent))
185
 
        {
186
 
                return 0;
187
 
        }
188
 
        xf_kb_unset_keypress(xevent->xkey.keycode);
189
 
        xf_kb_send_key(xfi, RDP_KEYRELEASE, xevent->xkey.keycode);
190
 
        return 0;
191
 
}
192
 
 
193
 
static int
194
 
xf_handle_event_FocusIn(xfInfo * xfi, XEvent * xevent)
195
 
{
196
 
        if (xevent->xfocus.mode == NotifyGrab)
197
 
                return 0;
198
 
 
199
 
        xfi->focused = True;
200
 
        if (xfi->mouse_into)
201
 
                XGrabKeyboard(xfi->display, xfi->wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime);
202
 
 
203
 
        xf_kb_focus_in(xfi);
204
 
        return 0;
205
 
}
206
 
 
207
 
static int
208
 
xf_handle_event_FocusOut(xfInfo * xfi, XEvent * xevent)
209
 
{
210
 
        if (xevent->xfocus.mode == NotifyUngrab)
211
 
                return 0;
212
 
 
213
 
        xfi->focused = False;
214
 
        if (xevent->xfocus.mode == NotifyWhileGrabbed)
215
 
                XUngrabKeyboard(xfi->display, CurrentTime);
216
 
 
217
 
        return 0;
218
 
}
219
 
 
220
 
static int
221
 
xf_handle_event_MappingNotify(xfInfo * xfi, XEvent * xevent)
222
 
{
223
 
        if (xevent->xmapping.request == MappingModifier)
224
 
        {
225
 
                XFreeModifiermap(xfi->mod_map);
226
 
                xfi->mod_map = XGetModifierMapping(xfi->display);
227
 
        }
228
 
        return 0;
229
 
}
230
 
 
231
 
static int
232
 
xf_handle_event_ClientMessage(xfInfo * xfi, XEvent * xevent)
233
 
{
234
 
        Atom protocol_atom = XInternAtom(xfi->display, "WM_PROTOCOLS", True);
235
 
        Atom kill_atom = XInternAtom(xfi->display, "WM_DELETE_WINDOW", True);
236
 
 
237
 
        if ((xevent->xclient.message_type == protocol_atom)
238
 
            && ((Atom) xevent->xclient.data.l[0] == kill_atom))
239
 
        {
240
 
                printf("xf_handle_event: ClientMessage user quit received\n");
241
 
                return 1;
242
 
        }
243
 
 
244
 
        return 0;
245
 
}
246
 
 
247
 
static int
248
 
xf_handle_event_EnterNotify(xfInfo * xfi, XEvent * xevent)
249
 
{
250
 
        xfi->mouse_into = True;
251
 
 
252
 
        if (xfi->fullscreen)
253
 
                XSetInputFocus(xfi->display, xfi->wnd, RevertToPointerRoot, CurrentTime);
254
 
 
255
 
        if (xfi->focused)
256
 
                XGrabKeyboard(xfi->display, xfi->wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime);
257
 
 
258
 
        return 0;
259
 
}
260
 
 
261
 
static int
262
 
xf_handle_event_LeaveNotify(xfInfo * xfi, XEvent * xevent)
263
 
{
264
 
        xfi->mouse_into = False;
265
 
        XUngrabKeyboard(xfi->display, CurrentTime);
266
 
        return 0;
267
 
}
268
 
 
269
 
int
270
 
xf_handle_event(xfInfo * xfi, XEvent * xevent)
271
 
{
272
 
        int rv;
273
 
 
274
 
        rv = 0;
275
 
        switch (xevent->type)
276
 
        {
277
 
                case Expose:
278
 
                        rv = xf_handle_event_Expose(xfi, xevent);
279
 
                        break;
280
 
                case VisibilityNotify:
281
 
                        rv = xf_handle_event_VisibilityNotify(xfi, xevent);
282
 
                        break;
283
 
                case MotionNotify:
284
 
                        rv = xf_handle_event_MotionNotify(xfi, xevent);
285
 
                        break;
286
 
                case ButtonPress:
287
 
                        rv = xf_handle_event_ButtonPress(xfi, xevent);
288
 
                        break;
289
 
                case ButtonRelease:
290
 
                        rv = xf_handle_event_ButtonRelease(xfi, xevent);
291
 
                        break;
292
 
                case KeyPress:
293
 
                        rv = xf_handle_event_KeyPress(xfi, xevent);
294
 
                        break;
295
 
                case KeyRelease:
296
 
                        rv = xf_handle_event_KeyRelease(xfi, xevent);
297
 
                        break;
298
 
                case FocusIn:
299
 
                        rv = xf_handle_event_FocusIn(xfi, xevent);
300
 
                        break;
301
 
                case FocusOut:
302
 
                        rv = xf_handle_event_FocusOut(xfi, xevent);
303
 
                        break;
304
 
                case EnterNotify:
305
 
                        rv = xf_handle_event_EnterNotify(xfi, xevent);
306
 
                        break;
307
 
                case LeaveNotify:
308
 
                        rv = xf_handle_event_LeaveNotify(xfi, xevent);
309
 
                        break;
310
 
                case NoExpose:
311
 
                        DEBUG("xf_handle_event: NoExpose\n");
312
 
                        break;
313
 
                case GraphicsExpose:
314
 
                        DEBUG("xf_handle_event: GraphicsExpose\n");
315
 
                        break;
316
 
                case ConfigureNotify:
317
 
                        DEBUG("xf_handle_event: ConfigureNotify\n");
318
 
                        break;
319
 
                case MapNotify:
320
 
                        DEBUG("xf_handle_event: MapNotify\n");
321
 
                        break;
322
 
                case ReparentNotify:
323
 
                        DEBUG("xf_handle_event: ReparentNotify\n");
324
 
                        break;
325
 
                case MappingNotify:
326
 
                        rv = xf_handle_event_MappingNotify(xfi, xevent);
327
 
                        break;
328
 
                case ClientMessage:
329
 
                        /* the window manager told us to quit */
330
 
                        rv = xf_handle_event_ClientMessage(xfi, xevent);
331
 
                        break;
332
 
                default:
333
 
                        printf("xf_handle_event unknown event %d\n", xevent->type);
334
 
                        break;
335
 
        }
336
 
        return rv;
337
 
}