Initial update from my source tree. For 0.52.0
[wmaker-crm.git] / src / event.c
blobcca7b2d70f21faaa44420fce1944f732bb287538
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;
301 default:
302 handleExtensions(event);
303 break;
309 *----------------------------------------------------------------------
310 * EventLoop-
311 * Processes X and internal events indefinitely.
313 * Returns:
314 * Never returns
316 * Side effects:
317 * The LastTimestamp global variable is updated.
318 *----------------------------------------------------------------------
320 void
321 EventLoop()
323 XEvent event;
325 for(;;) {
326 WMNextEvent(dpy, &event);
327 WMHandleEvent(&event);
333 Bool
334 IsDoubleClick(WScreen *scr, XEvent *event)
336 if ((scr->last_click_time>0) &&
337 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
338 && (event->xbutton.button == scr->last_click_button)
339 && (event->xbutton.window == scr->last_click_window)) {
341 scr->flags.next_click_is_not_double = 1;
342 scr->last_click_time = 0;
343 scr->last_click_window = event->xbutton.window;
345 return True;
347 return False;
351 void
352 NotifyDeadProcess(pid_t pid, unsigned char status)
354 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
355 wwarning("stack overflow: too many dead processes");
356 return;
358 /* stack the process to be handled later,
359 * as this is called from the signal handler */
360 deadProcesses[deadProcessPtr].pid = pid;
361 deadProcesses[deadProcessPtr].exit_status = status;
362 deadProcessPtr++;
366 static void
367 handleDeadProcess(void *foo)
369 DeathHandler *tmp;
370 int i;
372 for (i=0; i<deadProcessPtr; i++) {
373 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
376 if (!deathHandler) {
377 deadProcessPtr=0;
378 return;
381 /* get the pids on the queue and call handlers */
382 while (deadProcessPtr>0) {
383 deadProcessPtr--;
385 tmp = deathHandler;
386 while (tmp) {
387 DeathHandler *t;
389 t = tmp->next;
391 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
392 (*tmp->callback)(tmp->pid,
393 deadProcesses[deadProcessPtr].exit_status,
394 tmp->client_data);
395 wDeleteDeathHandler(tmp);
397 tmp = t;
403 static void
404 saveTimestamp(XEvent *event)
406 LastTimestamp = CurrentTime;
408 switch (event->type) {
409 case ButtonRelease:
410 case ButtonPress:
411 LastTimestamp = event->xbutton.time;
412 break;
413 case KeyPress:
414 case KeyRelease:
415 LastTimestamp = event->xkey.time;
416 break;
417 case MotionNotify:
418 LastTimestamp = event->xmotion.time;
419 break;
420 case PropertyNotify:
421 LastTimestamp = event->xproperty.time;
422 break;
423 case EnterNotify:
424 case LeaveNotify:
425 LastTimestamp = event->xcrossing.time;
426 break;
427 case SelectionClear:
428 LastTimestamp = event->xselectionclear.time;
429 break;
430 case SelectionRequest:
431 LastTimestamp = event->xselectionrequest.time;
432 break;
433 case SelectionNotify:
434 LastTimestamp = event->xselection.time;
435 break;
440 static void
441 handleExtensions(XEvent *event)
443 #ifdef SHAPE
444 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
445 handleShapeNotify(event);
447 #endif
448 #ifdef KEEP_XKB_LOCK_STATUS
449 if (wPreferences.modelock && event->type == (0x50|XkbIndicatorStateNotify)){
450 /* if someone know how to call this 0x50
451 * or how to clean code this please tell ]d */
452 handleXkbIndicatorStateNotify(event);
454 #endif /*KEEP_XKB_LOCK_STATUS*/
458 static void
459 handleMapRequest(XEvent *ev)
461 WWindow *wwin;
462 WScreen *scr = NULL;
463 Window window = ev->xmaprequest.window;
465 #ifdef DEBUG
466 printf("got map request for %x\n", (unsigned)window);
467 #endif
469 if ((wwin = wWindowFor(window))) {
470 if (wwin->flags.shaded) {
471 wUnshadeWindow(wwin);
473 /* deiconify window */
474 if (wwin->flags.miniaturized) {
475 wDeiconifyWindow(wwin);
476 } else if (wwin->flags.hidden) {
477 WApplication *wapp = wApplicationOf(wwin->main_window);
478 /* go to the last workspace that the user worked on the app */
479 #ifndef REDUCE_APPICONS
480 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
481 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
483 if (wapp) {
484 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
486 #endif
487 wUnhideApplication(wapp, False, False);
489 return;
492 scr = wScreenForRootWindow(ev->xmaprequest.parent);
494 wwin = wManageWindow(scr, window);
497 * This is to let the Dock know that the application it launched
498 * has already been mapped (eg: it has finished launching).
499 * It is not necessary for normally docked apps, but is needed for
500 * apps that were forcedly docked (like with dockit).
502 if (scr->last_dock) {
503 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
504 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
505 else
506 wDockTrackWindowLaunch(scr->last_dock, window);
509 if (wwin) {
510 wClientSetState(wwin, NormalState, None);
511 if (wwin->flags.maximized) {
512 wMaximizeWindow(wwin, wwin->flags.maximized);
514 if (wwin->flags.shaded) {
515 wwin->flags.shaded = 0;
516 wwin->flags.skip_next_animation = 1;
517 wShadeWindow(wwin);
519 if (wwin->flags.miniaturized) {
520 wwin->flags.miniaturized = 0;
521 wwin->flags.skip_next_animation = 1;
522 wIconifyWindow(wwin);
524 if (wwin->flags.hidden) {
525 WApplication *wapp = wApplicationOf(wwin->main_window);
527 wwin->flags.hidden = 0;
528 wwin->flags.skip_next_animation = 1;
529 if (wapp) {
530 wHideApplication(wapp);
537 static void
538 handleDestroyNotify(XEvent *event)
540 WWindow *wwin;
541 WApplication *app;
542 Window window = event->xdestroywindow.window;
544 #ifdef DEBUG
545 puts("got destroy notify");
546 #endif
548 wwin = wWindowFor(window);
549 if (wwin) {
550 wUnmanageWindow(wwin, False, True);
553 app = wApplicationOf(window);
554 if (app) {
555 if (window == app->main_window) {
556 app->refcount = 0;
557 wwin = app->main_window_desc->screen_ptr->focused_window;
558 while (wwin) {
559 if (wwin->main_window == window) {
560 wwin->main_window = None;
562 wwin = wwin->prev;
565 wApplicationDestroy(app);
568 #ifdef KWM_HINTS
569 wKWMCheckDestroy(&event->xdestroywindow);
570 #endif
575 static void
576 handleExpose(XEvent *event)
578 WObjDescriptor *desc;
579 XEvent ev;
581 #ifdef DEBUG
582 puts("got expose");
583 #endif
585 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
587 if (XFindContext(dpy, event->xexpose.window, wWinContext,
588 (XPointer *)&desc)==XCNOENT) {
589 return;
592 if (desc->handle_expose) {
593 (*desc->handle_expose)(desc, event);
598 /* bindable */
599 static void
600 handleButtonPress(XEvent *event)
602 WObjDescriptor *desc;
603 WScreen *scr;
605 #ifdef DEBUG
606 puts("got button press");
607 #endif
609 scr = wScreenForRootWindow(event->xbutton.root);
611 #ifdef BALLOON_TEXT
612 wBalloonHide(scr);
613 #endif
616 #ifndef LITE
617 if (event->xbutton.window==scr->root_win) {
619 #ifdef GNOME_STUFF
620 if (wGNOMEProxyizeButtonEvent(scr, event))
621 return;
622 #endif
624 if (event->xbutton.button==wPreferences.menu_button) {
625 OpenRootMenu(scr, event->xbutton.x_root,
626 event->xbutton.y_root, False);
627 /* ugly hack */
628 if (scr->root_menu) {
629 if (scr->root_menu->brother->flags.mapped)
630 event->xbutton.window = scr->root_menu->brother->frame->core->window;
631 else
632 event->xbutton.window = scr->root_menu->frame->core->window;
634 } else if (event->xbutton.button==wPreferences.windowl_button) {
635 OpenSwitchMenu(scr, event->xbutton.x_root,
636 event->xbutton.y_root, False);
637 if (scr->switch_menu) {
638 if (scr->switch_menu->brother->flags.mapped)
639 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
640 else
641 event->xbutton.window = scr->switch_menu->frame->core->window;
643 } else if (event->xbutton.button==wPreferences.select_button) {
644 wUnselectWindows(scr);
645 wSelectWindows(scr, event);
647 #ifdef MOUSE_WS_SWITCH
648 else if (event->xbutton.button==Button5) {
650 wWorkspaceRelativeChange(scr, -1);
652 } else if (event->xbutton.button==Button4) {
654 wWorkspaceRelativeChange(scr, 1);
657 #endif /* MOUSE_WS_SWITCH */
659 #endif /* !LITE */
661 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
662 (XPointer *)&desc)==XCNOENT) {
663 if (XFindContext(dpy, event->xbutton.window, wWinContext,
664 (XPointer *)&desc)==XCNOENT) {
665 return;
669 if (desc->handle_mousedown!=NULL) {
670 (*desc->handle_mousedown)(desc, event);
673 if (desc->parent_type == WCLASS_WINDOW) {
674 XSync(dpy, 0);
676 if (event->xbutton.state & MOD_MASK) {
677 XAllowEvents(dpy, AsyncPointer, CurrentTime);
680 if (wPreferences.focus_mode == WKF_CLICK) {
681 if (wPreferences.ignore_focus_click) {
682 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 XAllowEvents(dpy, ReplayPointer, CurrentTime);
686 XSync(dpy, 0);
687 } else if (desc->parent_type == WCLASS_APPICON
688 || desc->parent_type == WCLASS_MINIWINDOW
689 || desc->parent_type == WCLASS_DOCK_ICON) {
690 if (event->xbutton.state & MOD_MASK) {
691 XSync(dpy, 0);
692 XAllowEvents(dpy, AsyncPointer, CurrentTime);
693 XSync(dpy, 0);
697 /* save double-click information */
698 if (scr->flags.next_click_is_not_double) {
699 scr->flags.next_click_is_not_double = 0;
700 } else {
701 scr->last_click_time = event->xbutton.time;
702 scr->last_click_button = event->xbutton.button;
703 scr->last_click_window = event->xbutton.window;
708 static void
709 handleMapNotify(XEvent *event)
711 WWindow *wwin;
713 #ifdef DEBUG
714 puts("got map");
715 #endif
717 wwin = wWindowFor(event->xmap.event);
718 if (wwin && wwin->client_win == event->xmap.event) {
719 if (wwin->flags.miniaturized) {
720 wDeiconifyWindow(wwin);
721 } else {
722 XGrabServer(dpy);
723 wWindowMap(wwin);
724 wClientSetState(wwin, NormalState, None);
725 XUngrabServer(dpy);
731 static void
732 handleUnmapNotify(XEvent *event)
734 WWindow *wwin;
735 XEvent ev;
736 Bool withdraw = False;
738 #ifdef DEBUG
739 puts("got unmap");
740 #endif
742 /* only process windows with StructureNotify selected
743 * (ignore SubstructureNotify) */
744 wwin = wWindowFor(event->xunmap.window);
745 if (!wwin)
746 return;
748 /* whether the event is a Withdrawal request */
749 if (event->xunmap.event == wwin->screen_ptr->root_win
750 && event->xunmap.send_event)
751 withdraw = True;
753 if (wwin->client_win != event->xunmap.event && !withdraw)
754 return;
756 if (!wwin->flags.mapped && !withdraw
757 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
758 && !wwin->flags.miniaturized && !wwin->flags.hidden)
759 return;
761 XGrabServer(dpy);
762 XUnmapWindow(dpy, wwin->frame->core->window);
763 wwin->flags.mapped = 0;
764 XSync(dpy, 0);
765 /* check if the window was destroyed */
766 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
767 DispatchEvent(&ev);
768 } else {
769 Bool reparented = False;
771 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
772 reparented = True;
774 /* withdraw window */
775 wwin->flags.mapped = 0;
776 if (!reparented)
777 wClientSetState(wwin, WithdrawnState, None);
779 /* if the window was reparented, do not reparent it back to the
780 * root window */
781 // wUnmanageWindow(wwin, !reparented, False);
783 XUngrabServer(dpy);
787 static void
788 handleConfigureRequest(XEvent *event)
790 WWindow *wwin;
792 #ifdef DEBUG
793 puts("got configure request");
794 #endif
795 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
797 * Configure request for unmapped window
799 wClientConfigure(NULL, &(event->xconfigurerequest));
800 } else {
801 wClientConfigure(wwin, &(event->xconfigurerequest));
806 static void
807 handlePropertyNotify(XEvent *event)
809 WWindow *wwin;
810 WApplication *wapp;
811 Window jr;
812 int ji;
813 unsigned int ju;
814 WScreen *scr;
816 #ifdef DEBUG
817 puts("got property notify");
818 #endif
819 if ((wwin=wWindowFor(event->xproperty.window))) {
820 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
821 &ju, &ju, &ju, &ju)) {
822 return;
824 wClientCheckProperty(wwin, &event->xproperty);
826 wapp = wApplicationOf(event->xproperty.window);
827 if (wapp) {
828 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
831 scr = wScreenForWindow(event->xproperty.window);
832 if (scr && scr->root_win == event->xproperty.window) {
833 #ifdef KWM_HINTS
834 wKWMCheckRootHintChange(scr, &event->xproperty);
835 #endif
840 static void
841 handleClientMessage(XEvent *event)
843 WWindow *wwin;
844 WObjDescriptor *desc;
846 #ifdef DEBUG
847 puts("got client message");
848 #endif
849 /* handle transition from Normal to Iconic state */
850 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
851 && event->xclient.format == 32
852 && event->xclient.data.l[0] == IconicState) {
854 wwin = wWindowFor(event->xclient.window);
855 if (!wwin) return;
856 if (!wwin->flags.miniaturized)
857 wIconifyWindow(wwin);
858 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
859 && event->xclient.format == 32) {
860 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
862 if (!scr)
863 return;
865 if (event->xclient.data.l[1] == 1) { /* starting */
866 wColormapAllowClientInstallation(scr, True);
867 } else { /* stopping */
868 wColormapAllowClientInstallation(scr, False);
870 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
871 WApplication *wapp;
872 int done=0;
873 wapp = wApplicationOf(event->xclient.window);
874 if (wapp) {
875 switch (event->xclient.data.l[0]) {
876 case WMFHideOtherApplications:
877 wHideOtherApplications(wapp->main_window_desc);
878 done = 1;
879 break;
881 case WMFHideApplication:
882 wHideApplication(wapp);
883 done = 1;
884 break;
887 if (!done) {
888 wwin = wWindowFor(event->xclient.window);
889 if (wwin) {
890 switch (event->xclient.data.l[0]) {
891 case WMFHideOtherApplications:
892 wHideOtherApplications(wwin);
893 break;
895 case WMFHideApplication:
896 wHideApplication(wApplicationOf(wwin->main_window));
897 break;
901 #ifdef GNOME_STUFF
902 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
903 /* do nothing */
904 #endif /* GNOME_STUFF */
905 #ifdef KWM_HINTS
906 } else if (wKWMProcessClientMessage(&event->xclient)) {
907 /* do nothing */
908 #endif /* KWM_HINTS */
909 #ifdef XDE_DND
910 } else if (wXDEProcessClientMessage(&event->xclient)) {
911 /* do nothing */
912 #endif /* XDE_DND */
913 #ifdef OFFIX_DND
914 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
915 WScreen *scr = wScreenForWindow(event->xclient.window);
916 if (scr && wDockReceiveDNDDrop(scr,event))
917 goto redirect_message;
918 #endif /* OFFIX_DND */
919 } else {
920 #ifdef OFFIX_DND
921 redirect_message:
922 #endif
924 * Non-standard thing, but needed by OffiX DND.
925 * For when the icon frame gets a ClientMessage
926 * that should have gone to the icon_window.
928 if (XFindContext(dpy, event->xbutton.window, wWinContext,
929 (XPointer *)&desc)!=XCNOENT) {
930 struct WIcon *icon=NULL;
932 if (desc->parent_type == WCLASS_MINIWINDOW) {
933 icon = (WIcon*)desc->parent;
934 } else if (desc->parent_type == WCLASS_DOCK_ICON
935 || desc->parent_type == WCLASS_APPICON) {
936 icon = ((WAppIcon*)desc->parent)->icon;
938 if (icon && (wwin=icon->owner)) {
939 if (wwin->client_win!=event->xclient.window) {
940 event->xclient.window = wwin->client_win;
941 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
942 event);
950 static void
951 raiseWindow(WScreen *scr)
953 WWindow *wwin;
955 scr->autoRaiseTimer = NULL;
957 wwin = wWindowFor(scr->autoRaiseWindow);
958 if (!wwin)
959 return;
961 if (!wwin->flags.destroyed) {
962 wRaiseFrame(wwin->frame->core);
963 /* this is needed or a race condition will occur */
964 XSync(dpy, False);
969 static void
970 handleEnterNotify(XEvent *event)
972 WWindow *wwin;
973 WObjDescriptor *desc = NULL;
974 XEvent ev;
975 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
978 #ifdef DEBUG
979 puts("got enter notify");
980 #endif
982 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
983 &ev)) {
984 /* already left the window... */
985 saveTimestamp(&ev);
986 if (ev.xcrossing.mode==event->xcrossing.mode
987 && ev.xcrossing.detail==event->xcrossing.detail) {
988 return;
992 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
993 (XPointer *)&desc)!=XCNOENT) {
994 if(desc->handle_enternotify)
995 (*desc->handle_enternotify)(desc, event);
998 /* enter to window */
999 wwin = wWindowFor(event->xcrossing.window);
1000 if (!wwin) {
1001 if (wPreferences.focus_mode==WKF_POINTER
1002 && event->xcrossing.window==event->xcrossing.root) {
1003 wSetFocusTo(scr, NULL);
1005 if (wPreferences.colormap_mode==WKF_POINTER) {
1006 wColormapInstallForWindow(scr, NULL);
1008 if (scr->autoRaiseTimer
1009 && event->xcrossing.root==event->xcrossing.window) {
1010 WMDeleteTimerHandler(scr->autoRaiseTimer);
1011 scr->autoRaiseTimer = NULL;
1013 } else {
1014 /* set auto raise timer even if in focus-follows-mouse mode
1015 * and the event is for the frame window, even if the window
1016 * has focus already. useful if you move the pointer from a focused
1017 * window to the root window and back pretty fast
1019 * set focus if in focus-follows-mouse mode and the event
1020 * is for the frame window and window doesn't have focus yet */
1021 if ((wPreferences.focus_mode==WKF_POINTER
1022 || wPreferences.focus_mode==WKF_SLOPPY)
1023 && wwin->frame->core->window==event->xcrossing.window
1024 && !scr->flags.doing_alt_tab) {
1026 if (!wwin->flags.focused)
1027 wSetFocusTo(scr, wwin);
1029 if (scr->autoRaiseTimer)
1030 WMDeleteTimerHandler(scr->autoRaiseTimer);
1031 scr->autoRaiseTimer = NULL;
1033 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1034 scr->autoRaiseWindow = wwin->frame->core->window;
1035 scr->autoRaiseTimer
1036 = WMAddTimerHandler(wPreferences.raise_delay,
1037 (WMCallback*)raiseWindow, scr);
1040 /* Install colormap for window, if the colormap installation mode
1041 * is colormap_follows_mouse */
1042 if (wPreferences.colormap_mode==WKF_POINTER) {
1043 if (wwin->client_win==event->xcrossing.window)
1044 wColormapInstallForWindow(scr, wwin);
1045 else
1046 wColormapInstallForWindow(scr, NULL);
1050 /* a little kluge to hide the clip balloon */
1051 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1052 if (!desc) {
1053 XUnmapWindow(dpy, scr->clip_balloon);
1054 scr->flags.clip_balloon_mapped = 0;
1055 } else {
1056 if (desc->parent_type!=WCLASS_DOCK_ICON
1057 || scr->clip_icon != desc->parent) {
1058 XUnmapWindow(dpy, scr->clip_balloon);
1059 scr->flags.clip_balloon_mapped = 0;
1064 if (event->xcrossing.window == event->xcrossing.root
1065 && event->xcrossing.detail == NotifyNormal
1066 && event->xcrossing.detail != NotifyInferior
1067 && wPreferences.focus_mode != WKF_CLICK) {
1069 wSetFocusTo(scr, scr->focused_window);
1072 #ifdef BALLOON_TEXT
1073 wBalloonEnteredObject(scr, desc);
1074 #endif
1078 static void
1079 handleLeaveNotify(XEvent *event)
1081 WObjDescriptor *desc = NULL;
1083 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1084 (XPointer *)&desc)!=XCNOENT) {
1085 if(desc->handle_leavenotify)
1086 (*desc->handle_leavenotify)(desc, event);
1088 if (event->xcrossing.window == event->xcrossing.root
1089 && event->xcrossing.mode == NotifyNormal
1090 && event->xcrossing.detail != NotifyInferior
1091 && wPreferences.focus_mode != WKF_CLICK) {
1093 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1095 wSetFocusTo(scr, NULL);
1100 #ifdef SHAPE
1101 static void
1102 handleShapeNotify(XEvent *event)
1104 XShapeEvent *shev = (XShapeEvent*)event;
1105 WWindow *wwin;
1106 XEvent ev;
1108 #ifdef DEBUG
1109 puts("got shape notify");
1110 #endif
1112 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1113 XShapeEvent *sev = (XShapeEvent*)&ev;
1115 if (sev->kind == ShapeBounding) {
1116 if (sev->shaped == shev->shaped) {
1117 *shev = *sev;
1118 } else {
1119 XPutBackEvent(dpy, &ev);
1120 break;
1125 wwin = wWindowFor(shev->window);
1126 if (!wwin || shev->kind != ShapeBounding)
1127 return;
1129 if (!shev->shaped && wwin->flags.shaped) {
1131 wwin->flags.shaped = 0;
1132 wWindowClearShape(wwin);
1134 } else if (shev->shaped) {
1136 wwin->flags.shaped = 1;
1137 wWindowSetShape(wwin);
1140 #endif /* SHAPE */
1142 #ifdef KEEP_XKB_LOCK_STATUS
1143 /* please help ]d if you know what to do */
1144 handleXkbIndicatorStateNotify(XEvent *event)
1146 WWindow *wwin;
1147 WScreen *scr;
1148 XkbStateRec staterec;
1149 int i;
1151 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1152 for (i=0; i<wScreenCount; i++) {
1153 scr = wScreenWithNumber(i);
1154 wwin = scr->focused_window;
1155 if (wwin->flags.focused) {
1156 wwin->frame->languagemode=staterec.compat_state&32?1:0;
1157 #ifdef XKB_TITLE_HINT
1158 if (wwin->frame->titlebar) {
1159 XClearWindow(dpy, wwin->frame->titlebar->window);
1160 wFrameWindowPaint(wwin->frame);
1162 #endif /* XKB_TITLE_HINT */
1166 #endif /*KEEP_XKB_LOCK_STATUS*/
1168 static void
1169 handleColormapNotify(XEvent *event)
1171 WWindow *wwin;
1172 WScreen *scr;
1173 Bool reinstall = False;
1175 wwin = wWindowFor(event->xcolormap.window);
1176 if (!wwin)
1177 return;
1179 scr = wwin->screen_ptr;
1181 do {
1182 if (wwin) {
1183 if (event->xcolormap.new) {
1184 XWindowAttributes attr;
1186 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1188 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1189 scr->current_colormap = attr.colormap;
1191 reinstall = True;
1192 } else if (event->xcolormap.state == ColormapUninstalled &&
1193 scr->current_colormap == event->xcolormap.colormap) {
1195 /* some bastard app (like XV) removed our colormap */
1197 * can't enforce or things like xscreensaver wont work
1198 * reinstall = True;
1200 } else if (event->xcolormap.state == ColormapInstalled &&
1201 scr->current_colormap == event->xcolormap.colormap) {
1203 /* someone has put our colormap back */
1204 reinstall = False;
1207 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1208 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1210 if (reinstall && scr->current_colormap!=None) {
1211 if (!scr->flags.colormap_stuff_blocked)
1212 XInstallColormap(dpy, scr->current_colormap);
1218 static void
1219 handleFocusIn(XEvent *event)
1221 WWindow *wwin;
1224 * For applications that like stealing the focus.
1226 while (XCheckTypedEvent(dpy, FocusIn, event));
1227 saveTimestamp(event);
1228 if (event->xfocus.mode == NotifyUngrab
1229 || event->xfocus.mode == NotifyGrab
1230 || event->xfocus.detail > NotifyNonlinearVirtual) {
1231 return;
1234 wwin = wWindowFor(event->xfocus.window);
1235 if (wwin && !wwin->flags.focused) {
1236 if (wwin->flags.mapped)
1237 wSetFocusTo(wwin->screen_ptr, wwin);
1238 else
1239 wSetFocusTo(wwin->screen_ptr, NULL);
1240 } else if (!wwin) {
1241 WScreen *scr = wScreenForWindow(event->xfocus.window);
1242 if (scr)
1243 wSetFocusTo(scr, NULL);
1248 static WWindow*
1249 windowUnderPointer(WScreen *scr)
1251 unsigned int mask;
1252 int foo;
1253 Window bar, win;
1255 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1256 &mask))
1257 return wWindowFor(win);
1258 return NULL;
1261 #ifdef WEENDOZE_CYCLE
1263 static WWindow*
1264 nextToFocusAfter(WWindow *wwin)
1266 WWindow *tmp = wwin->next;
1268 while (tmp) {
1269 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1271 return tmp;
1273 tmp = tmp->next;
1276 tmp = wwin;
1277 /* start over from the beginning of the list */
1278 while (tmp->prev)
1279 tmp = tmp->prev;
1281 while (tmp && tmp != wwin) {
1282 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1284 return tmp;
1286 tmp = tmp->next;
1289 return wwin;
1293 static WWindow*
1294 nextToFocusBefore(WWindow *wwin)
1296 WWindow *tmp = wwin->prev;
1298 while (tmp) {
1299 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1301 return tmp;
1303 tmp = tmp->prev;
1306 /* start over from the beginning of the list */
1307 tmp = wwin;
1308 while (tmp->next)
1309 tmp = tmp->next;
1311 while (tmp && tmp != wwin) {
1312 if (wWindowCanReceiveFocus(tmp) && !WFLAGP(tmp, skip_window_list)) {
1314 return tmp;
1316 tmp = tmp->prev;
1319 return wwin;
1322 static void
1323 doWindozeCycle(WWindow *wwin, XEvent *event, Bool next)
1325 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1326 Bool done = False;
1327 WWindow *newFocused;
1328 WWindow *oldFocused;
1329 int modifiers;
1330 XModifierKeymap *keymap;
1332 if (!wwin)
1333 return;
1335 puts("IN");
1336 keymap = XGetModifierMapping(dpy);
1339 XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync,
1340 CurrentTime);
1342 if (next) {
1343 newFocused = nextToFocusAfter(wwin);
1344 } else {
1345 newFocused = nextToFocusBefore(wwin);
1348 scr->flags.doing_alt_tab = 1;
1350 wWindowFocus(newFocused, scr->focused_window);
1351 oldFocused = newFocused;
1353 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1355 while (!done) {
1356 XEvent ev;
1358 WMMaskEvent(dpy,KeyPressMask|KeyReleaseMask|ExposureMask, &ev);
1359 /* WMNextEvent(dpy, &ev);*/
1360 if (ev.type != KeyRelease && ev.type != KeyPress) {
1361 WMHandleEvent(&ev);
1362 continue;
1364 puts("EV");
1365 /* ignore CapsLock */
1366 modifiers = ev.xkey.state & ValidModMask;
1368 if (ev.type == KeyPress
1369 && wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
1370 && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) {
1372 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1373 newFocused = nextToFocusAfter(newFocused);
1374 wWindowFocus(newFocused, oldFocused);
1375 oldFocused = newFocused;
1376 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1378 } else if (ev.type == KeyPress
1379 && wKeyBindings[WKBD_FOCUSPREV].keycode == ev.xkey.keycode
1380 && wKeyBindings[WKBD_FOCUSPREV].modifier == modifiers) {
1382 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1383 newFocused = nextToFocusBefore(newFocused);
1384 wWindowFocus(newFocused, oldFocused);
1385 oldFocused = newFocused;
1386 UpdateSwitchMenu(scr, newFocused, ACTION_CHANGE_STATE);
1388 if (ev.type == KeyRelease) {
1389 int i;
1391 for (i = 0; i <= 8 * keymap->max_keypermod; i++) {
1392 if (keymap->modifiermap[i] == ev.xkey.keycode &&
1393 wKeyBindings[WKBD_FOCUSNEXT].modifier
1394 & 1<<(i/keymap->max_keypermod)) {
1395 done = True;
1396 break;
1401 puts("OUT");
1402 XFree(keymap);
1404 XUngrabKeyboard(dpy, CurrentTime);
1405 wSetFocusTo(scr, newFocused);
1406 scr->flags.doing_alt_tab = 0;
1407 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, False);
1411 #endif /* WEENDOZE_CYCLE */
1416 static void
1417 handleKeyPress(XEvent *event)
1419 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1420 WWindow *wwin = scr->focused_window;
1421 int i;
1422 int modifiers;
1423 int command=-1;
1424 #ifdef KEEP_XKB_LOCK_STATUS
1425 XkbStateRec staterec;
1426 #endif /*KEEP_XKB_LOCK_STATUS*/
1428 /* ignore CapsLock */
1429 modifiers = event->xkey.state & ValidModMask;
1431 for (i=0; i<WKBD_LAST; i++) {
1432 if (wKeyBindings[i].keycode==0)
1433 continue;
1435 if (wKeyBindings[i].keycode==event->xkey.keycode
1436 && (/*wKeyBindings[i].modifier==0
1437 ||*/ wKeyBindings[i].modifier==modifiers)) {
1438 command = i;
1439 break;
1443 if (command < 0) {
1444 #ifdef LITE
1446 #if 0
1448 #endif
1449 #else
1450 if (!wRootMenuPerformShortcut(event)) {
1451 #endif
1452 static int dontLoop = 0;
1454 if (dontLoop > 10) {
1455 wwarning("problem with key event processing code");
1456 return;
1458 dontLoop++;
1459 /* if the focused window is an internal window, try redispatching
1460 * the event to the managed window, as it can be a WINGs window */
1461 if (wwin && wwin->flags.internal_window
1462 && wwin->client_leader!=None) {
1463 /* client_leader contains the WINGs toplevel */
1464 event->xany.window = wwin->client_leader;
1465 WMHandleEvent(event);
1467 dontLoop--;
1469 return;
1472 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1473 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1475 switch (command) {
1476 #ifndef LITE
1477 case WKBD_ROOTMENU:
1478 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1479 break;
1480 case WKBD_WINDOWLIST:
1481 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1482 break;
1483 #endif /* !LITE */
1484 case WKBD_WINDOWMENU:
1485 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1486 OpenWindowMenu(wwin, wwin->frame_x,
1487 wwin->frame_y+wwin->frame->top_width, True);
1488 break;
1489 case WKBD_MINIATURIZE:
1490 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1491 && !WFLAGP(wwin, no_miniaturizable)) {
1492 CloseWindowMenu(scr);
1494 if (wwin->protocols.MINIATURIZE_WINDOW)
1495 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1496 event->xbutton.time);
1497 else {
1498 wIconifyWindow(wwin);
1501 break;
1502 case WKBD_HIDE:
1503 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1504 WApplication *wapp = wApplicationOf(wwin->main_window);
1505 CloseWindowMenu(scr);
1507 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1508 wHideApplication(wapp);
1511 break;
1512 case WKBD_MAXIMIZE:
1513 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1514 CloseWindowMenu(scr);
1516 if (wwin->flags.maximized) {
1517 wUnmaximizeWindow(wwin);
1518 } else {
1519 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1522 break;
1523 case WKBD_VMAXIMIZE:
1524 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1525 CloseWindowMenu(scr);
1527 if (wwin->flags.maximized) {
1528 wUnmaximizeWindow(wwin);
1529 } else {
1530 wMaximizeWindow(wwin, MAX_VERTICAL);
1533 break;
1534 case WKBD_RAISE:
1535 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1536 CloseWindowMenu(scr);
1538 wRaiseFrame(wwin->frame->core);
1540 break;
1541 case WKBD_LOWER:
1542 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1543 CloseWindowMenu(scr);
1545 wLowerFrame(wwin->frame->core);
1547 break;
1548 case WKBD_RAISELOWER:
1549 /* raise or lower the window under the pointer, not the
1550 * focused one
1552 wwin = windowUnderPointer(scr);
1553 if (wwin)
1554 wRaiseLowerFrame(wwin->frame->core);
1555 break;
1556 case WKBD_SHADE:
1557 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1558 if (wwin->flags.shaded)
1559 wUnshadeWindow(wwin);
1560 else
1561 wShadeWindow(wwin);
1563 break;
1564 case WKBD_MOVERESIZE:
1565 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1566 CloseWindowMenu(scr);
1568 wKeyboardMoveResizeWindow(wwin);
1570 break;
1571 case WKBD_CLOSE:
1572 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1573 CloseWindowMenu(scr);
1574 if (wwin->protocols.DELETE_WINDOW)
1575 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1576 event->xkey.time);
1578 break;
1579 case WKBD_SELECT:
1580 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1581 wSelectWindow(wwin, !wwin->flags.selected);
1583 break;
1584 case WKBD_FOCUSNEXT:
1585 #ifdef WEENDOZE_CYCLE
1586 if (wPreferences.windoze_cycling) {
1587 doWindozeCycle(wwin, event, True);
1588 } else
1589 #endif /* WEENDOZE_CYCLE */
1591 wwin = NextFocusWindow(scr);
1592 if (wwin != NULL) {
1593 wSetFocusTo(scr, wwin);
1594 if (wPreferences.circ_raise)
1595 wRaiseFrame(wwin->frame->core);
1598 break;
1600 case WKBD_FOCUSPREV:
1601 #ifdef WEENDOZE_CYCLE
1602 if (wPreferences.windoze_cycling) {
1603 doWindozeCycle(wwin, event, False);
1604 } else
1605 #endif /* WEENDOZE_CYCLE */
1607 wwin = PrevFocusWindow(scr);
1608 if (wwin != NULL) {
1609 wSetFocusTo(scr, wwin);
1610 if (wPreferences.circ_raise)
1611 wRaiseFrame(wwin->frame->core);
1614 break;
1616 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1617 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1618 i = (scr->current_workspace/10)*10 + wk - 1;\
1619 if (wPreferences.ws_advance || i<scr->workspace_count)\
1620 wWorkspaceChange(scr, i);\
1621 break
1622 #else
1623 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1624 i = (scr->current_workspace/10)*10 + wk - 1;\
1625 if (wPreferences.ws_advance || i<scr->workspace_count)\
1626 wWorkspaceChange(scr, i);\
1627 break
1628 #endif
1629 GOTOWORKS(1);
1630 GOTOWORKS(2);
1631 GOTOWORKS(3);
1632 GOTOWORKS(4);
1633 GOTOWORKS(5);
1634 GOTOWORKS(6);
1635 GOTOWORKS(7);
1636 GOTOWORKS(8);
1637 GOTOWORKS(9);
1638 GOTOWORKS(10);
1639 #undef GOTOWORKS
1640 case WKBD_NEXTWORKSPACE:
1641 wWorkspaceRelativeChange(scr, 1);
1642 break;
1643 case WKBD_PREVWORKSPACE:
1644 wWorkspaceRelativeChange(scr, -1);
1645 break;
1646 case WKBD_WINDOW1:
1647 case WKBD_WINDOW2:
1648 case WKBD_WINDOW3:
1649 case WKBD_WINDOW4:
1650 #ifdef EXTEND_WINDOWSHORTCUT
1651 case WKBD_WINDOW5:
1652 case WKBD_WINDOW6:
1653 case WKBD_WINDOW7:
1654 case WKBD_WINDOW8:
1655 case WKBD_WINDOW9:
1656 case WKBD_WINDOW10:
1657 #endif
1658 if (scr->shortcutWindow[command-WKBD_WINDOW1]) {
1659 wMakeWindowVisible(scr->shortcutWindow[command-WKBD_WINDOW1]);
1660 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1661 scr->shortcutWindow[command-WKBD_WINDOW1] = wwin;
1662 wSelectWindow(wwin, !wwin->flags.selected);
1663 XFlush(dpy);
1664 wusleep(3000);
1665 wSelectWindow(wwin, !wwin->flags.selected);
1666 XFlush(dpy);
1668 break;
1669 case WKBD_NEXTWSLAYER:
1670 case WKBD_PREVWSLAYER:
1672 int row, column;
1674 row = scr->current_workspace/10;
1675 column = scr->current_workspace%10;
1677 if (command==WKBD_NEXTWSLAYER) {
1678 if ((row+1)*10 < scr->workspace_count)
1679 wWorkspaceChange(scr, column+(row+1)*10);
1680 } else {
1681 if (row > 0)
1682 wWorkspaceChange(scr, column+(row-1)*10);
1685 break;
1686 case WKBD_CLIPLOWER:
1687 if (!wPreferences.flags.noclip)
1688 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1689 break;
1690 case WKBD_CLIPRAISE:
1691 if (!wPreferences.flags.noclip)
1692 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1693 break;
1694 case WKBD_CLIPRAISELOWER:
1695 if (!wPreferences.flags.noclip)
1696 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1697 break;
1698 #ifdef KEEP_XKB_LOCK_STATUS
1699 case WKBD_TOGGLE:
1700 if(wPreferences.modelock){
1701 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1702 /*toggle*/
1703 XkbLockGroup(dpy,XkbUseCoreKbd,
1704 wwin->frame->languagemode=staterec.compat_state&32?0:1);
1706 break;
1707 #endif /* KEEP_XKB_LOCK_STATUS */
1713 static void
1714 handleMotionNotify(XEvent *event)
1716 WMenu *menu;
1717 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1718 WWindow *wwin;
1720 if (wPreferences.scrollable_menus) {
1721 if (event->xmotion.x_root <= 1 ||
1722 event->xmotion.x_root >= (scr->scr_width - 2) ||
1723 event->xmotion.y_root <= 1 ||
1724 event->xmotion.y_root >= (scr->scr_height - 2)) {
1726 #ifdef DEBUG
1727 puts("pointer at screen edge");
1728 #endif
1730 menu = wMenuUnderPointer(scr);
1731 if (menu!=NULL)
1732 wMenuScroll(menu, event);
1735 #if 0
1736 if (event->xmotion.subwindow == None)
1737 return;
1739 if (scr->scrolledFMaximize != None) {
1740 WWindow *twin;
1742 twin = wWindowFor(scr->scrolledFMaximize);
1743 if (twin && twin->frame_y ==) {
1747 scr->scrolledFMaximize = NULL;
1749 } else {
1751 /* scroll full maximized window */
1752 if (event->xmotion.y_root < 1
1753 || event->xmotion.y_root > scr->scr_height - 1) {
1755 wwin = wWindowFor(event->xmotion.subwindow);
1757 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1758 && WFLAGP(wwin, full_maximize)
1759 && event->xmotion.x_root >= wwin->frame_x
1760 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1762 if (!WFLAGP(wwin, no_titlebar)
1763 && wwin->frame_y <= - wwin->frame->top_width) {
1765 wWindowMove(wwin, wwin->frame_x, 0);
1766 wwin->flags.dragged_while_fmaximized = 0;
1768 } else if (!WFLAGP(wwin, no_resizebar)
1769 && wwin->frame_y + wwin->frame->core->height >=
1770 scr->scr_height + wwin->frame->bottom_width) {
1772 int y = scr->scr_height + wwin->frame->bottom_width;
1774 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1776 wWindowMove(wwin, wwin->frame_x, y);
1777 wwin->flags.dragged_while_fmaximized = 0;
1781 #endif
1785 static void
1786 handleVisibilityNotify(XEvent *event)
1788 WWindow *wwin;
1790 wwin = wWindowFor(event->xvisibility.window);
1791 if (!wwin)
1792 return;
1793 wwin->flags.obscured =
1794 (event->xvisibility.state == VisibilityFullyObscured);