- Check whether libXft is at least version 2.1.2 else refuse to compile.
[wmaker-crm.git] / src / event.c
blobd5cab4dc0f233e0b2be7991e6654a223eb41c41b
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 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"
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(), handleUnmapNotify();
122 static void handleButtonPress(), handleExpose();
123 static void handleDestroyNotify();
124 static void handleConfigureRequest();
125 static void handleMapRequest();
126 static void handlePropertyNotify();
127 static void handleEnterNotify();
128 static void handleLeaveNotify();
129 static void handleExtensions();
130 static void handleClientMessage();
131 static void handleKeyPress();
132 static void handleFocusIn();
133 static void handleMotionNotify();
134 static void handleVisibilityNotify();
137 #ifdef SHAPE
138 static void handleShapeNotify();
139 #endif
141 /* called from the signal handler */
142 void NotifyDeadProcess(pid_t pid, unsigned char status);
144 /* real dead process handler */
145 static void handleDeadProcess(void *foo);
148 typedef struct DeadProcesses {
149 pid_t pid;
150 unsigned char exit_status;
151 } DeadProcesses;
153 /* stack of dead processes */
154 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
155 static int deadProcessPtr=0;
158 typedef struct DeathHandler {
159 WDeathHandler *callback;
160 pid_t pid;
161 void *client_data;
162 } DeathHandler;
164 static WMArray *deathHandlers=NULL;
168 WMagicNumber
169 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
171 DeathHandler *handler;
173 handler = malloc(sizeof(DeathHandler));
174 if (!handler)
175 return 0;
177 handler->pid = pid;
178 handler->callback = callback;
179 handler->client_data = cdata;
181 if (!deathHandlers)
182 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
184 WMAddToArray(deathHandlers, handler);
186 return handler;
191 void
192 wDeleteDeathHandler(WMagicNumber id)
194 DeathHandler *handler=(DeathHandler*)id;
196 if (!handler || !deathHandlers)
197 return;
199 /* array destructor will call wfree(handler) */
200 WMRemoveFromArray(deathHandlers, handler);
204 void
205 DispatchEvent(XEvent *event)
207 if (deathHandlers)
208 handleDeadProcess(NULL);
210 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
211 WCHANGE_STATE(WSTATE_EXITING);
212 /* received SIGTERM */
214 * WMHandleEvent() can't be called from anything
215 * executed inside here, or we can get in a infinite
216 * recursive loop.
218 Shutdown(WSExitMode);
220 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
221 WCHANGE_STATE(WSTATE_RESTARTING);
223 Shutdown(WSRestartPreparationMode);
224 /* received SIGHUP */
225 Restart(NULL, True);
226 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
227 WCHANGE_STATE(WSTATE_NORMAL);
228 wDefaultsCheckDomains("bla");
231 /* for the case that all that is wanted to be dispatched is
232 * the stuff above */
233 if (!event)
234 return;
236 saveTimestamp(event);
237 switch (event->type) {
238 case MapRequest:
239 handleMapRequest(event);
240 break;
242 case KeyPress:
243 handleKeyPress(event);
244 break;
246 case MotionNotify:
247 handleMotionNotify(event);
248 break;
250 case ConfigureRequest:
251 handleConfigureRequest(event);
252 break;
254 case DestroyNotify:
255 handleDestroyNotify(event);
256 break;
258 case MapNotify:
259 handleMapNotify(event);
260 break;
262 case UnmapNotify:
263 handleUnmapNotify(event);
264 break;
266 case ButtonPress:
267 handleButtonPress(event);
268 break;
270 case Expose:
271 handleExpose(event);
272 break;
274 case PropertyNotify:
275 handlePropertyNotify(event);
276 break;
278 case EnterNotify:
279 handleEnterNotify(event);
280 break;
282 case LeaveNotify:
283 handleLeaveNotify(event);
284 break;
286 case ClientMessage:
287 handleClientMessage(event);
288 break;
290 case ColormapNotify:
291 handleColormapNotify(event);
292 break;
294 case MappingNotify:
295 if (event->xmapping.request == MappingKeyboard
296 || event->xmapping.request == MappingModifier)
297 XRefreshKeyboardMapping(&event->xmapping);
298 break;
300 case FocusIn:
301 handleFocusIn(event);
302 break;
304 case VisibilityNotify:
305 handleVisibilityNotify(event);
306 break;
307 default:
308 handleExtensions(event);
309 break;
315 *----------------------------------------------------------------------
316 * EventLoop-
317 * Processes X and internal events indefinitely.
319 * Returns:
320 * Never returns
322 * Side effects:
323 * The LastTimestamp global variable is updated.
324 *----------------------------------------------------------------------
326 void
327 EventLoop()
329 XEvent event;
331 for(;;) {
332 WMNextEvent(dpy, &event);
333 WMHandleEvent(&event);
339 *----------------------------------------------------------------------
340 * ProcessPendingEvents --
341 * Processes the events that are currently pending (at the time
342 * this function is called) in the display's queue.
344 * Returns:
345 * After the pending events that were present at the function call
346 * are processed.
348 * Side effects:
349 * Many -- whatever handling events may involve.
351 *----------------------------------------------------------------------
353 void
354 ProcessPendingEvents()
356 XEvent event;
357 int count;
359 XSync(dpy, False);
361 /* Take a snapshot of the event count in the queue */
362 count = XPending(dpy);
364 while (count>0 && XPending(dpy)) {
365 WMNextEvent(dpy, &event);
366 WMHandleEvent(&event);
367 count--;
372 Bool
373 IsDoubleClick(WScreen *scr, XEvent *event)
375 if ((scr->last_click_time>0) &&
376 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
377 && (event->xbutton.button == scr->last_click_button)
378 && (event->xbutton.window == scr->last_click_window)) {
380 scr->flags.next_click_is_not_double = 1;
381 scr->last_click_time = 0;
382 scr->last_click_window = event->xbutton.window;
384 return True;
386 return False;
390 void
391 NotifyDeadProcess(pid_t pid, unsigned char status)
393 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
394 wwarning("stack overflow: too many dead processes");
395 return;
397 /* stack the process to be handled later,
398 * as this is called from the signal handler */
399 deadProcesses[deadProcessPtr].pid = pid;
400 deadProcesses[deadProcessPtr].exit_status = status;
401 deadProcessPtr++;
405 static void
406 handleDeadProcess(void *foo)
408 DeathHandler *tmp;
409 int i;
411 for (i=0; i<deadProcessPtr; i++) {
412 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
415 if (!deathHandlers) {
416 deadProcessPtr=0;
417 return;
420 /* get the pids on the queue and call handlers */
421 while (deadProcessPtr>0) {
422 deadProcessPtr--;
424 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
425 tmp = WMGetFromArray(deathHandlers, i);
426 if (!tmp)
427 continue;
429 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
430 (*tmp->callback)(tmp->pid,
431 deadProcesses[deadProcessPtr].exit_status,
432 tmp->client_data);
433 wDeleteDeathHandler(tmp);
440 static void
441 saveTimestamp(XEvent *event)
444 * Never save CurrentTime as LastTimestamp because CurrentTime
445 * it's not a real timestamp (it's the 0L constant)
448 switch (event->type) {
449 case ButtonRelease:
450 case ButtonPress:
451 LastTimestamp = event->xbutton.time;
452 break;
453 case KeyPress:
454 case KeyRelease:
455 LastTimestamp = event->xkey.time;
456 break;
457 case MotionNotify:
458 LastTimestamp = event->xmotion.time;
459 break;
460 case PropertyNotify:
461 LastTimestamp = event->xproperty.time;
462 break;
463 case EnterNotify:
464 case LeaveNotify:
465 LastTimestamp = event->xcrossing.time;
466 break;
467 case SelectionClear:
468 LastTimestamp = event->xselectionclear.time;
469 break;
470 case SelectionRequest:
471 LastTimestamp = event->xselectionrequest.time;
472 break;
473 case SelectionNotify:
474 LastTimestamp = event->xselection.time;
475 #ifdef XDND
476 wXDNDProcessSelection(event);
477 #endif
478 break;
483 static int
484 matchWindow(void *item, void *cdata)
486 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
490 static void
491 handleExtensions(XEvent *event)
493 #ifdef KEEP_XKB_LOCK_STATUS
494 XkbEvent *xkbevent;
495 xkbevent = (XkbEvent *)event;
496 #endif /*KEEP_XKB_LOCK_STATUS*/
497 #ifdef SHAPE
498 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
499 handleShapeNotify(event);
501 #endif
502 #ifdef KEEP_XKB_LOCK_STATUS
503 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
504 handleXkbIndicatorStateNotify(event);
506 #endif /*KEEP_XKB_LOCK_STATUS*/
510 static void
511 handleMapRequest(XEvent *ev)
513 WWindow *wwin;
514 WScreen *scr = NULL;
515 Window window = ev->xmaprequest.window;
517 #ifdef DEBUG
518 printf("got map request for %x\n", (unsigned)window);
519 #endif
520 if ((wwin = wWindowFor(window))) {
521 if (wwin->flags.shaded) {
522 wUnshadeWindow(wwin);
524 /* deiconify window */
525 if (wwin->flags.miniaturized) {
526 wDeiconifyWindow(wwin);
527 } else if (wwin->flags.hidden) {
528 WApplication *wapp = wApplicationOf(wwin->main_window);
529 /* go to the last workspace that the user worked on the app */
530 if (wapp) {
531 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
533 wUnhideApplication(wapp, False, False);
535 return;
538 scr = wScreenForRootWindow(ev->xmaprequest.parent);
540 wwin = wManageWindow(scr, window);
543 * This is to let the Dock know that the application it launched
544 * has already been mapped (eg: it has finished launching).
545 * It is not necessary for normally docked apps, but is needed for
546 * apps that were forcedly docked (like with dockit).
548 if (scr->last_dock) {
549 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
550 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
551 else
552 wDockTrackWindowLaunch(scr->last_dock, window);
555 if (wwin) {
556 wClientSetState(wwin, NormalState, None);
557 if (wwin->flags.maximized) {
558 wMaximizeWindow(wwin, wwin->flags.maximized);
560 if (wwin->flags.shaded) {
561 wwin->flags.shaded = 0;
562 wwin->flags.skip_next_animation = 1;
563 wShadeWindow(wwin);
565 if (wwin->flags.miniaturized) {
566 wwin->flags.miniaturized = 0;
567 wwin->flags.skip_next_animation = 1;
568 wIconifyWindow(wwin);
570 if (wwin->flags.hidden) {
571 WApplication *wapp = wApplicationOf(wwin->main_window);
573 wwin->flags.hidden = 0;
574 wwin->flags.skip_next_animation = 1;
575 if (wapp) {
576 wHideApplication(wapp);
583 static void
584 handleDestroyNotify(XEvent *event)
586 WWindow *wwin;
587 WApplication *app;
588 Window window = event->xdestroywindow.window;
589 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
590 int index;
592 #ifdef DEBUG
593 printf("got destroy notify\n");
594 #endif
595 wwin = wWindowFor(window);
596 if (wwin) {
597 wUnmanageWindow(wwin, False, True);
600 if (scr != NULL) {
601 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
602 (void*)window)) != WANotFound) {
603 WFakeGroupLeader *fPtr;
605 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
606 if (fPtr->retainCount > 0) {
607 fPtr->retainCount--;
608 if (fPtr->retainCount==0 && fPtr->leader!=None) {
609 XDestroyWindow(dpy, fPtr->leader);
610 fPtr->leader = None;
611 XFlush(dpy);
614 fPtr->origLeader = None;
618 app = wApplicationOf(window);
619 if (app) {
620 if (window == app->main_window) {
621 app->refcount = 0;
622 wwin = app->main_window_desc->screen_ptr->focused_window;
623 while (wwin) {
624 if (wwin->main_window == window) {
625 wwin->main_window = None;
627 wwin = wwin->prev;
630 wApplicationDestroy(app);
633 #ifdef KWM_HINTS
634 wKWMCheckDestroy(&event->xdestroywindow);
635 #endif
640 static void
641 handleExpose(XEvent *event)
643 WObjDescriptor *desc;
644 XEvent ev;
646 #ifdef DEBUG
647 printf("got expose\n");
648 #endif
649 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
651 if (XFindContext(dpy, event->xexpose.window, wWinContext,
652 (XPointer *)&desc)==XCNOENT) {
653 return;
656 if (desc->handle_expose) {
657 (*desc->handle_expose)(desc, event);
661 static void
662 executeButtonAction(WScreen *scr, XEvent *event, int action)
664 switch(action) {
665 case WA_SELECT_WINDOWS:
666 wUnselectWindows(scr);
667 wSelectWindows(scr, event);
668 break;
669 case WA_OPEN_APPMENU:
670 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
671 /* ugly hack */
672 if (scr->root_menu) {
673 if (scr->root_menu->brother->flags.mapped)
674 event->xbutton.window = scr->root_menu->brother->frame->core->window;
675 else
676 event->xbutton.window = scr->root_menu->frame->core->window;
678 break;
679 case WA_OPEN_WINLISTMENU:
680 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
681 if (scr->switch_menu) {
682 if (scr->switch_menu->brother->flags.mapped)
683 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
684 else
685 event->xbutton.window = scr->switch_menu->frame->core->window;
687 break;
688 default:
689 break;
694 /* bindable */
695 static void
696 handleButtonPress(XEvent *event)
698 WObjDescriptor *desc;
699 WScreen *scr;
701 #ifdef DEBUG
702 printf("got button press\n");
703 #endif
704 scr = wScreenForRootWindow(event->xbutton.root);
706 #ifdef BALLOON_TEXT
707 wBalloonHide(scr);
708 #endif
711 #ifndef LITE
712 if (event->xbutton.window==scr->root_win) {
713 if (event->xbutton.button==Button1 &&
714 wPreferences.mouse_button1!=WA_NONE) {
715 executeButtonAction(scr, event, wPreferences.mouse_button1);
716 } else if (event->xbutton.button==Button2 &&
717 wPreferences.mouse_button2!=WA_NONE) {
718 executeButtonAction(scr, event, wPreferences.mouse_button2);
719 } else if (event->xbutton.button==Button3 &&
720 wPreferences.mouse_button3!=WA_NONE) {
721 executeButtonAction(scr, event, wPreferences.mouse_button3);
722 } else if (event->xbutton.button==Button4 &&
723 wPreferences.mouse_wheel!=WA_NONE) {
724 wWorkspaceRelativeChange(scr, 1);
725 } else if (event->xbutton.button==Button5 &&
726 wPreferences.mouse_wheel!=WA_NONE) {
727 wWorkspaceRelativeChange(scr, -1);
729 #ifdef GNOME_STUFF
730 else if (wGNOMEProxyizeButtonEvent(scr, event))
731 return;
732 #endif
734 #endif /* !LITE */
736 desc = NULL;
737 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
738 (XPointer *)&desc)==XCNOENT) {
739 if (XFindContext(dpy, event->xbutton.window, wWinContext,
740 (XPointer *)&desc)==XCNOENT) {
741 return;
745 if (desc->parent_type == WCLASS_WINDOW) {
746 XSync(dpy, 0);
748 if (event->xbutton.state & MOD_MASK) {
749 XAllowEvents(dpy, AsyncPointer, CurrentTime);
752 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
753 if (wPreferences.ignore_focus_click) {
754 XAllowEvents(dpy, AsyncPointer, CurrentTime);
756 XAllowEvents(dpy, ReplayPointer, CurrentTime);
757 /* }*/
758 XSync(dpy, 0);
759 } else if (desc->parent_type == WCLASS_APPICON
760 || desc->parent_type == WCLASS_MINIWINDOW
761 || desc->parent_type == WCLASS_DOCK_ICON) {
762 if (event->xbutton.state & MOD_MASK) {
763 XSync(dpy, 0);
764 XAllowEvents(dpy, AsyncPointer, CurrentTime);
765 XSync(dpy, 0);
769 if (desc->handle_mousedown!=NULL) {
770 (*desc->handle_mousedown)(desc, event);
773 /* save double-click information */
774 if (scr->flags.next_click_is_not_double) {
775 scr->flags.next_click_is_not_double = 0;
776 } else {
777 scr->last_click_time = event->xbutton.time;
778 scr->last_click_button = event->xbutton.button;
779 scr->last_click_window = event->xbutton.window;
784 static void
785 handleMapNotify(XEvent *event)
787 WWindow *wwin;
788 #ifdef DEBUG
789 printf("got map\n");
790 #endif
791 wwin = wWindowFor(event->xmap.event);
792 if (wwin && wwin->client_win == event->xmap.event) {
793 if (wwin->flags.miniaturized) {
794 wDeiconifyWindow(wwin);
795 } else {
796 XGrabServer(dpy);
797 wWindowMap(wwin);
798 wClientSetState(wwin, NormalState, None);
799 XUngrabServer(dpy);
805 static void
806 handleUnmapNotify(XEvent *event)
808 WWindow *wwin;
809 XEvent ev;
810 Bool withdraw = False;
811 #ifdef DEBUG
812 printf("got unmap\n");
813 #endif
814 /* only process windows with StructureNotify selected
815 * (ignore SubstructureNotify) */
816 wwin = wWindowFor(event->xunmap.window);
817 if (!wwin)
818 return;
820 /* whether the event is a Withdrawal request */
821 if (event->xunmap.event == wwin->screen_ptr->root_win
822 && event->xunmap.send_event)
823 withdraw = True;
825 if (wwin->client_win != event->xunmap.event && !withdraw)
826 return;
828 if (!wwin->flags.mapped && !withdraw
829 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
830 && !wwin->flags.miniaturized && !wwin->flags.hidden)
831 return;
833 XGrabServer(dpy);
834 XUnmapWindow(dpy, wwin->frame->core->window);
835 wwin->flags.mapped = 0;
836 XSync(dpy, 0);
837 /* check if the window was destroyed */
838 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
839 DispatchEvent(&ev);
840 } else {
841 Bool reparented = False;
843 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
844 reparented = True;
846 /* withdraw window */
847 wwin->flags.mapped = 0;
848 if (!reparented)
849 wClientSetState(wwin, WithdrawnState, None);
851 /* if the window was reparented, do not reparent it back to the
852 * root window */
853 wUnmanageWindow(wwin, !reparented, False);
855 XUngrabServer(dpy);
859 static void
860 handleConfigureRequest(XEvent *event)
862 WWindow *wwin;
863 #ifdef DEBUG
864 printf("got configure request\n");
865 #endif
866 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
868 * Configure request for unmapped window
870 wClientConfigure(NULL, &(event->xconfigurerequest));
871 } else {
872 wClientConfigure(wwin, &(event->xconfigurerequest));
877 static void
878 handlePropertyNotify(XEvent *event)
880 WWindow *wwin;
881 WApplication *wapp;
882 Window jr;
883 int ji;
884 unsigned int ju;
885 WScreen *scr;
886 #ifdef DEBUG
887 printf("got property notify\n");
888 #endif
889 if ((wwin=wWindowFor(event->xproperty.window))) {
890 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
891 &ju, &ju, &ju, &ju)) {
892 return;
894 wClientCheckProperty(wwin, &event->xproperty);
896 wapp = wApplicationOf(event->xproperty.window);
897 if (wapp) {
898 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
901 scr = wScreenForWindow(event->xproperty.window);
902 if (scr && scr->root_win == event->xproperty.window) {
903 #ifdef KWM_HINTS
904 wKWMCheckRootHintChange(scr, &event->xproperty);
905 #endif
910 static void
911 handleClientMessage(XEvent *event)
913 WWindow *wwin;
914 WObjDescriptor *desc;
915 #ifdef DEBUG
916 printf("got client message\n");
917 #endif
918 /* handle transition from Normal to Iconic state */
919 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
920 && event->xclient.format == 32
921 && event->xclient.data.l[0] == IconicState) {
923 wwin = wWindowFor(event->xclient.window);
924 if (!wwin) return;
925 if (!wwin->flags.miniaturized)
926 wIconifyWindow(wwin);
927 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
928 && event->xclient.format == 32) {
929 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
931 if (!scr)
932 return;
934 if (event->xclient.data.l[1] == 1) { /* starting */
935 wColormapAllowClientInstallation(scr, True);
936 } else { /* stopping */
937 wColormapAllowClientInstallation(scr, False);
939 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
941 wDefaultsCheckDomains("bla");
943 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
944 WApplication *wapp;
945 int done=0;
946 wapp = wApplicationOf(event->xclient.window);
947 if (wapp) {
948 switch (event->xclient.data.l[0]) {
949 case WMFHideOtherApplications:
950 wHideOtherApplications(wapp->main_window_desc);
951 done = 1;
952 break;
954 case WMFHideApplication:
955 wHideApplication(wapp);
956 done = 1;
957 break;
960 if (!done) {
961 wwin = wWindowFor(event->xclient.window);
962 if (wwin) {
963 switch (event->xclient.data.l[0]) {
964 case WMFHideOtherApplications:
965 wHideOtherApplications(wwin);
966 break;
968 case WMFHideApplication:
969 wHideApplication(wApplicationOf(wwin->main_window));
970 break;
974 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
975 wwin = wWindowFor(event->xclient.window);
976 if (!wwin) return;
977 switch (event->xclient.data.l[0]) {
978 case GSWindowLevelAttr:
980 int level = (int)event->xclient.data.l[1];
982 if (WINDOW_LEVEL(wwin) != level) {
983 ChangeStackingLevel(wwin->frame->core, level);
986 break;
988 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
989 wwin = wWindowFor(event->xclient.window);
990 if (!wwin) return;
991 switch (event->xclient.data.l[0]) {
992 case WMTitleBarNormal:
993 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
994 break;
995 case WMTitleBarMain:
996 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
997 break;
998 case WMTitleBarKey:
999 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1000 break;
1002 #ifdef NETWM_HINTS
1003 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1004 /* do nothing */
1005 #endif
1006 #ifdef GNOME_STUFF
1007 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
1008 /* do nothing */
1009 #endif /* GNOME_STUFF */
1010 #ifdef KWM_HINTS
1011 } else if (wKWMProcessClientMessage(&event->xclient)) {
1012 /* do nothing */
1013 #endif /* KWM_HINTS */
1014 #ifdef XDND
1015 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1016 /* do nothing */
1017 #endif /* XDND */
1018 #ifdef OFFIX_DND
1019 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
1020 WScreen *scr = wScreenForWindow(event->xclient.window);
1021 if (scr && wDockReceiveDNDDrop(scr,event))
1022 goto redirect_message;
1023 #endif /* OFFIX_DND */
1024 } else {
1025 #ifdef OFFIX_DND
1026 redirect_message:
1027 #endif
1029 * Non-standard thing, but needed by OffiX DND.
1030 * For when the icon frame gets a ClientMessage
1031 * that should have gone to the icon_window.
1033 if (XFindContext(dpy, event->xbutton.window, wWinContext,
1034 (XPointer *)&desc)!=XCNOENT) {
1035 struct WIcon *icon=NULL;
1037 if (desc->parent_type == WCLASS_MINIWINDOW) {
1038 icon = (WIcon*)desc->parent;
1039 } else if (desc->parent_type == WCLASS_DOCK_ICON
1040 || desc->parent_type == WCLASS_APPICON) {
1041 icon = ((WAppIcon*)desc->parent)->icon;
1043 if (icon && (wwin=icon->owner)) {
1044 if (wwin->client_win!=event->xclient.window) {
1045 event->xclient.window = wwin->client_win;
1046 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1047 event);
1055 static void
1056 raiseWindow(WScreen *scr)
1058 WWindow *wwin;
1060 scr->autoRaiseTimer = NULL;
1062 wwin = wWindowFor(scr->autoRaiseWindow);
1063 if (!wwin)
1064 return;
1066 if (!wwin->flags.destroyed && wwin->flags.focused) {
1067 wRaiseFrame(wwin->frame->core);
1068 /* this is needed or a race condition will occur */
1069 XSync(dpy, False);
1074 static void
1075 handleEnterNotify(XEvent *event)
1077 WWindow *wwin;
1078 WObjDescriptor *desc = NULL;
1079 #ifdef VIRTUAL_DESKTOP
1080 void (*vdHandler)(XEvent * event);
1081 #endif
1082 XEvent ev;
1083 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1084 #ifdef DEBUG
1085 printf("got enter notify\n");
1086 #endif
1088 #ifdef VIRTUAL_DESKTOP
1089 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext,
1090 (XPointer *)&vdHandler)!=XCNOENT) {
1091 (*vdHandler)( event);
1093 #endif
1095 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1096 &ev)) {
1097 /* already left the window... */
1098 saveTimestamp(&ev);
1099 if (ev.xcrossing.mode==event->xcrossing.mode
1100 && ev.xcrossing.detail==event->xcrossing.detail) {
1101 return;
1105 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1106 (XPointer *)&desc)!=XCNOENT) {
1107 if(desc->handle_enternotify)
1108 (*desc->handle_enternotify)(desc, event);
1111 /* enter to window */
1112 wwin = wWindowFor(event->xcrossing.window);
1113 if (!wwin) {
1114 if (wPreferences.colormap_mode==WCM_POINTER) {
1115 wColormapInstallForWindow(scr, NULL);
1117 if (scr->autoRaiseTimer
1118 && event->xcrossing.root==event->xcrossing.window) {
1119 WMDeleteTimerHandler(scr->autoRaiseTimer);
1120 scr->autoRaiseTimer = NULL;
1122 } else {
1123 /* set auto raise timer even if in focus-follows-mouse mode
1124 * and the event is for the frame window, even if the window
1125 * has focus already. useful if you move the pointer from a focused
1126 * window to the root window and back pretty fast
1128 * set focus if in focus-follows-mouse mode and the event
1129 * is for the frame window and window doesn't have focus yet */
1130 if (wPreferences.focus_mode==WKF_SLOPPY
1131 && wwin->frame->core->window==event->xcrossing.window
1132 && !scr->flags.doing_alt_tab) {
1134 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1135 wSetFocusTo(scr, wwin);
1137 if (scr->autoRaiseTimer)
1138 WMDeleteTimerHandler(scr->autoRaiseTimer);
1139 scr->autoRaiseTimer = NULL;
1141 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1142 scr->autoRaiseWindow = wwin->frame->core->window;
1143 scr->autoRaiseTimer
1144 = WMAddTimerHandler(wPreferences.raise_delay,
1145 (WMCallback*)raiseWindow, scr);
1148 /* Install colormap for window, if the colormap installation mode
1149 * is colormap_follows_mouse */
1150 if (wPreferences.colormap_mode==WCM_POINTER) {
1151 if (wwin->client_win==event->xcrossing.window)
1152 wColormapInstallForWindow(scr, wwin);
1153 else
1154 wColormapInstallForWindow(scr, NULL);
1158 /* a little kluge to hide the clip balloon */
1159 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1160 if (!desc) {
1161 XUnmapWindow(dpy, scr->clip_balloon);
1162 scr->flags.clip_balloon_mapped = 0;
1163 } else {
1164 if (desc->parent_type!=WCLASS_DOCK_ICON
1165 || scr->clip_icon != desc->parent) {
1166 XUnmapWindow(dpy, scr->clip_balloon);
1167 scr->flags.clip_balloon_mapped = 0;
1172 if (event->xcrossing.window == event->xcrossing.root
1173 && event->xcrossing.detail == NotifyNormal
1174 && event->xcrossing.detail != NotifyInferior
1175 && wPreferences.focus_mode != WKF_CLICK) {
1177 wSetFocusTo(scr, scr->focused_window);
1180 #ifdef BALLOON_TEXT
1181 wBalloonEnteredObject(scr, desc);
1182 #endif
1186 static void
1187 handleLeaveNotify(XEvent *event)
1189 WObjDescriptor *desc = NULL;
1191 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1192 (XPointer *)&desc)!=XCNOENT) {
1193 if(desc->handle_leavenotify)
1194 (*desc->handle_leavenotify)(desc, event);
1199 #ifdef SHAPE
1200 static void
1201 handleShapeNotify(XEvent *event)
1203 XShapeEvent *shev = (XShapeEvent*)event;
1204 WWindow *wwin;
1205 XEvent ev;
1206 #ifdef DEBUG
1207 printf("got shape notify\n");
1208 #endif
1209 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1210 XShapeEvent *sev = (XShapeEvent*)&ev;
1212 if (sev->kind == ShapeBounding) {
1213 if (sev->shaped == shev->shaped) {
1214 *shev = *sev;
1215 } else {
1216 XPutBackEvent(dpy, &ev);
1217 break;
1222 wwin = wWindowFor(shev->window);
1223 if (!wwin || shev->kind != ShapeBounding)
1224 return;
1226 if (!shev->shaped && wwin->flags.shaped) {
1228 wwin->flags.shaped = 0;
1229 wWindowClearShape(wwin);
1231 } else if (shev->shaped) {
1233 wwin->flags.shaped = 1;
1234 wWindowSetShape(wwin);
1237 #endif /* SHAPE */
1239 #ifdef KEEP_XKB_LOCK_STATUS
1240 /* please help ]d if you know what to do */
1241 handleXkbIndicatorStateNotify(XEvent *event)
1243 WWindow *wwin;
1244 WScreen *scr;
1245 XkbStateRec staterec;
1246 int i;
1248 for (i=0; i<wScreenCount; i++) {
1249 scr = wScreenWithNumber(i);
1250 wwin = scr->focused_window;
1251 if (wwin && wwin->flags.focused) {
1252 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1253 if (wwin->frame->languagemode != staterec.group) {
1254 wwin->frame->last_languagemode = wwin->frame->languagemode;
1255 wwin->frame->languagemode = staterec.group;
1257 #ifdef XKB_BUTTON_HINT
1258 if (wwin->frame->titlebar) {
1259 wFrameWindowPaint(wwin->frame);
1261 #endif
1265 #endif /*KEEP_XKB_LOCK_STATUS*/
1267 static void
1268 handleColormapNotify(XEvent *event)
1270 WWindow *wwin;
1271 WScreen *scr;
1272 Bool reinstall = False;
1274 wwin = wWindowFor(event->xcolormap.window);
1275 if (!wwin)
1276 return;
1278 scr = wwin->screen_ptr;
1280 do {
1281 if (wwin) {
1282 if (event->xcolormap.new) {
1283 XWindowAttributes attr;
1285 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1287 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1288 scr->current_colormap = attr.colormap;
1290 reinstall = True;
1291 } else if (event->xcolormap.state == ColormapUninstalled &&
1292 scr->current_colormap == event->xcolormap.colormap) {
1294 /* some bastard app (like XV) removed our colormap */
1296 * can't enforce or things like xscreensaver wont work
1297 * reinstall = True;
1299 } else if (event->xcolormap.state == ColormapInstalled &&
1300 scr->current_colormap == event->xcolormap.colormap) {
1302 /* someone has put our colormap back */
1303 reinstall = False;
1306 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1307 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1309 if (reinstall && scr->current_colormap!=None) {
1310 if (!scr->flags.colormap_stuff_blocked)
1311 XInstallColormap(dpy, scr->current_colormap);
1317 static void
1318 handleFocusIn(XEvent *event)
1320 WWindow *wwin;
1323 * For applications that like stealing the focus.
1325 while (XCheckTypedEvent(dpy, FocusIn, event));
1326 saveTimestamp(event);
1327 if (event->xfocus.mode == NotifyUngrab
1328 || event->xfocus.mode == NotifyGrab
1329 || event->xfocus.detail > NotifyNonlinearVirtual) {
1330 return;
1333 wwin = wWindowFor(event->xfocus.window);
1334 if (wwin && !wwin->flags.focused) {
1335 if (wwin->flags.mapped)
1336 wSetFocusTo(wwin->screen_ptr, wwin);
1337 else
1338 wSetFocusTo(wwin->screen_ptr, NULL);
1339 } else if (!wwin) {
1340 WScreen *scr = wScreenForWindow(event->xfocus.window);
1341 if (scr)
1342 wSetFocusTo(scr, NULL);
1347 static WWindow*
1348 windowUnderPointer(WScreen *scr)
1350 unsigned int mask;
1351 int foo;
1352 Window bar, win;
1354 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1355 &mask))
1356 return wWindowFor(win);
1357 return NULL;
1363 static void
1364 handleKeyPress(XEvent *event)
1366 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1367 WWindow *wwin = scr->focused_window;
1368 int i;
1369 int modifiers;
1370 int command=-1, index;
1371 #ifdef KEEP_XKB_LOCK_STATUS
1372 XkbStateRec staterec;
1373 #endif /*KEEP_XKB_LOCK_STATUS*/
1375 /* ignore CapsLock */
1376 modifiers = event->xkey.state & ValidModMask;
1378 for (i=0; i<WKBD_LAST; i++) {
1379 if (wKeyBindings[i].keycode==0)
1380 continue;
1382 if (wKeyBindings[i].keycode==event->xkey.keycode
1383 && (/*wKeyBindings[i].modifier==0
1384 ||*/ wKeyBindings[i].modifier==modifiers)) {
1385 command = i;
1386 break;
1391 if (command < 0) {
1392 #ifdef LITE
1394 #if 0
1396 #endif
1397 #else
1398 if (!wRootMenuPerformShortcut(event)) {
1399 #endif
1400 static int dontLoop = 0;
1402 if (dontLoop > 10) {
1403 wwarning("problem with key event processing code");
1404 return;
1406 dontLoop++;
1407 /* if the focused window is an internal window, try redispatching
1408 * the event to the managed window, as it can be a WINGs window */
1409 if (wwin && wwin->flags.internal_window
1410 && wwin->client_leader!=None) {
1411 /* client_leader contains the WINGs toplevel */
1412 event->xany.window = wwin->client_leader;
1413 WMHandleEvent(event);
1415 dontLoop--;
1417 return;
1420 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1421 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1423 switch (command) {
1424 #ifndef LITE
1425 case WKBD_ROOTMENU:
1426 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1428 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1429 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1431 break;
1432 case WKBD_WINDOWLIST:
1434 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1435 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1437 break;
1438 #endif /* !LITE */
1439 case WKBD_WINDOWMENU:
1440 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1441 OpenWindowMenu(wwin, wwin->frame_x,
1442 wwin->frame_y+wwin->frame->top_width, True);
1443 break;
1444 case WKBD_MINIATURIZE:
1445 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1446 && !WFLAGP(wwin, no_miniaturizable)) {
1447 CloseWindowMenu(scr);
1449 if (wwin->protocols.MINIATURIZE_WINDOW)
1450 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1451 event->xbutton.time);
1452 else {
1453 wIconifyWindow(wwin);
1456 break;
1457 case WKBD_HIDE:
1458 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1459 WApplication *wapp = wApplicationOf(wwin->main_window);
1460 CloseWindowMenu(scr);
1462 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1463 wHideApplication(wapp);
1466 break;
1467 case WKBD_HIDE_OTHERS:
1468 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1469 CloseWindowMenu(scr);
1471 wHideOtherApplications(wwin);
1473 break;
1474 case WKBD_MAXIMIZE:
1475 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1476 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1478 CloseWindowMenu(scr);
1480 if (wwin->flags.maximized == newdir) {
1481 wUnmaximizeWindow(wwin);
1482 } else {
1483 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1486 break;
1487 case WKBD_VMAXIMIZE:
1488 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1489 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1491 CloseWindowMenu(scr);
1493 if (newdir) {
1494 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1495 } else {
1496 wUnmaximizeWindow(wwin);
1499 break;
1500 case WKBD_HMAXIMIZE:
1501 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1502 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1504 CloseWindowMenu(scr);
1506 if (newdir) {
1507 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1508 } else {
1509 wUnmaximizeWindow(wwin);
1512 break;
1513 case WKBD_RAISE:
1514 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1515 CloseWindowMenu(scr);
1517 wRaiseFrame(wwin->frame->core);
1519 break;
1520 case WKBD_LOWER:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1522 CloseWindowMenu(scr);
1524 wLowerFrame(wwin->frame->core);
1526 break;
1527 case WKBD_RAISELOWER:
1528 /* raise or lower the window under the pointer, not the
1529 * focused one
1531 wwin = windowUnderPointer(scr);
1532 if (wwin)
1533 wRaiseLowerFrame(wwin->frame->core);
1534 break;
1535 case WKBD_SHADE:
1536 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1537 if (wwin->flags.shaded)
1538 wUnshadeWindow(wwin);
1539 else
1540 wShadeWindow(wwin);
1542 break;
1543 case WKBD_MOVERESIZE:
1544 if (ISMAPPED(wwin) && ISFOCUSED(wwin) &&
1545 (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1546 CloseWindowMenu(scr);
1548 wKeyboardMoveResizeWindow(wwin);
1550 break;
1551 case WKBD_CLOSE:
1552 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1553 CloseWindowMenu(scr);
1554 if (wwin->protocols.DELETE_WINDOW)
1555 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1556 event->xkey.time);
1558 break;
1559 case WKBD_SELECT:
1560 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1561 wSelectWindow(wwin, !wwin->flags.selected);
1563 break;
1564 case WKBD_FOCUSNEXT:
1565 StartWindozeCycle(wwin, event, True);
1566 break;
1568 case WKBD_FOCUSPREV:
1569 StartWindozeCycle(wwin, event, False);
1570 break;
1572 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1573 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1574 i = (scr->current_workspace/10)*10 + wk - 1;\
1575 if (wPreferences.ws_advance || i<scr->workspace_count)\
1576 wWorkspaceChange(scr, i);\
1577 break
1578 #else
1579 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1580 i = (scr->current_workspace/10)*10 + wk - 1;\
1581 if (wPreferences.ws_advance || i<scr->workspace_count)\
1582 wWorkspaceChange(scr, i);\
1583 break
1584 #endif
1585 GOTOWORKS(1);
1586 GOTOWORKS(2);
1587 GOTOWORKS(3);
1588 GOTOWORKS(4);
1589 GOTOWORKS(5);
1590 GOTOWORKS(6);
1591 GOTOWORKS(7);
1592 GOTOWORKS(8);
1593 GOTOWORKS(9);
1594 GOTOWORKS(10);
1595 #undef GOTOWORKS
1596 case WKBD_NEXTWORKSPACE:
1597 wWorkspaceRelativeChange(scr, 1);
1598 break;
1599 case WKBD_PREVWORKSPACE:
1600 wWorkspaceRelativeChange(scr, -1);
1601 break;
1602 case WKBD_WINDOW1:
1603 case WKBD_WINDOW2:
1604 case WKBD_WINDOW3:
1605 case WKBD_WINDOW4:
1606 case WKBD_WINDOW5:
1607 case WKBD_WINDOW6:
1608 case WKBD_WINDOW7:
1609 case WKBD_WINDOW8:
1610 case WKBD_WINDOW9:
1611 case WKBD_WINDOW10:
1613 index = command-WKBD_WINDOW1;
1615 if (scr->shortcutWindows[index]) {
1616 WMArray *list = scr->shortcutWindows[index];
1617 int cw;
1618 int count = WMGetArrayItemCount(list);
1619 WWindow *twin;
1620 WMArrayIterator iter;
1621 WWindow *wwin;
1623 wUnselectWindows(scr);
1624 cw = scr->current_workspace;
1626 WM_ETARETI_ARRAY(list, wwin, iter) {
1627 if (count > 1)
1628 wWindowChangeWorkspace(wwin, cw);
1630 wMakeWindowVisible(wwin);
1632 if (count > 1)
1633 wSelectWindow(wwin, True);
1636 /* rotate the order of windows, to create a cycling effect */
1637 twin = WMGetFromArray(list, 0);
1638 WMDeleteFromArray(list, 0);
1639 WMAddToArray(list, twin);
1641 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1642 if (scr->shortcutWindows[index]) {
1643 WMFreeArray(scr->shortcutWindows[index]);
1644 scr->shortcutWindows[index] = NULL;
1647 if (wwin->flags.selected && scr->selected_windows) {
1648 scr->shortcutWindows[index] =
1649 WMDuplicateArray(scr->selected_windows);
1650 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1651 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1652 } else {
1653 scr->shortcutWindows[index] = WMCreateArray(4);
1654 WMAddToArray(scr->shortcutWindows[index], wwin);
1657 wSelectWindow(wwin, !wwin->flags.selected);
1658 XFlush(dpy);
1659 wusleep(3000);
1660 wSelectWindow(wwin, !wwin->flags.selected);
1661 XFlush(dpy);
1663 } else if (scr->selected_windows
1664 && WMGetArrayItemCount(scr->selected_windows)) {
1666 if (wwin->flags.selected && scr->selected_windows) {
1667 if (scr->shortcutWindows[index]) {
1668 WMFreeArray(scr->shortcutWindows[index]);
1670 scr->shortcutWindows[index] =
1671 WMDuplicateArray(scr->selected_windows);
1675 break;
1677 case WKBD_SWITCH_SCREEN:
1678 if (wScreenCount > 1) {
1679 WScreen *scr2;
1680 int i;
1682 /* find index of this screen */
1683 for (i = 0; i < wScreenCount; i++) {
1684 if (wScreenWithNumber(i) == scr)
1685 break;
1687 i++;
1688 if (i >= wScreenCount) {
1689 i = 0;
1691 scr2 = wScreenWithNumber(i);
1693 if (scr2) {
1694 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1695 scr2->scr_width/2, scr2->scr_height/2);
1698 break;
1700 case WKBD_NEXTWSLAYER:
1701 case WKBD_PREVWSLAYER:
1703 int row, column;
1705 row = scr->current_workspace/10;
1706 column = scr->current_workspace%10;
1708 if (command==WKBD_NEXTWSLAYER) {
1709 if ((row+1)*10 < scr->workspace_count)
1710 wWorkspaceChange(scr, column+(row+1)*10);
1711 } else {
1712 if (row > 0)
1713 wWorkspaceChange(scr, column+(row-1)*10);
1716 break;
1717 case WKBD_CLIPLOWER:
1718 if (!wPreferences.flags.noclip)
1719 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1720 break;
1721 case WKBD_CLIPRAISE:
1722 if (!wPreferences.flags.noclip)
1723 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1724 break;
1725 case WKBD_CLIPRAISELOWER:
1726 if (!wPreferences.flags.noclip)
1727 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1728 break;
1729 #ifdef KEEP_XKB_LOCK_STATUS
1730 case WKBD_TOGGLE:
1731 if(wPreferences.modelock) {
1732 /*toggle*/
1733 wwin = scr->focused_window;
1735 if (wwin && wwin->flags.mapped
1736 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1737 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1738 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1740 wwin->frame->languagemode = wwin->frame->last_languagemode;
1741 wwin->frame->last_languagemode = staterec.group;
1742 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1746 break;
1747 #endif /* KEEP_XKB_LOCK_STATUS */
1748 #ifdef VIRTUAL_DESKTOP
1749 case WKBD_VDESK_LEFT:
1750 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1751 break;
1753 case WKBD_VDESK_RIGHT:
1754 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1755 break;
1757 case WKBD_VDESK_UP:
1758 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1759 break;
1761 case WKBD_VDESK_DOWN:
1762 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1763 break;
1764 #endif
1770 static void
1771 handleMotionNotify(XEvent *event)
1773 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1775 if (wPreferences.scrollable_menus) {
1776 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1777 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1779 if (scr->flags.jump_back_pending ||
1780 p.x <= (rect.pos.x + 1) ||
1781 p.x >= (rect.pos.x + rect.size.width - 2) ||
1782 p.y <= (rect.pos.y + 1) ||
1783 p.y >= (rect.pos.y + rect.size.height - 2)) {
1784 WMenu *menu;
1785 #ifdef DEBUG
1786 printf("pointer at screen edge\n");
1787 #endif
1788 menu = wMenuUnderPointer(scr);
1789 if (menu!=NULL)
1790 wMenuScroll(menu, event);
1793 #if 0
1794 if (event->xmotion.subwindow == None)
1795 return;
1797 if (scr->scrolledFMaximize != None) {
1798 WWindow *twin;
1800 twin = wWindowFor(scr->scrolledFMaximize);
1801 if (twin && twin->frame_y ==) {
1805 scr->scrolledFMaximize = NULL;
1807 } else {
1809 /* scroll full maximized window */
1810 if (event->xmotion.y_root < 1
1811 || event->xmotion.y_root > scr->scr_height - 1) {
1813 wwin = wWindowFor(event->xmotion.subwindow);
1815 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1816 && WFLAGP(wwin, full_maximize)
1817 && event->xmotion.x_root >= wwin->frame_x
1818 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1820 if (HAS_BORDER(wwin)
1821 && wwin->frame_y <= - wwin->frame->top_width) {
1823 wWindowMove(wwin, wwin->frame_x, 0);
1824 wwin->flags.dragged_while_fmaximized = 0;
1826 } else if (HAS_RESIZEBAR(wwin)
1827 && wwin->frame_y + wwin->frame->core->height >=
1828 scr->scr_height + wwin->frame->bottom_width) {
1830 int y = scr->scr_height + wwin->frame->bottom_width;
1832 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1834 wWindowMove(wwin, wwin->frame_x, y);
1835 wwin->flags.dragged_while_fmaximized = 0;
1839 #endif
1843 static void
1844 handleVisibilityNotify(XEvent *event)
1846 WWindow *wwin;
1848 wwin = wWindowFor(event->xvisibility.window);
1849 if (!wwin)
1850 return;
1851 wwin->flags.obscured =
1852 (event->xvisibility.state == VisibilityFullyObscured);