- Fixed dock's menu mapping position when dock is on the right side.
[wmaker-crm.git] / src / event.c
blobf3d4f06f55ad3a10ae47146b0a3b5fad5d251bef
1 /* event.c- event loop and handling
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 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 if (scr != NULL) {
560 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
561 (void*)window)) != WANotFound) {
562 WFakeGroupLeader *fPtr;
564 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
565 if (fPtr->retainCount > 0) {
566 fPtr->retainCount--;
567 if (fPtr->retainCount==0 && fPtr->leader!=None) {
568 XDestroyWindow(dpy, fPtr->leader);
569 fPtr->leader = None;
570 XFlush(dpy);
573 fPtr->origLeader = None;
577 app = wApplicationOf(window);
578 if (app) {
579 if (window == app->main_window) {
580 app->refcount = 0;
581 wwin = app->main_window_desc->screen_ptr->focused_window;
582 while (wwin) {
583 if (wwin->main_window == window) {
584 wwin->main_window = None;
586 wwin = wwin->prev;
589 wApplicationDestroy(app);
592 #ifdef KWM_HINTS
593 wKWMCheckDestroy(&event->xdestroywindow);
594 #endif
599 static void
600 handleExpose(XEvent *event)
602 WObjDescriptor *desc;
603 XEvent ev;
605 #ifdef DEBUG
606 L("got expose");
607 #endif
608 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
610 if (XFindContext(dpy, event->xexpose.window, wWinContext,
611 (XPointer *)&desc)==XCNOENT) {
612 return;
615 if (desc->handle_expose) {
616 (*desc->handle_expose)(desc, event);
620 static void
621 executeButtonAction(WScreen *scr, XEvent *event, int action)
623 switch(action) {
624 case WA_SELECT_WINDOWS:
625 wUnselectWindows(scr);
626 wSelectWindows(scr, event);
627 break;
628 case WA_OPEN_APPMENU:
629 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
630 /* ugly hack */
631 if (scr->root_menu) {
632 if (scr->root_menu->brother->flags.mapped)
633 event->xbutton.window = scr->root_menu->brother->frame->core->window;
634 else
635 event->xbutton.window = scr->root_menu->frame->core->window;
637 break;
638 case WA_OPEN_WINLISTMENU:
639 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
640 if (scr->switch_menu) {
641 if (scr->switch_menu->brother->flags.mapped)
642 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
643 else
644 event->xbutton.window = scr->switch_menu->frame->core->window;
646 break;
647 default:
648 break;
653 /* bindable */
654 static void
655 handleButtonPress(XEvent *event)
657 WObjDescriptor *desc;
658 WScreen *scr;
660 #ifdef DEBUG
661 L("got button press");
662 #endif
663 scr = wScreenForRootWindow(event->xbutton.root);
665 #ifdef BALLOON_TEXT
666 wBalloonHide(scr);
667 #endif
670 #ifndef LITE
671 if (event->xbutton.window==scr->root_win) {
672 if (event->xbutton.button==Button1 &&
673 wPreferences.mouse_button1!=WA_NONE) {
674 executeButtonAction(scr, event, wPreferences.mouse_button1);
675 } else if (event->xbutton.button==Button2 &&
676 wPreferences.mouse_button2!=WA_NONE) {
677 executeButtonAction(scr, event, wPreferences.mouse_button2);
678 } else if (event->xbutton.button==Button3 &&
679 wPreferences.mouse_button3!=WA_NONE) {
680 executeButtonAction(scr, event, wPreferences.mouse_button3);
681 } else if (event->xbutton.button==Button4 &&
682 wPreferences.mouse_wheel!=WA_NONE) {
683 wWorkspaceRelativeChange(scr, 1);
684 } else if (event->xbutton.button==Button5 &&
685 wPreferences.mouse_wheel!=WA_NONE) {
686 wWorkspaceRelativeChange(scr, -1);
688 #ifdef GNOME_STUFF
689 else if (wGNOMEProxyizeButtonEvent(scr, event))
690 return;
691 #endif
693 #endif /* !LITE */
695 desc = NULL;
696 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
697 (XPointer *)&desc)==XCNOENT) {
698 if (XFindContext(dpy, event->xbutton.window, wWinContext,
699 (XPointer *)&desc)==XCNOENT) {
700 return;
704 if (desc->parent_type == WCLASS_WINDOW) {
705 XSync(dpy, 0);
707 if (event->xbutton.state & MOD_MASK) {
708 XAllowEvents(dpy, AsyncPointer, CurrentTime);
711 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
712 if (wPreferences.ignore_focus_click) {
713 XAllowEvents(dpy, AsyncPointer, CurrentTime);
715 XAllowEvents(dpy, ReplayPointer, CurrentTime);
716 /* }*/
717 XSync(dpy, 0);
718 } else if (desc->parent_type == WCLASS_APPICON
719 || desc->parent_type == WCLASS_MINIWINDOW
720 || desc->parent_type == WCLASS_DOCK_ICON) {
721 if (event->xbutton.state & MOD_MASK) {
722 XSync(dpy, 0);
723 XAllowEvents(dpy, AsyncPointer, CurrentTime);
724 XSync(dpy, 0);
728 if (desc->handle_mousedown!=NULL) {
729 (*desc->handle_mousedown)(desc, event);
732 /* save double-click information */
733 if (scr->flags.next_click_is_not_double) {
734 scr->flags.next_click_is_not_double = 0;
735 } else {
736 scr->last_click_time = event->xbutton.time;
737 scr->last_click_button = event->xbutton.button;
738 scr->last_click_window = event->xbutton.window;
743 static void
744 handleMapNotify(XEvent *event)
746 WWindow *wwin;
747 #ifdef DEBUG
748 L("got map");
749 #endif
750 wwin = wWindowFor(event->xmap.event);
751 if (wwin && wwin->client_win == event->xmap.event) {
752 if (wwin->flags.miniaturized) {
753 wDeiconifyWindow(wwin);
754 } else {
755 XGrabServer(dpy);
756 wWindowMap(wwin);
757 wClientSetState(wwin, NormalState, None);
758 XUngrabServer(dpy);
764 static void
765 handleUnmapNotify(XEvent *event)
767 WWindow *wwin;
768 XEvent ev;
769 Bool withdraw = False;
770 #ifdef DEBUG
771 L("got unmap");
772 #endif
773 /* only process windows with StructureNotify selected
774 * (ignore SubstructureNotify) */
775 wwin = wWindowFor(event->xunmap.window);
776 if (!wwin)
777 return;
779 /* whether the event is a Withdrawal request */
780 if (event->xunmap.event == wwin->screen_ptr->root_win
781 && event->xunmap.send_event)
782 withdraw = True;
784 if (wwin->client_win != event->xunmap.event && !withdraw)
785 return;
787 if (!wwin->flags.mapped && !withdraw
788 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
789 && !wwin->flags.miniaturized && !wwin->flags.hidden)
790 return;
792 XGrabServer(dpy);
793 XUnmapWindow(dpy, wwin->frame->core->window);
794 wwin->flags.mapped = 0;
795 XSync(dpy, 0);
796 /* check if the window was destroyed */
797 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
798 DispatchEvent(&ev);
799 } else {
800 Bool reparented = False;
802 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
803 reparented = True;
805 /* withdraw window */
806 wwin->flags.mapped = 0;
807 if (!reparented)
808 wClientSetState(wwin, WithdrawnState, None);
810 /* if the window was reparented, do not reparent it back to the
811 * root window */
812 wUnmanageWindow(wwin, !reparented, False);
814 XUngrabServer(dpy);
818 static void
819 handleConfigureRequest(XEvent *event)
821 WWindow *wwin;
822 #ifdef DEBUG
823 L("got configure request");
824 #endif
825 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
827 * Configure request for unmapped window
829 wClientConfigure(NULL, &(event->xconfigurerequest));
830 } else {
831 wClientConfigure(wwin, &(event->xconfigurerequest));
836 static void
837 handlePropertyNotify(XEvent *event)
839 WWindow *wwin;
840 WApplication *wapp;
841 Window jr;
842 int ji;
843 unsigned int ju;
844 WScreen *scr;
845 #ifdef DEBUG
846 L("got property notify");
847 #endif
848 if ((wwin=wWindowFor(event->xproperty.window))) {
849 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
850 &ju, &ju, &ju, &ju)) {
851 return;
853 wClientCheckProperty(wwin, &event->xproperty);
855 wapp = wApplicationOf(event->xproperty.window);
856 if (wapp) {
857 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
860 scr = wScreenForWindow(event->xproperty.window);
861 if (scr && scr->root_win == event->xproperty.window) {
862 #ifdef KWM_HINTS
863 wKWMCheckRootHintChange(scr, &event->xproperty);
864 #endif
869 static void
870 handleClientMessage(XEvent *event)
872 WWindow *wwin;
873 WObjDescriptor *desc;
874 #ifdef DEBUG
875 L("got client message");
876 #endif
877 /* handle transition from Normal to Iconic state */
878 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
879 && event->xclient.format == 32
880 && event->xclient.data.l[0] == IconicState) {
882 wwin = wWindowFor(event->xclient.window);
883 if (!wwin) return;
884 if (!wwin->flags.miniaturized)
885 wIconifyWindow(wwin);
886 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
887 && event->xclient.format == 32) {
888 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
890 if (!scr)
891 return;
893 if (event->xclient.data.l[1] == 1) { /* starting */
894 wColormapAllowClientInstallation(scr, True);
895 } else { /* stopping */
896 wColormapAllowClientInstallation(scr, False);
898 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
900 wDefaultsCheckDomains("bla");
902 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
903 WApplication *wapp;
904 int done=0;
905 wapp = wApplicationOf(event->xclient.window);
906 if (wapp) {
907 switch (event->xclient.data.l[0]) {
908 case WMFHideOtherApplications:
909 wHideOtherApplications(wapp->main_window_desc);
910 done = 1;
911 break;
913 case WMFHideApplication:
914 wHideApplication(wapp);
915 done = 1;
916 break;
919 if (!done) {
920 wwin = wWindowFor(event->xclient.window);
921 if (wwin) {
922 switch (event->xclient.data.l[0]) {
923 case WMFHideOtherApplications:
924 wHideOtherApplications(wwin);
925 break;
927 case WMFHideApplication:
928 wHideApplication(wApplicationOf(wwin->main_window));
929 break;
933 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
934 wwin = wWindowFor(event->xclient.window);
935 if (!wwin) return;
936 switch (event->xclient.data.l[0]) {
937 case GSWindowLevelAttr:
939 int level = (int)event->xclient.data.l[1];
941 if (WINDOW_LEVEL(wwin) != level) {
942 ChangeStackingLevel(wwin->frame->core, level);
945 break;
947 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
948 wwin = wWindowFor(event->xclient.window);
949 if (!wwin) return;
950 switch (event->xclient.data.l[0]) {
951 case WMTitleBarNormal:
952 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
953 break;
954 case WMTitleBarMain:
955 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
956 break;
957 case WMTitleBarKey:
958 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
959 break;
961 #ifdef GNOME_STUFF
962 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
963 /* do nothing */
964 #endif /* GNOME_STUFF */
965 #ifdef KWM_HINTS
966 } else if (wKWMProcessClientMessage(&event->xclient)) {
967 /* do nothing */
968 #endif /* KWM_HINTS */
969 #ifdef XDND
970 } else if (wXDNDProcessClientMessage(&event->xclient)) {
971 /* do nothing */
972 #endif /* XDND */
973 #ifdef OFFIX_DND
974 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
975 WScreen *scr = wScreenForWindow(event->xclient.window);
976 if (scr && wDockReceiveDNDDrop(scr,event))
977 goto redirect_message;
978 #endif /* OFFIX_DND */
979 } else {
980 #ifdef OFFIX_DND
981 redirect_message:
982 #endif
984 * Non-standard thing, but needed by OffiX DND.
985 * For when the icon frame gets a ClientMessage
986 * that should have gone to the icon_window.
988 if (XFindContext(dpy, event->xbutton.window, wWinContext,
989 (XPointer *)&desc)!=XCNOENT) {
990 struct WIcon *icon=NULL;
992 if (desc->parent_type == WCLASS_MINIWINDOW) {
993 icon = (WIcon*)desc->parent;
994 } else if (desc->parent_type == WCLASS_DOCK_ICON
995 || desc->parent_type == WCLASS_APPICON) {
996 icon = ((WAppIcon*)desc->parent)->icon;
998 if (icon && (wwin=icon->owner)) {
999 if (wwin->client_win!=event->xclient.window) {
1000 event->xclient.window = wwin->client_win;
1001 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1002 event);
1010 static void
1011 raiseWindow(WScreen *scr)
1013 WWindow *wwin;
1015 scr->autoRaiseTimer = NULL;
1017 wwin = wWindowFor(scr->autoRaiseWindow);
1018 if (!wwin)
1019 return;
1021 if (!wwin->flags.destroyed && wwin->flags.focused) {
1022 wRaiseFrame(wwin->frame->core);
1023 /* this is needed or a race condition will occur */
1024 XSync(dpy, False);
1029 static void
1030 handleEnterNotify(XEvent *event)
1032 WWindow *wwin;
1033 WObjDescriptor *desc = NULL;
1034 XEvent ev;
1035 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1036 #ifdef DEBUG
1037 L("got enter notify");
1038 #endif
1040 #ifdef VIRTUAL_DESKTOP
1041 /* TODO: acceleration code */
1042 if (wPreferences.vedge_thickness) {
1043 int x,y;
1044 if (event->xcrossing.window == scr->virtual_edge_r) {
1045 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1046 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1047 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1048 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1049 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, 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_u) {
1053 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1054 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1055 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1056 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1057 printf("enter bottom\n");
1058 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1059 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1060 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1063 #endif
1065 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1066 &ev)) {
1067 /* already left the window... */
1068 saveTimestamp(&ev);
1069 if (ev.xcrossing.mode==event->xcrossing.mode
1070 && ev.xcrossing.detail==event->xcrossing.detail) {
1071 return;
1075 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1076 (XPointer *)&desc)!=XCNOENT) {
1077 if(desc->handle_enternotify)
1078 (*desc->handle_enternotify)(desc, event);
1081 /* enter to window */
1082 wwin = wWindowFor(event->xcrossing.window);
1083 if (!wwin) {
1084 if (wPreferences.colormap_mode==WCM_POINTER) {
1085 wColormapInstallForWindow(scr, NULL);
1087 if (scr->autoRaiseTimer
1088 && event->xcrossing.root==event->xcrossing.window) {
1089 WMDeleteTimerHandler(scr->autoRaiseTimer);
1090 scr->autoRaiseTimer = NULL;
1092 } else {
1093 /* set auto raise timer even if in focus-follows-mouse mode
1094 * and the event is for the frame window, even if the window
1095 * has focus already. useful if you move the pointer from a focused
1096 * window to the root window and back pretty fast
1098 * set focus if in focus-follows-mouse mode and the event
1099 * is for the frame window and window doesn't have focus yet */
1100 if (wPreferences.focus_mode==WKF_SLOPPY
1101 && wwin->frame->core->window==event->xcrossing.window
1102 && !scr->flags.doing_alt_tab) {
1104 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1105 wSetFocusTo(scr, wwin);
1107 if (scr->autoRaiseTimer)
1108 WMDeleteTimerHandler(scr->autoRaiseTimer);
1109 scr->autoRaiseTimer = NULL;
1111 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1112 scr->autoRaiseWindow = wwin->frame->core->window;
1113 scr->autoRaiseTimer
1114 = WMAddTimerHandler(wPreferences.raise_delay,
1115 (WMCallback*)raiseWindow, scr);
1118 /* Install colormap for window, if the colormap installation mode
1119 * is colormap_follows_mouse */
1120 if (wPreferences.colormap_mode==WCM_POINTER) {
1121 if (wwin->client_win==event->xcrossing.window)
1122 wColormapInstallForWindow(scr, wwin);
1123 else
1124 wColormapInstallForWindow(scr, NULL);
1128 /* a little kluge to hide the clip balloon */
1129 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1130 if (!desc) {
1131 XUnmapWindow(dpy, scr->clip_balloon);
1132 scr->flags.clip_balloon_mapped = 0;
1133 } else {
1134 if (desc->parent_type!=WCLASS_DOCK_ICON
1135 || scr->clip_icon != desc->parent) {
1136 XUnmapWindow(dpy, scr->clip_balloon);
1137 scr->flags.clip_balloon_mapped = 0;
1142 if (event->xcrossing.window == event->xcrossing.root
1143 && event->xcrossing.detail == NotifyNormal
1144 && event->xcrossing.detail != NotifyInferior
1145 && wPreferences.focus_mode != WKF_CLICK) {
1147 wSetFocusTo(scr, scr->focused_window);
1150 #ifdef BALLOON_TEXT
1151 wBalloonEnteredObject(scr, desc);
1152 #endif
1156 static void
1157 handleLeaveNotify(XEvent *event)
1159 WObjDescriptor *desc = NULL;
1161 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1162 (XPointer *)&desc)!=XCNOENT) {
1163 if(desc->handle_leavenotify)
1164 (*desc->handle_leavenotify)(desc, event);
1166 if (event->xcrossing.window == event->xcrossing.root
1167 && event->xcrossing.mode == NotifyNormal
1168 && event->xcrossing.detail != NotifyInferior
1169 && wPreferences.focus_mode != WKF_CLICK) {
1171 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1173 wSetFocusTo(scr, NULL);
1178 #ifdef SHAPE
1179 static void
1180 handleShapeNotify(XEvent *event)
1182 XShapeEvent *shev = (XShapeEvent*)event;
1183 WWindow *wwin;
1184 XEvent ev;
1185 #ifdef DEBUG
1186 L("got shape notify");
1187 #endif
1188 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1189 XShapeEvent *sev = (XShapeEvent*)&ev;
1191 if (sev->kind == ShapeBounding) {
1192 if (sev->shaped == shev->shaped) {
1193 *shev = *sev;
1194 } else {
1195 XPutBackEvent(dpy, &ev);
1196 break;
1201 wwin = wWindowFor(shev->window);
1202 if (!wwin || shev->kind != ShapeBounding)
1203 return;
1205 if (!shev->shaped && wwin->flags.shaped) {
1207 wwin->flags.shaped = 0;
1208 wWindowClearShape(wwin);
1210 } else if (shev->shaped) {
1212 wwin->flags.shaped = 1;
1213 wWindowSetShape(wwin);
1216 #endif /* SHAPE */
1218 #ifdef KEEP_XKB_LOCK_STATUS
1219 /* please help ]d if you know what to do */
1220 handleXkbIndicatorStateNotify(XEvent *event)
1222 WWindow *wwin;
1223 WScreen *scr;
1224 XkbStateRec staterec;
1225 int i;
1227 for (i=0; i<wScreenCount; i++) {
1228 scr = wScreenWithNumber(i);
1229 wwin = scr->focused_window;
1230 if (wwin && wwin->flags.focused) {
1231 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1232 if (wwin->frame->languagemode != staterec.group) {
1233 wwin->frame->last_languagemode = wwin->frame->languagemode;
1234 wwin->frame->languagemode = staterec.group;
1236 #ifdef XKB_BUTTON_HINT
1237 if (wwin->frame->titlebar) {
1238 wFrameWindowPaint(wwin->frame);
1240 #endif
1244 #endif /*KEEP_XKB_LOCK_STATUS*/
1246 static void
1247 handleColormapNotify(XEvent *event)
1249 WWindow *wwin;
1250 WScreen *scr;
1251 Bool reinstall = False;
1253 wwin = wWindowFor(event->xcolormap.window);
1254 if (!wwin)
1255 return;
1257 scr = wwin->screen_ptr;
1259 do {
1260 if (wwin) {
1261 if (event->xcolormap.new) {
1262 XWindowAttributes attr;
1264 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1266 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1267 scr->current_colormap = attr.colormap;
1269 reinstall = True;
1270 } else if (event->xcolormap.state == ColormapUninstalled &&
1271 scr->current_colormap == event->xcolormap.colormap) {
1273 /* some bastard app (like XV) removed our colormap */
1275 * can't enforce or things like xscreensaver wont work
1276 * reinstall = True;
1278 } else if (event->xcolormap.state == ColormapInstalled &&
1279 scr->current_colormap == event->xcolormap.colormap) {
1281 /* someone has put our colormap back */
1282 reinstall = False;
1285 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1286 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1288 if (reinstall && scr->current_colormap!=None) {
1289 if (!scr->flags.colormap_stuff_blocked)
1290 XInstallColormap(dpy, scr->current_colormap);
1296 static void
1297 handleFocusIn(XEvent *event)
1299 WWindow *wwin;
1302 * For applications that like stealing the focus.
1304 while (XCheckTypedEvent(dpy, FocusIn, event));
1305 saveTimestamp(event);
1306 if (event->xfocus.mode == NotifyUngrab
1307 || event->xfocus.mode == NotifyGrab
1308 || event->xfocus.detail > NotifyNonlinearVirtual) {
1309 return;
1312 wwin = wWindowFor(event->xfocus.window);
1313 if (wwin && !wwin->flags.focused) {
1314 if (wwin->flags.mapped)
1315 wSetFocusTo(wwin->screen_ptr, wwin);
1316 else
1317 wSetFocusTo(wwin->screen_ptr, NULL);
1318 } else if (!wwin) {
1319 WScreen *scr = wScreenForWindow(event->xfocus.window);
1320 if (scr)
1321 wSetFocusTo(scr, NULL);
1326 static WWindow*
1327 windowUnderPointer(WScreen *scr)
1329 unsigned int mask;
1330 int foo;
1331 Window bar, win;
1333 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1334 &mask))
1335 return wWindowFor(win);
1336 return NULL;
1342 static void
1343 handleKeyPress(XEvent *event)
1345 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1346 WWindow *wwin = scr->focused_window;
1347 int i;
1348 int modifiers;
1349 int command=-1, index;
1350 #ifdef KEEP_XKB_LOCK_STATUS
1351 XkbStateRec staterec;
1352 #endif /*KEEP_XKB_LOCK_STATUS*/
1354 /* ignore CapsLock */
1355 modifiers = event->xkey.state & ValidModMask;
1357 for (i=0; i<WKBD_LAST; i++) {
1358 if (wKeyBindings[i].keycode==0)
1359 continue;
1361 if (wKeyBindings[i].keycode==event->xkey.keycode
1362 && (/*wKeyBindings[i].modifier==0
1363 ||*/ wKeyBindings[i].modifier==modifiers)) {
1364 command = i;
1365 break;
1370 if (command < 0) {
1371 #ifdef LITE
1373 #if 0
1375 #endif
1376 #else
1377 if (!wRootMenuPerformShortcut(event)) {
1378 #endif
1379 static int dontLoop = 0;
1381 if (dontLoop > 10) {
1382 wwarning("problem with key event processing code");
1383 return;
1385 dontLoop++;
1386 /* if the focused window is an internal window, try redispatching
1387 * the event to the managed window, as it can be a WINGs window */
1388 if (wwin && wwin->flags.internal_window
1389 && wwin->client_leader!=None) {
1390 /* client_leader contains the WINGs toplevel */
1391 event->xany.window = wwin->client_leader;
1392 WMHandleEvent(event);
1394 dontLoop--;
1396 return;
1399 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1400 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1402 switch (command) {
1403 #ifndef LITE
1404 case WKBD_ROOTMENU:
1405 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1406 OpenRootMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1407 break;
1408 case WKBD_WINDOWLIST:
1409 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1410 break;
1411 #endif /* !LITE */
1412 case WKBD_WINDOWMENU:
1413 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1414 OpenWindowMenu(wwin, wwin->frame_x,
1415 wwin->frame_y+wwin->frame->top_width, True);
1416 break;
1417 case WKBD_MINIATURIZE:
1418 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1419 && !WFLAGP(wwin, no_miniaturizable)) {
1420 CloseWindowMenu(scr);
1422 if (wwin->protocols.MINIATURIZE_WINDOW)
1423 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1424 event->xbutton.time);
1425 else {
1426 wIconifyWindow(wwin);
1429 break;
1430 case WKBD_HIDE:
1431 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1432 WApplication *wapp = wApplicationOf(wwin->main_window);
1433 CloseWindowMenu(scr);
1435 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1436 wHideApplication(wapp);
1439 break;
1440 case WKBD_HIDE_OTHERS:
1441 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1442 CloseWindowMenu(scr);
1444 wHideOtherApplications(wwin);
1446 break;
1447 case WKBD_MAXIMIZE:
1448 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1449 CloseWindowMenu(scr);
1451 if (wwin->flags.maximized) {
1452 wUnmaximizeWindow(wwin);
1453 } else {
1454 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1457 break;
1458 case WKBD_VMAXIMIZE:
1459 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1460 CloseWindowMenu(scr);
1462 if (wwin->flags.maximized) {
1463 wUnmaximizeWindow(wwin);
1464 } else {
1465 wMaximizeWindow(wwin, MAX_VERTICAL);
1468 break;
1469 case WKBD_HMAXIMIZE:
1470 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1471 CloseWindowMenu(scr);
1473 if (wwin->flags.maximized) {
1474 wUnmaximizeWindow(wwin);
1475 } else {
1476 wMaximizeWindow(wwin, MAX_HORIZONTAL);
1479 break;
1480 case WKBD_RAISE:
1481 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1482 CloseWindowMenu(scr);
1484 wRaiseFrame(wwin->frame->core);
1486 break;
1487 case WKBD_LOWER:
1488 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1489 CloseWindowMenu(scr);
1491 wLowerFrame(wwin->frame->core);
1493 break;
1494 case WKBD_RAISELOWER:
1495 /* raise or lower the window under the pointer, not the
1496 * focused one
1498 wwin = windowUnderPointer(scr);
1499 if (wwin)
1500 wRaiseLowerFrame(wwin->frame->core);
1501 break;
1502 case WKBD_SHADE:
1503 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1504 if (wwin->flags.shaded)
1505 wUnshadeWindow(wwin);
1506 else
1507 wShadeWindow(wwin);
1509 break;
1510 case WKBD_MOVERESIZE:
1511 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1512 CloseWindowMenu(scr);
1514 wKeyboardMoveResizeWindow(wwin);
1516 break;
1517 case WKBD_CLOSE:
1518 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1519 CloseWindowMenu(scr);
1520 if (wwin->protocols.DELETE_WINDOW)
1521 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1522 event->xkey.time);
1524 break;
1525 case WKBD_SELECT:
1526 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1527 wSelectWindow(wwin, !wwin->flags.selected);
1529 break;
1530 case WKBD_FOCUSNEXT:
1531 StartWindozeCycle(wwin, event, True);
1532 break;
1534 case WKBD_FOCUSPREV:
1535 StartWindozeCycle(wwin, event, False);
1536 break;
1538 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1539 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1540 i = (scr->current_workspace/10)*10 + wk - 1;\
1541 if (wPreferences.ws_advance || i<scr->workspace_count)\
1542 wWorkspaceChange(scr, i);\
1543 break
1544 #else
1545 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1546 i = (scr->current_workspace/10)*10 + wk - 1;\
1547 if (wPreferences.ws_advance || i<scr->workspace_count)\
1548 wWorkspaceChange(scr, i);\
1549 break
1550 #endif
1551 GOTOWORKS(1);
1552 GOTOWORKS(2);
1553 GOTOWORKS(3);
1554 GOTOWORKS(4);
1555 GOTOWORKS(5);
1556 GOTOWORKS(6);
1557 GOTOWORKS(7);
1558 GOTOWORKS(8);
1559 GOTOWORKS(9);
1560 GOTOWORKS(10);
1561 #undef GOTOWORKS
1562 case WKBD_NEXTWORKSPACE:
1563 wWorkspaceRelativeChange(scr, 1);
1564 break;
1565 case WKBD_PREVWORKSPACE:
1566 wWorkspaceRelativeChange(scr, -1);
1567 break;
1568 case WKBD_WINDOW1:
1569 case WKBD_WINDOW2:
1570 case WKBD_WINDOW3:
1571 case WKBD_WINDOW4:
1572 case WKBD_WINDOW5:
1573 case WKBD_WINDOW6:
1574 case WKBD_WINDOW7:
1575 case WKBD_WINDOW8:
1576 case WKBD_WINDOW9:
1577 case WKBD_WINDOW10:
1579 index = command-WKBD_WINDOW1;
1581 if (scr->shortcutWindows[index]) {
1582 WMArray *list = scr->shortcutWindows[index];
1583 int cw;
1584 int count = WMGetArrayItemCount(list);
1585 WWindow *twin;
1586 WMArrayIterator iter;
1587 WWindow *wwin;
1589 wUnselectWindows(scr);
1590 cw = scr->current_workspace;
1592 WM_ETARETI_ARRAY(list, wwin, iter) {
1593 if (count > 1)
1594 wWindowChangeWorkspace(wwin, cw);
1596 wMakeWindowVisible(wwin);
1598 if (count > 1)
1599 wSelectWindow(wwin, True);
1602 /* rotate the order of windows, to create a cycling effect */
1603 twin = WMGetFromArray(list, 0);
1604 WMDeleteFromArray(list, 0);
1605 WMAddToArray(list, twin);
1607 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1608 if (scr->shortcutWindows[index]) {
1609 WMFreeArray(scr->shortcutWindows[index]);
1610 scr->shortcutWindows[index] = NULL;
1613 if (wwin->flags.selected && scr->selected_windows) {
1614 scr->shortcutWindows[index] =
1615 WMDuplicateArray(scr->selected_windows);
1616 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1617 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1618 } else {
1619 scr->shortcutWindows[index] = WMCreateArray(4);
1620 WMAddToArray(scr->shortcutWindows[index], wwin);
1623 wSelectWindow(wwin, !wwin->flags.selected);
1624 XFlush(dpy);
1625 wusleep(3000);
1626 wSelectWindow(wwin, !wwin->flags.selected);
1627 XFlush(dpy);
1629 } else if (scr->selected_windows
1630 && WMGetArrayItemCount(scr->selected_windows)) {
1632 if (wwin->flags.selected && scr->selected_windows) {
1633 if (scr->shortcutWindows[index]) {
1634 WMFreeArray(scr->shortcutWindows[index]);
1636 scr->shortcutWindows[index] =
1637 WMDuplicateArray(scr->selected_windows);
1641 break;
1643 case WKBD_SWITCH_SCREEN:
1644 if (wScreenCount > 1) {
1645 WScreen *scr2;
1646 int i;
1648 /* find index of this screen */
1649 for (i = 0; i < wScreenCount; i++) {
1650 if (wScreenWithNumber(i) == scr)
1651 break;
1653 i++;
1654 if (i >= wScreenCount) {
1655 i = 0;
1657 scr2 = wScreenWithNumber(i);
1659 if (scr2) {
1660 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1661 scr2->scr_width/2, scr2->scr_height/2);
1664 break;
1666 case WKBD_NEXTWSLAYER:
1667 case WKBD_PREVWSLAYER:
1669 int row, column;
1671 row = scr->current_workspace/10;
1672 column = scr->current_workspace%10;
1674 if (command==WKBD_NEXTWSLAYER) {
1675 if ((row+1)*10 < scr->workspace_count)
1676 wWorkspaceChange(scr, column+(row+1)*10);
1677 } else {
1678 if (row > 0)
1679 wWorkspaceChange(scr, column+(row-1)*10);
1682 break;
1683 case WKBD_CLIPLOWER:
1684 if (!wPreferences.flags.noclip)
1685 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1686 break;
1687 case WKBD_CLIPRAISE:
1688 if (!wPreferences.flags.noclip)
1689 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1690 break;
1691 case WKBD_CLIPRAISELOWER:
1692 if (!wPreferences.flags.noclip)
1693 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1694 break;
1695 #ifdef KEEP_XKB_LOCK_STATUS
1696 case WKBD_TOGGLE:
1697 if(wPreferences.modelock) {
1698 /*toggle*/
1699 wwin = scr->focused_window;
1701 if (wwin && wwin->flags.mapped
1702 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1703 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1704 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1706 wwin->frame->languagemode = wwin->frame->last_languagemode;
1707 wwin->frame->last_languagemode = staterec.group;
1708 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1712 break;
1713 #endif /* KEEP_XKB_LOCK_STATUS */
1719 static void
1720 handleMotionNotify(XEvent *event)
1722 WMenu *menu;
1723 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1725 if (wPreferences.scrollable_menus) {
1726 if (scr->flags.jump_back_pending ||
1727 event->xmotion.x_root <= 1 ||
1728 event->xmotion.x_root >= (scr->scr_width - 2) ||
1729 event->xmotion.y_root <= 1 ||
1730 event->xmotion.y_root >= (scr->scr_height - 2)) {
1731 #ifdef DEBUG
1732 L("pointer at screen edge");
1733 #endif
1734 menu = wMenuUnderPointer(scr);
1735 if (menu!=NULL)
1736 wMenuScroll(menu, event);
1739 #if 0
1740 if (event->xmotion.subwindow == None)
1741 return;
1743 if (scr->scrolledFMaximize != None) {
1744 WWindow *twin;
1746 twin = wWindowFor(scr->scrolledFMaximize);
1747 if (twin && twin->frame_y ==) {
1751 scr->scrolledFMaximize = NULL;
1753 } else {
1755 /* scroll full maximized window */
1756 if (event->xmotion.y_root < 1
1757 || event->xmotion.y_root > scr->scr_height - 1) {
1759 wwin = wWindowFor(event->xmotion.subwindow);
1761 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1762 && WFLAGP(wwin, full_maximize)
1763 && event->xmotion.x_root >= wwin->frame_x
1764 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1766 if (!WFLAGP(wwin, no_titlebar)
1767 && wwin->frame_y <= - wwin->frame->top_width) {
1769 wWindowMove(wwin, wwin->frame_x, 0);
1770 wwin->flags.dragged_while_fmaximized = 0;
1772 } else if (!WFLAGP(wwin, no_resizebar)
1773 && wwin->frame_y + wwin->frame->core->height >=
1774 scr->scr_height + wwin->frame->bottom_width) {
1776 int y = scr->scr_height + wwin->frame->bottom_width;
1778 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1780 wWindowMove(wwin, wwin->frame_x, y);
1781 wwin->flags.dragged_while_fmaximized = 0;
1785 #endif
1789 static void
1790 handleVisibilityNotify(XEvent *event)
1792 WWindow *wwin;
1794 wwin = wWindowFor(event->xvisibility.window);
1795 if (!wwin)
1796 return;
1797 wwin->flags.obscured =
1798 (event->xvisibility.state == VisibilityFullyObscured);