4f1287c5a7202ebff8cce96048b325ade0d74379
[wmaker-crm.git] / src / event.c
blob4f1287c5a7202ebff8cce96048b325ade0d74379
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.
23 #include "wconfig.h"
25 #ifdef HAVE_INOTIFY
26 #include <sys/inotify.h>
27 #endif
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #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"
62 #include "wmspec.h"
64 /******** Global Variables **********/
65 extern XContext wWinContext;
66 extern XContext wVEdgeContext;
68 extern Cursor wCursor[WCUR_LAST];
70 extern WShortKey wKeyBindings[WKBD_LAST];
71 extern int wScreenCount;
72 extern Time LastTimestamp;
73 extern Time LastFocusChange;
75 extern WPreferences wPreferences;
77 #define MOD_MASK wPreferences.modifier_mask
79 extern Atom _XA_WM_COLORMAP_NOTIFY;
81 extern Atom _XA_WM_CHANGE_STATE;
82 extern Atom _XA_WM_DELETE_WINDOW;
83 extern Atom _XA_GNUSTEP_WM_ATTR;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
85 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
86 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
87 extern Atom _XA_WINDOWMAKER_COMMAND;
88 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
90 #ifdef SHAPE
91 extern Bool wShapeSupported;
92 extern int wShapeEventBase;
93 #endif
95 #ifdef KEEP_XKB_LOCK_STATUS
96 extern int wXkbEventBase;
97 #endif
99 /* special flags */
100 /*extern char WDelayedActionSet;*/
102 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent *event);
105 static void handleColormapNotify(XEvent *event);
106 static void handleMapNotify(XEvent *event);
107 static void handleUnmapNotify(XEvent *event);
108 static void handleButtonPress(XEvent *event);
109 static void handleExpose(XEvent *event);
110 static void handleDestroyNotify(XEvent *event);
111 static void handleConfigureRequest(XEvent *event);
112 static void handleMapRequest(XEvent *event);
113 static void handlePropertyNotify(XEvent *event);
114 static void handleEnterNotify(XEvent *event);
115 static void handleLeaveNotify(XEvent *event);
116 static void handleExtensions(XEvent *event);
117 static void handleClientMessage(XEvent *event);
118 static void handleKeyPress(XEvent *event);
119 static void handleFocusIn(XEvent *event);
120 static void handleMotionNotify(XEvent *event);
121 static void handleVisibilityNotify(XEvent *event);
123 #ifdef SHAPE
124 static void handleShapeNotify(XEvent *event);
125 #endif
127 #ifdef KEEP_XKB_LOCK_STATUS
128 static void handleXkbIndicatorStateNotify(XEvent *event);
129 #endif
131 /* called from the signal handler */
132 void NotifyDeadProcess(pid_t pid, unsigned char status);
134 /* real dead process handler */
135 static void handleDeadProcess(void *foo);
137 typedef struct DeadProcesses {
138 pid_t pid;
139 unsigned char exit_status;
140 } DeadProcesses;
142 /* stack of dead processes */
143 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
144 static int deadProcessPtr = 0;
146 typedef struct DeathHandler {
147 WDeathHandler *callback;
148 pid_t pid;
149 void *client_data;
150 } DeathHandler;
152 static WMArray *deathHandlers = NULL;
154 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
156 DeathHandler *handler;
158 handler = malloc(sizeof(DeathHandler));
159 if (!handler)
160 return 0;
162 handler->pid = pid;
163 handler->callback = callback;
164 handler->client_data = cdata;
166 if (!deathHandlers)
167 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
169 WMAddToArray(deathHandlers, handler);
171 return handler;
174 void wDeleteDeathHandler(WMagicNumber id)
176 DeathHandler *handler = (DeathHandler *) id;
178 if (!handler || !deathHandlers)
179 return;
181 /* array destructor will call wfree(handler) */
182 WMRemoveFromArray(deathHandlers, handler);
185 void DispatchEvent(XEvent * event)
187 if (deathHandlers)
188 handleDeadProcess(NULL);
190 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
191 WCHANGE_STATE(WSTATE_EXITING);
192 /* received SIGTERM */
194 * WMHandleEvent() can't be called from anything
195 * executed inside here, or we can get in a infinite
196 * recursive loop.
198 Shutdown(WSExitMode);
200 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
201 WCHANGE_STATE(WSTATE_RESTARTING);
203 Shutdown(WSRestartPreparationMode);
204 /* received SIGHUP */
205 Restart(NULL, True);
206 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
207 WCHANGE_STATE(WSTATE_NORMAL);
208 wDefaultsCheckDomains(NULL);
211 /* for the case that all that is wanted to be dispatched is
212 * the stuff above */
213 if (!event)
214 return;
216 saveTimestamp(event);
217 switch (event->type) {
218 case MapRequest:
219 handleMapRequest(event);
220 break;
222 case KeyPress:
223 handleKeyPress(event);
224 break;
226 case MotionNotify:
227 handleMotionNotify(event);
228 break;
230 case ConfigureRequest:
231 handleConfigureRequest(event);
232 break;
234 case DestroyNotify:
235 handleDestroyNotify(event);
236 break;
238 case MapNotify:
239 handleMapNotify(event);
240 break;
242 case UnmapNotify:
243 handleUnmapNotify(event);
244 break;
246 case ButtonPress:
247 handleButtonPress(event);
248 break;
250 case Expose:
251 handleExpose(event);
252 break;
254 case PropertyNotify:
255 handlePropertyNotify(event);
256 break;
258 case EnterNotify:
259 handleEnterNotify(event);
260 break;
262 case LeaveNotify:
263 handleLeaveNotify(event);
264 break;
266 case ClientMessage:
267 handleClientMessage(event);
268 break;
270 case ColormapNotify:
271 handleColormapNotify(event);
272 break;
274 case MappingNotify:
275 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
276 XRefreshKeyboardMapping(&event->xmapping);
277 break;
279 case FocusIn:
280 handleFocusIn(event);
281 break;
283 case VisibilityNotify:
284 handleVisibilityNotify(event);
285 break;
286 default:
287 handleExtensions(event);
288 break;
292 #ifdef HAVE_INOTIFY
294 *----------------------------------------------------------------------
295 * inotifyHandleEvents-
296 * Check for inotify events
298 * Returns:
299 * After reading events for the given file descriptor (fd) and
300 * watch descriptor (wd)
302 * Side effects:
303 * Calls wDefaultsCheckDomains if config database is updated
304 *----------------------------------------------------------------------
306 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
307 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
308 void inotifyHandleEvents(int fd, int wd)
310 extern void wDefaultsCheckDomains(void *);
311 ssize_t eventQLength, i = 0;
312 char buff[BUFF_SIZE] = { 0 };
313 /* Check config only once per read of the event queue */
314 int oneShotFlag = 0;
317 * Read off the queued events
318 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
319 * not occur; the block is on Xevents, but a config file change will normally
320 * occur as a result of an Xevent - so the event queue should never have more than
321 * a few entries before a read().
323 eventQLength = read(fd, buff, BUFF_SIZE);
325 /* check what events occured */
326 /* Should really check wd here too, but for now we only have one watch! */
327 while (i < eventQLength) {
328 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
331 * see inotify.h for event types.
333 if (pevent->mask & IN_DELETE_SELF) {
334 wwarning(_("the defaults database has been deleted!"
335 " Restart Window Maker to create the database" " with the default settings"));
336 close(fd);
338 if (pevent->mask & IN_UNMOUNT) {
339 wwarning(_("the unit containing the defaults database has"
340 " been unmounted. Setting --static mode." " Any changes will not be saved."));
341 close(fd);
342 wPreferences.flags.noupdates = 1;
344 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
345 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
346 wDefaultsCheckDomains(NULL);
349 /* move to next event in the buffer */
350 i += sizeof(struct inotify_event) + pevent->len;
353 #endif /* HAVE_INOTIFY */
356 *----------------------------------------------------------------------
357 * EventLoop-
358 * Processes X and internal events indefinitely.
360 * Returns:
361 * Never returns
363 * Side effects:
364 * The LastTimestamp global variable is updated.
365 * Calls inotifyGetEvents if defaults database changes.
366 *----------------------------------------------------------------------
368 void EventLoop(void)
370 XEvent event;
371 #ifdef HAVE_INOTIFY
372 extern int inotifyFD;
373 extern int inotifyWD;
374 struct timeval time;
375 fd_set rfds;
376 int retVal = 0;
378 if (inotifyFD < 0 || inotifyWD < 0)
379 retVal = -1;
380 #endif
382 for (;;) {
384 WMNextEvent(dpy, &event); /* Blocks here */
385 WMHandleEvent(&event);
386 #ifdef HAVE_INOTIFY
387 if (retVal != -1) {
388 time.tv_sec = 0;
389 time.tv_usec = 0;
390 FD_ZERO(&rfds);
391 FD_SET(inotifyFD, &rfds);
393 /* check for available read data from inotify - don't block! */
394 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
396 if (retVal < 0) { /* an error has occured */
397 wwarning(_("select failed. The inotify instance will be closed."
398 " Changes to the defaults database will require"
399 " a restart to take effect."));
400 close(inotifyFD);
401 continue;
403 if (FD_ISSET(inotifyFD, &rfds))
404 inotifyHandleEvents(inotifyFD, inotifyWD);
406 #endif
411 *----------------------------------------------------------------------
412 * ProcessPendingEvents --
413 * Processes the events that are currently pending (at the time
414 * this function is called) in the display's queue.
416 * Returns:
417 * After the pending events that were present at the function call
418 * are processed.
420 * Side effects:
421 * Many -- whatever handling events may involve.
423 *----------------------------------------------------------------------
425 void ProcessPendingEvents(void)
427 XEvent event;
428 int count;
430 XSync(dpy, False);
432 /* Take a snapshot of the event count in the queue */
433 count = XPending(dpy);
435 while (count > 0 && XPending(dpy)) {
436 WMNextEvent(dpy, &event);
437 WMHandleEvent(&event);
438 count--;
442 Bool IsDoubleClick(WScreen * scr, XEvent * event)
444 if ((scr->last_click_time > 0) &&
445 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
446 && (event->xbutton.button == scr->last_click_button)
447 && (event->xbutton.window == scr->last_click_window)) {
449 scr->flags.next_click_is_not_double = 1;
450 scr->last_click_time = 0;
451 scr->last_click_window = event->xbutton.window;
453 return True;
455 return False;
458 void NotifyDeadProcess(pid_t pid, unsigned char status)
460 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
461 wwarning("stack overflow: too many dead processes");
462 return;
464 /* stack the process to be handled later,
465 * as this is called from the signal handler */
466 deadProcesses[deadProcessPtr].pid = pid;
467 deadProcesses[deadProcessPtr].exit_status = status;
468 deadProcessPtr++;
471 static void handleDeadProcess(void *foo)
473 DeathHandler *tmp;
474 int i;
476 for (i = 0; i < deadProcessPtr; i++) {
477 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
480 if (!deathHandlers) {
481 deadProcessPtr = 0;
482 return;
485 /* get the pids on the queue and call handlers */
486 while (deadProcessPtr > 0) {
487 deadProcessPtr--;
489 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
490 tmp = WMGetFromArray(deathHandlers, i);
491 if (!tmp)
492 continue;
494 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
495 (*tmp->callback) (tmp->pid,
496 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
497 wDeleteDeathHandler(tmp);
503 static void saveTimestamp(XEvent * event)
506 * Never save CurrentTime as LastTimestamp because CurrentTime
507 * it's not a real timestamp (it's the 0L constant)
510 switch (event->type) {
511 case ButtonRelease:
512 case ButtonPress:
513 LastTimestamp = event->xbutton.time;
514 break;
515 case KeyPress:
516 case KeyRelease:
517 LastTimestamp = event->xkey.time;
518 break;
519 case MotionNotify:
520 LastTimestamp = event->xmotion.time;
521 break;
522 case PropertyNotify:
523 LastTimestamp = event->xproperty.time;
524 break;
525 case EnterNotify:
526 case LeaveNotify:
527 LastTimestamp = event->xcrossing.time;
528 break;
529 case SelectionClear:
530 LastTimestamp = event->xselectionclear.time;
531 break;
532 case SelectionRequest:
533 LastTimestamp = event->xselectionrequest.time;
534 break;
535 case SelectionNotify:
536 LastTimestamp = event->xselection.time;
537 #ifdef XDND
538 wXDNDProcessSelection(event);
539 #endif
540 break;
544 static int matchWindow(const void *item, const void *cdata)
546 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
549 static void handleExtensions(XEvent * event)
551 #ifdef KEEP_XKB_LOCK_STATUS
552 XkbEvent *xkbevent;
553 xkbevent = (XkbEvent *) event;
554 #endif /*KEEP_XKB_LOCK_STATUS */
555 #ifdef SHAPE
556 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
557 handleShapeNotify(event);
559 #endif
560 #ifdef KEEP_XKB_LOCK_STATUS
561 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
562 handleXkbIndicatorStateNotify(event);
564 #endif /*KEEP_XKB_LOCK_STATUS */
567 static void handleMapRequest(XEvent * ev)
569 WWindow *wwin;
570 WScreen *scr = NULL;
571 Window window = ev->xmaprequest.window;
573 if ((wwin = wWindowFor(window))) {
574 if (wwin->flags.shaded) {
575 wUnshadeWindow(wwin);
577 /* deiconify window */
578 if (wwin->flags.miniaturized) {
579 wDeiconifyWindow(wwin);
580 } else if (wwin->flags.hidden) {
581 WApplication *wapp = wApplicationOf(wwin->main_window);
582 /* go to the last workspace that the user worked on the app */
583 if (wapp) {
584 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
586 wUnhideApplication(wapp, False, False);
588 return;
591 scr = wScreenForRootWindow(ev->xmaprequest.parent);
593 wwin = wManageWindow(scr, window);
596 * This is to let the Dock know that the application it launched
597 * has already been mapped (eg: it has finished launching).
598 * It is not necessary for normally docked apps, but is needed for
599 * apps that were forcedly docked (like with dockit).
601 if (scr->last_dock) {
602 if (wwin && wwin->main_window != None && wwin->main_window != window)
603 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
604 else
605 wDockTrackWindowLaunch(scr->last_dock, window);
608 if (wwin) {
609 wClientSetState(wwin, NormalState, None);
610 if (wwin->flags.maximized) {
611 wMaximizeWindow(wwin, wwin->flags.maximized);
613 if (wwin->flags.shaded) {
614 wwin->flags.shaded = 0;
615 wwin->flags.skip_next_animation = 1;
616 wShadeWindow(wwin);
618 if (wwin->flags.miniaturized) {
619 wwin->flags.miniaturized = 0;
620 wwin->flags.skip_next_animation = 1;
621 wIconifyWindow(wwin);
623 if (wwin->flags.fullscreen) {
624 wwin->flags.fullscreen = 0;
625 wFullscreenWindow(wwin);
627 if (wwin->flags.hidden) {
628 WApplication *wapp = wApplicationOf(wwin->main_window);
630 wwin->flags.hidden = 0;
631 wwin->flags.skip_next_animation = 1;
632 if (wapp) {
633 wHideApplication(wapp);
639 static void handleDestroyNotify(XEvent * event)
641 WWindow *wwin;
642 WApplication *app;
643 Window window = event->xdestroywindow.window;
644 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
645 int widx;
647 wwin = wWindowFor(window);
648 if (wwin) {
649 wUnmanageWindow(wwin, False, True);
652 if (scr != NULL) {
653 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
654 WFakeGroupLeader *fPtr;
656 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
657 if (fPtr->retainCount > 0) {
658 fPtr->retainCount--;
659 if (fPtr->retainCount == 0 && fPtr->leader != None) {
660 XDestroyWindow(dpy, fPtr->leader);
661 fPtr->leader = None;
662 XFlush(dpy);
665 fPtr->origLeader = None;
669 app = wApplicationOf(window);
670 if (app) {
671 if (window == app->main_window) {
672 app->refcount = 0;
673 wwin = app->main_window_desc->screen_ptr->focused_window;
674 while (wwin) {
675 if (wwin->main_window == window) {
676 wwin->main_window = None;
678 wwin = wwin->prev;
681 wApplicationDestroy(app);
685 static void handleExpose(XEvent * event)
687 WObjDescriptor *desc;
688 XEvent ev;
690 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
692 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
693 return;
696 if (desc->handle_expose) {
697 (*desc->handle_expose) (desc, event);
701 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
703 switch (action) {
704 case WA_SELECT_WINDOWS:
705 wUnselectWindows(scr);
706 wSelectWindows(scr, event);
707 break;
708 case WA_OPEN_APPMENU:
709 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
710 /* ugly hack */
711 if (scr->root_menu) {
712 if (scr->root_menu->brother->flags.mapped)
713 event->xbutton.window = scr->root_menu->brother->frame->core->window;
714 else
715 event->xbutton.window = scr->root_menu->frame->core->window;
717 break;
718 case WA_OPEN_WINLISTMENU:
719 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
720 if (scr->switch_menu) {
721 if (scr->switch_menu->brother->flags.mapped)
722 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
723 else
724 event->xbutton.window = scr->switch_menu->frame->core->window;
726 break;
727 default:
728 break;
732 /* bindable */
733 static void handleButtonPress(XEvent * event)
735 WObjDescriptor *desc;
736 WScreen *scr;
738 scr = wScreenForRootWindow(event->xbutton.root);
740 #ifdef BALLOON_TEXT
741 wBalloonHide(scr);
742 #endif
744 if (event->xbutton.window == scr->root_win) {
745 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
746 executeButtonAction(scr, event, wPreferences.mouse_button1);
747 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
748 executeButtonAction(scr, event, wPreferences.mouse_button2);
749 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
750 executeButtonAction(scr, event, wPreferences.mouse_button3);
751 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
752 wWorkspaceRelativeChange(scr, 1);
753 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
754 wWorkspaceRelativeChange(scr, -1);
758 desc = NULL;
759 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
760 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
761 return;
765 if (desc->parent_type == WCLASS_WINDOW) {
766 XSync(dpy, 0);
768 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
769 XAllowEvents(dpy, AsyncPointer, CurrentTime);
770 } else {
771 /* if (wPreferences.focus_mode == WKF_CLICK) { */
772 if (wPreferences.ignore_focus_click) {
773 XAllowEvents(dpy, AsyncPointer, CurrentTime);
775 XAllowEvents(dpy, ReplayPointer, CurrentTime);
776 /* } */
778 XSync(dpy, 0);
779 } else if (desc->parent_type == WCLASS_APPICON
780 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
781 if (event->xbutton.state & MOD_MASK) {
782 XSync(dpy, 0);
783 XAllowEvents(dpy, AsyncPointer, CurrentTime);
784 XSync(dpy, 0);
788 if (desc->handle_mousedown != NULL) {
789 (*desc->handle_mousedown) (desc, event);
792 /* save double-click information */
793 if (scr->flags.next_click_is_not_double) {
794 scr->flags.next_click_is_not_double = 0;
795 } else {
796 scr->last_click_time = event->xbutton.time;
797 scr->last_click_button = event->xbutton.button;
798 scr->last_click_window = event->xbutton.window;
802 static void handleMapNotify(XEvent * event)
804 WWindow *wwin;
806 wwin = wWindowFor(event->xmap.event);
807 if (wwin && wwin->client_win == event->xmap.event) {
808 if (wwin->flags.miniaturized) {
809 wDeiconifyWindow(wwin);
810 } else {
811 XGrabServer(dpy);
812 wWindowMap(wwin);
813 wClientSetState(wwin, NormalState, None);
814 XUngrabServer(dpy);
819 static void handleUnmapNotify(XEvent * event)
821 WWindow *wwin;
822 XEvent ev;
823 Bool withdraw = False;
825 /* only process windows with StructureNotify selected
826 * (ignore SubstructureNotify) */
827 wwin = wWindowFor(event->xunmap.window);
828 if (!wwin)
829 return;
831 /* whether the event is a Withdrawal request */
832 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
833 withdraw = True;
835 if (wwin->client_win != event->xunmap.event && !withdraw)
836 return;
838 if (!wwin->flags.mapped && !withdraw
839 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
840 && !wwin->flags.miniaturized && !wwin->flags.hidden)
841 return;
843 XGrabServer(dpy);
844 XUnmapWindow(dpy, wwin->frame->core->window);
845 wwin->flags.mapped = 0;
846 XSync(dpy, 0);
847 /* check if the window was destroyed */
848 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
849 DispatchEvent(&ev);
850 } else {
851 Bool reparented = False;
853 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
854 reparented = True;
856 /* withdraw window */
857 wwin->flags.mapped = 0;
858 if (!reparented)
859 wClientSetState(wwin, WithdrawnState, None);
861 /* if the window was reparented, do not reparent it back to the
862 * root window */
863 wUnmanageWindow(wwin, !reparented, False);
865 XUngrabServer(dpy);
868 static void handleConfigureRequest(XEvent * event)
870 WWindow *wwin;
872 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
874 * Configure request for unmapped window
876 wClientConfigure(NULL, &(event->xconfigurerequest));
877 } else {
878 wClientConfigure(wwin, &(event->xconfigurerequest));
882 static void handlePropertyNotify(XEvent * event)
884 WWindow *wwin;
885 WApplication *wapp;
886 Window jr;
887 int ji;
888 unsigned int ju;
889 WScreen *scr;
891 wwin = wWindowFor(event->xproperty.window);
892 if (wwin) {
893 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
894 return;
896 wClientCheckProperty(wwin, &event->xproperty);
898 wapp = wApplicationOf(event->xproperty.window);
899 if (wapp) {
900 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
903 scr = wScreenForWindow(event->xproperty.window);
906 static void handleClientMessage(XEvent * event)
908 WWindow *wwin;
909 WObjDescriptor *desc;
911 /* handle transition from Normal to Iconic state */
912 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
913 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
915 wwin = wWindowFor(event->xclient.window);
916 if (!wwin)
917 return;
918 if (!wwin->flags.miniaturized)
919 wIconifyWindow(wwin);
920 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
921 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
923 if (!scr)
924 return;
926 if (event->xclient.data.l[1] == 1) { /* starting */
927 wColormapAllowClientInstallation(scr, True);
928 } else { /* stopping */
929 wColormapAllowClientInstallation(scr, False);
931 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
933 char *command;
934 size_t len;
936 len = sizeof(event->xclient.data.b) + 1;
937 command = wmalloc(len);
938 memset(command, 0, len);
939 strncpy(command, event->xclient.data.b, sizeof(event->xclient.data.b));
941 if (strncmp(command, "Reconfigure", sizeof("Reconfigure")) == 0) {
942 wwarning(_("Got Reconfigure command"));
943 wDefaultsCheckDomains(NULL);
944 } else {
945 wwarning(_("Got unknown command %s"), command);
948 wfree(command);
950 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
951 WApplication *wapp;
952 int done = 0;
953 wapp = wApplicationOf(event->xclient.window);
954 if (wapp) {
955 switch (event->xclient.data.l[0]) {
956 case WMFHideOtherApplications:
957 wHideOtherApplications(wapp->main_window_desc);
958 done = 1;
959 break;
961 case WMFHideApplication:
962 wHideApplication(wapp);
963 done = 1;
964 break;
967 if (!done) {
968 wwin = wWindowFor(event->xclient.window);
969 if (wwin) {
970 switch (event->xclient.data.l[0]) {
971 case WMFHideOtherApplications:
972 wHideOtherApplications(wwin);
973 break;
975 case WMFHideApplication:
976 wHideApplication(wApplicationOf(wwin->main_window));
977 break;
981 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
982 wwin = wWindowFor(event->xclient.window);
983 if (!wwin)
984 return;
985 switch (event->xclient.data.l[0]) {
986 case GSWindowLevelAttr:
988 int level = (int)event->xclient.data.l[1];
990 if (WINDOW_LEVEL(wwin) != level) {
991 ChangeStackingLevel(wwin->frame->core, level);
994 break;
996 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
997 wwin = wWindowFor(event->xclient.window);
998 if (!wwin)
999 return;
1000 switch (event->xclient.data.l[0]) {
1001 case WMTitleBarNormal:
1002 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1003 break;
1004 case WMTitleBarMain:
1005 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1006 break;
1007 case WMTitleBarKey:
1008 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1009 break;
1011 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1012 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1013 if (!scr)
1014 return;
1015 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1016 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1017 /* do nothing */
1018 #ifdef XDND
1019 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1020 /* do nothing */
1021 #endif /* XDND */
1022 } else {
1024 * Non-standard thing, but needed by OffiX DND.
1025 * For when the icon frame gets a ClientMessage
1026 * that should have gone to the icon_window.
1028 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1029 struct WIcon *icon = NULL;
1031 if (desc->parent_type == WCLASS_MINIWINDOW) {
1032 icon = (WIcon *) desc->parent;
1033 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1034 icon = ((WAppIcon *) desc->parent)->icon;
1036 if (icon && (wwin = icon->owner)) {
1037 if (wwin->client_win != event->xclient.window) {
1038 event->xclient.window = wwin->client_win;
1039 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1046 static void raiseWindow(WScreen * scr)
1048 WWindow *wwin;
1050 scr->autoRaiseTimer = NULL;
1052 wwin = wWindowFor(scr->autoRaiseWindow);
1053 if (!wwin)
1054 return;
1056 if (!wwin->flags.destroyed && wwin->flags.focused) {
1057 wRaiseFrame(wwin->frame->core);
1058 /* this is needed or a race condition will occur */
1059 XSync(dpy, False);
1063 static void handleEnterNotify(XEvent * event)
1065 WWindow *wwin;
1066 WObjDescriptor *desc = NULL;
1067 XEvent ev;
1068 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1070 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1071 /* already left the window... */
1072 saveTimestamp(&ev);
1073 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1074 return;
1078 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1079 if (desc->handle_enternotify)
1080 (*desc->handle_enternotify) (desc, event);
1083 /* enter to window */
1084 wwin = wWindowFor(event->xcrossing.window);
1085 if (!wwin) {
1086 if (wPreferences.colormap_mode == WCM_POINTER) {
1087 wColormapInstallForWindow(scr, NULL);
1089 if (scr->autoRaiseTimer && 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 && !scr->flags.doing_alt_tab) {
1104 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1105 wSetFocusTo(scr, wwin);
1107 if (scr->autoRaiseTimer)
1108 WMDeleteTimerHandler(scr->autoRaiseTimer);
1109 scr->autoRaiseTimer = NULL;
1111 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1112 scr->autoRaiseWindow = wwin->frame->core->window;
1113 scr->autoRaiseTimer
1114 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1117 /* Install colormap for window, if the colormap installation mode
1118 * is colormap_follows_mouse */
1119 if (wPreferences.colormap_mode == WCM_POINTER) {
1120 if (wwin->client_win == event->xcrossing.window)
1121 wColormapInstallForWindow(scr, wwin);
1122 else
1123 wColormapInstallForWindow(scr, NULL);
1127 /* a little kluge to hide the clip balloon */
1128 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1129 if (!desc) {
1130 XUnmapWindow(dpy, scr->clip_balloon);
1131 scr->flags.clip_balloon_mapped = 0;
1132 } else {
1133 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1134 XUnmapWindow(dpy, scr->clip_balloon);
1135 scr->flags.clip_balloon_mapped = 0;
1140 if (event->xcrossing.window == event->xcrossing.root
1141 && event->xcrossing.detail == NotifyNormal
1142 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1144 wSetFocusTo(scr, scr->focused_window);
1146 #ifdef BALLOON_TEXT
1147 wBalloonEnteredObject(scr, desc);
1148 #endif
1151 static void handleLeaveNotify(XEvent * event)
1153 WObjDescriptor *desc = NULL;
1155 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1156 if (desc->handle_leavenotify)
1157 (*desc->handle_leavenotify) (desc, event);
1161 #ifdef SHAPE
1162 static void handleShapeNotify(XEvent * event)
1164 XShapeEvent *shev = (XShapeEvent *) event;
1165 WWindow *wwin;
1166 union {
1167 XEvent xevent;
1168 XShapeEvent xshape;
1169 } ev;
1171 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev.xevent)) {
1172 if (ev.xshape.kind == ShapeBounding) {
1173 if (ev.xshape.shaped == shev->shaped) {
1174 *shev = ev.xshape;
1175 } else {
1176 XPutBackEvent(dpy, &ev.xevent);
1177 break;
1182 wwin = wWindowFor(shev->window);
1183 if (!wwin || shev->kind != ShapeBounding)
1184 return;
1186 if (!shev->shaped && wwin->flags.shaped) {
1188 wwin->flags.shaped = 0;
1189 wWindowClearShape(wwin);
1191 } else if (shev->shaped) {
1193 wwin->flags.shaped = 1;
1194 wWindowSetShape(wwin);
1197 #endif /* SHAPE */
1199 #ifdef KEEP_XKB_LOCK_STATUS
1200 /* please help ]d if you know what to do */
1201 static void handleXkbIndicatorStateNotify(XEvent *event)
1203 WWindow *wwin;
1204 WScreen *scr;
1205 XkbStateRec staterec;
1206 int i;
1208 for (i = 0; i < wScreenCount; i++) {
1209 scr = wScreenWithNumber(i);
1210 wwin = scr->focused_window;
1211 if (wwin && wwin->flags.focused) {
1212 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1213 if (wwin->frame->languagemode != staterec.group) {
1214 wwin->frame->last_languagemode = wwin->frame->languagemode;
1215 wwin->frame->languagemode = staterec.group;
1217 #ifdef XKB_BUTTON_HINT
1218 if (wwin->frame->titlebar) {
1219 wFrameWindowPaint(wwin->frame);
1221 #endif
1225 #endif /*KEEP_XKB_LOCK_STATUS */
1227 static void handleColormapNotify(XEvent * event)
1229 WWindow *wwin;
1230 WScreen *scr;
1231 Bool reinstall = False;
1233 wwin = wWindowFor(event->xcolormap.window);
1234 if (!wwin)
1235 return;
1237 scr = wwin->screen_ptr;
1239 do {
1240 if (wwin) {
1241 if (event->xcolormap.new) {
1242 XWindowAttributes attr;
1244 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1246 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1247 scr->current_colormap = attr.colormap;
1249 reinstall = True;
1250 } else if (event->xcolormap.state == ColormapUninstalled &&
1251 scr->current_colormap == event->xcolormap.colormap) {
1253 /* some bastard app (like XV) removed our colormap */
1255 * can't enforce or things like xscreensaver wont work
1256 * reinstall = True;
1258 } else if (event->xcolormap.state == ColormapInstalled &&
1259 scr->current_colormap == event->xcolormap.colormap) {
1261 /* someone has put our colormap back */
1262 reinstall = False;
1265 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1266 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1268 if (reinstall && scr->current_colormap != None) {
1269 if (!scr->flags.colormap_stuff_blocked)
1270 XInstallColormap(dpy, scr->current_colormap);
1274 static void handleFocusIn(XEvent * event)
1276 WWindow *wwin;
1279 * For applications that like stealing the focus.
1281 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1282 saveTimestamp(event);
1283 if (event->xfocus.mode == NotifyUngrab
1284 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1285 return;
1288 wwin = wWindowFor(event->xfocus.window);
1289 if (wwin && !wwin->flags.focused) {
1290 if (wwin->flags.mapped)
1291 wSetFocusTo(wwin->screen_ptr, wwin);
1292 else
1293 wSetFocusTo(wwin->screen_ptr, NULL);
1294 } else if (!wwin) {
1295 WScreen *scr = wScreenForWindow(event->xfocus.window);
1296 if (scr)
1297 wSetFocusTo(scr, NULL);
1301 static WWindow *windowUnderPointer(WScreen * scr)
1303 unsigned int mask;
1304 int foo;
1305 Window bar, win;
1307 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1308 return wWindowFor(win);
1309 return NULL;
1312 static int CheckFullScreenWindowFocused(WScreen * scr)
1314 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1315 return 1;
1316 else
1317 return 0;
1320 static void handleKeyPress(XEvent * event)
1322 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1323 WWindow *wwin = scr->focused_window;
1324 short i, widx;
1325 int modifiers;
1326 int command = -1;
1327 #ifdef KEEP_XKB_LOCK_STATUS
1328 XkbStateRec staterec;
1329 #endif /*KEEP_XKB_LOCK_STATUS */
1331 /* ignore CapsLock */
1332 modifiers = event->xkey.state & ValidModMask;
1334 for (i = 0; i < WKBD_LAST; i++) {
1335 if (wKeyBindings[i].keycode == 0)
1336 continue;
1338 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1339 || */ wKeyBindings[i].modifier ==
1340 modifiers)) {
1341 command = i;
1342 break;
1346 if (command < 0) {
1348 if (!wRootMenuPerformShortcut(event)) {
1349 static int dontLoop = 0;
1351 if (dontLoop > 10) {
1352 wwarning("problem with key event processing code");
1353 return;
1355 dontLoop++;
1356 /* if the focused window is an internal window, try redispatching
1357 * the event to the managed window, as it can be a WINGs window */
1358 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1359 /* client_leader contains the WINGs toplevel */
1360 event->xany.window = wwin->client_leader;
1361 WMHandleEvent(event);
1363 dontLoop--;
1365 return;
1367 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1368 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1370 switch (command) {
1372 case WKBD_ROOTMENU:
1373 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1374 if (!CheckFullScreenWindowFocused(scr)) {
1375 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1376 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1377 True);
1379 break;
1380 case WKBD_WINDOWLIST:
1381 if (!CheckFullScreenWindowFocused(scr)) {
1382 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1383 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1384 True);
1386 break;
1388 case WKBD_WINDOWMENU:
1389 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1390 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1391 break;
1392 case WKBD_MINIATURIZE:
1393 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1394 && !WFLAGP(wwin, no_miniaturizable)) {
1395 CloseWindowMenu(scr);
1397 if (wwin->protocols.MINIATURIZE_WINDOW)
1398 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1399 else {
1400 wIconifyWindow(wwin);
1403 break;
1404 case WKBD_HIDE:
1405 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1406 WApplication *wapp = wApplicationOf(wwin->main_window);
1407 CloseWindowMenu(scr);
1409 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1410 wHideApplication(wapp);
1413 break;
1414 case WKBD_HIDE_OTHERS:
1415 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1416 CloseWindowMenu(scr);
1418 wHideOtherApplications(wwin);
1420 break;
1421 case WKBD_MAXIMIZE:
1422 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1423 CloseWindowMenu(scr);
1425 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_HORIZONTAL))
1426 wUnmaximizeWindow(wwin);
1427 else
1428 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1430 break;
1431 case WKBD_VMAXIMIZE:
1432 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1433 CloseWindowMenu(scr);
1435 if (wwin->flags.maximized == MAX_VERTICAL)
1436 wUnmaximizeWindow(wwin);
1437 else
1438 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1440 break;
1441 case WKBD_HMAXIMIZE:
1442 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1443 CloseWindowMenu(scr);
1445 if (wwin->flags.maximized == MAX_HORIZONTAL)
1446 wUnmaximizeWindow(wwin);
1447 else
1448 wMaximizeWindow(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1450 break;
1451 case WKBD_LHMAXIMIZE:
1452 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1453 CloseWindowMenu(scr);
1455 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_LEFTHALF))
1456 wUnmaximizeWindow(wwin);
1457 else
1458 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1460 break;
1461 case WKBD_RHMAXIMIZE:
1462 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1463 CloseWindowMenu(scr);
1465 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_RIGHTHALF))
1466 wUnmaximizeWindow(wwin);
1467 else
1468 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1470 break;
1471 case WKBD_MAXIMUS:
1472 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1473 CloseWindowMenu(scr);
1475 if (wwin->flags.maximized == MAX_MAXIMUS)
1476 wUnmaximizeWindow(wwin);
1477 else
1478 wMaximizeWindow(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1480 break;
1481 case WKBD_RAISE:
1482 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1483 CloseWindowMenu(scr);
1485 wRaiseFrame(wwin->frame->core);
1487 break;
1488 case WKBD_LOWER:
1489 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1490 CloseWindowMenu(scr);
1492 wLowerFrame(wwin->frame->core);
1494 break;
1495 case WKBD_RAISELOWER:
1496 /* raise or lower the window under the pointer, not the
1497 * focused one
1499 wwin = windowUnderPointer(scr);
1500 if (wwin)
1501 wRaiseLowerFrame(wwin->frame->core);
1502 break;
1503 case WKBD_SHADE:
1504 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1505 if (wwin->flags.shaded)
1506 wUnshadeWindow(wwin);
1507 else
1508 wShadeWindow(wwin);
1510 break;
1511 case WKBD_MOVERESIZE:
1512 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1513 CloseWindowMenu(scr);
1515 wKeyboardMoveResizeWindow(wwin);
1517 break;
1518 case WKBD_CLOSE:
1519 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1520 CloseWindowMenu(scr);
1521 if (wwin->protocols.DELETE_WINDOW)
1522 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1524 break;
1525 case WKBD_SELECT:
1526 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1527 wSelectWindow(wwin, !wwin->flags.selected);
1529 break;
1530 case WKBD_FOCUSNEXT:
1531 StartWindozeCycle(wwin, event, True, False);
1532 break;
1534 case WKBD_FOCUSPREV:
1535 StartWindozeCycle(wwin, event, False, False);
1536 break;
1538 case WKBD_GROUPNEXT:
1539 StartWindozeCycle(wwin, event, True, True);
1540 break;
1542 case WKBD_GROUPPREV:
1543 StartWindozeCycle(wwin, event, False, True);
1544 break;
1546 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1547 widx = command - WKBD_WORKSPACE1;
1548 i = (scr->current_workspace / 10) * 10 + widx;
1549 if (wPreferences.ws_advance || i < scr->workspace_count)
1550 wWorkspaceChange(scr, i);
1551 break;
1553 case WKBD_NEXTWORKSPACE:
1554 wWorkspaceRelativeChange(scr, 1);
1555 break;
1556 case WKBD_PREVWORKSPACE:
1557 wWorkspaceRelativeChange(scr, -1);
1558 break;
1560 case WKBD_WINDOW1:
1561 case WKBD_WINDOW2:
1562 case WKBD_WINDOW3:
1563 case WKBD_WINDOW4:
1564 case WKBD_WINDOW5:
1565 case WKBD_WINDOW6:
1566 case WKBD_WINDOW7:
1567 case WKBD_WINDOW8:
1568 case WKBD_WINDOW9:
1569 case WKBD_WINDOW10:
1571 widx = command - WKBD_WINDOW1;
1573 if (scr->shortcutWindows[widx]) {
1574 WMArray *list = scr->shortcutWindows[widx];
1575 int cw;
1576 int count = WMGetArrayItemCount(list);
1577 WWindow *twin;
1578 WMArrayIterator iter;
1579 WWindow *wwin;
1581 wUnselectWindows(scr);
1582 cw = scr->current_workspace;
1584 WM_ETARETI_ARRAY(list, wwin, iter) {
1585 if (count > 1)
1586 wWindowChangeWorkspace(wwin, cw);
1588 wMakeWindowVisible(wwin);
1590 if (count > 1)
1591 wSelectWindow(wwin, True);
1594 /* rotate the order of windows, to create a cycling effect */
1595 twin = WMGetFromArray(list, 0);
1596 WMDeleteFromArray(list, 0);
1597 WMAddToArray(list, twin);
1599 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1600 if (scr->shortcutWindows[widx]) {
1601 WMFreeArray(scr->shortcutWindows[widx]);
1602 scr->shortcutWindows[widx] = NULL;
1605 if (wwin->flags.selected && scr->selected_windows) {
1606 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1607 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1608 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1609 } else {
1610 scr->shortcutWindows[widx] = WMCreateArray(4);
1611 WMAddToArray(scr->shortcutWindows[widx], wwin);
1614 wSelectWindow(wwin, !wwin->flags.selected);
1615 XFlush(dpy);
1616 wusleep(3000);
1617 wSelectWindow(wwin, !wwin->flags.selected);
1618 XFlush(dpy);
1620 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1622 if (wwin->flags.selected && scr->selected_windows) {
1623 if (scr->shortcutWindows[widx]) {
1624 WMFreeArray(scr->shortcutWindows[widx]);
1626 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1630 break;
1632 case WKBD_SWITCH_SCREEN:
1633 if (wScreenCount > 1) {
1634 WScreen *scr2;
1635 int i;
1637 /* find index of this screen */
1638 for (i = 0; i < wScreenCount; i++) {
1639 if (wScreenWithNumber(i) == scr)
1640 break;
1642 i++;
1643 if (i >= wScreenCount) {
1644 i = 0;
1646 scr2 = wScreenWithNumber(i);
1648 if (scr2) {
1649 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1650 scr2->scr_width / 2, scr2->scr_height / 2);
1653 break;
1655 case WKBD_NEXTWSLAYER:
1656 case WKBD_PREVWSLAYER:
1658 int row, column;
1660 row = scr->current_workspace / 10;
1661 column = scr->current_workspace % 10;
1663 if (command == WKBD_NEXTWSLAYER) {
1664 if ((row + 1) * 10 < scr->workspace_count)
1665 wWorkspaceChange(scr, column + (row + 1) * 10);
1666 } else {
1667 if (row > 0)
1668 wWorkspaceChange(scr, column + (row - 1) * 10);
1671 break;
1672 case WKBD_CLIPRAISELOWER:
1673 if (!wPreferences.flags.noclip)
1674 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1675 break;
1676 case WKBD_DOCKRAISELOWER:
1677 if (!wPreferences.flags.nodock)
1678 wDockRaiseLower(scr->dock);
1679 break;
1680 #ifdef KEEP_XKB_LOCK_STATUS
1681 case WKBD_TOGGLE:
1682 if (wPreferences.modelock) {
1683 /*toggle */
1684 wwin = scr->focused_window;
1686 if (wwin && wwin->flags.mapped
1687 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1688 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1689 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1691 wwin->frame->languagemode = wwin->frame->last_languagemode;
1692 wwin->frame->last_languagemode = staterec.group;
1693 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1697 break;
1698 #endif /* KEEP_XKB_LOCK_STATUS */
1702 static void handleMotionNotify(XEvent * event)
1704 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1706 if (wPreferences.scrollable_menus) {
1707 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1708 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1710 if (scr->flags.jump_back_pending ||
1711 p.x <= (rect.pos.x + 1) ||
1712 p.x >= (rect.pos.x + rect.size.width - 2) ||
1713 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1714 WMenu *menu;
1716 menu = wMenuUnderPointer(scr);
1717 if (menu != NULL)
1718 wMenuScroll(menu, event);
1723 static void handleVisibilityNotify(XEvent * event)
1725 WWindow *wwin;
1727 wwin = wWindowFor(event->xvisibility.window);
1728 if (!wwin)
1729 return;
1730 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);