- improved behaviour for the shared appicon thing.
[wmaker-crm.git] / src / event.c
blob5bfec568532cbf70fa6df8a5de01a620189c4131
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #ifdef SHAPE
37 # include <X11/extensions/shape.h>
38 #endif
39 #ifdef XDND
40 #include "xdnd.h"
41 #endif
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
48 #include "window.h"
49 #include "actions.h"
50 #include "client.h"
51 #include "funcs.h"
52 #include "keybind.h"
53 #include "application.h"
54 #include "stacking.h"
55 #include "defaults.h"
56 #include "workspace.h"
57 #include "dock.h"
58 #include "framewin.h"
59 #include "properties.h"
60 #include "balloon.h"
62 #ifdef GNOME_STUFF
63 # include "gnome.h"
64 #endif
65 #ifdef KWM_HINTS
66 # include "kwm.h"
67 #endif
69 /******** Global Variables **********/
70 extern XContext wWinContext;
72 extern Cursor wCursor[WCUR_LAST];
74 extern WShortKey wKeyBindings[WKBD_LAST];
75 extern int wScreenCount;
76 extern Time LastTimestamp;
77 extern Time LastFocusChange;
79 extern WPreferences wPreferences;
81 #define MOD_MASK wPreferences.modifier_mask
83 extern Atom _XA_WM_COLORMAP_NOTIFY;
85 extern Atom _XA_WM_CHANGE_STATE;
86 extern Atom _XA_WM_DELETE_WINDOW;
87 extern Atom _XA_GNUSTEP_WM_ATTR;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
89 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
90 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
91 extern Atom _XA_WINDOWMAKER_COMMAND;
93 #ifdef OFFIX_DND
94 extern Atom _XA_DND_PROTOCOL;
95 #endif
98 #ifdef SHAPE
99 extern Bool wShapeSupported;
100 extern int wShapeEventBase;
101 #endif
103 #ifdef KEEP_XKB_LOCK_STATUS
104 extern int wXkbEventBase;
105 #endif
107 /* special flags */
108 extern char WDelayedActionSet;
111 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent *event);
115 static void handleColormapNotify();
116 static void handleMapNotify(), handleUnmapNotify();
117 static void handleButtonPress(), handleExpose();
118 static void handleDestroyNotify();
119 static void handleConfigureRequest();
120 static void handleMapRequest();
121 static void handlePropertyNotify();
122 static void handleEnterNotify();
123 static void handleLeaveNotify();
124 static void handleExtensions();
125 static void handleClientMessage();
126 static void handleKeyPress();
127 static void handleFocusIn();
128 static void handleMotionNotify();
129 static void handleVisibilityNotify();
132 #ifdef SHAPE
133 static void handleShapeNotify();
134 #endif
136 /* called from the signal handler */
137 void NotifyDeadProcess(pid_t pid, unsigned char status);
139 /* real dead process handler */
140 static void handleDeadProcess(void *foo);
143 typedef struct DeadProcesses {
144 pid_t pid;
145 unsigned char exit_status;
146 } DeadProcesses;
148 /* stack of dead processes */
149 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
150 static int deadProcessPtr=0;
153 typedef struct DeathHandler {
154 WDeathHandler *callback;
155 pid_t pid;
156 void *client_data;
157 } DeathHandler;
159 static WMArray *deathHandlers=NULL;
163 WMagicNumber
164 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
166 DeathHandler *handler;
168 handler = malloc(sizeof(DeathHandler));
169 if (!handler)
170 return 0;
172 handler->pid = pid;
173 handler->callback = callback;
174 handler->client_data = cdata;
176 if (!deathHandlers)
177 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
179 WMAddToArray(deathHandlers, handler);
181 return handler;
186 void
187 wDeleteDeathHandler(WMagicNumber id)
189 DeathHandler *handler=(DeathHandler*)id;
191 if (!handler || !deathHandlers)
192 return;
194 /* array destructor will call wfree(handler) */
195 WMRemoveFromArray(deathHandlers, handler);
199 void
200 DispatchEvent(XEvent *event)
202 if (deathHandlers)
203 handleDeadProcess(NULL);
205 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
206 WCHANGE_STATE(WSTATE_EXITING);
207 /* received SIGTERM */
209 * WMHandleEvent() can't be called from anything
210 * executed inside here, or we can get in a infinite
211 * recursive loop.
213 Shutdown(WSExitMode);
215 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
216 WCHANGE_STATE(WSTATE_RESTARTING);
218 Shutdown(WSRestartPreparationMode);
219 /* received SIGHUP */
220 Restart(NULL, True);
221 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
222 WCHANGE_STATE(WSTATE_NORMAL);
223 wDefaultsCheckDomains("bla");
226 /* for the case that all that is wanted to be dispatched is
227 * the stuff above */
228 if (!event)
229 return;
231 saveTimestamp(event);
232 switch (event->type) {
233 case MapRequest:
234 handleMapRequest(event);
235 break;
237 case KeyPress:
238 handleKeyPress(event);
239 break;
241 case MotionNotify:
242 handleMotionNotify(event);
243 break;
245 case ConfigureRequest:
246 handleConfigureRequest(event);
247 break;
249 case DestroyNotify:
250 handleDestroyNotify(event);
251 break;
253 case MapNotify:
254 handleMapNotify(event);
255 break;
257 case UnmapNotify:
258 handleUnmapNotify(event);
259 break;
261 case ButtonPress:
262 handleButtonPress(event);
263 break;
265 case Expose:
266 handleExpose(event);
267 break;
269 case PropertyNotify:
270 handlePropertyNotify(event);
271 break;
273 case EnterNotify:
274 handleEnterNotify(event);
275 break;
277 case LeaveNotify:
278 handleLeaveNotify(event);
279 break;
281 case ClientMessage:
282 handleClientMessage(event);
283 break;
285 case ColormapNotify:
286 handleColormapNotify(event);
287 break;
289 case MappingNotify:
290 if (event->xmapping.request == MappingKeyboard
291 || event->xmapping.request == MappingModifier)
292 XRefreshKeyboardMapping(&event->xmapping);
293 break;
295 case FocusIn:
296 handleFocusIn(event);
297 break;
299 case VisibilityNotify:
300 handleVisibilityNotify(event);
301 break;
302 default:
303 handleExtensions(event);
304 break;
310 *----------------------------------------------------------------------
311 * EventLoop-
312 * Processes X and internal events indefinitely.
314 * Returns:
315 * Never returns
317 * Side effects:
318 * The LastTimestamp global variable is updated.
319 *----------------------------------------------------------------------
321 void
322 EventLoop()
324 XEvent event;
326 for(;;) {
327 WMNextEvent(dpy, &event);
328 WMHandleEvent(&event);
334 Bool
335 IsDoubleClick(WScreen *scr, XEvent *event)
337 if ((scr->last_click_time>0) &&
338 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
339 && (event->xbutton.button == scr->last_click_button)
340 && (event->xbutton.window == scr->last_click_window)) {
342 scr->flags.next_click_is_not_double = 1;
343 scr->last_click_time = 0;
344 scr->last_click_window = event->xbutton.window;
346 return True;
348 return False;
352 void
353 NotifyDeadProcess(pid_t pid, unsigned char status)
355 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
356 wwarning("stack overflow: too many dead processes");
357 return;
359 /* stack the process to be handled later,
360 * as this is called from the signal handler */
361 deadProcesses[deadProcessPtr].pid = pid;
362 deadProcesses[deadProcessPtr].exit_status = status;
363 deadProcessPtr++;
367 static void
368 handleDeadProcess(void *foo)
370 DeathHandler *tmp;
371 int i;
373 for (i=0; i<deadProcessPtr; i++) {
374 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
377 if (!deathHandlers) {
378 deadProcessPtr=0;
379 return;
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr>0) {
384 deadProcessPtr--;
386 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
387 tmp = WMGetFromArray(deathHandlers, i);
388 if (!tmp)
389 continue;
391 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
392 (*tmp->callback)(tmp->pid,
393 deadProcesses[deadProcessPtr].exit_status,
394 tmp->client_data);
395 wDeleteDeathHandler(tmp);
402 static void
403 saveTimestamp(XEvent *event)
405 LastTimestamp = CurrentTime;
407 switch (event->type) {
408 case ButtonRelease:
409 case ButtonPress:
410 LastTimestamp = event->xbutton.time;
411 break;
412 case KeyPress:
413 case KeyRelease:
414 LastTimestamp = event->xkey.time;
415 break;
416 case MotionNotify:
417 LastTimestamp = event->xmotion.time;
418 break;
419 case PropertyNotify:
420 LastTimestamp = event->xproperty.time;
421 break;
422 case EnterNotify:
423 case LeaveNotify:
424 LastTimestamp = event->xcrossing.time;
425 break;
426 case SelectionClear:
427 LastTimestamp = event->xselectionclear.time;
428 break;
429 case SelectionRequest:
430 LastTimestamp = event->xselectionrequest.time;
431 break;
432 case SelectionNotify:
433 LastTimestamp = event->xselection.time;
434 #ifdef XDND
435 wXDNDProcessSelection(event);
436 #endif
437 break;
442 static int
443 matchWindow(void *item, void *cdata)
445 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
449 static void
450 handleExtensions(XEvent *event)
452 #ifdef KEEP_XKB_LOCK_STATUS
453 XkbEvent *xkbevent;
454 xkbevent = (XkbEvent *)event;
455 #endif /*KEEP_XKB_LOCK_STATUS*/
456 #ifdef SHAPE
457 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
458 handleShapeNotify(event);
460 #endif
461 #ifdef KEEP_XKB_LOCK_STATUS
462 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
463 handleXkbIndicatorStateNotify(event);
465 #endif /*KEEP_XKB_LOCK_STATUS*/
469 static void
470 handleMapRequest(XEvent *ev)
472 WWindow *wwin;
473 WScreen *scr = NULL;
474 Window window = ev->xmaprequest.window;
476 #ifdef DEBUG
477 L("got map request for %x\n", (unsigned)window);
478 #endif
479 if ((wwin = wWindowFor(window))) {
480 if (wwin->flags.shaded) {
481 wUnshadeWindow(wwin);
483 /* deiconify window */
484 if (wwin->flags.miniaturized) {
485 wDeiconifyWindow(wwin);
486 } else if (wwin->flags.hidden) {
487 WApplication *wapp = wApplicationOf(wwin->main_window);
488 /* go to the last workspace that the user worked on the app */
489 if (wapp) {
490 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
492 wUnhideApplication(wapp, False, False);
494 return;
497 scr = wScreenForRootWindow(ev->xmaprequest.parent);
499 wwin = wManageWindow(scr, window);
502 * This is to let the Dock know that the application it launched
503 * has already been mapped (eg: it has finished launching).
504 * It is not necessary for normally docked apps, but is needed for
505 * apps that were forcedly docked (like with dockit).
507 if (scr->last_dock) {
508 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
509 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
510 else
511 wDockTrackWindowLaunch(scr->last_dock, window);
514 if (wwin) {
515 wClientSetState(wwin, NormalState, None);
516 if (wwin->flags.maximized) {
517 wMaximizeWindow(wwin, wwin->flags.maximized);
519 if (wwin->flags.shaded) {
520 wwin->flags.shaded = 0;
521 wwin->flags.skip_next_animation = 1;
522 wShadeWindow(wwin);
524 if (wwin->flags.miniaturized) {
525 wwin->flags.miniaturized = 0;
526 wwin->flags.skip_next_animation = 1;
527 wIconifyWindow(wwin);
529 if (wwin->flags.hidden) {
530 WApplication *wapp = wApplicationOf(wwin->main_window);
532 wwin->flags.hidden = 0;
533 wwin->flags.skip_next_animation = 1;
534 if (wapp) {
535 wHideApplication(wapp);
542 static void
543 handleDestroyNotify(XEvent *event)
545 WWindow *wwin;
546 WApplication *app;
547 Window window = event->xdestroywindow.window;
548 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
549 int index;
551 #ifdef DEBUG
552 L("got destroy notify");
553 #endif
554 wwin = wWindowFor(window);
555 if (wwin) {
556 wUnmanageWindow(wwin, False, True);
559 index = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void*)window);
560 if (index != WANotFound) {
561 WFakeGroupLeader *fPtr;
563 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
564 if (fPtr->retainCount > 0) {
565 fPtr->retainCount--;
566 if (fPtr->retainCount==0 && fPtr->leader!=None) {
567 XDestroyWindow(dpy, fPtr->leader);
568 fPtr->leader = None;
569 XFlush(dpy);
572 fPtr->origLeader = None;
576 app = wApplicationOf(window);
577 if (app) {
578 if (window == app->main_window) {
579 app->refcount = 0;
580 wwin = app->main_window_desc->screen_ptr->focused_window;
581 while (wwin) {
582 if (wwin->main_window == window) {
583 wwin->main_window = None;
585 wwin = wwin->prev;
588 wApplicationDestroy(app);
591 #ifdef KWM_HINTS
592 wKWMCheckDestroy(&event->xdestroywindow);
593 #endif
598 static void
599 handleExpose(XEvent *event)
601 WObjDescriptor *desc;
602 XEvent ev;
604 #ifdef DEBUG
605 L("got expose");
606 #endif
607 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
609 if (XFindContext(dpy, event->xexpose.window, wWinContext,
610 (XPointer *)&desc)==XCNOENT) {
611 return;
614 if (desc->handle_expose) {
615 (*desc->handle_expose)(desc, event);
619 static void
620 executeButtonAction(WScreen *scr, XEvent *event, int action)
622 switch(action) {
623 case WA_SELECT_WINDOWS:
624 wUnselectWindows(scr);
625 wSelectWindows(scr, event);
626 break;
627 case WA_OPEN_APPMENU:
628 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
629 /* ugly hack */
630 if (scr->root_menu) {
631 if (scr->root_menu->brother->flags.mapped)
632 event->xbutton.window = scr->root_menu->brother->frame->core->window;
633 else
634 event->xbutton.window = scr->root_menu->frame->core->window;
636 break;
637 case WA_OPEN_WINLISTMENU:
638 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
639 if (scr->switch_menu) {
640 if (scr->switch_menu->brother->flags.mapped)
641 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
642 else
643 event->xbutton.window = scr->switch_menu->frame->core->window;
645 break;
646 default:
647 break;
652 /* bindable */
653 static void
654 handleButtonPress(XEvent *event)
656 WObjDescriptor *desc;
657 WScreen *scr;
659 #ifdef DEBUG
660 L("got button press");
661 #endif
662 scr = wScreenForRootWindow(event->xbutton.root);
664 #ifdef BALLOON_TEXT
665 wBalloonHide(scr);
666 #endif
669 #ifndef LITE
670 if (event->xbutton.window==scr->root_win) {
671 if (event->xbutton.button==Button1 &&
672 wPreferences.mouse_button1!=WA_NONE) {
673 executeButtonAction(scr, event, wPreferences.mouse_button1);
674 } else if (event->xbutton.button==Button2 &&
675 wPreferences.mouse_button2!=WA_NONE) {
676 executeButtonAction(scr, event, wPreferences.mouse_button2);
677 } else if (event->xbutton.button==Button3 &&
678 wPreferences.mouse_button3!=WA_NONE) {
679 executeButtonAction(scr, event, wPreferences.mouse_button3);
680 } else if (event->xbutton.button==Button4 &&
681 wPreferences.mouse_wheel!=WA_NONE) {
682 wWorkspaceRelativeChange(scr, 1);
683 } else if (event->xbutton.button==Button5 &&
684 wPreferences.mouse_wheel!=WA_NONE) {
685 wWorkspaceRelativeChange(scr, -1);
687 #ifdef GNOME_STUFF
688 else if (wGNOMEProxyizeButtonEvent(scr, event))
689 return;
690 #endif
692 #endif /* !LITE */
694 desc = NULL;
695 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
696 (XPointer *)&desc)==XCNOENT) {
697 if (XFindContext(dpy, event->xbutton.window, wWinContext,
698 (XPointer *)&desc)==XCNOENT) {
699 return;
703 if (desc->parent_type == WCLASS_WINDOW) {
704 XSync(dpy, 0);
706 if (event->xbutton.state & MOD_MASK) {
707 XAllowEvents(dpy, AsyncPointer, CurrentTime);
710 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
711 if (wPreferences.ignore_focus_click) {
712 XAllowEvents(dpy, AsyncPointer, CurrentTime);
714 XAllowEvents(dpy, ReplayPointer, CurrentTime);
715 /* }*/
716 XSync(dpy, 0);
717 } else if (desc->parent_type == WCLASS_APPICON
718 || desc->parent_type == WCLASS_MINIWINDOW
719 || desc->parent_type == WCLASS_DOCK_ICON) {
720 if (event->xbutton.state & MOD_MASK) {
721 XSync(dpy, 0);
722 XAllowEvents(dpy, AsyncPointer, CurrentTime);
723 XSync(dpy, 0);
727 if (desc->handle_mousedown!=NULL) {
728 (*desc->handle_mousedown)(desc, event);
731 /* save double-click information */
732 if (scr->flags.next_click_is_not_double) {
733 scr->flags.next_click_is_not_double = 0;
734 } else {
735 scr->last_click_time = event->xbutton.time;
736 scr->last_click_button = event->xbutton.button;
737 scr->last_click_window = event->xbutton.window;
742 static void
743 handleMapNotify(XEvent *event)
745 WWindow *wwin;
746 #ifdef DEBUG
747 L("got map");
748 #endif
749 wwin = wWindowFor(event->xmap.event);
750 if (wwin && wwin->client_win == event->xmap.event) {
751 if (wwin->flags.miniaturized) {
752 wDeiconifyWindow(wwin);
753 } else {
754 XGrabServer(dpy);
755 wWindowMap(wwin);
756 wClientSetState(wwin, NormalState, None);
757 XUngrabServer(dpy);
763 static void
764 handleUnmapNotify(XEvent *event)
766 WWindow *wwin;
767 XEvent ev;
768 Bool withdraw = False;
769 #ifdef DEBUG
770 L("got unmap");
771 #endif
772 /* only process windows with StructureNotify selected
773 * (ignore SubstructureNotify) */
774 wwin = wWindowFor(event->xunmap.window);
775 if (!wwin)
776 return;
778 /* whether the event is a Withdrawal request */
779 if (event->xunmap.event == wwin->screen_ptr->root_win
780 && event->xunmap.send_event)
781 withdraw = True;
783 if (wwin->client_win != event->xunmap.event && !withdraw)
784 return;
786 if (!wwin->flags.mapped && !withdraw
787 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
788 && !wwin->flags.miniaturized && !wwin->flags.hidden)
789 return;
791 XGrabServer(dpy);
792 XUnmapWindow(dpy, wwin->frame->core->window);
793 wwin->flags.mapped = 0;
794 XSync(dpy, 0);
795 /* check if the window was destroyed */
796 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
797 DispatchEvent(&ev);
798 } else {
799 Bool reparented = False;
801 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
802 reparented = True;
804 /* withdraw window */
805 wwin->flags.mapped = 0;
806 if (!reparented)
807 wClientSetState(wwin, WithdrawnState, None);
809 /* if the window was reparented, do not reparent it back to the
810 * root window */
811 wUnmanageWindow(wwin, !reparented, False);
813 XUngrabServer(dpy);
817 static void
818 handleConfigureRequest(XEvent *event)
820 WWindow *wwin;
821 #ifdef DEBUG
822 L("got configure request");
823 #endif
824 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
826 * Configure request for unmapped window
828 wClientConfigure(NULL, &(event->xconfigurerequest));
829 } else {
830 wClientConfigure(wwin, &(event->xconfigurerequest));
835 static void
836 handlePropertyNotify(XEvent *event)
838 WWindow *wwin;
839 WApplication *wapp;
840 Window jr;
841 int ji;
842 unsigned int ju;
843 WScreen *scr;
844 #ifdef DEBUG
845 L("got property notify");
846 #endif
847 if ((wwin=wWindowFor(event->xproperty.window))) {
848 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
849 &ju, &ju, &ju, &ju)) {
850 return;
852 wClientCheckProperty(wwin, &event->xproperty);
854 wapp = wApplicationOf(event->xproperty.window);
855 if (wapp) {
856 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
859 scr = wScreenForWindow(event->xproperty.window);
860 if (scr && scr->root_win == event->xproperty.window) {
861 #ifdef KWM_HINTS
862 wKWMCheckRootHintChange(scr, &event->xproperty);
863 #endif
868 static void
869 handleClientMessage(XEvent *event)
871 WWindow *wwin;
872 WObjDescriptor *desc;
873 #ifdef DEBUG
874 L("got client message");
875 #endif
876 /* handle transition from Normal to Iconic state */
877 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
878 && event->xclient.format == 32
879 && event->xclient.data.l[0] == IconicState) {
881 wwin = wWindowFor(event->xclient.window);
882 if (!wwin) return;
883 if (!wwin->flags.miniaturized)
884 wIconifyWindow(wwin);
885 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
886 && event->xclient.format == 32) {
887 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
889 if (!scr)
890 return;
892 if (event->xclient.data.l[1] == 1) { /* starting */
893 wColormapAllowClientInstallation(scr, True);
894 } else { /* stopping */
895 wColormapAllowClientInstallation(scr, False);
897 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
899 wDefaultsCheckDomains("bla");
901 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
902 WApplication *wapp;
903 int done=0;
904 wapp = wApplicationOf(event->xclient.window);
905 if (wapp) {
906 switch (event->xclient.data.l[0]) {
907 case WMFHideOtherApplications:
908 wHideOtherApplications(wapp->main_window_desc);
909 done = 1;
910 break;
912 case WMFHideApplication:
913 wHideApplication(wapp);
914 done = 1;
915 break;
918 if (!done) {
919 wwin = wWindowFor(event->xclient.window);
920 if (wwin) {
921 switch (event->xclient.data.l[0]) {
922 case WMFHideOtherApplications:
923 wHideOtherApplications(wwin);
924 break;
926 case WMFHideApplication:
927 wHideApplication(wApplicationOf(wwin->main_window));
928 break;
932 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
933 wwin = wWindowFor(event->xclient.window);
934 if (!wwin) return;
935 switch (event->xclient.data.l[0]) {
936 case GSWindowLevelAttr:
938 int level = (int)event->xclient.data.l[1];
940 if (WINDOW_LEVEL(wwin) != level) {
941 ChangeStackingLevel(wwin->frame->core, level);
944 break;
946 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
947 wwin = wWindowFor(event->xclient.window);
948 if (!wwin) return;
949 switch (event->xclient.data.l[0]) {
950 case WMTitleBarNormal:
951 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
952 break;
953 case WMTitleBarMain:
954 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
955 break;
956 case WMTitleBarKey:
957 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
958 break;
960 #ifdef GNOME_STUFF
961 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
962 /* do nothing */
963 #endif /* GNOME_STUFF */
964 #ifdef KWM_HINTS
965 } else if (wKWMProcessClientMessage(&event->xclient)) {
966 /* do nothing */
967 #endif /* KWM_HINTS */
968 #ifdef XDND
969 } else if (wXDNDProcessClientMessage(&event->xclient)) {
970 /* do nothing */
971 #endif /* XDND */
972 #ifdef OFFIX_DND
973 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
974 WScreen *scr = wScreenForWindow(event->xclient.window);
975 if (scr && wDockReceiveDNDDrop(scr,event))
976 goto redirect_message;
977 #endif /* OFFIX_DND */
978 } else {
979 #ifdef OFFIX_DND
980 redirect_message:
981 #endif
983 * Non-standard thing, but needed by OffiX DND.
984 * For when the icon frame gets a ClientMessage
985 * that should have gone to the icon_window.
987 if (XFindContext(dpy, event->xbutton.window, wWinContext,
988 (XPointer *)&desc)!=XCNOENT) {
989 struct WIcon *icon=NULL;
991 if (desc->parent_type == WCLASS_MINIWINDOW) {
992 icon = (WIcon*)desc->parent;
993 } else if (desc->parent_type == WCLASS_DOCK_ICON
994 || desc->parent_type == WCLASS_APPICON) {
995 icon = ((WAppIcon*)desc->parent)->icon;
997 if (icon && (wwin=icon->owner)) {
998 if (wwin->client_win!=event->xclient.window) {
999 event->xclient.window = wwin->client_win;
1000 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1001 event);
1009 static void
1010 raiseWindow(WScreen *scr)
1012 WWindow *wwin;
1014 scr->autoRaiseTimer = NULL;
1016 wwin = wWindowFor(scr->autoRaiseWindow);
1017 if (!wwin)
1018 return;
1020 if (!wwin->flags.destroyed && wwin->flags.focused) {
1021 wRaiseFrame(wwin->frame->core);
1022 /* this is needed or a race condition will occur */
1023 XSync(dpy, False);
1028 static void
1029 handleEnterNotify(XEvent *event)
1031 WWindow *wwin;
1032 WObjDescriptor *desc = NULL;
1033 XEvent ev;
1034 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1035 #ifdef DEBUG
1036 L("got enter notify");
1037 #endif
1039 #ifdef VIRTUAL_DESKTOP
1040 /* TODO: acceleration code */
1041 if (wPreferences.vedge_thickness) {
1042 int x,y;
1043 if (event->xcrossing.window == scr->virtual_edge_r) {
1044 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1045 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1046 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1047 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1048 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1049 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1050 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1051 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1052 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1053 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1054 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1055 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1056 printf("enter bottom\n");
1057 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1058 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1059 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1062 #endif
1064 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1065 &ev)) {
1066 /* already left the window... */
1067 saveTimestamp(&ev);
1068 if (ev.xcrossing.mode==event->xcrossing.mode
1069 && ev.xcrossing.detail==event->xcrossing.detail) {
1070 return;
1074 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1075 (XPointer *)&desc)!=XCNOENT) {
1076 if(desc->handle_enternotify)
1077 (*desc->handle_enternotify)(desc, event);
1080 /* enter to window */
1081 wwin = wWindowFor(event->xcrossing.window);
1082 if (!wwin) {
1083 if (wPreferences.colormap_mode==WCM_POINTER) {
1084 wColormapInstallForWindow(scr, NULL);
1086 if (scr->autoRaiseTimer
1087 && event->xcrossing.root==event->xcrossing.window) {
1088 WMDeleteTimerHandler(scr->autoRaiseTimer);
1089 scr->autoRaiseTimer = NULL;
1091 } else {
1092 /* set auto raise timer even if in focus-follows-mouse mode
1093 * and the event is for the frame window, even if the window
1094 * has focus already. useful if you move the pointer from a focused
1095 * window to the root window and back pretty fast
1097 * set focus if in focus-follows-mouse mode and the event
1098 * is for the frame window and window doesn't have focus yet */
1099 if (wPreferences.focus_mode==WKF_SLOPPY
1100 && wwin->frame->core->window==event->xcrossing.window
1101 && !scr->flags.doing_alt_tab) {
1103 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1104 wSetFocusTo(scr, wwin);
1106 if (scr->autoRaiseTimer)
1107 WMDeleteTimerHandler(scr->autoRaiseTimer);
1108 scr->autoRaiseTimer = NULL;
1110 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1111 scr->autoRaiseWindow = wwin->frame->core->window;
1112 scr->autoRaiseTimer
1113 = WMAddTimerHandler(wPreferences.raise_delay,
1114 (WMCallback*)raiseWindow, scr);
1117 /* Install colormap for window, if the colormap installation mode
1118 * is colormap_follows_mouse */
1119 if (wPreferences.colormap_mode==WCM_POINTER) {
1120 if (wwin->client_win==event->xcrossing.window)
1121 wColormapInstallForWindow(scr, wwin);
1122 else
1123 wColormapInstallForWindow(scr, NULL);
1127 /* a little kluge to hide the clip balloon */
1128 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1129 if (!desc) {
1130 XUnmapWindow(dpy, scr->clip_balloon);
1131 scr->flags.clip_balloon_mapped = 0;
1132 } else {
1133 if (desc->parent_type!=WCLASS_DOCK_ICON
1134 || scr->clip_icon != desc->parent) {
1135 XUnmapWindow(dpy, scr->clip_balloon);
1136 scr->flags.clip_balloon_mapped = 0;
1141 if (event->xcrossing.window == event->xcrossing.root
1142 && event->xcrossing.detail == NotifyNormal
1143 && event->xcrossing.detail != NotifyInferior
1144 && wPreferences.focus_mode != WKF_CLICK) {
1146 wSetFocusTo(scr, scr->focused_window);
1149 #ifdef BALLOON_TEXT
1150 wBalloonEnteredObject(scr, desc);
1151 #endif
1155 static void
1156 handleLeaveNotify(XEvent *event)
1158 WObjDescriptor *desc = NULL;
1160 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1161 (XPointer *)&desc)!=XCNOENT) {
1162 if(desc->handle_leavenotify)
1163 (*desc->handle_leavenotify)(desc, event);
1165 if (event->xcrossing.window == event->xcrossing.root
1166 && event->xcrossing.mode == NotifyNormal
1167 && event->xcrossing.detail != NotifyInferior
1168 && wPreferences.focus_mode != WKF_CLICK) {
1170 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1172 wSetFocusTo(scr, NULL);
1177 #ifdef SHAPE
1178 static void
1179 handleShapeNotify(XEvent *event)
1181 XShapeEvent *shev = (XShapeEvent*)event;
1182 WWindow *wwin;
1183 XEvent ev;
1184 #ifdef DEBUG
1185 L("got shape notify");
1186 #endif
1187 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1188 XShapeEvent *sev = (XShapeEvent*)&ev;
1190 if (sev->kind == ShapeBounding) {
1191 if (sev->shaped == shev->shaped) {
1192 *shev = *sev;
1193 } else {
1194 XPutBackEvent(dpy, &ev);
1195 break;
1200 wwin = wWindowFor(shev->window);
1201 if (!wwin || shev->kind != ShapeBounding)
1202 return;
1204 if (!shev->shaped && wwin->flags.shaped) {
1206 wwin->flags.shaped = 0;
1207 wWindowClearShape(wwin);
1209 } else if (shev->shaped) {
1211 wwin->flags.shaped = 1;
1212 wWindowSetShape(wwin);
1215 #endif /* SHAPE */
1217 #ifdef KEEP_XKB_LOCK_STATUS
1218 /* please help ]d if you know what to do */
1219 handleXkbIndicatorStateNotify(XEvent *event)
1221 WWindow *wwin;
1222 WScreen *scr;
1223 XkbStateRec staterec;
1224 int i;
1226 for (i=0; i<wScreenCount; i++) {
1227 scr = wScreenWithNumber(i);
1228 wwin = scr->focused_window;
1229 if (wwin && wwin->flags.focused) {
1230 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1231 if (wwin->frame->languagemode != staterec.group) {
1232 wwin->frame->last_languagemode = wwin->frame->languagemode;
1233 wwin->frame->languagemode = staterec.group;
1235 #ifdef XKB_BUTTON_HINT
1236 if (wwin->frame->titlebar) {
1237 wFrameWindowPaint(wwin->frame);
1239 #endif
1243 #endif /*KEEP_XKB_LOCK_STATUS*/
1245 static void
1246 handleColormapNotify(XEvent *event)
1248 WWindow *wwin;
1249 WScreen *scr;
1250 Bool reinstall = False;
1252 wwin = wWindowFor(event->xcolormap.window);
1253 if (!wwin)
1254 return;
1256 scr = wwin->screen_ptr;
1258 do {
1259 if (wwin) {
1260 if (event->xcolormap.new) {
1261 XWindowAttributes attr;
1263 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1265 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1266 scr->current_colormap = attr.colormap;
1268 reinstall = True;
1269 } else if (event->xcolormap.state == ColormapUninstalled &&
1270 scr->current_colormap == event->xcolormap.colormap) {
1272 /* some bastard app (like XV) removed our colormap */
1274 * can't enforce or things like xscreensaver wont work
1275 * reinstall = True;
1277 } else if (event->xcolormap.state == ColormapInstalled &&
1278 scr->current_colormap == event->xcolormap.colormap) {
1280 /* someone has put our colormap back */
1281 reinstall = False;
1284 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1285 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1287 if (reinstall && scr->current_colormap!=None) {
1288 if (!scr->flags.colormap_stuff_blocked)
1289 XInstallColormap(dpy, scr->current_colormap);
1295 static void
1296 handleFocusIn(XEvent *event)
1298 WWindow *wwin;
1301 * For applications that like stealing the focus.
1303 while (XCheckTypedEvent(dpy, FocusIn, event));
1304 saveTimestamp(event);
1305 if (event->xfocus.mode == NotifyUngrab
1306 || event->xfocus.mode == NotifyGrab
1307 || event->xfocus.detail > NotifyNonlinearVirtual) {
1308 return;
1311 wwin = wWindowFor(event->xfocus.window);
1312 if (wwin && !wwin->flags.focused) {
1313 if (wwin->flags.mapped)
1314 wSetFocusTo(wwin->screen_ptr, wwin);
1315 else
1316 wSetFocusTo(wwin->screen_ptr, NULL);
1317 } else if (!wwin) {
1318 WScreen *scr = wScreenForWindow(event->xfocus.window);
1319 if (scr)
1320 wSetFocusTo(scr, NULL);
1325 static WWindow*
1326 windowUnderPointer(WScreen *scr)
1328 unsigned int mask;
1329 int foo;
1330 Window bar, win;
1332 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1333 &mask))
1334 return wWindowFor(win);
1335 return NULL;
1341 static void
1342 handleKeyPress(XEvent *event)
1344 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1345 WWindow *wwin = scr->focused_window;
1346 int i;
1347 int modifiers;
1348 int command=-1, index;
1349 #ifdef KEEP_XKB_LOCK_STATUS
1350 XkbStateRec staterec;
1351 #endif /*KEEP_XKB_LOCK_STATUS*/
1353 /* ignore CapsLock */
1354 modifiers = event->xkey.state & ValidModMask;
1356 for (i=0; i<WKBD_LAST; i++) {
1357 if (wKeyBindings[i].keycode==0)
1358 continue;
1360 if (wKeyBindings[i].keycode==event->xkey.keycode
1361 && (/*wKeyBindings[i].modifier==0
1362 ||*/ wKeyBindings[i].modifier==modifiers)) {
1363 command = i;
1364 break;
1369 if (command < 0) {
1370 #ifdef LITE
1372 #if 0
1374 #endif
1375 #else
1376 if (!wRootMenuPerformShortcut(event)) {
1377 #endif
1378 static int dontLoop = 0;
1380 if (dontLoop > 10) {
1381 wwarning("problem with key event processing code");
1382 return;
1384 dontLoop++;
1385 /* if the focused window is an internal window, try redispatching
1386 * the event to the managed window, as it can be a WINGs window */
1387 if (wwin && wwin->flags.internal_window
1388 && wwin->client_leader!=None) {
1389 /* client_leader contains the WINGs toplevel */
1390 event->xany.window = wwin->client_leader;
1391 WMHandleEvent(event);
1393 dontLoop--;
1395 return;
1398 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1399 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1401 switch (command) {
1402 #ifndef LITE
1403 case WKBD_ROOTMENU:
1404 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1405 OpenRootMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1406 break;
1407 case WKBD_WINDOWLIST:
1408 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1409 break;
1410 #endif /* !LITE */
1411 case WKBD_WINDOWMENU:
1412 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1413 OpenWindowMenu(wwin, wwin->frame_x,
1414 wwin->frame_y+wwin->frame->top_width, True);
1415 break;
1416 case WKBD_MINIATURIZE:
1417 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1418 && !WFLAGP(wwin, no_miniaturizable)) {
1419 CloseWindowMenu(scr);
1421 if (wwin->protocols.MINIATURIZE_WINDOW)
1422 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1423 event->xbutton.time);
1424 else {
1425 wIconifyWindow(wwin);
1428 break;
1429 case WKBD_HIDE:
1430 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1431 WApplication *wapp = wApplicationOf(wwin->main_window);
1432 CloseWindowMenu(scr);
1434 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1435 wHideApplication(wapp);
1438 break;
1439 case WKBD_MAXIMIZE:
1440 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1441 CloseWindowMenu(scr);
1443 if (wwin->flags.maximized) {
1444 wUnmaximizeWindow(wwin);
1445 } else {
1446 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1449 break;
1450 case WKBD_VMAXIMIZE:
1451 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1452 CloseWindowMenu(scr);
1454 if (wwin->flags.maximized) {
1455 wUnmaximizeWindow(wwin);
1456 } else {
1457 wMaximizeWindow(wwin, MAX_VERTICAL);
1460 break;
1461 case WKBD_HMAXIMIZE:
1462 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1463 CloseWindowMenu(scr);
1465 if (wwin->flags.maximized) {
1466 wUnmaximizeWindow(wwin);
1467 } else {
1468 wMaximizeWindow(wwin, MAX_HORIZONTAL);
1471 break;
1472 case WKBD_RAISE:
1473 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1474 CloseWindowMenu(scr);
1476 wRaiseFrame(wwin->frame->core);
1478 break;
1479 case WKBD_LOWER:
1480 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1481 CloseWindowMenu(scr);
1483 wLowerFrame(wwin->frame->core);
1485 break;
1486 case WKBD_RAISELOWER:
1487 /* raise or lower the window under the pointer, not the
1488 * focused one
1490 wwin = windowUnderPointer(scr);
1491 if (wwin)
1492 wRaiseLowerFrame(wwin->frame->core);
1493 break;
1494 case WKBD_SHADE:
1495 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1496 if (wwin->flags.shaded)
1497 wUnshadeWindow(wwin);
1498 else
1499 wShadeWindow(wwin);
1501 break;
1502 case WKBD_MOVERESIZE:
1503 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1504 CloseWindowMenu(scr);
1506 wKeyboardMoveResizeWindow(wwin);
1508 break;
1509 case WKBD_CLOSE:
1510 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1511 CloseWindowMenu(scr);
1512 if (wwin->protocols.DELETE_WINDOW)
1513 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1514 event->xkey.time);
1516 break;
1517 case WKBD_SELECT:
1518 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1519 wSelectWindow(wwin, !wwin->flags.selected);
1521 break;
1522 case WKBD_FOCUSNEXT:
1523 StartWindozeCycle(wwin, event, True);
1524 break;
1526 case WKBD_FOCUSPREV:
1527 StartWindozeCycle(wwin, event, False);
1528 break;
1530 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1531 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1532 i = (scr->current_workspace/10)*10 + wk - 1;\
1533 if (wPreferences.ws_advance || i<scr->workspace_count)\
1534 wWorkspaceChange(scr, i);\
1535 break
1536 #else
1537 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1538 i = (scr->current_workspace/10)*10 + wk - 1;\
1539 if (wPreferences.ws_advance || i<scr->workspace_count)\
1540 wWorkspaceChange(scr, i);\
1541 break
1542 #endif
1543 GOTOWORKS(1);
1544 GOTOWORKS(2);
1545 GOTOWORKS(3);
1546 GOTOWORKS(4);
1547 GOTOWORKS(5);
1548 GOTOWORKS(6);
1549 GOTOWORKS(7);
1550 GOTOWORKS(8);
1551 GOTOWORKS(9);
1552 GOTOWORKS(10);
1553 #undef GOTOWORKS
1554 case WKBD_NEXTWORKSPACE:
1555 wWorkspaceRelativeChange(scr, 1);
1556 break;
1557 case WKBD_PREVWORKSPACE:
1558 wWorkspaceRelativeChange(scr, -1);
1559 break;
1560 case WKBD_WINDOW1:
1561 case WKBD_WINDOW2:
1562 case WKBD_WINDOW3:
1563 case WKBD_WINDOW4:
1564 case WKBD_WINDOW5:
1565 case WKBD_WINDOW6:
1566 case WKBD_WINDOW7:
1567 case WKBD_WINDOW8:
1568 case WKBD_WINDOW9:
1569 case WKBD_WINDOW10:
1571 index = command-WKBD_WINDOW1;
1573 if (scr->shortcutWindows[index]) {
1574 WMArray *list = scr->shortcutWindows[index];
1575 int cw;
1576 int count = WMGetArrayItemCount(list);
1577 WWindow *twin;
1578 WMArrayIterator iter;
1579 WWindow *wwin;
1581 wUnselectWindows(scr);
1582 cw = scr->current_workspace;
1584 WM_ETARETI_ARRAY(list, wwin, iter) {
1585 if (count > 1)
1586 wWindowChangeWorkspace(wwin, cw);
1588 wMakeWindowVisible(wwin);
1590 if (count > 1)
1591 wSelectWindow(wwin, True);
1594 /* rotate the order of windows, to create a cycling effect */
1595 twin = WMGetFromArray(list, 0);
1596 WMDeleteFromArray(list, 0);
1597 WMAddToArray(list, twin);
1599 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1600 if (scr->shortcutWindows[index]) {
1601 WMFreeArray(scr->shortcutWindows[index]);
1602 scr->shortcutWindows[index] = NULL;
1605 if (wwin->flags.selected && scr->selected_windows) {
1606 scr->shortcutWindows[index] =
1607 WMDuplicateArray(scr->selected_windows);
1608 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1609 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1610 } else {
1611 scr->shortcutWindows[index] = WMCreateArray(4);
1612 WMAddToArray(scr->shortcutWindows[index], wwin);
1615 wSelectWindow(wwin, !wwin->flags.selected);
1616 XFlush(dpy);
1617 wusleep(3000);
1618 wSelectWindow(wwin, !wwin->flags.selected);
1619 XFlush(dpy);
1621 } else if (scr->selected_windows
1622 && WMGetArrayItemCount(scr->selected_windows)) {
1624 if (wwin->flags.selected && scr->selected_windows) {
1625 if (scr->shortcutWindows[index]) {
1626 WMFreeArray(scr->shortcutWindows[index]);
1628 scr->shortcutWindows[index] =
1629 WMDuplicateArray(scr->selected_windows);
1633 break;
1635 case WKBD_SWITCH_SCREEN:
1636 if (wScreenCount > 1) {
1637 WScreen *scr2;
1638 int i;
1640 /* find index of this screen */
1641 for (i = 0; i < wScreenCount; i++) {
1642 if (wScreenWithNumber(i) == scr)
1643 break;
1645 i++;
1646 if (i >= wScreenCount) {
1647 i = 0;
1649 scr2 = wScreenWithNumber(i);
1651 if (scr2) {
1652 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1653 scr2->scr_width/2, scr2->scr_height/2);
1656 break;
1658 case WKBD_NEXTWSLAYER:
1659 case WKBD_PREVWSLAYER:
1661 int row, column;
1663 row = scr->current_workspace/10;
1664 column = scr->current_workspace%10;
1666 if (command==WKBD_NEXTWSLAYER) {
1667 if ((row+1)*10 < scr->workspace_count)
1668 wWorkspaceChange(scr, column+(row+1)*10);
1669 } else {
1670 if (row > 0)
1671 wWorkspaceChange(scr, column+(row-1)*10);
1674 break;
1675 case WKBD_CLIPLOWER:
1676 if (!wPreferences.flags.noclip)
1677 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1678 break;
1679 case WKBD_CLIPRAISE:
1680 if (!wPreferences.flags.noclip)
1681 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1682 break;
1683 case WKBD_CLIPRAISELOWER:
1684 if (!wPreferences.flags.noclip)
1685 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1686 break;
1687 #ifdef KEEP_XKB_LOCK_STATUS
1688 case WKBD_TOGGLE:
1689 if(wPreferences.modelock) {
1690 /*toggle*/
1691 wwin = scr->focused_window;
1693 if (wwin && wwin->flags.mapped
1694 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1695 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1696 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1698 wwin->frame->languagemode = wwin->frame->last_languagemode;
1699 wwin->frame->last_languagemode = staterec.group;
1700 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1704 break;
1705 #endif /* KEEP_XKB_LOCK_STATUS */
1711 static void
1712 handleMotionNotify(XEvent *event)
1714 WMenu *menu;
1715 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1717 if (wPreferences.scrollable_menus) {
1718 if (scr->flags.jump_back_pending ||
1719 event->xmotion.x_root <= 1 ||
1720 event->xmotion.x_root >= (scr->scr_width - 2) ||
1721 event->xmotion.y_root <= 1 ||
1722 event->xmotion.y_root >= (scr->scr_height - 2)) {
1723 #ifdef DEBUG
1724 L("pointer at screen edge");
1725 #endif
1726 menu = wMenuUnderPointer(scr);
1727 if (menu!=NULL)
1728 wMenuScroll(menu, event);
1731 #if 0
1732 if (event->xmotion.subwindow == None)
1733 return;
1735 if (scr->scrolledFMaximize != None) {
1736 WWindow *twin;
1738 twin = wWindowFor(scr->scrolledFMaximize);
1739 if (twin && twin->frame_y ==) {
1743 scr->scrolledFMaximize = NULL;
1745 } else {
1747 /* scroll full maximized window */
1748 if (event->xmotion.y_root < 1
1749 || event->xmotion.y_root > scr->scr_height - 1) {
1751 wwin = wWindowFor(event->xmotion.subwindow);
1753 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1754 && WFLAGP(wwin, full_maximize)
1755 && event->xmotion.x_root >= wwin->frame_x
1756 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1758 if (!WFLAGP(wwin, no_titlebar)
1759 && wwin->frame_y <= - wwin->frame->top_width) {
1761 wWindowMove(wwin, wwin->frame_x, 0);
1762 wwin->flags.dragged_while_fmaximized = 0;
1764 } else if (!WFLAGP(wwin, no_resizebar)
1765 && wwin->frame_y + wwin->frame->core->height >=
1766 scr->scr_height + wwin->frame->bottom_width) {
1768 int y = scr->scr_height + wwin->frame->bottom_width;
1770 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1772 wWindowMove(wwin, wwin->frame_x, y);
1773 wwin->flags.dragged_while_fmaximized = 0;
1777 #endif
1781 static void
1782 handleVisibilityNotify(XEvent *event)
1784 WWindow *wwin;
1786 wwin = wWindowFor(event->xvisibility.window);
1787 if (!wwin)
1788 return;
1789 wwin->flags.obscured =
1790 (event->xvisibility.state == VisibilityFullyObscured);