Update for 0.51.2-pre2
[wmaker-crm.git] / src / event.c
blob5c9d8402f36aca376fd758e75818b83b46ffcf29
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
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.
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.
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 02111-1307,
20 * USA.
24 #include "wconfig.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
32 #include <X11/Xlib.h>
33 #include <X11/Xutil.h>
34 #ifdef SHAPE
35 #include <X11/extensions/shape.h>
36 #endif
37 #ifdef XDE_DND
38 #include "xde.h"
39 #endif
41 #ifdef KEEP_XKB_LOCK_STATUS
42 #include <X11/XKBlib.h>
43 #endif /* KEEP_XKB_LOCK_STATUS */
45 #include "WindowMaker.h"
46 #include "window.h"
47 #include "actions.h"
48 #include "client.h"
49 #include "funcs.h"
50 #include "keybind.h"
51 #include "application.h"
52 #include "stacking.h"
53 #include "defaults.h"
54 #include "workspace.h"
55 #include "dock.h"
56 #include "framewin.h"
57 #include "properties.h"
58 #include "balloon.h"
59 #ifdef GNOME_STUFF
60 # include "gnome.h"
61 #endif
62 #ifdef KWM_HINTS
63 # include "kwm.h"
64 #endif
66 /******** Global Variables **********/
67 extern XContext wWinContext;
69 extern Cursor wCursor[WCUR_LAST];
71 extern WShortKey wKeyBindings[WKBD_LAST];
72 extern int wScreenCount;
73 extern Time LastTimestamp;
74 extern Time LastFocusChange;
76 extern WPreferences wPreferences;
78 #define MOD_MASK wPreferences.modifier_mask
80 extern Atom _XA_WM_COLORMAP_NOTIFY;
82 extern Atom _XA_WM_CHANGE_STATE;
83 extern Atom _XA_WM_DELETE_WINDOW;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
85 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
87 #ifdef OFFIX_DND
88 extern Atom _XA_DND_PROTOCOL;
89 #endif
92 #ifdef SHAPE
93 extern Bool wShapeSupported;
94 extern int wShapeEventBase;
95 #endif
97 /* special flags */
98 extern char WDelayedActionSet;
101 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent *event);
105 static void handleColormapNotify();
106 static void handleMapNotify(), handleUnmapNotify();
107 static void handleButtonPress(), handleExpose();
108 static void handleDestroyNotify();
109 static void handleConfigureRequest();
110 static void handleMapRequest();
111 static void handlePropertyNotify();
112 static void handleEnterNotify();
113 static void handleLeaveNotify();
114 static void handleExtensions();
115 static void handleClientMessage();
116 static void handleKeyPress();
117 static void handleFocusIn();
118 static void handleMotionNotify();
119 static void handleVisibilityNotify();
122 #ifdef SHAPE
123 static void handleShapeNotify();
124 #endif
126 /* called from the signal handler */
127 void NotifyDeadProcess(pid_t pid, unsigned char status);
129 /* real dead process handler */
130 static void handleDeadProcess(void *foo);
133 typedef struct DeadProcesses {
134 pid_t pid;
135 unsigned char exit_status;
136 } DeadProcesses;
138 /* stack of dead processes */
139 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
140 static int deadProcessPtr=0;
143 typedef struct DeathHandler {
144 WDeathHandler *callback;
145 pid_t pid;
146 struct DeathHandler *next;
147 void *client_data;
148 } DeathHandler;
150 static DeathHandler *deathHandler=NULL;
154 WMagicNumber
155 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
157 DeathHandler *handler;
159 handler = malloc(sizeof(DeathHandler));
160 if (!handler)
161 return 0;
163 handler->pid = pid;
164 handler->callback = callback;
165 handler->client_data = cdata;
167 handler->next = deathHandler;
169 deathHandler = handler;
171 return handler;
176 void
177 wDeleteDeathHandler(WMagicNumber id)
179 DeathHandler *tmp, *handler=(DeathHandler*)id;
181 if (!handler || !deathHandler)
182 return;
184 tmp = deathHandler;
185 if (tmp==handler) {
186 deathHandler = handler->next;
187 free(handler);
188 } else {
189 while (tmp->next) {
190 if (tmp->next==handler) {
191 tmp->next=handler->next;
192 free(handler);
193 break;
195 tmp = tmp->next;
201 void
202 DispatchEvent(XEvent *event)
204 if (deathHandler)
205 handleDeadProcess(NULL);
207 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
208 WCHANGE_STATE(WSTATE_EXITING);
209 /* received SIGTERM */
211 * WMHandleEvent() can't be called from anything
212 * executed inside here, or we can get in a infinite
213 * recursive loop.
215 Shutdown(WSExitMode);
217 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
218 WCHANGE_STATE(WSTATE_RESTARTING);
220 Shutdown(WSRestartPreparationMode);
221 /* received SIGHUP */
222 Restart(NULL);
225 /* for the case that all that is wanted to be dispatched is
226 * the stuff above */
227 if (!event)
228 return;
230 saveTimestamp(event);
231 switch (event->type) {
232 case MapRequest:
233 handleMapRequest(event);
234 break;
236 case KeyPress:
237 handleKeyPress(event);
238 break;
240 case MotionNotify:
241 handleMotionNotify(event);
242 break;
244 case ConfigureRequest:
245 handleConfigureRequest(event);
246 break;
248 case DestroyNotify:
249 handleDestroyNotify(event);
250 break;
252 case MapNotify:
253 handleMapNotify(event);
254 break;
256 case UnmapNotify:
257 handleUnmapNotify(event);
258 break;
260 case ButtonPress:
261 handleButtonPress(event);
262 break;
264 case Expose:
265 handleExpose(event);
266 break;
268 case PropertyNotify:
269 handlePropertyNotify(event);
270 break;
272 case EnterNotify:
273 handleEnterNotify(event);
274 break;
276 case LeaveNotify:
277 handleLeaveNotify(event);
278 break;
280 case ClientMessage:
281 handleClientMessage(event);
282 break;
284 case ColormapNotify:
285 handleColormapNotify(event);
286 break;
288 case MappingNotify:
289 if (event->xmapping.request == MappingKeyboard
290 || event->xmapping.request == MappingModifier)
291 XRefreshKeyboardMapping(&event->xmapping);
292 break;
294 case FocusIn:
295 handleFocusIn(event);
296 break;
298 case VisibilityNotify:
299 handleVisibilityNotify(event);
300 break;
302 default:
303 handleExtensions(event);
304 break;
310 *----------------------------------------------------------------------
311 * EventLoop-
312 * Processes X and internal events indefinitely.
314 * Returns:
315 * Never returns
317 * Side effects:
318 * The LastTimestamp global variable is updated.
319 *----------------------------------------------------------------------
321 void
322 EventLoop()
324 XEvent event;
326 for(;;) {
327 WMNextEvent(dpy, &event);
328 WMHandleEvent(&event);
334 Bool
335 IsDoubleClick(WScreen *scr, XEvent *event)
337 if ((scr->last_click_time>0) &&
338 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
339 && (event->xbutton.button == scr->last_click_button)
340 && (event->xbutton.window == scr->last_click_window)) {
342 scr->flags.next_click_is_not_double = 1;
343 scr->last_click_time = 0;
344 scr->last_click_window = event->xbutton.window;
346 return True;
348 return False;
352 void
353 NotifyDeadProcess(pid_t pid, unsigned char status)
355 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
356 wwarning("stack overflow: too many dead processes");
357 return;
359 /* stack the process to be handled later,
360 * as this is called from the signal handler */
361 deadProcesses[deadProcessPtr].pid = pid;
362 deadProcesses[deadProcessPtr].exit_status = status;
363 deadProcessPtr++;
367 static void
368 handleDeadProcess(void *foo)
370 DeathHandler *tmp;
371 int i;
373 for (i=0; i<deadProcessPtr; i++) {
374 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
377 if (!deathHandler) {
378 deadProcessPtr=0;
379 return;
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr>0) {
384 deadProcessPtr--;
386 tmp = deathHandler;
387 while (tmp) {
388 DeathHandler *t;
390 t = tmp->next;
392 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
393 (*tmp->callback)(tmp->pid,
394 deadProcesses[deadProcessPtr].exit_status,
395 tmp->client_data);
396 wDeleteDeathHandler(tmp);
398 tmp = t;
404 static void
405 saveTimestamp(XEvent *event)
407 LastTimestamp = CurrentTime;
409 switch (event->type) {
410 case ButtonRelease:
411 case ButtonPress:
412 LastTimestamp = event->xbutton.time;
413 break;
414 case KeyPress:
415 case KeyRelease:
416 LastTimestamp = event->xkey.time;
417 break;
418 case MotionNotify:
419 LastTimestamp = event->xmotion.time;
420 break;
421 case PropertyNotify:
422 LastTimestamp = event->xproperty.time;
423 break;
424 case EnterNotify:
425 case LeaveNotify:
426 LastTimestamp = event->xcrossing.time;
427 break;
428 case SelectionClear:
429 LastTimestamp = event->xselectionclear.time;
430 break;
431 case SelectionRequest:
432 LastTimestamp = event->xselectionrequest.time;
433 break;
434 case SelectionNotify:
435 LastTimestamp = event->xselection.time;
436 break;
441 static void
442 handleExtensions(XEvent *event)
444 #ifdef SHAPE
445 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
446 handleShapeNotify(event);
448 #endif
452 static void
453 handleMapRequest(XEvent *ev)
455 WWindow *wwin;
456 WScreen *scr = NULL;
457 Window window = ev->xmaprequest.window;
459 #ifdef DEBUG
460 printf("got map request for %x\n", (unsigned)window);
461 #endif
463 if ((wwin = wWindowFor(window))) {
464 if (wwin->flags.shaded) {
465 wUnshadeWindow(wwin);
467 /* deiconify window */
468 if (wwin->flags.miniaturized) {
469 wDeiconifyWindow(wwin);
470 } else if (wwin->flags.hidden) {
471 WApplication *wapp = wApplicationOf(wwin->main_window);
472 /* go to the last workspace that the user worked on the app */
473 #ifndef REDUCE_APPICONS
474 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
475 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
477 if (wapp) {
478 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
480 #endif
481 wUnhideApplication(wapp, False, False);
483 return;
486 scr = wScreenForRootWindow(ev->xmaprequest.parent);
488 wwin = wManageWindow(scr, window);
491 * This is to let the Dock know that the application it launched
492 * has already been mapped (eg: it has finished launching).
493 * It is not necessary for normally docked apps, but is needed for
494 * apps that were forcedly docked (like with dockit).
496 if (scr->last_dock) {
497 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
498 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
499 else
500 wDockTrackWindowLaunch(scr->last_dock, window);
503 if (wwin) {
504 wClientSetState(wwin, NormalState, None);
505 if (wwin->flags.maximized) {
506 wMaximizeWindow(wwin, wwin->flags.maximized);
508 if (wwin->flags.shaded) {
509 wwin->flags.shaded = 0;
510 wwin->flags.skip_next_animation = 1;
511 wShadeWindow(wwin);
513 if (wwin->flags.miniaturized) {
514 wwin->flags.miniaturized = 0;
515 wwin->flags.skip_next_animation = 1;
516 wIconifyWindow(wwin);
518 if (wwin->flags.hidden) {
519 WApplication *wapp = wApplicationOf(wwin->main_window);
521 wwin->flags.hidden = 0;
522 wwin->flags.skip_next_animation = 1;
523 if (wapp) {
524 wHideApplication(wapp);
531 static void
532 handleDestroyNotify(XEvent *event)
534 WWindow *wwin;
535 WApplication *app;
536 Window window = event->xdestroywindow.window;
538 #ifdef DEBUG
539 puts("got destroy notify");
540 #endif
542 wwin = wWindowFor(window);
543 if (wwin) {
544 wUnmanageWindow(wwin, False, True);
547 app = wApplicationOf(window);
548 if (app) {
549 if (window == app->main_window) {
550 app->refcount = 0;
551 wwin = app->main_window_desc->screen_ptr->focused_window;
552 while (wwin) {
553 if (wwin->main_window == window) {
554 wwin->main_window = None;
556 wwin = wwin->prev;
559 wApplicationDestroy(app);
562 #ifdef KWM_HINTS
563 wKWMCheckDestroy(&event->xdestroywindow);
564 #endif
569 static void
570 handleExpose(XEvent *event)
572 WObjDescriptor *desc;
573 XEvent ev;
575 #ifdef DEBUG
576 puts("got expose");
577 #endif
579 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
581 if (XFindContext(dpy, event->xexpose.window, wWinContext,
582 (XPointer *)&desc)==XCNOENT) {
583 return;
586 if (desc->handle_expose) {
587 (*desc->handle_expose)(desc, event);
592 /* bindable */
593 static void
594 handleButtonPress(XEvent *event)
596 WObjDescriptor *desc;
597 WScreen *scr;
599 #ifdef DEBUG
600 puts("got button press");
601 #endif
603 scr = wScreenForRootWindow(event->xbutton.root);
605 #ifdef BALLOON_TEXT
606 wBalloonHide(scr);
607 #endif
610 #ifndef LITE
611 if (event->xbutton.window==scr->root_win) {
613 #ifdef GNOME_STUFF
614 if (wGNOMEProxyizeButtonEvent(scr, event))
615 return;
616 #endif
618 if (event->xbutton.button==wPreferences.menu_button) {
619 OpenRootMenu(scr, event->xbutton.x_root,
620 event->xbutton.y_root, False);
621 /* ugly hack */
622 if (scr->root_menu) {
623 if (scr->root_menu->brother->flags.mapped)
624 event->xbutton.window = scr->root_menu->brother->frame->core->window;
625 else
626 event->xbutton.window = scr->root_menu->frame->core->window;
628 } else if (event->xbutton.button==wPreferences.windowl_button) {
629 OpenSwitchMenu(scr, event->xbutton.x_root,
630 event->xbutton.y_root, False);
631 if (scr->switch_menu) {
632 if (scr->switch_menu->brother->flags.mapped)
633 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
634 else
635 event->xbutton.window = scr->switch_menu->frame->core->window;
637 } else if (event->xbutton.button==wPreferences.select_button) {
638 wUnselectWindows(scr);
639 wSelectWindows(scr, event);
641 #ifdef MOUSE_WS_SWITCH
642 else if (event->xbutton.button==Button4) {
644 wWorkspaceRelativeChange(scr, -1);
646 } else if (event->xbutton.button==Button5) {
648 wWorkspaceRelativeChange(scr, 1);
651 #endif /* MOUSE_WS_SWITCH */
653 #endif /* !LITE */
655 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
656 (XPointer *)&desc)==XCNOENT) {
657 if (XFindContext(dpy, event->xbutton.window, wWinContext,
658 (XPointer *)&desc)==XCNOENT) {
659 return;
663 if (desc->handle_mousedown!=NULL) {
664 (*desc->handle_mousedown)(desc, event);
667 if (desc->parent_type == WCLASS_WINDOW) {
668 XSync(dpy, 0);
670 if (event->xbutton.state & MOD_MASK) {
671 XAllowEvents(dpy, AsyncPointer, CurrentTime);
674 if (wPreferences.focus_mode == WKF_CLICK) {
675 if (wPreferences.ignore_focus_click) {
676 XAllowEvents(dpy, AsyncPointer, CurrentTime);
678 XAllowEvents(dpy, ReplayPointer, CurrentTime);
680 XSync(dpy, 0);
681 } else if (desc->parent_type == WCLASS_APPICON
682 || desc->parent_type == WCLASS_MINIWINDOW
683 || desc->parent_type == WCLASS_DOCK_ICON) {
684 if (event->xbutton.state & MOD_MASK) {
685 XSync(dpy, 0);
686 XAllowEvents(dpy, AsyncPointer, CurrentTime);
687 XSync(dpy, 0);
691 /* save double-click information */
692 if (scr->flags.next_click_is_not_double) {
693 scr->flags.next_click_is_not_double = 0;
694 } else {
695 scr->last_click_time = event->xbutton.time;
696 scr->last_click_button = event->xbutton.button;
697 scr->last_click_window = event->xbutton.window;
702 static void
703 handleMapNotify(XEvent *event)
705 WWindow *wwin;
707 #ifdef DEBUG
708 puts("got map");
709 #endif
711 wwin = wWindowFor(event->xmap.event);
712 if (wwin && wwin->client_win == event->xmap.event) {
713 if (wwin->flags.miniaturized) {
714 wDeiconifyWindow(wwin);
715 } else {
716 XGrabServer(dpy);
717 wWindowMap(wwin);
718 wClientSetState(wwin, NormalState, None);
719 XUngrabServer(dpy);
725 static void
726 handleUnmapNotify(XEvent *event)
728 WWindow *wwin;
729 XEvent ev;
730 Bool withdraw = False;
732 #ifdef DEBUG
733 puts("got unmap");
734 #endif
736 /* only process windows with StructureNotify selected
737 * (ignore SubstructureNotify) */
738 wwin = wWindowFor(event->xunmap.window);
739 if (!wwin)
740 return;
742 /* whether the event is a Withdrawal request */
743 if (event->xunmap.event == wwin->screen_ptr->root_win
744 && event->xunmap.send_event)
745 withdraw = True;
747 if (wwin->client_win != event->xunmap.event && !withdraw)
748 return;
750 if (!wwin->flags.mapped && !withdraw
751 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
752 && !wwin->flags.miniaturized && !wwin->flags.hidden)
753 return;
755 XGrabServer(dpy);
756 XUnmapWindow(dpy, wwin->frame->core->window);
757 wwin->flags.mapped = 0;
758 XSync(dpy, 0);
759 /* check if the window was destroyed */
760 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
761 DispatchEvent(&ev);
762 } else {
763 Bool reparented = False;
765 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
766 reparented = True;
768 /* withdraw window */
769 wwin->flags.mapped = 0;
770 if (!reparented)
771 wClientSetState(wwin, WithdrawnState, None);
773 /* if the window was reparented, do not reparent it back to the
774 * root window */
775 wUnmanageWindow(wwin, !reparented, False);
777 XUngrabServer(dpy);
781 static void
782 handleConfigureRequest(XEvent *event)
784 WWindow *wwin;
786 #ifdef DEBUG
787 puts("got configure request");
788 #endif
789 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
791 * Configure request for unmapped window
793 wClientConfigure(NULL, &(event->xconfigurerequest));
794 } else {
795 wClientConfigure(wwin, &(event->xconfigurerequest));
800 static void
801 handlePropertyNotify(XEvent *event)
803 WWindow *wwin;
804 WApplication *wapp;
805 Window jr;
806 int ji;
807 unsigned int ju;
808 WScreen *scr;
810 #ifdef DEBUG
811 puts("got property notify");
812 #endif
813 if ((wwin=wWindowFor(event->xproperty.window))) {
814 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
815 &ju, &ju, &ju, &ju)) {
816 return;
818 wClientCheckProperty(wwin, &event->xproperty);
820 wapp = wApplicationOf(event->xproperty.window);
821 if (wapp) {
822 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
825 scr = wScreenForWindow(event->xproperty.window);
826 if (scr && scr->root_win == event->xproperty.window) {
827 #ifdef KWM_HINTS
828 wKWMCheckRootHintChange(scr, &event->xproperty);
829 #endif
834 static void
835 handleClientMessage(XEvent *event)
837 WWindow *wwin;
838 WObjDescriptor *desc;
840 #ifdef DEBUG
841 puts("got client message");
842 #endif
843 /* handle transition from Normal to Iconic state */
844 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
845 && event->xclient.format == 32
846 && event->xclient.data.l[0] == IconicState) {
848 wwin = wWindowFor(event->xclient.window);
849 if (!wwin) return;
850 if (!wwin->flags.miniaturized)
851 wIconifyWindow(wwin);
852 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
853 && event->xclient.format == 32) {
854 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
856 if (!scr)
857 return;
859 if (event->xclient.data.l[1] == 1) { /* starting */
860 wColormapAllowClientInstallation(scr, True);
861 } else { /* stopping */
862 wColormapAllowClientInstallation(scr, False);
864 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
865 WApplication *wapp;
866 int done=0;
867 wapp = wApplicationOf(event->xclient.window);
868 if (wapp) {
869 switch (event->xclient.data.l[0]) {
870 case WMFHideOtherApplications:
871 wHideOtherApplications(wapp->main_window_desc);
872 done = 1;
873 break;
875 case WMFHideApplication:
876 wHideApplication(wapp);
877 done = 1;
878 break;
881 if (!done) {
882 wwin = wWindowFor(event->xclient.window);
883 if (wwin) {
884 switch (event->xclient.data.l[0]) {
885 case WMFHideOtherApplications:
886 wHideOtherApplications(wwin);
887 break;
889 case WMFHideApplication:
890 wHideApplication(wApplicationOf(wwin->main_window));
891 break;
895 #ifdef GNOME_STUFF
896 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
897 /* do nothing */
898 #endif /* GNOME_STUFF */
899 #ifdef KWM_HINTS
900 } else if (wKWMProcessClientMessage(&event->xclient)) {
901 /* do nothing */
902 #endif /* KWM_HINTS */
903 #ifdef XDE_DND
904 } else if (wXDEProcessClientMessage(&event->xclient)) {
905 /* do nothing */
906 #endif /* XDE_DND */
907 #ifdef OFFIX_DND
908 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
909 WScreen *scr = wScreenForWindow(event->xclient.window);
910 if (scr && wDockReceiveDNDDrop(scr,event))
911 goto redirect_message;
912 #endif /* OFFIX_DND */
913 } else {
914 #ifdef OFFIX_DND
915 redirect_message:
916 #endif
918 * Non-standard thing, but needed by OffiX DND.
919 * For when the icon frame gets a ClientMessage
920 * that should have gone to the icon_window.
922 if (XFindContext(dpy, event->xbutton.window, wWinContext,
923 (XPointer *)&desc)!=XCNOENT) {
924 struct WIcon *icon=NULL;
926 if (desc->parent_type == WCLASS_MINIWINDOW) {
927 icon = (WIcon*)desc->parent;
928 } else if (desc->parent_type == WCLASS_DOCK_ICON
929 || desc->parent_type == WCLASS_APPICON) {
930 icon = ((WAppIcon*)desc->parent)->icon;
932 if (icon && (wwin=icon->owner)) {
933 if (wwin->client_win!=event->xclient.window) {
934 event->xclient.window = wwin->client_win;
935 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
936 event);
944 static void
945 raiseWindow(WScreen *scr)
947 WWindow *wwin;
949 scr->autoRaiseTimer = NULL;
951 wwin = wWindowFor(scr->autoRaiseWindow);
952 if (!wwin)
953 return;
955 if (!wwin->flags.destroyed) {
956 wRaiseFrame(wwin->frame->core);
957 /* this is needed or a race condition will occur */
958 XSync(dpy, False);
963 static void
964 handleEnterNotify(XEvent *event)
966 WWindow *wwin;
967 WObjDescriptor *desc = NULL;
968 XEvent ev;
969 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
972 #ifdef DEBUG
973 puts("got enter notify");
974 #endif
976 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
977 &ev)) {
978 /* already left the window... */
979 saveTimestamp(&ev);
980 if (ev.xcrossing.mode==event->xcrossing.mode
981 && ev.xcrossing.detail==event->xcrossing.detail) {
982 return;
986 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
987 (XPointer *)&desc)!=XCNOENT) {
988 if(desc->handle_enternotify)
989 (*desc->handle_enternotify)(desc, event);
992 /* enter to window */
993 wwin = wWindowFor(event->xcrossing.window);
994 if (!wwin) {
995 if (wPreferences.focus_mode==WKF_POINTER
996 && event->xcrossing.window==event->xcrossing.root) {
997 wSetFocusTo(scr, NULL);
999 if (wPreferences.colormap_mode==WKF_POINTER) {
1000 wColormapInstallForWindow(scr, NULL);
1002 if (scr->autoRaiseTimer
1003 && event->xcrossing.root==event->xcrossing.window) {
1004 WMDeleteTimerHandler(scr->autoRaiseTimer);
1005 scr->autoRaiseTimer = NULL;
1007 } else {
1008 /* set auto raise timer even if in focus-follows-mouse mode
1009 * and the event is for the frame window, even if the window
1010 * has focus already. useful if you move the pointer from a focused
1011 * window to the root window and back pretty fast
1013 * set focus if in focus-follows-mouse mode and the event
1014 * is for the frame window and window doesn't have focus yet */
1015 if ((wPreferences.focus_mode==WKF_POINTER
1016 || wPreferences.focus_mode==WKF_SLOPPY)
1017 && wwin->frame->core->window==event->xcrossing.window
1018 && !scr->flags.doing_alt_tab) {
1020 if (!wwin->flags.focused)
1021 wSetFocusTo(scr, wwin);
1023 if (scr->autoRaiseTimer)
1024 WMDeleteTimerHandler(scr->autoRaiseTimer);
1025 scr->autoRaiseTimer = NULL;
1027 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1028 scr->autoRaiseWindow = wwin->frame->core->window;
1029 scr->autoRaiseTimer
1030 = WMAddTimerHandler(wPreferences.raise_delay,
1031 (WMCallback*)raiseWindow, scr);
1034 /* Install colormap for window, if the colormap installation mode
1035 * is colormap_follows_mouse */
1036 if (wPreferences.colormap_mode==WKF_POINTER) {
1037 if (wwin->client_win==event->xcrossing.window)
1038 wColormapInstallForWindow(scr, wwin);
1039 else
1040 wColormapInstallForWindow(scr, NULL);
1044 /* a little kluge to hide the clip balloon */
1045 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1046 if (!desc) {
1047 XUnmapWindow(dpy, scr->clip_balloon);
1048 scr->flags.clip_balloon_mapped = 0;
1049 } else {
1050 if (desc->parent_type!=WCLASS_DOCK_ICON
1051 || scr->clip_icon != desc->parent) {
1052 XUnmapWindow(dpy, scr->clip_balloon);
1053 scr->flags.clip_balloon_mapped = 0;
1058 if (event->xcrossing.window == event->xcrossing.root
1059 && event->xcrossing.detail == NotifyNormal
1060 && event->xcrossing.detail != NotifyInferior
1061 && wPreferences.focus_mode != WKF_CLICK) {
1063 wSetFocusTo(scr, scr->focused_window);
1066 #ifdef BALLOON_TEXT
1067 wBalloonEnteredObject(scr, desc);
1068 #endif
1072 static void
1073 handleLeaveNotify(XEvent *event)
1075 WObjDescriptor *desc = NULL;
1077 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1078 (XPointer *)&desc)!=XCNOENT) {
1079 if(desc->handle_leavenotify)
1080 (*desc->handle_leavenotify)(desc, event);
1082 if (event->xcrossing.window == event->xcrossing.root
1083 && event->xcrossing.mode == NotifyNormal
1084 && event->xcrossing.detail != NotifyInferior
1085 && wPreferences.focus_mode != WKF_CLICK) {
1087 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1089 wSetFocusTo(scr, NULL);
1094 #ifdef SHAPE
1095 static void
1096 handleShapeNotify(XEvent *event)
1098 XShapeEvent *shev = (XShapeEvent*)event;
1099 WWindow *wwin;
1100 XEvent ev;
1102 #ifdef DEBUG
1103 puts("got shape notify");
1104 #endif
1106 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1107 XShapeEvent *sev = (XShapeEvent*)&ev;
1109 if (sev->kind == ShapeBounding) {
1110 if (sev->shaped == shev->shaped) {
1111 *shev = *sev;
1112 } else {
1113 XPutBackEvent(dpy, &ev);
1114 break;
1119 wwin = wWindowFor(shev->window);
1120 if (!wwin || shev->kind != ShapeBounding)
1121 return;
1123 if (!shev->shaped && wwin->flags.shaped) {
1125 wwin->flags.shaped = 0;
1126 wWindowClearShape(wwin);
1128 } else if (shev->shaped) {
1130 wwin->flags.shaped = 1;
1131 wWindowSetShape(wwin);
1134 #endif /* SHAPE */
1137 static void
1138 handleColormapNotify(XEvent *event)
1140 WWindow *wwin;
1141 WScreen *scr;
1142 Bool reinstall = False;
1144 wwin = wWindowFor(event->xcolormap.window);
1145 if (!wwin)
1146 return;
1148 scr = wwin->screen_ptr;
1150 do {
1151 if (wwin) {
1152 if (event->xcolormap.new) {
1153 XWindowAttributes attr;
1155 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1157 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1158 scr->current_colormap = attr.colormap;
1160 reinstall = True;
1161 } else if (event->xcolormap.state == ColormapUninstalled &&
1162 scr->current_colormap == event->xcolormap.colormap) {
1164 /* some bastard app (like XV) removed our colormap */
1166 * can't enforce or things like xscreensaver wont work
1167 * reinstall = True;
1169 } else if (event->xcolormap.state == ColormapInstalled &&
1170 scr->current_colormap == event->xcolormap.colormap) {
1172 /* someone has put our colormap back */
1173 reinstall = False;
1176 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1177 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1179 if (reinstall && scr->current_colormap!=None) {
1180 if (!scr->flags.colormap_stuff_blocked)
1181 XInstallColormap(dpy, scr->current_colormap);
1187 static void
1188 handleFocusIn(XEvent *event)
1190 WWindow *wwin;
1193 * For applications that like stealing the focus.
1195 while (XCheckTypedEvent(dpy, FocusIn, event));
1196 saveTimestamp(event);
1197 if (event->xfocus.mode == NotifyUngrab
1198 || event->xfocus.mode == NotifyGrab
1199 || event->xfocus.detail > NotifyNonlinearVirtual) {
1200 return;
1203 wwin = wWindowFor(event->xfocus.window);
1204 if (wwin && !wwin->flags.focused) {
1205 if (wwin->flags.mapped)
1206 wSetFocusTo(wwin->screen_ptr, wwin);
1207 else
1208 wSetFocusTo(wwin->screen_ptr, NULL);
1209 } else if (!wwin) {
1210 WScreen *scr = wScreenForWindow(event->xfocus.window);
1211 if (scr)
1212 wSetFocusTo(scr, NULL);
1217 static WWindow*
1218 windowUnderPointer(WScreen *scr)
1220 unsigned int mask;
1221 int foo;
1222 Window bar, win;
1224 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1225 &mask))
1226 return wWindowFor(win);
1227 return NULL;
1230 #ifdef WEENDOZE_CYCLE
1232 static WWindow*
1233 nextToFocusAfter(WWindow *wwin)
1235 WWindow *tmp = wwin->next;
1237 while (tmp) {
1238 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1240 return tmp;
1242 tmp = tmp->next;
1245 tmp = wwin;
1246 /* start over from the beginning of the list */
1247 while (tmp->prev)
1248 tmp = tmp->prev;
1250 while (tmp && tmp != wwin) {
1251 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1253 return tmp;
1255 tmp = tmp->next;
1258 return wwin;
1262 static WWindow*
1263 nextToFocusBefore(WWindow *wwin)
1265 WWindow *tmp = wwin->prev;
1267 while (tmp) {
1268 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1270 return tmp;
1272 tmp = tmp->prev;
1275 /* start over from the beginning of the list */
1276 tmp = wwin;
1277 while (tmp->next)
1278 tmp = tmp->next;
1280 while (tmp && tmp != wwin) {
1281 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1283 return tmp;
1285 tmp = tmp->prev;
1288 return wwin;
1291 static void
1292 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1294 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1295 Bool done = False;
1296 WWindow *newFocused;
1297 WWindow *oldFocused;
1298 int modifiers;
1299 XModifierKeymap *keymap;
1301 if (!wwin)
1302 return;
1304 puts("IN");
1305 keymap = XGetModifierMapping(dpy);
1308 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1309 CurrentTime);
1311 if (next) {
1312 newFocused = nextToFocusAfter(wwin);
1313 } else {
1314 newFocused = nextToFocusBefore(wwin);
1317 scr->flags.doing_alt_tab = 1;
1319 wWindowFocus(newFocused, scr->focused_window);
1320 oldFocused = newFocused;
1322 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1324 while (!done) {
1325 XEvent ev;
1327 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1328 /* WMNextEvent(dpy, &ev);*/
1329 if (ev.type != KeyRelease && ev.type != KeyPress) {
1330 WMHandleEvent(&ev);
1331 continue;
1333 puts("EV");
1334 /* ignore CapsLock */
1335 modifiers = ev.xkey.state & ValidModMask;
1337 if (ev.type == KeyPress
1338 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1339 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1341 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1342 newFocused = nextToFocusAfter(newFocused);
1343 wWindowFocus(newFocused, oldFocused);
1344 oldFocused = newFocused;
1345 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1347 } else if (ev.type == KeyPress
1348 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1349 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1351 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1352 newFocused = nextToFocusBefore(newFocused);
1353 wWindowFocus(newFocused, oldFocused);
1354 oldFocused = newFocused;
1355 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1357 if (ev.type == KeyRelease) {
1358 int i;
1360 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1361 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1362 wKeyBindings[WKBD_FOCUSNEXT].modifier
1363 & 1<<(i/keymap->max_keypermod)) {
1364 done = True;
1365 break;
1370 puts("OUT");
1371 XFree(keymap);
1373 XUngrabKeyboard(dpy, CurrentTime);
1374 wSetFocusTo(scr, newFocused);
1375 scr->flags.doing_alt_tab = 0;
1376 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1380 #endif /* WEENDOZE_CYCLE */
1385 static void
1386 handleKeyPress(XEvent *event)
1388 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1389 WWindow *wwin = scr->focused_window;
1390 int i;
1391 int modifiers;
1392 int command=-1;
1393 #ifdef KEEP_XKB_LOCK_STATUS
1394 XkbStateRec staterec;
1395 #endif /*KEEP_XKB_LOCK_STATUS*/
1397 /* ignore CapsLock */
1398 modifiers = event->xkey.state & ValidModMask;
1400 for (i=0; i<WKBD_LAST; i++) {
1401 if (wKeyBindings[i].keycode==0)
1402 continue;
1404 if (wKeyBindings[i].keycode==event->xkey.keycode
1405 && (/*wKeyBindings[i].modifier==0
1406 ||*/ wKeyBindings[i].modifier==modifiers)) {
1407 command = i;
1408 break;
1412 if (command < 0) {
1413 #ifdef LITE
1415 #if 0
1417 #endif
1418 #else
1419 if (!wRootMenuPerformShortcut(event)) {
1420 #endif
1421 static int dontLoop = 0;
1423 if (dontLoop > 10) {
1424 wwarning("problem with key event processing code");
1425 return;
1427 dontLoop++;
1428 /* if the focused window is an internal window, try redispatching
1429 * the event to the managed window, as it can be a WINGs window */
1430 if (wwin && wwin->flags.internal_window
1431 && wwin->client_leader!=None) {
1432 /* client_leader contains the WINGs toplevel */
1433 event->xany.window = wwin->client_leader;
1434 WMHandleEvent(event);
1436 dontLoop--;
1438 return;
1441 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1442 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1444 switch (command) {
1445 #ifndef LITE
1446 case WKBD_ROOTMENU:
1447 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1448 break;
1449 case WKBD_WINDOWLIST:
1450 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1451 break;
1452 #endif /* !LITE */
1453 case WKBD_WINDOWMENU:
1454 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1455 OpenWindowMenu(wwin, wwin->frame_x,
1456 wwin->frame_y+wwin->frame->top_width, True);
1457 break;
1458 case WKBD_MINIATURIZE:
1459 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1460 && !WFLAGP(wwin, no_miniaturizable)) {
1461 CloseWindowMenu(scr);
1463 if (wwin->protocols.MINIATURIZE_WINDOW)
1464 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1465 event->xbutton.time);
1466 else {
1467 wIconifyWindow(wwin);
1470 break;
1471 case WKBD_HIDE:
1472 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1473 WApplication *wapp = wApplicationOf(wwin->main_window);
1474 CloseWindowMenu(scr);
1476 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1477 wHideApplication(wapp);
1480 break;
1481 case WKBD_MAXIMIZE:
1482 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1483 CloseWindowMenu(scr);
1485 if (wwin->flags.maximized) {
1486 wUnmaximizeWindow(wwin);
1487 } else {
1488 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1491 break;
1492 case WKBD_VMAXIMIZE:
1493 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1494 CloseWindowMenu(scr);
1496 if (wwin->flags.maximized) {
1497 wUnmaximizeWindow(wwin);
1498 } else {
1499 wMaximizeWindow(wwin, MAX_VERTICAL);
1502 break;
1503 case WKBD_RAISE:
1504 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1505 CloseWindowMenu(scr);
1507 wRaiseFrame(wwin->frame->core);
1509 break;
1510 case WKBD_LOWER:
1511 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1512 CloseWindowMenu(scr);
1514 wLowerFrame(wwin->frame->core);
1516 break;
1517 case WKBD_RAISELOWER:
1518 /* raise or lower the window under the pointer, not the
1519 * focused one
1521 wwin = windowUnderPointer(scr);
1522 if (wwin)
1523 wRaiseLowerFrame(wwin->frame->core);
1524 break;
1525 case WKBD_SHADE:
1526 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1527 if (wwin->flags.shaded)
1528 wUnshadeWindow(wwin);
1529 else
1530 wShadeWindow(wwin);
1532 break;
1533 case WKBD_MOVERESIZE:
1534 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1535 CloseWindowMenu(scr);
1537 wKeyboardMoveResizeWindow(wwin);
1539 break;
1540 case WKBD_CLOSE:
1541 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1542 CloseWindowMenu(scr);
1543 if (wwin->protocols.DELETE_WINDOW)
1544 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1545 event->xkey.time);
1547 break;
1548 case WKBD_SELECT:
1549 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1550 wSelectWindow(wwin, !wwin->flags.selected);
1552 break;
1553 case WKBD_FOCUSNEXT:
1554 #ifdef WEENDOZE_CYCLE
1555 if (wPreferences.windoze_cycling) {
1556 doWindozeCycle(wwin, event, True);
1557 } else
1558 #endif /* WEENDOZE_CYCLE */
1560 wwin = NextFocusWindow(scr);
1561 if (wwin != NULL) {
1562 wSetFocusTo(scr, wwin);
1563 if (wPreferences.circ_raise)
1564 wRaiseFrame(wwin->frame->core);
1567 break;
1569 case WKBD_FOCUSPREV:
1570 #ifdef WEENDOZE_CYCLE
1571 if (wPreferences.windoze_cycling) {
1572 doWindozeCycle(wwin, event, False);
1573 } else
1574 #endif /* WEENDOZE_CYCLE */
1576 wwin = PrevFocusWindow(scr);
1577 if (wwin != NULL) {
1578 wSetFocusTo(scr, wwin);
1579 if (wPreferences.circ_raise)
1580 wRaiseFrame(wwin->frame->core);
1583 break;
1585 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1586 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1587 i = (scr->current_workspace/10)*10 + wk - 1;\
1588 if (wPreferences.ws_advance || i<scr->workspace_count)\
1589 wWorkspaceChange(scr, i);\
1590 break
1591 #else
1592 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1593 i = (scr->current_workspace/10)*10 + wk - 1;\
1594 if (wPreferences.ws_advance || i<scr->workspace_count)\
1595 wWorkspaceChange(scr, i);\
1596 break
1597 #endif
1598 GOTOWORKS(1);
1599 GOTOWORKS(2);
1600 GOTOWORKS(3);
1601 GOTOWORKS(4);
1602 GOTOWORKS(5);
1603 GOTOWORKS(6);
1604 GOTOWORKS(7);
1605 GOTOWORKS(8);
1606 GOTOWORKS(9);
1607 GOTOWORKS(10);
1608 #undef GOTOWORKS
1609 case WKBD_NEXTWORKSPACE:
1610 wWorkspaceRelativeChange(scr, 1);
1611 break;
1612 case WKBD_PREVWORKSPACE:
1613 wWorkspaceRelativeChange(scr, -1);
1614 break;
1615 case WKBD_WINDOW1:
1616 case WKBD_WINDOW2:
1617 case WKBD_WINDOW3:
1618 case WKBD_WINDOW4:
1619 #ifdef EXTEND_WINDOWSHORTCUT
1620 case WKBD_WINDOW5:
1621 case WKBD_WINDOW6:
1622 case WKBD_WINDOW7:
1623 case WKBD_WINDOW8:
1624 case WKBD_WINDOW9:
1625 case WKBD_WINDOW10:
1626 #endif
1627 if (scr->shortcutWindow[command-WKBD_WINDOW1]) {
1628 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1629 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1630 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1631 wSelectWindow(wwin, !wwin->flags.selected);
1632 XFlush(dpy);
1633 wusleep(3000);
1634 wSelectWindow(wwin, !wwin->flags.selected);
1635 XFlush(dpy);
1637 break;
1638 case WKBD_NEXTWSLAYER:
1639 case WKBD_PREVWSLAYER:
1641 int row, column;
1643 row = scr->current_workspace/10;
1644 column = scr->current_workspace%10;
1646 if (command==WKBD_NEXTWSLAYER) {
1647 if ((row+1)*10 < scr->workspace_count)
1648 wWorkspaceChange(scr, column+(row+1)*10);
1649 } else {
1650 if (row > 0)
1651 wWorkspaceChange(scr, column+(row-1)*10);
1654 break;
1655 case WKBD_CLIPLOWER:
1656 if (!wPreferences.flags.noclip)
1657 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1658 break;
1659 case WKBD_CLIPRAISE:
1660 if (!wPreferences.flags.noclip)
1661 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1662 break;
1663 case WKBD_CLIPRAISELOWER:
1664 if (!wPreferences.flags.noclip)
1665 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1666 break;
1667 #ifdef KEEP_XKB_LOCK_STATUS
1668 case WKBD_TOGGLE:
1669 if(wPreferences.modelock){
1670 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1671 /*toggle*/
1672 XkbLockGroup(dpy,XkbUseCoreKbd,
1673 wwin->languagemode=staterec.compat_state&32?0:1);
1675 break;
1676 #endif /* KEEP_XKB_LOCK_STATUS */
1682 static void
1683 handleMotionNotify(XEvent *event)
1685 WMenu *menu;
1686 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1687 WWindow *wwin;
1689 if (wPreferences.scrollable_menus) {
1690 if (event->xmotion.x_root <= 1 ||
1691 event->xmotion.x_root >= (scr->scr_width - 2) ||
1692 event->xmotion.y_root <= 1 ||
1693 event->xmotion.y_root >= (scr->scr_height - 2)) {
1695 #ifdef DEBUG
1696 puts("pointer at screen edge");
1697 #endif
1699 menu = wMenuUnderPointer(scr);
1700 if (menu!=NULL)
1701 wMenuScroll(menu, event);
1704 #if 0
1705 if (event->xmotion.subwindow == None)
1706 return;
1708 if (scr->scrolledFMaximize != None) {
1709 WWindow *twin;
1711 twin = wWindowFor(scr->scrolledFMaximize);
1712 if (twin && twin->frame_y ==) {
1716 scr->scrolledFMaximize = NULL;
1718 } else {
1720 /* scroll full maximized window */
1721 if (event->xmotion.y_root < 1
1722 || event->xmotion.y_root > scr->scr_height - 1) {
1724 wwin = wWindowFor(event->xmotion.subwindow);
1726 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1727 && WFLAGP(wwin, full_maximize)
1728 && event->xmotion.x_root >= wwin->frame_x
1729 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1731 if (!WFLAGP(wwin, no_titlebar)
1732 && wwin->frame_y <= - wwin->frame->top_width) {
1734 wWindowMove(wwin, wwin->frame_x, 0);
1735 wwin->flags.dragged_while_fmaximized = 0;
1737 } else if (!WFLAGP(wwin, no_resizebar)
1738 && wwin->frame_y + wwin->frame->core->height >=
1739 scr->scr_height + wwin->frame->bottom_width) {
1741 int y = scr->scr_height + wwin->frame->bottom_width;
1743 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1745 wWindowMove(wwin, wwin->frame_x, y);
1746 wwin->flags.dragged_while_fmaximized = 0;
1750 #endif
1754 static void
1755 handleVisibilityNotify(XEvent *event)
1757 WWindow *wwin;
1759 wwin = wWindowFor(event->xvisibility.window);
1760 if (!wwin)
1761 return;
1762 wwin->flags.obscured =
1763 (event->xvisibility.state == VisibilityFullyObscured);