changed indentation to use spaces only
[wmaker-crm.git] / src / event.c
blobb3a16b66b3e62a6fa880ad338c846edf95a7b590
1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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"
61 #include "xinerama.h"
63 #ifdef GNOME_STUFF
64 # include "gnome.h"
65 #endif
66 #ifdef KWM_HINTS
67 # include "kwm.h"
68 #endif
69 #ifdef NETWM_HINTS
70 # include "wmspec.h"
71 #endif
73 /******** Global Variables **********/
74 extern XContext wWinContext;
75 extern XContext wVEdgeContext;
77 extern Cursor wCursor[WCUR_LAST];
79 extern WShortKey wKeyBindings[WKBD_LAST];
80 extern int wScreenCount;
81 extern Time LastTimestamp;
82 extern Time LastFocusChange;
84 extern WPreferences wPreferences;
86 #define MOD_MASK wPreferences.modifier_mask
88 extern Atom _XA_WM_COLORMAP_NOTIFY;
90 extern Atom _XA_WM_CHANGE_STATE;
91 extern Atom _XA_WM_DELETE_WINDOW;
92 extern Atom _XA_GNUSTEP_WM_ATTR;
93 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
94 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
95 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
96 extern Atom _XA_WINDOWMAKER_COMMAND;
98 #ifdef OFFIX_DND
99 extern Atom _XA_DND_PROTOCOL;
100 #endif
103 #ifdef SHAPE
104 extern Bool wShapeSupported;
105 extern int wShapeEventBase;
106 #endif
108 #ifdef KEEP_XKB_LOCK_STATUS
109 extern int wXkbEventBase;
110 #endif
112 /* special flags */
113 extern char WDelayedActionSet;
116 /************ Local stuff ***********/
119 static void saveTimestamp(XEvent *event);
120 static void handleColormapNotify();
121 static void handleMapNotify();
122 static void handleUnmapNotify();
123 static void handleButtonPress();
124 static void handleExpose();
125 static void handleDestroyNotify();
126 static void handleConfigureRequest();
127 static void handleMapRequest();
128 static void handlePropertyNotify();
129 static void handleEnterNotify();
130 static void handleLeaveNotify();
131 static void handleExtensions();
132 static void handleClientMessage();
133 static void handleKeyPress();
134 static void handleFocusIn();
135 static void handleMotionNotify();
136 static void handleVisibilityNotify();
139 #ifdef SHAPE
140 static void handleShapeNotify();
141 #endif
143 /* called from the signal handler */
144 void NotifyDeadProcess(pid_t pid, unsigned char status);
146 /* real dead process handler */
147 static void handleDeadProcess(void *foo);
150 typedef struct DeadProcesses {
151 pid_t pid;
152 unsigned char exit_status;
153 } DeadProcesses;
155 /* stack of dead processes */
156 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
157 static int deadProcessPtr=0;
160 typedef struct DeathHandler {
161 WDeathHandler *callback;
162 pid_t pid;
163 void *client_data;
164 } DeathHandler;
166 static WMArray *deathHandlers=NULL;
170 WMagicNumber
171 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
173 DeathHandler *handler;
175 handler = malloc(sizeof(DeathHandler));
176 if (!handler)
177 return 0;
179 handler->pid = pid;
180 handler->callback = callback;
181 handler->client_data = cdata;
183 if (!deathHandlers)
184 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
186 WMAddToArray(deathHandlers, handler);
188 return handler;
193 void
194 wDeleteDeathHandler(WMagicNumber id)
196 DeathHandler *handler=(DeathHandler*)id;
198 if (!handler || !deathHandlers)
199 return;
201 /* array destructor will call wfree(handler) */
202 WMRemoveFromArray(deathHandlers, handler);
206 void
207 DispatchEvent(XEvent *event)
209 if (deathHandlers)
210 handleDeadProcess(NULL);
212 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
213 WCHANGE_STATE(WSTATE_EXITING);
214 /* received SIGTERM */
216 * WMHandleEvent() can't be called from anything
217 * executed inside here, or we can get in a infinite
218 * recursive loop.
220 Shutdown(WSExitMode);
222 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
223 WCHANGE_STATE(WSTATE_RESTARTING);
225 Shutdown(WSRestartPreparationMode);
226 /* received SIGHUP */
227 Restart(NULL, True);
228 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
229 WCHANGE_STATE(WSTATE_NORMAL);
230 wDefaultsCheckDomains("bla");
233 /* for the case that all that is wanted to be dispatched is
234 * the stuff above */
235 if (!event)
236 return;
238 saveTimestamp(event);
239 switch (event->type) {
240 case MapRequest:
241 handleMapRequest(event);
242 break;
244 case KeyPress:
245 handleKeyPress(event);
246 break;
248 case MotionNotify:
249 handleMotionNotify(event);
250 break;
252 case ConfigureRequest:
253 handleConfigureRequest(event);
254 break;
256 case DestroyNotify:
257 handleDestroyNotify(event);
258 break;
260 case MapNotify:
261 handleMapNotify(event);
262 break;
264 case UnmapNotify:
265 handleUnmapNotify(event);
266 break;
268 case ButtonPress:
269 handleButtonPress(event);
270 break;
272 case Expose:
273 handleExpose(event);
274 break;
276 case PropertyNotify:
277 handlePropertyNotify(event);
278 break;
280 case EnterNotify:
281 handleEnterNotify(event);
282 break;
284 case LeaveNotify:
285 handleLeaveNotify(event);
286 break;
288 case ClientMessage:
289 handleClientMessage(event);
290 break;
292 case ColormapNotify:
293 handleColormapNotify(event);
294 break;
296 case MappingNotify:
297 if (event->xmapping.request == MappingKeyboard
298 || event->xmapping.request == MappingModifier)
299 XRefreshKeyboardMapping(&event->xmapping);
300 break;
302 case FocusIn:
303 handleFocusIn(event);
304 break;
306 case VisibilityNotify:
307 handleVisibilityNotify(event);
308 break;
309 default:
310 handleExtensions(event);
311 break;
317 *----------------------------------------------------------------------
318 * EventLoop-
319 * Processes X and internal events indefinitely.
321 * Returns:
322 * Never returns
324 * Side effects:
325 * The LastTimestamp global variable is updated.
326 *----------------------------------------------------------------------
328 void
329 EventLoop()
331 XEvent event;
333 for(;;) {
334 WMNextEvent(dpy, &event);
335 WMHandleEvent(&event);
341 *----------------------------------------------------------------------
342 * ProcessPendingEvents --
343 * Processes the events that are currently pending (at the time
344 * this function is called) in the display's queue.
346 * Returns:
347 * After the pending events that were present at the function call
348 * are processed.
350 * Side effects:
351 * Many -- whatever handling events may involve.
353 *----------------------------------------------------------------------
355 void
356 ProcessPendingEvents()
358 XEvent event;
359 int count;
361 XSync(dpy, False);
363 /* Take a snapshot of the event count in the queue */
364 count = XPending(dpy);
366 while (count>0 && XPending(dpy)) {
367 WMNextEvent(dpy, &event);
368 WMHandleEvent(&event);
369 count--;
374 Bool
375 IsDoubleClick(WScreen *scr, XEvent *event)
377 if ((scr->last_click_time>0) &&
378 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
379 && (event->xbutton.button == scr->last_click_button)
380 && (event->xbutton.window == scr->last_click_window)) {
382 scr->flags.next_click_is_not_double = 1;
383 scr->last_click_time = 0;
384 scr->last_click_window = event->xbutton.window;
386 return True;
388 return False;
392 void
393 NotifyDeadProcess(pid_t pid, unsigned char status)
395 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
396 wwarning("stack overflow: too many dead processes");
397 return;
399 /* stack the process to be handled later,
400 * as this is called from the signal handler */
401 deadProcesses[deadProcessPtr].pid = pid;
402 deadProcesses[deadProcessPtr].exit_status = status;
403 deadProcessPtr++;
407 static void
408 handleDeadProcess(void *foo)
410 DeathHandler *tmp;
411 int i;
413 for (i=0; i<deadProcessPtr; i++) {
414 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
417 if (!deathHandlers) {
418 deadProcessPtr=0;
419 return;
422 /* get the pids on the queue and call handlers */
423 while (deadProcessPtr>0) {
424 deadProcessPtr--;
426 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
427 tmp = WMGetFromArray(deathHandlers, i);
428 if (!tmp)
429 continue;
431 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
432 (*tmp->callback)(tmp->pid,
433 deadProcesses[deadProcessPtr].exit_status,
434 tmp->client_data);
435 wDeleteDeathHandler(tmp);
442 static void
443 saveTimestamp(XEvent *event)
446 * Never save CurrentTime as LastTimestamp because CurrentTime
447 * it's not a real timestamp (it's the 0L constant)
450 switch (event->type) {
451 case ButtonRelease:
452 case ButtonPress:
453 LastTimestamp = event->xbutton.time;
454 break;
455 case KeyPress:
456 case KeyRelease:
457 LastTimestamp = event->xkey.time;
458 break;
459 case MotionNotify:
460 LastTimestamp = event->xmotion.time;
461 break;
462 case PropertyNotify:
463 LastTimestamp = event->xproperty.time;
464 break;
465 case EnterNotify:
466 case LeaveNotify:
467 LastTimestamp = event->xcrossing.time;
468 break;
469 case SelectionClear:
470 LastTimestamp = event->xselectionclear.time;
471 break;
472 case SelectionRequest:
473 LastTimestamp = event->xselectionrequest.time;
474 break;
475 case SelectionNotify:
476 LastTimestamp = event->xselection.time;
477 #ifdef XDND
478 wXDNDProcessSelection(event);
479 #endif
480 break;
485 static int
486 matchWindow(void *item, void *cdata)
488 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
492 static void
493 handleExtensions(XEvent *event)
495 #ifdef KEEP_XKB_LOCK_STATUS
496 XkbEvent *xkbevent;
497 xkbevent = (XkbEvent *)event;
498 #endif /*KEEP_XKB_LOCK_STATUS*/
499 #ifdef SHAPE
500 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
501 handleShapeNotify(event);
503 #endif
504 #ifdef KEEP_XKB_LOCK_STATUS
505 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
506 handleXkbIndicatorStateNotify(event);
508 #endif /*KEEP_XKB_LOCK_STATUS*/
512 static void
513 handleMapRequest(XEvent *ev)
515 WWindow *wwin;
516 WScreen *scr = NULL;
517 Window window = ev->xmaprequest.window;
519 #ifdef DEBUG
520 printf("got map request for %x\n", (unsigned)window);
521 #endif
522 if ((wwin = wWindowFor(window))) {
523 if (wwin->flags.shaded) {
524 wUnshadeWindow(wwin);
526 /* deiconify window */
527 if (wwin->flags.miniaturized) {
528 wDeiconifyWindow(wwin);
529 } else if (wwin->flags.hidden) {
530 WApplication *wapp = wApplicationOf(wwin->main_window);
531 /* go to the last workspace that the user worked on the app */
532 if (wapp) {
533 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
535 wUnhideApplication(wapp, False, False);
537 return;
540 scr = wScreenForRootWindow(ev->xmaprequest.parent);
542 wwin = wManageWindow(scr, window);
545 * This is to let the Dock know that the application it launched
546 * has already been mapped (eg: it has finished launching).
547 * It is not necessary for normally docked apps, but is needed for
548 * apps that were forcedly docked (like with dockit).
550 if (scr->last_dock) {
551 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
552 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
553 else
554 wDockTrackWindowLaunch(scr->last_dock, window);
557 if (wwin) {
558 wClientSetState(wwin, NormalState, None);
559 if (wwin->flags.maximized) {
560 wMaximizeWindow(wwin, wwin->flags.maximized);
562 if (wwin->flags.shaded) {
563 wwin->flags.shaded = 0;
564 wwin->flags.skip_next_animation = 1;
565 wShadeWindow(wwin);
567 if (wwin->flags.miniaturized) {
568 wwin->flags.miniaturized = 0;
569 wwin->flags.skip_next_animation = 1;
570 wIconifyWindow(wwin);
572 if (wwin->flags.hidden) {
573 WApplication *wapp = wApplicationOf(wwin->main_window);
575 wwin->flags.hidden = 0;
576 wwin->flags.skip_next_animation = 1;
577 if (wapp) {
578 wHideApplication(wapp);
585 static void
586 handleDestroyNotify(XEvent *event)
588 WWindow *wwin;
589 WApplication *app;
590 Window window = event->xdestroywindow.window;
591 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
592 int index;
594 #ifdef DEBUG
595 printf("got destroy notify\n");
596 #endif
597 wwin = wWindowFor(window);
598 if (wwin) {
599 wUnmanageWindow(wwin, False, True);
602 if (scr != NULL) {
603 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
604 (void*)window)) != WANotFound) {
605 WFakeGroupLeader *fPtr;
607 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
608 if (fPtr->retainCount > 0) {
609 fPtr->retainCount--;
610 if (fPtr->retainCount==0 && fPtr->leader!=None) {
611 XDestroyWindow(dpy, fPtr->leader);
612 fPtr->leader = None;
613 XFlush(dpy);
616 fPtr->origLeader = None;
620 app = wApplicationOf(window);
621 if (app) {
622 if (window == app->main_window) {
623 app->refcount = 0;
624 wwin = app->main_window_desc->screen_ptr->focused_window;
625 while (wwin) {
626 if (wwin->main_window == window) {
627 wwin->main_window = None;
629 wwin = wwin->prev;
632 wApplicationDestroy(app);
635 #ifdef KWM_HINTS
636 wKWMCheckDestroy(&event->xdestroywindow);
637 #endif
642 static void
643 handleExpose(XEvent *event)
645 WObjDescriptor *desc;
646 XEvent ev;
648 #ifdef DEBUG
649 printf("got expose\n");
650 #endif
651 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
653 if (XFindContext(dpy, event->xexpose.window, wWinContext,
654 (XPointer *)&desc)==XCNOENT) {
655 return;
658 if (desc->handle_expose) {
659 (*desc->handle_expose)(desc, event);
663 static void
664 executeButtonAction(WScreen *scr, XEvent *event, int action)
666 switch(action) {
667 case WA_SELECT_WINDOWS:
668 wUnselectWindows(scr);
669 wSelectWindows(scr, event);
670 break;
671 case WA_OPEN_APPMENU:
672 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
673 /* ugly hack */
674 if (scr->root_menu) {
675 if (scr->root_menu->brother->flags.mapped)
676 event->xbutton.window = scr->root_menu->brother->frame->core->window;
677 else
678 event->xbutton.window = scr->root_menu->frame->core->window;
680 break;
681 case WA_OPEN_WINLISTMENU:
682 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
683 if (scr->switch_menu) {
684 if (scr->switch_menu->brother->flags.mapped)
685 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
686 else
687 event->xbutton.window = scr->switch_menu->frame->core->window;
689 break;
690 default:
691 break;
696 /* bindable */
697 static void
698 handleButtonPress(XEvent *event)
700 WObjDescriptor *desc;
701 WScreen *scr;
703 #ifdef DEBUG
704 printf("got button press\n");
705 #endif
706 scr = wScreenForRootWindow(event->xbutton.root);
708 #ifdef BALLOON_TEXT
709 wBalloonHide(scr);
710 #endif
713 #ifndef LITE
714 if (event->xbutton.window==scr->root_win) {
715 if (event->xbutton.button==Button1 &&
716 wPreferences.mouse_button1!=WA_NONE) {
717 executeButtonAction(scr, event, wPreferences.mouse_button1);
718 } else if (event->xbutton.button==Button2 &&
719 wPreferences.mouse_button2!=WA_NONE) {
720 executeButtonAction(scr, event, wPreferences.mouse_button2);
721 } else if (event->xbutton.button==Button3 &&
722 wPreferences.mouse_button3!=WA_NONE) {
723 executeButtonAction(scr, event, wPreferences.mouse_button3);
724 } else if (event->xbutton.button==Button4 &&
725 wPreferences.mouse_wheel!=WA_NONE) {
726 wWorkspaceRelativeChange(scr, 1);
727 } else if (event->xbutton.button==Button5 &&
728 wPreferences.mouse_wheel!=WA_NONE) {
729 wWorkspaceRelativeChange(scr, -1);
731 #ifdef GNOME_STUFF
732 else if (wGNOMEProxyizeButtonEvent(scr, event))
733 return;
734 #endif
736 #endif /* !LITE */
738 desc = NULL;
739 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
740 (XPointer *)&desc)==XCNOENT) {
741 if (XFindContext(dpy, event->xbutton.window, wWinContext,
742 (XPointer *)&desc)==XCNOENT) {
743 return;
747 if (desc->parent_type == WCLASS_WINDOW) {
748 XSync(dpy, 0);
750 if (event->xbutton.state & MOD_MASK) {
751 XAllowEvents(dpy, AsyncPointer, CurrentTime);
754 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
755 if (wPreferences.ignore_focus_click) {
756 XAllowEvents(dpy, AsyncPointer, CurrentTime);
758 XAllowEvents(dpy, ReplayPointer, CurrentTime);
759 /* }*/
760 XSync(dpy, 0);
761 } else if (desc->parent_type == WCLASS_APPICON
762 || desc->parent_type == WCLASS_MINIWINDOW
763 || desc->parent_type == WCLASS_DOCK_ICON) {
764 if (event->xbutton.state & MOD_MASK) {
765 XSync(dpy, 0);
766 XAllowEvents(dpy, AsyncPointer, CurrentTime);
767 XSync(dpy, 0);
771 if (desc->handle_mousedown!=NULL) {
772 (*desc->handle_mousedown)(desc, event);
775 /* save double-click information */
776 if (scr->flags.next_click_is_not_double) {
777 scr->flags.next_click_is_not_double = 0;
778 } else {
779 scr->last_click_time = event->xbutton.time;
780 scr->last_click_button = event->xbutton.button;
781 scr->last_click_window = event->xbutton.window;
786 static void
787 handleMapNotify(XEvent *event)
789 WWindow *wwin;
790 #ifdef DEBUG
791 printf("got map\n");
792 #endif
793 wwin = wWindowFor(event->xmap.event);
794 if (wwin && wwin->client_win == event->xmap.event) {
795 if (wwin->flags.miniaturized) {
796 wDeiconifyWindow(wwin);
797 } else {
798 XGrabServer(dpy);
799 wWindowMap(wwin);
800 wClientSetState(wwin, NormalState, None);
801 XUngrabServer(dpy);
807 static void
808 handleUnmapNotify(XEvent *event)
810 WWindow *wwin;
811 XEvent ev;
812 Bool withdraw = False;
813 #ifdef DEBUG
814 printf("got unmap\n");
815 #endif
816 /* only process windows with StructureNotify selected
817 * (ignore SubstructureNotify) */
818 wwin = wWindowFor(event->xunmap.window);
819 if (!wwin)
820 return;
822 /* whether the event is a Withdrawal request */
823 if (event->xunmap.event == wwin->screen_ptr->root_win
824 && event->xunmap.send_event)
825 withdraw = True;
827 if (wwin->client_win != event->xunmap.event && !withdraw)
828 return;
830 if (!wwin->flags.mapped && !withdraw
831 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
832 && !wwin->flags.miniaturized && !wwin->flags.hidden)
833 return;
835 XGrabServer(dpy);
836 XUnmapWindow(dpy, wwin->frame->core->window);
837 wwin->flags.mapped = 0;
838 XSync(dpy, 0);
839 /* check if the window was destroyed */
840 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
841 DispatchEvent(&ev);
842 } else {
843 Bool reparented = False;
845 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
846 reparented = True;
848 /* withdraw window */
849 wwin->flags.mapped = 0;
850 if (!reparented)
851 wClientSetState(wwin, WithdrawnState, None);
853 /* if the window was reparented, do not reparent it back to the
854 * root window */
855 wUnmanageWindow(wwin, !reparented, False);
857 XUngrabServer(dpy);
861 static void
862 handleConfigureRequest(XEvent *event)
864 WWindow *wwin;
865 #ifdef DEBUG
866 printf("got configure request\n");
867 #endif
868 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
870 * Configure request for unmapped window
872 wClientConfigure(NULL, &(event->xconfigurerequest));
873 } else {
874 wClientConfigure(wwin, &(event->xconfigurerequest));
879 static void
880 handlePropertyNotify(XEvent *event)
882 WWindow *wwin;
883 WApplication *wapp;
884 Window jr;
885 int ji;
886 unsigned int ju;
887 WScreen *scr;
888 #ifdef DEBUG
889 printf("got property notify\n");
890 #endif
891 if ((wwin=wWindowFor(event->xproperty.window))) {
892 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
893 &ju, &ju, &ju, &ju)) {
894 return;
896 wClientCheckProperty(wwin, &event->xproperty);
898 wapp = wApplicationOf(event->xproperty.window);
899 if (wapp) {
900 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
903 scr = wScreenForWindow(event->xproperty.window);
904 if (scr && scr->root_win == event->xproperty.window) {
905 #ifdef KWM_HINTS
906 wKWMCheckRootHintChange(scr, &event->xproperty);
907 #endif
912 static void
913 handleClientMessage(XEvent *event)
915 WWindow *wwin;
916 WObjDescriptor *desc;
917 #ifdef DEBUG
918 printf("got client message\n");
919 #endif
920 /* handle transition from Normal to Iconic state */
921 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
922 && event->xclient.format == 32
923 && event->xclient.data.l[0] == IconicState) {
925 wwin = wWindowFor(event->xclient.window);
926 if (!wwin) return;
927 if (!wwin->flags.miniaturized)
928 wIconifyWindow(wwin);
929 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
930 && event->xclient.format == 32) {
931 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
933 if (!scr)
934 return;
936 if (event->xclient.data.l[1] == 1) { /* starting */
937 wColormapAllowClientInstallation(scr, True);
938 } else { /* stopping */
939 wColormapAllowClientInstallation(scr, False);
941 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
943 wDefaultsCheckDomains("bla");
945 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
946 WApplication *wapp;
947 int done=0;
948 wapp = wApplicationOf(event->xclient.window);
949 if (wapp) {
950 switch (event->xclient.data.l[0]) {
951 case WMFHideOtherApplications:
952 wHideOtherApplications(wapp->main_window_desc);
953 done = 1;
954 break;
956 case WMFHideApplication:
957 wHideApplication(wapp);
958 done = 1;
959 break;
962 if (!done) {
963 wwin = wWindowFor(event->xclient.window);
964 if (wwin) {
965 switch (event->xclient.data.l[0]) {
966 case WMFHideOtherApplications:
967 wHideOtherApplications(wwin);
968 break;
970 case WMFHideApplication:
971 wHideApplication(wApplicationOf(wwin->main_window));
972 break;
976 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
977 wwin = wWindowFor(event->xclient.window);
978 if (!wwin) return;
979 switch (event->xclient.data.l[0]) {
980 case GSWindowLevelAttr:
982 int level = (int)event->xclient.data.l[1];
984 if (WINDOW_LEVEL(wwin) != level) {
985 ChangeStackingLevel(wwin->frame->core, level);
988 break;
990 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
991 wwin = wWindowFor(event->xclient.window);
992 if (!wwin) return;
993 switch (event->xclient.data.l[0]) {
994 case WMTitleBarNormal:
995 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
996 break;
997 case WMTitleBarMain:
998 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
999 break;
1000 case WMTitleBarKey:
1001 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1002 break;
1004 #ifdef NETWM_HINTS
1005 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1006 /* do nothing */
1007 #endif
1008 #ifdef GNOME_STUFF
1009 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
1010 /* do nothing */
1011 #endif /* GNOME_STUFF */
1012 #ifdef KWM_HINTS
1013 } else if (wKWMProcessClientMessage(&event->xclient)) {
1014 /* do nothing */
1015 #endif /* KWM_HINTS */
1016 #ifdef XDND
1017 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1018 /* do nothing */
1019 #endif /* XDND */
1020 #ifdef OFFIX_DND
1021 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
1022 WScreen *scr = wScreenForWindow(event->xclient.window);
1023 if (scr && wDockReceiveDNDDrop(scr,event))
1024 goto redirect_message;
1025 #endif /* OFFIX_DND */
1026 } else {
1027 #ifdef OFFIX_DND
1028 redirect_message:
1029 #endif
1031 * Non-standard thing, but needed by OffiX DND.
1032 * For when the icon frame gets a ClientMessage
1033 * that should have gone to the icon_window.
1035 if (XFindContext(dpy, event->xbutton.window, wWinContext,
1036 (XPointer *)&desc)!=XCNOENT) {
1037 struct WIcon *icon=NULL;
1039 if (desc->parent_type == WCLASS_MINIWINDOW) {
1040 icon = (WIcon*)desc->parent;
1041 } else if (desc->parent_type == WCLASS_DOCK_ICON
1042 || desc->parent_type == WCLASS_APPICON) {
1043 icon = ((WAppIcon*)desc->parent)->icon;
1045 if (icon && (wwin=icon->owner)) {
1046 if (wwin->client_win!=event->xclient.window) {
1047 event->xclient.window = wwin->client_win;
1048 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1049 event);
1057 static void
1058 raiseWindow(WScreen *scr)
1060 WWindow *wwin;
1062 scr->autoRaiseTimer = NULL;
1064 wwin = wWindowFor(scr->autoRaiseWindow);
1065 if (!wwin)
1066 return;
1068 if (!wwin->flags.destroyed && wwin->flags.focused) {
1069 wRaiseFrame(wwin->frame->core);
1070 /* this is needed or a race condition will occur */
1071 XSync(dpy, False);
1076 static void
1077 handleEnterNotify(XEvent *event)
1079 WWindow *wwin;
1080 WObjDescriptor *desc = NULL;
1081 #ifdef VIRTUAL_DESKTOP
1082 void (*vdHandler)(XEvent * event);
1083 #endif
1084 XEvent ev;
1085 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1086 #ifdef DEBUG
1087 printf("got enter notify\n");
1088 #endif
1090 #ifdef VIRTUAL_DESKTOP
1091 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext,
1092 (XPointer *)&vdHandler)!=XCNOENT) {
1093 (*vdHandler)( event);
1095 #endif
1097 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1098 &ev)) {
1099 /* already left the window... */
1100 saveTimestamp(&ev);
1101 if (ev.xcrossing.mode==event->xcrossing.mode
1102 && ev.xcrossing.detail==event->xcrossing.detail) {
1103 return;
1107 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1108 (XPointer *)&desc)!=XCNOENT) {
1109 if(desc->handle_enternotify)
1110 (*desc->handle_enternotify)(desc, event);
1113 /* enter to window */
1114 wwin = wWindowFor(event->xcrossing.window);
1115 if (!wwin) {
1116 if (wPreferences.colormap_mode==WCM_POINTER) {
1117 wColormapInstallForWindow(scr, NULL);
1119 if (scr->autoRaiseTimer
1120 && event->xcrossing.root==event->xcrossing.window) {
1121 WMDeleteTimerHandler(scr->autoRaiseTimer);
1122 scr->autoRaiseTimer = NULL;
1124 } else {
1125 /* set auto raise timer even if in focus-follows-mouse mode
1126 * and the event is for the frame window, even if the window
1127 * has focus already. useful if you move the pointer from a focused
1128 * window to the root window and back pretty fast
1130 * set focus if in focus-follows-mouse mode and the event
1131 * is for the frame window and window doesn't have focus yet */
1132 if (wPreferences.focus_mode==WKF_SLOPPY
1133 && wwin->frame->core->window==event->xcrossing.window
1134 && !scr->flags.doing_alt_tab) {
1136 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1137 wSetFocusTo(scr, wwin);
1139 if (scr->autoRaiseTimer)
1140 WMDeleteTimerHandler(scr->autoRaiseTimer);
1141 scr->autoRaiseTimer = NULL;
1143 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1144 scr->autoRaiseWindow = wwin->frame->core->window;
1145 scr->autoRaiseTimer
1146 = WMAddTimerHandler(wPreferences.raise_delay,
1147 (WMCallback*)raiseWindow, scr);
1150 /* Install colormap for window, if the colormap installation mode
1151 * is colormap_follows_mouse */
1152 if (wPreferences.colormap_mode==WCM_POINTER) {
1153 if (wwin->client_win==event->xcrossing.window)
1154 wColormapInstallForWindow(scr, wwin);
1155 else
1156 wColormapInstallForWindow(scr, NULL);
1160 /* a little kluge to hide the clip balloon */
1161 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1162 if (!desc) {
1163 XUnmapWindow(dpy, scr->clip_balloon);
1164 scr->flags.clip_balloon_mapped = 0;
1165 } else {
1166 if (desc->parent_type!=WCLASS_DOCK_ICON
1167 || scr->clip_icon != desc->parent) {
1168 XUnmapWindow(dpy, scr->clip_balloon);
1169 scr->flags.clip_balloon_mapped = 0;
1174 if (event->xcrossing.window == event->xcrossing.root
1175 && event->xcrossing.detail == NotifyNormal
1176 && event->xcrossing.detail != NotifyInferior
1177 && wPreferences.focus_mode != WKF_CLICK) {
1179 wSetFocusTo(scr, scr->focused_window);
1182 #ifdef BALLOON_TEXT
1183 wBalloonEnteredObject(scr, desc);
1184 #endif
1188 static void
1189 handleLeaveNotify(XEvent *event)
1191 WObjDescriptor *desc = NULL;
1193 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1194 (XPointer *)&desc)!=XCNOENT) {
1195 if(desc->handle_leavenotify)
1196 (*desc->handle_leavenotify)(desc, event);
1201 #ifdef SHAPE
1202 static void
1203 handleShapeNotify(XEvent *event)
1205 XShapeEvent *shev = (XShapeEvent*)event;
1206 WWindow *wwin;
1207 XEvent ev;
1208 #ifdef DEBUG
1209 printf("got shape notify\n");
1210 #endif
1211 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1212 XShapeEvent *sev = (XShapeEvent*)&ev;
1214 if (sev->kind == ShapeBounding) {
1215 if (sev->shaped == shev->shaped) {
1216 *shev = *sev;
1217 } else {
1218 XPutBackEvent(dpy, &ev);
1219 break;
1224 wwin = wWindowFor(shev->window);
1225 if (!wwin || shev->kind != ShapeBounding)
1226 return;
1228 if (!shev->shaped && wwin->flags.shaped) {
1230 wwin->flags.shaped = 0;
1231 wWindowClearShape(wwin);
1233 } else if (shev->shaped) {
1235 wwin->flags.shaped = 1;
1236 wWindowSetShape(wwin);
1239 #endif /* SHAPE */
1241 #ifdef KEEP_XKB_LOCK_STATUS
1242 /* please help ]d if you know what to do */
1243 handleXkbIndicatorStateNotify(XEvent *event)
1245 WWindow *wwin;
1246 WScreen *scr;
1247 XkbStateRec staterec;
1248 int i;
1250 for (i=0; i<wScreenCount; i++) {
1251 scr = wScreenWithNumber(i);
1252 wwin = scr->focused_window;
1253 if (wwin && wwin->flags.focused) {
1254 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1255 if (wwin->frame->languagemode != staterec.group) {
1256 wwin->frame->last_languagemode = wwin->frame->languagemode;
1257 wwin->frame->languagemode = staterec.group;
1259 #ifdef XKB_BUTTON_HINT
1260 if (wwin->frame->titlebar) {
1261 wFrameWindowPaint(wwin->frame);
1263 #endif
1267 #endif /*KEEP_XKB_LOCK_STATUS*/
1269 static void
1270 handleColormapNotify(XEvent *event)
1272 WWindow *wwin;
1273 WScreen *scr;
1274 Bool reinstall = False;
1276 wwin = wWindowFor(event->xcolormap.window);
1277 if (!wwin)
1278 return;
1280 scr = wwin->screen_ptr;
1282 do {
1283 if (wwin) {
1284 if (event->xcolormap.new) {
1285 XWindowAttributes attr;
1287 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1289 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1290 scr->current_colormap = attr.colormap;
1292 reinstall = True;
1293 } else if (event->xcolormap.state == ColormapUninstalled &&
1294 scr->current_colormap == event->xcolormap.colormap) {
1296 /* some bastard app (like XV) removed our colormap */
1298 * can't enforce or things like xscreensaver wont work
1299 * reinstall = True;
1301 } else if (event->xcolormap.state == ColormapInstalled &&
1302 scr->current_colormap == event->xcolormap.colormap) {
1304 /* someone has put our colormap back */
1305 reinstall = False;
1308 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1309 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1311 if (reinstall && scr->current_colormap!=None) {
1312 if (!scr->flags.colormap_stuff_blocked)
1313 XInstallColormap(dpy, scr->current_colormap);
1319 static void
1320 handleFocusIn(XEvent *event)
1322 WWindow *wwin;
1325 * For applications that like stealing the focus.
1327 while (XCheckTypedEvent(dpy, FocusIn, event));
1328 saveTimestamp(event);
1329 if (event->xfocus.mode == NotifyUngrab
1330 || event->xfocus.mode == NotifyGrab
1331 || event->xfocus.detail > NotifyNonlinearVirtual) {
1332 return;
1335 wwin = wWindowFor(event->xfocus.window);
1336 if (wwin && !wwin->flags.focused) {
1337 if (wwin->flags.mapped)
1338 wSetFocusTo(wwin->screen_ptr, wwin);
1339 else
1340 wSetFocusTo(wwin->screen_ptr, NULL);
1341 } else if (!wwin) {
1342 WScreen *scr = wScreenForWindow(event->xfocus.window);
1343 if (scr)
1344 wSetFocusTo(scr, NULL);
1349 static WWindow*
1350 windowUnderPointer(WScreen *scr)
1352 unsigned int mask;
1353 int foo;
1354 Window bar, win;
1356 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1357 &mask))
1358 return wWindowFor(win);
1359 return NULL;
1365 static void
1366 handleKeyPress(XEvent *event)
1368 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1369 WWindow *wwin = scr->focused_window;
1370 int i;
1371 int modifiers;
1372 int command=-1, index;
1373 #ifdef KEEP_XKB_LOCK_STATUS
1374 XkbStateRec staterec;
1375 #endif /*KEEP_XKB_LOCK_STATUS*/
1377 /* ignore CapsLock */
1378 modifiers = event->xkey.state & ValidModMask;
1380 for (i=0; i<WKBD_LAST; i++) {
1381 if (wKeyBindings[i].keycode==0)
1382 continue;
1384 if (wKeyBindings[i].keycode==event->xkey.keycode
1385 && (/*wKeyBindings[i].modifier==0
1386 ||*/ wKeyBindings[i].modifier==modifiers)) {
1387 command = i;
1388 break;
1393 if (command < 0) {
1394 #ifdef LITE
1396 #if 0
1398 #endif
1399 #else
1400 if (!wRootMenuPerformShortcut(event)) {
1401 #endif
1402 static int dontLoop = 0;
1404 if (dontLoop > 10) {
1405 wwarning("problem with key event processing code");
1406 return;
1408 dontLoop++;
1409 /* if the focused window is an internal window, try redispatching
1410 * the event to the managed window, as it can be a WINGs window */
1411 if (wwin && wwin->flags.internal_window
1412 && wwin->client_leader!=None) {
1413 /* client_leader contains the WINGs toplevel */
1414 event->xany.window = wwin->client_leader;
1415 WMHandleEvent(event);
1417 dontLoop--;
1419 return;
1422 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1423 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1425 switch (command) {
1426 #ifndef LITE
1427 case WKBD_ROOTMENU:
1428 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1430 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1431 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1433 break;
1434 case WKBD_WINDOWLIST:
1436 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1437 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1439 break;
1440 #endif /* !LITE */
1441 case WKBD_WINDOWMENU:
1442 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1443 OpenWindowMenu(wwin, wwin->frame_x,
1444 wwin->frame_y+wwin->frame->top_width, True);
1445 break;
1446 case WKBD_MINIATURIZE:
1447 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1448 && !WFLAGP(wwin, no_miniaturizable)) {
1449 CloseWindowMenu(scr);
1451 if (wwin->protocols.MINIATURIZE_WINDOW)
1452 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1453 event->xbutton.time);
1454 else {
1455 wIconifyWindow(wwin);
1458 break;
1459 case WKBD_HIDE:
1460 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1461 WApplication *wapp = wApplicationOf(wwin->main_window);
1462 CloseWindowMenu(scr);
1464 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1465 wHideApplication(wapp);
1468 break;
1469 case WKBD_HIDE_OTHERS:
1470 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1471 CloseWindowMenu(scr);
1473 wHideOtherApplications(wwin);
1475 break;
1476 case WKBD_MAXIMIZE:
1477 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1478 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1480 CloseWindowMenu(scr);
1482 if (wwin->flags.maximized == newdir) {
1483 wUnmaximizeWindow(wwin);
1484 } else {
1485 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1488 break;
1489 case WKBD_VMAXIMIZE:
1490 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1491 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1493 CloseWindowMenu(scr);
1495 if (newdir) {
1496 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1497 } else {
1498 wUnmaximizeWindow(wwin);
1501 break;
1502 case WKBD_HMAXIMIZE:
1503 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1504 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1506 CloseWindowMenu(scr);
1508 if (newdir) {
1509 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1510 } else {
1511 wUnmaximizeWindow(wwin);
1514 break;
1515 case WKBD_RAISE:
1516 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1517 CloseWindowMenu(scr);
1519 wRaiseFrame(wwin->frame->core);
1521 break;
1522 case WKBD_LOWER:
1523 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1524 CloseWindowMenu(scr);
1526 wLowerFrame(wwin->frame->core);
1528 break;
1529 case WKBD_RAISELOWER:
1530 /* raise or lower the window under the pointer, not the
1531 * focused one
1533 wwin = windowUnderPointer(scr);
1534 if (wwin)
1535 wRaiseLowerFrame(wwin->frame->core);
1536 break;
1537 case WKBD_SHADE:
1538 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1539 if (wwin->flags.shaded)
1540 wUnshadeWindow(wwin);
1541 else
1542 wShadeWindow(wwin);
1544 break;
1545 case WKBD_MOVERESIZE:
1546 if (ISMAPPED(wwin) && ISFOCUSED(wwin) &&
1547 (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1548 CloseWindowMenu(scr);
1550 wKeyboardMoveResizeWindow(wwin);
1552 break;
1553 case WKBD_CLOSE:
1554 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1555 CloseWindowMenu(scr);
1556 if (wwin->protocols.DELETE_WINDOW)
1557 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1558 event->xkey.time);
1560 break;
1561 case WKBD_SELECT:
1562 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1563 wSelectWindow(wwin, !wwin->flags.selected);
1565 break;
1566 case WKBD_FOCUSNEXT:
1567 StartWindozeCycle(wwin, event, True);
1568 break;
1570 case WKBD_FOCUSPREV:
1571 StartWindozeCycle(wwin, event, False);
1572 break;
1574 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1575 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1576 i = (scr->current_workspace/10)*10 + wk - 1;\
1577 if (wPreferences.ws_advance || i<scr->workspace_count)\
1578 wWorkspaceChange(scr, i);\
1579 break
1580 #else
1581 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1582 i = (scr->current_workspace/10)*10 + wk - 1;\
1583 if (wPreferences.ws_advance || i<scr->workspace_count)\
1584 wWorkspaceChange(scr, i);\
1585 break
1586 #endif
1587 GOTOWORKS(1);
1588 GOTOWORKS(2);
1589 GOTOWORKS(3);
1590 GOTOWORKS(4);
1591 GOTOWORKS(5);
1592 GOTOWORKS(6);
1593 GOTOWORKS(7);
1594 GOTOWORKS(8);
1595 GOTOWORKS(9);
1596 GOTOWORKS(10);
1597 #undef GOTOWORKS
1598 case WKBD_NEXTWORKSPACE:
1599 wWorkspaceRelativeChange(scr, 1);
1600 break;
1601 case WKBD_PREVWORKSPACE:
1602 wWorkspaceRelativeChange(scr, -1);
1603 break;
1604 case WKBD_WINDOW1:
1605 case WKBD_WINDOW2:
1606 case WKBD_WINDOW3:
1607 case WKBD_WINDOW4:
1608 case WKBD_WINDOW5:
1609 case WKBD_WINDOW6:
1610 case WKBD_WINDOW7:
1611 case WKBD_WINDOW8:
1612 case WKBD_WINDOW9:
1613 case WKBD_WINDOW10:
1615 index = command-WKBD_WINDOW1;
1617 if (scr->shortcutWindows[index]) {
1618 WMArray *list = scr->shortcutWindows[index];
1619 int cw;
1620 int count = WMGetArrayItemCount(list);
1621 WWindow *twin;
1622 WMArrayIterator iter;
1623 WWindow *wwin;
1625 wUnselectWindows(scr);
1626 cw = scr->current_workspace;
1628 WM_ETARETI_ARRAY(list, wwin, iter) {
1629 if (count > 1)
1630 wWindowChangeWorkspace(wwin, cw);
1632 wMakeWindowVisible(wwin);
1634 if (count > 1)
1635 wSelectWindow(wwin, True);
1638 /* rotate the order of windows, to create a cycling effect */
1639 twin = WMGetFromArray(list, 0);
1640 WMDeleteFromArray(list, 0);
1641 WMAddToArray(list, twin);
1643 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1644 if (scr->shortcutWindows[index]) {
1645 WMFreeArray(scr->shortcutWindows[index]);
1646 scr->shortcutWindows[index] = NULL;
1649 if (wwin->flags.selected && scr->selected_windows) {
1650 scr->shortcutWindows[index] =
1651 WMDuplicateArray(scr->selected_windows);
1652 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1653 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1654 } else {
1655 scr->shortcutWindows[index] = WMCreateArray(4);
1656 WMAddToArray(scr->shortcutWindows[index], wwin);
1659 wSelectWindow(wwin, !wwin->flags.selected);
1660 XFlush(dpy);
1661 wusleep(3000);
1662 wSelectWindow(wwin, !wwin->flags.selected);
1663 XFlush(dpy);
1665 } else if (scr->selected_windows
1666 && WMGetArrayItemCount(scr->selected_windows)) {
1668 if (wwin->flags.selected && scr->selected_windows) {
1669 if (scr->shortcutWindows[index]) {
1670 WMFreeArray(scr->shortcutWindows[index]);
1672 scr->shortcutWindows[index] =
1673 WMDuplicateArray(scr->selected_windows);
1677 break;
1679 case WKBD_SWITCH_SCREEN:
1680 if (wScreenCount > 1) {
1681 WScreen *scr2;
1682 int i;
1684 /* find index of this screen */
1685 for (i = 0; i < wScreenCount; i++) {
1686 if (wScreenWithNumber(i) == scr)
1687 break;
1689 i++;
1690 if (i >= wScreenCount) {
1691 i = 0;
1693 scr2 = wScreenWithNumber(i);
1695 if (scr2) {
1696 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1697 scr2->scr_width/2, scr2->scr_height/2);
1700 break;
1702 case WKBD_NEXTWSLAYER:
1703 case WKBD_PREVWSLAYER:
1705 int row, column;
1707 row = scr->current_workspace/10;
1708 column = scr->current_workspace%10;
1710 if (command==WKBD_NEXTWSLAYER) {
1711 if ((row+1)*10 < scr->workspace_count)
1712 wWorkspaceChange(scr, column+(row+1)*10);
1713 } else {
1714 if (row > 0)
1715 wWorkspaceChange(scr, column+(row-1)*10);
1718 break;
1719 case WKBD_CLIPLOWER:
1720 if (!wPreferences.flags.noclip)
1721 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1722 break;
1723 case WKBD_CLIPRAISE:
1724 if (!wPreferences.flags.noclip)
1725 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1726 break;
1727 case WKBD_CLIPRAISELOWER:
1728 if (!wPreferences.flags.noclip)
1729 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1730 break;
1731 #ifdef KEEP_XKB_LOCK_STATUS
1732 case WKBD_TOGGLE:
1733 if(wPreferences.modelock) {
1734 /*toggle*/
1735 wwin = scr->focused_window;
1737 if (wwin && wwin->flags.mapped
1738 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1739 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1740 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1742 wwin->frame->languagemode = wwin->frame->last_languagemode;
1743 wwin->frame->last_languagemode = staterec.group;
1744 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1748 break;
1749 #endif /* KEEP_XKB_LOCK_STATUS */
1750 #ifdef VIRTUAL_DESKTOP
1751 case WKBD_VDESK_LEFT:
1752 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1753 break;
1755 case WKBD_VDESK_RIGHT:
1756 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1757 break;
1759 case WKBD_VDESK_UP:
1760 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1761 break;
1763 case WKBD_VDESK_DOWN:
1764 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1765 break;
1766 #endif
1772 static void
1773 handleMotionNotify(XEvent *event)
1775 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1777 if (wPreferences.scrollable_menus) {
1778 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1779 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1781 if (scr->flags.jump_back_pending ||
1782 p.x <= (rect.pos.x + 1) ||
1783 p.x >= (rect.pos.x + rect.size.width - 2) ||
1784 p.y <= (rect.pos.y + 1) ||
1785 p.y >= (rect.pos.y + rect.size.height - 2)) {
1786 WMenu *menu;
1787 #ifdef DEBUG
1788 printf("pointer at screen edge\n");
1789 #endif
1790 menu = wMenuUnderPointer(scr);
1791 if (menu!=NULL)
1792 wMenuScroll(menu, event);
1796 #if 0 // what is with this? -Dan
1797 if (event->xmotion.subwindow == None)
1798 return;
1800 if (scr->scrolledFMaximize != None) {
1801 WWindow *twin;
1803 twin = wWindowFor(scr->scrolledFMaximize);
1804 if (twin && twin->frame_y ==) {
1808 scr->scrolledFMaximize = NULL;
1810 } else {
1812 /* scroll full maximized window */
1813 if (event->xmotion.y_root < 1
1814 || event->xmotion.y_root > scr->scr_height - 1) {
1816 wwin = wWindowFor(event->xmotion.subwindow);
1818 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1819 && WFLAGP(wwin, full_maximize)
1820 && event->xmotion.x_root >= wwin->frame_x
1821 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1823 if (HAS_BORDER(wwin)
1824 && wwin->frame_y <= - wwin->frame->top_width) {
1826 wWindowMove(wwin, wwin->frame_x, 0);
1827 wwin->flags.dragged_while_fmaximized = 0;
1829 } else if (HAS_RESIZEBAR(wwin)
1830 && wwin->frame_y + wwin->frame->core->height >=
1831 scr->scr_height + wwin->frame->bottom_width) {
1833 int y = scr->scr_height + wwin->frame->bottom_width;
1835 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1837 wWindowMove(wwin, wwin->frame_x, y);
1838 wwin->flags.dragged_while_fmaximized = 0;
1842 #endif
1846 static void
1847 handleVisibilityNotify(XEvent *event)
1849 WWindow *wwin;
1851 wwin = wWindowFor(event->xvisibility.window);
1852 if (!wwin)
1853 return;
1854 wwin->flags.obscured =
1855 (event->xvisibility.state == VisibilityFullyObscured);