]> Dogcows Code - chaz/openbox/blob - openbox/event.c
make fullscreen windows more xinerama and multi-screen aware
[chaz/openbox] / openbox / event.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "event.h"
21 #include "debug.h"
22 #include "window.h"
23 #include "openbox.h"
24 #include "dock.h"
25 #include "actions.h"
26 #include "client.h"
27 #include "xerror.h"
28 #include "prop.h"
29 #include "config.h"
30 #include "screen.h"
31 #include "frame.h"
32 #include "grab.h"
33 #include "menu.h"
34 #include "menuframe.h"
35 #include "keyboard.h"
36 #include "modkeys.h"
37 #include "mouse.h"
38 #include "mainloop.h"
39 #include "focus.h"
40 #include "focus_cycle.h"
41 #include "moveresize.h"
42 #include "group.h"
43 #include "stacking.h"
44 #include "extensions.h"
45 #include "translate.h"
46 #include "ping.h"
47
48 #include <X11/Xlib.h>
49 #include <X11/Xatom.h>
50 #include <glib.h>
51
52 #ifdef HAVE_SYS_SELECT_H
53 # include <sys/select.h>
54 #endif
55 #ifdef HAVE_SIGNAL_H
56 # include <signal.h>
57 #endif
58 #ifdef HAVE_UNISTD_H
59 # include <unistd.h> /* for usleep() */
60 #endif
61 #ifdef XKB
62 # include <X11/XKBlib.h>
63 #endif
64
65 #ifdef USE_SM
66 #include <X11/ICE/ICElib.h>
67 #endif
68
69 typedef struct
70 {
71 gboolean ignored;
72 } ObEventData;
73
74 typedef struct
75 {
76 ObClient *client;
77 Time time;
78 gulong serial;
79 } ObFocusDelayData;
80
81 typedef struct
82 {
83 gulong start; /* inclusive */
84 gulong end; /* inclusive */
85 } ObSerialRange;
86
87 static void event_process(const XEvent *e, gpointer data);
88 static void event_handle_root(XEvent *e);
89 static gboolean event_handle_menu_keyboard(XEvent *e);
90 static gboolean event_handle_menu(XEvent *e);
91 static void event_handle_dock(ObDock *s, XEvent *e);
92 static void event_handle_dockapp(ObDockApp *app, XEvent *e);
93 static void event_handle_client(ObClient *c, XEvent *e);
94 static void event_handle_user_input(ObClient *client, XEvent *e);
95 static gboolean is_enter_focus_event_ignored(XEvent *e);
96 static void event_ignore_enter_range(gulong start, gulong end);
97
98 static void focus_delay_dest(gpointer data);
99 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
100 static gboolean focus_delay_func(gpointer data);
101 static void focus_delay_client_dest(ObClient *client, gpointer data);
102
103 Time event_curtime = CurrentTime;
104 Time event_last_user_time = CurrentTime;
105 /*! The serial of the current X event */
106
107 static gulong event_curserial;
108 static gboolean focus_left_screen = FALSE;
109 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
110 static GSList *ignore_serials = NULL;
111
112 #ifdef USE_SM
113 static void ice_handler(gint fd, gpointer conn)
114 {
115 Bool b;
116 IceProcessMessages(conn, NULL, &b);
117 }
118
119 static void ice_watch(IceConn conn, IcePointer data, Bool opening,
120 IcePointer *watch_data)
121 {
122 static gint fd = -1;
123
124 if (opening) {
125 fd = IceConnectionNumber(conn);
126 ob_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL);
127 } else {
128 ob_main_loop_fd_remove(ob_main_loop, fd);
129 fd = -1;
130 }
131 }
132 #endif
133
134 void event_startup(gboolean reconfig)
135 {
136 if (reconfig) return;
137
138 ob_main_loop_x_add(ob_main_loop, event_process, NULL, NULL);
139
140 #ifdef USE_SM
141 IceAddConnectionWatch(ice_watch, NULL);
142 #endif
143
144 client_add_destroy_notify(focus_delay_client_dest, NULL);
145 }
146
147 void event_shutdown(gboolean reconfig)
148 {
149 if (reconfig) return;
150
151 #ifdef USE_SM
152 IceRemoveConnectionWatch(ice_watch, NULL);
153 #endif
154
155 client_remove_destroy_notify(focus_delay_client_dest);
156 }
157
158 static Window event_get_window(XEvent *e)
159 {
160 Window window;
161
162 /* pick a window */
163 switch (e->type) {
164 case SelectionClear:
165 window = RootWindow(ob_display, ob_screen);
166 break;
167 case MapRequest:
168 window = e->xmap.window;
169 break;
170 case UnmapNotify:
171 window = e->xunmap.window;
172 break;
173 case DestroyNotify:
174 window = e->xdestroywindow.window;
175 break;
176 case ConfigureRequest:
177 window = e->xconfigurerequest.window;
178 break;
179 case ConfigureNotify:
180 window = e->xconfigure.window;
181 break;
182 default:
183 #ifdef XKB
184 if (extensions_xkb && e->type == extensions_xkb_event_basep) {
185 switch (((XkbAnyEvent*)e)->xkb_type) {
186 case XkbBellNotify:
187 window = ((XkbBellNotifyEvent*)e)->window;
188 default:
189 window = None;
190 }
191 } else
192 #endif
193 #ifdef SYNC
194 if (extensions_sync &&
195 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
196 {
197 window = None;
198 } else
199 #endif
200 window = e->xany.window;
201 }
202 return window;
203 }
204
205 static void event_set_curtime(XEvent *e)
206 {
207 Time t = CurrentTime;
208
209 /* grab the lasttime and hack up the state */
210 switch (e->type) {
211 case ButtonPress:
212 case ButtonRelease:
213 t = e->xbutton.time;
214 break;
215 case KeyPress:
216 t = e->xkey.time;
217 break;
218 case KeyRelease:
219 t = e->xkey.time;
220 break;
221 case MotionNotify:
222 t = e->xmotion.time;
223 break;
224 case PropertyNotify:
225 t = e->xproperty.time;
226 break;
227 case EnterNotify:
228 case LeaveNotify:
229 t = e->xcrossing.time;
230 break;
231 default:
232 #ifdef SYNC
233 if (extensions_sync &&
234 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
235 {
236 t = ((XSyncAlarmNotifyEvent*)e)->time;
237 }
238 #endif
239 /* if more event types are anticipated, get their timestamp
240 explicitly */
241 break;
242 }
243
244 /* watch that if we get an event earlier than the last specified user_time,
245 which can happen if the clock goes backwards, we erase the last
246 specified user_time */
247 if (t && event_last_user_time && event_time_after(event_last_user_time, t))
248 event_last_user_time = CurrentTime;
249
250 event_curtime = t;
251 }
252
253 static void event_hack_mods(XEvent *e)
254 {
255 #ifdef XKB
256 XkbStateRec xkb_state;
257 #endif
258
259 switch (e->type) {
260 case ButtonPress:
261 case ButtonRelease:
262 e->xbutton.state = modkeys_only_modifier_masks(e->xbutton.state);
263 break;
264 case KeyPress:
265 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
266 break;
267 case KeyRelease:
268 #ifdef XKB
269 /* If XKB is present, then the modifiers are all strange from its
270 magic. Our X core protocol stuff won't work, so we use this to
271 find what the modifier state is instead. */
272 if (XkbGetState(ob_display, XkbUseCoreKbd, &xkb_state) == Success)
273 e->xkey.state =
274 modkeys_only_modifier_masks(xkb_state.compat_state);
275 else
276 #endif
277 {
278 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
279 /* remove from the state the mask of the modifier key being
280 released, if it is a modifier key being released that is */
281 e->xkey.state &= ~modkeys_keycode_to_mask(e->xkey.keycode);
282 }
283 break;
284 case MotionNotify:
285 e->xmotion.state = modkeys_only_modifier_masks(e->xmotion.state);
286 /* compress events */
287 {
288 XEvent ce;
289 while (XCheckTypedWindowEvent(ob_display, e->xmotion.window,
290 e->type, &ce)) {
291 e->xmotion.x = ce.xmotion.x;
292 e->xmotion.y = ce.xmotion.y;
293 e->xmotion.x_root = ce.xmotion.x_root;
294 e->xmotion.y_root = ce.xmotion.y_root;
295 }
296 }
297 break;
298 }
299 }
300
301 static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
302 {
303 gint mode = e->xfocus.mode;
304 gint detail = e->xfocus.detail;
305 Window win = e->xany.window;
306
307 if (e->type == FocusIn) {
308 /* These are ones we never want.. */
309
310 /* This means focus was given by a keyboard/mouse grab. */
311 if (mode == NotifyGrab)
312 return FALSE;
313 /* This means focus was given back from a keyboard/mouse grab. */
314 if (mode == NotifyUngrab)
315 return FALSE;
316
317 /* These are the ones we want.. */
318
319 if (win == RootWindow(ob_display, ob_screen)) {
320 /* If looking for a focus in on a client, then always return
321 FALSE for focus in's to the root window */
322 if (in_client_only)
323 return FALSE;
324 /* This means focus reverted off of a client */
325 else if (detail == NotifyPointerRoot ||
326 detail == NotifyDetailNone ||
327 detail == NotifyInferior ||
328 /* This means focus got here from another screen */
329 detail == NotifyNonlinear)
330 return TRUE;
331 else
332 return FALSE;
333 }
334
335 /* It was on a client, was it a valid one?
336 It's possible to get a FocusIn event for a client that was managed
337 but has disappeared.
338 */
339 if (in_client_only) {
340 ObWindow *w = g_hash_table_lookup(window_map, &e->xfocus.window);
341 if (!w || !WINDOW_IS_CLIENT(w))
342 return FALSE;
343 }
344 else {
345 /* This means focus reverted to parent from the client (this
346 happens often during iconify animation) */
347 if (detail == NotifyInferior)
348 return TRUE;
349 }
350
351 /* This means focus moved from the root window to a client */
352 if (detail == NotifyVirtual)
353 return TRUE;
354 /* This means focus moved from one client to another */
355 if (detail == NotifyNonlinearVirtual)
356 return TRUE;
357
358 /* Otherwise.. */
359 return FALSE;
360 } else {
361 g_assert(e->type == FocusOut);
362
363 /* These are ones we never want.. */
364
365 /* This means focus was taken by a keyboard/mouse grab. */
366 if (mode == NotifyGrab)
367 return FALSE;
368 /* This means focus was grabbed on a window and it was released. */
369 if (mode == NotifyUngrab)
370 return FALSE;
371
372 /* Focus left the root window revertedto state */
373 if (win == RootWindow(ob_display, ob_screen))
374 return FALSE;
375
376 /* These are the ones we want.. */
377
378 /* This means focus moved from a client to the root window */
379 if (detail == NotifyVirtual)
380 return TRUE;
381 /* This means focus moved from one client to another */
382 if (detail == NotifyNonlinearVirtual)
383 return TRUE;
384
385 /* Otherwise.. */
386 return FALSE;
387 }
388 }
389
390 static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
391 {
392 return e->type == FocusIn && wanted_focusevent(e, FALSE);
393 }
394
395 static Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
396 {
397 return e->type == FocusIn && wanted_focusevent(e, TRUE);
398 }
399
400 static void print_focusevent(XEvent *e)
401 {
402 gint mode = e->xfocus.mode;
403 gint detail = e->xfocus.detail;
404 Window win = e->xany.window;
405 const gchar *modestr, *detailstr;
406
407 switch (mode) {
408 case NotifyNormal: modestr="NotifyNormal"; break;
409 case NotifyGrab: modestr="NotifyGrab"; break;
410 case NotifyUngrab: modestr="NotifyUngrab"; break;
411 case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
412 }
413 switch (detail) {
414 case NotifyAncestor: detailstr="NotifyAncestor"; break;
415 case NotifyVirtual: detailstr="NotifyVirtual"; break;
416 case NotifyInferior: detailstr="NotifyInferior"; break;
417 case NotifyNonlinear: detailstr="NotifyNonlinear"; break;
418 case NotifyNonlinearVirtual: detailstr="NotifyNonlinearVirtual"; break;
419 case NotifyPointer: detailstr="NotifyPointer"; break;
420 case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
421 case NotifyDetailNone: detailstr="NotifyDetailNone"; break;
422 }
423
424 if (mode == NotifyGrab || mode == NotifyUngrab)
425 return;
426
427 g_assert(modestr);
428 g_assert(detailstr);
429 ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s\n",
430 (e->xfocus.type == FocusIn ? "In" : "Out"),
431 win,
432 modestr, detailstr);
433
434 }
435
436 static gboolean event_ignore(XEvent *e, ObClient *client)
437 {
438 switch(e->type) {
439 case FocusIn:
440 print_focusevent(e);
441 if (!wanted_focusevent(e, FALSE))
442 return TRUE;
443 break;
444 case FocusOut:
445 print_focusevent(e);
446 if (!wanted_focusevent(e, FALSE))
447 return TRUE;
448 break;
449 }
450 return FALSE;
451 }
452
453 static void event_process(const XEvent *ec, gpointer data)
454 {
455 Window window;
456 ObClient *client = NULL;
457 ObDock *dock = NULL;
458 ObDockApp *dockapp = NULL;
459 ObWindow *obwin = NULL;
460 XEvent ee, *e;
461 ObEventData *ed = data;
462
463 /* make a copy we can mangle */
464 ee = *ec;
465 e = &ee;
466
467 window = event_get_window(e);
468 if ((obwin = g_hash_table_lookup(window_map, &window))) {
469 switch (obwin->type) {
470 case Window_Dock:
471 dock = WINDOW_AS_DOCK(obwin);
472 break;
473 case Window_DockApp:
474 dockapp = WINDOW_AS_DOCKAPP(obwin);
475 break;
476 case Window_Client:
477 client = WINDOW_AS_CLIENT(obwin);
478 break;
479 case Window_Menu:
480 /* not to be used for events */
481 g_assert_not_reached();
482 break;
483 case Window_Internal:
484 /* we don't do anything with events directly on these windows */
485 break;
486 }
487 }
488
489 event_set_curtime(e);
490 event_curserial = e->xany.serial;
491 event_hack_mods(e);
492 if (event_ignore(e, client)) {
493 if (ed)
494 ed->ignored = TRUE;
495 return;
496 } else if (ed)
497 ed->ignored = FALSE;
498
499 /* deal with it in the kernel */
500
501 if (menu_frame_visible &&
502 (e->type == EnterNotify || e->type == LeaveNotify))
503 {
504 /* crossing events for menu */
505 event_handle_menu(e);
506 } else if (e->type == FocusIn) {
507 if (client &&
508 e->xfocus.detail == NotifyInferior)
509 {
510 ob_debug_type(OB_DEBUG_FOCUS,
511 "Focus went to the frame window");
512
513 focus_left_screen = FALSE;
514
515 focus_fallback(FALSE, config_focus_under_mouse, TRUE, TRUE);
516
517 /* We don't get a FocusOut for this case, because it's just moving
518 from our Inferior up to us. This happens when iconifying a
519 window with RevertToParent focus */
520 frame_adjust_focus(client->frame, FALSE);
521 /* focus_set_client(NULL) has already been called */
522 }
523 else if (e->xfocus.detail == NotifyPointerRoot ||
524 e->xfocus.detail == NotifyDetailNone ||
525 e->xfocus.detail == NotifyInferior ||
526 e->xfocus.detail == NotifyNonlinear)
527 {
528 XEvent ce;
529
530 ob_debug_type(OB_DEBUG_FOCUS,
531 "Focus went to root or pointer root/none\n");
532
533 if (e->xfocus.detail == NotifyInferior ||
534 e->xfocus.detail == NotifyNonlinear)
535 {
536 focus_left_screen = FALSE;
537 }
538
539 /* If another FocusIn is in the queue then don't fallback yet. This
540 fixes the fun case of:
541 window map -> send focusin
542 window unmap -> get focusout
543 window map -> send focusin
544 get first focus out -> fall back to something (new window
545 hasn't received focus yet, so something else) -> send focusin
546 which means the "something else" is the last thing to get a
547 focusin sent to it, so the new window doesn't end up with focus.
548
549 But if the other focus in is something like PointerRoot then we
550 still want to fall back.
551 */
552 if (XCheckIfEvent(ob_display, &ce, event_look_for_focusin_client,
553 NULL))
554 {
555 XPutBackEvent(ob_display, &ce);
556 ob_debug_type(OB_DEBUG_FOCUS,
557 " but another FocusIn is coming\n");
558 } else {
559 /* Focus has been reverted.
560
561 FocusOut events come after UnmapNotify, so we don't need to
562 worry about focusing an invalid window
563 */
564
565 if (!focus_left_screen)
566 focus_fallback(FALSE, config_focus_under_mouse,
567 TRUE, TRUE);
568 }
569 }
570 else if (!client)
571 {
572 ob_debug_type(OB_DEBUG_FOCUS,
573 "Focus went to a window that is already gone\n");
574
575 /* If you send focus to a window and then it disappears, you can
576 get the FocusIn for it, after it is unmanaged.
577 Just wait for the next FocusOut/FocusIn pair, but make note that
578 the window that was focused no longer is. */
579 focus_set_client(NULL);
580 }
581 else if (client != focus_client) {
582 focus_left_screen = FALSE;
583 frame_adjust_focus(client->frame, TRUE);
584 focus_set_client(client);
585 client_calc_layer(client);
586 client_bring_helper_windows(client);
587 }
588 } else if (e->type == FocusOut) {
589 XEvent ce;
590
591 /* Look for the followup FocusIn */
592 if (!XCheckIfEvent(ob_display, &ce, event_look_for_focusin, NULL)) {
593 /* There is no FocusIn, this means focus went to a window that
594 is not being managed, or a window on another screen. */
595 Window win, root;
596 gint i;
597 guint u;
598 xerror_set_ignore(TRUE);
599 if (XGetInputFocus(ob_display, &win, &i) != 0 &&
600 XGetGeometry(ob_display, win, &root, &i,&i,&u,&u,&u,&u) != 0 &&
601 root != RootWindow(ob_display, ob_screen))
602 {
603 ob_debug_type(OB_DEBUG_FOCUS,
604 "Focus went to another screen !\n");
605 focus_left_screen = TRUE;
606 }
607 else
608 ob_debug_type(OB_DEBUG_FOCUS,
609 "Focus went to a black hole !\n");
610 xerror_set_ignore(FALSE);
611 /* nothing is focused */
612 focus_set_client(NULL);
613 } else {
614 /* Focus moved, so process the FocusIn event */
615 ObEventData ed = { .ignored = FALSE };
616 event_process(&ce, &ed);
617 if (ed.ignored) {
618 /* The FocusIn was ignored, this means it was on a window
619 that isn't a client. */
620 ob_debug_type(OB_DEBUG_FOCUS,
621 "Focus went to an unmanaged window 0x%x !\n",
622 ce.xfocus.window);
623 focus_fallback(TRUE, config_focus_under_mouse, TRUE, TRUE);
624 }
625 }
626
627 if (client && client != focus_client) {
628 frame_adjust_focus(client->frame, FALSE);
629 /* focus_set_client(NULL) has already been called in this
630 section or by focus_fallback */
631 }
632 }
633 else if (client)
634 event_handle_client(client, e);
635 else if (dockapp)
636 event_handle_dockapp(dockapp, e);
637 else if (dock)
638 event_handle_dock(dock, e);
639 else if (window == RootWindow(ob_display, ob_screen))
640 event_handle_root(e);
641 else if (e->type == MapRequest)
642 client_manage(window);
643 else if (e->type == MappingNotify) {
644 /* keyboard layout changes for modifier mapping changes. reload the
645 modifier map, and rebind all the key bindings as appropriate */
646 ob_debug("Kepboard map changed. Reloading keyboard bindings.\n");
647 modkeys_shutdown(TRUE);
648 modkeys_startup(TRUE);
649 keyboard_rebind();
650 }
651 else if (e->type == ClientMessage) {
652 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
653 windows that are not managed yet. */
654 if (e->xclient.message_type == prop_atoms.net_request_frame_extents) {
655 /* Pretend to manage the client, getting information used to
656 determine its decorations */
657 ObClient *c = client_fake_manage(e->xclient.window);
658 gulong vals[4];
659
660 /* set the frame extents on the window */
661 vals[0] = c->frame->size.left;
662 vals[1] = c->frame->size.right;
663 vals[2] = c->frame->size.top;
664 vals[3] = c->frame->size.bottom;
665 PROP_SETA32(e->xclient.window, net_frame_extents,
666 cardinal, vals, 4);
667
668 /* Free the pretend client */
669 client_fake_unmanage(c);
670 }
671 }
672 else if (e->type == ConfigureRequest) {
673 /* unhandled configure requests must be used to configure the
674 window directly */
675 XWindowChanges xwc;
676
677 xwc.x = e->xconfigurerequest.x;
678 xwc.y = e->xconfigurerequest.y;
679 xwc.width = e->xconfigurerequest.width;
680 xwc.height = e->xconfigurerequest.height;
681 xwc.border_width = e->xconfigurerequest.border_width;
682 xwc.sibling = e->xconfigurerequest.above;
683 xwc.stack_mode = e->xconfigurerequest.detail;
684
685 /* we are not to be held responsible if someone sends us an
686 invalid request! */
687 xerror_set_ignore(TRUE);
688 XConfigureWindow(ob_display, window,
689 e->xconfigurerequest.value_mask, &xwc);
690 xerror_set_ignore(FALSE);
691 }
692 #ifdef SYNC
693 else if (extensions_sync &&
694 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
695 {
696 XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e;
697 if (se->alarm == moveresize_alarm && moveresize_in_progress)
698 moveresize_event(e);
699 }
700 #endif
701
702 if (e->type == ButtonPress || e->type == ButtonRelease) {
703 /* If the button press was on some non-root window, or was physically
704 on the root window, the process it */
705 if (window != RootWindow(ob_display, ob_screen) ||
706 e->xbutton.subwindow == None)
707 {
708 event_handle_user_input(client, e);
709 }
710 /* Otherwise only process it if it was physically on an openbox
711 internal window */
712 else {
713 ObWindow *w;
714
715 if ((w = g_hash_table_lookup(window_map, &e->xbutton.subwindow)) &&
716 WINDOW_IS_INTERNAL(w))
717 {
718 event_handle_user_input(client, e);
719 }
720 }
721 }
722 else if (e->type == KeyPress || e->type == KeyRelease ||
723 e->type == MotionNotify)
724 event_handle_user_input(client, e);
725
726 /* if something happens and it's not from an XEvent, then we don't know
727 the time */
728 event_curtime = CurrentTime;
729 event_curserial = 0;
730 }
731
732 static void event_handle_root(XEvent *e)
733 {
734 Atom msgtype;
735
736 switch(e->type) {
737 case SelectionClear:
738 ob_debug("Another WM has requested to replace us. Exiting.\n");
739 ob_exit_replace();
740 break;
741
742 case ClientMessage:
743 if (e->xclient.format != 32) break;
744
745 msgtype = e->xclient.message_type;
746 if (msgtype == prop_atoms.net_current_desktop) {
747 guint d = e->xclient.data.l[0];
748 if (d < screen_num_desktops) {
749 event_curtime = e->xclient.data.l[1];
750 if (event_curtime == 0)
751 ob_debug_type(OB_DEBUG_APP_BUGS,
752 "_NET_CURRENT_DESKTOP message is missing "
753 "a timestamp\n");
754 screen_set_desktop(d, TRUE);
755 }
756 } else if (msgtype == prop_atoms.net_number_of_desktops) {
757 guint d = e->xclient.data.l[0];
758 if (d > 0 && d <= 1000)
759 screen_set_num_desktops(d);
760 } else if (msgtype == prop_atoms.net_showing_desktop) {
761 screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
762 } else if (msgtype == prop_atoms.ob_control) {
763 ob_debug("OB_CONTROL: %d\n", e->xclient.data.l[0]);
764 if (e->xclient.data.l[0] == 1)
765 ob_reconfigure();
766 else if (e->xclient.data.l[0] == 2)
767 ob_restart();
768 else if (e->xclient.data.l[0] == 3)
769 ob_exit(0);
770 } else if (msgtype == prop_atoms.wm_protocols) {
771 if ((Atom)e->xclient.data.l[0] == prop_atoms.net_wm_ping)
772 ping_got_pong(e->xclient.data.l[1]);
773 }
774 break;
775 case PropertyNotify:
776 if (e->xproperty.atom == prop_atoms.net_desktop_names) {
777 ob_debug("UPDATE DESKTOP NAMES\n");
778 screen_update_desktop_names();
779 }
780 else if (e->xproperty.atom == prop_atoms.net_desktop_layout)
781 screen_update_layout();
782 break;
783 case ConfigureNotify:
784 #ifdef XRANDR
785 XRRUpdateConfiguration(e);
786 #endif
787 screen_resize();
788 break;
789 default:
790 ;
791 }
792 }
793
794 void event_enter_client(ObClient *client)
795 {
796 g_assert(config_focus_follow);
797
798 if (client_enter_focusable(client) && client_can_focus(client)) {
799 if (config_focus_delay) {
800 ObFocusDelayData *data;
801
802 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
803
804 data = g_new(ObFocusDelayData, 1);
805 data->client = client;
806 data->time = event_curtime;
807 data->serial = event_curserial;
808
809 ob_main_loop_timeout_add(ob_main_loop,
810 config_focus_delay * 1000,
811 focus_delay_func,
812 data, focus_delay_cmp, focus_delay_dest);
813 } else {
814 ObFocusDelayData data;
815 data.client = client;
816 data.time = event_curtime;
817 data.serial = event_curserial;
818 focus_delay_func(&data);
819 }
820 }
821 }
822
823 static void event_handle_client(ObClient *client, XEvent *e)
824 {
825 XEvent ce;
826 Atom msgtype;
827 ObFrameContext con;
828 static gint px = -1, py = -1;
829 static guint pb = 0;
830
831 switch (e->type) {
832 case ButtonPress:
833 /* save where the press occured for the first button pressed */
834 if (!pb) {
835 pb = e->xbutton.button;
836 px = e->xbutton.x;
837 py = e->xbutton.y;
838 }
839 case ButtonRelease:
840 /* Wheel buttons don't draw because they are an instant click, so it
841 is a waste of resources to go drawing it.
842 if the user is doing an intereactive thing, or has a menu open then
843 the mouse is grabbed (possibly) and if we get these events we don't
844 want to deal with them
845 */
846 if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
847 !grab_on_keyboard())
848 {
849 /* use where the press occured */
850 con = frame_context(client, e->xbutton.window, px, py);
851 con = mouse_button_frame_context(con, e->xbutton.button,
852 e->xbutton.state);
853
854 if (e->type == ButtonRelease && e->xbutton.button == pb)
855 pb = 0, px = py = -1;
856
857 switch (con) {
858 case OB_FRAME_CONTEXT_MAXIMIZE:
859 client->frame->max_press = (e->type == ButtonPress);
860 frame_adjust_state(client->frame);
861 break;
862 case OB_FRAME_CONTEXT_CLOSE:
863 client->frame->close_press = (e->type == ButtonPress);
864 frame_adjust_state(client->frame);
865 break;
866 case OB_FRAME_CONTEXT_ICONIFY:
867 client->frame->iconify_press = (e->type == ButtonPress);
868 frame_adjust_state(client->frame);
869 break;
870 case OB_FRAME_CONTEXT_ALLDESKTOPS:
871 client->frame->desk_press = (e->type == ButtonPress);
872 frame_adjust_state(client->frame);
873 break;
874 case OB_FRAME_CONTEXT_SHADE:
875 client->frame->shade_press = (e->type == ButtonPress);
876 frame_adjust_state(client->frame);
877 break;
878 default:
879 /* nothing changes with clicks for any other contexts */
880 break;
881 }
882 }
883 break;
884 case MotionNotify:
885 /* when there is a grab on the pointer, we won't get enter/leave
886 notifies, but we still get motion events */
887 if (grab_on_pointer()) break;
888
889 con = frame_context(client, e->xmotion.window,
890 e->xmotion.x, e->xmotion.y);
891 switch (con) {
892 case OB_FRAME_CONTEXT_TITLEBAR:
893 case OB_FRAME_CONTEXT_TLCORNER:
894 case OB_FRAME_CONTEXT_TRCORNER:
895 /* we've left the button area inside the titlebar */
896 if (client->frame->max_hover || client->frame->desk_hover ||
897 client->frame->shade_hover || client->frame->iconify_hover ||
898 client->frame->close_hover)
899 {
900 client->frame->max_hover = FALSE;
901 client->frame->desk_hover = FALSE;
902 client->frame->shade_hover = FALSE;
903 client->frame->iconify_hover = FALSE;
904 client->frame->close_hover = FALSE;
905 frame_adjust_state(client->frame);
906 }
907 break;
908 case OB_FRAME_CONTEXT_MAXIMIZE:
909 if (!client->frame->max_hover) {
910 client->frame->max_hover = TRUE;
911 frame_adjust_state(client->frame);
912 }
913 break;
914 case OB_FRAME_CONTEXT_ALLDESKTOPS:
915 if (!client->frame->desk_hover) {
916 client->frame->desk_hover = TRUE;
917 frame_adjust_state(client->frame);
918 }
919 break;
920 case OB_FRAME_CONTEXT_SHADE:
921 if (!client->frame->shade_hover) {
922 client->frame->shade_hover = TRUE;
923 frame_adjust_state(client->frame);
924 }
925 break;
926 case OB_FRAME_CONTEXT_ICONIFY:
927 if (!client->frame->iconify_hover) {
928 client->frame->iconify_hover = TRUE;
929 frame_adjust_state(client->frame);
930 }
931 break;
932 case OB_FRAME_CONTEXT_CLOSE:
933 if (!client->frame->close_hover) {
934 client->frame->close_hover = TRUE;
935 frame_adjust_state(client->frame);
936 }
937 break;
938 default:
939 break;
940 }
941 break;
942 case LeaveNotify:
943 con = frame_context(client, e->xcrossing.window,
944 e->xcrossing.x, e->xcrossing.y);
945 switch (con) {
946 case OB_FRAME_CONTEXT_TITLEBAR:
947 case OB_FRAME_CONTEXT_TLCORNER:
948 case OB_FRAME_CONTEXT_TRCORNER:
949 /* we've left the button area inside the titlebar */
950 if (client->frame->max_hover || client->frame->desk_hover ||
951 client->frame->shade_hover || client->frame->iconify_hover ||
952 client->frame->close_hover)
953 {
954 client->frame->max_hover = FALSE;
955 client->frame->desk_hover = FALSE;
956 client->frame->shade_hover = FALSE;
957 client->frame->iconify_hover = FALSE;
958 client->frame->close_hover = FALSE;
959 frame_adjust_state(client->frame);
960 }
961 break;
962 case OB_FRAME_CONTEXT_MAXIMIZE:
963 client->frame->max_hover = FALSE;
964 frame_adjust_state(client->frame);
965 break;
966 case OB_FRAME_CONTEXT_ALLDESKTOPS:
967 client->frame->desk_hover = FALSE;
968 frame_adjust_state(client->frame);
969 break;
970 case OB_FRAME_CONTEXT_SHADE:
971 client->frame->shade_hover = FALSE;
972 frame_adjust_state(client->frame);
973 break;
974 case OB_FRAME_CONTEXT_ICONIFY:
975 client->frame->iconify_hover = FALSE;
976 frame_adjust_state(client->frame);
977 break;
978 case OB_FRAME_CONTEXT_CLOSE:
979 client->frame->close_hover = FALSE;
980 frame_adjust_state(client->frame);
981 break;
982 case OB_FRAME_CONTEXT_FRAME:
983 /* When the mouse leaves an animating window, don't use the
984 corresponding enter events. Pretend like the animating window
985 doesn't even exist..! */
986 if (frame_iconify_animating(client->frame))
987 event_end_ignore_all_enters(event_start_ignore_all_enters());
988
989 ob_debug_type(OB_DEBUG_FOCUS,
990 "%sNotify mode %d detail %d on %lx\n",
991 (e->type == EnterNotify ? "Enter" : "Leave"),
992 e->xcrossing.mode,
993 e->xcrossing.detail, (client?client->window:0));
994 if (grab_on_keyboard())
995 break;
996 if (config_focus_follow && config_focus_delay &&
997 /* leave inferior events can happen when the mouse goes onto
998 the window's border and then into the window before the
999 delay is up */
1000 e->xcrossing.detail != NotifyInferior)
1001 {
1002 ob_main_loop_timeout_remove_data(ob_main_loop,
1003 focus_delay_func,
1004 client, FALSE);
1005 }
1006 break;
1007 default:
1008 break;
1009 }
1010 break;
1011 case EnterNotify:
1012 {
1013 con = frame_context(client, e->xcrossing.window,
1014 e->xcrossing.x, e->xcrossing.y);
1015 switch (con) {
1016 case OB_FRAME_CONTEXT_MAXIMIZE:
1017 client->frame->max_hover = TRUE;
1018 frame_adjust_state(client->frame);
1019 break;
1020 case OB_FRAME_CONTEXT_ALLDESKTOPS:
1021 client->frame->desk_hover = TRUE;
1022 frame_adjust_state(client->frame);
1023 break;
1024 case OB_FRAME_CONTEXT_SHADE:
1025 client->frame->shade_hover = TRUE;
1026 frame_adjust_state(client->frame);
1027 break;
1028 case OB_FRAME_CONTEXT_ICONIFY:
1029 client->frame->iconify_hover = TRUE;
1030 frame_adjust_state(client->frame);
1031 break;
1032 case OB_FRAME_CONTEXT_CLOSE:
1033 client->frame->close_hover = TRUE;
1034 frame_adjust_state(client->frame);
1035 break;
1036 case OB_FRAME_CONTEXT_FRAME:
1037 if (grab_on_keyboard())
1038 break;
1039 if (e->xcrossing.mode == NotifyGrab ||
1040 e->xcrossing.mode == NotifyUngrab ||
1041 /*ignore enters when we're already in the window */
1042 e->xcrossing.detail == NotifyInferior ||
1043 is_enter_focus_event_ignored(e))
1044 {
1045 ob_debug_type(OB_DEBUG_FOCUS,
1046 "%sNotify mode %d detail %d serial %lu on %lx "
1047 "IGNORED\n",
1048 (e->type == EnterNotify ? "Enter" : "Leave"),
1049 e->xcrossing.mode,
1050 e->xcrossing.detail,
1051 e->xcrossing.serial,
1052 client?client->window:0);
1053 }
1054 else {
1055 ob_debug_type(OB_DEBUG_FOCUS,
1056 "%sNotify mode %d detail %d serial %lu on %lx, "
1057 "focusing window\n",
1058 (e->type == EnterNotify ? "Enter" : "Leave"),
1059 e->xcrossing.mode,
1060 e->xcrossing.detail,
1061 e->xcrossing.serial,
1062 (client?client->window:0));
1063 if (config_focus_follow)
1064 event_enter_client(client);
1065 }
1066 break;
1067 default:
1068 break;
1069 }
1070 break;
1071 }
1072 case ConfigureRequest:
1073 {
1074 /* dont compress these unless you're going to watch for property
1075 notifies in between (these can change what the configure would
1076 do to the window).
1077 also you can't compress stacking events
1078 */
1079
1080 gint x, y, w, h;
1081 gboolean move = FALSE;
1082 gboolean resize = FALSE;
1083
1084 /* get the current area */
1085 RECT_TO_DIMS(client->area, x, y, w, h);
1086
1087 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1088 "visibile %d\n"
1089 " x %d y %d w %d h %d b %d\n",
1090 client->title,
1091 screen_desktop, client->wmstate, client->frame->visible,
1092 x, y, w, h, client->border_width);
1093
1094 if (e->xconfigurerequest.value_mask & CWBorderWidth)
1095 if (client->border_width != e->xconfigurerequest.border_width) {
1096 client->border_width = e->xconfigurerequest.border_width;
1097
1098 /* if the border width is changing then that is the same
1099 as requesting a resize, but we don't actually change
1100 the client's border, so it will change their root
1101 coordiantes (since they include the border width) and
1102 we need to a notify then */
1103 move = TRUE;
1104 }
1105
1106
1107 if (e->xconfigurerequest.value_mask & CWStackMode) {
1108 ObClient *sibling = NULL;
1109 gulong ignore_start;
1110 gboolean ok = TRUE;
1111
1112 /* get the sibling */
1113 if (e->xconfigurerequest.value_mask & CWSibling) {
1114 ObWindow *win;
1115 win = g_hash_table_lookup(window_map,
1116 &e->xconfigurerequest.above);
1117 if (win && WINDOW_IS_CLIENT(win) &&
1118 WINDOW_AS_CLIENT(win) != client)
1119 {
1120 sibling = WINDOW_AS_CLIENT(win);
1121 }
1122 else
1123 /* an invalid sibling was specified so don't restack at
1124 all, it won't make sense no matter what we do */
1125 ok = FALSE;
1126 }
1127
1128 if (ok) {
1129 if (!config_focus_under_mouse)
1130 ignore_start = event_start_ignore_all_enters();
1131 stacking_restack_request(client, sibling,
1132 e->xconfigurerequest.detail);
1133 if (!config_focus_under_mouse)
1134 event_end_ignore_all_enters(ignore_start);
1135 }
1136
1137 /* a stacking change moves the window without resizing */
1138 move = TRUE;
1139 }
1140
1141 if ((e->xconfigurerequest.value_mask & CWX) ||
1142 (e->xconfigurerequest.value_mask & CWY) ||
1143 (e->xconfigurerequest.value_mask & CWWidth) ||
1144 (e->xconfigurerequest.value_mask & CWHeight))
1145 {
1146 if (e->xconfigurerequest.value_mask & CWX) {
1147 /* don't allow clients to move shaded windows (fvwm does this)
1148 */
1149 if (!client->shaded)
1150 x = e->xconfigurerequest.x;
1151 move = TRUE;
1152 }
1153 if (e->xconfigurerequest.value_mask & CWY) {
1154 /* don't allow clients to move shaded windows (fvwm does this)
1155 */
1156 if (!client->shaded)
1157 y = e->xconfigurerequest.y;
1158 move = TRUE;
1159 }
1160
1161 if (e->xconfigurerequest.value_mask & CWWidth) {
1162 w = e->xconfigurerequest.width;
1163 resize = TRUE;
1164 }
1165 if (e->xconfigurerequest.value_mask & CWHeight) {
1166 h = e->xconfigurerequest.height;
1167 resize = TRUE;
1168 }
1169 }
1170
1171 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1172 "move %d resize %d\n",
1173 e->xconfigurerequest.value_mask & CWX, x,
1174 e->xconfigurerequest.value_mask & CWY, y,
1175 e->xconfigurerequest.value_mask & CWWidth, w,
1176 e->xconfigurerequest.value_mask & CWHeight, h,
1177 move, resize);
1178
1179 /* check for broken apps moving to their root position
1180
1181 XXX remove this some day...that would be nice. right now all
1182 kde apps do this when they try activate themselves on another
1183 desktop. eg. open amarok window on desktop 1, switch to desktop
1184 2, click amarok tray icon. it will move by its decoration size.
1185 */
1186 if (x != client->area.x &&
1187 x == (client->frame->area.x + client->frame->size.left -
1188 (gint)client->border_width) &&
1189 y != client->area.y &&
1190 y == (client->frame->area.y + client->frame->size.top -
1191 (gint)client->border_width) &&
1192 w == client->area.width &&
1193 h == client->area.height)
1194 {
1195 ob_debug_type(OB_DEBUG_APP_BUGS,
1196 "Application %s is trying to move via "
1197 "ConfigureRequest to it's root window position "
1198 "but it is not using StaticGravity\n",
1199 client->title);
1200 /* don't move it */
1201 x = client->area.x;
1202 y = client->area.y;
1203
1204 /* they still requested a move, so don't change whether a
1205 notify is sent or not */
1206 }
1207
1208 {
1209 gint lw,lh;
1210
1211 client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
1212
1213 /* if x was not given, then use gravity to figure out the new
1214 x. the reference point should not be moved */
1215 if ((e->xconfigurerequest.value_mask & CWWidth &&
1216 !(e->xconfigurerequest.value_mask & CWX)))
1217 client_gravity_resize_w(client, &x, client->area.width, w);
1218 /* if y was not given, then use gravity to figure out the new
1219 y. the reference point should not be moved */
1220 if ((e->xconfigurerequest.value_mask & CWHeight &&
1221 !(e->xconfigurerequest.value_mask & CWY)))
1222 client_gravity_resize_h(client, &y, client->area.height,h);
1223
1224 client_find_onscreen(client, &x, &y, w, h, FALSE);
1225
1226 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1227 x, y, w, h);
1228 client_configure(client, x, y, w, h, FALSE, TRUE, TRUE);
1229 }
1230 break;
1231 }
1232 case UnmapNotify:
1233 if (client->ignore_unmaps) {
1234 client->ignore_unmaps--;
1235 break;
1236 }
1237 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1238 "ignores left %d\n",
1239 client->window, e->xunmap.event, e->xunmap.from_configure,
1240 client->ignore_unmaps);
1241 client_unmanage(client);
1242 break;
1243 case DestroyNotify:
1244 ob_debug("DestroyNotify for window 0x%x\n", client->window);
1245 client_unmanage(client);
1246 break;
1247 case ReparentNotify:
1248 /* this is when the client is first taken captive in the frame */
1249 if (e->xreparent.parent == client->frame->window) break;
1250
1251 /*
1252 This event is quite rare and is usually handled in unmapHandler.
1253 However, if the window is unmapped when the reparent event occurs,
1254 the window manager never sees it because an unmap event is not sent
1255 to an already unmapped window.
1256 */
1257
1258 /* we don't want the reparent event, put it back on the stack for the
1259 X server to deal with after we unmanage the window */
1260 XPutBackEvent(ob_display, e);
1261
1262 ob_debug("ReparentNotify for window 0x%x\n", client->window);
1263 client_unmanage(client);
1264 break;
1265 case MapRequest:
1266 ob_debug("MapRequest for 0x%lx\n", client->window);
1267 if (!client->iconic) break; /* this normally doesn't happen, but if it
1268 does, we don't want it!
1269 it can happen now when the window is on
1270 another desktop, but we still don't
1271 want it! */
1272 client_activate(client, FALSE, TRUE, TRUE, TRUE);
1273 break;
1274 case ClientMessage:
1275 /* validate cuz we query stuff off the client here */
1276 if (!client_validate(client)) break;
1277
1278 if (e->xclient.format != 32) return;
1279
1280 msgtype = e->xclient.message_type;
1281 if (msgtype == prop_atoms.wm_change_state) {
1282 /* compress changes into a single change */
1283 while (XCheckTypedWindowEvent(ob_display, client->window,
1284 e->type, &ce)) {
1285 /* XXX: it would be nice to compress ALL messages of a
1286 type, not just messages in a row without other
1287 message types between. */
1288 if (ce.xclient.message_type != msgtype) {
1289 XPutBackEvent(ob_display, &ce);
1290 break;
1291 }
1292 e->xclient = ce.xclient;
1293 }
1294 client_set_wm_state(client, e->xclient.data.l[0]);
1295 } else if (msgtype == prop_atoms.net_wm_desktop) {
1296 /* compress changes into a single change */
1297 while (XCheckTypedWindowEvent(ob_display, client->window,
1298 e->type, &ce)) {
1299 /* XXX: it would be nice to compress ALL messages of a
1300 type, not just messages in a row without other
1301 message types between. */
1302 if (ce.xclient.message_type != msgtype) {
1303 XPutBackEvent(ob_display, &ce);
1304 break;
1305 }
1306 e->xclient = ce.xclient;
1307 }
1308 if ((unsigned)e->xclient.data.l[0] < screen_num_desktops ||
1309 (unsigned)e->xclient.data.l[0] == DESKTOP_ALL)
1310 client_set_desktop(client, (unsigned)e->xclient.data.l[0],
1311 FALSE, FALSE);
1312 } else if (msgtype == prop_atoms.net_wm_state) {
1313 gulong ignore_start;
1314
1315 /* can't compress these */
1316 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1317 (e->xclient.data.l[0] == 0 ? "Remove" :
1318 e->xclient.data.l[0] == 1 ? "Add" :
1319 e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"),
1320 e->xclient.data.l[1], e->xclient.data.l[2],
1321 client->window);
1322
1323 /* ignore enter events caused by these like ob actions do */
1324 if (!config_focus_under_mouse)
1325 ignore_start = event_start_ignore_all_enters();
1326 client_set_state(client, e->xclient.data.l[0],
1327 e->xclient.data.l[1], e->xclient.data.l[2]);
1328 if (!config_focus_under_mouse)
1329 event_end_ignore_all_enters(ignore_start);
1330 } else if (msgtype == prop_atoms.net_close_window) {
1331 ob_debug("net_close_window for 0x%lx\n", client->window);
1332 client_close(client);
1333 } else if (msgtype == prop_atoms.net_active_window) {
1334 ob_debug("net_active_window for 0x%lx source=%s\n",
1335 client->window,
1336 (e->xclient.data.l[0] == 0 ? "unknown" :
1337 (e->xclient.data.l[0] == 1 ? "application" :
1338 (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
1339 /* XXX make use of data.l[2] !? */
1340 if (e->xclient.data.l[0] == 1 || e->xclient.data.l[0] == 2) {
1341 /* don't use the user's timestamp for client_focus, cuz if it's
1342 an old broken timestamp (happens all the time) then focus
1343 won't move even though we're trying to move it
1344 event_curtime = e->xclient.data.l[1];*/
1345 if (e->xclient.data.l[1] == 0)
1346 ob_debug_type(OB_DEBUG_APP_BUGS,
1347 "_NET_ACTIVE_WINDOW message for window %s is"
1348 " missing a timestamp\n", client->title);
1349 } else
1350 ob_debug_type(OB_DEBUG_APP_BUGS,
1351 "_NET_ACTIVE_WINDOW message for window %s is "
1352 "missing source indication\n");
1353 client_activate(client, FALSE, TRUE, TRUE,
1354 (e->xclient.data.l[0] == 0 ||
1355 e->xclient.data.l[0] == 2));
1356 } else if (msgtype == prop_atoms.net_wm_moveresize) {
1357 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1358 client->window, e->xclient.data.l[2]);
1359 if ((Atom)e->xclient.data.l[2] ==
1360 prop_atoms.net_wm_moveresize_size_topleft ||
1361 (Atom)e->xclient.data.l[2] ==
1362 prop_atoms.net_wm_moveresize_size_top ||
1363 (Atom)e->xclient.data.l[2] ==
1364 prop_atoms.net_wm_moveresize_size_topright ||
1365 (Atom)e->xclient.data.l[2] ==
1366 prop_atoms.net_wm_moveresize_size_right ||
1367 (Atom)e->xclient.data.l[2] ==
1368 prop_atoms.net_wm_moveresize_size_right ||
1369 (Atom)e->xclient.data.l[2] ==
1370 prop_atoms.net_wm_moveresize_size_bottomright ||
1371 (Atom)e->xclient.data.l[2] ==
1372 prop_atoms.net_wm_moveresize_size_bottom ||
1373 (Atom)e->xclient.data.l[2] ==
1374 prop_atoms.net_wm_moveresize_size_bottomleft ||
1375 (Atom)e->xclient.data.l[2] ==
1376 prop_atoms.net_wm_moveresize_size_left ||
1377 (Atom)e->xclient.data.l[2] ==
1378 prop_atoms.net_wm_moveresize_move ||
1379 (Atom)e->xclient.data.l[2] ==
1380 prop_atoms.net_wm_moveresize_size_keyboard ||
1381 (Atom)e->xclient.data.l[2] ==
1382 prop_atoms.net_wm_moveresize_move_keyboard) {
1383
1384 moveresize_start(client, e->xclient.data.l[0],
1385 e->xclient.data.l[1], e->xclient.data.l[3],
1386 e->xclient.data.l[2]);
1387 }
1388 else if ((Atom)e->xclient.data.l[2] ==
1389 prop_atoms.net_wm_moveresize_cancel)
1390 moveresize_end(TRUE);
1391 } else if (msgtype == prop_atoms.net_moveresize_window) {
1392 gint ograv, x, y, w, h;
1393
1394 ograv = client->gravity;
1395
1396 if (e->xclient.data.l[0] & 0xff)
1397 client->gravity = e->xclient.data.l[0] & 0xff;
1398
1399 if (e->xclient.data.l[0] & 1 << 8)
1400 x = e->xclient.data.l[1];
1401 else
1402 x = client->area.x;
1403 if (e->xclient.data.l[0] & 1 << 9)
1404 y = e->xclient.data.l[2];
1405 else
1406 y = client->area.y;
1407
1408 if (e->xclient.data.l[0] & 1 << 10) {
1409 w = e->xclient.data.l[3];
1410
1411 /* if x was not given, then use gravity to figure out the new
1412 x. the reference point should not be moved */
1413 if (!(e->xclient.data.l[0] & 1 << 8))
1414 client_gravity_resize_w(client, &x, client->area.width, w);
1415 }
1416 else
1417 w = client->area.width;
1418
1419 if (e->xclient.data.l[0] & 1 << 11) {
1420 h = e->xclient.data.l[4];
1421
1422 /* if y was not given, then use gravity to figure out the new
1423 y. the reference point should not be moved */
1424 if (!(e->xclient.data.l[0] & 1 << 9))
1425 client_gravity_resize_h(client, &y, client->area.height,h);
1426 }
1427 else
1428 h = client->area.height;
1429
1430 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1431 e->xclient.data.l[0] & 1 << 8, x,
1432 e->xclient.data.l[0] & 1 << 9, y,
1433 client->gravity);
1434
1435 client_find_onscreen(client, &x, &y, w, h, FALSE);
1436
1437 client_configure(client, x, y, w, h, FALSE, TRUE, FALSE);
1438
1439 client->gravity = ograv;
1440 } else if (msgtype == prop_atoms.net_restack_window) {
1441 if (e->xclient.data.l[0] != 2) {
1442 ob_debug_type(OB_DEBUG_APP_BUGS,
1443 "_NET_RESTACK_WINDOW sent for window %s with "
1444 "invalid source indication %ld\n",
1445 client->title, e->xclient.data.l[0]);
1446 } else {
1447 ObClient *sibling = NULL;
1448 if (e->xclient.data.l[1]) {
1449 ObWindow *win = g_hash_table_lookup
1450 (window_map, &e->xclient.data.l[1]);
1451 if (WINDOW_IS_CLIENT(win) &&
1452 WINDOW_AS_CLIENT(win) != client)
1453 {
1454 sibling = WINDOW_AS_CLIENT(win);
1455 }
1456 if (sibling == NULL)
1457 ob_debug_type(OB_DEBUG_APP_BUGS,
1458 "_NET_RESTACK_WINDOW sent for window %s "
1459 "with invalid sibling 0x%x\n",
1460 client->title, e->xclient.data.l[1]);
1461 }
1462 if (e->xclient.data.l[2] == Below ||
1463 e->xclient.data.l[2] == BottomIf ||
1464 e->xclient.data.l[2] == Above ||
1465 e->xclient.data.l[2] == TopIf ||
1466 e->xclient.data.l[2] == Opposite)
1467 {
1468 gulong ignore_start;
1469
1470 if (!config_focus_under_mouse)
1471 ignore_start = event_start_ignore_all_enters();
1472 /* just raise, don't activate */
1473 stacking_restack_request(client, sibling,
1474 e->xclient.data.l[2]);
1475 if (!config_focus_under_mouse)
1476 event_end_ignore_all_enters(ignore_start);
1477
1478 /* send a synthetic ConfigureNotify, cuz this is supposed
1479 to be like a ConfigureRequest. */
1480 client_reconfigure(client, TRUE);
1481 } else
1482 ob_debug_type(OB_DEBUG_APP_BUGS,
1483 "_NET_RESTACK_WINDOW sent for window %s "
1484 "with invalid detail %d\n",
1485 client->title, e->xclient.data.l[2]);
1486 }
1487 }
1488 break;
1489 case PropertyNotify:
1490 /* validate cuz we query stuff off the client here */
1491 if (!client_validate(client)) break;
1492
1493 /* compress changes to a single property into a single change */
1494 while (XCheckTypedWindowEvent(ob_display, client->window,
1495 e->type, &ce)) {
1496 Atom a, b;
1497
1498 /* XXX: it would be nice to compress ALL changes to a property,
1499 not just changes in a row without other props between. */
1500
1501 a = ce.xproperty.atom;
1502 b = e->xproperty.atom;
1503
1504 if (a == b)
1505 continue;
1506 if ((a == prop_atoms.net_wm_name ||
1507 a == prop_atoms.wm_name ||
1508 a == prop_atoms.net_wm_icon_name ||
1509 a == prop_atoms.wm_icon_name)
1510 &&
1511 (b == prop_atoms.net_wm_name ||
1512 b == prop_atoms.wm_name ||
1513 b == prop_atoms.net_wm_icon_name ||
1514 b == prop_atoms.wm_icon_name)) {
1515 continue;
1516 }
1517 if (a == prop_atoms.net_wm_icon &&
1518 b == prop_atoms.net_wm_icon)
1519 continue;
1520
1521 XPutBackEvent(ob_display, &ce);
1522 break;
1523 }
1524
1525 msgtype = e->xproperty.atom;
1526 if (msgtype == XA_WM_NORMAL_HINTS) {
1527 ob_debug("Update NORMAL hints\n");
1528 client_update_normal_hints(client);
1529 /* normal hints can make a window non-resizable */
1530 client_setup_decor_and_functions(client, FALSE);
1531
1532 /* make sure the client's sizes are within its bounds, but only
1533 reconfigure the window if it needs to. emacs will update its
1534 normal hints every time it receives a conigurenotify */
1535 client_reconfigure(client, FALSE);
1536 } else if (msgtype == XA_WM_HINTS) {
1537 client_update_wmhints(client);
1538 } else if (msgtype == XA_WM_TRANSIENT_FOR) {
1539 client_update_transient_for(client);
1540 client_get_type_and_transientness(client);
1541 /* type may have changed, so update the layer */
1542 client_calc_layer(client);
1543 client_setup_decor_and_functions(client, TRUE);
1544 } else if (msgtype == prop_atoms.net_wm_name ||
1545 msgtype == prop_atoms.wm_name ||
1546 msgtype == prop_atoms.net_wm_icon_name ||
1547 msgtype == prop_atoms.wm_icon_name) {
1548 client_update_title(client);
1549 } else if (msgtype == prop_atoms.wm_protocols) {
1550 client_update_protocols(client);
1551 client_setup_decor_and_functions(client, TRUE);
1552 }
1553 else if (msgtype == prop_atoms.net_wm_strut) {
1554 client_update_strut(client);
1555 }
1556 else if (msgtype == prop_atoms.net_wm_strut_partial) {
1557 client_update_strut(client);
1558 }
1559 else if (msgtype == prop_atoms.net_wm_icon) {
1560 client_update_icons(client);
1561 }
1562 else if (msgtype == prop_atoms.net_wm_icon_geometry) {
1563 client_update_icon_geometry(client);
1564 }
1565 else if (msgtype == prop_atoms.net_wm_user_time) {
1566 guint32 t;
1567 if (client == focus_client &&
1568 PROP_GET32(client->window, net_wm_user_time, cardinal, &t) &&
1569 t && !event_time_after(t, e->xproperty.time) &&
1570 (!event_last_user_time ||
1571 event_time_after(t, event_last_user_time)))
1572 {
1573 event_last_user_time = t;
1574 }
1575 }
1576 #ifdef SYNC
1577 else if (msgtype == prop_atoms.net_wm_sync_request_counter) {
1578 client_update_sync_request_counter(client);
1579 }
1580 #endif
1581 break;
1582 case ColormapNotify:
1583 client_update_colormap(client, e->xcolormap.colormap);
1584 break;
1585 default:
1586 ;
1587 #ifdef SHAPE
1588 if (extensions_shape && e->type == extensions_shape_event_basep) {
1589 client->shaped = ((XShapeEvent*)e)->shaped;
1590 frame_adjust_shape(client->frame);
1591 }
1592 #endif
1593 }
1594 }
1595
1596 static void event_handle_dock(ObDock *s, XEvent *e)
1597 {
1598 switch (e->type) {
1599 case ButtonPress:
1600 if (e->xbutton.button == 1)
1601 stacking_raise(DOCK_AS_WINDOW(s));
1602 else if (e->xbutton.button == 2)
1603 stacking_lower(DOCK_AS_WINDOW(s));
1604 break;
1605 case EnterNotify:
1606 dock_hide(FALSE);
1607 break;
1608 case LeaveNotify:
1609 /* don't hide when moving into a dock app */
1610 if (e->xcrossing.detail != NotifyInferior)
1611 dock_hide(TRUE);
1612 break;
1613 }
1614 }
1615
1616 static void event_handle_dockapp(ObDockApp *app, XEvent *e)
1617 {
1618 switch (e->type) {
1619 case MotionNotify:
1620 dock_app_drag(app, &e->xmotion);
1621 break;
1622 case UnmapNotify:
1623 if (app->ignore_unmaps) {
1624 app->ignore_unmaps--;
1625 break;
1626 }
1627 dock_remove(app, TRUE);
1628 break;
1629 case DestroyNotify:
1630 dock_remove(app, FALSE);
1631 break;
1632 case ReparentNotify:
1633 dock_remove(app, FALSE);
1634 break;
1635 case ConfigureNotify:
1636 dock_app_configure(app, e->xconfigure.width, e->xconfigure.height);
1637 break;
1638 }
1639 }
1640
1641 static ObMenuFrame* find_active_menu(void)
1642 {
1643 GList *it;
1644 ObMenuFrame *ret = NULL;
1645
1646 for (it = menu_frame_visible; it; it = g_list_next(it)) {
1647 ret = it->data;
1648 if (ret->selected)
1649 break;
1650 ret = NULL;
1651 }
1652 return ret;
1653 }
1654
1655 static ObMenuFrame* find_active_or_last_menu(void)
1656 {
1657 ObMenuFrame *ret = NULL;
1658
1659 ret = find_active_menu();
1660 if (!ret && menu_frame_visible)
1661 ret = menu_frame_visible->data;
1662 return ret;
1663 }
1664
1665 static gboolean event_handle_menu_keyboard(XEvent *ev)
1666 {
1667 guint keycode, state;
1668 gunichar unikey;
1669 ObMenuFrame *frame;
1670 gboolean ret = FALSE;
1671
1672 keycode = ev->xkey.keycode;
1673 state = ev->xkey.state;
1674 unikey = translate_unichar(keycode);
1675
1676 frame = find_active_or_last_menu();
1677 if (frame == NULL)
1678 g_assert_not_reached(); /* there is no active menu */
1679
1680 /* Allow control while going thru the menu */
1681 else if (ev->type == KeyPress && (state & ~ControlMask) == 0) {
1682 frame->got_press = TRUE;
1683
1684 if (keycode == ob_keycode(OB_KEY_ESCAPE)) {
1685 menu_frame_hide_all();
1686 ret = TRUE;
1687 }
1688
1689 else if (keycode == ob_keycode(OB_KEY_LEFT)) {
1690 /* Left goes to the parent menu */
1691 menu_frame_select(frame, NULL, TRUE);
1692 ret = TRUE;
1693 }
1694
1695 else if (keycode == ob_keycode(OB_KEY_RIGHT)) {
1696 /* Right goes to the selected submenu */
1697 if (frame->child) menu_frame_select_next(frame->child);
1698 ret = TRUE;
1699 }
1700
1701 else if (keycode == ob_keycode(OB_KEY_UP)) {
1702 menu_frame_select_previous(frame);
1703 ret = TRUE;
1704 }
1705
1706 else if (keycode == ob_keycode(OB_KEY_DOWN)) {
1707 menu_frame_select_next(frame);
1708 ret = TRUE;
1709 }
1710 }
1711
1712 /* Use KeyRelease events for running things so that the key release doesn't
1713 get sent to the focused application.
1714
1715 Allow ControlMask only, and don't bother if the menu is empty */
1716 else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 &&
1717 frame->entries && frame->got_press)
1718 {
1719 if (keycode == ob_keycode(OB_KEY_RETURN)) {
1720 /* Enter runs the active item or goes into the submenu.
1721 Control-Enter runs it without closing the menu. */
1722 if (frame->child)
1723 menu_frame_select_next(frame->child);
1724 else if (frame->selected)
1725 menu_entry_frame_execute(frame->selected, state);
1726
1727 ret = TRUE;
1728 }
1729
1730 /* keyboard accelerator shortcuts. (if it was a valid key) */
1731 else if (unikey != 0) {
1732 GList *start;
1733 GList *it;
1734 ObMenuEntryFrame *found = NULL;
1735 guint num_found = 0;
1736
1737 /* start after the selected one */
1738 start = frame->entries;
1739 if (frame->selected) {
1740 for (it = start; frame->selected != it->data;
1741 it = g_list_next(it))
1742 g_assert(it != NULL); /* nothing was selected? */
1743 /* next with wraparound */
1744 start = g_list_next(it);
1745 if (start == NULL) start = frame->entries;
1746 }
1747
1748 it = start;
1749 do {
1750 ObMenuEntryFrame *e = it->data;
1751 gunichar entrykey = 0;
1752
1753 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
1754 entrykey = e->entry->data.normal.shortcut;
1755 else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
1756 entrykey = e->entry->data.submenu.submenu->shortcut;
1757
1758 if (unikey == entrykey) {
1759 if (found == NULL) found = e;
1760 ++num_found;
1761 }
1762
1763 /* next with wraparound */
1764 it = g_list_next(it);
1765 if (it == NULL) it = frame->entries;
1766 } while (it != start);
1767
1768 if (found) {
1769 if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
1770 num_found == 1)
1771 {
1772 menu_frame_select(frame, found, TRUE);
1773 usleep(50000); /* highlight the item for a short bit so the
1774 user can see what happened */
1775 menu_entry_frame_execute(found, state);
1776 } else {
1777 menu_frame_select(frame, found, TRUE);
1778 if (num_found == 1)
1779 menu_frame_select_next(frame->child);
1780 }
1781
1782 ret = TRUE;
1783 }
1784 }
1785 }
1786
1787 return ret;
1788 }
1789
1790 static gboolean event_handle_menu(XEvent *ev)
1791 {
1792 ObMenuFrame *f;
1793 ObMenuEntryFrame *e;
1794 gboolean ret = TRUE;
1795
1796 switch (ev->type) {
1797 case ButtonRelease:
1798 if (menu_hide_delay_reached() &&
1799 (ev->xbutton.button < 4 || ev->xbutton.button > 5))
1800 {
1801 if ((e = menu_entry_frame_under(ev->xbutton.x_root,
1802 ev->xbutton.y_root)))
1803 {
1804 menu_frame_select(e->frame, e, TRUE);
1805 menu_entry_frame_execute(e, ev->xbutton.state);
1806 }
1807 else
1808 menu_frame_hide_all();
1809 }
1810 break;
1811 case EnterNotify:
1812 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
1813 if (e->ignore_enters)
1814 --e->ignore_enters;
1815 else if (!(f = find_active_menu()) ||
1816 f == e->frame ||
1817 f->parent == e->frame ||
1818 f->child == e->frame)
1819 menu_frame_select(e->frame, e, FALSE);
1820 }
1821 break;
1822 case LeaveNotify:
1823 /*ignore leaves when we're already in the window */
1824 if (ev->xcrossing.detail == NotifyInferior)
1825 break;
1826
1827 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
1828 (f = find_active_menu()) && f->selected == e &&
1829 e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
1830 {
1831 menu_frame_select(e->frame, NULL, FALSE);
1832 }
1833 break;
1834 case MotionNotify:
1835 if ((e = menu_entry_frame_under(ev->xmotion.x_root,
1836 ev->xmotion.y_root)))
1837 if (!(f = find_active_menu()) ||
1838 f == e->frame ||
1839 f->parent == e->frame ||
1840 f->child == e->frame)
1841 menu_frame_select(e->frame, e, FALSE);
1842 break;
1843 case KeyPress:
1844 case KeyRelease:
1845 ret = event_handle_menu_keyboard(ev);
1846 break;
1847 }
1848 return ret;
1849 }
1850
1851 static void event_handle_user_input(ObClient *client, XEvent *e)
1852 {
1853 g_assert(e->type == ButtonPress || e->type == ButtonRelease ||
1854 e->type == MotionNotify || e->type == KeyPress ||
1855 e->type == KeyRelease);
1856
1857 if (menu_frame_visible) {
1858 if (event_handle_menu(e))
1859 /* don't use the event if the menu used it, but if the menu
1860 didn't use it and it's a keypress that is bound, it will
1861 close the menu and be used */
1862 return;
1863 }
1864
1865 /* if the keyboard interactive action uses the event then dont
1866 use it for bindings. likewise is moveresize uses the event. */
1867 if (!actions_interactive_input_event(e) && !moveresize_event(e)) {
1868 if (moveresize_in_progress)
1869 /* make further actions work on the client being
1870 moved/resized */
1871 client = moveresize_client;
1872
1873 if (e->type == ButtonPress ||
1874 e->type == ButtonRelease ||
1875 e->type == MotionNotify)
1876 {
1877 /* the frame may not be "visible" but they can still click on it
1878 in the case where it is animating before disappearing */
1879 if (!client || !frame_iconify_animating(client->frame))
1880 mouse_event(client, e);
1881 } else
1882 keyboard_event((focus_cycle_target ? focus_cycle_target :
1883 (client ? client : focus_client)), e);
1884 }
1885 }
1886
1887 static void focus_delay_dest(gpointer data)
1888 {
1889 g_free(data);
1890 }
1891
1892 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2)
1893 {
1894 const ObFocusDelayData *f1 = d1;
1895 return f1->client == d2;
1896 }
1897
1898 static gboolean focus_delay_func(gpointer data)
1899 {
1900 ObFocusDelayData *d = data;
1901 Time old = event_curtime;
1902
1903 /* don't move focus and kill the menu or the move/resize */
1904 if (menu_frame_visible || moveresize_in_progress) return FALSE;
1905
1906 event_curtime = d->time;
1907 event_curserial = d->serial;
1908 if (client_focus(d->client) && config_focus_raise)
1909 stacking_raise(CLIENT_AS_WINDOW(d->client));
1910 event_curtime = old;
1911 return FALSE; /* no repeat */
1912 }
1913
1914 static void focus_delay_client_dest(ObClient *client, gpointer data)
1915 {
1916 ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
1917 client, FALSE);
1918 }
1919
1920 void event_halt_focus_delay(void)
1921 {
1922 /* ignore all enter events up till the event which caused this to occur */
1923 if (event_curserial) event_ignore_enter_range(1, event_curserial);
1924 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
1925 }
1926
1927 gulong event_start_ignore_all_enters(void)
1928 {
1929 return NextRequest(ob_display);
1930 }
1931
1932 static void event_ignore_enter_range(gulong start, gulong end)
1933 {
1934 ObSerialRange *r;
1935
1936 g_assert(start != 0);
1937 g_assert(end != 0);
1938
1939 r = g_new(ObSerialRange, 1);
1940 r->start = start;
1941 r->end = end;
1942 ignore_serials = g_slist_prepend(ignore_serials, r);
1943
1944 ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu\n",
1945 r->start, r->end);
1946
1947 /* increment the serial so we don't ignore events we weren't meant to */
1948 PROP_ERASE(screen_support_win, motif_wm_hints);
1949 }
1950
1951 void event_end_ignore_all_enters(gulong start)
1952 {
1953 /* Use (NextRequest-1) so that we ignore up to the current serial only.
1954 Inside event_ignore_enter_range, we increment the serial by one, but if
1955 we ignore that serial too, then any enter events generated by mouse
1956 movement will be ignored until we create some further network traffic.
1957 Instead ignore up to NextRequest-1, then when we increment the serial,
1958 we will be *past* the range of ignored serials */
1959 event_ignore_enter_range(start, NextRequest(ob_display)-1);
1960 }
1961
1962 static gboolean is_enter_focus_event_ignored(XEvent *e)
1963 {
1964 GSList *it, *next;
1965
1966 g_assert(e->type == EnterNotify &&
1967 !(e->xcrossing.mode == NotifyGrab ||
1968 e->xcrossing.mode == NotifyUngrab ||
1969 e->xcrossing.detail == NotifyInferior));
1970
1971 for (it = ignore_serials; it; it = next) {
1972 ObSerialRange *r = it->data;
1973
1974 next = g_slist_next(it);
1975
1976 if ((glong)(e->xany.serial - r->end) > 0) {
1977 /* past the end */
1978 ignore_serials = g_slist_delete_link(ignore_serials, it);
1979 g_free(r);
1980 }
1981 else if ((glong)(e->xany.serial - r->start) >= 0)
1982 return TRUE;
1983 }
1984 return FALSE;
1985 }
1986
1987 void event_cancel_all_key_grabs(void)
1988 {
1989 if (actions_interactive_act_running()) {
1990 actions_interactive_cancel_act();
1991 ob_debug("KILLED interactive action\n");
1992 }
1993 else if (menu_frame_visible) {
1994 menu_frame_hide_all();
1995 ob_debug("KILLED open menus\n");
1996 }
1997 else if (moveresize_in_progress) {
1998 moveresize_end(TRUE);
1999 ob_debug("KILLED interactive moveresize\n");
2000 }
2001 else if (grab_on_keyboard()) {
2002 ungrab_keyboard();
2003 ob_debug("KILLED active grab on keyboard\n");
2004 }
2005 else
2006 ungrab_passive_key();
2007
2008 XSync(ob_display, FALSE);
2009 }
2010
2011 gboolean event_time_after(Time t1, Time t2)
2012 {
2013 g_assert(t1 != CurrentTime);
2014 g_assert(t2 != CurrentTime);
2015
2016 /*
2017 Timestamp values wrap around (after about 49.7 days). The server, given
2018 its current time is represented by timestamp T, always interprets
2019 timestamps from clients by treating half of the timestamp space as being
2020 later in time than T.
2021 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2022 */
2023
2024 /* TIME_HALF is half of the number space of a Time type variable */
2025 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2026
2027 if (t2 >= TIME_HALF)
2028 /* t2 is in the second half so t1 might wrap around and be smaller than
2029 t2 */
2030 return t1 >= t2 || t1 < (t2 + TIME_HALF);
2031 else
2032 /* t2 is in the first half so t1 has to come after it */
2033 return t1 >= t2 && t1 < (t2 + TIME_HALF);
2034 }
2035
2036 Time event_get_server_time(void)
2037 {
2038 /* Generate a timestamp */
2039 XEvent event;
2040
2041 XChangeProperty(ob_display, screen_support_win,
2042 prop_atoms.wm_class, prop_atoms.string,
2043 8, PropModeAppend, NULL, 0);
2044 XWindowEvent(ob_display, screen_support_win, PropertyChangeMask, &event);
2045 return event.xproperty.time;
2046 }
This page took 0.121708 seconds and 5 git commands to generate.