- Removed the following 3 options from configuration: SelectWindowsMouseButton,
[wmaker-crm.git] / src / event.c
blobea1a239b64da6d3cbfd977cdcae3de0d451da067
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 void
443 handleExtensions(XEvent *event)
445 #ifdef KEEP_XKB_LOCK_STATUS
446 XkbEvent *xkbevent;
447 xkbevent = (XkbEvent *)event;
448 #endif /*KEEP_XKB_LOCK_STATUS*/
449 #ifdef SHAPE
450 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
451 handleShapeNotify(event);
453 #endif
454 #ifdef KEEP_XKB_LOCK_STATUS
455 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
456 handleXkbIndicatorStateNotify(event);
458 #endif /*KEEP_XKB_LOCK_STATUS*/
462 static void
463 handleMapRequest(XEvent *ev)
465 WWindow *wwin;
466 WScreen *scr = NULL;
467 Window window = ev->xmaprequest.window;
469 #ifdef DEBUG
470 L("got map request for %x\n", (unsigned)window);
471 #endif
472 if ((wwin = wWindowFor(window))) {
473 if (wwin->flags.shaded) {
474 wUnshadeWindow(wwin);
476 /* deiconify window */
477 if (wwin->flags.miniaturized) {
478 wDeiconifyWindow(wwin);
479 } else if (wwin->flags.hidden) {
480 WApplication *wapp = wApplicationOf(wwin->main_window);
481 /* go to the last workspace that the user worked on the app */
482 if (wapp) {
483 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
485 wUnhideApplication(wapp, False, False);
487 return;
490 scr = wScreenForRootWindow(ev->xmaprequest.parent);
492 wwin = wManageWindow(scr, window);
495 * This is to let the Dock know that the application it launched
496 * has already been mapped (eg: it has finished launching).
497 * It is not necessary for normally docked apps, but is needed for
498 * apps that were forcedly docked (like with dockit).
500 if (scr->last_dock) {
501 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
502 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
503 else
504 wDockTrackWindowLaunch(scr->last_dock, window);
507 if (wwin) {
508 wClientSetState(wwin, NormalState, None);
509 if (wwin->flags.maximized) {
510 wMaximizeWindow(wwin, wwin->flags.maximized);
512 if (wwin->flags.shaded) {
513 wwin->flags.shaded = 0;
514 wwin->flags.skip_next_animation = 1;
515 wShadeWindow(wwin);
517 if (wwin->flags.miniaturized) {
518 wwin->flags.miniaturized = 0;
519 wwin->flags.skip_next_animation = 1;
520 wIconifyWindow(wwin);
522 if (wwin->flags.hidden) {
523 WApplication *wapp = wApplicationOf(wwin->main_window);
525 wwin->flags.hidden = 0;
526 wwin->flags.skip_next_animation = 1;
527 if (wapp) {
528 wHideApplication(wapp);
535 static void
536 handleDestroyNotify(XEvent *event)
538 WWindow *wwin;
539 WApplication *app;
540 Window window = event->xdestroywindow.window;
542 #ifdef DEBUG
543 L("got destroy notify");
544 #endif
545 wwin = wWindowFor(window);
546 if (wwin) {
547 wUnmanageWindow(wwin, False, True);
550 app = wApplicationOf(window);
551 if (app) {
552 if (window == app->main_window) {
553 app->refcount = 0;
554 wwin = app->main_window_desc->screen_ptr->focused_window;
555 while (wwin) {
556 if (wwin->main_window == window) {
557 wwin->main_window = None;
559 wwin = wwin->prev;
562 wApplicationDestroy(app);
565 #ifdef KWM_HINTS
566 wKWMCheckDestroy(&event->xdestroywindow);
567 #endif
572 static void
573 handleExpose(XEvent *event)
575 WObjDescriptor *desc;
576 XEvent ev;
578 #ifdef DEBUG
579 L("got expose");
580 #endif
581 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
583 if (XFindContext(dpy, event->xexpose.window, wWinContext,
584 (XPointer *)&desc)==XCNOENT) {
585 return;
588 if (desc->handle_expose) {
589 (*desc->handle_expose)(desc, event);
593 static void
594 executeButtonAction(WScreen *scr, XEvent *event, int action)
596 switch(action) {
597 case WA_SELECT_WINDOWS:
598 wUnselectWindows(scr);
599 wSelectWindows(scr, event);
600 break;
601 case WA_OPEN_APPMENU:
602 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
603 /* ugly hack */
604 if (scr->root_menu) {
605 if (scr->root_menu->brother->flags.mapped)
606 event->xbutton.window = scr->root_menu->brother->frame->core->window;
607 else
608 event->xbutton.window = scr->root_menu->frame->core->window;
610 break;
611 case WA_OPEN_WINLISTMENU:
612 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
613 if (scr->switch_menu) {
614 if (scr->switch_menu->brother->flags.mapped)
615 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
616 else
617 event->xbutton.window = scr->switch_menu->frame->core->window;
619 break;
620 default:
621 break;
626 /* bindable */
627 static void
628 handleButtonPress(XEvent *event)
630 WObjDescriptor *desc;
631 WScreen *scr;
633 #ifdef DEBUG
634 L("got button press");
635 #endif
636 scr = wScreenForRootWindow(event->xbutton.root);
638 #ifdef BALLOON_TEXT
639 wBalloonHide(scr);
640 #endif
643 #ifndef LITE
644 if (event->xbutton.window==scr->root_win) {
645 if (event->xbutton.button==Button1 &&
646 wPreferences.mouse_button1!=WA_NONE) {
647 executeButtonAction(scr, event, wPreferences.mouse_button1);
648 } else if (event->xbutton.button==Button2 &&
649 wPreferences.mouse_button2!=WA_NONE) {
650 executeButtonAction(scr, event, wPreferences.mouse_button2);
651 } else if (event->xbutton.button==Button3 &&
652 wPreferences.mouse_button3!=WA_NONE) {
653 executeButtonAction(scr, event, wPreferences.mouse_button3);
654 } else if (event->xbutton.button==Button4 &&
655 wPreferences.mouse_wheel!=WA_NONE) {
656 wWorkspaceRelativeChange(scr, 1);
657 } else if (event->xbutton.button==Button5 &&
658 wPreferences.mouse_wheel!=WA_NONE) {
659 wWorkspaceRelativeChange(scr, -1);
661 #ifdef GNOME_STUFF
662 else if (wGNOMEProxyizeButtonEvent(scr, event))
663 return;
664 #endif
666 #endif /* !LITE */
668 desc = NULL;
669 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
670 (XPointer *)&desc)==XCNOENT) {
671 if (XFindContext(dpy, event->xbutton.window, wWinContext,
672 (XPointer *)&desc)==XCNOENT) {
673 return;
677 if (desc->parent_type == WCLASS_WINDOW) {
678 XSync(dpy, 0);
680 if (event->xbutton.state & MOD_MASK) {
681 XAllowEvents(dpy, AsyncPointer, CurrentTime);
684 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
685 if (wPreferences.ignore_focus_click) {
686 XAllowEvents(dpy, AsyncPointer, CurrentTime);
688 XAllowEvents(dpy, ReplayPointer, CurrentTime);
689 /* }*/
690 XSync(dpy, 0);
691 } else if (desc->parent_type == WCLASS_APPICON
692 || desc->parent_type == WCLASS_MINIWINDOW
693 || desc->parent_type == WCLASS_DOCK_ICON) {
694 if (event->xbutton.state & MOD_MASK) {
695 XSync(dpy, 0);
696 XAllowEvents(dpy, AsyncPointer, CurrentTime);
697 XSync(dpy, 0);
701 if (desc->handle_mousedown!=NULL) {
702 (*desc->handle_mousedown)(desc, event);
705 /* save double-click information */
706 if (scr->flags.next_click_is_not_double) {
707 scr->flags.next_click_is_not_double = 0;
708 } else {
709 scr->last_click_time = event->xbutton.time;
710 scr->last_click_button = event->xbutton.button;
711 scr->last_click_window = event->xbutton.window;
716 static void
717 handleMapNotify(XEvent *event)
719 WWindow *wwin;
720 #ifdef DEBUG
721 L("got map");
722 #endif
723 wwin = wWindowFor(event->xmap.event);
724 if (wwin && wwin->client_win == event->xmap.event) {
725 if (wwin->flags.miniaturized) {
726 wDeiconifyWindow(wwin);
727 } else {
728 XGrabServer(dpy);
729 wWindowMap(wwin);
730 wClientSetState(wwin, NormalState, None);
731 XUngrabServer(dpy);
737 static void
738 handleUnmapNotify(XEvent *event)
740 WWindow *wwin;
741 XEvent ev;
742 Bool withdraw = False;
743 #ifdef DEBUG
744 L("got unmap");
745 #endif
746 /* only process windows with StructureNotify selected
747 * (ignore SubstructureNotify) */
748 wwin = wWindowFor(event->xunmap.window);
749 if (!wwin)
750 return;
752 /* whether the event is a Withdrawal request */
753 if (event->xunmap.event == wwin->screen_ptr->root_win
754 && event->xunmap.send_event)
755 withdraw = True;
757 if (wwin->client_win != event->xunmap.event && !withdraw)
758 return;
760 if (!wwin->flags.mapped && !withdraw
761 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
762 && !wwin->flags.miniaturized && !wwin->flags.hidden)
763 return;
765 XGrabServer(dpy);
766 XUnmapWindow(dpy, wwin->frame->core->window);
767 wwin->flags.mapped = 0;
768 XSync(dpy, 0);
769 /* check if the window was destroyed */
770 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
771 DispatchEvent(&ev);
772 } else {
773 Bool reparented = False;
775 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
776 reparented = True;
778 /* withdraw window */
779 wwin->flags.mapped = 0;
780 if (!reparented)
781 wClientSetState(wwin, WithdrawnState, None);
783 /* if the window was reparented, do not reparent it back to the
784 * root window */
785 wUnmanageWindow(wwin, !reparented, False);
787 XUngrabServer(dpy);
791 static void
792 handleConfigureRequest(XEvent *event)
794 WWindow *wwin;
795 #ifdef DEBUG
796 L("got configure request");
797 #endif
798 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
800 * Configure request for unmapped window
802 wClientConfigure(NULL, &(event->xconfigurerequest));
803 } else {
804 wClientConfigure(wwin, &(event->xconfigurerequest));
809 static void
810 handlePropertyNotify(XEvent *event)
812 WWindow *wwin;
813 WApplication *wapp;
814 Window jr;
815 int ji;
816 unsigned int ju;
817 WScreen *scr;
818 #ifdef DEBUG
819 L("got property notify");
820 #endif
821 if ((wwin=wWindowFor(event->xproperty.window))) {
822 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
823 &ju, &ju, &ju, &ju)) {
824 return;
826 wClientCheckProperty(wwin, &event->xproperty);
828 wapp = wApplicationOf(event->xproperty.window);
829 if (wapp) {
830 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
833 scr = wScreenForWindow(event->xproperty.window);
834 if (scr && scr->root_win == event->xproperty.window) {
835 #ifdef KWM_HINTS
836 wKWMCheckRootHintChange(scr, &event->xproperty);
837 #endif
842 static void
843 handleClientMessage(XEvent *event)
845 WWindow *wwin;
846 WObjDescriptor *desc;
847 #ifdef DEBUG
848 L("got client message");
849 #endif
850 /* handle transition from Normal to Iconic state */
851 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
852 && event->xclient.format == 32
853 && event->xclient.data.l[0] == IconicState) {
855 wwin = wWindowFor(event->xclient.window);
856 if (!wwin) return;
857 if (!wwin->flags.miniaturized)
858 wIconifyWindow(wwin);
859 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
860 && event->xclient.format == 32) {
861 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
863 if (!scr)
864 return;
866 if (event->xclient.data.l[1] == 1) { /* starting */
867 wColormapAllowClientInstallation(scr, True);
868 } else { /* stopping */
869 wColormapAllowClientInstallation(scr, False);
871 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
873 wDefaultsCheckDomains("bla");
875 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
876 WApplication *wapp;
877 int done=0;
878 wapp = wApplicationOf(event->xclient.window);
879 if (wapp) {
880 switch (event->xclient.data.l[0]) {
881 case WMFHideOtherApplications:
882 wHideOtherApplications(wapp->main_window_desc);
883 done = 1;
884 break;
886 case WMFHideApplication:
887 wHideApplication(wapp);
888 done = 1;
889 break;
892 if (!done) {
893 wwin = wWindowFor(event->xclient.window);
894 if (wwin) {
895 switch (event->xclient.data.l[0]) {
896 case WMFHideOtherApplications:
897 wHideOtherApplications(wwin);
898 break;
900 case WMFHideApplication:
901 wHideApplication(wApplicationOf(wwin->main_window));
902 break;
906 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
907 wwin = wWindowFor(event->xclient.window);
908 if (!wwin) return;
909 switch (event->xclient.data.l[0]) {
910 case GSWindowLevelAttr:
912 int level = (int)event->xclient.data.l[1];
914 if (WINDOW_LEVEL(wwin) != level) {
915 ChangeStackingLevel(wwin->frame->core, level);
918 break;
920 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
921 wwin = wWindowFor(event->xclient.window);
922 if (!wwin) return;
923 switch (event->xclient.data.l[0]) {
924 case WMTitleBarNormal:
925 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
926 break;
927 case WMTitleBarMain:
928 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
929 break;
930 case WMTitleBarKey:
931 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
932 break;
934 #ifdef GNOME_STUFF
935 } else if (wGNOMEProcessClientMessage(&event->xclient)) {
936 /* do nothing */
937 #endif /* GNOME_STUFF */
938 #ifdef KWM_HINTS
939 } else if (wKWMProcessClientMessage(&event->xclient)) {
940 /* do nothing */
941 #endif /* KWM_HINTS */
942 #ifdef XDND
943 } else if (wXDNDProcessClientMessage(&event->xclient)) {
944 /* do nothing */
945 #endif /* XDND */
946 #ifdef OFFIX_DND
947 } else if (event->xclient.message_type==_XA_DND_PROTOCOL) {
948 WScreen *scr = wScreenForWindow(event->xclient.window);
949 if (scr && wDockReceiveDNDDrop(scr,event))
950 goto redirect_message;
951 #endif /* OFFIX_DND */
952 } else {
953 #ifdef OFFIX_DND
954 redirect_message:
955 #endif
957 * Non-standard thing, but needed by OffiX DND.
958 * For when the icon frame gets a ClientMessage
959 * that should have gone to the icon_window.
961 if (XFindContext(dpy, event->xbutton.window, wWinContext,
962 (XPointer *)&desc)!=XCNOENT) {
963 struct WIcon *icon=NULL;
965 if (desc->parent_type == WCLASS_MINIWINDOW) {
966 icon = (WIcon*)desc->parent;
967 } else if (desc->parent_type == WCLASS_DOCK_ICON
968 || desc->parent_type == WCLASS_APPICON) {
969 icon = ((WAppIcon*)desc->parent)->icon;
971 if (icon && (wwin=icon->owner)) {
972 if (wwin->client_win!=event->xclient.window) {
973 event->xclient.window = wwin->client_win;
974 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
975 event);
983 static void
984 raiseWindow(WScreen *scr)
986 WWindow *wwin;
988 scr->autoRaiseTimer = NULL;
990 wwin = wWindowFor(scr->autoRaiseWindow);
991 if (!wwin)
992 return;
994 if (!wwin->flags.destroyed && wwin->flags.focused) {
995 wRaiseFrame(wwin->frame->core);
996 /* this is needed or a race condition will occur */
997 XSync(dpy, False);
1002 static void
1003 handleEnterNotify(XEvent *event)
1005 WWindow *wwin;
1006 WObjDescriptor *desc = NULL;
1007 XEvent ev;
1008 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1009 #ifdef DEBUG
1010 L("got enter notify");
1011 #endif
1013 #ifdef VIRTUAL_DESKTOP
1014 /* TODO: acceleration code */
1015 if (wPreferences.vedge_thickness) {
1016 int x,y;
1017 if (event->xcrossing.window == scr->virtual_edge_r) {
1018 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, scr->scr_width - wPreferences.vedge_thickness - 1, event->xcrossing.y_root);
1019 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1020 wWorkspaceSetViewPort(scr, scr->current_workspace, x + VIRTUALEDGE_SCROLL_HSTEP, y);
1021 } else if (event->xcrossing.window == scr->virtual_edge_l) {
1022 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, wPreferences.vedge_thickness + 1, event->xcrossing.y_root);
1023 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1024 wWorkspaceSetViewPort(scr, scr->current_workspace, x - VIRTUALEDGE_SCROLL_HSTEP, y);
1025 } else if (event->xcrossing.window == scr->virtual_edge_u) {
1026 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, wPreferences.vedge_thickness + 1);
1027 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1028 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y - VIRTUALEDGE_SCROLL_VSTEP);
1029 } else if (event->xcrossing.window == scr->virtual_edge_d) {
1030 printf("enter bottom\n");
1031 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, event->xcrossing.x_root, scr->scr_height - wPreferences.vedge_thickness - 1);
1032 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1033 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y + VIRTUALEDGE_SCROLL_VSTEP);
1036 #endif
1038 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1039 &ev)) {
1040 /* already left the window... */
1041 saveTimestamp(&ev);
1042 if (ev.xcrossing.mode==event->xcrossing.mode
1043 && ev.xcrossing.detail==event->xcrossing.detail) {
1044 return;
1048 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1049 (XPointer *)&desc)!=XCNOENT) {
1050 if(desc->handle_enternotify)
1051 (*desc->handle_enternotify)(desc, event);
1054 /* enter to window */
1055 wwin = wWindowFor(event->xcrossing.window);
1056 if (!wwin) {
1057 if (wPreferences.focus_mode==WKF_POINTER
1058 && event->xcrossing.window==event->xcrossing.root) {
1059 wSetFocusTo(scr, NULL);
1061 if (wPreferences.colormap_mode==WKF_POINTER) {
1062 wColormapInstallForWindow(scr, NULL);
1064 if (scr->autoRaiseTimer
1065 && event->xcrossing.root==event->xcrossing.window) {
1066 WMDeleteTimerHandler(scr->autoRaiseTimer);
1067 scr->autoRaiseTimer = NULL;
1069 } else {
1070 /* set auto raise timer even if in focus-follows-mouse mode
1071 * and the event is for the frame window, even if the window
1072 * has focus already. useful if you move the pointer from a focused
1073 * window to the root window and back pretty fast
1075 * set focus if in focus-follows-mouse mode and the event
1076 * is for the frame window and window doesn't have focus yet */
1077 if ((wPreferences.focus_mode==WKF_POINTER
1078 || wPreferences.focus_mode==WKF_SLOPPY)
1079 && wwin->frame->core->window==event->xcrossing.window
1080 && !scr->flags.doing_alt_tab) {
1082 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1083 wSetFocusTo(scr, wwin);
1085 if (scr->autoRaiseTimer)
1086 WMDeleteTimerHandler(scr->autoRaiseTimer);
1087 scr->autoRaiseTimer = NULL;
1089 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1090 scr->autoRaiseWindow = wwin->frame->core->window;
1091 scr->autoRaiseTimer
1092 = WMAddTimerHandler(wPreferences.raise_delay,
1093 (WMCallback*)raiseWindow, scr);
1096 /* Install colormap for window, if the colormap installation mode
1097 * is colormap_follows_mouse */
1098 if (wPreferences.colormap_mode==WKF_POINTER) {
1099 if (wwin->client_win==event->xcrossing.window)
1100 wColormapInstallForWindow(scr, wwin);
1101 else
1102 wColormapInstallForWindow(scr, NULL);
1106 /* a little kluge to hide the clip balloon */
1107 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1108 if (!desc) {
1109 XUnmapWindow(dpy, scr->clip_balloon);
1110 scr->flags.clip_balloon_mapped = 0;
1111 } else {
1112 if (desc->parent_type!=WCLASS_DOCK_ICON
1113 || scr->clip_icon != desc->parent) {
1114 XUnmapWindow(dpy, scr->clip_balloon);
1115 scr->flags.clip_balloon_mapped = 0;
1120 if (event->xcrossing.window == event->xcrossing.root
1121 && event->xcrossing.detail == NotifyNormal
1122 && event->xcrossing.detail != NotifyInferior
1123 && wPreferences.focus_mode != WKF_CLICK) {
1125 wSetFocusTo(scr, scr->focused_window);
1128 #ifdef BALLOON_TEXT
1129 wBalloonEnteredObject(scr, desc);
1130 #endif
1134 static void
1135 handleLeaveNotify(XEvent *event)
1137 WObjDescriptor *desc = NULL;
1139 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1140 (XPointer *)&desc)!=XCNOENT) {
1141 if(desc->handle_leavenotify)
1142 (*desc->handle_leavenotify)(desc, event);
1144 if (event->xcrossing.window == event->xcrossing.root
1145 && event->xcrossing.mode == NotifyNormal
1146 && event->xcrossing.detail != NotifyInferior
1147 && wPreferences.focus_mode != WKF_CLICK) {
1149 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1151 wSetFocusTo(scr, NULL);
1156 #ifdef SHAPE
1157 static void
1158 handleShapeNotify(XEvent *event)
1160 XShapeEvent *shev = (XShapeEvent*)event;
1161 WWindow *wwin;
1162 XEvent ev;
1163 #ifdef DEBUG
1164 L("got shape notify");
1165 #endif
1166 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1167 XShapeEvent *sev = (XShapeEvent*)&ev;
1169 if (sev->kind == ShapeBounding) {
1170 if (sev->shaped == shev->shaped) {
1171 *shev = *sev;
1172 } else {
1173 XPutBackEvent(dpy, &ev);
1174 break;
1179 wwin = wWindowFor(shev->window);
1180 if (!wwin || shev->kind != ShapeBounding)
1181 return;
1183 if (!shev->shaped && wwin->flags.shaped) {
1185 wwin->flags.shaped = 0;
1186 wWindowClearShape(wwin);
1188 } else if (shev->shaped) {
1190 wwin->flags.shaped = 1;
1191 wWindowSetShape(wwin);
1194 #endif /* SHAPE */
1196 #ifdef KEEP_XKB_LOCK_STATUS
1197 /* please help ]d if you know what to do */
1198 handleXkbIndicatorStateNotify(XEvent *event)
1200 WWindow *wwin;
1201 WScreen *scr;
1202 XkbStateRec staterec;
1203 int i;
1205 for (i=0; i<wScreenCount; i++) {
1206 scr = wScreenWithNumber(i);
1207 wwin = scr->focused_window;
1208 if (wwin && wwin->flags.focused) {
1209 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1210 if (wwin->frame->languagemode != staterec.group) {
1211 wwin->frame->last_languagemode = wwin->frame->languagemode;
1212 wwin->frame->languagemode = staterec.group;
1214 #ifdef XKB_BUTTON_HINT
1215 if (wwin->frame->titlebar) {
1216 wFrameWindowPaint(wwin->frame);
1218 #endif
1222 #endif /*KEEP_XKB_LOCK_STATUS*/
1224 static void
1225 handleColormapNotify(XEvent *event)
1227 WWindow *wwin;
1228 WScreen *scr;
1229 Bool reinstall = False;
1231 wwin = wWindowFor(event->xcolormap.window);
1232 if (!wwin)
1233 return;
1235 scr = wwin->screen_ptr;
1237 do {
1238 if (wwin) {
1239 if (event->xcolormap.new) {
1240 XWindowAttributes attr;
1242 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1244 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1245 scr->current_colormap = attr.colormap;
1247 reinstall = True;
1248 } else if (event->xcolormap.state == ColormapUninstalled &&
1249 scr->current_colormap == event->xcolormap.colormap) {
1251 /* some bastard app (like XV) removed our colormap */
1253 * can't enforce or things like xscreensaver wont work
1254 * reinstall = True;
1256 } else if (event->xcolormap.state == ColormapInstalled &&
1257 scr->current_colormap == event->xcolormap.colormap) {
1259 /* someone has put our colormap back */
1260 reinstall = False;
1263 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1264 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1266 if (reinstall && scr->current_colormap!=None) {
1267 if (!scr->flags.colormap_stuff_blocked)
1268 XInstallColormap(dpy, scr->current_colormap);
1274 static void
1275 handleFocusIn(XEvent *event)
1277 WWindow *wwin;
1280 * For applications that like stealing the focus.
1282 while (XCheckTypedEvent(dpy, FocusIn, event));
1283 saveTimestamp(event);
1284 if (event->xfocus.mode == NotifyUngrab
1285 || event->xfocus.mode == NotifyGrab
1286 || event->xfocus.detail > NotifyNonlinearVirtual) {
1287 return;
1290 wwin = wWindowFor(event->xfocus.window);
1291 if (wwin && !wwin->flags.focused) {
1292 if (wwin->flags.mapped)
1293 wSetFocusTo(wwin->screen_ptr, wwin);
1294 else
1295 wSetFocusTo(wwin->screen_ptr, NULL);
1296 } else if (!wwin) {
1297 WScreen *scr = wScreenForWindow(event->xfocus.window);
1298 if (scr)
1299 wSetFocusTo(scr, NULL);
1304 static WWindow*
1305 windowUnderPointer(WScreen *scr)
1307 unsigned int mask;
1308 int foo;
1309 Window bar, win;
1311 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1312 &mask))
1313 return wWindowFor(win);
1314 return NULL;
1320 static void
1321 handleKeyPress(XEvent *event)
1323 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1324 WWindow *wwin = scr->focused_window;
1325 int i;
1326 int modifiers;
1327 int command=-1, index;
1328 #ifdef KEEP_XKB_LOCK_STATUS
1329 XkbStateRec staterec;
1330 #endif /*KEEP_XKB_LOCK_STATUS*/
1332 /* ignore CapsLock */
1333 modifiers = event->xkey.state & ValidModMask;
1335 for (i=0; i<WKBD_LAST; i++) {
1336 if (wKeyBindings[i].keycode==0)
1337 continue;
1339 if (wKeyBindings[i].keycode==event->xkey.keycode
1340 && (/*wKeyBindings[i].modifier==0
1341 ||*/ wKeyBindings[i].modifier==modifiers)) {
1342 command = i;
1343 break;
1348 if (command < 0) {
1349 #ifdef LITE
1351 #if 0
1353 #endif
1354 #else
1355 if (!wRootMenuPerformShortcut(event)) {
1356 #endif
1357 static int dontLoop = 0;
1359 if (dontLoop > 10) {
1360 wwarning("problem with key event processing code");
1361 return;
1363 dontLoop++;
1364 /* if the focused window is an internal window, try redispatching
1365 * the event to the managed window, as it can be a WINGs window */
1366 if (wwin && wwin->flags.internal_window
1367 && wwin->client_leader!=None) {
1368 /* client_leader contains the WINGs toplevel */
1369 event->xany.window = wwin->client_leader;
1370 WMHandleEvent(event);
1372 dontLoop--;
1374 return;
1377 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1378 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1380 switch (command) {
1381 #ifndef LITE
1382 case WKBD_ROOTMENU:
1383 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1384 OpenRootMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1385 break;
1386 case WKBD_WINDOWLIST:
1387 /*OpenSwitchMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1388 OpenSwitchMenu(scr, scr->scr_width/2, scr->scr_height/2, True);
1389 break;
1390 #endif /* !LITE */
1391 case WKBD_WINDOWMENU:
1392 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1393 OpenWindowMenu(wwin, wwin->frame_x,
1394 wwin->frame_y+wwin->frame->top_width, True);
1395 break;
1396 case WKBD_MINIATURIZE:
1397 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1398 && !WFLAGP(wwin, no_miniaturizable)) {
1399 CloseWindowMenu(scr);
1401 if (wwin->protocols.MINIATURIZE_WINDOW)
1402 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1403 event->xbutton.time);
1404 else {
1405 wIconifyWindow(wwin);
1408 break;
1409 case WKBD_HIDE:
1410 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1411 WApplication *wapp = wApplicationOf(wwin->main_window);
1412 CloseWindowMenu(scr);
1414 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1415 wHideApplication(wapp);
1418 break;
1419 case WKBD_MAXIMIZE:
1420 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1421 CloseWindowMenu(scr);
1423 if (wwin->flags.maximized) {
1424 wUnmaximizeWindow(wwin);
1425 } else {
1426 wMaximizeWindow(wwin, MAX_VERTICAL|MAX_HORIZONTAL);
1429 break;
1430 case WKBD_VMAXIMIZE:
1431 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_resizable)) {
1432 CloseWindowMenu(scr);
1434 if (wwin->flags.maximized) {
1435 wUnmaximizeWindow(wwin);
1436 } else {
1437 wMaximizeWindow(wwin, MAX_VERTICAL);
1440 break;
1441 case WKBD_RAISE:
1442 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1443 CloseWindowMenu(scr);
1445 wRaiseFrame(wwin->frame->core);
1447 break;
1448 case WKBD_LOWER:
1449 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1450 CloseWindowMenu(scr);
1452 wLowerFrame(wwin->frame->core);
1454 break;
1455 case WKBD_RAISELOWER:
1456 /* raise or lower the window under the pointer, not the
1457 * focused one
1459 wwin = windowUnderPointer(scr);
1460 if (wwin)
1461 wRaiseLowerFrame(wwin->frame->core);
1462 break;
1463 case WKBD_SHADE:
1464 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1465 if (wwin->flags.shaded)
1466 wUnshadeWindow(wwin);
1467 else
1468 wShadeWindow(wwin);
1470 break;
1471 case WKBD_MOVERESIZE:
1472 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1473 CloseWindowMenu(scr);
1475 wKeyboardMoveResizeWindow(wwin);
1477 break;
1478 case WKBD_CLOSE:
1479 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1480 CloseWindowMenu(scr);
1481 if (wwin->protocols.DELETE_WINDOW)
1482 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1483 event->xkey.time);
1485 break;
1486 case WKBD_SELECT:
1487 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1488 wSelectWindow(wwin, !wwin->flags.selected);
1490 break;
1491 case WKBD_FOCUSNEXT:
1492 StartWindozeCycle(wwin, event, True);
1493 break;
1495 case WKBD_FOCUSPREV:
1496 StartWindozeCycle(wwin, event, False);
1497 break;
1499 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1500 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1501 i = (scr->current_workspace/10)*10 + wk - 1;\
1502 if (wPreferences.ws_advance || i<scr->workspace_count)\
1503 wWorkspaceChange(scr, i);\
1504 break
1505 #else
1506 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1507 i = (scr->current_workspace/10)*10 + wk - 1;\
1508 if (wPreferences.ws_advance || i<scr->workspace_count)\
1509 wWorkspaceChange(scr, i);\
1510 break
1511 #endif
1512 GOTOWORKS(1);
1513 GOTOWORKS(2);
1514 GOTOWORKS(3);
1515 GOTOWORKS(4);
1516 GOTOWORKS(5);
1517 GOTOWORKS(6);
1518 GOTOWORKS(7);
1519 GOTOWORKS(8);
1520 GOTOWORKS(9);
1521 GOTOWORKS(10);
1522 #undef GOTOWORKS
1523 case WKBD_NEXTWORKSPACE:
1524 wWorkspaceRelativeChange(scr, 1);
1525 break;
1526 case WKBD_PREVWORKSPACE:
1527 wWorkspaceRelativeChange(scr, -1);
1528 break;
1529 case WKBD_WINDOW1:
1530 case WKBD_WINDOW2:
1531 case WKBD_WINDOW3:
1532 case WKBD_WINDOW4:
1533 case WKBD_WINDOW5:
1534 case WKBD_WINDOW6:
1535 case WKBD_WINDOW7:
1536 case WKBD_WINDOW8:
1537 case WKBD_WINDOW9:
1538 case WKBD_WINDOW10:
1540 index = command-WKBD_WINDOW1;
1542 if (scr->shortcutWindows[index]) {
1543 WMArray *list = scr->shortcutWindows[index];
1544 int cw;
1545 int count = WMGetArrayItemCount(list);
1546 WWindow *twin;
1547 WMArrayIterator iter;
1548 WWindow *wwin;
1550 wUnselectWindows(scr);
1551 cw = scr->current_workspace;
1553 WM_ETARETI_ARRAY(list, wwin, iter) {
1554 if (count > 1)
1555 wWindowChangeWorkspace(wwin, cw);
1557 wMakeWindowVisible(wwin);
1559 if (count > 1)
1560 wSelectWindow(wwin, True);
1563 /* rotate the order of windows, to create a cycling effect */
1564 twin = WMGetFromArray(list, 0);
1565 WMDeleteFromArray(list, 0);
1566 WMAddToArray(list, twin);
1568 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1569 if (scr->shortcutWindows[index]) {
1570 WMFreeArray(scr->shortcutWindows[index]);
1571 scr->shortcutWindows[index] = NULL;
1574 if (wwin->flags.selected && scr->selected_windows) {
1575 scr->shortcutWindows[index] =
1576 WMDuplicateArray(scr->selected_windows);
1577 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1578 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1579 } else {
1580 scr->shortcutWindows[index] = WMCreateArray(4);
1581 WMAddToArray(scr->shortcutWindows[index], wwin);
1584 wSelectWindow(wwin, !wwin->flags.selected);
1585 XFlush(dpy);
1586 wusleep(3000);
1587 wSelectWindow(wwin, !wwin->flags.selected);
1588 XFlush(dpy);
1590 } else if (scr->selected_windows
1591 && WMGetArrayItemCount(scr->selected_windows)) {
1593 if (wwin->flags.selected && scr->selected_windows) {
1594 if (scr->shortcutWindows[index]) {
1595 WMFreeArray(scr->shortcutWindows[index]);
1597 scr->shortcutWindows[index] =
1598 WMDuplicateArray(scr->selected_windows);
1602 break;
1604 case WKBD_SWITCH_SCREEN:
1605 if (wScreenCount > 1) {
1606 WScreen *scr2;
1607 int i;
1609 /* find index of this screen */
1610 for (i = 0; i < wScreenCount; i++) {
1611 if (wScreenWithNumber(i) == scr)
1612 break;
1614 i++;
1615 if (i >= wScreenCount) {
1616 i = 0;
1618 scr2 = wScreenWithNumber(i);
1620 if (scr2) {
1621 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1622 scr2->scr_width/2, scr2->scr_height/2);
1625 break;
1627 case WKBD_NEXTWSLAYER:
1628 case WKBD_PREVWSLAYER:
1630 int row, column;
1632 row = scr->current_workspace/10;
1633 column = scr->current_workspace%10;
1635 if (command==WKBD_NEXTWSLAYER) {
1636 if ((row+1)*10 < scr->workspace_count)
1637 wWorkspaceChange(scr, column+(row+1)*10);
1638 } else {
1639 if (row > 0)
1640 wWorkspaceChange(scr, column+(row-1)*10);
1643 break;
1644 case WKBD_CLIPLOWER:
1645 if (!wPreferences.flags.noclip)
1646 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1647 break;
1648 case WKBD_CLIPRAISE:
1649 if (!wPreferences.flags.noclip)
1650 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1651 break;
1652 case WKBD_CLIPRAISELOWER:
1653 if (!wPreferences.flags.noclip)
1654 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1655 break;
1656 #ifdef KEEP_XKB_LOCK_STATUS
1657 case WKBD_TOGGLE:
1658 if(wPreferences.modelock) {
1659 /*toggle*/
1660 wwin = scr->focused_window;
1662 if (wwin && wwin->flags.mapped
1663 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1664 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1665 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1667 wwin->frame->languagemode = wwin->frame->last_languagemode;
1668 wwin->frame->last_languagemode = staterec.group;
1669 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1673 break;
1674 #endif /* KEEP_XKB_LOCK_STATUS */
1680 static void
1681 handleMotionNotify(XEvent *event)
1683 WMenu *menu;
1684 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1686 if (wPreferences.scrollable_menus) {
1687 if (scr->flags.jump_back_pending ||
1688 event->xmotion.x_root <= 1 ||
1689 event->xmotion.x_root >= (scr->scr_width - 2) ||
1690 event->xmotion.y_root <= 1 ||
1691 event->xmotion.y_root >= (scr->scr_height - 2)) {
1692 #ifdef DEBUG
1693 L("pointer at screen edge");
1694 #endif
1695 menu = wMenuUnderPointer(scr);
1696 if (menu!=NULL)
1697 wMenuScroll(menu, event);
1700 #if 0
1701 if (event->xmotion.subwindow == None)
1702 return;
1704 if (scr->scrolledFMaximize != None) {
1705 WWindow *twin;
1707 twin = wWindowFor(scr->scrolledFMaximize);
1708 if (twin && twin->frame_y ==) {
1712 scr->scrolledFMaximize = NULL;
1714 } else {
1716 /* scroll full maximized window */
1717 if (event->xmotion.y_root < 1
1718 || event->xmotion.y_root > scr->scr_height - 1) {
1720 wwin = wWindowFor(event->xmotion.subwindow);
1722 if (wwin && (wwin->flags.maximized & MAX_VERTICAL)
1723 && WFLAGP(wwin, full_maximize)
1724 && event->xmotion.x_root >= wwin->frame_x
1725 && event->xmotion.x_root <= wwin->frame_x + wwin->frame->core->width) {
1727 if (!WFLAGP(wwin, no_titlebar)
1728 && wwin->frame_y <= - wwin->frame->top_width) {
1730 wWindowMove(wwin, wwin->frame_x, 0);
1731 wwin->flags.dragged_while_fmaximized = 0;
1733 } else if (!WFLAGP(wwin, no_resizebar)
1734 && wwin->frame_y + wwin->frame->core->height >=
1735 scr->scr_height + wwin->frame->bottom_width) {
1737 int y = scr->scr_height + wwin->frame->bottom_width;
1739 y = scr->scr_height - wwin->frame_y - wwin->frame->core->height;
1741 wWindowMove(wwin, wwin->frame_x, y);
1742 wwin->flags.dragged_while_fmaximized = 0;
1746 #endif
1750 static void
1751 handleVisibilityNotify(XEvent *event)
1753 WWindow *wwin;
1755 wwin = wWindowFor(event->xvisibility.window);
1756 if (!wwin)
1757 return;
1758 wwin->flags.obscured =
1759 (event->xvisibility.state == VisibilityFullyObscured);