- Fixed sloppy focus bug (Pawel S. Veselov <pv76716@druid.SFBay.Sun.COM>)
[wmaker-crm.git] / src / event.c
blob5214aad4e526b6492f2827878095fad0215b82db
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"
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)
406 LastTimestamp = CurrentTime;
408 switch (event->type) {
409 case ButtonRelease:
410 case ButtonPress:
411 LastTimestamp = event->xbutton.time;
412 break;
413 case KeyPress:
414 case KeyRelease:
415 LastTimestamp = event->xkey.time;
416 break;
417 case MotionNotify:
418 LastTimestamp = event->xmotion.time;
419 break;
420 case PropertyNotify:
421 LastTimestamp = event->xproperty.time;
422 break;
423 case EnterNotify:
424 case LeaveNotify:
425 LastTimestamp = event->xcrossing.time;
426 break;
427 case SelectionClear:
428 LastTimestamp = event->xselectionclear.time;
429 break;
430 case SelectionRequest:
431 LastTimestamp = event->xselectionrequest.time;
432 break;
433 case SelectionNotify:
434 LastTimestamp = event->xselection.time;
435 #ifdef XDND
436 wXDNDProcessSelection(event);
437 #endif
438 break;
443 static int
444 matchWindow(void *item, void *cdata)
446 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
450 static void
451 handleExtensions(XEvent *event)
453 #ifdef KEEP_XKB_LOCK_STATUS
454 XkbEvent *xkbevent;
455 xkbevent = (XkbEvent *)event;
456 #endif /*KEEP_XKB_LOCK_STATUS*/
457 #ifdef SHAPE
458 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
459 handleShapeNotify(event);
461 #endif
462 #ifdef KEEP_XKB_LOCK_STATUS
463 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
464 handleXkbIndicatorStateNotify(event);
466 #endif /*KEEP_XKB_LOCK_STATUS*/
470 static void
471 handleMapRequest(XEvent *ev)
473 WWindow *wwin;
474 WScreen *scr = NULL;
475 Window window = ev->xmaprequest.window;
477 #ifdef DEBUG
478 L("got map request for %x\n", (unsigned)window);
479 #endif
480 if ((wwin = wWindowFor(window))) {
481 if (wwin->flags.shaded) {
482 wUnshadeWindow(wwin);
484 /* deiconify window */
485 if (wwin->flags.miniaturized) {
486 wDeiconifyWindow(wwin);
487 } else if (wwin->flags.hidden) {
488 WApplication *wapp = wApplicationOf(wwin->main_window);
489 /* go to the last workspace that the user worked on the app */
490 if (wapp) {
491 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
493 wUnhideApplication(wapp, False, False);
495 return;
498 scr = wScreenForRootWindow(ev->xmaprequest.parent);
500 wwin = wManageWindow(scr, window);
503 * This is to let the Dock know that the application it launched
504 * has already been mapped (eg: it has finished launching).
505 * It is not necessary for normally docked apps, but is needed for
506 * apps that were forcedly docked (like with dockit).
508 if (scr->last_dock) {
509 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
510 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
511 else
512 wDockTrackWindowLaunch(scr->last_dock, window);
515 if (wwin) {
516 wClientSetState(wwin, NormalState, None);
517 if (wwin->flags.maximized) {
518 wMaximizeWindow(wwin, wwin->flags.maximized);
520 if (wwin->flags.shaded) {
521 wwin->flags.shaded = 0;
522 wwin->flags.skip_next_animation = 1;
523 wShadeWindow(wwin);
525 if (wwin->flags.miniaturized) {
526 wwin->flags.miniaturized = 0;
527 wwin->flags.skip_next_animation = 1;
528 wIconifyWindow(wwin);
530 if (wwin->flags.hidden) {
531 WApplication *wapp = wApplicationOf(wwin->main_window);
533 wwin->flags.hidden = 0;
534 wwin->flags.skip_next_animation = 1;
535 if (wapp) {
536 wHideApplication(wapp);
543 static void
544 handleDestroyNotify(XEvent *event)
546 WWindow *wwin;
547 WApplication *app;
548 Window window = event->xdestroywindow.window;
549 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
550 int index;
552 #ifdef DEBUG
553 L("got destroy notify");
554 #endif
555 wwin = wWindowFor(window);
556 if (wwin) {
557 wUnmanageWindow(wwin, False, True);
560 if (scr != NULL) {
561 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
562 (void*)window)) != WANotFound) {
563 WFakeGroupLeader *fPtr;
565 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
566 if (fPtr->retainCount > 0) {
567 fPtr->retainCount--;
568 if (fPtr->retainCount==0 && fPtr->leader!=None) {
569 XDestroyWindow(dpy, fPtr->leader);
570 fPtr->leader = None;
571 XFlush(dpy);
574 fPtr->origLeader = None;
578 app = wApplicationOf(window);
579 if (app) {
580 if (window == app->main_window) {
581 app->refcount = 0;
582 wwin = app->main_window_desc->screen_ptr->focused_window;
583 while (wwin) {
584 if (wwin->main_window == window) {
585 wwin->main_window = None;
587 wwin = wwin->prev;
590 wApplicationDestroy(app);
593 #ifdef KWM_HINTS
594 wKWMCheckDestroy(&event->xdestroywindow);
595 #endif
600 static void
601 handleExpose(XEvent *event)
603 WObjDescriptor *desc;
604 XEvent ev;
606 #ifdef DEBUG
607 L("got expose");
608 #endif
609 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
611 if (XFindContext(dpy, event->xexpose.window, wWinContext,
612 (XPointer *)&desc)==XCNOENT) {
613 return;
616 if (desc->handle_expose) {
617 (*desc->handle_expose)(desc, event);
621 static void
622 executeButtonAction(WScreen *scr, XEvent *event, int action)
624 switch(action) {
625 case WA_SELECT_WINDOWS:
626 wUnselectWindows(scr);
627 wSelectWindows(scr, event);
628 break;
629 case WA_OPEN_APPMENU:
630 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
631 /* ugly hack */
632 if (scr->root_menu) {
633 if (scr->root_menu->brother->flags.mapped)
634 event->xbutton.window = scr->root_menu->brother->frame->core->window;
635 else
636 event->xbutton.window = scr->root_menu->frame->core->window;
638 break;
639 case WA_OPEN_WINLISTMENU:
640 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
641 if (scr->switch_menu) {
642 if (scr->switch_menu->brother->flags.mapped)
643 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
644 else
645 event->xbutton.window = scr->switch_menu->frame->core->window;
647 break;
648 default:
649 break;
654 /* bindable */
655 static void
656 handleButtonPress(XEvent *event)
658 WObjDescriptor *desc;
659 WScreen *scr;
661 #ifdef DEBUG
662 L("got button press");
663 #endif
664 scr = wScreenForRootWindow(event->xbutton.root);
666 #ifdef BALLOON_TEXT
667 wBalloonHide(scr);
668 #endif
671 #ifndef LITE
672 if (event->xbutton.window==scr->root_win) {
673 if (event->xbutton.button==Button1 &&
674 wPreferences.mouse_button1!=WA_NONE) {
675 executeButtonAction(scr, event, wPreferences.mouse_button1);
676 } else if (event->xbutton.button==Button2 &&
677 wPreferences.mouse_button2!=WA_NONE) {
678 executeButtonAction(scr, event, wPreferences.mouse_button2);
679 } else if (event->xbutton.button==Button3 &&
680 wPreferences.mouse_button3!=WA_NONE) {
681 executeButtonAction(scr, event, wPreferences.mouse_button3);
682 } else if (event->xbutton.button==Button4 &&
683 wPreferences.mouse_wheel!=WA_NONE) {
684 wWorkspaceRelativeChange(scr, 1);
685 } else if (event->xbutton.button==Button5 &&
686 wPreferences.mouse_wheel!=WA_NONE) {
687 wWorkspaceRelativeChange(scr, -1);
689 #ifdef GNOME_STUFF
690 else if (wGNOMEProxyizeButtonEvent(scr, event))
691 return;
692 #endif
694 #endif /* !LITE */
696 desc = NULL;
697 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
698 (XPointer *)&desc)==XCNOENT) {
699 if (XFindContext(dpy, event->xbutton.window, wWinContext,
700 (XPointer *)&desc)==XCNOENT) {
701 return;
705 if (desc->parent_type == WCLASS_WINDOW) {
706 XSync(dpy, 0);
708 if (event->xbutton.state & MOD_MASK) {
709 XAllowEvents(dpy, AsyncPointer, CurrentTime);
712 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
713 if (wPreferences.ignore_focus_click) {
714 XAllowEvents(dpy, AsyncPointer, CurrentTime);
716 XAllowEvents(dpy, ReplayPointer, CurrentTime);
717 /* }*/
718 XSync(dpy, 0);
719 } else if (desc->parent_type == WCLASS_APPICON
720 || desc->parent_type == WCLASS_MINIWINDOW
721 || desc->parent_type == WCLASS_DOCK_ICON) {
722 if (event->xbutton.state & MOD_MASK) {
723 XSync(dpy, 0);
724 XAllowEvents(dpy, AsyncPointer, CurrentTime);
725 XSync(dpy, 0);
729 if (desc->handle_mousedown!=NULL) {
730 (*desc->handle_mousedown)(desc, event);
733 /* save double-click information */
734 if (scr->flags.next_click_is_not_double) {
735 scr->flags.next_click_is_not_double = 0;
736 } else {
737 scr->last_click_time = event->xbutton.time;
738 scr->last_click_button = event->xbutton.button;
739 scr->last_click_window = event->xbutton.window;
744 static void
745 handleMapNotify(XEvent *event)
747 WWindow *wwin;
748 #ifdef DEBUG
749 L("got map");
750 #endif
751 wwin = wWindowFor(event->xmap.event);
752 if (wwin && wwin->client_win == event->xmap.event) {
753 if (wwin->flags.miniaturized) {
754 wDeiconifyWindow(wwin);
755 } else {
756 XGrabServer(dpy);
757 wWindowMap(wwin);
758 wClientSetState(wwin, NormalState, None);
759 XUngrabServer(dpy);
765 static void
766 handleUnmapNotify(XEvent *event)
768 WWindow *wwin;
769 XEvent ev;
770 Bool withdraw = False;
771 #ifdef DEBUG
772 L("got unmap");
773 #endif
774 /* only process windows with StructureNotify selected
775 * (ignore SubstructureNotify) */
776 wwin = wWindowFor(event->xunmap.window);
777 if (!wwin)
778 return;
780 /* whether the event is a Withdrawal request */
781 if (event->xunmap.event == wwin->screen_ptr->root_win
782 && event->xunmap.send_event)
783 withdraw = True;
785 if (wwin->client_win != event->xunmap.event && !withdraw)
786 return;
788 if (!wwin->flags.mapped && !withdraw
789 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
790 && !wwin->flags.miniaturized && !wwin->flags.hidden)
791 return;
793 XGrabServer(dpy);
794 XUnmapWindow(dpy, wwin->frame->core->window);
795 wwin->flags.mapped = 0;
796 XSync(dpy, 0);
797 /* check if the window was destroyed */
798 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
799 DispatchEvent(&ev);
800 } else {
801 Bool reparented = False;
803 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
804 reparented = True;
806 /* withdraw window */
807 wwin->flags.mapped = 0;
808 if (!reparented)
809 wClientSetState(wwin, WithdrawnState, None);
811 /* if the window was reparented, do not reparent it back to the
812 * root window */
813 wUnmanageWindow(wwin, !reparented, False);
815 XUngrabServer(dpy);
819 static void
820 handleConfigureRequest(XEvent *event)
822 WWindow *wwin;
823 #ifdef DEBUG
824 L("got configure request");
825 #endif
826 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
828 * Configure request for unmapped window
830 wClientConfigure(NULL, &(event->xconfigurerequest));
831 } else {
832 wClientConfigure(wwin, &(event->xconfigurerequest));
837 static void
838 handlePropertyNotify(XEvent *event)
840 WWindow *wwin;
841 WApplication *wapp;
842 Window jr;
843 int ji;
844 unsigned int ju;
845 WScreen *scr;
846 #ifdef DEBUG
847 L("got property notify");
848 #endif
849 if ((wwin=wWindowFor(event->xproperty.window))) {
850 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
851 &ju, &ju, &ju, &ju)) {
852 return;
854 wClientCheckProperty(wwin, &event->xproperty);
856 wapp = wApplicationOf(event->xproperty.window);
857 if (wapp) {
858 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
861 scr = wScreenForWindow(event->xproperty.window);
862 if (scr && scr->root_win == event->xproperty.window) {
863 #ifdef KWM_HINTS
864 wKWMCheckRootHintChange(scr, &event->xproperty);
865 #endif
870 static void
871 handleClientMessage(XEvent *event)
873 WWindow *wwin;
874 WObjDescriptor *desc;
875 #ifdef DEBUG
876 L("got client message");
877 #endif
878 /* handle transition from Normal to Iconic state */
879 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
880 && event->xclient.format == 32
881 && event->xclient.data.l[0] == IconicState) {
883 wwin = wWindowFor(event->xclient.window);
884 if (!wwin) return;
885 if (!wwin->flags.miniaturized)
886 wIconifyWindow(wwin);
887 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
888 && event->xclient.format == 32) {
889 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
891 if (!scr)
892 return;
894 if (event->xclient.data.l[1] == 1) { /* starting */
895 wColormapAllowClientInstallation(scr, True);
896 } else { /* stopping */
897 wColormapAllowClientInstallation(scr, False);
899 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
901 wDefaultsCheckDomains("bla");
903 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
904 WApplication *wapp;
905 int done=0;
906 wapp = wApplicationOf(event->xclient.window);
907 if (wapp) {
908 switch (event->xclient.data.l[0]) {
909 case WMFHideOtherApplications:
910 wHideOtherApplications(wapp->main_window_desc);
911 done = 1;
912 break;
914 case WMFHideApplication:
915 wHideApplication(wapp);
916 done = 1;
917 break;
920 if (!done) {
921 wwin = wWindowFor(event->xclient.window);
922 if (wwin) {
923 switch (event->xclient.data.l[0]) {
924 case WMFHideOtherApplications:
925 wHideOtherApplications(wwin);
926 break;
928 case WMFHideApplication:
929 wHideApplication(wApplicationOf(wwin->main_window));
930 break;
934 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
935 wwin = wWindowFor(event->xclient.window);
936 if (!wwin) return;
937 switch (event->xclient.data.l[0]) {
938 case GSWindowLevelAttr:
940 int level = (int)event->xclient.data.l[1];
942 if (WINDOW_LEVEL(wwin) != level) {
943 ChangeStackingLevel(wwin->frame->core, level);
946 break;
948 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
949 wwin = wWindowFor(event->xclient.window);
950 if (!wwin) return;
951 switch (event->xclient.data.l[0]) {
952 case WMTitleBarNormal:
953 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
954 break;
955 case WMTitleBarMain:
956 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
957 break;
958 case WMTitleBarKey:
959 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
960 break;
962 #ifdef GNOME_STUFF
963 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
964 /* do nothing */
965 #endif /* GNOME_STUFF */
966 #ifdef KWM_HINTS
967 } else if (wKWMProcessClientMessage(&event->xclient)) {
968 /* do nothing */
969 #endif /* KWM_HINTS */
970 #ifdef XDND
971 } else if (wXDNDProcessClientMessage(&event->xclient)) {
972 /* do nothing */
973 #endif /* XDND */
974 #ifdef OFFIX_DND
975 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
976 WScreen *scr = wScreenForWindow(event->xclient.window);
977 if (scr && wDockReceiveDNDDrop(scr,event))
978 goto redirect_message;
979 #endif /* OFFIX_DND */
980 } else {
981 #ifdef OFFIX_DND
982 redirect_message:
983 #endif
985 * Non-standard thing, but needed by OffiX DND.
986 * For when the icon frame gets a ClientMessage
987 * that should have gone to the icon_window.
989 if (XFindContext(dpy, event->xbutton.window, wWinContext,
990 (XPointer *)&desc)!=XCNOENT) {
991 struct WIcon *icon=NULL;
993 if (desc->parent_type == WCLASS_MINIWINDOW) {
994 icon = (WIcon*)desc->parent;
995 } else if (desc->parent_type == WCLASS_DOCK_ICON
996 || desc->parent_type == WCLASS_APPICON) {
997 icon = ((WAppIcon*)desc->parent)->icon;
999 if (icon && (wwin=icon->owner)) {
1000 if (wwin->client_win!=event->xclient.window) {
1001 event->xclient.window = wwin->client_win;
1002 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1003 event);
1011 static void
1012 raiseWindow(WScreen *scr)
1014 WWindow *wwin;
1016 scr->autoRaiseTimer = NULL;
1018 wwin = wWindowFor(scr->autoRaiseWindow);
1019 if (!wwin)
1020 return;
1022 if (!wwin->flags.destroyed && wwin->flags.focused) {
1023 wRaiseFrame(wwin->frame->core);
1024 /* this is needed or a race condition will occur */
1025 XSync(dpy, False);
1030 static void
1031 handleEnterNotify(XEvent *event)
1033 WWindow *wwin;
1034 WObjDescriptor *desc = NULL;
1035 XEvent ev;
1036 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1037 #ifdef DEBUG
1038 L("got enter notify");
1039 #endif
1041 #ifdef VIRTUAL_DESKTOP
1042 /* TODO: acceleration code */
1043 if (wPreferences.vedge_thickness) {
1044 int x,y;
1045 if (event->xcrossing.window == scr->virtual_edge_r) {
1046 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1047 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1048 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1049 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1050 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1051 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1052 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1053 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1054 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1055 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1056 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1057 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1058 printf("enter bottom\n");
1059 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1060 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1061 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1064 #endif
1066 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1067 &ev)) {
1068 /* already left the window... */
1069 saveTimestamp(&ev);
1070 if (ev.xcrossing.mode==event->xcrossing.mode
1071 && ev.xcrossing.detail==event->xcrossing.detail) {
1072 return;
1076 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1077 (XPointer *)&desc)!=XCNOENT) {
1078 if(desc->handle_enternotify)
1079 (*desc->handle_enternotify)(desc, event);
1082 /* enter to window */
1083 wwin = wWindowFor(event->xcrossing.window);
1084 if (!wwin) {
1085 if (wPreferences.colormap_mode==WCM_POINTER) {
1086 wColormapInstallForWindow(scr, NULL);
1088 if (scr->autoRaiseTimer
1089 && event->xcrossing.root==event->xcrossing.window) {
1090 WMDeleteTimerHandler(scr->autoRaiseTimer);
1091 scr->autoRaiseTimer = NULL;
1093 } else {
1094 /* set auto raise timer even if in focus-follows-mouse mode
1095 * and the event is for the frame window, even if the window
1096 * has focus already. useful if you move the pointer from a focused
1097 * window to the root window and back pretty fast
1099 * set focus if in focus-follows-mouse mode and the event
1100 * is for the frame window and window doesn't have focus yet */
1101 if (wPreferences.focus_mode==WKF_SLOPPY
1102 && wwin->frame->core->window==event->xcrossing.window
1103 && !scr->flags.doing_alt_tab) {
1105 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1106 wSetFocusTo(scr, wwin);
1108 if (scr->autoRaiseTimer)
1109 WMDeleteTimerHandler(scr->autoRaiseTimer);
1110 scr->autoRaiseTimer = NULL;
1112 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1113 scr->autoRaiseWindow = wwin->frame->core->window;
1114 scr->autoRaiseTimer
1115 = WMAddTimerHandler(wPreferences.raise_delay,
1116 (WMCallback*)raiseWindow, scr);
1119 /* Install colormap for window, if the colormap installation mode
1120 * is colormap_follows_mouse */
1121 if (wPreferences.colormap_mode==WCM_POINTER) {
1122 if (wwin->client_win==event->xcrossing.window)
1123 wColormapInstallForWindow(scr, wwin);
1124 else
1125 wColormapInstallForWindow(scr, NULL);
1129 /* a little kluge to hide the clip balloon */
1130 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1131 if (!desc) {
1132 XUnmapWindow(dpy, scr->clip_balloon);
1133 scr->flags.clip_balloon_mapped = 0;
1134 } else {
1135 if (desc->parent_type!=WCLASS_DOCK_ICON
1136 || scr->clip_icon != desc->parent) {
1137 XUnmapWindow(dpy, scr->clip_balloon);
1138 scr->flags.clip_balloon_mapped = 0;
1143 if (event->xcrossing.window == event->xcrossing.root
1144 && (event->xcrossing.mode == NotifyNormal ||
1145 event->xcrossing.mode == NotifyUngrab )
1146 && event->xcrossing.detail == NotifyInferior
1147 && wPreferences.focus_mode != WKF_CLICK) {
1148 wSetFocusTo(scr, NULL);
1151 #ifdef BALLOON_TEXT
1152 wBalloonEnteredObject(scr, desc);
1153 #endif
1157 static void
1158 handleLeaveNotify(XEvent *event)
1160 WObjDescriptor *desc = NULL;
1162 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1163 (XPointer *)&desc)!=XCNOENT) {
1164 if(desc->handle_leavenotify)
1165 (*desc->handle_leavenotify)(desc, event);
1170 #ifdef SHAPE
1171 static void
1172 handleShapeNotify(XEvent *event)
1174 XShapeEvent *shev = (XShapeEvent*)event;
1175 WWindow *wwin;
1176 XEvent ev;
1177 #ifdef DEBUG
1178 L("got shape notify");
1179 #endif
1180 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1181 XShapeEvent *sev = (XShapeEvent*)&ev;
1183 if (sev->kind == ShapeBounding) {
1184 if (sev->shaped == shev->shaped) {
1185 *shev = *sev;
1186 } else {
1187 XPutBackEvent(dpy, &ev);
1188 break;
1193 wwin = wWindowFor(shev->window);
1194 if (!wwin || shev->kind != ShapeBounding)
1195 return;
1197 if (!shev->shaped && wwin->flags.shaped) {
1199 wwin->flags.shaped = 0;
1200 wWindowClearShape(wwin);
1202 } else if (shev->shaped) {
1204 wwin->flags.shaped = 1;
1205 wWindowSetShape(wwin);
1208 #endif /* SHAPE */
1210 #ifdef KEEP_XKB_LOCK_STATUS
1211 /* please help ]d if you know what to do */
1212 handleXkbIndicatorStateNotify(XEvent *event)
1214 WWindow *wwin;
1215 WScreen *scr;
1216 XkbStateRec staterec;
1217 int i;
1219 for (i=0; i<wScreenCount; i++) {
1220 scr = wScreenWithNumber(i);
1221 wwin = scr->focused_window;
1222 if (wwin && wwin->flags.focused) {
1223 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1224 if (wwin->frame->languagemode != staterec.group) {
1225 wwin->frame->last_languagemode = wwin->frame->languagemode;
1226 wwin->frame->languagemode = staterec.group;
1228 #ifdef XKB_BUTTON_HINT
1229 if (wwin->frame->titlebar) {
1230 wFrameWindowPaint(wwin->frame);
1232 #endif
1236 #endif /*KEEP_XKB_LOCK_STATUS*/
1238 static void
1239 handleColormapNotify(XEvent *event)
1241 WWindow *wwin;
1242 WScreen *scr;
1243 Bool reinstall = False;
1245 wwin = wWindowFor(event->xcolormap.window);
1246 if (!wwin)
1247 return;
1249 scr = wwin->screen_ptr;
1251 do {
1252 if (wwin) {
1253 if (event->xcolormap.new) {
1254 XWindowAttributes attr;
1256 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1258 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1259 scr->current_colormap = attr.colormap;
1261 reinstall = True;
1262 } else if (event->xcolormap.state == ColormapUninstalled &&
1263 scr->current_colormap == event->xcolormap.colormap) {
1265 /* some bastard app (like XV) removed our colormap */
1267 * can't enforce or things like xscreensaver wont work
1268 * reinstall = True;
1270 } else if (event->xcolormap.state == ColormapInstalled &&
1271 scr->current_colormap == event->xcolormap.colormap) {
1273 /* someone has put our colormap back */
1274 reinstall = False;
1277 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1278 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1280 if (reinstall && scr->current_colormap!=None) {
1281 if (!scr->flags.colormap_stuff_blocked)
1282 XInstallColormap(dpy, scr->current_colormap);
1288 static void
1289 handleFocusIn(XEvent *event)
1291 WWindow *wwin;
1294 * For applications that like stealing the focus.
1296 while (XCheckTypedEvent(dpy, FocusIn, event));
1297 saveTimestamp(event);
1298 if (event->xfocus.mode == NotifyUngrab
1299 || event->xfocus.mode == NotifyGrab
1300 || event->xfocus.detail > NotifyNonlinearVirtual) {
1301 return;
1304 wwin = wWindowFor(event->xfocus.window);
1305 if (wwin && !wwin->flags.focused) {
1306 if (wwin->flags.mapped)
1307 wSetFocusTo(wwin->screen_ptr, wwin);
1308 else
1309 wSetFocusTo(wwin->screen_ptr, NULL);
1310 } else if (!wwin) {
1311 WScreen *scr = wScreenForWindow(event->xfocus.window);
1312 if (scr)
1313 wSetFocusTo(scr, NULL);
1318 static WWindow*
1319 windowUnderPointer(WScreen *scr)
1321 unsigned int mask;
1322 int foo;
1323 Window bar, win;
1325 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1326 &mask))
1327 return wWindowFor(win);
1328 return NULL;
1334 static void
1335 handleKeyPress(XEvent *event)
1337 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1338 WWindow *wwin = scr->focused_window;
1339 int i;
1340 int modifiers;
1341 int command=-1, index;
1342 #ifdef KEEP_XKB_LOCK_STATUS
1343 XkbStateRec staterec;
1344 #endif /*KEEP_XKB_LOCK_STATUS*/
1346 /* ignore CapsLock */
1347 modifiers = event->xkey.state & ValidModMask;
1349 for (i=0; i<WKBD_LAST; i++) {
1350 if (wKeyBindings[i].keycode==0)
1351 continue;
1353 if (wKeyBindings[i].keycode==event->xkey.keycode
1354 && (/*wKeyBindings[i].modifier==0
1355 ||*/ wKeyBindings[i].modifier==modifiers)) {
1356 command = i;
1357 break;
1362 if (command < 0) {
1363 #ifdef LITE
1365 #if 0
1367 #endif
1368 #else
1369 if (!wRootMenuPerformShortcut(event)) {
1370 #endif
1371 static int dontLoop = 0;
1373 if (dontLoop > 10) {
1374 wwarning("problem with key event processing code");
1375 return;
1377 dontLoop++;
1378 /* if the focused window is an internal window, try redispatching
1379 * the event to the managed window, as it can be a WINGs window */
1380 if (wwin && wwin->flags.internal_window
1381 && wwin->client_leader!=None) {
1382 /* client_leader contains the WINGs toplevel */
1383 event->xany.window = wwin->client_leader;
1384 WMHandleEvent(event);
1386 dontLoop--;
1388 return;
1391 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1392 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1394 switch (command) {
1395 #ifndef LITE
1396 case WKBD_ROOTMENU:
1397 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1399 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1400 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1402 break;
1403 case WKBD_WINDOWLIST:
1405 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1406 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1408 break;
1409 #endif /* !LITE */
1410 case WKBD_WINDOWMENU:
1411 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1412 OpenWindowMenu(wwin, wwin->frame_x,
1413 wwin->frame_y+wwin->frame->top_width, True);
1414 break;
1415 case WKBD_MINIATURIZE:
1416 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1417 && !WFLAGP(wwin, no_miniaturizable)) {
1418 CloseWindowMenu(scr);
1420 if (wwin->protocols.MINIATURIZE_WINDOW)
1421 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1422 event->xbutton.time);
1423 else {
1424 wIconifyWindow(wwin);
1427 break;
1428 case WKBD_HIDE:
1429 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1430 WApplication *wapp = wApplicationOf(wwin->main_window);
1431 CloseWindowMenu(scr);
1433 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1434 wHideApplication(wapp);
1437 break;
1438 case WKBD_HIDE_OTHERS:
1439 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1440 CloseWindowMenu(scr);
1442 wHideOtherApplications(wwin);
1444 break;
1445 case WKBD_MAXIMIZE:
1446 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1447 CloseWindowMenu(scr);
1449 if (wwin->flags.maximized) {
1450 wUnmaximizeWindow(wwin);
1451 } else {
1452 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1455 break;
1456 case WKBD_VMAXIMIZE:
1457 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1458 CloseWindowMenu(scr);
1460 if (wwin->flags.maximized) {
1461 wUnmaximizeWindow(wwin);
1462 } else {
1463 wMaximizeWindow(wwin, MAX_VERTICAL);
1466 break;
1467 case WKBD_HMAXIMIZE:
1468 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1469 CloseWindowMenu(scr);
1471 if (wwin->flags.maximized) {
1472 wUnmaximizeWindow(wwin);
1473 } else {
1474 wMaximizeWindow(wwin, MAX_HORIZONTAL);
1477 break;
1478 case WKBD_RAISE:
1479 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1480 CloseWindowMenu(scr);
1482 wRaiseFrame(wwin->frame->core);
1484 break;
1485 case WKBD_LOWER:
1486 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1487 CloseWindowMenu(scr);
1489 wLowerFrame(wwin->frame->core);
1491 break;
1492 case WKBD_RAISELOWER:
1493 /* raise or lower the window under the pointer, not the
1494 * focused one
1496 wwin = windowUnderPointer(scr);
1497 if (wwin)
1498 wRaiseLowerFrame(wwin->frame->core);
1499 break;
1500 case WKBD_SHADE:
1501 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1502 if (wwin->flags.shaded)
1503 wUnshadeWindow(wwin);
1504 else
1505 wShadeWindow(wwin);
1507 break;
1508 case WKBD_MOVERESIZE:
1509 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1510 CloseWindowMenu(scr);
1512 wKeyboardMoveResizeWindow(wwin);
1514 break;
1515 case WKBD_CLOSE:
1516 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1517 CloseWindowMenu(scr);
1518 if (wwin->protocols.DELETE_WINDOW)
1519 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1520 event->xkey.time);
1522 break;
1523 case WKBD_SELECT:
1524 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1525 wSelectWindow(wwin, !wwin->flags.selected);
1527 break;
1528 case WKBD_FOCUSNEXT:
1529 StartWindozeCycle(wwin, event, True);
1530 break;
1532 case WKBD_FOCUSPREV:
1533 StartWindozeCycle(wwin, event, False);
1534 break;
1536 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
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 #else
1543 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1544 i = (scr->current_workspace/10)*10 + wk - 1;\
1545 if (wPreferences.ws_advance || i<scr->workspace_count)\
1546 wWorkspaceChange(scr, i);\
1547 break
1548 #endif
1549 GOTOWORKS(1);
1550 GOTOWORKS(2);
1551 GOTOWORKS(3);
1552 GOTOWORKS(4);
1553 GOTOWORKS(5);
1554 GOTOWORKS(6);
1555 GOTOWORKS(7);
1556 GOTOWORKS(8);
1557 GOTOWORKS(9);
1558 GOTOWORKS(10);
1559 #undef GOTOWORKS
1560 case WKBD_NEXTWORKSPACE:
1561 wWorkspaceRelativeChange(scr, 1);
1562 break;
1563 case WKBD_PREVWORKSPACE:
1564 wWorkspaceRelativeChange(scr, -1);
1565 break;
1566 case WKBD_WINDOW1:
1567 case WKBD_WINDOW2:
1568 case WKBD_WINDOW3:
1569 case WKBD_WINDOW4:
1570 case WKBD_WINDOW5:
1571 case WKBD_WINDOW6:
1572 case WKBD_WINDOW7:
1573 case WKBD_WINDOW8:
1574 case WKBD_WINDOW9:
1575 case WKBD_WINDOW10:
1577 index = command-WKBD_WINDOW1;
1579 if (scr->shortcutWindows[index]) {
1580 WMArray *list = scr->shortcutWindows[index];
1581 int cw;
1582 int count = WMGetArrayItemCount(list);
1583 WWindow *twin;
1584 WMArrayIterator iter;
1585 WWindow *wwin;
1587 wUnselectWindows(scr);
1588 cw = scr->current_workspace;
1590 WM_ETARETI_ARRAY(list, wwin, iter) {
1591 if (count > 1)
1592 wWindowChangeWorkspace(wwin, cw);
1594 wMakeWindowVisible(wwin);
1596 if (count > 1)
1597 wSelectWindow(wwin, True);
1600 /* rotate the order of windows, to create a cycling effect */
1601 twin = WMGetFromArray(list, 0);
1602 WMDeleteFromArray(list, 0);
1603 WMAddToArray(list, twin);
1605 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1606 if (scr->shortcutWindows[index]) {
1607 WMFreeArray(scr->shortcutWindows[index]);
1608 scr->shortcutWindows[index] = NULL;
1611 if (wwin->flags.selected && scr->selected_windows) {
1612 scr->shortcutWindows[index] =
1613 WMDuplicateArray(scr->selected_windows);
1614 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1615 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1616 } else {
1617 scr->shortcutWindows[index] = WMCreateArray(4);
1618 WMAddToArray(scr->shortcutWindows[index], wwin);
1621 wSelectWindow(wwin, !wwin->flags.selected);
1622 XFlush(dpy);
1623 wusleep(3000);
1624 wSelectWindow(wwin, !wwin->flags.selected);
1625 XFlush(dpy);
1627 } else if (scr->selected_windows
1628 && WMGetArrayItemCount(scr->selected_windows)) {
1630 if (wwin->flags.selected && scr->selected_windows) {
1631 if (scr->shortcutWindows[index]) {
1632 WMFreeArray(scr->shortcutWindows[index]);
1634 scr->shortcutWindows[index] =
1635 WMDuplicateArray(scr->selected_windows);
1639 break;
1641 case WKBD_SWITCH_SCREEN:
1642 if (wScreenCount > 1) {
1643 WScreen *scr2;
1644 int i;
1646 /* find index of this screen */
1647 for (i = 0; i < wScreenCount; i++) {
1648 if (wScreenWithNumber(i) == scr)
1649 break;
1651 i++;
1652 if (i >= wScreenCount) {
1653 i = 0;
1655 scr2 = wScreenWithNumber(i);
1657 if (scr2) {
1658 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1659 scr2->scr_width/2, scr2->scr_height/2);
1662 break;
1664 case WKBD_NEXTWSLAYER:
1665 case WKBD_PREVWSLAYER:
1667 int row, column;
1669 row = scr->current_workspace/10;
1670 column = scr->current_workspace%10;
1672 if (command==WKBD_NEXTWSLAYER) {
1673 if ((row+1)*10 < scr->workspace_count)
1674 wWorkspaceChange(scr, column+(row+1)*10);
1675 } else {
1676 if (row > 0)
1677 wWorkspaceChange(scr, column+(row-1)*10);
1680 break;
1681 case WKBD_CLIPLOWER:
1682 if (!wPreferences.flags.noclip)
1683 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1684 break;
1685 case WKBD_CLIPRAISE:
1686 if (!wPreferences.flags.noclip)
1687 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1688 break;
1689 case WKBD_CLIPRAISELOWER:
1690 if (!wPreferences.flags.noclip)
1691 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1692 break;
1693 #ifdef KEEP_XKB_LOCK_STATUS
1694 case WKBD_TOGGLE:
1695 if(wPreferences.modelock) {
1696 /*toggle*/
1697 wwin = scr->focused_window;
1699 if (wwin && wwin->flags.mapped
1700 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1701 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1702 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1704 wwin->frame->languagemode = wwin->frame->last_languagemode;
1705 wwin->frame->last_languagemode = staterec.group;
1706 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1710 break;
1711 #endif /* KEEP_XKB_LOCK_STATUS */
1717 static void
1718 handleMotionNotify(XEvent *event)
1720 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1722 if (wPreferences.scrollable_menus) {
1723 WMPoint p = { event->xmotion.x_root, event->xmotion.y_root };
1724 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1726 if (scr->flags.jump_back_pending ||
1727 p.x <= (rect.pos.x + 1) ||
1728 p.x >= (rect.pos.x + rect.size.width - 2) ||
1729 p.y <= (rect.pos.y + 1) ||
1730 p.y >= (rect.pos.y + rect.size.height - 2)) {
1731 WMenu *menu;
1732 #ifdef DEBUG
1733 L("pointer at screen edge");
1734 #endif
1735 menu = wMenuUnderPointer(scr);
1736 if (menu!=NULL)
1737 wMenuScroll(menu, event);
1740 #if 0
1741 if (event->xmotion.subwindow == None)
1742 return;
1744 if (scr->scrolledFMaximize != None) {
1745 WWindow *twin;
1747 twin = wWindowFor(scr->scrolledFMaximize);
1748 if (twin && twin->frame_y ==) {
1752 scr->scrolledFMaximize = NULL;
1754 } else {
1756 /* scroll full maximized window */
1757 if (event->xmotion.y_root < 1
1758 || event->xmotion.y_root > scr->scr_height - 1) {
1760 wwin = wWindowFor(event->xmotion.subwindow);
1762 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1763 && WFLAGP(wwin, full_maximize)
1764 && event->xmotion.x_root >= wwin->frame_x
1765 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1767 if (!WFLAGP(wwin, no_titlebar)
1768 && wwin->frame_y <= - wwin->frame->top_width) {
1770 wWindowMove(wwin, wwin->frame_x, 0);
1771 wwin->flags.dragged_while_fmaximized = 0;
1773 } else if (!WFLAGP(wwin, no_resizebar)
1774 && wwin->frame_y + wwin->frame->core->height >=
1775 scr->scr_height + wwin->frame->bottom_width) {
1777 int y = scr->scr_height + wwin->frame->bottom_width;
1779 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1781 wWindowMove(wwin, wwin->frame_x, y);
1782 wwin->flags.dragged_while_fmaximized = 0;
1786 #endif
1790 static void
1791 handleVisibilityNotify(XEvent *event)
1793 WWindow *wwin;
1795 wwin = wWindowFor(event->xvisibility.window);
1796 if (!wwin)
1797 return;
1798 wwin->flags.obscured =
1799 (event->xvisibility.state == VisibilityFullyObscured);