- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the
[wmaker-crm.git] / src / event.c
blob7e07e19f82e62a886af41859c74c4d0dfc875d9a
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 WMArray *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 = WMCreateArrayWithDestructor(8, wfree);
179 WMAddToArray(deathHandlers, handler);
181 return handler;
186 void
187 wDeleteDeathHandler(WMagicNumber id)
189 DeathHandler *handler=(DeathHandler*)id;
191 if (!handler || !deathHandlers)
192 return;
194 /* array destructor will call wfree(handler) */
195 WMRemoveFromArray(deathHandlers, handler);
199 void
200 DispatchEvent(XEvent *event)
202 if (deathHandlers)
203 handleDeadProcess(NULL);
205 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
206 WCHANGE_STATE(WSTATE_EXITING);
207 /* received SIGTERM */
209 * WMHandleEvent() can't be called from anything
210 * executed inside here, or we can get in a infinite
211 * recursive loop.
213 Shutdown(WSExitMode);
215 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
216 WCHANGE_STATE(WSTATE_RESTARTING);
218 Shutdown(WSRestartPreparationMode);
219 /* received SIGHUP */
220 Restart(NULL, True);
221 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
222 WCHANGE_STATE(WSTATE_NORMAL);
223 wDefaultsCheckDomains("bla");
226 /* for the case that all that is wanted to be dispatched is
227 * the stuff above */
228 if (!event)
229 return;
231 saveTimestamp(event);
232 switch (event->type) {
233 case MapRequest:
234 handleMapRequest(event);
235 break;
237 case KeyPress:
238 handleKeyPress(event);
239 break;
241 case MotionNotify:
242 handleMotionNotify(event);
243 break;
245 case ConfigureRequest:
246 handleConfigureRequest(event);
247 break;
249 case DestroyNotify:
250 handleDestroyNotify(event);
251 break;
253 case MapNotify:
254 handleMapNotify(event);
255 break;
257 case UnmapNotify:
258 handleUnmapNotify(event);
259 break;
261 case ButtonPress:
262 handleButtonPress(event);
263 break;
265 case Expose:
266 handleExpose(event);
267 break;
269 case PropertyNotify:
270 handlePropertyNotify(event);
271 break;
273 case EnterNotify:
274 handleEnterNotify(event);
275 break;
277 case LeaveNotify:
278 handleLeaveNotify(event);
279 break;
281 case ClientMessage:
282 handleClientMessage(event);
283 break;
285 case ColormapNotify:
286 handleColormapNotify(event);
287 break;
289 case MappingNotify:
290 if (event->xmapping.request == MappingKeyboard
291 || event->xmapping.request == MappingModifier)
292 XRefreshKeyboardMapping(&event->xmapping);
293 break;
295 case FocusIn:
296 handleFocusIn(event);
297 break;
299 case VisibilityNotify:
300 handleVisibilityNotify(event);
301 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 (!deathHandlers) {
378 deadProcessPtr=0;
379 return;
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr>0) {
384 deadProcessPtr--;
386 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
387 tmp = WMGetFromArray(deathHandlers, i);
388 if (!tmp)
389 continue;
391 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
392 (*tmp->callback)(tmp->pid,
393 deadProcesses[deadProcessPtr].exit_status,
394 tmp->client_data);
395 wDeleteDeathHandler(tmp);
402 static void
403 saveTimestamp(XEvent *event)
405 LastTimestamp = CurrentTime;
407 switch (event->type) {
408 case ButtonRelease:
409 case ButtonPress:
410 LastTimestamp = event->xbutton.time;
411 break;
412 case KeyPress:
413 case KeyRelease:
414 LastTimestamp = event->xkey.time;
415 break;
416 case MotionNotify:
417 LastTimestamp = event->xmotion.time;
418 break;
419 case PropertyNotify:
420 LastTimestamp = event->xproperty.time;
421 break;
422 case EnterNotify:
423 case LeaveNotify:
424 LastTimestamp = event->xcrossing.time;
425 break;
426 case SelectionClear:
427 LastTimestamp = event->xselectionclear.time;
428 break;
429 case SelectionRequest:
430 LastTimestamp = event->xselectionrequest.time;
431 break;
432 case SelectionNotify:
433 LastTimestamp = event->xselection.time;
434 #ifdef XDND
435 wXDNDProcessSelection(event);
436 #endif
437 break;
442 static void
443 handleExtensions(XEvent *event)
445 #ifdef KEEP_XKB_LOCK_STATUS
446 XkbEvent *xkbevent;
447 xkbevent = (XkbEvent *)event;
448 #endif /*KEEP_XKB_LOCK_STATUS*/
449 #ifdef SHAPE
450 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
451 handleShapeNotify(event);
453 #endif
454 #ifdef KEEP_XKB_LOCK_STATUS
455 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
456 handleXkbIndicatorStateNotify(event);
458 #endif /*KEEP_XKB_LOCK_STATUS*/
462 static void
463 handleMapRequest(XEvent *ev)
465 WWindow *wwin;
466 WScreen *scr = NULL;
467 Window window = ev->xmaprequest.window;
469 #ifdef DEBUG
470 L("got map request for %x\n", (unsigned)window);
471 #endif
472 if ((wwin = wWindowFor(window))) {
473 if (wwin->flags.shaded) {
474 wUnshadeWindow(wwin);
476 /* deiconify window */
477 if (wwin->flags.miniaturized) {
478 wDeiconifyWindow(wwin);
479 } else if (wwin->flags.hidden) {
480 WApplication *wapp = wApplicationOf(wwin->main_window);
481 /* go to the last workspace that the user worked on the app */
482 if (wapp) {
483 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
485 wUnhideApplication(wapp, False, False);
487 return;
490 scr = wScreenForRootWindow(ev->xmaprequest.parent);
492 wwin = wManageWindow(scr, window);
495 * This is to let the Dock know that the application it launched
496 * has already been mapped (eg: it has finished launching).
497 * It is not necessary for normally docked apps, but is needed for
498 * apps that were forcedly docked (like with dockit).
500 if (scr->last_dock) {
501 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
502 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
503 else
504 wDockTrackWindowLaunch(scr->last_dock, window);
507 if (wwin) {
508 wClientSetState(wwin, NormalState, None);
509 if (wwin->flags.maximized) {
510 wMaximizeWindow(wwin, wwin->flags.maximized);
512 if (wwin->flags.shaded) {
513 wwin->flags.shaded = 0;
514 wwin->flags.skip_next_animation = 1;
515 wShadeWindow(wwin);
517 if (wwin->flags.miniaturized) {
518 wwin->flags.miniaturized = 0;
519 wwin->flags.skip_next_animation = 1;
520 wIconifyWindow(wwin);
522 if (wwin->flags.hidden) {
523 WApplication *wapp = wApplicationOf(wwin->main_window);
525 wwin->flags.hidden = 0;
526 wwin->flags.skip_next_animation = 1;
527 if (wapp) {
528 wHideApplication(wapp);
535 static void
536 handleDestroyNotify(XEvent *event)
538 WWindow *wwin;
539 WApplication *app;
540 Window window = event->xdestroywindow.window;
542 #ifdef DEBUG
543 L("got destroy notify");
544 #endif
545 wwin = wWindowFor(window);
546 if (wwin) {
547 wUnmanageWindow(wwin, False, True);
550 app = wApplicationOf(window);
551 if (app) {
552 if (window == app->main_window) {
553 app->refcount = 0;
554 wwin = app->main_window_desc->screen_ptr->focused_window;
555 while (wwin) {
556 if (wwin->main_window == window) {
557 wwin->main_window = None;
559 wwin = wwin->prev;
562 wApplicationDestroy(app);
565 #ifdef KWM_HINTS
566 wKWMCheckDestroy(&event->xdestroywindow);
567 #endif
572 static void
573 handleExpose(XEvent *event)
575 WObjDescriptor *desc;
576 XEvent ev;
578 #ifdef DEBUG
579 L("got expose");
580 #endif
581 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
583 if (XFindContext(dpy, event->xexpose.window, wWinContext,
584 (XPointer *)&desc)==XCNOENT) {
585 return;
588 if (desc->handle_expose) {
589 (*desc->handle_expose)(desc, event);
593 /* bindable */
594 static void
595 handleButtonPress(XEvent *event)
597 WObjDescriptor *desc;
598 WScreen *scr;
600 #ifdef DEBUG
601 L("got button press");
602 #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) {
612 if (event->xbutton.button==wPreferences.menu_button) {
613 OpenRootMenu(scr, event->xbutton.x_root,
614 event->xbutton.y_root, False);
615 /* ugly hack */
616 if (scr->root_menu) {
617 if (scr->root_menu->brother->flags.mapped)
618 event->xbutton.window = scr->root_menu->brother->frame->core->window;
619 else
620 event->xbutton.window = scr->root_menu->frame->core->window;
622 } else if (event->xbutton.button==wPreferences.windowl_button) {
623 OpenSwitchMenu(scr, event->xbutton.x_root,
624 event->xbutton.y_root, False);
625 if (scr->switch_menu) {
626 if (scr->switch_menu->brother->flags.mapped)
627 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
628 else
629 event->xbutton.window = scr->switch_menu->frame->core->window;
631 } else if (event->xbutton.button==wPreferences.select_button) {
632 wUnselectWindows(scr);
633 wSelectWindows(scr, event);
635 else if (event->xbutton.button==Button5) {
636 wWorkspaceRelativeChange(scr, -1);
637 } else if (event->xbutton.button==Button4) {
638 wWorkspaceRelativeChange(scr, 1);
640 #ifdef GNOME_STUFF
641 else if (wGNOMEProxyizeButtonEvent(scr, event))
642 return;
643 #endif
645 #endif /* !LITE */
647 desc = NULL;
648 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
649 (XPointer *)&desc)==XCNOENT) {
650 if (XFindContext(dpy, event->xbutton.window, wWinContext,
651 (XPointer *)&desc)==XCNOENT) {
652 return;
656 if (desc->parent_type == WCLASS_WINDOW) {
657 XSync(dpy, 0);
659 if (event->xbutton.state & MOD_MASK) {
660 XAllowEvents(dpy, AsyncPointer, CurrentTime);
663 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
664 if (wPreferences.ignore_focus_click) {
665 XAllowEvents(dpy, AsyncPointer, CurrentTime);
667 XAllowEvents(dpy, ReplayPointer, CurrentTime);
668 /* }*/
669 XSync(dpy, 0);
670 } else if (desc->parent_type == WCLASS_APPICON
671 || desc->parent_type == WCLASS_MINIWINDOW
672 || desc->parent_type == WCLASS_DOCK_ICON) {
673 if (event->xbutton.state & MOD_MASK) {
674 XSync(dpy, 0);
675 XAllowEvents(dpy, AsyncPointer, CurrentTime);
676 XSync(dpy, 0);
680 if (desc->handle_mousedown!=NULL) {
681 (*desc->handle_mousedown)(desc, event);
684 /* save double-click information */
685 if (scr->flags.next_click_is_not_double) {
686 scr->flags.next_click_is_not_double = 0;
687 } else {
688 scr->last_click_time = event->xbutton.time;
689 scr->last_click_button = event->xbutton.button;
690 scr->last_click_window = event->xbutton.window;
695 static void
696 handleMapNotify(XEvent *event)
698 WWindow *wwin;
699 #ifdef DEBUG
700 L("got map");
701 #endif
702 wwin = wWindowFor(event->xmap.event);
703 if (wwin && wwin->client_win == event->xmap.event) {
704 if (wwin->flags.miniaturized) {
705 wDeiconifyWindow(wwin);
706 } else {
707 XGrabServer(dpy);
708 wWindowMap(wwin);
709 wClientSetState(wwin, NormalState, None);
710 XUngrabServer(dpy);
716 static void
717 handleUnmapNotify(XEvent *event)
719 WWindow *wwin;
720 XEvent ev;
721 Bool withdraw = False;
722 #ifdef DEBUG
723 L("got unmap");
724 #endif
725 /* only process windows with StructureNotify selected
726 * (ignore SubstructureNotify) */
727 wwin = wWindowFor(event->xunmap.window);
728 if (!wwin)
729 return;
731 /* whether the event is a Withdrawal request */
732 if (event->xunmap.event == wwin->screen_ptr->root_win
733 && event->xunmap.send_event)
734 withdraw = True;
736 if (wwin->client_win != event->xunmap.event && !withdraw)
737 return;
739 if (!wwin->flags.mapped && !withdraw
740 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
741 && !wwin->flags.miniaturized && !wwin->flags.hidden)
742 return;
744 XGrabServer(dpy);
745 XUnmapWindow(dpy, wwin->frame->core->window);
746 wwin->flags.mapped = 0;
747 XSync(dpy, 0);
748 /* check if the window was destroyed */
749 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
750 DispatchEvent(&ev);
751 } else {
752 Bool reparented = False;
754 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
755 reparented = True;
757 /* withdraw window */
758 wwin->flags.mapped = 0;
759 if (!reparented)
760 wClientSetState(wwin, WithdrawnState, None);
762 /* if the window was reparented, do not reparent it back to the
763 * root window */
764 wUnmanageWindow(wwin, !reparented, False);
766 XUngrabServer(dpy);
770 static void
771 handleConfigureRequest(XEvent *event)
773 WWindow *wwin;
774 #ifdef DEBUG
775 L("got configure request");
776 #endif
777 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
779 * Configure request for unmapped window
781 wClientConfigure(NULL, &(event->xconfigurerequest));
782 } else {
783 wClientConfigure(wwin, &(event->xconfigurerequest));
788 static void
789 handlePropertyNotify(XEvent *event)
791 WWindow *wwin;
792 WApplication *wapp;
793 Window jr;
794 int ji;
795 unsigned int ju;
796 WScreen *scr;
797 #ifdef DEBUG
798 L("got property notify");
799 #endif
800 if ((wwin=wWindowFor(event->xproperty.window))) {
801 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
802 &ju, &ju, &ju, &ju)) {
803 return;
805 wClientCheckProperty(wwin, &event->xproperty);
807 wapp = wApplicationOf(event->xproperty.window);
808 if (wapp) {
809 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
812 scr = wScreenForWindow(event->xproperty.window);
813 if (scr && scr->root_win == event->xproperty.window) {
814 #ifdef KWM_HINTS
815 wKWMCheckRootHintChange(scr, &event->xproperty);
816 #endif
821 static void
822 handleClientMessage(XEvent *event)
824 WWindow *wwin;
825 WObjDescriptor *desc;
826 #ifdef DEBUG
827 L("got client message");
828 #endif
829 /* handle transition from Normal to Iconic state */
830 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
831 && event->xclient.format == 32
832 && event->xclient.data.l[0] == IconicState) {
834 wwin = wWindowFor(event->xclient.window);
835 if (!wwin) return;
836 if (!wwin->flags.miniaturized)
837 wIconifyWindow(wwin);
838 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
839 && event->xclient.format == 32) {
840 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
842 if (!scr)
843 return;
845 if (event->xclient.data.l[1] == 1) { /* starting */
846 wColormapAllowClientInstallation(scr, True);
847 } else { /* stopping */
848 wColormapAllowClientInstallation(scr, False);
850 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
852 wDefaultsCheckDomains("bla");
854 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
855 WApplication *wapp;
856 int done=0;
857 wapp = wApplicationOf(event->xclient.window);
858 if (wapp) {
859 switch (event->xclient.data.l[0]) {
860 case WMFHideOtherApplications:
861 wHideOtherApplications(wapp->main_window_desc);
862 done = 1;
863 break;
865 case WMFHideApplication:
866 wHideApplication(wapp);
867 done = 1;
868 break;
871 if (!done) {
872 wwin = wWindowFor(event->xclient.window);
873 if (wwin) {
874 switch (event->xclient.data.l[0]) {
875 case WMFHideOtherApplications:
876 wHideOtherApplications(wwin);
877 break;
879 case WMFHideApplication:
880 wHideApplication(wApplicationOf(wwin->main_window));
881 break;
885 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
886 wwin = wWindowFor(event->xclient.window);
887 if (!wwin) return;
888 switch (event->xclient.data.l[0]) {
889 case GSWindowLevelAttr:
891 int level = (int)event->xclient.data.l[1];
893 if (WINDOW_LEVEL(wwin) != level) {
894 ChangeStackingLevel(wwin->frame->core, level);
897 break;
899 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
900 wwin = wWindowFor(event->xclient.window);
901 if (!wwin) return;
902 switch (event->xclient.data.l[0]) {
903 case WMTitleBarNormal:
904 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
905 break;
906 case WMTitleBarMain:
907 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
908 break;
909 case WMTitleBarKey:
910 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
911 break;
913 #ifdef GNOME_STUFF
914 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
915 /* do nothing */
916 #endif /* GNOME_STUFF */
917 #ifdef KWM_HINTS
918 } else if (wKWMProcessClientMessage(&event->xclient)) {
919 /* do nothing */
920 #endif /* KWM_HINTS */
921 #ifdef XDND
922 } else if (wXDNDProcessClientMessage(&event->xclient)) {
923 /* do nothing */
924 #endif /* XDND */
925 #ifdef OFFIX_DND
926 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
927 WScreen *scr = wScreenForWindow(event->xclient.window);
928 if (scr && wDockReceiveDNDDrop(scr,event))
929 goto redirect_message;
930 #endif /* OFFIX_DND */
931 } else {
932 #ifdef OFFIX_DND
933 redirect_message:
934 #endif
936 * Non-standard thing, but needed by OffiX DND.
937 * For when the icon frame gets a ClientMessage
938 * that should have gone to the icon_window.
940 if (XFindContext(dpy, event->xbutton.window, wWinContext,
941 (XPointer *)&desc)!=XCNOENT) {
942 struct WIcon *icon=NULL;
944 if (desc->parent_type == WCLASS_MINIWINDOW) {
945 icon = (WIcon*)desc->parent;
946 } else if (desc->parent_type == WCLASS_DOCK_ICON
947 || desc->parent_type == WCLASS_APPICON) {
948 icon = ((WAppIcon*)desc->parent)->icon;
950 if (icon && (wwin=icon->owner)) {
951 if (wwin->client_win!=event->xclient.window) {
952 event->xclient.window = wwin->client_win;
953 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
954 event);
962 static void
963 raiseWindow(WScreen *scr)
965 WWindow *wwin;
967 scr->autoRaiseTimer = NULL;
969 wwin = wWindowFor(scr->autoRaiseWindow);
970 if (!wwin)
971 return;
973 if (!wwin->flags.destroyed && wwin->flags.focused) {
974 wRaiseFrame(wwin->frame->core);
975 /* this is needed or a race condition will occur */
976 XSync(dpy, False);
981 static void
982 handleEnterNotify(XEvent *event)
984 WWindow *wwin;
985 WObjDescriptor *desc = NULL;
986 XEvent ev;
987 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
988 #ifdef DEBUG
989 L("got enter notify");
990 #endif
992 #ifdef VIRTUAL_DESKTOP
993 /* TODO: acceleration code */
994 if (wPreferences.vedge_thickness) {
995 int x,y;
996 if (event->xcrossing.window == scr->virtual_edge_r) {
997 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
998 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
999 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1000 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1001 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1002 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1003 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1004 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1005 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1006 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1007 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1008 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1009 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1010 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1011 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1014 #endif
1016 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1017 &ev)) {
1018 /* already left the window... */
1019 saveTimestamp(&ev);
1020 if (ev.xcrossing.mode==event->xcrossing.mode
1021 && ev.xcrossing.detail==event->xcrossing.detail) {
1022 return;
1026 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1027 (XPointer *)&desc)!=XCNOENT) {
1028 if(desc->handle_enternotify)
1029 (*desc->handle_enternotify)(desc, event);
1032 /* enter to window */
1033 wwin = wWindowFor(event->xcrossing.window);
1034 if (!wwin) {
1035 if (wPreferences.focus_mode==WKF_POINTER
1036 && event->xcrossing.window==event->xcrossing.root) {
1037 wSetFocusTo(scr, NULL);
1039 if (wPreferences.colormap_mode==WKF_POINTER) {
1040 wColormapInstallForWindow(scr, NULL);
1042 if (scr->autoRaiseTimer
1043 && event->xcrossing.root==event->xcrossing.window) {
1044 WMDeleteTimerHandler(scr->autoRaiseTimer);
1045 scr->autoRaiseTimer = NULL;
1047 } else {
1048 /* set auto raise timer even if in focus-follows-mouse mode
1049 * and the event is for the frame window, even if the window
1050 * has focus already. useful if you move the pointer from a focused
1051 * window to the root window and back pretty fast
1053 * set focus if in focus-follows-mouse mode and the event
1054 * is for the frame window and window doesn't have focus yet */
1055 if ((wPreferences.focus_mode==WKF_POINTER
1056 || wPreferences.focus_mode==WKF_SLOPPY)
1057 && wwin->frame->core->window==event->xcrossing.window
1058 && !scr->flags.doing_alt_tab) {
1060 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1061 wSetFocusTo(scr, wwin);
1063 if (scr->autoRaiseTimer)
1064 WMDeleteTimerHandler(scr->autoRaiseTimer);
1065 scr->autoRaiseTimer = NULL;
1067 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1068 scr->autoRaiseWindow = wwin->frame->core->window;
1069 scr->autoRaiseTimer
1070 = WMAddTimerHandler(wPreferences.raise_delay,
1071 (WMCallback*)raiseWindow, scr);
1074 /* Install colormap for window, if the colormap installation mode
1075 * is colormap_follows_mouse */
1076 if (wPreferences.colormap_mode==WKF_POINTER) {
1077 if (wwin->client_win==event->xcrossing.window)
1078 wColormapInstallForWindow(scr, wwin);
1079 else
1080 wColormapInstallForWindow(scr, NULL);
1084 /* a little kluge to hide the clip balloon */
1085 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1086 if (!desc) {
1087 XUnmapWindow(dpy, scr->clip_balloon);
1088 scr->flags.clip_balloon_mapped = 0;
1089 } else {
1090 if (desc->parent_type!=WCLASS_DOCK_ICON
1091 || scr->clip_icon != desc->parent) {
1092 XUnmapWindow(dpy, scr->clip_balloon);
1093 scr->flags.clip_balloon_mapped = 0;
1098 if (event->xcrossing.window == event->xcrossing.root
1099 && event->xcrossing.detail == NotifyNormal
1100 && event->xcrossing.detail != NotifyInferior
1101 && wPreferences.focus_mode != WKF_CLICK) {
1103 wSetFocusTo(scr, scr->focused_window);
1106 #ifdef BALLOON_TEXT
1107 wBalloonEnteredObject(scr, desc);
1108 #endif
1112 static void
1113 handleLeaveNotify(XEvent *event)
1115 WObjDescriptor *desc = NULL;
1117 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1118 (XPointer *)&desc)!=XCNOENT) {
1119 if(desc->handle_leavenotify)
1120 (*desc->handle_leavenotify)(desc, event);
1122 if (event->xcrossing.window == event->xcrossing.root
1123 && event->xcrossing.mode == NotifyNormal
1124 && event->xcrossing.detail != NotifyInferior
1125 && wPreferences.focus_mode != WKF_CLICK) {
1127 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1129 wSetFocusTo(scr, NULL);
1134 #ifdef SHAPE
1135 static void
1136 handleShapeNotify(XEvent *event)
1138 XShapeEvent *shev = (XShapeEvent*)event;
1139 WWindow *wwin;
1140 XEvent ev;
1141 #ifdef DEBUG
1142 L("got shape notify");
1143 #endif
1144 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1145 XShapeEvent *sev = (XShapeEvent*)&ev;
1147 if (sev->kind == ShapeBounding) {
1148 if (sev->shaped == shev->shaped) {
1149 *shev = *sev;
1150 } else {
1151 XPutBackEvent(dpy, &ev);
1152 break;
1157 wwin = wWindowFor(shev->window);
1158 if (!wwin || shev->kind != ShapeBounding)
1159 return;
1161 if (!shev->shaped && wwin->flags.shaped) {
1163 wwin->flags.shaped = 0;
1164 wWindowClearShape(wwin);
1166 } else if (shev->shaped) {
1168 wwin->flags.shaped = 1;
1169 wWindowSetShape(wwin);
1172 #endif /* SHAPE */
1174 #ifdef KEEP_XKB_LOCK_STATUS
1175 /* please help ]d if you know what to do */
1176 handleXkbIndicatorStateNotify(XEvent *event)
1178 WWindow *wwin;
1179 WScreen *scr;
1180 XkbStateRec staterec;
1181 int i;
1183 for (i=0; i<wScreenCount; i++) {
1184 scr = wScreenWithNumber(i);
1185 wwin = scr->focused_window;
1186 if (wwin && wwin->flags.focused) {
1187 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1188 if (wwin->frame->languagemode != staterec.group) {
1189 wwin->frame->last_languagemode = wwin->frame->languagemode;
1190 wwin->frame->languagemode = staterec.group;
1192 #ifdef XKB_BUTTON_HINT
1193 if (wwin->frame->titlebar) {
1194 wFrameWindowPaint(wwin->frame);
1196 #endif
1200 #endif /*KEEP_XKB_LOCK_STATUS*/
1202 static void
1203 handleColormapNotify(XEvent *event)
1205 WWindow *wwin;
1206 WScreen *scr;
1207 Bool reinstall = False;
1209 wwin = wWindowFor(event->xcolormap.window);
1210 if (!wwin)
1211 return;
1213 scr = wwin->screen_ptr;
1215 do {
1216 if (wwin) {
1217 if (event->xcolormap.new) {
1218 XWindowAttributes attr;
1220 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1222 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1223 scr->current_colormap = attr.colormap;
1225 reinstall = True;
1226 } else if (event->xcolormap.state == ColormapUninstalled &&
1227 scr->current_colormap == event->xcolormap.colormap) {
1229 /* some bastard app (like XV) removed our colormap */
1231 * can't enforce or things like xscreensaver wont work
1232 * reinstall = True;
1234 } else if (event->xcolormap.state == ColormapInstalled &&
1235 scr->current_colormap == event->xcolormap.colormap) {
1237 /* someone has put our colormap back */
1238 reinstall = False;
1241 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1242 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1244 if (reinstall && scr->current_colormap!=None) {
1245 if (!scr->flags.colormap_stuff_blocked)
1246 XInstallColormap(dpy, scr->current_colormap);
1252 static void
1253 handleFocusIn(XEvent *event)
1255 WWindow *wwin;
1258 * For applications that like stealing the focus.
1260 while (XCheckTypedEvent(dpy, FocusIn, event));
1261 saveTimestamp(event);
1262 if (event->xfocus.mode == NotifyUngrab
1263 || event->xfocus.mode == NotifyGrab
1264 || event->xfocus.detail > NotifyNonlinearVirtual) {
1265 return;
1268 wwin = wWindowFor(event->xfocus.window);
1269 if (wwin && !wwin->flags.focused) {
1270 if (wwin->flags.mapped)
1271 wSetFocusTo(wwin->screen_ptr, wwin);
1272 else
1273 wSetFocusTo(wwin->screen_ptr, NULL);
1274 } else if (!wwin) {
1275 WScreen *scr = wScreenForWindow(event->xfocus.window);
1276 if (scr)
1277 wSetFocusTo(scr, NULL);
1282 static WWindow*
1283 windowUnderPointer(WScreen *scr)
1285 unsigned int mask;
1286 int foo;
1287 Window bar, win;
1289 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1290 &mask))
1291 return wWindowFor(win);
1292 return NULL;
1298 static void
1299 handleKeyPress(XEvent *event)
1301 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1302 WWindow *wwin = scr->focused_window;
1303 int i;
1304 int modifiers;
1305 int command=-1, index;
1306 #ifdef KEEP_XKB_LOCK_STATUS
1307 XkbStateRec staterec;
1308 #endif /*KEEP_XKB_LOCK_STATUS*/
1310 /* ignore CapsLock */
1311 modifiers = event->xkey.state & ValidModMask;
1313 for (i=0; i<WKBD_LAST; i++) {
1314 if (wKeyBindings[i].keycode==0)
1315 continue;
1317 if (wKeyBindings[i].keycode==event->xkey.keycode
1318 && (/*wKeyBindings[i].modifier==0
1319 ||*/ wKeyBindings[i].modifier==modifiers)) {
1320 command = i;
1321 break;
1326 if (command < 0) {
1327 #ifdef LITE
1329 #if 0
1331 #endif
1332 #else
1333 if (!wRootMenuPerformShortcut(event)) {
1334 #endif
1335 static int dontLoop = 0;
1337 if (dontLoop > 10) {
1338 wwarning("problem with key event processing code");
1339 return;
1341 dontLoop++;
1342 /* if the focused window is an internal window, try redispatching
1343 * the event to the managed window, as it can be a WINGs window */
1344 if (wwin && wwin->flags.internal_window
1345 && wwin->client_leader!=None) {
1346 /* client_leader contains the WINGs toplevel */
1347 event->xany.window = wwin->client_leader;
1348 WMHandleEvent(event);
1350 dontLoop--;
1352 return;
1355 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1356 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1358 switch (command) {
1359 #ifndef LITE
1360 case WKBD_ROOTMENU:
1361 OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1362 break;
1363 case WKBD_WINDOWLIST:
1364 OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);
1365 break;
1366 #endif /* !LITE */
1367 case WKBD_WINDOWMENU:
1368 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1369 OpenWindowMenu(wwin, wwin->frame_x,
1370 wwin->frame_y+wwin->frame->top_width, True);
1371 break;
1372 case WKBD_MINIATURIZE:
1373 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1374 && !WFLAGP(wwin, no_miniaturizable)) {
1375 CloseWindowMenu(scr);
1377 if (wwin->protocols.MINIATURIZE_WINDOW)
1378 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1379 event->xbutton.time);
1380 else {
1381 wIconifyWindow(wwin);
1384 break;
1385 case WKBD_HIDE:
1386 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1387 WApplication *wapp = wApplicationOf(wwin->main_window);
1388 CloseWindowMenu(scr);
1390 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1391 wHideApplication(wapp);
1394 break;
1395 case WKBD_MAXIMIZE:
1396 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1397 CloseWindowMenu(scr);
1399 if (wwin->flags.maximized) {
1400 wUnmaximizeWindow(wwin);
1401 } else {
1402 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1405 break;
1406 case WKBD_VMAXIMIZE:
1407 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1408 CloseWindowMenu(scr);
1410 if (wwin->flags.maximized) {
1411 wUnmaximizeWindow(wwin);
1412 } else {
1413 wMaximizeWindow(wwin, MAX_VERTICAL);
1416 break;
1417 case WKBD_RAISE:
1418 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1419 CloseWindowMenu(scr);
1421 wRaiseFrame(wwin->frame->core);
1423 break;
1424 case WKBD_LOWER:
1425 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1426 CloseWindowMenu(scr);
1428 wLowerFrame(wwin->frame->core);
1430 break;
1431 case WKBD_RAISELOWER:
1432 /* raise or lower the window under the pointer, not the
1433 * focused one
1435 wwin = windowUnderPointer(scr);
1436 if (wwin)
1437 wRaiseLowerFrame(wwin->frame->core);
1438 break;
1439 case WKBD_SHADE:
1440 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1441 if (wwin->flags.shaded)
1442 wUnshadeWindow(wwin);
1443 else
1444 wShadeWindow(wwin);
1446 break;
1447 case WKBD_MOVERESIZE:
1448 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1449 CloseWindowMenu(scr);
1451 wKeyboardMoveResizeWindow(wwin);
1453 break;
1454 case WKBD_CLOSE:
1455 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1456 CloseWindowMenu(scr);
1457 if (wwin->protocols.DELETE_WINDOW)
1458 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1459 event->xkey.time);
1461 break;
1462 case WKBD_SELECT:
1463 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1464 wSelectWindow(wwin, !wwin->flags.selected);
1466 break;
1467 case WKBD_FOCUSNEXT:
1468 StartWindozeCycle(wwin, event, True);
1469 break;
1471 case WKBD_FOCUSPREV:
1472 StartWindozeCycle(wwin, event, False);
1473 break;
1475 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1476 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1477 i = (scr->current_workspace/10)*10 + wk - 1;\
1478 if (wPreferences.ws_advance || i<scr->workspace_count)\
1479 wWorkspaceChange(scr, i);\
1480 break
1481 #else
1482 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1483 i = (scr->current_workspace/10)*10 + wk - 1;\
1484 if (wPreferences.ws_advance || i<scr->workspace_count)\
1485 wWorkspaceChange(scr, i);\
1486 break
1487 #endif
1488 GOTOWORKS(1);
1489 GOTOWORKS(2);
1490 GOTOWORKS(3);
1491 GOTOWORKS(4);
1492 GOTOWORKS(5);
1493 GOTOWORKS(6);
1494 GOTOWORKS(7);
1495 GOTOWORKS(8);
1496 GOTOWORKS(9);
1497 GOTOWORKS(10);
1498 #undef GOTOWORKS
1499 case WKBD_NEXTWORKSPACE:
1500 wWorkspaceRelativeChange(scr, 1);
1501 break;
1502 case WKBD_PREVWORKSPACE:
1503 wWorkspaceRelativeChange(scr, -1);
1504 break;
1505 case WKBD_WINDOW1:
1506 case WKBD_WINDOW2:
1507 case WKBD_WINDOW3:
1508 case WKBD_WINDOW4:
1509 case WKBD_WINDOW5:
1510 case WKBD_WINDOW6:
1511 case WKBD_WINDOW7:
1512 case WKBD_WINDOW8:
1513 case WKBD_WINDOW9:
1514 case WKBD_WINDOW10:
1516 index = command-WKBD_WINDOW1;
1518 if (scr->shortcutWindows[index]) {
1519 WMArray *list = scr->shortcutWindows[index];
1520 int cw;
1521 int count = WMGetArrayItemCount(list);
1522 WWindow *twin;
1523 WMArrayIterator iter;
1524 WWindow *wwin;
1526 wUnselectWindows(scr);
1527 cw = scr->current_workspace;
1529 WM_ETARETI_ARRAY(list, wwin, iter) {
1530 if (count > 1)
1531 wWindowChangeWorkspace(wwin, cw);
1533 wMakeWindowVisible(wwin);
1535 if (count > 1)
1536 wSelectWindow(wwin, True);
1539 /* rotate the order of windows, to create a cycling effect */
1540 twin = WMGetFromArray(list, 0);
1541 WMDeleteFromArray(list, 0);
1542 WMAddToArray(list, twin);
1544 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1545 if (scr->shortcutWindows[index]) {
1546 WMFreeArray(scr->shortcutWindows[index]);
1547 scr->shortcutWindows[index] = NULL;
1550 if (wwin->flags.selected && scr->selected_windows) {
1551 scr->shortcutWindows[index] =
1552 WMDuplicateArray(scr->selected_windows);
1553 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1554 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1555 } else {
1556 scr->shortcutWindows[index] = WMCreateArray(4);
1557 WMAddToArray(scr->shortcutWindows[index], wwin);
1560 wSelectWindow(wwin, !wwin->flags.selected);
1561 XFlush(dpy);
1562 wusleep(3000);
1563 wSelectWindow(wwin, !wwin->flags.selected);
1564 XFlush(dpy);
1566 } else if (scr->selected_windows
1567 && WMGetArrayItemCount(scr->selected_windows)) {
1569 if (wwin->flags.selected && scr->selected_windows) {
1570 if (scr->shortcutWindows[index]) {
1571 WMFreeArray(scr->shortcutWindows[index]);
1573 scr->shortcutWindows[index] =
1574 WMDuplicateArray(scr->selected_windows);
1578 break;
1580 case WKBD_SWITCH_SCREEN:
1581 if (wScreenCount > 1) {
1582 WScreen *scr2;
1583 int i;
1585 /* find index of this screen */
1586 for (i = 0; i < wScreenCount; i++) {
1587 if (wScreenWithNumber(i) == scr)
1588 break;
1590 i++;
1591 if (i >= wScreenCount) {
1592 i = 0;
1594 scr2 = wScreenWithNumber(i);
1596 if (scr2) {
1597 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1598 scr2->scr_width/2, scr2->scr_height/2);
1601 break;
1603 case WKBD_NEXTWSLAYER:
1604 case WKBD_PREVWSLAYER:
1606 int row, column;
1608 row = scr->current_workspace/10;
1609 column = scr->current_workspace%10;
1611 if (command==WKBD_NEXTWSLAYER) {
1612 if ((row+1)*10 < scr->workspace_count)
1613 wWorkspaceChange(scr, column+(row+1)*10);
1614 } else {
1615 if (row > 0)
1616 wWorkspaceChange(scr, column+(row-1)*10);
1619 break;
1620 case WKBD_CLIPLOWER:
1621 if (!wPreferences.flags.noclip)
1622 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1623 break;
1624 case WKBD_CLIPRAISE:
1625 if (!wPreferences.flags.noclip)
1626 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1627 break;
1628 case WKBD_CLIPRAISELOWER:
1629 if (!wPreferences.flags.noclip)
1630 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1631 break;
1632 #ifdef KEEP_XKB_LOCK_STATUS
1633 case WKBD_TOGGLE:
1634 if(wPreferences.modelock) {
1635 /*toggle*/
1636 wwin = scr->focused_window;
1638 if (wwin && wwin->flags.mapped
1639 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1640 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1641 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1643 wwin->frame->languagemode = wwin->frame->last_languagemode;
1644 wwin->frame->last_languagemode = staterec.group;
1645 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1649 break;
1650 #endif /* KEEP_XKB_LOCK_STATUS */
1656 static void
1657 handleMotionNotify(XEvent *event)
1659 WMenu *menu;
1660 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1662 if (wPreferences.scrollable_menus) {
1663 if (scr->flags.jump_back_pending ||
1664 event->xmotion.x_root <= 1 ||
1665 event->xmotion.x_root >= (scr->scr_width - 2) ||
1666 event->xmotion.y_root <= 1 ||
1667 event->xmotion.y_root >= (scr->scr_height - 2)) {
1668 #ifdef DEBUG
1669 L("pointer at screen edge");
1670 #endif
1671 menu = wMenuUnderPointer(scr);
1672 if (menu!=NULL)
1673 wMenuScroll(menu, event);
1676 #if 0
1677 if (event->xmotion.subwindow == None)
1678 return;
1680 if (scr->scrolledFMaximize != None) {
1681 WWindow *twin;
1683 twin = wWindowFor(scr->scrolledFMaximize);
1684 if (twin && twin->frame_y ==) {
1688 scr->scrolledFMaximize = NULL;
1690 } else {
1692 /* scroll full maximized window */
1693 if (event->xmotion.y_root < 1
1694 || event->xmotion.y_root > scr->scr_height - 1) {
1696 wwin = wWindowFor(event->xmotion.subwindow);
1698 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1699 && WFLAGP(wwin, full_maximize)
1700 && event->xmotion.x_root >= wwin->frame_x
1701 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1703 if (!WFLAGP(wwin, no_titlebar)
1704 && wwin->frame_y <= - wwin->frame->top_width) {
1706 wWindowMove(wwin, wwin->frame_x, 0);
1707 wwin->flags.dragged_while_fmaximized = 0;
1709 } else if (!WFLAGP(wwin, no_resizebar)
1710 && wwin->frame_y + wwin->frame->core->height >=
1711 scr->scr_height + wwin->frame->bottom_width) {
1713 int y = scr->scr_height + wwin->frame->bottom_width;
1715 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1717 wWindowMove(wwin, wwin->frame_x, y);
1718 wwin->flags.dragged_while_fmaximized = 0;
1722 #endif
1726 static void
1727 handleVisibilityNotify(XEvent *event)
1729 WWindow *wwin;
1731 wwin = wWindowFor(event->xvisibility.window);
1732 if (!wwin)
1733 return;
1734 wwin->flags.obscured =
1735 (event->xvisibility.state == VisibilityFullyObscured);