wmaker: Reduce wakeups to zero
[wmaker-crm.git] / src / event.c
bloba4f614f40df90e9168c4c7363ef5cc0def570403
1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 NETWM_HINTS
64 # include "wmspec.h"
65 #endif
67 /******** Global Variables **********/
68 extern XContext wWinContext;
69 extern XContext wVEdgeContext;
71 extern Cursor wCursor[WCUR_LAST];
73 extern WShortKey wKeyBindings[WKBD_LAST];
74 extern int wScreenCount;
75 extern Time LastTimestamp;
76 extern Time LastFocusChange;
78 extern WPreferences wPreferences;
80 #define MOD_MASK wPreferences.modifier_mask
82 extern Atom _XA_WM_COLORMAP_NOTIFY;
84 extern Atom _XA_WM_CHANGE_STATE;
85 extern Atom _XA_WM_DELETE_WINDOW;
86 extern Atom _XA_GNUSTEP_WM_ATTR;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
88 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
89 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
90 extern Atom _XA_WINDOWMAKER_COMMAND;
93 #ifdef SHAPE
94 extern Bool wShapeSupported;
95 extern int wShapeEventBase;
96 #endif
98 #ifdef KEEP_XKB_LOCK_STATUS
99 extern int wXkbEventBase;
100 #endif
102 /* special flags */
103 extern char WDelayedActionSet;
106 /************ Local stuff ***********/
109 static void saveTimestamp(XEvent *event);
110 static void handleColormapNotify();
111 static void handleMapNotify();
112 static void handleUnmapNotify();
113 static void handleButtonPress();
114 static void handleExpose();
115 static void handleDestroyNotify();
116 static void handleConfigureRequest();
117 static void handleMapRequest();
118 static void handlePropertyNotify();
119 static void handleEnterNotify();
120 static void handleLeaveNotify();
121 static void handleExtensions();
122 static void handleClientMessage();
123 static void handleKeyPress();
124 static void handleFocusIn();
125 static void handleMotionNotify();
126 static void handleVisibilityNotify();
129 #ifdef SHAPE
130 static void handleShapeNotify();
131 #endif
133 /* called from the signal handler */
134 void NotifyDeadProcess(pid_t pid, unsigned char status);
136 /* real dead process handler */
137 static void handleDeadProcess(void *foo);
140 typedef struct DeadProcesses {
141 pid_t pid;
142 unsigned char exit_status;
143 } DeadProcesses;
145 /* stack of dead processes */
146 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
147 static int deadProcessPtr=0;
150 typedef struct DeathHandler {
151 WDeathHandler *callback;
152 pid_t pid;
153 void *client_data;
154 } DeathHandler;
156 static WMArray *deathHandlers=NULL;
160 WMagicNumber
161 wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
163 DeathHandler *handler;
165 handler = malloc(sizeof(DeathHandler));
166 if (!handler)
167 return 0;
169 handler->pid = pid;
170 handler->callback = callback;
171 handler->client_data = cdata;
173 if (!deathHandlers)
174 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
176 WMAddToArray(deathHandlers, handler);
178 return handler;
183 void
184 wDeleteDeathHandler(WMagicNumber id)
186 DeathHandler *handler=(DeathHandler*)id;
188 if (!handler || !deathHandlers)
189 return;
191 /* array destructor will call wfree(handler) */
192 WMRemoveFromArray(deathHandlers, handler);
196 void
197 DispatchEvent(XEvent *event)
199 if (deathHandlers)
200 handleDeadProcess(NULL);
202 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
203 WCHANGE_STATE(WSTATE_EXITING);
204 /* received SIGTERM */
206 * WMHandleEvent() can't be called from anything
207 * executed inside here, or we can get in a infinite
208 * recursive loop.
210 Shutdown(WSExitMode);
212 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
213 WCHANGE_STATE(WSTATE_RESTARTING);
215 Shutdown(WSRestartPreparationMode);
216 /* received SIGHUP */
217 Restart(NULL, True);
218 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
219 WCHANGE_STATE(WSTATE_NORMAL);
220 wDefaultsCheckDomains("bla");
223 /* for the case that all that is wanted to be dispatched is
224 * the stuff above */
225 if (!event)
226 return;
228 saveTimestamp(event);
229 switch (event->type) {
230 case MapRequest:
231 handleMapRequest(event);
232 break;
234 case KeyPress:
235 handleKeyPress(event);
236 break;
238 case MotionNotify:
239 handleMotionNotify(event);
240 break;
242 case ConfigureRequest:
243 handleConfigureRequest(event);
244 break;
246 case DestroyNotify:
247 handleDestroyNotify(event);
248 break;
250 case MapNotify:
251 handleMapNotify(event);
252 break;
254 case UnmapNotify:
255 handleUnmapNotify(event);
256 break;
258 case ButtonPress:
259 handleButtonPress(event);
260 break;
262 case Expose:
263 handleExpose(event);
264 break;
266 case PropertyNotify:
267 handlePropertyNotify(event);
268 break;
270 case EnterNotify:
271 handleEnterNotify(event);
272 break;
274 case LeaveNotify:
275 handleLeaveNotify(event);
276 break;
278 case ClientMessage:
279 handleClientMessage(event);
280 break;
282 case ColormapNotify:
283 handleColormapNotify(event);
284 break;
286 case MappingNotify:
287 if (event->xmapping.request == MappingKeyboard
288 || event->xmapping.request == MappingModifier)
289 XRefreshKeyboardMapping(&event->xmapping);
290 break;
292 case FocusIn:
293 handleFocusIn(event);
294 break;
296 case VisibilityNotify:
297 handleVisibilityNotify(event);
298 break;
299 default:
300 handleExtensions(event);
301 break;
307 *----------------------------------------------------------------------
308 * EventLoop-
309 * Processes X and internal events indefinitely.
311 * Returns:
312 * Never returns
314 * Side effects:
315 * The LastTimestamp global variable is updated.
316 *----------------------------------------------------------------------
318 void
319 EventLoop()
321 XEvent event;
322 extern volatile int filesChanged;
323 extern void wDefaultsCheckDomains();
325 for(;;) {
326 WMNextEvent(dpy, &event);
327 WMHandleEvent(&event);
330 * If dnotify detects changes in configuration
331 * files we have to read them again.
333 if (filesChanged){
334 fprintf(stdout,"wmaker: reading config files in defaults database.\n");
335 wDefaultsCheckDomains(NULL);
336 filesChanged = 0;
343 *----------------------------------------------------------------------
344 * ProcessPendingEvents --
345 * Processes the events that are currently pending (at the time
346 * this function is called) in the display's queue.
348 * Returns:
349 * After the pending events that were present at the function call
350 * are processed.
352 * Side effects:
353 * Many -- whatever handling events may involve.
355 *----------------------------------------------------------------------
357 void
358 ProcessPendingEvents()
360 XEvent event;
361 int count;
363 XSync(dpy, False);
365 /* Take a snapshot of the event count in the queue */
366 count = XPending(dpy);
368 while (count>0 && XPending(dpy)) {
369 WMNextEvent(dpy, &event);
370 WMHandleEvent(&event);
371 count--;
376 Bool
377 IsDoubleClick(WScreen *scr, XEvent *event)
379 if ((scr->last_click_time>0) &&
380 (event->xbutton.time-scr->last_click_time<=wPreferences.dblclick_time)
381 && (event->xbutton.button == scr->last_click_button)
382 && (event->xbutton.window == scr->last_click_window)) {
384 scr->flags.next_click_is_not_double = 1;
385 scr->last_click_time = 0;
386 scr->last_click_window = event->xbutton.window;
388 return True;
390 return False;
394 void
395 NotifyDeadProcess(pid_t pid, unsigned char status)
397 if (deadProcessPtr>=MAX_DEAD_PROCESSES-1) {
398 wwarning("stack overflow: too many dead processes");
399 return;
401 /* stack the process to be handled later,
402 * as this is called from the signal handler */
403 deadProcesses[deadProcessPtr].pid = pid;
404 deadProcesses[deadProcessPtr].exit_status = status;
405 deadProcessPtr++;
409 static void
410 handleDeadProcess(void *foo)
412 DeathHandler *tmp;
413 int i;
415 for (i=0; i<deadProcessPtr; i++) {
416 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
419 if (!deathHandlers) {
420 deadProcessPtr=0;
421 return;
424 /* get the pids on the queue and call handlers */
425 while (deadProcessPtr>0) {
426 deadProcessPtr--;
428 for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
429 tmp = WMGetFromArray(deathHandlers, i);
430 if (!tmp)
431 continue;
433 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
434 (*tmp->callback)(tmp->pid,
435 deadProcesses[deadProcessPtr].exit_status,
436 tmp->client_data);
437 wDeleteDeathHandler(tmp);
444 static void
445 saveTimestamp(XEvent *event)
448 * Never save CurrentTime as LastTimestamp because CurrentTime
449 * it's not a real timestamp (it's the 0L constant)
452 switch (event->type) {
453 case ButtonRelease:
454 case ButtonPress:
455 LastTimestamp = event->xbutton.time;
456 break;
457 case KeyPress:
458 case KeyRelease:
459 LastTimestamp = event->xkey.time;
460 break;
461 case MotionNotify:
462 LastTimestamp = event->xmotion.time;
463 break;
464 case PropertyNotify:
465 LastTimestamp = event->xproperty.time;
466 break;
467 case EnterNotify:
468 case LeaveNotify:
469 LastTimestamp = event->xcrossing.time;
470 break;
471 case SelectionClear:
472 LastTimestamp = event->xselectionclear.time;
473 break;
474 case SelectionRequest:
475 LastTimestamp = event->xselectionrequest.time;
476 break;
477 case SelectionNotify:
478 LastTimestamp = event->xselection.time;
479 #ifdef XDND
480 wXDNDProcessSelection(event);
481 #endif
482 break;
487 static int
488 matchWindow(void *item, void *cdata)
490 return (((WFakeGroupLeader*)item)->origLeader == (Window)cdata);
494 static void
495 handleExtensions(XEvent *event)
497 #ifdef KEEP_XKB_LOCK_STATUS
498 XkbEvent *xkbevent;
499 xkbevent = (XkbEvent *)event;
500 #endif /*KEEP_XKB_LOCK_STATUS*/
501 #ifdef SHAPE
502 if (wShapeSupported && event->type == (wShapeEventBase+ShapeNotify)) {
503 handleShapeNotify(event);
505 #endif
506 #ifdef KEEP_XKB_LOCK_STATUS
507 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)){
508 handleXkbIndicatorStateNotify(event);
510 #endif /*KEEP_XKB_LOCK_STATUS*/
514 static void
515 handleMapRequest(XEvent *ev)
517 WWindow *wwin;
518 WScreen *scr = NULL;
519 Window window = ev->xmaprequest.window;
521 #ifdef DEBUG
522 printf("got map request for %x\n", (unsigned)window);
523 #endif
524 if ((wwin = wWindowFor(window))) {
525 if (wwin->flags.shaded) {
526 wUnshadeWindow(wwin);
528 /* deiconify window */
529 if (wwin->flags.miniaturized) {
530 wDeiconifyWindow(wwin);
531 } else if (wwin->flags.hidden) {
532 WApplication *wapp = wApplicationOf(wwin->main_window);
533 /* go to the last workspace that the user worked on the app */
534 if (wapp) {
535 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
537 wUnhideApplication(wapp, False, False);
539 return;
542 scr = wScreenForRootWindow(ev->xmaprequest.parent);
544 wwin = wManageWindow(scr, window);
547 * This is to let the Dock know that the application it launched
548 * has already been mapped (eg: it has finished launching).
549 * It is not necessary for normally docked apps, but is needed for
550 * apps that were forcedly docked (like with dockit).
552 if (scr->last_dock) {
553 if (wwin && wwin->main_window!=None && wwin->main_window!=window)
554 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
555 else
556 wDockTrackWindowLaunch(scr->last_dock, window);
559 if (wwin) {
560 wClientSetState(wwin, NormalState, None);
561 if (wwin->flags.maximized) {
562 wMaximizeWindow(wwin, wwin->flags.maximized);
564 if (wwin->flags.shaded) {
565 wwin->flags.shaded = 0;
566 wwin->flags.skip_next_animation = 1;
567 wShadeWindow(wwin);
569 if (wwin->flags.miniaturized) {
570 wwin->flags.miniaturized = 0;
571 wwin->flags.skip_next_animation = 1;
572 wIconifyWindow(wwin);
574 if (wwin->flags.fullscreen) {
575 wwin->flags.fullscreen = 0;
576 wFullscreenWindow(wwin);
578 if (wwin->flags.hidden) {
579 WApplication *wapp = wApplicationOf(wwin->main_window);
581 wwin->flags.hidden = 0;
582 wwin->flags.skip_next_animation = 1;
583 if (wapp) {
584 wHideApplication(wapp);
591 static void
592 handleDestroyNotify(XEvent *event)
594 WWindow *wwin;
595 WApplication *app;
596 Window window = event->xdestroywindow.window;
597 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
598 int index;
600 #ifdef DEBUG
601 printf("got destroy notify\n");
602 #endif
603 wwin = wWindowFor(window);
604 if (wwin) {
605 wUnmanageWindow(wwin, False, True);
608 if (scr != NULL) {
609 while ((index = WMFindInArray(scr->fakeGroupLeaders, matchWindow,
610 (void*)window)) != WANotFound) {
611 WFakeGroupLeader *fPtr;
613 fPtr = WMGetFromArray(scr->fakeGroupLeaders, index);
614 if (fPtr->retainCount > 0) {
615 fPtr->retainCount--;
616 if (fPtr->retainCount==0 && fPtr->leader!=None) {
617 XDestroyWindow(dpy, fPtr->leader);
618 fPtr->leader = None;
619 XFlush(dpy);
622 fPtr->origLeader = None;
626 app = wApplicationOf(window);
627 if (app) {
628 if (window == app->main_window) {
629 app->refcount = 0;
630 wwin = app->main_window_desc->screen_ptr->focused_window;
631 while (wwin) {
632 if (wwin->main_window == window) {
633 wwin->main_window = None;
635 wwin = wwin->prev;
638 wApplicationDestroy(app);
644 static void
645 handleExpose(XEvent *event)
647 WObjDescriptor *desc;
648 XEvent ev;
650 #ifdef DEBUG
651 printf("got expose\n");
652 #endif
653 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev));
655 if (XFindContext(dpy, event->xexpose.window, wWinContext,
656 (XPointer *)&desc)==XCNOENT) {
657 return;
660 if (desc->handle_expose) {
661 (*desc->handle_expose)(desc, event);
665 static void
666 executeButtonAction(WScreen *scr, XEvent *event, int action)
668 switch(action) {
669 case WA_SELECT_WINDOWS:
670 wUnselectWindows(scr);
671 wSelectWindows(scr, event);
672 break;
673 case WA_OPEN_APPMENU:
674 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
675 /* ugly hack */
676 if (scr->root_menu) {
677 if (scr->root_menu->brother->flags.mapped)
678 event->xbutton.window = scr->root_menu->brother->frame->core->window;
679 else
680 event->xbutton.window = scr->root_menu->frame->core->window;
682 break;
683 case WA_OPEN_WINLISTMENU:
684 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
685 if (scr->switch_menu) {
686 if (scr->switch_menu->brother->flags.mapped)
687 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
688 else
689 event->xbutton.window = scr->switch_menu->frame->core->window;
691 break;
692 default:
693 break;
698 /* bindable */
699 static void
700 handleButtonPress(XEvent *event)
702 WObjDescriptor *desc;
703 WScreen *scr;
705 #ifdef DEBUG
706 printf("got button press\n");
707 #endif
708 scr = wScreenForRootWindow(event->xbutton.root);
710 #ifdef BALLOON_TEXT
711 wBalloonHide(scr);
712 #endif
715 #ifndef LITE
716 if (event->xbutton.window==scr->root_win) {
717 if (event->xbutton.button==Button1 &&
718 wPreferences.mouse_button1!=WA_NONE) {
719 executeButtonAction(scr, event, wPreferences.mouse_button1);
720 } else if (event->xbutton.button==Button2 &&
721 wPreferences.mouse_button2!=WA_NONE) {
722 executeButtonAction(scr, event, wPreferences.mouse_button2);
723 } else if (event->xbutton.button==Button3 &&
724 wPreferences.mouse_button3!=WA_NONE) {
725 executeButtonAction(scr, event, wPreferences.mouse_button3);
726 } else if (event->xbutton.button==Button4 &&
727 wPreferences.mouse_wheel!=WA_NONE) {
728 wWorkspaceRelativeChange(scr, 1);
729 } else if (event->xbutton.button==Button5 &&
730 wPreferences.mouse_wheel!=WA_NONE) {
731 wWorkspaceRelativeChange(scr, -1);
734 #endif /* !LITE */
736 desc = NULL;
737 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext,
738 (XPointer *)&desc)==XCNOENT) {
739 if (XFindContext(dpy, event->xbutton.window, wWinContext,
740 (XPointer *)&desc)==XCNOENT) {
741 return;
745 if (desc->parent_type == WCLASS_WINDOW) {
746 XSync(dpy, 0);
748 if (event->xbutton.state & MOD_MASK) {
749 XAllowEvents(dpy, AsyncPointer, CurrentTime);
752 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
753 if (wPreferences.ignore_focus_click) {
754 XAllowEvents(dpy, AsyncPointer, CurrentTime);
756 XAllowEvents(dpy, ReplayPointer, CurrentTime);
757 /* }*/
758 XSync(dpy, 0);
759 } else if (desc->parent_type == WCLASS_APPICON
760 || desc->parent_type == WCLASS_MINIWINDOW
761 || desc->parent_type == WCLASS_DOCK_ICON) {
762 if (event->xbutton.state & MOD_MASK) {
763 XSync(dpy, 0);
764 XAllowEvents(dpy, AsyncPointer, CurrentTime);
765 XSync(dpy, 0);
769 if (desc->handle_mousedown!=NULL) {
770 (*desc->handle_mousedown)(desc, event);
773 /* save double-click information */
774 if (scr->flags.next_click_is_not_double) {
775 scr->flags.next_click_is_not_double = 0;
776 } else {
777 scr->last_click_time = event->xbutton.time;
778 scr->last_click_button = event->xbutton.button;
779 scr->last_click_window = event->xbutton.window;
784 static void
785 handleMapNotify(XEvent *event)
787 WWindow *wwin;
788 #ifdef DEBUG
789 printf("got map\n");
790 #endif
791 wwin = wWindowFor(event->xmap.event);
792 if (wwin && wwin->client_win == event->xmap.event) {
793 if (wwin->flags.miniaturized) {
794 wDeiconifyWindow(wwin);
795 } else {
796 XGrabServer(dpy);
797 wWindowMap(wwin);
798 wClientSetState(wwin, NormalState, None);
799 XUngrabServer(dpy);
805 static void
806 handleUnmapNotify(XEvent *event)
808 WWindow *wwin;
809 XEvent ev;
810 Bool withdraw = False;
811 #ifdef DEBUG
812 printf("got unmap\n");
813 #endif
814 /* only process windows with StructureNotify selected
815 * (ignore SubstructureNotify) */
816 wwin = wWindowFor(event->xunmap.window);
817 if (!wwin)
818 return;
820 /* whether the event is a Withdrawal request */
821 if (event->xunmap.event == wwin->screen_ptr->root_win
822 && event->xunmap.send_event)
823 withdraw = True;
825 if (wwin->client_win != event->xunmap.event && !withdraw)
826 return;
828 if (!wwin->flags.mapped && !withdraw
829 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
830 && !wwin->flags.miniaturized && !wwin->flags.hidden)
831 return;
833 XGrabServer(dpy);
834 XUnmapWindow(dpy, wwin->frame->core->window);
835 wwin->flags.mapped = 0;
836 XSync(dpy, 0);
837 /* check if the window was destroyed */
838 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify,&ev)) {
839 DispatchEvent(&ev);
840 } else {
841 Bool reparented = False;
843 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
844 reparented = True;
846 /* withdraw window */
847 wwin->flags.mapped = 0;
848 if (!reparented)
849 wClientSetState(wwin, WithdrawnState, None);
851 /* if the window was reparented, do not reparent it back to the
852 * root window */
853 wUnmanageWindow(wwin, !reparented, False);
855 XUngrabServer(dpy);
859 static void
860 handleConfigureRequest(XEvent *event)
862 WWindow *wwin;
863 #ifdef DEBUG
864 printf("got configure request\n");
865 #endif
866 if (!(wwin=wWindowFor(event->xconfigurerequest.window))) {
868 * Configure request for unmapped window
870 wClientConfigure(NULL, &(event->xconfigurerequest));
871 } else {
872 wClientConfigure(wwin, &(event->xconfigurerequest));
877 static void
878 handlePropertyNotify(XEvent *event)
880 WWindow *wwin;
881 WApplication *wapp;
882 Window jr;
883 int ji;
884 unsigned int ju;
885 WScreen *scr;
886 #ifdef DEBUG
887 printf("got property notify\n");
888 #endif
889 if ((wwin=wWindowFor(event->xproperty.window))) {
890 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji,
891 &ju, &ju, &ju, &ju)) {
892 return;
894 wClientCheckProperty(wwin, &event->xproperty);
896 wapp = wApplicationOf(event->xproperty.window);
897 if (wapp) {
898 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
901 scr = wScreenForWindow(event->xproperty.window);
905 static void
906 handleClientMessage(XEvent *event)
908 WWindow *wwin;
909 WObjDescriptor *desc;
910 #ifdef DEBUG
911 printf("got client message\n");
912 #endif
913 /* handle transition from Normal to Iconic state */
914 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
915 && event->xclient.format == 32
916 && event->xclient.data.l[0] == IconicState) {
918 wwin = wWindowFor(event->xclient.window);
919 if (!wwin) return;
920 if (!wwin->flags.miniaturized)
921 wIconifyWindow(wwin);
922 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY
923 && event->xclient.format == 32) {
924 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
926 if (!scr)
927 return;
929 if (event->xclient.data.l[1] == 1) { /* starting */
930 wColormapAllowClientInstallation(scr, True);
931 } else { /* stopping */
932 wColormapAllowClientInstallation(scr, False);
934 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
936 wDefaultsCheckDomains("bla");
938 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
939 WApplication *wapp;
940 int done=0;
941 wapp = wApplicationOf(event->xclient.window);
942 if (wapp) {
943 switch (event->xclient.data.l[0]) {
944 case WMFHideOtherApplications:
945 wHideOtherApplications(wapp->main_window_desc);
946 done = 1;
947 break;
949 case WMFHideApplication:
950 wHideApplication(wapp);
951 done = 1;
952 break;
955 if (!done) {
956 wwin = wWindowFor(event->xclient.window);
957 if (wwin) {
958 switch (event->xclient.data.l[0]) {
959 case WMFHideOtherApplications:
960 wHideOtherApplications(wwin);
961 break;
963 case WMFHideApplication:
964 wHideApplication(wApplicationOf(wwin->main_window));
965 break;
969 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
970 wwin = wWindowFor(event->xclient.window);
971 if (!wwin) return;
972 switch (event->xclient.data.l[0]) {
973 case GSWindowLevelAttr:
975 int level = (int)event->xclient.data.l[1];
977 if (WINDOW_LEVEL(wwin) != level) {
978 ChangeStackingLevel(wwin->frame->core, level);
981 break;
983 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
984 wwin = wWindowFor(event->xclient.window);
985 if (!wwin) return;
986 switch (event->xclient.data.l[0]) {
987 case WMTitleBarNormal:
988 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
989 break;
990 case WMTitleBarMain:
991 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
992 break;
993 case WMTitleBarKey:
994 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
995 break;
997 #ifdef NETWM_HINTS
998 } else if (wNETWMProcessClientMessage(&event->xclient)) {
999 /* do nothing */
1000 #endif
1001 #ifdef XDND
1002 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1003 /* do nothing */
1004 #endif /* XDND */
1005 } else {
1007 * Non-standard thing, but needed by OffiX DND.
1008 * For when the icon frame gets a ClientMessage
1009 * that should have gone to the icon_window.
1011 if (XFindContext(dpy, event->xbutton.window, wWinContext,
1012 (XPointer *)&desc)!=XCNOENT) {
1013 struct WIcon *icon=NULL;
1015 if (desc->parent_type == WCLASS_MINIWINDOW) {
1016 icon = (WIcon*)desc->parent;
1017 } else if (desc->parent_type == WCLASS_DOCK_ICON
1018 || desc->parent_type == WCLASS_APPICON) {
1019 icon = ((WAppIcon*)desc->parent)->icon;
1021 if (icon && (wwin=icon->owner)) {
1022 if (wwin->client_win!=event->xclient.window) {
1023 event->xclient.window = wwin->client_win;
1024 XSendEvent(dpy, wwin->client_win, False, NoEventMask,
1025 event);
1033 static void
1034 raiseWindow(WScreen *scr)
1036 WWindow *wwin;
1038 scr->autoRaiseTimer = NULL;
1040 wwin = wWindowFor(scr->autoRaiseWindow);
1041 if (!wwin)
1042 return;
1044 if (!wwin->flags.destroyed && wwin->flags.focused) {
1045 wRaiseFrame(wwin->frame->core);
1046 /* this is needed or a race condition will occur */
1047 XSync(dpy, False);
1052 static void
1053 handleEnterNotify(XEvent *event)
1055 WWindow *wwin;
1056 WObjDescriptor *desc = NULL;
1057 #ifdef VIRTUAL_DESKTOP
1058 void (*vdHandler)(XEvent * event);
1059 #endif
1060 XEvent ev;
1061 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1062 #ifdef DEBUG
1063 printf("got enter notify\n");
1064 #endif
1066 #ifdef VIRTUAL_DESKTOP
1067 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext,
1068 (XPointer *)&vdHandler)!=XCNOENT) {
1069 (*vdHandler)(event);
1071 #endif
1073 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify,
1074 &ev)) {
1075 /* already left the window... */
1076 saveTimestamp(&ev);
1077 if (ev.xcrossing.mode==event->xcrossing.mode
1078 && ev.xcrossing.detail==event->xcrossing.detail) {
1079 return;
1083 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1084 (XPointer *)&desc)!=XCNOENT) {
1085 if(desc->handle_enternotify)
1086 (*desc->handle_enternotify)(desc, event);
1089 /* enter to window */
1090 wwin = wWindowFor(event->xcrossing.window);
1091 if (!wwin) {
1092 if (wPreferences.colormap_mode==WCM_POINTER) {
1093 wColormapInstallForWindow(scr, NULL);
1095 if (scr->autoRaiseTimer
1096 && event->xcrossing.root==event->xcrossing.window) {
1097 WMDeleteTimerHandler(scr->autoRaiseTimer);
1098 scr->autoRaiseTimer = NULL;
1100 } else {
1101 /* set auto raise timer even if in focus-follows-mouse mode
1102 * and the event is for the frame window, even if the window
1103 * has focus already. useful if you move the pointer from a focused
1104 * window to the root window and back pretty fast
1106 * set focus if in focus-follows-mouse mode and the event
1107 * is for the frame window and window doesn't have focus yet */
1108 if (wPreferences.focus_mode==WKF_SLOPPY
1109 && wwin->frame->core->window==event->xcrossing.window
1110 && !scr->flags.doing_alt_tab) {
1112 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1113 wSetFocusTo(scr, wwin);
1115 if (scr->autoRaiseTimer)
1116 WMDeleteTimerHandler(scr->autoRaiseTimer);
1117 scr->autoRaiseTimer = NULL;
1119 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1120 scr->autoRaiseWindow = wwin->frame->core->window;
1121 scr->autoRaiseTimer
1122 = WMAddTimerHandler(wPreferences.raise_delay,
1123 (WMCallback*)raiseWindow, scr);
1126 /* Install colormap for window, if the colormap installation mode
1127 * is colormap_follows_mouse */
1128 if (wPreferences.colormap_mode==WCM_POINTER) {
1129 if (wwin->client_win==event->xcrossing.window)
1130 wColormapInstallForWindow(scr, wwin);
1131 else
1132 wColormapInstallForWindow(scr, NULL);
1136 /* a little kluge to hide the clip balloon */
1137 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1138 if (!desc) {
1139 XUnmapWindow(dpy, scr->clip_balloon);
1140 scr->flags.clip_balloon_mapped = 0;
1141 } else {
1142 if (desc->parent_type!=WCLASS_DOCK_ICON
1143 || scr->clip_icon != desc->parent) {
1144 XUnmapWindow(dpy, scr->clip_balloon);
1145 scr->flags.clip_balloon_mapped = 0;
1150 if (event->xcrossing.window == event->xcrossing.root
1151 && event->xcrossing.detail == NotifyNormal
1152 && event->xcrossing.detail != NotifyInferior
1153 && wPreferences.focus_mode != WKF_CLICK) {
1155 wSetFocusTo(scr, scr->focused_window);
1158 #ifdef BALLOON_TEXT
1159 wBalloonEnteredObject(scr, desc);
1160 #endif
1164 static void
1165 handleLeaveNotify(XEvent *event)
1167 WObjDescriptor *desc = NULL;
1169 if (XFindContext(dpy, event->xcrossing.window, wWinContext,
1170 (XPointer *)&desc)!=XCNOENT) {
1171 if(desc->handle_leavenotify)
1172 (*desc->handle_leavenotify)(desc, event);
1177 #ifdef SHAPE
1178 static void
1179 handleShapeNotify(XEvent *event)
1181 XShapeEvent *shev = (XShapeEvent*)event;
1182 WWindow *wwin;
1183 XEvent ev;
1184 #ifdef DEBUG
1185 printf("got shape notify\n");
1186 #endif
1187 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1188 XShapeEvent *sev = (XShapeEvent*)&ev;
1190 if (sev->kind == ShapeBounding) {
1191 if (sev->shaped == shev->shaped) {
1192 *shev = *sev;
1193 } else {
1194 XPutBackEvent(dpy, &ev);
1195 break;
1200 wwin = wWindowFor(shev->window);
1201 if (!wwin || shev->kind != ShapeBounding)
1202 return;
1204 if (!shev->shaped && wwin->flags.shaped) {
1206 wwin->flags.shaped = 0;
1207 wWindowClearShape(wwin);
1209 } else if (shev->shaped) {
1211 wwin->flags.shaped = 1;
1212 wWindowSetShape(wwin);
1215 #endif /* SHAPE */
1217 #ifdef KEEP_XKB_LOCK_STATUS
1218 /* please help ]d if you know what to do */
1219 handleXkbIndicatorStateNotify(XEvent *event)
1221 WWindow *wwin;
1222 WScreen *scr;
1223 XkbStateRec staterec;
1224 int i;
1226 for (i=0; i<wScreenCount; i++) {
1227 scr = wScreenWithNumber(i);
1228 wwin = scr->focused_window;
1229 if (wwin && wwin->flags.focused) {
1230 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1231 if (wwin->frame->languagemode != staterec.group) {
1232 wwin->frame->last_languagemode = wwin->frame->languagemode;
1233 wwin->frame->languagemode = staterec.group;
1235 #ifdef XKB_BUTTON_HINT
1236 if (wwin->frame->titlebar) {
1237 wFrameWindowPaint(wwin->frame);
1239 #endif
1243 #endif /*KEEP_XKB_LOCK_STATUS*/
1245 static void
1246 handleColormapNotify(XEvent *event)
1248 WWindow *wwin;
1249 WScreen *scr;
1250 Bool reinstall = False;
1252 wwin = wWindowFor(event->xcolormap.window);
1253 if (!wwin)
1254 return;
1256 scr = wwin->screen_ptr;
1258 do {
1259 if (wwin) {
1260 if (event->xcolormap.new) {
1261 XWindowAttributes attr;
1263 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1265 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1266 scr->current_colormap = attr.colormap;
1268 reinstall = True;
1269 } else if (event->xcolormap.state == ColormapUninstalled &&
1270 scr->current_colormap == event->xcolormap.colormap) {
1272 /* some bastard app (like XV) removed our colormap */
1274 * can't enforce or things like xscreensaver wont work
1275 * reinstall = True;
1277 } else if (event->xcolormap.state == ColormapInstalled &&
1278 scr->current_colormap == event->xcolormap.colormap) {
1280 /* someone has put our colormap back */
1281 reinstall = False;
1284 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1285 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1287 if (reinstall && scr->current_colormap!=None) {
1288 if (!scr->flags.colormap_stuff_blocked)
1289 XInstallColormap(dpy, scr->current_colormap);
1295 static void
1296 handleFocusIn(XEvent *event)
1298 WWindow *wwin;
1301 * For applications that like stealing the focus.
1303 while (XCheckTypedEvent(dpy, FocusIn, event));
1304 saveTimestamp(event);
1305 if (event->xfocus.mode == NotifyUngrab
1306 || event->xfocus.mode == NotifyGrab
1307 || event->xfocus.detail > NotifyNonlinearVirtual) {
1308 return;
1311 wwin = wWindowFor(event->xfocus.window);
1312 if (wwin && !wwin->flags.focused) {
1313 if (wwin->flags.mapped)
1314 wSetFocusTo(wwin->screen_ptr, wwin);
1315 else
1316 wSetFocusTo(wwin->screen_ptr, NULL);
1317 } else if (!wwin) {
1318 WScreen *scr = wScreenForWindow(event->xfocus.window);
1319 if (scr)
1320 wSetFocusTo(scr, NULL);
1325 static WWindow*
1326 windowUnderPointer(WScreen *scr)
1328 unsigned int mask;
1329 int foo;
1330 Window bar, win;
1332 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo,
1333 &mask))
1334 return wWindowFor(win);
1335 return NULL;
1339 static int CheckFullScreenWindowFocused(WScreen *scr)
1341 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1342 return 1;
1343 else
1344 return 0;
1348 static void
1349 handleKeyPress(XEvent *event)
1351 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1352 WWindow *wwin = scr->focused_window;
1353 int i;
1354 int modifiers;
1355 int command=-1, index;
1356 #ifdef KEEP_XKB_LOCK_STATUS
1357 XkbStateRec staterec;
1358 #endif /*KEEP_XKB_LOCK_STATUS*/
1360 /* ignore CapsLock */
1361 modifiers = event->xkey.state & ValidModMask;
1363 for (i=0; i<WKBD_LAST; i++) {
1364 if (wKeyBindings[i].keycode==0)
1365 continue;
1367 if (wKeyBindings[i].keycode==event->xkey.keycode
1368 && (/*wKeyBindings[i].modifier==0
1369 ||*/ wKeyBindings[i].modifier==modifiers)) {
1370 command = i;
1371 break;
1376 if (command < 0) {
1377 #ifdef LITE
1379 #if 0
1381 #endif
1382 #else
1383 if (!wRootMenuPerformShortcut(event)) {
1384 #endif
1385 static int dontLoop = 0;
1387 if (dontLoop > 10) {
1388 wwarning("problem with key event processing code");
1389 return;
1391 dontLoop++;
1392 /* if the focused window is an internal window, try redispatching
1393 * the event to the managed window, as it can be a WINGs window */
1394 if (wwin && wwin->flags.internal_window
1395 && wwin->client_leader!=None) {
1396 /* client_leader contains the WINGs toplevel */
1397 event->xany.window = wwin->client_leader;
1398 WMHandleEvent(event);
1400 dontLoop--;
1402 return;
1405 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1406 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1408 switch (command) {
1409 #ifndef LITE
1410 case WKBD_ROOTMENU:
1411 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1412 if (!CheckFullScreenWindowFocused(scr)) {
1413 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1414 OpenRootMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1416 break;
1417 case WKBD_WINDOWLIST:
1418 if (!CheckFullScreenWindowFocused(scr)) {
1419 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1420 OpenSwitchMenu(scr, rect.pos.x + rect.size.width/2, rect.pos.y + rect.size.height/2, True);
1422 break;
1423 #endif /* !LITE */
1424 case WKBD_WINDOWMENU:
1425 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1426 OpenWindowMenu(wwin, wwin->frame_x,
1427 wwin->frame_y+wwin->frame->top_width, True);
1428 break;
1429 case WKBD_MINIATURIZE:
1430 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1431 && !WFLAGP(wwin, no_miniaturizable)) {
1432 CloseWindowMenu(scr);
1434 if (wwin->protocols.MINIATURIZE_WINDOW)
1435 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW,
1436 event->xbutton.time);
1437 else {
1438 wIconifyWindow(wwin);
1441 break;
1442 case WKBD_HIDE:
1443 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1444 WApplication *wapp = wApplicationOf(wwin->main_window);
1445 CloseWindowMenu(scr);
1447 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1448 wHideApplication(wapp);
1451 break;
1452 case WKBD_HIDE_OTHERS:
1453 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1454 CloseWindowMenu(scr);
1456 wHideOtherApplications(wwin);
1458 break;
1459 case WKBD_MAXIMIZE:
1460 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1461 int newdir = (MAX_VERTICAL|MAX_HORIZONTAL);
1463 CloseWindowMenu(scr);
1465 if (wwin->flags.maximized == newdir) {
1466 wUnmaximizeWindow(wwin);
1467 } else {
1468 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1471 break;
1472 case WKBD_VMAXIMIZE:
1473 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1474 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1476 CloseWindowMenu(scr);
1478 if (newdir) {
1479 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1480 } else {
1481 wUnmaximizeWindow(wwin);
1484 break;
1485 case WKBD_HMAXIMIZE:
1486 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1487 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1489 CloseWindowMenu(scr);
1491 if (newdir) {
1492 wMaximizeWindow(wwin, newdir|MAX_KEYBOARD);
1493 } else {
1494 wUnmaximizeWindow(wwin);
1497 break;
1498 case WKBD_RAISE:
1499 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1500 CloseWindowMenu(scr);
1502 wRaiseFrame(wwin->frame->core);
1504 break;
1505 case WKBD_LOWER:
1506 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1507 CloseWindowMenu(scr);
1509 wLowerFrame(wwin->frame->core);
1511 break;
1512 case WKBD_RAISELOWER:
1513 /* raise or lower the window under the pointer, not the
1514 * focused one
1516 wwin = windowUnderPointer(scr);
1517 if (wwin)
1518 wRaiseLowerFrame(wwin->frame->core);
1519 break;
1520 case WKBD_SHADE:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1522 if (wwin->flags.shaded)
1523 wUnshadeWindow(wwin);
1524 else
1525 wShadeWindow(wwin);
1527 break;
1528 case WKBD_MOVERESIZE:
1529 if (ISMAPPED(wwin) && ISFOCUSED(wwin) &&
1530 (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1531 CloseWindowMenu(scr);
1533 wKeyboardMoveResizeWindow(wwin);
1535 break;
1536 case WKBD_CLOSE:
1537 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1538 CloseWindowMenu(scr);
1539 if (wwin->protocols.DELETE_WINDOW)
1540 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW,
1541 event->xkey.time);
1543 break;
1544 case WKBD_SELECT:
1545 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1546 wSelectWindow(wwin, !wwin->flags.selected);
1548 break;
1549 case WKBD_FOCUSNEXT:
1550 StartWindozeCycle(wwin, event, True);
1551 break;
1553 case WKBD_FOCUSPREV:
1554 StartWindozeCycle(wwin, event, False);
1555 break;
1557 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1558 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1559 i = (scr->current_workspace/10)*10 + wk - 1;\
1560 if (wPreferences.ws_advance || i<scr->workspace_count)\
1561 wWorkspaceChange(scr, i);\
1562 break
1563 #else
1564 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1565 i = (scr->current_workspace/10)*10 + wk - 1;\
1566 if (wPreferences.ws_advance || i<scr->workspace_count)\
1567 wWorkspaceChange(scr, i);\
1568 break
1569 #endif
1570 GOTOWORKS(1);
1571 GOTOWORKS(2);
1572 GOTOWORKS(3);
1573 GOTOWORKS(4);
1574 GOTOWORKS(5);
1575 GOTOWORKS(6);
1576 GOTOWORKS(7);
1577 GOTOWORKS(8);
1578 GOTOWORKS(9);
1579 GOTOWORKS(10);
1580 #undef GOTOWORKS
1581 case WKBD_NEXTWORKSPACE:
1582 wWorkspaceRelativeChange(scr, 1);
1583 break;
1584 case WKBD_PREVWORKSPACE:
1585 wWorkspaceRelativeChange(scr, -1);
1586 break;
1587 case WKBD_WINDOW1:
1588 case WKBD_WINDOW2:
1589 case WKBD_WINDOW3:
1590 case WKBD_WINDOW4:
1591 case WKBD_WINDOW5:
1592 case WKBD_WINDOW6:
1593 case WKBD_WINDOW7:
1594 case WKBD_WINDOW8:
1595 case WKBD_WINDOW9:
1596 case WKBD_WINDOW10:
1598 index = command-WKBD_WINDOW1;
1600 if (scr->shortcutWindows[index]) {
1601 WMArray *list = scr->shortcutWindows[index];
1602 int cw;
1603 int count = WMGetArrayItemCount(list);
1604 WWindow *twin;
1605 WMArrayIterator iter;
1606 WWindow *wwin;
1608 wUnselectWindows(scr);
1609 cw = scr->current_workspace;
1611 WM_ETARETI_ARRAY(list, wwin, iter) {
1612 if (count > 1)
1613 wWindowChangeWorkspace(wwin, cw);
1615 wMakeWindowVisible(wwin);
1617 if (count > 1)
1618 wSelectWindow(wwin, True);
1621 /* rotate the order of windows, to create a cycling effect */
1622 twin = WMGetFromArray(list, 0);
1623 WMDeleteFromArray(list, 0);
1624 WMAddToArray(list, twin);
1626 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1627 if (scr->shortcutWindows[index]) {
1628 WMFreeArray(scr->shortcutWindows[index]);
1629 scr->shortcutWindows[index] = NULL;
1632 if (wwin->flags.selected && scr->selected_windows) {
1633 scr->shortcutWindows[index] =
1634 WMDuplicateArray(scr->selected_windows);
1635 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1636 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1637 } else {
1638 scr->shortcutWindows[index] = WMCreateArray(4);
1639 WMAddToArray(scr->shortcutWindows[index], wwin);
1642 wSelectWindow(wwin, !wwin->flags.selected);
1643 XFlush(dpy);
1644 wusleep(3000);
1645 wSelectWindow(wwin, !wwin->flags.selected);
1646 XFlush(dpy);
1648 } else if (scr->selected_windows
1649 && WMGetArrayItemCount(scr->selected_windows)) {
1651 if (wwin->flags.selected && scr->selected_windows) {
1652 if (scr->shortcutWindows[index]) {
1653 WMFreeArray(scr->shortcutWindows[index]);
1655 scr->shortcutWindows[index] =
1656 WMDuplicateArray(scr->selected_windows);
1660 break;
1662 case WKBD_SWITCH_SCREEN:
1663 if (wScreenCount > 1) {
1664 WScreen *scr2;
1665 int i;
1667 /* find index of this screen */
1668 for (i = 0; i < wScreenCount; i++) {
1669 if (wScreenWithNumber(i) == scr)
1670 break;
1672 i++;
1673 if (i >= wScreenCount) {
1674 i = 0;
1676 scr2 = wScreenWithNumber(i);
1678 if (scr2) {
1679 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1680 scr2->scr_width/2, scr2->scr_height/2);
1683 break;
1685 case WKBD_NEXTWSLAYER:
1686 case WKBD_PREVWSLAYER:
1688 int row, column;
1690 row = scr->current_workspace/10;
1691 column = scr->current_workspace%10;
1693 if (command==WKBD_NEXTWSLAYER) {
1694 if ((row+1)*10 < scr->workspace_count)
1695 wWorkspaceChange(scr, column+(row+1)*10);
1696 } else {
1697 if (row > 0)
1698 wWorkspaceChange(scr, column+(row-1)*10);
1701 break;
1702 case WKBD_CLIPLOWER:
1703 if (!wPreferences.flags.noclip)
1704 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1705 break;
1706 case WKBD_CLIPRAISE:
1707 if (!wPreferences.flags.noclip)
1708 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1709 break;
1710 case WKBD_CLIPRAISELOWER:
1711 if (!wPreferences.flags.noclip)
1712 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1713 break;
1714 #ifdef KEEP_XKB_LOCK_STATUS
1715 case WKBD_TOGGLE:
1716 if(wPreferences.modelock) {
1717 /*toggle*/
1718 wwin = scr->focused_window;
1720 if (wwin && wwin->flags.mapped
1721 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1722 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1723 XkbGetState(dpy,XkbUseCoreKbd,&staterec);
1725 wwin->frame->languagemode = wwin->frame->last_languagemode;
1726 wwin->frame->last_languagemode = staterec.group;
1727 XkbLockGroup(dpy,XkbUseCoreKbd, wwin->frame->languagemode);
1731 break;
1732 #endif /* KEEP_XKB_LOCK_STATUS */
1733 #ifdef VIRTUAL_DESKTOP
1734 case WKBD_VDESK_LEFT:
1735 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1736 break;
1738 case WKBD_VDESK_RIGHT:
1739 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1740 break;
1742 case WKBD_VDESK_UP:
1743 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1744 break;
1746 case WKBD_VDESK_DOWN:
1747 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1748 break;
1749 #endif
1755 static void
1756 handleMotionNotify(XEvent *event)
1758 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1760 if (wPreferences.scrollable_menus) {
1761 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1762 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1764 if (scr->flags.jump_back_pending ||
1765 p.x <= (rect.pos.x + 1) ||
1766 p.x >= (rect.pos.x + rect.size.width - 2) ||
1767 p.y <= (rect.pos.y + 1) ||
1768 p.y >= (rect.pos.y + rect.size.height - 2)) {
1769 WMenu *menu;
1770 #ifdef DEBUG
1771 printf("pointer at screen edge\n");
1772 #endif
1773 menu = wMenuUnderPointer(scr);
1774 if (menu!=NULL)
1775 wMenuScroll(menu, event);
1781 static void
1782 handleVisibilityNotify(XEvent *event)
1784 WWindow *wwin;
1786 wwin = wWindowFor(event->xvisibility.window);
1787 if (!wwin)
1788 return;
1789 wwin->flags.obscured =
1790 (event->xvisibility.state == VisibilityFullyObscured);