reverted the last test commit (duh)
[wmaker-crm.git] / src / event.c
blob484de8165d9a89a1011103777dd11dcd31820524
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
70 /******** Global Variables **********/
71 extern XContext wWinContext;
73 extern Cursor wCursor[WCUR_LAST];
75 extern WShortKey wKeyBindings[WKBD_LAST];
76 extern int wScreenCount;
77 extern Time LastTimestamp;
78 extern Time LastFocusChange;
80 extern WPreferences wPreferences;
82 #define MOD_MASK wPreferences.modifier_mask
84 extern Atom _XA_WM_COLORMAP_NOTIFY;
86 extern Atom _XA_WM_CHANGE_STATE;
87 extern Atom _XA_WM_DELETE_WINDOW;
88 extern Atom _XA_GNUSTEP_WM_ATTR;
89 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
90 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
91 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
92 extern Atom _XA_WINDOWMAKER_COMMAND;
94 #ifdef OFFIX_DND
95 extern Atom _XA_DND_PROTOCOL;
96 #endif
99 #ifdef SHAPE
100 extern Bool wShapeSupported;
101 extern int wShapeEventBase;
102 #endif
104 #ifdef KEEP_XKB_LOCK_STATUS
105 extern int wXkbEventBase;
106 #endif
108 /* special flags */
109 extern char WDelayedActionSet;
112 /************ Local stuff ***********/
115 static void saveTimestamp(XEvent *event);
116 static void handleColormapNotify();
117 static void handleMapNotify(), handleUnmapNotify();
118 static void handleButtonPress(), handleExpose();
119 static void handleDestroyNotify();
120 static void handleConfigureRequest();
121 static void handleMapRequest();
122 static void handlePropertyNotify();
123 static void handleEnterNotify();
124 static void handleLeaveNotify();
125 static void handleExtensions();
126 static void handleClientMessage();
127 static void handleKeyPress();
128 static void handleFocusIn();
129 static void handleMotionNotify();
130 static void handleVisibilityNotify();
133 #ifdef SHAPE
134 static void handleShapeNotify();
135 #endif
137 /* called from the signal handler */
138 void NotifyDeadProcess(pid_t pid, unsigned char status);
140 /* real dead process handler */
141 static void handleDeadProcess(void *foo);
144 typedef struct DeadProcesses {
145 pid_t pid;
146 unsigned char exit_status;
147 } DeadProcesses;
149 /* stack of dead processes */
150 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
151 static int deadProcessPtr=0;
154 typedef struct DeathHandler {
155 WDeathHandler *callback;
156 pid_t pid;
157 void *client_data;
158 } DeathHandler;
160 static WMArray *deathHandlers=NULL;
164 WMagicNumber
165 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
167 DeathHandler *handler;
169 handler = malloc(sizeof(DeathHandler));
170 if (!handler)
171 return 0;
173 handler->pid = pid;
174 handler->callback = callback;
175 handler->client_data = cdata;
177 if (!deathHandlers)
178 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
180 WMAddToArray(deathHandlers, handler);
182 return handler;
187 void
188 wDeleteDeathHandler(WMagicNumber id)
190 DeathHandler *handler=(DeathHandler*)id;
192 if (!handler || !deathHandlers)
193 return;
195 /* array destructor will call wfree(handler) */
196 WMRemoveFromArray(deathHandlers, handler);
200 void
201 DispatchEvent(XEvent *event)
203 if (deathHandlers)
204 handleDeadProcess(NULL);
206 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
207 WCHANGE_STATE(WSTATE_EXITING);
208 /* received SIGTERM */
210 * WMHandleEvent() can't be called from anything
211 * executed inside here, or we can get in a infinite
212 * recursive loop.
214 Shutdown(WSExitMode);
216 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
217 WCHANGE_STATE(WSTATE_RESTARTING);
219 Shutdown(WSRestartPreparationMode);
220 /* received SIGHUP */
221 Restart(NULL, True);
222 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
223 WCHANGE_STATE(WSTATE_NORMAL);
224 wDefaultsCheckDomains("bla");
227 /* for the case that all that is wanted to be dispatched is
228 * the stuff above */
229 if (!event)
230 return;
232 saveTimestamp(event);
233 switch (event->type) {
234 case MapRequest:
235 handleMapRequest(event);
236 break;
238 case KeyPress:
239 handleKeyPress(event);
240 break;
242 case MotionNotify:
243 handleMotionNotify(event);
244 break;
246 case ConfigureRequest:
247 handleConfigureRequest(event);
248 break;
250 case DestroyNotify:
251 handleDestroyNotify(event);
252 break;
254 case MapNotify:
255 handleMapNotify(event);
256 break;
258 case UnmapNotify:
259 handleUnmapNotify(event);
260 break;
262 case ButtonPress:
263 handleButtonPress(event);
264 break;
266 case Expose:
267 handleExpose(event);
268 break;
270 case PropertyNotify:
271 handlePropertyNotify(event);
272 break;
274 case EnterNotify:
275 handleEnterNotify(event);
276 break;
278 case LeaveNotify:
279 handleLeaveNotify(event);
280 break;
282 case ClientMessage:
283 handleClientMessage(event);
284 break;
286 case ColormapNotify:
287 handleColormapNotify(event);
288 break;
290 case MappingNotify:
291 if (event->xmapping.request == MappingKeyboard
292 || event->xmapping.request == MappingModifier)
293 XRefreshKeyboardMapping(&event->xmapping);
294 break;
296 case FocusIn:
297 handleFocusIn(event);
298 break;
300 case VisibilityNotify:
301 handleVisibilityNotify(event);
302 break;
303 default:
304 handleExtensions(event);
305 break;
311 *----------------------------------------------------------------------
312 * EventLoop-
313 * Processes X and internal events indefinitely.
315 * Returns:
316 * Never returns
318 * Side effects:
319 * The LastTimestamp global variable is updated.
320 *----------------------------------------------------------------------
322 void
323 EventLoop()
325 XEvent event;
327 for(;;) {
328 WMNextEvent(dpy, &event);
329 WMHandleEvent(&event);
335 Bool
336 IsDoubleClick(WScreen *scr, XEvent *event)
338 if ((scr->last_click_time>0) &&
339 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
340 && (event->xbutton.button == scr->last_click_button)
341 && (event->xbutton.window == scr->last_click_window)) {
343 scr->flags.next_click_is_not_double = 1;
344 scr->last_click_time = 0;
345 scr->last_click_window = event->xbutton.window;
347 return True;
349 return False;
353 void
354 NotifyDeadProcess(pid_t pid, unsigned char status)
356 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
357 wwarning("stack overflow: too many dead processes");
358 return;
360 /* stack the process to be handled later,
361 * as this is called from the signal handler */
362 deadProcesses[deadProcessPtr].pid = pid;
363 deadProcesses[deadProcessPtr].exit_status = status;
364 deadProcessPtr++;
368 static void
369 handleDeadProcess(void *foo)
371 DeathHandler *tmp;
372 int i;
374 for (i=0; i<deadProcessPtr; i++) {
375 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
378 if (!deathHandlers) {
379 deadProcessPtr=0;
380 return;
383 /* get the pids on the queue and call handlers */
384 while (deadProcessPtr>0) {
385 deadProcessPtr--;
387 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
388 tmp = WMGetFromArray(deathHandlers, i);
389 if (!tmp)
390 continue;
392 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
393 (*tmp->callback)(tmp->pid,
394 deadProcesses[deadProcessPtr].exit_status,
395 tmp->client_data);
396 wDeleteDeathHandler(tmp);
403 static void
404 saveTimestamp(XEvent *event)
407 * Never save CurrentTime as LastTimestamp because CurrentTime
408 * it's not a real timestamp (it's the 0L constant)
411 switch (event->type) {
412 case ButtonRelease:
413 case ButtonPress:
414 LastTimestamp = event->xbutton.time;
415 break;
416 case KeyPress:
417 case KeyRelease:
418 LastTimestamp = event->xkey.time;
419 break;
420 case MotionNotify:
421 LastTimestamp = event->xmotion.time;
422 break;
423 case PropertyNotify:
424 LastTimestamp = event->xproperty.time;
425 break;
426 case EnterNotify:
427 case LeaveNotify:
428 LastTimestamp = event->xcrossing.time;
429 break;
430 case SelectionClear:
431 LastTimestamp = event->xselectionclear.time;
432 break;
433 case SelectionRequest:
434 LastTimestamp = event->xselectionrequest.time;
435 break;
436 case SelectionNotify:
437 LastTimestamp = event->xselection.time;
438 #ifdef XDND
439 wXDNDProcessSelection(event);
440 #endif
441 break;
446 static int
447 matchWindow(void *item, void *cdata)
449 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
453 static void
454 handleExtensions(XEvent *event)
456 #ifdef KEEP_XKB_LOCK_STATUS
457 XkbEvent *xkbevent;
458 xkbevent = (XkbEvent *)event;
459 #endif /*KEEP_XKB_LOCK_STATUS*/
460 #ifdef SHAPE
461 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
462 handleShapeNotify(event);
464 #endif
465 #ifdef KEEP_XKB_LOCK_STATUS
466 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
467 handleXkbIndicatorStateNotify(event);
469 #endif /*KEEP_XKB_LOCK_STATUS*/
473 static void
474 handleMapRequest(XEvent *ev)
476 WWindow *wwin;
477 WScreen *scr = NULL;
478 Window window = ev->xmaprequest.window;
480 #ifdef DEBUG
481 L("got map request for %x\n", (unsigned)window);
482 #endif
483 if ((wwin = wWindowFor(window))) {
484 if (wwin->flags.shaded) {
485 wUnshadeWindow(wwin);
487 /* deiconify window */
488 if (wwin->flags.miniaturized) {
489 wDeiconifyWindow(wwin);
490 } else if (wwin->flags.hidden) {
491 WApplication *wapp = wApplicationOf(wwin->main_window);
492 /* go to the last workspace that the user worked on the app */
493 if (wapp) {
494 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
496 wUnhideApplication(wapp, False, False);
498 return;
501 scr = wScreenForRootWindow(ev->xmaprequest.parent);
503 wwin = wManageWindow(scr, window);
506 * This is to let the Dock know that the application it launched
507 * has already been mapped (eg: it has finished launching).
508 * It is not necessary for normally docked apps, but is needed for
509 * apps that were forcedly docked (like with dockit).
511 if (scr->last_dock) {
512 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
513 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
514 else
515 wDockTrackWindowLaunch(scr->last_dock, window);
518 if (wwin) {
519 wClientSetState(wwin, NormalState, None);
520 if (wwin->flags.maximized) {
521 wMaximizeWindow(wwin, wwin->flags.maximized);
523 if (wwin->flags.shaded) {
524 wwin->flags.shaded = 0;
525 wwin->flags.skip_next_animation = 1;
526 wShadeWindow(wwin);
528 if (wwin->flags.miniaturized) {
529 wwin->flags.miniaturized = 0;
530 wwin->flags.skip_next_animation = 1;
531 wIconifyWindow(wwin);
533 if (wwin->flags.hidden) {
534 WApplication *wapp = wApplicationOf(wwin->main_window);
536 wwin->flags.hidden = 0;
537 wwin->flags.skip_next_animation = 1;
538 if (wapp) {
539 wHideApplication(wapp);
546 static void
547 handleDestroyNotify(XEvent *event)
549 WWindow *wwin;
550 WApplication *app;
551 Window window = event->xdestroywindow.window;
552 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
553 int index;
555 #ifdef DEBUG
556 L("got destroy notify");
557 #endif
558 wwin = wWindowFor(window);
559 if (wwin) {
560 wUnmanageWindow(wwin, False, True);
563 if (scr != NULL) {
564 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
565 (void*)window)) != WANotFound) {
566 WFakeGroupLeader *fPtr;
568 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
569 if (fPtr->retainCount > 0) {
570 fPtr->retainCount--;
571 if (fPtr->retainCount==0 && fPtr->leader!=None) {
572 XDestroyWindow(dpy, fPtr->leader);
573 fPtr->leader = None;
574 XFlush(dpy);
577 fPtr->origLeader = None;
581 app = wApplicationOf(window);
582 if (app) {
583 if (window == app->main_window) {
584 app->refcount = 0;
585 wwin = app->main_window_desc->screen_ptr->focused_window;
586 while (wwin) {
587 if (wwin->main_window == window) {
588 wwin->main_window = None;
590 wwin = wwin->prev;
593 wApplicationDestroy(app);
596 #ifdef KWM_HINTS
597 wKWMCheckDestroy(&event->xdestroywindow);
598 #endif
603 static void
604 handleExpose(XEvent *event)
606 WObjDescriptor *desc;
607 XEvent ev;
609 #ifdef DEBUG
610 L("got expose");
611 #endif
612 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
614 if (XFindContext(dpy, event->xexpose.window, wWinContext,
615 (XPointer *)&desc)==XCNOENT) {
616 return;
619 if (desc->handle_expose) {
620 (*desc->handle_expose)(desc, event);
624 static void
625 executeButtonAction(WScreen *scr, XEvent *event, int action)
627 switch(action) {
628 case WA_SELECT_WINDOWS:
629 wUnselectWindows(scr);
630 wSelectWindows(scr, event);
631 break;
632 case WA_OPEN_APPMENU:
633 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
634 /* ugly hack */
635 if (scr->root_menu) {
636 if (scr->root_menu->brother->flags.mapped)
637 event->xbutton.window = scr->root_menu->brother->frame->core->window;
638 else
639 event->xbutton.window = scr->root_menu->frame->core->window;
641 break;
642 case WA_OPEN_WINLISTMENU:
643 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
644 if (scr->switch_menu) {
645 if (scr->switch_menu->brother->flags.mapped)
646 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
647 else
648 event->xbutton.window = scr->switch_menu->frame->core->window;
650 break;
651 default:
652 break;
657 /* bindable */
658 static void
659 handleButtonPress(XEvent *event)
661 WObjDescriptor *desc;
662 WScreen *scr;
664 #ifdef DEBUG
665 L("got button press");
666 #endif
667 scr = wScreenForRootWindow(event->xbutton.root);
669 #ifdef BALLOON_TEXT
670 wBalloonHide(scr);
671 #endif
674 #ifndef LITE
675 if (event->xbutton.window==scr->root_win) {
676 if (event->xbutton.button==Button1 &&
677 wPreferences.mouse_button1!=WA_NONE) {
678 executeButtonAction(scr, event, wPreferences.mouse_button1);
679 } else if (event->xbutton.button==Button2 &&
680 wPreferences.mouse_button2!=WA_NONE) {
681 executeButtonAction(scr, event, wPreferences.mouse_button2);
682 } else if (event->xbutton.button==Button3 &&
683 wPreferences.mouse_button3!=WA_NONE) {
684 executeButtonAction(scr, event, wPreferences.mouse_button3);
685 } else if (event->xbutton.button==Button4 &&
686 wPreferences.mouse_wheel!=WA_NONE) {
687 wWorkspaceRelativeChange(scr, 1);
688 } else if (event->xbutton.button==Button5 &&
689 wPreferences.mouse_wheel!=WA_NONE) {
690 wWorkspaceRelativeChange(scr, -1);
692 #ifdef GNOME_STUFF
693 else if (wGNOMEProxyizeButtonEvent(scr, event))
694 return;
695 #endif
697 #endif /* !LITE */
699 desc = NULL;
700 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
701 (XPointer *)&desc)==XCNOENT) {
702 if (XFindContext(dpy, event->xbutton.window, wWinContext,
703 (XPointer *)&desc)==XCNOENT) {
704 return;
708 if (desc->parent_type == WCLASS_WINDOW) {
709 XSync(dpy, 0);
711 if (event->xbutton.state & MOD_MASK) {
712 XAllowEvents(dpy, AsyncPointer, CurrentTime);
715 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
716 if (wPreferences.ignore_focus_click) {
717 XAllowEvents(dpy, AsyncPointer, CurrentTime);
719 XAllowEvents(dpy, ReplayPointer, CurrentTime);
720 /* }*/
721 XSync(dpy, 0);
722 } else if (desc->parent_type == WCLASS_APPICON
723 || desc->parent_type == WCLASS_MINIWINDOW
724 || desc->parent_type == WCLASS_DOCK_ICON) {
725 if (event->xbutton.state & MOD_MASK) {
726 XSync(dpy, 0);
727 XAllowEvents(dpy, AsyncPointer, CurrentTime);
728 XSync(dpy, 0);
732 if (desc->handle_mousedown!=NULL) {
733 (*desc->handle_mousedown)(desc, event);
736 /* save double-click information */
737 if (scr->flags.next_click_is_not_double) {
738 scr->flags.next_click_is_not_double = 0;
739 } else {
740 scr->last_click_time = event->xbutton.time;
741 scr->last_click_button = event->xbutton.button;
742 scr->last_click_window = event->xbutton.window;
747 static void
748 handleMapNotify(XEvent *event)
750 WWindow *wwin;
751 #ifdef DEBUG
752 L("got map");
753 #endif
754 wwin = wWindowFor(event->xmap.event);
755 if (wwin && wwin->client_win == event->xmap.event) {
756 if (wwin->flags.miniaturized) {
757 wDeiconifyWindow(wwin);
758 } else {
759 XGrabServer(dpy);
760 wWindowMap(wwin);
761 wClientSetState(wwin, NormalState, None);
762 XUngrabServer(dpy);
768 static void
769 handleUnmapNotify(XEvent *event)
771 WWindow *wwin;
772 XEvent ev;
773 Bool withdraw = False;
774 #ifdef DEBUG
775 L("got unmap");
776 #endif
777 /* only process windows with StructureNotify selected
778 * (ignore SubstructureNotify) */
779 wwin = wWindowFor(event->xunmap.window);
780 if (!wwin)
781 return;
783 /* whether the event is a Withdrawal request */
784 if (event->xunmap.event == wwin->screen_ptr->root_win
785 && event->xunmap.send_event)
786 withdraw = True;
788 if (wwin->client_win != event->xunmap.event && !withdraw)
789 return;
791 if (!wwin->flags.mapped && !withdraw
792 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
793 && !wwin->flags.miniaturized && !wwin->flags.hidden)
794 return;
796 XGrabServer(dpy);
797 XUnmapWindow(dpy, wwin->frame->core->window);
798 wwin->flags.mapped = 0;
799 XSync(dpy, 0);
800 /* check if the window was destroyed */
801 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
802 DispatchEvent(&ev);
803 } else {
804 Bool reparented = False;
806 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
807 reparented = True;
809 /* withdraw window */
810 wwin->flags.mapped = 0;
811 if (!reparented)
812 wClientSetState(wwin, WithdrawnState, None);
814 /* if the window was reparented, do not reparent it back to the
815 * root window */
816 wUnmanageWindow(wwin, !reparented, False);
818 XUngrabServer(dpy);
822 static void
823 handleConfigureRequest(XEvent *event)
825 WWindow *wwin;
826 #ifdef DEBUG
827 L("got configure request");
828 #endif
829 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
831 * Configure request for unmapped window
833 wClientConfigure(NULL, &(event->xconfigurerequest));
834 } else {
835 wClientConfigure(wwin, &(event->xconfigurerequest));
840 static void
841 handlePropertyNotify(XEvent *event)
843 WWindow *wwin;
844 WApplication *wapp;
845 Window jr;
846 int ji;
847 unsigned int ju;
848 WScreen *scr;
849 #ifdef DEBUG
850 L("got property notify");
851 #endif
852 if ((wwin=wWindowFor(event->xproperty.window))) {
853 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
854 &ju, &ju, &ju, &ju)) {
855 return;
857 wClientCheckProperty(wwin, &event->xproperty);
859 wapp = wApplicationOf(event->xproperty.window);
860 if (wapp) {
861 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
864 scr = wScreenForWindow(event->xproperty.window);
865 if (scr && scr->root_win == event->xproperty.window) {
866 #ifdef KWM_HINTS
867 wKWMCheckRootHintChange(scr, &event->xproperty);
868 #endif
873 static void
874 handleClientMessage(XEvent *event)
876 WWindow *wwin;
877 WObjDescriptor *desc;
878 #ifdef DEBUG
879 L("got client message");
880 #endif
881 /* handle transition from Normal to Iconic state */
882 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
883 && event->xclient.format == 32
884 && event->xclient.data.l[0] == IconicState) {
886 wwin = wWindowFor(event->xclient.window);
887 if (!wwin) return;
888 if (!wwin->flags.miniaturized)
889 wIconifyWindow(wwin);
890 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
891 && event->xclient.format == 32) {
892 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
894 if (!scr)
895 return;
897 if (event->xclient.data.l[1] == 1) { /* starting */
898 wColormapAllowClientInstallation(scr, True);
899 } else { /* stopping */
900 wColormapAllowClientInstallation(scr, False);
902 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
904 wDefaultsCheckDomains("bla");
906 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
907 WApplication *wapp;
908 int done=0;
909 wapp = wApplicationOf(event->xclient.window);
910 if (wapp) {
911 switch (event->xclient.data.l[0]) {
912 case WMFHideOtherApplications:
913 wHideOtherApplications(wapp->main_window_desc);
914 done = 1;
915 break;
917 case WMFHideApplication:
918 wHideApplication(wapp);
919 done = 1;
920 break;
923 if (!done) {
924 wwin = wWindowFor(event->xclient.window);
925 if (wwin) {
926 switch (event->xclient.data.l[0]) {
927 case WMFHideOtherApplications:
928 wHideOtherApplications(wwin);
929 break;
931 case WMFHideApplication:
932 wHideApplication(wApplicationOf(wwin->main_window));
933 break;
937 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
938 wwin = wWindowFor(event->xclient.window);
939 if (!wwin) return;
940 switch (event->xclient.data.l[0]) {
941 case GSWindowLevelAttr:
943 int level = (int)event->xclient.data.l[1];
945 if (WINDOW_LEVEL(wwin) != level) {
946 ChangeStackingLevel(wwin->frame->core, level);
949 break;
951 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
952 wwin = wWindowFor(event->xclient.window);
953 if (!wwin) return;
954 switch (event->xclient.data.l[0]) {
955 case WMTitleBarNormal:
956 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
957 break;
958 case WMTitleBarMain:
959 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
960 break;
961 case WMTitleBarKey:
962 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
963 break;
965 #ifdef GNOME_STUFF
966 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
967 /* do nothing */
968 #endif /* GNOME_STUFF */
969 #ifdef KWM_HINTS
970 } else if (wKWMProcessClientMessage(&event->xclient)) {
971 /* do nothing */
972 #endif /* KWM_HINTS */
973 #ifdef XDND
974 } else if (wXDNDProcessClientMessage(&event->xclient)) {
975 /* do nothing */
976 #endif /* XDND */
977 #ifdef OFFIX_DND
978 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
979 WScreen *scr = wScreenForWindow(event->xclient.window);
980 if (scr && wDockReceiveDNDDrop(scr,event))
981 goto redirect_message;
982 #endif /* OFFIX_DND */
983 } else {
984 #ifdef OFFIX_DND
985 redirect_message:
986 #endif
988 * Non-standard thing, but needed by OffiX DND.
989 * For when the icon frame gets a ClientMessage
990 * that should have gone to the icon_window.
992 if (XFindContext(dpy, event->xbutton.window, wWinContext,
993 (XPointer *)&desc)!=XCNOENT) {
994 struct WIcon *icon=NULL;
996 if (desc->parent_type == WCLASS_MINIWINDOW) {
997 icon = (WIcon*)desc->parent;
998 } else if (desc->parent_type == WCLASS_DOCK_ICON
999 || desc->parent_type == WCLASS_APPICON) {
1000 icon = ((WAppIcon*)desc->parent)->icon;
1002 if (icon && (wwin=icon->owner)) {
1003 if (wwin->client_win!=event->xclient.window) {
1004 event->xclient.window = wwin->client_win;
1005 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1006 event);
1014 static void
1015 raiseWindow(WScreen *scr)
1017 WWindow *wwin;
1019 scr->autoRaiseTimer = NULL;
1021 wwin = wWindowFor(scr->autoRaiseWindow);
1022 if (!wwin)
1023 return;
1025 if (!wwin->flags.destroyed && wwin->flags.focused) {
1026 wRaiseFrame(wwin->frame->core);
1027 /* this is needed or a race condition will occur */
1028 XSync(dpy, False);
1033 static void
1034 handleEnterNotify(XEvent *event)
1036 WWindow *wwin;
1037 WObjDescriptor *desc = NULL;
1038 XEvent ev;
1039 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1040 #ifdef DEBUG
1041 L("got enter notify");
1042 #endif
1044 #ifdef VIRTUAL_DESKTOP
1045 /* TODO: acceleration code */
1046 if (wPreferences.vedge_thickness) {
1047 int x,y;
1048 if (event->xcrossing.window == scr->virtual_edge_r) {
1049 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1050 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1051 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1052 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1053 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1054 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1055 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1056 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1057 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1058 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1059 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1060 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1061 printf("enter bottom\n");
1062 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1063 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1064 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1067 #endif
1069 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1070 &ev)) {
1071 /* already left the window... */
1072 saveTimestamp(&ev);
1073 if (ev.xcrossing.mode==event->xcrossing.mode
1074 && ev.xcrossing.detail==event->xcrossing.detail) {
1075 return;
1079 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1080 (XPointer *)&desc)!=XCNOENT) {
1081 if(desc->handle_enternotify)
1082 (*desc->handle_enternotify)(desc, event);
1085 /* enter to window */
1086 wwin = wWindowFor(event->xcrossing.window);
1087 if (!wwin) {
1088 if (wPreferences.colormap_mode==WCM_POINTER) {
1089 wColormapInstallForWindow(scr, NULL);
1091 if (scr->autoRaiseTimer
1092 && event->xcrossing.root==event->xcrossing.window) {
1093 WMDeleteTimerHandler(scr->autoRaiseTimer);
1094 scr->autoRaiseTimer = NULL;
1096 } else {
1097 /* set auto raise timer even if in focus-follows-mouse mode
1098 * and the event is for the frame window, even if the window
1099 * has focus already. useful if you move the pointer from a focused
1100 * window to the root window and back pretty fast
1102 * set focus if in focus-follows-mouse mode and the event
1103 * is for the frame window and window doesn't have focus yet */
1104 if (wPreferences.focus_mode==WKF_SLOPPY
1105 && wwin->frame->core->window==event->xcrossing.window
1106 && !scr->flags.doing_alt_tab) {
1108 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1109 wSetFocusTo(scr, wwin);
1111 if (scr->autoRaiseTimer)
1112 WMDeleteTimerHandler(scr->autoRaiseTimer);
1113 scr->autoRaiseTimer = NULL;
1115 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1116 scr->autoRaiseWindow = wwin->frame->core->window;
1117 scr->autoRaiseTimer
1118 = WMAddTimerHandler(wPreferences.raise_delay,
1119 (WMCallback*)raiseWindow, scr);
1122 /* Install colormap for window, if the colormap installation mode
1123 * is colormap_follows_mouse */
1124 if (wPreferences.colormap_mode==WCM_POINTER) {
1125 if (wwin->client_win==event->xcrossing.window)
1126 wColormapInstallForWindow(scr, wwin);
1127 else
1128 wColormapInstallForWindow(scr, NULL);
1132 /* a little kluge to hide the clip balloon */
1133 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1134 if (!desc) {
1135 XUnmapWindow(dpy, scr->clip_balloon);
1136 scr->flags.clip_balloon_mapped = 0;
1137 } else {
1138 if (desc->parent_type!=WCLASS_DOCK_ICON
1139 || scr->clip_icon != desc->parent) {
1140 XUnmapWindow(dpy, scr->clip_balloon);
1141 scr->flags.clip_balloon_mapped = 0;
1146 if (event->xcrossing.window == event->xcrossing.root
1147 && event->xcrossing.detail == NotifyNormal
1148 && event->xcrossing.detail != NotifyInferior
1149 && wPreferences.focus_mode != WKF_CLICK) {
1151 wSetFocusTo(scr, scr->focused_window);
1154 #ifdef BALLOON_TEXT
1155 wBalloonEnteredObject(scr, desc);
1156 #endif
1160 static void
1161 handleLeaveNotify(XEvent *event)
1163 WObjDescriptor *desc = NULL;
1165 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1166 (XPointer *)&desc)!=XCNOENT) {
1167 if(desc->handle_leavenotify)
1168 (*desc->handle_leavenotify)(desc, event);
1173 #ifdef SHAPE
1174 static void
1175 handleShapeNotify(XEvent *event)
1177 XShapeEvent *shev = (XShapeEvent*)event;
1178 WWindow *wwin;
1179 XEvent ev;
1180 #ifdef DEBUG
1181 L("got shape notify");
1182 #endif
1183 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1184 XShapeEvent *sev = (XShapeEvent*)&ev;
1186 if (sev->kind == ShapeBounding) {
1187 if (sev->shaped == shev->shaped) {
1188 *shev = *sev;
1189 } else {
1190 XPutBackEvent(dpy, &ev);
1191 break;
1196 wwin = wWindowFor(shev->window);
1197 if (!wwin || shev->kind != ShapeBounding)
1198 return;
1200 if (!shev->shaped && wwin->flags.shaped) {
1202 wwin->flags.shaped = 0;
1203 wWindowClearShape(wwin);
1205 } else if (shev->shaped) {
1207 wwin->flags.shaped = 1;
1208 wWindowSetShape(wwin);
1211 #endif /* SHAPE */
1213 #ifdef KEEP_XKB_LOCK_STATUS
1214 /* please help ]d if you know what to do */
1215 handleXkbIndicatorStateNotify(XEvent *event)
1217 WWindow *wwin;
1218 WScreen *scr;
1219 XkbStateRec staterec;
1220 int i;
1222 for (i=0; i<wScreenCount; i++) {
1223 scr = wScreenWithNumber(i);
1224 wwin = scr->focused_window;
1225 if (wwin && wwin->flags.focused) {
1226 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1227 if (wwin->frame->languagemode != staterec.group) {
1228 wwin->frame->last_languagemode = wwin->frame->languagemode;
1229 wwin->frame->languagemode = staterec.group;
1231 #ifdef XKB_BUTTON_HINT
1232 if (wwin->frame->titlebar) {
1233 wFrameWindowPaint(wwin->frame);
1235 #endif
1239 #endif /*KEEP_XKB_LOCK_STATUS*/
1241 static void
1242 handleColormapNotify(XEvent *event)
1244 WWindow *wwin;
1245 WScreen *scr;
1246 Bool reinstall = False;
1248 wwin = wWindowFor(event->xcolormap.window);
1249 if (!wwin)
1250 return;
1252 scr = wwin->screen_ptr;
1254 do {
1255 if (wwin) {
1256 if (event->xcolormap.new) {
1257 XWindowAttributes attr;
1259 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1261 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1262 scr->current_colormap = attr.colormap;
1264 reinstall = True;
1265 } else if (event->xcolormap.state == ColormapUninstalled &&
1266 scr->current_colormap == event->xcolormap.colormap) {
1268 /* some bastard app (like XV) removed our colormap */
1270 * can't enforce or things like xscreensaver wont work
1271 * reinstall = True;
1273 } else if (event->xcolormap.state == ColormapInstalled &&
1274 scr->current_colormap == event->xcolormap.colormap) {
1276 /* someone has put our colormap back */
1277 reinstall = False;
1280 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1281 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1283 if (reinstall && scr->current_colormap!=None) {
1284 if (!scr->flags.colormap_stuff_blocked)
1285 XInstallColormap(dpy, scr->current_colormap);
1291 static void
1292 handleFocusIn(XEvent *event)
1294 WWindow *wwin;
1297 * For applications that like stealing the focus.
1299 while (XCheckTypedEvent(dpy, FocusIn, event));
1300 saveTimestamp(event);
1301 if (event->xfocus.mode == NotifyUngrab
1302 || event->xfocus.mode == NotifyGrab
1303 || event->xfocus.detail > NotifyNonlinearVirtual) {
1304 return;
1307 wwin = wWindowFor(event->xfocus.window);
1308 if (wwin && !wwin->flags.focused) {
1309 if (wwin->flags.mapped)
1310 wSetFocusTo(wwin->screen_ptr, wwin);
1311 else
1312 wSetFocusTo(wwin->screen_ptr, NULL);
1313 } else if (!wwin) {
1314 WScreen *scr = wScreenForWindow(event->xfocus.window);
1315 if (scr)
1316 wSetFocusTo(scr, NULL);
1321 static WWindow*
1322 windowUnderPointer(WScreen *scr)
1324 unsigned int mask;
1325 int foo;
1326 Window bar, win;
1328 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1329 &mask))
1330 return wWindowFor(win);
1331 return NULL;
1337 static void
1338 handleKeyPress(XEvent *event)
1340 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1341 WWindow *wwin = scr->focused_window;
1342 int i;
1343 int modifiers;
1344 int command=-1, index;
1345 #ifdef KEEP_XKB_LOCK_STATUS
1346 XkbStateRec staterec;
1347 #endif /*KEEP_XKB_LOCK_STATUS*/
1349 /* ignore CapsLock */
1350 modifiers = event->xkey.state & ValidModMask;
1352 for (i=0; i<WKBD_LAST; i++) {
1353 if (wKeyBindings[i].keycode==0)
1354 continue;
1356 if (wKeyBindings[i].keycode==event->xkey.keycode
1357 && (/*wKeyBindings[i].modifier==0
1358 ||*/ wKeyBindings[i].modifier==modifiers)) {
1359 command = i;
1360 break;
1365 if (command < 0) {
1366 #ifdef LITE
1368 #if 0
1370 #endif
1371 #else
1372 if (!wRootMenuPerformShortcut(event)) {
1373 #endif
1374 static int dontLoop = 0;
1376 if (dontLoop > 10) {
1377 wwarning("problem with key event processing code");
1378 return;
1380 dontLoop++;
1381 /* if the focused window is an internal window, try redispatching
1382 * the event to the managed window, as it can be a WINGs window */
1383 if (wwin && wwin->flags.internal_window
1384 && wwin->client_leader!=None) {
1385 /* client_leader contains the WINGs toplevel */
1386 event->xany.window = wwin->client_leader;
1387 WMHandleEvent(event);
1389 dontLoop--;
1391 return;
1394 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1395 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1397 switch (command) {
1398 #ifndef LITE
1399 case WKBD_ROOTMENU:
1400 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1402 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1403 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1405 break;
1406 case WKBD_WINDOWLIST:
1408 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1409 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1411 break;
1412 #endif /* !LITE */
1413 case WKBD_WINDOWMENU:
1414 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1415 OpenWindowMenu(wwin, wwin->frame_x,
1416 wwin->frame_y+wwin->frame->top_width, True);
1417 break;
1418 case WKBD_MINIATURIZE:
1419 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1420 && !WFLAGP(wwin, no_miniaturizable)) {
1421 CloseWindowMenu(scr);
1423 if (wwin->protocols.MINIATURIZE_WINDOW)
1424 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1425 event->xbutton.time);
1426 else {
1427 wIconifyWindow(wwin);
1430 break;
1431 case WKBD_HIDE:
1432 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1433 WApplication *wapp = wApplicationOf(wwin->main_window);
1434 CloseWindowMenu(scr);
1436 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1437 wHideApplication(wapp);
1440 break;
1441 case WKBD_HIDE_OTHERS:
1442 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1443 CloseWindowMenu(scr);
1445 wHideOtherApplications(wwin);
1447 break;
1448 case WKBD_MAXIMIZE:
1449 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1450 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1452 CloseWindowMenu(scr);
1454 if (wwin->flags.maximized == newdir) {
1455 wUnmaximizeWindow(wwin);
1456 } else {
1457 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1460 break;
1461 case WKBD_VMAXIMIZE:
1462 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1463 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1465 CloseWindowMenu(scr);
1467 if (newdir) {
1468 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1469 } else {
1470 wUnmaximizeWindow(wwin);
1473 break;
1474 case WKBD_HMAXIMIZE:
1475 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1476 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1478 CloseWindowMenu(scr);
1480 if (newdir) {
1481 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1482 } else {
1483 wUnmaximizeWindow(wwin);
1486 break;
1487 case WKBD_RAISE:
1488 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1489 CloseWindowMenu(scr);
1491 wRaiseFrame(wwin->frame->core);
1493 break;
1494 case WKBD_LOWER:
1495 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1496 CloseWindowMenu(scr);
1498 wLowerFrame(wwin->frame->core);
1500 break;
1501 case WKBD_RAISELOWER:
1502 /* raise or lower the window under the pointer, not the
1503 * focused one
1505 wwin = windowUnderPointer(scr);
1506 if (wwin)
1507 wRaiseLowerFrame(wwin->frame->core);
1508 break;
1509 case WKBD_SHADE:
1510 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1511 if (wwin->flags.shaded)
1512 wUnshadeWindow(wwin);
1513 else
1514 wShadeWindow(wwin);
1516 break;
1517 case WKBD_MOVERESIZE:
1518 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1519 CloseWindowMenu(scr);
1521 wKeyboardMoveResizeWindow(wwin);
1523 break;
1524 case WKBD_CLOSE:
1525 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1526 CloseWindowMenu(scr);
1527 if (wwin->protocols.DELETE_WINDOW)
1528 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1529 event->xkey.time);
1531 break;
1532 case WKBD_SELECT:
1533 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1534 wSelectWindow(wwin, !wwin->flags.selected);
1536 break;
1537 case WKBD_FOCUSNEXT:
1538 StartWindozeCycle(wwin, event, True);
1539 break;
1541 case WKBD_FOCUSPREV:
1542 StartWindozeCycle(wwin, event, False);
1543 break;
1545 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1546 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1547 i = (scr->current_workspace/10)*10 + wk - 1;\
1548 if (wPreferences.ws_advance || i<scr->workspace_count)\
1549 wWorkspaceChange(scr, i);\
1550 break
1551 #else
1552 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1553 i = (scr->current_workspace/10)*10 + wk - 1;\
1554 if (wPreferences.ws_advance || i<scr->workspace_count)\
1555 wWorkspaceChange(scr, i);\
1556 break
1557 #endif
1558 GOTOWORKS(1);
1559 GOTOWORKS(2);
1560 GOTOWORKS(3);
1561 GOTOWORKS(4);
1562 GOTOWORKS(5);
1563 GOTOWORKS(6);
1564 GOTOWORKS(7);
1565 GOTOWORKS(8);
1566 GOTOWORKS(9);
1567 GOTOWORKS(10);
1568 #undef GOTOWORKS
1569 case WKBD_NEXTWORKSPACE:
1570 wWorkspaceRelativeChange(scr, 1);
1571 break;
1572 case WKBD_PREVWORKSPACE:
1573 wWorkspaceRelativeChange(scr, -1);
1574 break;
1575 case WKBD_WINDOW1:
1576 case WKBD_WINDOW2:
1577 case WKBD_WINDOW3:
1578 case WKBD_WINDOW4:
1579 case WKBD_WINDOW5:
1580 case WKBD_WINDOW6:
1581 case WKBD_WINDOW7:
1582 case WKBD_WINDOW8:
1583 case WKBD_WINDOW9:
1584 case WKBD_WINDOW10:
1586 index = command-WKBD_WINDOW1;
1588 if (scr->shortcutWindows[index]) {
1589 WMArray *list = scr->shortcutWindows[index];
1590 int cw;
1591 int count = WMGetArrayItemCount(list);
1592 WWindow *twin;
1593 WMArrayIterator iter;
1594 WWindow *wwin;
1596 wUnselectWindows(scr);
1597 cw = scr->current_workspace;
1599 WM_ETARETI_ARRAY(list, wwin, iter) {
1600 if (count > 1)
1601 wWindowChangeWorkspace(wwin, cw);
1603 wMakeWindowVisible(wwin);
1605 if (count > 1)
1606 wSelectWindow(wwin, True);
1609 /* rotate the order of windows, to create a cycling effect */
1610 twin = WMGetFromArray(list, 0);
1611 WMDeleteFromArray(list, 0);
1612 WMAddToArray(list, twin);
1614 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1615 if (scr->shortcutWindows[index]) {
1616 WMFreeArray(scr->shortcutWindows[index]);
1617 scr->shortcutWindows[index] = NULL;
1620 if (wwin->flags.selected && scr->selected_windows) {
1621 scr->shortcutWindows[index] =
1622 WMDuplicateArray(scr->selected_windows);
1623 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1624 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1625 } else {
1626 scr->shortcutWindows[index] = WMCreateArray(4);
1627 WMAddToArray(scr->shortcutWindows[index], wwin);
1630 wSelectWindow(wwin, !wwin->flags.selected);
1631 XFlush(dpy);
1632 wusleep(3000);
1633 wSelectWindow(wwin, !wwin->flags.selected);
1634 XFlush(dpy);
1636 } else if (scr->selected_windows
1637 && WMGetArrayItemCount(scr->selected_windows)) {
1639 if (wwin->flags.selected && scr->selected_windows) {
1640 if (scr->shortcutWindows[index]) {
1641 WMFreeArray(scr->shortcutWindows[index]);
1643 scr->shortcutWindows[index] =
1644 WMDuplicateArray(scr->selected_windows);
1648 break;
1650 case WKBD_SWITCH_SCREEN:
1651 if (wScreenCount > 1) {
1652 WScreen *scr2;
1653 int i;
1655 /* find index of this screen */
1656 for (i = 0; i < wScreenCount; i++) {
1657 if (wScreenWithNumber(i) == scr)
1658 break;
1660 i++;
1661 if (i >= wScreenCount) {
1662 i = 0;
1664 scr2 = wScreenWithNumber(i);
1666 if (scr2) {
1667 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1668 scr2->scr_width/2, scr2->scr_height/2);
1671 break;
1673 case WKBD_NEXTWSLAYER:
1674 case WKBD_PREVWSLAYER:
1676 int row, column;
1678 row = scr->current_workspace/10;
1679 column = scr->current_workspace%10;
1681 if (command==WKBD_NEXTWSLAYER) {
1682 if ((row+1)*10 < scr->workspace_count)
1683 wWorkspaceChange(scr, column+(row+1)*10);
1684 } else {
1685 if (row > 0)
1686 wWorkspaceChange(scr, column+(row-1)*10);
1689 break;
1690 case WKBD_CLIPLOWER:
1691 if (!wPreferences.flags.noclip)
1692 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1693 break;
1694 case WKBD_CLIPRAISE:
1695 if (!wPreferences.flags.noclip)
1696 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1697 break;
1698 case WKBD_CLIPRAISELOWER:
1699 if (!wPreferences.flags.noclip)
1700 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1701 break;
1702 #ifdef KEEP_XKB_LOCK_STATUS
1703 case WKBD_TOGGLE:
1704 if(wPreferences.modelock) {
1705 /*toggle*/
1706 wwin = scr->focused_window;
1708 if (wwin && wwin->flags.mapped
1709 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1710 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1711 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1713 wwin->frame->languagemode = wwin->frame->last_languagemode;
1714 wwin->frame->last_languagemode = staterec.group;
1715 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1719 break;
1720 #endif /* KEEP_XKB_LOCK_STATUS */
1726 static void
1727 handleMotionNotify(XEvent *event)
1729 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1731 if (wPreferences.scrollable_menus) {
1732 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1733 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1735 if (scr->flags.jump_back_pending ||
1736 p.x <= (rect.pos.x + 1) ||
1737 p.x >= (rect.pos.x + rect.size.width - 2) ||
1738 p.y <= (rect.pos.y + 1) ||
1739 p.y >= (rect.pos.y + rect.size.height - 2)) {
1740 WMenu *menu;
1741 #ifdef DEBUG
1742 L("pointer at screen edge");
1743 #endif
1744 menu = wMenuUnderPointer(scr);
1745 if (menu!=NULL)
1746 wMenuScroll(menu, event);
1749 #if 0
1750 if (event->xmotion.subwindow == None)
1751 return;
1753 if (scr->scrolledFMaximize != None) {
1754 WWindow *twin;
1756 twin = wWindowFor(scr->scrolledFMaximize);
1757 if (twin && twin->frame_y ==) {
1761 scr->scrolledFMaximize = NULL;
1763 } else {
1765 /* scroll full maximized window */
1766 if (event->xmotion.y_root < 1
1767 || event->xmotion.y_root > scr->scr_height - 1) {
1769 wwin = wWindowFor(event->xmotion.subwindow);
1771 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1772 && WFLAGP(wwin, full_maximize)
1773 && event->xmotion.x_root >= wwin->frame_x
1774 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1776 if (!WFLAGP(wwin, no_titlebar)
1777 && wwin->frame_y <= - wwin->frame->top_width) {
1779 wWindowMove(wwin, wwin->frame_x, 0);
1780 wwin->flags.dragged_while_fmaximized = 0;
1782 } else if (!WFLAGP(wwin, no_resizebar)
1783 && wwin->frame_y + wwin->frame->core->height >=
1784 scr->scr_height + wwin->frame->bottom_width) {
1786 int y = scr->scr_height + wwin->frame->bottom_width;
1788 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1790 wWindowMove(wwin, wwin->frame_x, y);
1791 wwin->flags.dragged_while_fmaximized = 0;
1795 #endif
1799 static void
1800 handleVisibilityNotify(XEvent *event)
1802 WWindow *wwin;
1804 wwin = wWindowFor(event->xvisibility.window);
1805 if (!wwin)
1806 return;
1807 wwin->flags.obscured =
1808 (event->xvisibility.state == VisibilityFullyObscured);