wmaker: Moved function prototype to the appropriate header
[wmaker-crm.git] / src / event.c
blob95b437b2c56cda8faac03563779ded93ef0ef698
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #ifdef HAVE_INOTIFY
25 #include <sys/select.h>
26 #include <sys/inotify.h>
27 #endif
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <time.h>
36 #include <X11/Xlib.h>
37 #include <X11/Xutil.h>
38 #ifdef SHAPE
39 # include <X11/extensions/shape.h>
40 #endif
41 #ifdef XDND
42 #include "xdnd.h"
43 #endif
45 #ifdef HAVE_XRANDR
46 #include <X11/extensions/Xrandr.h>
47 #endif
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
54 #include "window.h"
55 #include "actions.h"
56 #include "client.h"
57 #include "main.h"
58 #include "cycling.h"
59 #include "keybind.h"
60 #include "application.h"
61 #include "stacking.h"
62 #include "defaults.h"
63 #include "workspace.h"
64 #include "dock.h"
65 #include "framewin.h"
66 #include "properties.h"
67 #include "balloon.h"
68 #include "xinerama.h"
69 #include "wmspec.h"
70 #include "rootmenu.h"
71 #include "colormap.h"
72 #include "screen.h"
73 #include "shutdown.h"
74 #include "misc.h"
75 #include "event.h"
76 #include "winmenu.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern XContext wWinContext;
81 extern XContext wVEdgeContext;
83 extern Cursor wCursor[WCUR_LAST];
85 extern WShortKey wKeyBindings[WKBD_LAST];
86 extern int wScreenCount;
87 extern Time LastTimestamp;
88 extern Time LastFocusChange;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern Atom _XA_WM_COLORMAP_NOTIFY;
94 extern Atom _XA_WM_CHANGE_STATE;
95 extern Atom _XA_WM_DELETE_WINDOW;
96 extern Atom _XA_GNUSTEP_WM_ATTR;
97 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
98 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
99 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
100 extern Atom _XA_WINDOWMAKER_COMMAND;
101 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
103 #ifdef SHAPE
104 extern Bool wShapeSupported;
105 extern int wShapeEventBase;
106 #endif
108 #ifdef KEEP_XKB_LOCK_STATUS
109 extern int wXkbEventBase;
110 #endif
112 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent *event);
115 static void handleColormapNotify(XEvent *event);
116 static void handleMapNotify(XEvent *event);
117 static void handleUnmapNotify(XEvent *event);
118 static void handleButtonPress(XEvent *event);
119 static void handleExpose(XEvent *event);
120 static void handleDestroyNotify(XEvent *event);
121 static void handleConfigureRequest(XEvent *event);
122 static void handleMapRequest(XEvent *event);
123 static void handlePropertyNotify(XEvent *event);
124 static void handleEnterNotify(XEvent *event);
125 static void handleLeaveNotify(XEvent *event);
126 static void handleExtensions(XEvent *event);
127 static void handleClientMessage(XEvent *event);
128 static void handleKeyPress(XEvent *event);
129 static void handleFocusIn(XEvent *event);
130 static void handleMotionNotify(XEvent *event);
131 static void handleVisibilityNotify(XEvent *event);
132 static void handle_inotify_events(int fd, int wd);
133 static void wdelete_death_handler(WMagicNumber id);
136 #ifdef SHAPE
137 static void handleShapeNotify(XEvent *event);
138 #endif
140 #ifdef KEEP_XKB_LOCK_STATUS
141 static void handleXkbIndicatorStateNotify(XEvent *event);
142 #endif
144 /* real dead process handler */
145 static void handleDeadProcess(void *foo);
147 typedef struct DeadProcesses {
148 pid_t pid;
149 unsigned char exit_status;
150 } DeadProcesses;
152 /* stack of dead processes */
153 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
154 static int deadProcessPtr = 0;
156 typedef struct DeathHandler {
157 WDeathHandler *callback;
158 pid_t pid;
159 void *client_data;
160 } DeathHandler;
162 static WMArray *deathHandlers = NULL;
164 WMagicNumber 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, free);
179 WMAddToArray(deathHandlers, handler);
181 return handler;
184 static void wdelete_death_handler(WMagicNumber id)
186 DeathHandler *handler = (DeathHandler *) id;
188 if (!handler || !deathHandlers)
189 return;
191 /* array destructor will call free(handler) */
192 WMRemoveFromArray(deathHandlers, handler);
195 void DispatchEvent(XEvent * event)
197 if (deathHandlers)
198 handleDeadProcess(NULL);
200 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
201 WCHANGE_STATE(WSTATE_EXITING);
202 /* received SIGTERM */
204 * WMHandleEvent() can't be called from anything
205 * executed inside here, or we can get in a infinite
206 * recursive loop.
208 Shutdown(WSExitMode);
210 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
211 WCHANGE_STATE(WSTATE_RESTARTING);
213 Shutdown(WSRestartPreparationMode);
214 /* received SIGHUP */
215 Restart(NULL, True);
216 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
217 WCHANGE_STATE(WSTATE_NORMAL);
218 wDefaultsCheckDomains(NULL);
221 /* for the case that all that is wanted to be dispatched is
222 * the stuff above */
223 if (!event)
224 return;
226 saveTimestamp(event);
227 switch (event->type) {
228 case MapRequest:
229 handleMapRequest(event);
230 break;
232 case KeyPress:
233 handleKeyPress(event);
234 break;
236 case MotionNotify:
237 handleMotionNotify(event);
238 break;
240 case ConfigureRequest:
241 handleConfigureRequest(event);
242 break;
244 case DestroyNotify:
245 handleDestroyNotify(event);
246 break;
248 case MapNotify:
249 handleMapNotify(event);
250 break;
252 case UnmapNotify:
253 handleUnmapNotify(event);
254 break;
256 case ButtonPress:
257 handleButtonPress(event);
258 break;
260 case Expose:
261 handleExpose(event);
262 break;
264 case PropertyNotify:
265 handlePropertyNotify(event);
266 break;
268 case EnterNotify:
269 handleEnterNotify(event);
270 break;
272 case LeaveNotify:
273 handleLeaveNotify(event);
274 break;
276 case ClientMessage:
277 handleClientMessage(event);
278 break;
280 case ColormapNotify:
281 handleColormapNotify(event);
282 break;
284 case MappingNotify:
285 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
286 XRefreshKeyboardMapping(&event->xmapping);
287 break;
289 case FocusIn:
290 handleFocusIn(event);
291 break;
293 case VisibilityNotify:
294 handleVisibilityNotify(event);
295 break;
297 case ConfigureNotify:
298 #ifdef HAVE_XRANDR
299 if (event->xconfigure.window == DefaultRootWindow(dpy))
300 XRRUpdateConfiguration(event);
301 #endif
302 break;
304 default:
305 handleExtensions(event);
306 break;
310 #ifdef HAVE_INOTIFY
312 *----------------------------------------------------------------------
313 * handle_inotify_events-
314 * Check for inotify events
316 * Returns:
317 * After reading events for the given file descriptor (fd) and
318 * watch descriptor (wd)
320 * Side effects:
321 * Calls wDefaultsCheckDomains if config database is updated
322 *----------------------------------------------------------------------
324 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
325 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
326 static void handle_inotify_events(int fd, int wd)
328 ssize_t eventQLength, i = 0;
329 char buff[BUFF_SIZE] = { 0 };
330 /* Check config only once per read of the event queue */
331 int oneShotFlag = 0;
334 * Read off the queued events
335 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
336 * not occur; the block is on Xevents, but a config file change will normally
337 * occur as a result of an Xevent - so the event queue should never have more than
338 * a few entries before a read().
340 eventQLength = read(fd, buff, BUFF_SIZE);
342 /* check what events occured */
343 /* Should really check wd here too, but for now we only have one watch! */
344 while (i < eventQLength) {
345 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
348 * see inotify.h for event types.
350 if (pevent->mask & IN_DELETE_SELF) {
351 wwarning(_("the defaults database has been deleted!"
352 " Restart Window Maker to create the database" " with the default settings"));
353 close(fd);
355 if (pevent->mask & IN_UNMOUNT) {
356 wwarning(_("the unit containing the defaults database has"
357 " been unmounted. Setting --static mode." " Any changes will not be saved."));
358 close(fd);
359 wPreferences.flags.noupdates = 1;
361 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
362 wwarning(_("Inotify: Reading config files in defaults database."));
363 wDefaultsCheckDomains(NULL);
366 /* move to next event in the buffer */
367 i += sizeof(struct inotify_event) + pevent->len;
370 #endif /* HAVE_INOTIFY */
373 *----------------------------------------------------------------------
374 * EventLoop-
375 * Processes X and internal events indefinitely.
377 * Returns:
378 * Never returns
380 * Side effects:
381 * The LastTimestamp global variable is updated.
382 * Calls inotifyGetEvents if defaults database changes.
383 *----------------------------------------------------------------------
385 noreturn void EventLoop(void)
387 XEvent event;
388 #ifdef HAVE_INOTIFY
389 extern int inotifyFD;
390 extern int inotifyWD;
391 struct timeval time;
392 fd_set rfds;
393 int retVal = 0;
395 if (inotifyFD < 0 || inotifyWD < 0)
396 retVal = -1;
397 #endif
399 for (;;) {
401 WMNextEvent(dpy, &event); /* Blocks here */
402 WMHandleEvent(&event);
403 #ifdef HAVE_INOTIFY
404 if (retVal != -1) {
405 time.tv_sec = 0;
406 time.tv_usec = 0;
407 FD_ZERO(&rfds);
408 FD_SET(inotifyFD, &rfds);
410 /* check for available read data from inotify - don't block! */
411 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
413 if (retVal < 0) { /* an error has occured */
414 wwarning(_("select failed. The inotify instance will be closed."
415 " Changes to the defaults database will require"
416 " a restart to take effect."));
417 close(inotifyFD);
418 continue;
420 if (FD_ISSET(inotifyFD, &rfds))
421 handle_inotify_events(inotifyFD, inotifyWD);
423 #endif
428 *----------------------------------------------------------------------
429 * ProcessPendingEvents --
430 * Processes the events that are currently pending (at the time
431 * this function is called) in the display's queue.
433 * Returns:
434 * After the pending events that were present at the function call
435 * are processed.
437 * Side effects:
438 * Many -- whatever handling events may involve.
440 *----------------------------------------------------------------------
442 void ProcessPendingEvents(void)
444 XEvent event;
445 int count;
447 XSync(dpy, False);
449 /* Take a snapshot of the event count in the queue */
450 count = XPending(dpy);
452 while (count > 0 && XPending(dpy)) {
453 WMNextEvent(dpy, &event);
454 WMHandleEvent(&event);
455 count--;
459 Bool IsDoubleClick(WScreen * scr, XEvent * event)
461 if ((scr->last_click_time > 0) &&
462 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
463 && (event->xbutton.button == scr->last_click_button)
464 && (event->xbutton.window == scr->last_click_window)) {
466 scr->flags.next_click_is_not_double = 1;
467 scr->last_click_time = 0;
468 scr->last_click_window = event->xbutton.window;
470 return True;
472 return False;
475 void NotifyDeadProcess(pid_t pid, unsigned char status)
477 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
478 wwarning("stack overflow: too many dead processes");
479 return;
481 /* stack the process to be handled later,
482 * as this is called from the signal handler */
483 deadProcesses[deadProcessPtr].pid = pid;
484 deadProcesses[deadProcessPtr].exit_status = status;
485 deadProcessPtr++;
488 static void handleDeadProcess(void *foo)
490 DeathHandler *tmp;
491 int i;
493 for (i = 0; i < deadProcessPtr; i++) {
494 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
497 if (!deathHandlers) {
498 deadProcessPtr = 0;
499 return;
502 /* get the pids on the queue and call handlers */
503 while (deadProcessPtr > 0) {
504 deadProcessPtr--;
506 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
507 tmp = WMGetFromArray(deathHandlers, i);
508 if (!tmp)
509 continue;
511 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
512 (*tmp->callback) (tmp->pid,
513 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
514 wdelete_death_handler(tmp);
520 static void saveTimestamp(XEvent * event)
523 * Never save CurrentTime as LastTimestamp because CurrentTime
524 * it's not a real timestamp (it's the 0L constant)
527 switch (event->type) {
528 case ButtonRelease:
529 case ButtonPress:
530 LastTimestamp = event->xbutton.time;
531 break;
532 case KeyPress:
533 case KeyRelease:
534 LastTimestamp = event->xkey.time;
535 break;
536 case MotionNotify:
537 LastTimestamp = event->xmotion.time;
538 break;
539 case PropertyNotify:
540 LastTimestamp = event->xproperty.time;
541 break;
542 case EnterNotify:
543 case LeaveNotify:
544 LastTimestamp = event->xcrossing.time;
545 break;
546 case SelectionClear:
547 LastTimestamp = event->xselectionclear.time;
548 break;
549 case SelectionRequest:
550 LastTimestamp = event->xselectionrequest.time;
551 break;
552 case SelectionNotify:
553 LastTimestamp = event->xselection.time;
554 #ifdef XDND
555 wXDNDProcessSelection(event);
556 #endif
557 break;
561 static int matchWindow(const void *item, const void *cdata)
563 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
566 static void handleExtensions(XEvent * event)
568 #ifdef KEEP_XKB_LOCK_STATUS
569 XkbEvent *xkbevent;
570 xkbevent = (XkbEvent *) event;
571 #endif /*KEEP_XKB_LOCK_STATUS */
572 #ifdef SHAPE
573 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
574 handleShapeNotify(event);
576 #endif
577 #ifdef KEEP_XKB_LOCK_STATUS
578 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
579 handleXkbIndicatorStateNotify(event);
581 #endif /*KEEP_XKB_LOCK_STATUS */
582 #ifdef HAVE_XRANDR
583 if (has_randr && event->type == (randr_event_base + RRScreenChangeNotify)) {
584 /* From xrandr man page: "Clients must call back into Xlib using
585 * XRRUpdateConfiguration when screen configuration change notify
586 * events are generated */
587 XRRUpdateConfiguration(event);
588 WCHANGE_STATE(WSTATE_RESTARTING);
589 Shutdown(WSRestartPreparationMode);
590 Restart(NULL,True);
592 #endif
595 static void handleMapRequest(XEvent * ev)
597 WWindow *wwin;
598 WScreen *scr = NULL;
599 Window window = ev->xmaprequest.window;
601 if ((wwin = wWindowFor(window))) {
602 if (wwin->flags.shaded) {
603 wUnshadeWindow(wwin);
605 /* deiconify window */
606 if (wwin->flags.miniaturized) {
607 wDeiconifyWindow(wwin);
608 } else if (wwin->flags.hidden) {
609 WApplication *wapp = wApplicationOf(wwin->main_window);
610 /* go to the last workspace that the user worked on the app */
611 if (wapp) {
612 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
614 wUnhideApplication(wapp, False, False);
616 return;
619 scr = wScreenForRootWindow(ev->xmaprequest.parent);
621 wwin = wManageWindow(scr, window);
624 * This is to let the Dock know that the application it launched
625 * has already been mapped (eg: it has finished launching).
626 * It is not necessary for normally docked apps, but is needed for
627 * apps that were forcedly docked (like with dockit).
629 if (scr->last_dock) {
630 if (wwin && wwin->main_window != None && wwin->main_window != window)
631 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
632 else
633 wDockTrackWindowLaunch(scr->last_dock, window);
636 if (wwin) {
637 wClientSetState(wwin, NormalState, None);
638 if (wwin->flags.maximized) {
639 wMaximizeWindow(wwin, wwin->flags.maximized);
641 if (wwin->flags.shaded) {
642 wwin->flags.shaded = 0;
643 wwin->flags.skip_next_animation = 1;
644 wShadeWindow(wwin);
646 if (wwin->flags.miniaturized) {
647 wwin->flags.miniaturized = 0;
648 wwin->flags.skip_next_animation = 1;
649 wIconifyWindow(wwin);
651 if (wwin->flags.fullscreen) {
652 wwin->flags.fullscreen = 0;
653 wFullscreenWindow(wwin);
655 if (wwin->flags.hidden) {
656 WApplication *wapp = wApplicationOf(wwin->main_window);
658 wwin->flags.hidden = 0;
659 wwin->flags.skip_next_animation = 1;
660 if (wapp) {
661 wHideApplication(wapp);
667 static void handleDestroyNotify(XEvent * event)
669 WWindow *wwin;
670 WApplication *app;
671 Window window = event->xdestroywindow.window;
672 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
673 int widx;
675 wwin = wWindowFor(window);
676 if (wwin) {
677 wUnmanageWindow(wwin, False, True);
680 if (scr != NULL) {
681 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
682 WFakeGroupLeader *fPtr;
684 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
685 if (fPtr->retainCount > 0) {
686 fPtr->retainCount--;
687 if (fPtr->retainCount == 0 && fPtr->leader != None) {
688 XDestroyWindow(dpy, fPtr->leader);
689 fPtr->leader = None;
690 XFlush(dpy);
693 fPtr->origLeader = None;
697 app = wApplicationOf(window);
698 if (app) {
699 if (window == app->main_window) {
700 app->refcount = 0;
701 wwin = app->main_window_desc->screen_ptr->focused_window;
702 while (wwin) {
703 if (wwin->main_window == window) {
704 wwin->main_window = None;
706 wwin = wwin->prev;
709 wApplicationDestroy(app);
713 static void handleExpose(XEvent * event)
715 WObjDescriptor *desc;
716 XEvent ev;
718 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
720 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
721 return;
724 if (desc->handle_expose) {
725 (*desc->handle_expose) (desc, event);
729 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
731 switch (action) {
732 case WA_SELECT_WINDOWS:
733 wUnselectWindows(scr);
734 wSelectWindows(scr, event);
735 break;
736 case WA_OPEN_APPMENU:
737 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
738 /* ugly hack */
739 if (scr->root_menu) {
740 if (scr->root_menu->brother->flags.mapped)
741 event->xbutton.window = scr->root_menu->brother->frame->core->window;
742 else
743 event->xbutton.window = scr->root_menu->frame->core->window;
745 break;
746 case WA_OPEN_WINLISTMENU:
747 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
748 if (scr->switch_menu) {
749 if (scr->switch_menu->brother->flags.mapped)
750 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
751 else
752 event->xbutton.window = scr->switch_menu->frame->core->window;
754 break;
755 default:
756 break;
760 /* bindable */
761 static void handleButtonPress(XEvent * event)
763 WObjDescriptor *desc;
764 WScreen *scr;
766 scr = wScreenForRootWindow(event->xbutton.root);
768 #ifdef BALLOON_TEXT
769 wBalloonHide(scr);
770 #endif
772 if (event->xbutton.window == scr->root_win) {
773 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
774 executeButtonAction(scr, event, wPreferences.mouse_button1);
775 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
776 executeButtonAction(scr, event, wPreferences.mouse_button2);
777 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
778 executeButtonAction(scr, event, wPreferences.mouse_button3);
779 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
780 wWorkspaceRelativeChange(scr, 1);
781 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
782 wWorkspaceRelativeChange(scr, -1);
786 desc = NULL;
787 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
788 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
789 return;
793 if (desc->parent_type == WCLASS_WINDOW) {
794 XSync(dpy, 0);
796 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
797 XAllowEvents(dpy, AsyncPointer, CurrentTime);
798 } else {
799 /* if (wPreferences.focus_mode == WKF_CLICK) { */
800 if (wPreferences.ignore_focus_click) {
801 XAllowEvents(dpy, AsyncPointer, CurrentTime);
803 XAllowEvents(dpy, ReplayPointer, CurrentTime);
804 /* } */
806 XSync(dpy, 0);
807 } else if (desc->parent_type == WCLASS_APPICON
808 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
809 if (event->xbutton.state & MOD_MASK) {
810 XSync(dpy, 0);
811 XAllowEvents(dpy, AsyncPointer, CurrentTime);
812 XSync(dpy, 0);
816 if (desc->handle_mousedown != NULL) {
817 (*desc->handle_mousedown) (desc, event);
820 /* save double-click information */
821 if (scr->flags.next_click_is_not_double) {
822 scr->flags.next_click_is_not_double = 0;
823 } else {
824 scr->last_click_time = event->xbutton.time;
825 scr->last_click_button = event->xbutton.button;
826 scr->last_click_window = event->xbutton.window;
830 static void handleMapNotify(XEvent * event)
832 WWindow *wwin;
834 wwin = wWindowFor(event->xmap.event);
835 if (wwin && wwin->client_win == event->xmap.event) {
836 if (wwin->flags.miniaturized) {
837 wDeiconifyWindow(wwin);
838 } else {
839 XGrabServer(dpy);
840 wWindowMap(wwin);
841 wClientSetState(wwin, NormalState, None);
842 XUngrabServer(dpy);
847 static void handleUnmapNotify(XEvent * event)
849 WWindow *wwin;
850 XEvent ev;
851 Bool withdraw = False;
853 /* only process windows with StructureNotify selected
854 * (ignore SubstructureNotify) */
855 wwin = wWindowFor(event->xunmap.window);
856 if (!wwin)
857 return;
859 /* whether the event is a Withdrawal request */
860 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
861 withdraw = True;
863 if (wwin->client_win != event->xunmap.event && !withdraw)
864 return;
866 if (!wwin->flags.mapped && !withdraw
867 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
868 && !wwin->flags.miniaturized && !wwin->flags.hidden)
869 return;
871 XGrabServer(dpy);
872 XUnmapWindow(dpy, wwin->frame->core->window);
873 wwin->flags.mapped = 0;
874 XSync(dpy, 0);
875 /* check if the window was destroyed */
876 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
877 DispatchEvent(&ev);
878 } else {
879 Bool reparented = False;
881 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
882 reparented = True;
884 /* withdraw window */
885 wwin->flags.mapped = 0;
886 if (!reparented)
887 wClientSetState(wwin, WithdrawnState, None);
889 /* if the window was reparented, do not reparent it back to the
890 * root window */
891 wUnmanageWindow(wwin, !reparented, False);
893 XUngrabServer(dpy);
896 static void handleConfigureRequest(XEvent * event)
898 WWindow *wwin;
900 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
902 * Configure request for unmapped window
904 wClientConfigure(NULL, &(event->xconfigurerequest));
905 } else {
906 wClientConfigure(wwin, &(event->xconfigurerequest));
910 static void handlePropertyNotify(XEvent * event)
912 WWindow *wwin;
913 WApplication *wapp;
914 Window jr;
915 int ji;
916 unsigned int ju;
918 wwin = wWindowFor(event->xproperty.window);
919 if (wwin) {
920 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
921 return;
923 wClientCheckProperty(wwin, &event->xproperty);
925 wapp = wApplicationOf(event->xproperty.window);
926 if (wapp) {
927 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
931 static void handleClientMessage(XEvent * event)
933 WWindow *wwin;
934 WObjDescriptor *desc;
936 /* handle transition from Normal to Iconic state */
937 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
938 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
940 wwin = wWindowFor(event->xclient.window);
941 if (!wwin)
942 return;
943 if (!wwin->flags.miniaturized)
944 wIconifyWindow(wwin);
945 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
946 WScreen *scr = wScreenForRootWindow(event->xclient.window);
948 if (!scr)
949 return;
951 if (event->xclient.data.l[1] == 1) { /* starting */
952 wColormapAllowClientInstallation(scr, True);
953 } else { /* stopping */
954 wColormapAllowClientInstallation(scr, False);
956 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
958 char *command;
959 size_t len;
961 len = sizeof(event->xclient.data.b) + 1;
962 command = wmalloc(len);
963 strncpy(command, event->xclient.data.b, sizeof(event->xclient.data.b));
965 if (strncmp(command, "Reconfigure", sizeof("Reconfigure")) == 0) {
966 wwarning(_("Got Reconfigure command"));
967 wDefaultsCheckDomains(NULL);
968 } else {
969 wwarning(_("Got unknown command %s"), command);
972 wfree(command);
974 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
975 WApplication *wapp;
976 int done = 0;
977 wapp = wApplicationOf(event->xclient.window);
978 if (wapp) {
979 switch (event->xclient.data.l[0]) {
980 case WMFHideOtherApplications:
981 wHideOtherApplications(wapp->main_window_desc);
982 done = 1;
983 break;
985 case WMFHideApplication:
986 wHideApplication(wapp);
987 done = 1;
988 break;
991 if (!done) {
992 wwin = wWindowFor(event->xclient.window);
993 if (wwin) {
994 switch (event->xclient.data.l[0]) {
995 case WMFHideOtherApplications:
996 wHideOtherApplications(wwin);
997 break;
999 case WMFHideApplication:
1000 wHideApplication(wApplicationOf(wwin->main_window));
1001 break;
1005 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
1006 wwin = wWindowFor(event->xclient.window);
1007 if (!wwin)
1008 return;
1009 switch (event->xclient.data.l[0]) {
1010 case GSWindowLevelAttr:
1012 int level = (int)event->xclient.data.l[1];
1014 if (WINDOW_LEVEL(wwin) != level) {
1015 ChangeStackingLevel(wwin->frame->core, level);
1018 break;
1020 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
1021 wwin = wWindowFor(event->xclient.window);
1022 if (!wwin)
1023 return;
1024 switch (event->xclient.data.l[0]) {
1025 case WMTitleBarNormal:
1026 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1027 break;
1028 case WMTitleBarMain:
1029 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1030 break;
1031 case WMTitleBarKey:
1032 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1033 break;
1035 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1036 WScreen *scr = wScreenForRootWindow(event->xclient.window);
1037 if (!scr)
1038 return;
1039 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1040 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1041 /* do nothing */
1042 #ifdef XDND
1043 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1044 /* do nothing */
1045 #endif /* XDND */
1046 } else {
1048 * Non-standard thing, but needed by OffiX DND.
1049 * For when the icon frame gets a ClientMessage
1050 * that should have gone to the icon_window.
1052 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1053 struct WIcon *icon = NULL;
1055 if (desc->parent_type == WCLASS_MINIWINDOW) {
1056 icon = (WIcon *) desc->parent;
1057 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1058 icon = ((WAppIcon *) desc->parent)->icon;
1060 if (icon && (wwin = icon->owner)) {
1061 if (wwin->client_win != event->xclient.window) {
1062 event->xclient.window = wwin->client_win;
1063 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1070 static void raiseWindow(WScreen * scr)
1072 WWindow *wwin;
1074 scr->autoRaiseTimer = NULL;
1076 wwin = wWindowFor(scr->autoRaiseWindow);
1077 if (!wwin)
1078 return;
1080 if (!wwin->flags.destroyed && wwin->flags.focused) {
1081 wRaiseFrame(wwin->frame->core);
1082 /* this is needed or a race condition will occur */
1083 XSync(dpy, False);
1087 static void handleEnterNotify(XEvent * event)
1089 WWindow *wwin;
1090 WObjDescriptor *desc = NULL;
1091 XEvent ev;
1092 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1094 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1095 /* already left the window... */
1096 saveTimestamp(&ev);
1097 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1098 return;
1102 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1103 if (desc->handle_enternotify)
1104 (*desc->handle_enternotify) (desc, event);
1107 /* enter to window */
1108 wwin = wWindowFor(event->xcrossing.window);
1109 if (!wwin) {
1110 if (wPreferences.colormap_mode == WCM_POINTER) {
1111 wColormapInstallForWindow(scr, NULL);
1113 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1114 WMDeleteTimerHandler(scr->autoRaiseTimer);
1115 scr->autoRaiseTimer = NULL;
1117 } else {
1118 /* set auto raise timer even if in focus-follows-mouse mode
1119 * and the event is for the frame window, even if the window
1120 * has focus already. useful if you move the pointer from a focused
1121 * window to the root window and back pretty fast
1123 * set focus if in focus-follows-mouse mode and the event
1124 * is for the frame window and window doesn't have focus yet */
1125 if (wPreferences.focus_mode == WKF_SLOPPY
1126 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1128 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1129 wSetFocusTo(scr, wwin);
1131 if (scr->autoRaiseTimer)
1132 WMDeleteTimerHandler(scr->autoRaiseTimer);
1133 scr->autoRaiseTimer = NULL;
1135 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1136 scr->autoRaiseWindow = wwin->frame->core->window;
1137 scr->autoRaiseTimer
1138 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1141 /* Install colormap for window, if the colormap installation mode
1142 * is colormap_follows_mouse */
1143 if (wPreferences.colormap_mode == WCM_POINTER) {
1144 if (wwin->client_win == event->xcrossing.window)
1145 wColormapInstallForWindow(scr, wwin);
1146 else
1147 wColormapInstallForWindow(scr, NULL);
1151 if (event->xcrossing.window == event->xcrossing.root
1152 && event->xcrossing.detail == NotifyNormal
1153 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1155 wSetFocusTo(scr, scr->focused_window);
1157 #ifdef BALLOON_TEXT
1158 wBalloonEnteredObject(scr, desc);
1159 #endif
1162 static void handleLeaveNotify(XEvent * event)
1164 WObjDescriptor *desc = NULL;
1166 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1167 if (desc->handle_leavenotify)
1168 (*desc->handle_leavenotify) (desc, event);
1172 #ifdef SHAPE
1173 static void handleShapeNotify(XEvent * event)
1175 XShapeEvent *shev = (XShapeEvent *) event;
1176 WWindow *wwin;
1177 union {
1178 XEvent xevent;
1179 XShapeEvent xshape;
1180 } ev;
1182 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev.xevent)) {
1183 if (ev.xshape.kind == ShapeBounding) {
1184 if (ev.xshape.shaped == shev->shaped) {
1185 *shev = ev.xshape;
1186 } else {
1187 XPutBackEvent(dpy, &ev.xevent);
1188 break;
1193 wwin = wWindowFor(shev->window);
1194 if (!wwin || shev->kind != ShapeBounding)
1195 return;
1197 if (!shev->shaped && wwin->flags.shaped) {
1199 wwin->flags.shaped = 0;
1200 wWindowClearShape(wwin);
1202 } else if (shev->shaped) {
1204 wwin->flags.shaped = 1;
1205 wWindowSetShape(wwin);
1208 #endif /* SHAPE */
1210 #ifdef KEEP_XKB_LOCK_STATUS
1211 /* please help ]d if you know what to do */
1212 static void handleXkbIndicatorStateNotify(XEvent *event)
1214 WWindow *wwin;
1215 WScreen *scr;
1216 XkbStateRec staterec;
1217 int i;
1219 for (i = 0; i < wScreenCount; i++) {
1220 scr = wScreenWithNumber(i);
1221 wwin = scr->focused_window;
1222 if (wwin && wwin->flags.focused) {
1223 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1224 if (wwin->frame->languagemode != staterec.group) {
1225 wwin->frame->last_languagemode = wwin->frame->languagemode;
1226 wwin->frame->languagemode = staterec.group;
1228 #ifdef XKB_BUTTON_HINT
1229 if (wwin->frame->titlebar) {
1230 wFrameWindowPaint(wwin->frame);
1232 #endif
1236 #endif /*KEEP_XKB_LOCK_STATUS */
1238 static void handleColormapNotify(XEvent * event)
1240 WWindow *wwin;
1241 WScreen *scr;
1242 Bool reinstall = False;
1244 wwin = wWindowFor(event->xcolormap.window);
1245 if (!wwin)
1246 return;
1248 scr = wwin->screen_ptr;
1250 do {
1251 if (wwin) {
1252 if (event->xcolormap.new) {
1253 XWindowAttributes attr;
1255 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1257 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1258 scr->current_colormap = attr.colormap;
1260 reinstall = True;
1261 } else if (event->xcolormap.state == ColormapUninstalled &&
1262 scr->current_colormap == event->xcolormap.colormap) {
1264 /* some bastard app (like XV) removed our colormap */
1266 * can't enforce or things like xscreensaver wont work
1267 * reinstall = True;
1269 } else if (event->xcolormap.state == ColormapInstalled &&
1270 scr->current_colormap == event->xcolormap.colormap) {
1272 /* someone has put our colormap back */
1273 reinstall = False;
1276 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1277 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1279 if (reinstall && scr->current_colormap != None) {
1280 if (!scr->flags.colormap_stuff_blocked)
1281 XInstallColormap(dpy, scr->current_colormap);
1285 static void handleFocusIn(XEvent * event)
1287 WWindow *wwin;
1290 * For applications that like stealing the focus.
1292 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1293 saveTimestamp(event);
1294 if (event->xfocus.mode == NotifyUngrab
1295 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1296 return;
1299 wwin = wWindowFor(event->xfocus.window);
1300 if (wwin && !wwin->flags.focused) {
1301 if (wwin->flags.mapped)
1302 wSetFocusTo(wwin->screen_ptr, wwin);
1303 else
1304 wSetFocusTo(wwin->screen_ptr, NULL);
1305 } else if (!wwin) {
1306 WScreen *scr = wScreenForWindow(event->xfocus.window);
1307 if (scr)
1308 wSetFocusTo(scr, NULL);
1312 static WWindow *windowUnderPointer(WScreen * scr)
1314 unsigned int mask;
1315 int foo;
1316 Window bar, win;
1318 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1319 return wWindowFor(win);
1320 return NULL;
1323 static int CheckFullScreenWindowFocused(WScreen * scr)
1325 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1326 return 1;
1327 else
1328 return 0;
1331 static void handleKeyPress(XEvent * event)
1333 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1334 WWindow *wwin = scr->focused_window;
1335 short i, widx;
1336 int modifiers;
1337 int command = -1;
1338 #ifdef KEEP_XKB_LOCK_STATUS
1339 XkbStateRec staterec;
1340 #endif /*KEEP_XKB_LOCK_STATUS */
1342 /* ignore CapsLock */
1343 modifiers = event->xkey.state & ValidModMask;
1345 for (i = 0; i < WKBD_LAST; i++) {
1346 if (wKeyBindings[i].keycode == 0)
1347 continue;
1349 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1350 || */ wKeyBindings[i].modifier ==
1351 modifiers)) {
1352 command = i;
1353 break;
1357 if (command < 0) {
1359 if (!wRootMenuPerformShortcut(event)) {
1360 static int dontLoop = 0;
1362 if (dontLoop > 10) {
1363 wwarning("problem with key event processing code");
1364 return;
1366 dontLoop++;
1367 /* if the focused window is an internal window, try redispatching
1368 * the event to the managed window, as it can be a WINGs window */
1369 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1370 /* client_leader contains the WINGs toplevel */
1371 event->xany.window = wwin->client_leader;
1372 WMHandleEvent(event);
1374 dontLoop--;
1376 return;
1378 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1379 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1381 switch (command) {
1383 case WKBD_ROOTMENU:
1384 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1385 if (!CheckFullScreenWindowFocused(scr)) {
1386 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1387 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1388 True);
1390 break;
1391 case WKBD_WINDOWLIST:
1392 if (!CheckFullScreenWindowFocused(scr)) {
1393 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1394 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1395 True);
1397 break;
1399 case WKBD_WINDOWMENU:
1400 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1401 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1402 break;
1403 case WKBD_MINIMIZEALL:
1404 CloseWindowMenu(scr);
1405 wHideAll(scr);
1406 break;
1407 case WKBD_MINIATURIZE:
1408 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1409 && !WFLAGP(wwin, no_miniaturizable)) {
1410 CloseWindowMenu(scr);
1412 if (wwin->protocols.MINIATURIZE_WINDOW)
1413 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1414 else {
1415 wIconifyWindow(wwin);
1418 break;
1419 case WKBD_HIDE:
1420 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1421 WApplication *wapp = wApplicationOf(wwin->main_window);
1422 CloseWindowMenu(scr);
1424 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1425 wHideApplication(wapp);
1428 break;
1429 case WKBD_HIDE_OTHERS:
1430 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1431 CloseWindowMenu(scr);
1433 wHideOtherApplications(wwin);
1435 break;
1436 case WKBD_MAXIMIZE:
1437 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1438 CloseWindowMenu(scr);
1440 handleMaximize(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1442 break;
1443 case WKBD_VMAXIMIZE:
1444 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1445 CloseWindowMenu(scr);
1447 handleMaximize(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1449 break;
1450 case WKBD_HMAXIMIZE:
1451 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1452 CloseWindowMenu(scr);
1454 handleMaximize(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1456 break;
1457 case WKBD_LHMAXIMIZE:
1458 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1459 CloseWindowMenu(scr);
1461 handleMaximize(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1463 break;
1464 case WKBD_RHMAXIMIZE:
1465 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1466 CloseWindowMenu(scr);
1468 handleMaximize(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1470 break;
1471 case WKBD_THMAXIMIZE:
1472 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1473 CloseWindowMenu(scr);
1475 handleMaximize(wwin, MAX_HORIZONTAL | MAX_TOPHALF | MAX_KEYBOARD);
1477 break;
1478 case WKBD_BHMAXIMIZE:
1479 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1480 CloseWindowMenu(scr);
1482 handleMaximize(wwin, MAX_HORIZONTAL | MAX_BOTTOMHALF | MAX_KEYBOARD);
1484 break;
1485 case WKBD_LTCMAXIMIZE:
1486 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1487 CloseWindowMenu(scr);
1489 handleMaximize(wwin, MAX_LEFTHALF | MAX_TOPHALF | MAX_KEYBOARD);
1491 break;
1492 case WKBD_RTCMAXIMIZE:
1493 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1494 CloseWindowMenu(scr);
1496 handleMaximize(wwin, MAX_RIGHTHALF | MAX_TOPHALF | MAX_KEYBOARD);
1498 break;
1499 case WKBD_LBCMAXIMIZE:
1500 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1501 CloseWindowMenu(scr);
1503 handleMaximize(wwin, MAX_LEFTHALF | MAX_BOTTOMHALF | MAX_KEYBOARD);
1505 break;
1506 case WKBD_RBCMAXIMIZE:
1507 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1508 CloseWindowMenu(scr);
1510 handleMaximize(wwin, MAX_RIGHTHALF | MAX_BOTTOMHALF | MAX_KEYBOARD);
1512 break;
1513 case WKBD_MAXIMUS:
1514 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1515 CloseWindowMenu(scr);
1517 handleMaximize(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1519 break;
1520 case WKBD_RAISE:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1522 CloseWindowMenu(scr);
1524 wRaiseFrame(wwin->frame->core);
1526 break;
1527 case WKBD_LOWER:
1528 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1529 CloseWindowMenu(scr);
1531 wLowerFrame(wwin->frame->core);
1533 break;
1534 case WKBD_RAISELOWER:
1535 /* raise or lower the window under the pointer, not the
1536 * focused one
1538 wwin = windowUnderPointer(scr);
1539 if (wwin)
1540 wRaiseLowerFrame(wwin->frame->core);
1541 break;
1542 case WKBD_SHADE:
1543 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1544 if (wwin->flags.shaded)
1545 wUnshadeWindow(wwin);
1546 else
1547 wShadeWindow(wwin);
1549 break;
1550 case WKBD_MOVERESIZE:
1551 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1552 CloseWindowMenu(scr);
1554 wKeyboardMoveResizeWindow(wwin);
1556 break;
1557 case WKBD_CLOSE:
1558 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1559 CloseWindowMenu(scr);
1560 if (wwin->protocols.DELETE_WINDOW)
1561 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1563 break;
1564 case WKBD_SELECT:
1565 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1566 wSelectWindow(wwin, !wwin->flags.selected);
1568 break;
1569 case WKBD_FOCUSNEXT:
1570 StartWindozeCycle(wwin, event, True, False);
1571 break;
1573 case WKBD_FOCUSPREV:
1574 StartWindozeCycle(wwin, event, False, False);
1575 break;
1577 case WKBD_GROUPNEXT:
1578 StartWindozeCycle(wwin, event, True, True);
1579 break;
1581 case WKBD_GROUPPREV:
1582 StartWindozeCycle(wwin, event, False, True);
1583 break;
1585 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1586 widx = command - WKBD_WORKSPACE1;
1587 i = (scr->current_workspace / 10) * 10 + widx;
1588 if (wPreferences.ws_advance || i < scr->workspace_count)
1589 wWorkspaceChange(scr, i);
1590 break;
1592 case WKBD_NEXTWORKSPACE:
1593 wWorkspaceRelativeChange(scr, 1);
1594 break;
1595 case WKBD_PREVWORKSPACE:
1596 wWorkspaceRelativeChange(scr, -1);
1597 break;
1598 case WKBD_LASTWORKSPACE:
1599 wWorkspaceChange(scr, scr->last_workspace);
1600 break;
1602 case WKBD_MOVE_WORKSPACE1 ... WKBD_MOVE_WORKSPACE10:
1603 widx = command - WKBD_MOVE_WORKSPACE1;
1604 i = (scr->current_workspace / 10) * 10 + widx;
1605 if (wwin && (wPreferences.ws_advance || i < scr->workspace_count))
1606 wWindowChangeWorkspace(wwin, i);
1607 break;
1609 case WKBD_MOVE_NEXTWORKSPACE:
1610 if (wwin)
1611 wWindowChangeWorkspaceRelative(wwin, 1);
1612 break;
1613 case WKBD_MOVE_PREVWORKSPACE:
1614 if (wwin)
1615 wWindowChangeWorkspaceRelative(wwin, -1);
1616 break;
1617 case WKBD_MOVE_LASTWORKSPACE:
1618 if (wwin)
1619 wWindowChangeWorkspace(wwin, scr->last_workspace);
1620 break;
1622 case WKBD_MOVE_NEXTWSLAYER:
1623 case WKBD_MOVE_PREVWSLAYER:
1625 if (wwin) {
1626 int row, column;
1628 row = scr->current_workspace / 10;
1629 column = scr->current_workspace % 10;
1631 if (command == WKBD_MOVE_NEXTWSLAYER) {
1632 if ((row + 1) * 10 < scr->workspace_count)
1633 wWindowChangeWorkspace(wwin, column + (row + 1) * 10);
1634 } else {
1635 if (row > 0)
1636 wWindowChangeWorkspace(wwin, column + (row - 1) * 10);
1640 break;
1642 case WKBD_WINDOW1:
1643 case WKBD_WINDOW2:
1644 case WKBD_WINDOW3:
1645 case WKBD_WINDOW4:
1646 case WKBD_WINDOW5:
1647 case WKBD_WINDOW6:
1648 case WKBD_WINDOW7:
1649 case WKBD_WINDOW8:
1650 case WKBD_WINDOW9:
1651 case WKBD_WINDOW10:
1653 widx = command - WKBD_WINDOW1;
1655 if (scr->shortcutWindows[widx]) {
1656 WMArray *list = scr->shortcutWindows[widx];
1657 int cw;
1658 int count = WMGetArrayItemCount(list);
1659 WWindow *twin;
1660 WMArrayIterator iter;
1661 WWindow *wwin;
1663 wUnselectWindows(scr);
1664 cw = scr->current_workspace;
1666 WM_ETARETI_ARRAY(list, wwin, iter) {
1667 if (count > 1)
1668 wWindowChangeWorkspace(wwin, cw);
1670 wMakeWindowVisible(wwin);
1672 if (count > 1)
1673 wSelectWindow(wwin, True);
1676 /* rotate the order of windows, to create a cycling effect */
1677 twin = WMGetFromArray(list, 0);
1678 WMDeleteFromArray(list, 0);
1679 WMAddToArray(list, twin);
1681 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1682 if (scr->shortcutWindows[widx]) {
1683 WMFreeArray(scr->shortcutWindows[widx]);
1684 scr->shortcutWindows[widx] = NULL;
1687 if (wwin->flags.selected && scr->selected_windows) {
1688 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1689 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1690 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1691 } else {
1692 scr->shortcutWindows[widx] = WMCreateArray(4);
1693 WMAddToArray(scr->shortcutWindows[widx], wwin);
1696 wSelectWindow(wwin, !wwin->flags.selected);
1697 XFlush(dpy);
1698 wusleep(3000);
1699 wSelectWindow(wwin, !wwin->flags.selected);
1700 XFlush(dpy);
1702 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1704 if (wwin->flags.selected && scr->selected_windows) {
1705 if (scr->shortcutWindows[widx]) {
1706 WMFreeArray(scr->shortcutWindows[widx]);
1708 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1712 break;
1714 case WKBD_RELAUNCH:
1715 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1716 (void) RelaunchWindow(wwin);
1718 break;
1720 case WKBD_SWITCH_SCREEN:
1721 if (wScreenCount > 1) {
1722 WScreen *scr2;
1723 int i;
1725 /* find index of this screen */
1726 for (i = 0; i < wScreenCount; i++) {
1727 if (wScreenWithNumber(i) == scr)
1728 break;
1730 i++;
1731 if (i >= wScreenCount) {
1732 i = 0;
1734 scr2 = wScreenWithNumber(i);
1736 if (scr2) {
1737 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1738 scr2->scr_width / 2, scr2->scr_height / 2);
1741 break;
1743 case WKBD_NEXTWSLAYER:
1744 case WKBD_PREVWSLAYER:
1746 int row, column;
1748 row = scr->current_workspace / 10;
1749 column = scr->current_workspace % 10;
1751 if (command == WKBD_NEXTWSLAYER) {
1752 if ((row + 1) * 10 < scr->workspace_count)
1753 wWorkspaceChange(scr, column + (row + 1) * 10);
1754 } else {
1755 if (row > 0)
1756 wWorkspaceChange(scr, column + (row - 1) * 10);
1759 break;
1760 case WKBD_CLIPRAISELOWER:
1761 if (!wPreferences.flags.noclip)
1762 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1763 break;
1764 case WKBD_DOCKRAISELOWER:
1765 if (!wPreferences.flags.nodock)
1766 wDockRaiseLower(scr->dock);
1767 break;
1768 #ifdef KEEP_XKB_LOCK_STATUS
1769 case WKBD_TOGGLE:
1770 if (wPreferences.modelock) {
1771 /*toggle */
1772 wwin = scr->focused_window;
1774 if (wwin && wwin->flags.mapped
1775 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1776 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1777 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1779 wwin->frame->languagemode = wwin->frame->last_languagemode;
1780 wwin->frame->last_languagemode = staterec.group;
1781 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1785 break;
1786 #endif /* KEEP_XKB_LOCK_STATUS */
1790 static void handleMotionNotify(XEvent * event)
1792 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1794 if (wPreferences.scrollable_menus) {
1795 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1796 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1798 if (scr->flags.jump_back_pending ||
1799 p.x <= (rect.pos.x + 1) ||
1800 p.x >= (rect.pos.x + rect.size.width - 2) ||
1801 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1802 WMenu *menu;
1804 menu = wMenuUnderPointer(scr);
1805 if (menu != NULL)
1806 wMenuScroll(menu, event);
1811 static void handleVisibilityNotify(XEvent * event)
1813 WWindow *wwin;
1815 wwin = wWindowFor(event->xvisibility.window);
1816 if (!wwin)
1817 return;
1818 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);