forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.c
More file actions
487 lines (444 loc) · 15 KB
/
Copy pathevent.c
File metadata and controls
487 lines (444 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
* event.c - event handlers
*
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xrandr.h>
#include "screen.h"
#include "event.h"
#include "tag.h"
#include "statusbar.h"
#include "window.h"
#include "mouse.h"
#include "ewmh.h"
#include "client.h"
#include "widget.h"
#include "rules.h"
#include "titlebar.h"
#include "layouts/tile.h"
#include "layouts/floating.h"
#include "common/xscreen.h"
extern AwesomeConf globalconf;
/** Handle mouse button click
* \param screen screen number
* \param button button number
* \param state modkeys state
* \param buttons buttons list to check for
* \param arg optional arg passed to uicb, otherwise buttons' arg are used
*/
static void
event_handle_mouse_button_press(int screen, unsigned int button, unsigned int state,
Button *buttons, char *arg)
{
Button *b;
for(b = buttons; b; b = b->next)
if(button == b->button && CLEANMASK(state) == b->mod && b->func)
{
if(arg)
b->func(screen, arg);
else
b->func(screen, b->arg);
}
}
/** Handle XButtonPressed events
* \param e XEvent
*/
void
event_handle_buttonpress(XEvent *e)
{
int i, screen, x = 0, y = 0;
unsigned int udummy;
Client *c;
Window wdummy;
Widget *widget;
Statusbar *statusbar;
XButtonPressedEvent *ev = &e->xbutton;
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow)
{
switch(statusbar->position)
{
case Top:
case Bottom:
for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->x >= widget->area.x && ev->x < widget->area.x + widget->area.width
&& ev->y >= widget->area.y && ev->y < widget->area.y + widget->area.height)
{
widget->button_press(widget, ev);
return;
}
break;
case Right:
for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->y >= widget->area.x && ev->y < widget->area.x + widget->area.width
&& statusbar->sw->geometry.width - ev->x >= widget->area.y
&& statusbar->sw->geometry.width - ev->x
< widget->area.y + widget->area.height)
{
widget->button_press(widget, ev);
return;
}
break;
case Left:
for(widget = statusbar->widgets; widget; widget = widget->next)
if(statusbar->sw->geometry.height - ev->y >= widget->area.x
&& statusbar->sw->geometry.height - ev->y
< widget->area.x + widget->area.width
&& ev->x >= widget->area.y && ev->x < widget->area.y + widget->area.height)
{
widget->button_press(widget, ev);
return;
}
break;
default:
break;
}
/* return if no widget match */
return;
}
for(c = globalconf.clients; c; c = c->next)
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
{
if(!client_focus(c, c->screen, True))
client_stack(c);
if(CLEANMASK(ev->state) == NoSymbol
&& ev->button == Button1)
window_grabbuttons(c->win, c->phys_screen);
event_handle_mouse_button_press(c->screen, ev->button, ev->state,
globalconf.buttons.titlebar, NULL);
return;
}
if((c = client_get_bywin(globalconf.clients, ev->window)))
{
if(!client_focus(c, c->screen, True))
client_stack(c);
if(CLEANMASK(ev->state) == NoSymbol
&& ev->button == Button1)
{
XAllowEvents(globalconf.display, ReplayPointer, CurrentTime);
window_grabbuttons(c->win, c->phys_screen);
}
else
event_handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.client, NULL);
}
else
{
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(RootWindow(e->xany.display, screen) == ev->window
&& XQueryPointer(e->xany.display,
ev->window, &wdummy,
&wdummy, &x, &y, &i,
&i, &udummy))
{
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
event_handle_mouse_button_press(screen, ev->button, ev->state,
globalconf.buttons.root, NULL);
return;
}
}
}
/** Handle XConfigureRequest events
* \param e XEvent
*/
void
event_handle_configurerequest(XEvent * e)
{
Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc;
area_t geometry;
if((c = client_get_bywin(globalconf.clients, ev->window)))
{
geometry = c->geometry;
if(ev->value_mask & CWX)
geometry.x = ev->x;
if(ev->value_mask & CWY)
geometry.y = ev->y;
if(ev->value_mask & CWWidth)
geometry.width = ev->width;
if(ev->value_mask & CWHeight)
geometry.height = ev->height;
if(geometry.x != c->geometry.x || geometry.y != c->geometry.y
|| geometry.width != c->geometry.width || geometry.height != c->geometry.height)
{
if(c->isfloating || layout_get_current(c->screen)->arrange == layout_floating)
client_resize(c, geometry, False);
else
{
globalconf.screens[c->screen].need_arrange = True;
/* If we do not resize the client, at least tell it that it
* has its new configuration. That fixes at least
* gnome-terminal */
window_configure(c->win, c->geometry, c->border);
}
}
else
{
titlebar_update_geometry_floating(c);
window_configure(c->win, geometry, c->border);
}
}
else
{
wc.x = ev->x;
wc.y = ev->y;
wc.width = ev->width;
wc.height = ev->height;
wc.border_width = ev->border_width;
wc.sibling = ev->above;
wc.stack_mode = ev->detail;
XConfigureWindow(e->xany.display, ev->window, ev->value_mask, &wc);
}
}
/** Handle XConfigure events
* \param e XEvent
*/
void
event_handle_configurenotify(XEvent * e)
{
XConfigureEvent *ev = &e->xconfigure;
int screen;
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(ev->window == RootWindow(e->xany.display, screen)
&& (ev->width != DisplayWidth(e->xany.display, screen)
|| ev->height != DisplayHeight(e->xany.display, screen)))
/* it's not that we panic, but restart */
uicb_restart(0, NULL);
}
/** Handle XDestroyWindow events
* \param e XEvent
*/
void
event_handle_destroynotify(XEvent *e)
{
Client *c;
XDestroyWindowEvent *ev = &e->xdestroywindow;
if((c = client_get_bywin(globalconf.clients, ev->window)))
client_unmanage(c);
}
/** Handle XCrossing events on enter
* \param e XEvent
*/
void
event_handle_enternotify(XEvent *e)
{
Client *c;
XCrossingEvent *ev = &e->xcrossing;
int screen;
if(ev->mode != NotifyNormal
|| (ev->x_root == globalconf.pointer_x
&& ev->y_root == globalconf.pointer_y))
return;
for(c = globalconf.clients; c; c = c->next)
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
break;
if(c || (c = client_get_bywin(globalconf.clients, ev->window)))
{
window_grabbuttons(c->win, c->phys_screen);
/* the idea behind saving pointer_x and pointer_y is Bob Marley powered
* this will allow us top drop some EnterNotify events and thus not giving
* focus to windows appering under the cursor without a cursor move */
globalconf.pointer_x = ev->x_root;
globalconf.pointer_y = ev->y_root;
if(globalconf.screens[c->screen].sloppy_focus)
client_focus(c, c->screen,
globalconf.screens[c->screen].sloppy_focus_raise);
}
else
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(ev->window == RootWindow(e->xany.display, screen))
{
window_root_grabbuttons(screen);
return;
}
}
/** Handle XExpose events
* \param e XEvent
*/
void
event_handle_expose(XEvent *e)
{
XExposeEvent *ev = &e->xexpose;
int screen;
Statusbar *statusbar;
Client *c;
if(!ev->count)
{
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->sw->window == ev->window)
{
statusbar_display(statusbar);
return;
}
for(c = globalconf.clients; c; c = c->next)
if(c->titlebar.sw && c->titlebar.sw->window == ev->window)
{
simplewindow_refresh_drawable(c->titlebar.sw, c->phys_screen);
return;
}
}
}
/** Handle XKey events
* \param e XEvent
*/
void
event_handle_keypress(XEvent *e)
{
int screen, x, y, d;
unsigned int m;
XKeyEvent *ev = &e->xkey;
KeySym keysym;
Window dummy;
Key *k;
/* find the right screen for this event */
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), &dummy, &dummy, &x, &y, &d, &d, &m))
{
/* if screen is 0, we are on first Zaphod screen or on the
* only screen in Xinerama, so we can ask for a better screen
* number with screen_get_bycoord: we'll get 0 in Zaphod mode
* so it's the same, or maybe the real Xinerama screen */
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
break;
}
keysym = XkbKeycodeToKeysym(globalconf.display, (KeyCode) ev->keycode, 0, 0);
for(k = globalconf.keys; k; k = k->next)
if(((k->keycode && ev->keycode == k->keycode) || (k->keysym && keysym == k->keysym)) &&
k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state))
k->func(screen, k->arg);
}
/** Handle XMapping events
* \param e XEvent
*/
void
event_handle_mappingnotify(XEvent *e)
{
XMappingEvent *ev = &e->xmapping;
int screen;
XRefreshKeyboardMapping(ev);
if(ev->request == MappingKeyboard)
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
window_root_grabkeys(screen);
}
/** Handle XMapRequest events
* \param e XEvent
*/
void
event_handle_maprequest(XEvent *e)
{
static XWindowAttributes wa;
XMapRequestEvent *ev = &e->xmaprequest;
int screen = 0, x, y, d;
unsigned int m;
Window dummy;
if(!XGetWindowAttributes(e->xany.display, ev->window, &wa))
return;
if(wa.override_redirect)
return;
if(!client_get_bywin(globalconf.clients, ev->window))
{
if(globalconf.screens_info->xinerama_is_active
&& XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen),
&dummy, &dummy, &x, &y, &d, &d, &m))
screen = screen_get_bycoord(globalconf.screens_info, screen, x, y);
else
for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++);
client_manage(ev->window, &wa, screen);
}
}
/** Handle XProperty events
* \param e XEvent
*/
void
event_handle_propertynotify(XEvent * e)
{
Client *c;
Window trans;
XPropertyEvent *ev = &e->xproperty;
if(ev->state == PropertyDelete)
return; /* ignore */
if((c = client_get_bywin(globalconf.clients, ev->window)))
{
switch (ev->atom)
{
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(e->xany.display, c->win, &trans);
if(!c->isfloating
&& (c->isfloating = (client_get_bywin(globalconf.clients, trans) != NULL)))
globalconf.screens[c->screen].need_arrange = True;
break;
case XA_WM_NORMAL_HINTS:
client_updatesizehints(c);
break;
case XA_WM_HINTS:
client_updatewmhints(c);
break;
}
if(ev->atom == XA_WM_NAME || ev->atom == XInternAtom(globalconf.display, "_NET_WM_NAME", False))
client_updatetitle(c);
}
}
/** Handle XUnmap events
* \param e XEvent
*/
void
event_handle_unmapnotify(XEvent * e)
{
Client *c;
XUnmapEvent *ev = &e->xunmap;
if((c = client_get_bywin(globalconf.clients, ev->window))
&& ev->event == RootWindow(e->xany.display, c->phys_screen)
&& ev->send_event && window_getstate(c->win) == NormalState)
client_unmanage(c);
}
/** Handle XShape events
* \param e XEvent
*/
void
event_handle_shape(XEvent * e)
{
XShapeEvent *ev = (XShapeEvent *) e;
Client *c = client_get_bywin(globalconf.clients, ev->window);
if(c)
window_setshape(c->win, c->phys_screen);
}
/** Handle XRandR events
* \param e XEvent
*/
void
event_handle_randr_screen_change_notify(XEvent *e)
{
XRRUpdateConfiguration(e);
uicb_restart(0, NULL);
}
/** Handle XClientMessage events
* \param e XEvent
*/
void
event_handle_clientmessage(XEvent *e)
{
ewmh_process_client_message(&e->xclient);
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80