Changes relate to virtual edge.
[wmaker-crm.git] / src / event.c
blob3165c325fb0562a7e8003c84e8ac73e065057128
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>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #ifdef SHAPE
37 # include <X11/extensions/shape.h>
38 #endif
39 #ifdef XDND
40 #include "xdnd.h"
41 #endif
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
48 #include "window.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "application.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
57 #include "dock.h"
58 #include "framewin.h"
59 #include "properties.h"
60 #include "balloon.h"
62 #ifdef GNOME_STUFF
63 # include "gnome.h"
64 #endif
65 #ifdef KWM_HINTS
66 # include "kwm.h"
67 #endif
69 /******** Global Variables **********/
70 extern XContext wWinContext;
72 extern Cursor wCursor[WCUR_LAST];
74 extern WShortKey wKeyBindings[WKBD_LAST];
75 extern int wScreenCount;
76 extern Time LastTimestamp;
77 extern Time LastFocusChange;
79 extern WPreferences wPreferences;
81 #define MOD_MASK wPreferences.modifier_mask
83 extern Atom _XA_WM_COLORMAP_NOTIFY;
85 extern Atom _XA_WM_CHANGE_STATE;
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_ATTR;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
90 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
91 extern Atom _XA_WINDOWMAKER_COMMAND;
93 #ifdef OFFIX_DND
94 extern Atom _XA_DND_PROTOCOL;
95 #endif
98 #ifdef SHAPE
99 extern Bool wShapeSupported;
100 extern int wShapeEventBase;
101 #endif
103 #ifdef KEEP_XKB_LOCK_STATUS
104 extern int wXkbEventBase;
105 #endif
107 /* special flags */
108 extern char WDelayedActionSet;
111 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent *event);
115 static void handleColormapNotify();
116 static void handleMapNotify(), handleUnmapNotify();
117 static void handleButtonPress(), handleExpose();
118 static void handleDestroyNotify();
119 static void handleConfigureRequest();
120 static void handleMapRequest();
121 static void handlePropertyNotify();
122 static void handleEnterNotify();
123 static void handleLeaveNotify();
124 static void handleExtensions();
125 static void handleClientMessage();
126 static void handleKeyPress();
127 static void handleFocusIn();
128 static void handleMotionNotify();
129 static void handleVisibilityNotify();
132 #ifdef SHAPE
133 static void handleShapeNotify();
134 #endif
136 /* called from the signal handler */
137 void NotifyDeadProcess(pid_t pid, unsigned char status);
139 /* real dead process handler */
140 static void handleDeadProcess(void *foo);
143 typedef struct DeadProcesses {
144 pid_t pid;
145 unsigned char exit_status;
146 } DeadProcesses;
148 /* stack of dead processes */
149 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
150 static int deadProcessPtr=0;
153 typedef struct DeathHandler {
154 WDeathHandler *callback;
155 pid_t pid;
156 void *client_data;
157 } DeathHandler;
159 static WMBag *deathHandlers=NULL;
163 WMagicNumber
164 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
166 DeathHandler *handler;
168 handler = malloc(sizeof(DeathHandler));
169 if (!handler)
170 return 0;
172 handler->pid = pid;
173 handler->callback = callback;
174 handler->client_data = cdata;
176 if (!deathHandlers)
177 deathHandlers = WMCreateBag(8);
179 WMPutInBag(deathHandlers, handler);
181 return handler;
186 void
187 wDeleteDeathHandler(WMagicNumber id)
189 DeathHandler *handler=(DeathHandler*)id;
191 if (!handler || !deathHandlers)
192 return;
194 WMRemoveFromBag(deathHandlers, handler);
196 wfree(handler);
200 void
201 DispatchEvent(XEvent *event)
203 if (deathHandlers)
204 handleDeadProcess(NULL);
206 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
207 WCHANGE_STATE(WSTATE_EXITING);
208 /* received SIGTERM */
210 * WMHandleEvent() can't be called from anything
211 * executed inside here, or we can get in a infinite
212 * recursive loop.
214 Shutdown(WSExitMode);
216 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
217 WCHANGE_STATE(WSTATE_RESTARTING);
219 Shutdown(WSRestartPreparationMode);
220 /* received SIGHUP */
221 Restart(NULL, True);
224 /* for the case that all that is wanted to be dispatched is
225 * the stuff above */
226 if (!event)
227 return;
229 saveTimestamp(event);
230 switch (event->type) {
231 case MapRequest:
232 handleMapRequest(event);
233 break;
235 case KeyPress:
236 handleKeyPress(event);
237 break;
239 case MotionNotify:
240 handleMotionNotify(event);
241 break;
243 case ConfigureRequest:
244 handleConfigureRequest(event);
245 break;
247 case DestroyNotify:
248 handleDestroyNotify(event);
249 break;
251 case MapNotify:
252 handleMapNotify(event);
253 break;
255 case UnmapNotify:
256 handleUnmapNotify(event);
257 break;
259 case ButtonPress:
260 handleButtonPress(event);
261 break;
263 case Expose:
264 handleExpose(event);
265 break;
267 case PropertyNotify:
268 handlePropertyNotify(event);
269 break;
271 case EnterNotify:
272 handleEnterNotify(event);
273 break;
275 case LeaveNotify:
276 handleLeaveNotify(event);
277 break;
279 case ClientMessage:
280 handleClientMessage(event);
281 break;
283 case ColormapNotify:
284 handleColormapNotify(event);
285 break;
287 case MappingNotify:
288 if (event->xmapping.request == MappingKeyboard
289 || event->xmapping.request == MappingModifier)
290 XRefreshKeyboardMapping(&event->xmapping);
291 break;
293 case FocusIn:
294 handleFocusIn(event);
295 break;
297 case VisibilityNotify:
298 handleVisibilityNotify(event);
299 break;
300 default:
301 handleExtensions(event);
302 break;
308 *----------------------------------------------------------------------
309 * EventLoop-
310 * Processes X and internal events indefinitely.
312 * Returns:
313 * Never returns
315 * Side effects:
316 * The LastTimestamp global variable is updated.
317 *----------------------------------------------------------------------
319 void
320 EventLoop()
322 XEvent event;
324 for(;;) {
325 WMNextEvent(dpy, &event);
326 WMHandleEvent(&event);
332 Bool
333 IsDoubleClick(WScreen *scr, XEvent *event)
335 if ((scr->last_click_time>0) &&
336 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
337 && (event->xbutton.button == scr->last_click_button)
338 && (event->xbutton.window == scr->last_click_window)) {
340 scr->flags.next_click_is_not_double = 1;
341 scr->last_click_time = 0;
342 scr->last_click_window = event->xbutton.window;
344 return True;
346 return False;
350 void
351 NotifyDeadProcess(pid_t pid, unsigned char status)
353 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
354 wwarning("stack overflow: too many dead processes");
355 return;
357 /* stack the process to be handled later,
358 * as this is called from the signal handler */
359 deadProcesses[deadProcessPtr].pid = pid;
360 deadProcesses[deadProcessPtr].exit_status = status;
361 deadProcessPtr++;
365 static void
366 handleDeadProcess(void *foo)
368 DeathHandler *tmp;
369 int i;
371 for (i=0; i<deadProcessPtr; i++) {
372 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
375 if (!deathHandlers) {
376 deadProcessPtr=0;
377 return;
380 /* get the pids on the queue and call handlers */
381 while (deadProcessPtr>0) {
382 deadProcessPtr--;
384 for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) {
385 tmp = WMGetFromBag(deathHandlers, i);
386 if (!tmp)
387 continue;
389 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
390 (*tmp->callback)(tmp->pid,
391 deadProcesses[deadProcessPtr].exit_status,
392 tmp->client_data);
393 wDeleteDeathHandler(tmp);
400 static void
401 saveTimestamp(XEvent *event)
403 LastTimestamp = CurrentTime;
405 switch (event->type) {
406 case ButtonRelease:
407 case ButtonPress:
408 LastTimestamp = event->xbutton.time;
409 break;
410 case KeyPress:
411 case KeyRelease:
412 LastTimestamp = event->xkey.time;
413 break;
414 case MotionNotify:
415 LastTimestamp = event->xmotion.time;
416 break;
417 case PropertyNotify:
418 LastTimestamp = event->xproperty.time;
419 break;
420 case EnterNotify:
421 case LeaveNotify:
422 LastTimestamp = event->xcrossing.time;
423 break;
424 case SelectionClear:
425 LastTimestamp = event->xselectionclear.time;
426 break;
427 case SelectionRequest:
428 LastTimestamp = event->xselectionrequest.time;
429 break;
430 case SelectionNotify:
431 LastTimestamp = event->xselection.time;
432 #ifdef XDND
433 wXDNDProcessSelection(event);
434 #endif
435 break;
440 static void
441 handleExtensions(XEvent *event)
443 #ifdef KEEP_XKB_LOCK_STATUS
444 XkbEvent *xkbevent;
445 xkbevent = (XkbEvent *)event;
446 #endif /*KEEP_XKB_LOCK_STATUS*/
447 #ifdef SHAPE
448 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
449 handleShapeNotify(event);
451 #endif
452 #ifdef KEEP_XKB_LOCK_STATUS
453 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
454 handleXkbIndicatorStateNotify(event);
456 #endif /*KEEP_XKB_LOCK_STATUS*/
460 static void
461 handleMapRequest(XEvent *ev)
463 WWindow *wwin;
464 WScreen *scr = NULL;
465 Window window = ev->xmaprequest.window;
467 #ifdef DEBUG
468 L("got map request for %x\n", (unsigned)window);
469 #endif
470 if ((wwin = wWindowFor(window))) {
471 if (wwin->flags.shaded) {
472 wUnshadeWindow(wwin);
474 /* deiconify window */
475 if (wwin->flags.miniaturized) {
476 wDeiconifyWindow(wwin);
477 } else if (wwin->flags.hidden) {
478 WApplication *wapp = wApplicationOf(wwin->main_window);
479 /* go to the last workspace that the user worked on the app */
480 #ifndef REDUCE_APPICONS
481 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
482 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
484 if (wapp) {
485 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
487 #endif
488 wUnhideApplication(wapp, False, False);
490 return;
493 scr = wScreenForRootWindow(ev->xmaprequest.parent);
495 wwin = wManageWindow(scr, window);
498 * This is to let the Dock know that the application it launched
499 * has already been mapped (eg: it has finished launching).
500 * It is not necessary for normally docked apps, but is needed for
501 * apps that were forcedly docked (like with dockit).
503 if (scr->last_dock) {
504 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
505 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
506 else
507 wDockTrackWindowLaunch(scr->last_dock, window);
510 if (wwin) {
511 wClientSetState(wwin, NormalState, None);
512 if (wwin->flags.maximized) {
513 wMaximizeWindow(wwin, wwin->flags.maximized);
515 if (wwin->flags.shaded) {
516 wwin->flags.shaded = 0;
517 wwin->flags.skip_next_animation = 1;
518 wShadeWindow(wwin);
520 if (wwin->flags.miniaturized) {
521 wwin->flags.miniaturized = 0;
522 wwin->flags.skip_next_animation = 1;
523 wIconifyWindow(wwin);
525 if (wwin->flags.hidden) {
526 WApplication *wapp = wApplicationOf(wwin->main_window);
528 wwin->flags.hidden = 0;
529 wwin->flags.skip_next_animation = 1;
530 if (wapp) {
531 wHideApplication(wapp);
538 static void
539 handleDestroyNotify(XEvent *event)
541 WWindow *wwin;
542 WApplication *app;
543 Window window = event->xdestroywindow.window;
545 #ifdef DEBUG
546 L("got destroy notify");
547 #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 L("got expose");
583 #endif
584 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
586 if (XFindContext(dpy, event->xexpose.window, wWinContext,
587 (XPointer *)&desc)==XCNOENT) {
588 return;
591 if (desc->handle_expose) {
592 (*desc->handle_expose)(desc, event);
596 /* bindable */
597 static void
598 handleButtonPress(XEvent *event)
600 WObjDescriptor *desc;
601 WScreen *scr;
602 #ifdef DEBUG
603 L("got button press");
604 #endif
605 scr = wScreenForRootWindow(event->xbutton.root);
607 #ifdef BALLOON_TEXT
608 wBalloonHide(scr);
609 #endif
612 #ifndef LITE
613 if (event->xbutton.window==scr->root_win) {
614 if (event->xbutton.button==wPreferences.menu_button) {
615 OpenRootMenu(scr, event->xbutton.x_root,
616 event->xbutton.y_root, False);
617 /* ugly hack */
618 if (scr->root_menu) {
619 if (scr->root_menu->brother->flags.mapped)
620 event->xbutton.window = scr->root_menu->brother->frame->core->window;
621 else
622 event->xbutton.window = scr->root_menu->frame->core->window;
624 } else if (event->xbutton.button==wPreferences.windowl_button) {
625 OpenSwitchMenu(scr, event->xbutton.x_root,
626 event->xbutton.y_root, False);
627 if (scr->switch_menu) {
628 if (scr->switch_menu->brother->flags.mapped)
629 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
630 else
631 event->xbutton.window = scr->switch_menu->frame->core->window;
633 } else if (event->xbutton.button==wPreferences.select_button) {
634 wUnselectWindows(scr);
635 wSelectWindows(scr, event);
637 #ifdef MOUSE_WS_SWITCH
638 else if (event->xbutton.button==Button5) {
640 wWorkspaceRelativeChange(scr, -1);
642 } else if (event->xbutton.button==Button4) {
644 wWorkspaceRelativeChange(scr, 1);
647 #endif /* MOUSE_WS_SWITCH */
648 #ifdef GNOME_STUFF
649 else if (wGNOMEProxyizeButtonEvent(scr, event))
650 return;
651 #endif
653 #endif /* !LITE */
655 desc = NULL;
656 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
657 (XPointer *)&desc)==XCNOENT) {
658 if (XFindContext(dpy, event->xbutton.window, wWinContext,
659 (XPointer *)&desc)==XCNOENT) {
660 return;
664 if (desc->parent_type == WCLASS_WINDOW) {
665 XSync(dpy, 0);
667 if (event->xbutton.state & MOD_MASK) {
668 XAllowEvents(dpy, AsyncPointer, CurrentTime);
671 if (wPreferences.focus_mode == WKF_CLICK) {
672 if (wPreferences.ignore_focus_click) {
673 XAllowEvents(dpy, AsyncPointer, CurrentTime);
675 XAllowEvents(dpy, ReplayPointer, CurrentTime);
677 XSync(dpy, 0);
678 } else if (desc->parent_type == WCLASS_APPICON
679 || desc->parent_type == WCLASS_MINIWINDOW
680 || desc->parent_type == WCLASS_DOCK_ICON) {
681 if (event->xbutton.state & MOD_MASK) {
682 XSync(dpy, 0);
683 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 XSync(dpy, 0);
688 if (desc->handle_mousedown!=NULL) {
689 (*desc->handle_mousedown)(desc, event);
692 /* save double-click information */
693 if (scr->flags.next_click_is_not_double) {
694 scr->flags.next_click_is_not_double = 0;
695 } else {
696 scr->last_click_time = event->xbutton.time;
697 scr->last_click_button = event->xbutton.button;
698 scr->last_click_window = event->xbutton.window;
703 static void
704 handleMapNotify(XEvent *event)
706 WWindow *wwin;
707 #ifdef DEBUG
708 L("got map");
709 #endif
710 wwin = wWindowFor(event->xmap.event);
711 if (wwin && wwin->client_win == event->xmap.event) {
712 if (wwin->flags.miniaturized) {
713 wDeiconifyWindow(wwin);
714 } else {
715 XGrabServer(dpy);
716 wWindowMap(wwin);
717 wClientSetState(wwin, NormalState, None);
718 XUngrabServer(dpy);
724 static void
725 handleUnmapNotify(XEvent *event)
727 WWindow *wwin;
728 XEvent ev;
729 Bool withdraw = False;
730 #ifdef DEBUG
731 L("got unmap");
732 #endif
733 /* only process windows with StructureNotify selected
734 * (ignore SubstructureNotify) */
735 wwin = wWindowFor(event->xunmap.window);
736 if (!wwin)
737 return;
739 /* whether the event is a Withdrawal request */
740 if (event->xunmap.event == wwin->screen_ptr->root_win
741 && event->xunmap.send_event)
742 withdraw = True;
744 if (wwin->client_win != event->xunmap.event && !withdraw)
745 return;
747 if (!wwin->flags.mapped && !withdraw
748 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
749 && !wwin->flags.miniaturized && !wwin->flags.hidden)
750 return;
752 XGrabServer(dpy);
753 XUnmapWindow(dpy, wwin->frame->core->window);
754 wwin->flags.mapped = 0;
755 XSync(dpy, 0);
756 /* check if the window was destroyed */
757 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
758 DispatchEvent(&ev);
759 } else {
760 Bool reparented = False;
762 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
763 reparented = True;
765 /* withdraw window */
766 wwin->flags.mapped = 0;
767 if (!reparented)
768 wClientSetState(wwin, WithdrawnState, None);
770 /* if the window was reparented, do not reparent it back to the
771 * root window */
772 wUnmanageWindow(wwin, !reparented, False);
774 XUngrabServer(dpy);
778 static void
779 handleConfigureRequest(XEvent *event)
781 WWindow *wwin;
782 #ifdef DEBUG
783 L("got configure request");
784 #endif
785 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
787 * Configure request for unmapped window
789 wClientConfigure(NULL, &(event->xconfigurerequest));
790 } else {
791 wClientConfigure(wwin, &(event->xconfigurerequest));
796 static void
797 handlePropertyNotify(XEvent *event)
799 WWindow *wwin;
800 WApplication *wapp;
801 Window jr;
802 int ji;
803 unsigned int ju;
804 WScreen *scr;
805 #ifdef DEBUG
806 L("got property notify");
807 #endif
808 if ((wwin=wWindowFor(event->xproperty.window))) {
809 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
810 &ju, &ju, &ju, &ju)) {
811 return;
813 wClientCheckProperty(wwin, &event->xproperty);
815 wapp = wApplicationOf(event->xproperty.window);
816 if (wapp) {
817 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
820 scr = wScreenForWindow(event->xproperty.window);
821 if (scr && scr->root_win == event->xproperty.window) {
822 #ifdef KWM_HINTS
823 wKWMCheckRootHintChange(scr, &event->xproperty);
824 #endif
829 static void
830 handleClientMessage(XEvent *event)
832 WWindow *wwin;
833 WObjDescriptor *desc;
834 #ifdef DEBUG
835 L("got client message");
836 #endif
837 /* handle transition from Normal to Iconic state */
838 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
839 && event->xclient.format == 32
840 && event->xclient.data.l[0] == IconicState) {
842 wwin = wWindowFor(event->xclient.window);
843 if (!wwin) return;
844 if (!wwin->flags.miniaturized)
845 wIconifyWindow(wwin);
846 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
847 && event->xclient.format == 32) {
848 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
850 if (!scr)
851 return;
853 if (event->xclient.data.l[1] == 1) { /* starting */
854 wColormapAllowClientInstallation(scr, True);
855 } else { /* stopping */
856 wColormapAllowClientInstallation(scr, False);
858 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
860 wDefaultsCheckDomains("bla");
862 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
863 WApplication *wapp;
864 int done=0;
865 wapp = wApplicationOf(event->xclient.window);
866 if (wapp) {
867 switch (event->xclient.data.l[0]) {
868 case WMFHideOtherApplications:
869 wHideOtherApplications(wapp->main_window_desc);
870 done = 1;
871 break;
873 case WMFHideApplication:
874 wHideApplication(wapp);
875 done = 1;
876 break;
879 if (!done) {
880 wwin = wWindowFor(event->xclient.window);
881 if (wwin) {
882 switch (event->xclient.data.l[0]) {
883 case WMFHideOtherApplications:
884 wHideOtherApplications(wwin);
885 break;
887 case WMFHideApplication:
888 wHideApplication(wApplicationOf(wwin->main_window));
889 break;
893 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
894 wwin = wWindowFor(event->xclient.window);
895 if (!wwin) return;
896 switch (event->xclient.data.l[0]) {
897 case GSWindowLevelAttr:
899 int level = (int)event->xclient.data.l[1];
901 if (WINDOW_LEVEL(wwin) != level) {
902 ChangeStackingLevel(wwin->frame->core, level);
905 break;
907 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
908 wwin = wWindowFor(event->xclient.window);
909 if (!wwin) return;
910 switch (event->xclient.data.l[0]) {
911 case WMTitleBarNormal:
912 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
913 break;
914 case WMTitleBarMain:
915 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
916 break;
917 case WMTitleBarKey:
918 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
919 break;
921 #ifdef GNOME_STUFF
922 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
923 /* do nothing */
924 #endif /* GNOME_STUFF */
925 #ifdef KWM_HINTS
926 } else if (wKWMProcessClientMessage(&event->xclient)) {
927 /* do nothing */
928 #endif /* KWM_HINTS */
929 #ifdef XDND
930 } else if (wXDNDProcessClientMessage(&event->xclient)) {
931 /* do nothing */
932 #endif /* XDND */
933 #ifdef OFFIX_DND
934 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
935 WScreen *scr = wScreenForWindow(event->xclient.window);
936 if (scr && wDockReceiveDNDDrop(scr,event))
937 goto redirect_message;
938 #endif /* OFFIX_DND */
939 } else {
940 #ifdef OFFIX_DND
941 redirect_message:
942 #endif
944 * Non-standard thing, but needed by OffiX DND.
945 * For when the icon frame gets a ClientMessage
946 * that should have gone to the icon_window.
948 if (XFindContext(dpy, event->xbutton.window, wWinContext,
949 (XPointer *)&desc)!=XCNOENT) {
950 struct WIcon *icon=NULL;
952 if (desc->parent_type == WCLASS_MINIWINDOW) {
953 icon = (WIcon*)desc->parent;
954 } else if (desc->parent_type == WCLASS_DOCK_ICON
955 || desc->parent_type == WCLASS_APPICON) {
956 icon = ((WAppIcon*)desc->parent)->icon;
958 if (icon && (wwin=icon->owner)) {
959 if (wwin->client_win!=event->xclient.window) {
960 event->xclient.window = wwin->client_win;
961 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
962 event);
970 static void
971 raiseWindow(WScreen *scr)
973 WWindow *wwin;
975 scr->autoRaiseTimer = NULL;
977 wwin = wWindowFor(scr->autoRaiseWindow);
978 if (!wwin)
979 return;
981 if (!wwin->flags.destroyed && wwin->flags.focused) {
982 wRaiseFrame(wwin->frame->core);
983 /* this is needed or a race condition will occur */
984 XSync(dpy, False);
989 static void
990 handleEnterNotify(XEvent *event)
992 WWindow *wwin;
993 WObjDescriptor *desc = NULL;
994 XEvent ev;
995 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
996 #ifdef DEBUG
997 L("got enter notify");
998 #endif
1000 #ifdef VIRTUAL_DESKTOP
1001 if (wPreferences.vedge_thickness) {
1002 int x,y;
1003 if (event->xcrossing.window == scr->virtual_edge_r) {
1004 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1005 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y, NULL, NULL);
1006 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1007 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1008 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1009 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y, NULL, NULL);
1010 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1011 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1012 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1013 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y, NULL, NULL);
1014 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1015 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1016 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1017 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y, NULL, NULL);
1018 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1021 #endif
1023 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1024 &ev)) {
1025 /* already left the window... */
1026 saveTimestamp(&ev);
1027 if (ev.xcrossing.mode==event->xcrossing.mode
1028 && ev.xcrossing.detail==event->xcrossing.detail) {
1029 return;
1033 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1034 (XPointer *)&desc)!=XCNOENT) {
1035 if(desc->handle_enternotify)
1036 (*desc->handle_enternotify)(desc, event);
1039 /* enter to window */
1040 wwin = wWindowFor(event->xcrossing.window);
1041 if (!wwin) {
1042 if (wPreferences.focus_mode==WKF_POINTER
1043 && event->xcrossing.window==event->xcrossing.root) {
1044 wSetFocusTo(scr, NULL);
1046 if (wPreferences.colormap_mode==WKF_POINTER) {
1047 wColormapInstallForWindow(scr, NULL);
1049 if (scr->autoRaiseTimer
1050 && event->xcrossing.root==event->xcrossing.window) {
1051 WMDeleteTimerHandler(scr->autoRaiseTimer);
1052 scr->autoRaiseTimer = NULL;
1054 } else {
1055 /* set auto raise timer even if in focus-follows-mouse mode
1056 * and the event is for the frame window, even if the window
1057 * has focus already. useful if you move the pointer from a focused
1058 * window to the root window and back pretty fast
1060 * set focus if in focus-follows-mouse mode and the event
1061 * is for the frame window and window doesn't have focus yet */
1062 if ((wPreferences.focus_mode==WKF_POINTER
1063 || wPreferences.focus_mode==WKF_SLOPPY)
1064 && wwin->frame->core->window==event->xcrossing.window
1065 && !scr->flags.doing_alt_tab) {
1067 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1068 wSetFocusTo(scr, wwin);
1070 if (scr->autoRaiseTimer)
1071 WMDeleteTimerHandler(scr->autoRaiseTimer);
1072 scr->autoRaiseTimer = NULL;
1074 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1075 scr->autoRaiseWindow = wwin->frame->core->window;
1076 scr->autoRaiseTimer
1077 = WMAddTimerHandler(wPreferences.raise_delay,
1078 (WMCallback*)raiseWindow, scr);
1081 /* Install colormap for window, if the colormap installation mode
1082 * is colormap_follows_mouse */
1083 if (wPreferences.colormap_mode==WKF_POINTER) {
1084 if (wwin->client_win==event->xcrossing.window)
1085 wColormapInstallForWindow(scr, wwin);
1086 else
1087 wColormapInstallForWindow(scr, NULL);
1091 /* a little kluge to hide the clip balloon */
1092 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1093 if (!desc) {
1094 XUnmapWindow(dpy, scr->clip_balloon);
1095 scr->flags.clip_balloon_mapped = 0;
1096 } else {
1097 if (desc->parent_type!=WCLASS_DOCK_ICON
1098 || scr->clip_icon != desc->parent) {
1099 XUnmapWindow(dpy, scr->clip_balloon);
1100 scr->flags.clip_balloon_mapped = 0;
1105 if (event->xcrossing.window == event->xcrossing.root
1106 && event->xcrossing.detail == NotifyNormal
1107 && event->xcrossing.detail != NotifyInferior
1108 && wPreferences.focus_mode != WKF_CLICK) {
1110 wSetFocusTo(scr, scr->focused_window);
1113 #ifdef BALLOON_TEXT
1114 wBalloonEnteredObject(scr, desc);
1115 #endif
1119 static void
1120 handleLeaveNotify(XEvent *event)
1122 WObjDescriptor *desc = NULL;
1124 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1125 (XPointer *)&desc)!=XCNOENT) {
1126 if(desc->handle_leavenotify)
1127 (*desc->handle_leavenotify)(desc, event);
1129 if (event->xcrossing.window == event->xcrossing.root
1130 && event->xcrossing.mode == NotifyNormal
1131 && event->xcrossing.detail != NotifyInferior
1132 && wPreferences.focus_mode != WKF_CLICK) {
1134 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1136 wSetFocusTo(scr, NULL);
1141 #ifdef SHAPE
1142 static void
1143 handleShapeNotify(XEvent *event)
1145 XShapeEvent *shev = (XShapeEvent*)event;
1146 WWindow *wwin;
1147 XEvent ev;
1148 #ifdef DEBUG
1149 L("got shape notify");
1150 #endif
1151 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1152 XShapeEvent *sev = (XShapeEvent*)&ev;
1154 if (sev->kind == ShapeBounding) {
1155 if (sev->shaped == shev->shaped) {
1156 *shev = *sev;
1157 } else {
1158 XPutBackEvent(dpy, &ev);
1159 break;
1164 wwin = wWindowFor(shev->window);
1165 if (!wwin || shev->kind != ShapeBounding)
1166 return;
1168 if (!shev->shaped && wwin->flags.shaped) {
1170 wwin->flags.shaped = 0;
1171 wWindowClearShape(wwin);
1173 } else if (shev->shaped) {
1175 wwin->flags.shaped = 1;
1176 wWindowSetShape(wwin);
1179 #endif /* SHAPE */
1181 #ifdef KEEP_XKB_LOCK_STATUS
1182 /* please help ]d if you know what to do */
1183 handleXkbIndicatorStateNotify(XEvent *event)
1185 WWindow *wwin;
1186 WScreen *scr;
1187 XkbStateRec staterec;
1188 int i;
1190 for (i=0; i<wScreenCount; i++) {
1191 scr = wScreenWithNumber(i);
1192 wwin = scr->focused_window;
1193 if (wwin && wwin->flags.focused) {
1194 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1195 if (wwin->frame->languagemode != staterec.group) {
1196 wwin->frame->last_languagemode = wwin->frame->languagemode;
1197 wwin->frame->languagemode = staterec.group;
1199 #ifdef XKB_BUTTON_HINT
1200 if (wwin->frame->titlebar) {
1201 wFrameWindowPaint(wwin->frame);
1203 #endif
1207 #endif /*KEEP_XKB_LOCK_STATUS*/
1209 static void
1210 handleColormapNotify(XEvent *event)
1212 WWindow *wwin;
1213 WScreen *scr;
1214 Bool reinstall = False;
1216 wwin = wWindowFor(event->xcolormap.window);
1217 if (!wwin)
1218 return;
1220 scr = wwin->screen_ptr;
1222 do {
1223 if (wwin) {
1224 if (event->xcolormap.new) {
1225 XWindowAttributes attr;
1227 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1229 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1230 scr->current_colormap = attr.colormap;
1232 reinstall = True;
1233 } else if (event->xcolormap.state == ColormapUninstalled &&
1234 scr->current_colormap == event->xcolormap.colormap) {
1236 /* some bastard app (like XV) removed our colormap */
1238 * can't enforce or things like xscreensaver wont work
1239 * reinstall = True;
1241 } else if (event->xcolormap.state == ColormapInstalled &&
1242 scr->current_colormap == event->xcolormap.colormap) {
1244 /* someone has put our colormap back */
1245 reinstall = False;
1248 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1249 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1251 if (reinstall && scr->current_colormap!=None) {
1252 if (!scr->flags.colormap_stuff_blocked)
1253 XInstallColormap(dpy, scr->current_colormap);
1259 static void
1260 handleFocusIn(XEvent *event)
1262 WWindow *wwin;
1265 * For applications that like stealing the focus.
1267 while (XCheckTypedEvent(dpy, FocusIn, event));
1268 saveTimestamp(event);
1269 if (event->xfocus.mode == NotifyUngrab
1270 || event->xfocus.mode == NotifyGrab
1271 || event->xfocus.detail > NotifyNonlinearVirtual) {
1272 return;
1275 wwin = wWindowFor(event->xfocus.window);
1276 if (wwin && !wwin->flags.focused) {
1277 if (wwin->flags.mapped)
1278 wSetFocusTo(wwin->screen_ptr, wwin);
1279 else
1280 wSetFocusTo(wwin->screen_ptr, NULL);
1281 } else if (!wwin) {
1282 WScreen *scr = wScreenForWindow(event->xfocus.window);
1283 if (scr)
1284 wSetFocusTo(scr, NULL);
1289 static WWindow*
1290 windowUnderPointer(WScreen *scr)
1292 unsigned int mask;
1293 int foo;
1294 Window bar, win;
1296 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1297 &mask))
1298 return wWindowFor(win);
1299 return NULL;
1305 static void
1306 handleKeyPress(XEvent *event)
1308 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1309 WWindow *wwin = scr->focused_window;
1310 int i;
1311 int modifiers;
1312 int command=-1, index;
1313 #ifdef KEEP_XKB_LOCK_STATUS
1314 XkbStateRec staterec;
1315 #endif /*KEEP_XKB_LOCK_STATUS*/
1317 /* ignore CapsLock */
1318 modifiers = event->xkey.state & ValidModMask;
1320 for (i=0; i<WKBD_LAST; i++) {
1321 if (wKeyBindings[i].keycode==0)
1322 continue;
1324 if (wKeyBindings[i].keycode==event->xkey.keycode
1325 && (/*wKeyBindings[i].modifier==0
1326 ||*/ wKeyBindings[i].modifier==modifiers)) {
1327 command = i;
1328 break;
1333 if (command < 0) {
1334 #ifdef LITE
1336 #if 0
1338 #endif
1339 #else
1340 if (!wRootMenuPerformShortcut(event)) {
1341 #endif
1342 static int dontLoop = 0;
1344 if (dontLoop > 10) {
1345 wwarning("problem with key event processing code");
1346 return;
1348 dontLoop++;
1349 /* if the focused window is an internal window, try redispatching
1350 * the event to the managed window, as it can be a WINGs window */
1351 if (wwin && wwin->flags.internal_window
1352 && wwin->client_leader!=None) {
1353 /* client_leader contains the WINGs toplevel */
1354 event->xany.window = wwin->client_leader;
1355 WMHandleEvent(event);
1357 dontLoop--;
1359 return;
1362 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1363 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1365 switch (command) {
1366 #ifndef LITE
1367 case WKBD_ROOTMENU:
1368 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1369 break;
1370 case WKBD_WINDOWLIST:
1371 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1372 break;
1373 #endif /* !LITE */
1374 case WKBD_WINDOWMENU:
1375 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1376 OpenWindowMenu(wwin, wwin->frame_x,
1377 wwin->frame_y+wwin->frame->top_width, True);
1378 break;
1379 case WKBD_MINIATURIZE:
1380 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1381 && !WFLAGP(wwin, no_miniaturizable)) {
1382 CloseWindowMenu(scr);
1384 if (wwin->protocols.MINIATURIZE_WINDOW)
1385 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1386 event->xbutton.time);
1387 else {
1388 wIconifyWindow(wwin);
1391 break;
1392 case WKBD_HIDE:
1393 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1394 WApplication *wapp = wApplicationOf(wwin->main_window);
1395 CloseWindowMenu(scr);
1397 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1398 wHideApplication(wapp);
1401 break;
1402 case WKBD_MAXIMIZE:
1403 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1404 CloseWindowMenu(scr);
1406 if (wwin->flags.maximized) {
1407 wUnmaximizeWindow(wwin);
1408 } else {
1409 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1412 break;
1413 case WKBD_VMAXIMIZE:
1414 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1415 CloseWindowMenu(scr);
1417 if (wwin->flags.maximized) {
1418 wUnmaximizeWindow(wwin);
1419 } else {
1420 wMaximizeWindow(wwin, MAX_VERTICAL);
1423 break;
1424 case WKBD_RAISE:
1425 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1426 CloseWindowMenu(scr);
1428 wRaiseFrame(wwin->frame->core);
1430 break;
1431 case WKBD_LOWER:
1432 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1433 CloseWindowMenu(scr);
1435 wLowerFrame(wwin->frame->core);
1437 break;
1438 case WKBD_RAISELOWER:
1439 /* raise or lower the window under the pointer, not the
1440 * focused one
1442 wwin = windowUnderPointer(scr);
1443 if (wwin)
1444 wRaiseLowerFrame(wwin->frame->core);
1445 break;
1446 case WKBD_SHADE:
1447 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1448 if (wwin->flags.shaded)
1449 wUnshadeWindow(wwin);
1450 else
1451 wShadeWindow(wwin);
1453 break;
1454 case WKBD_MOVERESIZE:
1455 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1456 CloseWindowMenu(scr);
1458 wKeyboardMoveResizeWindow(wwin);
1460 break;
1461 case WKBD_CLOSE:
1462 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1463 CloseWindowMenu(scr);
1464 if (wwin->protocols.DELETE_WINDOW)
1465 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1466 event->xkey.time);
1468 break;
1469 case WKBD_SELECT:
1470 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1471 wSelectWindow(wwin, !wwin->flags.selected);
1473 break;
1474 case WKBD_FOCUSNEXT:
1475 if (wKeyBindings[WKBD_FOCUSNEXT].modifier != 0
1476 && wPreferences.windows_cycling)
1477 StartWindozeCycle(wwin, event, True);
1478 else
1479 CycleWindow(scr, True);
1480 break;
1482 case WKBD_FOCUSPREV:
1483 if (wKeyBindings[WKBD_FOCUSPREV].modifier != 0
1484 && wPreferences.windows_cycling)
1485 StartWindozeCycle(wwin, event, False);
1486 else
1487 CycleWindow(scr, False);
1488 break;
1490 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1491 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1492 i = (scr->current_workspace/10)*10 + wk - 1;\
1493 if (wPreferences.ws_advance || i<scr->workspace_count)\
1494 wWorkspaceChange(scr, i);\
1495 break
1496 #else
1497 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1498 i = (scr->current_workspace/10)*10 + wk - 1;\
1499 if (wPreferences.ws_advance || i<scr->workspace_count)\
1500 wWorkspaceChange(scr, i);\
1501 break
1502 #endif
1503 GOTOWORKS(1);
1504 GOTOWORKS(2);
1505 GOTOWORKS(3);
1506 GOTOWORKS(4);
1507 GOTOWORKS(5);
1508 GOTOWORKS(6);
1509 GOTOWORKS(7);
1510 GOTOWORKS(8);
1511 GOTOWORKS(9);
1512 GOTOWORKS(10);
1513 #undef GOTOWORKS
1514 case WKBD_NEXTWORKSPACE:
1515 wWorkspaceRelativeChange(scr, 1);
1516 break;
1517 case WKBD_PREVWORKSPACE:
1518 wWorkspaceRelativeChange(scr, -1);
1519 break;
1520 case WKBD_WINDOW1:
1521 case WKBD_WINDOW2:
1522 case WKBD_WINDOW3:
1523 case WKBD_WINDOW4:
1524 case WKBD_WINDOW5:
1525 case WKBD_WINDOW6:
1526 case WKBD_WINDOW7:
1527 case WKBD_WINDOW8:
1528 case WKBD_WINDOW9:
1529 case WKBD_WINDOW10:
1531 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1533 index = command-WKBD_WINDOW1;
1535 if (scr->shortcutWindows[index]) {
1536 WMBag *list = scr->shortcutWindows[index];
1537 int cw;
1538 int count = WMGetBagItemCount(list);
1539 WWindow *twin;
1540 WMBagIterator iter;
1541 WWindow *wwin;
1543 wUnselectWindows(scr);
1544 cw = scr->current_workspace;
1546 for (wwin = WMBagLast(list, &iter);
1547 iter != NULL;
1548 wwin = WMBagPrevious(list, &iter)) {
1550 if (count > 1)
1551 wWindowChangeWorkspace(wwin, cw);
1553 wMakeWindowVisible(wwin);
1555 if (count > 1)
1556 wSelectWindow(wwin, True);
1559 /* rotate the order of windows, to create a cycling effect */
1560 twin = WMBagFirst(list, &iter);
1561 WMRemoveFromBag(list, twin);
1562 WMPutInBag(list, twin);
1564 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1566 INITBAG(scr->shortcutWindows[index]);
1567 WMPutInBag(scr->shortcutWindows[index], wwin);
1569 if (wwin->flags.selected && scr->selected_windows) {
1570 WMBag *selwins = scr->selected_windows;
1571 int i;
1573 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1574 WWindow *tmp = WMGetFromBag(selwins, i);
1576 if (tmp != wwin)
1577 WMPutInBag(scr->shortcutWindows[index], tmp);
1580 wSelectWindow(wwin, !wwin->flags.selected);
1581 XFlush(dpy);
1582 wusleep(3000);
1583 wSelectWindow(wwin, !wwin->flags.selected);
1584 XFlush(dpy);
1586 } else if (scr->selected_windows
1587 && WMGetBagItemCount(scr->selected_windows)) {
1589 if (wwin->flags.selected && scr->selected_windows) {
1590 WMBag *selwins = scr->selected_windows;
1591 int i;
1593 INITBAG(scr->shortcutWindows[index]);
1595 for (i = 0; i < WMGetBagItemCount(selwins); i++) {
1596 WWindow *tmp = WMGetFromBag(selwins, i);
1598 WMPutInBag(scr->shortcutWindows[index], tmp);
1602 #undef INITBAG
1604 break;
1606 case WKBD_SWITCH_SCREEN:
1607 if (wScreenCount > 1) {
1608 WScreen *scr2;
1609 int i;
1611 /* find index of this screen */
1612 for (i = 0; i < wScreenCount; i++) {
1613 if (wScreenWithNumber(i) == scr)
1614 break;
1616 i++;
1617 if (i >= wScreenCount) {
1618 i = 0;
1620 scr2 = wScreenWithNumber(i);
1622 if (scr2) {
1623 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1624 scr2->scr_width/2, scr2->scr_height/2);
1627 break;
1629 case WKBD_NEXTWSLAYER:
1630 case WKBD_PREVWSLAYER:
1632 int row, column;
1634 row = scr->current_workspace/10;
1635 column = scr->current_workspace%10;
1637 if (command==WKBD_NEXTWSLAYER) {
1638 if ((row+1)*10 < scr->workspace_count)
1639 wWorkspaceChange(scr, column+(row+1)*10);
1640 } else {
1641 if (row > 0)
1642 wWorkspaceChange(scr, column+(row-1)*10);
1645 break;
1646 case WKBD_CLIPLOWER:
1647 if (!wPreferences.flags.noclip)
1648 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1649 break;
1650 case WKBD_CLIPRAISE:
1651 if (!wPreferences.flags.noclip)
1652 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1653 break;
1654 case WKBD_CLIPRAISELOWER:
1655 if (!wPreferences.flags.noclip)
1656 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1657 break;
1658 #ifdef KEEP_XKB_LOCK_STATUS
1659 case WKBD_TOGGLE:
1660 if(wPreferences.modelock) {
1661 /*toggle*/
1662 wwin = scr->focused_window;
1664 if (wwin && wwin->flags.mapped
1665 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1666 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1667 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1669 wwin->frame->languagemode = wwin->frame->last_languagemode;
1670 wwin->frame->last_languagemode = staterec.group;
1671 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
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);
1688 if (wPreferences.scrollable_menus) {
1689 if (scr->flags.jump_back_pending ||
1690 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)) {
1694 #ifdef DEBUG
1695 L("pointer at screen edge");
1696 #endif
1697 menu = wMenuUnderPointer(scr);
1698 if (menu!=NULL)
1699 wMenuScroll(menu, event);
1702 #if 0
1703 if (event->xmotion.subwindow == None)
1704 return;
1706 if (scr->scrolledFMaximize != None) {
1707 WWindow *twin;
1709 twin = wWindowFor(scr->scrolledFMaximize);
1710 if (twin && twin->frame_y ==) {
1714 scr->scrolledFMaximize = NULL;
1716 } else {
1718 /* scroll full maximized window */
1719 if (event->xmotion.y_root < 1
1720 || event->xmotion.y_root > scr->scr_height - 1) {
1722 wwin = wWindowFor(event->xmotion.subwindow);
1724 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1725 && WFLAGP(wwin, full_maximize)
1726 && event->xmotion.x_root >= wwin->frame_x
1727 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1729 if (!WFLAGP(wwin, no_titlebar)
1730 && wwin->frame_y <= - wwin->frame->top_width) {
1732 wWindowMove(wwin, wwin->frame_x, 0);
1733 wwin->flags.dragged_while_fmaximized = 0;
1735 } else if (!WFLAGP(wwin, no_resizebar)
1736 && wwin->frame_y + wwin->frame->core->height >=
1737 scr->scr_height + wwin->frame->bottom_width) {
1739 int y = scr->scr_height + wwin->frame->bottom_width;
1741 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1743 wWindowMove(wwin, wwin->frame_x, y);
1744 wwin->flags.dragged_while_fmaximized = 0;
1748 #endif
1752 static void
1753 handleVisibilityNotify(XEvent *event)
1755 WWindow *wwin;
1757 wwin = wWindowFor(event->xvisibility.window);
1758 if (!wwin)
1759 return;
1760 wwin->flags.obscured =
1761 (event->xvisibility.state == VisibilityFullyObscured);