Fix non-ascii workspace rename via menu
[wmaker-crm.git] / src / event.c
blobe45cdc2b5148750301bb8fa20486620309341292
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 "funcs.h"
58 #include "keybind.h"
59 #include "application.h"
60 #include "stacking.h"
61 #include "defaults.h"
62 #include "workspace.h"
63 #include "dock.h"
64 #include "framewin.h"
65 #include "properties.h"
66 #include "balloon.h"
67 #include "xinerama.h"
68 #include "wmspec.h"
70 /******** Global Variables **********/
71 extern XContext wWinContext;
72 extern XContext wVEdgeContext;
74 extern Cursor wCursor[WCUR_LAST];
76 extern WShortKey wKeyBindings[WKBD_LAST];
77 extern int wScreenCount;
78 extern Time LastTimestamp;
79 extern Time LastFocusChange;
81 extern WPreferences wPreferences;
83 #define MOD_MASK wPreferences.modifier_mask
85 extern Atom _XA_WM_COLORMAP_NOTIFY;
87 extern Atom _XA_WM_CHANGE_STATE;
88 extern Atom _XA_WM_DELETE_WINDOW;
89 extern Atom _XA_GNUSTEP_WM_ATTR;
90 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
91 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
92 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
93 extern Atom _XA_WINDOWMAKER_COMMAND;
94 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
96 #ifdef SHAPE
97 extern Bool wShapeSupported;
98 extern int wShapeEventBase;
99 #endif
101 #ifdef KEEP_XKB_LOCK_STATUS
102 extern int wXkbEventBase;
103 #endif
105 #ifdef HAVE_XRANDR
106 extern Bool has_randr;
107 extern int randr_event_base;
108 #endif
110 /* special flags */
111 /*extern char WDelayedActionSet;*/
113 /************ Local stuff ***********/
115 static void saveTimestamp(XEvent *event);
116 static void handleColormapNotify(XEvent *event);
117 static void handleMapNotify(XEvent *event);
118 static void handleUnmapNotify(XEvent *event);
119 static void handleButtonPress(XEvent *event);
120 static void handleExpose(XEvent *event);
121 static void handleDestroyNotify(XEvent *event);
122 static void handleConfigureRequest(XEvent *event);
123 static void handleMapRequest(XEvent *event);
124 static void handlePropertyNotify(XEvent *event);
125 static void handleEnterNotify(XEvent *event);
126 static void handleLeaveNotify(XEvent *event);
127 static void handleExtensions(XEvent *event);
128 static void handleClientMessage(XEvent *event);
129 static void handleKeyPress(XEvent *event);
130 static void handleFocusIn(XEvent *event);
131 static void handleMotionNotify(XEvent *event);
132 static void handleVisibilityNotify(XEvent *event);
134 #ifdef SHAPE
135 static void handleShapeNotify(XEvent *event);
136 #endif
138 #ifdef KEEP_XKB_LOCK_STATUS
139 static void handleXkbIndicatorStateNotify(XEvent *event);
140 #endif
142 /* called from the signal handler */
143 void NotifyDeadProcess(pid_t pid, unsigned char status);
145 /* real dead process handler */
146 static void handleDeadProcess(void *foo);
148 typedef struct DeadProcesses {
149 pid_t pid;
150 unsigned char exit_status;
151 } DeadProcesses;
153 /* stack of dead processes */
154 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
155 static int deadProcessPtr = 0;
157 typedef struct DeathHandler {
158 WDeathHandler *callback;
159 pid_t pid;
160 void *client_data;
161 } DeathHandler;
163 static WMArray *deathHandlers = NULL;
165 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
167 DeathHandler *handler;
169 handler = malloc(sizeof(DeathHandler));
170 if (!handler)
171 return 0;
173 handler->pid = pid;
174 handler->callback = callback;
175 handler->client_data = cdata;
177 if (!deathHandlers)
178 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
180 WMAddToArray(deathHandlers, handler);
182 return handler;
185 void wDeleteDeathHandler(WMagicNumber id)
187 DeathHandler *handler = (DeathHandler *) id;
189 if (!handler || !deathHandlers)
190 return;
192 /* array destructor will call wfree(handler) */
193 WMRemoveFromArray(deathHandlers, handler);
196 void DispatchEvent(XEvent * event)
198 if (deathHandlers)
199 handleDeadProcess(NULL);
201 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
202 WCHANGE_STATE(WSTATE_EXITING);
203 /* received SIGTERM */
205 * WMHandleEvent() can't be called from anything
206 * executed inside here, or we can get in a infinite
207 * recursive loop.
209 Shutdown(WSExitMode);
211 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
212 WCHANGE_STATE(WSTATE_RESTARTING);
214 Shutdown(WSRestartPreparationMode);
215 /* received SIGHUP */
216 Restart(NULL, True);
217 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
218 WCHANGE_STATE(WSTATE_NORMAL);
219 wDefaultsCheckDomains(NULL);
222 /* for the case that all that is wanted to be dispatched is
223 * the stuff above */
224 if (!event)
225 return;
227 saveTimestamp(event);
228 switch (event->type) {
229 case MapRequest:
230 handleMapRequest(event);
231 break;
233 case KeyPress:
234 handleKeyPress(event);
235 break;
237 case MotionNotify:
238 handleMotionNotify(event);
239 break;
241 case ConfigureRequest:
242 handleConfigureRequest(event);
243 break;
245 case DestroyNotify:
246 handleDestroyNotify(event);
247 break;
249 case MapNotify:
250 handleMapNotify(event);
251 break;
253 case UnmapNotify:
254 handleUnmapNotify(event);
255 break;
257 case ButtonPress:
258 handleButtonPress(event);
259 break;
261 case Expose:
262 handleExpose(event);
263 break;
265 case PropertyNotify:
266 handlePropertyNotify(event);
267 break;
269 case EnterNotify:
270 handleEnterNotify(event);
271 break;
273 case LeaveNotify:
274 handleLeaveNotify(event);
275 break;
277 case ClientMessage:
278 handleClientMessage(event);
279 break;
281 case ColormapNotify:
282 handleColormapNotify(event);
283 break;
285 case MappingNotify:
286 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
287 XRefreshKeyboardMapping(&event->xmapping);
288 break;
290 case FocusIn:
291 handleFocusIn(event);
292 break;
294 case VisibilityNotify:
295 handleVisibilityNotify(event);
296 break;
298 case ConfigureNotify:
299 if (event->xconfigure.window == DefaultRootWindow(dpy)) {
300 #ifdef HAVE_XRANDR
301 XRRUpdateConfiguration(event);
302 #endif
304 break;
306 default:
307 handleExtensions(event);
308 break;
312 #ifdef HAVE_INOTIFY
314 *----------------------------------------------------------------------
315 * inotifyHandleEvents-
316 * Check for inotify events
318 * Returns:
319 * After reading events for the given file descriptor (fd) and
320 * watch descriptor (wd)
322 * Side effects:
323 * Calls wDefaultsCheckDomains if config database is updated
324 *----------------------------------------------------------------------
326 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
327 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
328 void inotifyHandleEvents(int fd, int wd)
330 extern void wDefaultsCheckDomains(void *);
331 ssize_t eventQLength, i = 0;
332 char buff[BUFF_SIZE] = { 0 };
333 /* Check config only once per read of the event queue */
334 int oneShotFlag = 0;
337 * Read off the queued events
338 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
339 * not occur; the block is on Xevents, but a config file change will normally
340 * occur as a result of an Xevent - so the event queue should never have more than
341 * a few entries before a read().
343 eventQLength = read(fd, buff, BUFF_SIZE);
345 /* check what events occured */
346 /* Should really check wd here too, but for now we only have one watch! */
347 while (i < eventQLength) {
348 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
351 * see inotify.h for event types.
353 if (pevent->mask & IN_DELETE_SELF) {
354 wwarning(_("the defaults database has been deleted!"
355 " Restart Window Maker to create the database" " with the default settings"));
356 close(fd);
358 if (pevent->mask & IN_UNMOUNT) {
359 wwarning(_("the unit containing the defaults database has"
360 " been unmounted. Setting --static mode." " Any changes will not be saved."));
361 close(fd);
362 wPreferences.flags.noupdates = 1;
364 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
365 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
366 wDefaultsCheckDomains(NULL);
369 /* move to next event in the buffer */
370 i += sizeof(struct inotify_event) + pevent->len;
373 #endif /* HAVE_INOTIFY */
376 *----------------------------------------------------------------------
377 * EventLoop-
378 * Processes X and internal events indefinitely.
380 * Returns:
381 * Never returns
383 * Side effects:
384 * The LastTimestamp global variable is updated.
385 * Calls inotifyGetEvents if defaults database changes.
386 *----------------------------------------------------------------------
388 void EventLoop(void)
390 XEvent event;
391 #ifdef HAVE_INOTIFY
392 extern int inotifyFD;
393 extern int inotifyWD;
394 struct timeval time;
395 fd_set rfds;
396 int retVal = 0;
398 if (inotifyFD < 0 || inotifyWD < 0)
399 retVal = -1;
400 #endif
402 for (;;) {
404 WMNextEvent(dpy, &event); /* Blocks here */
405 WMHandleEvent(&event);
406 #ifdef HAVE_INOTIFY
407 if (retVal != -1) {
408 time.tv_sec = 0;
409 time.tv_usec = 0;
410 FD_ZERO(&rfds);
411 FD_SET(inotifyFD, &rfds);
413 /* check for available read data from inotify - don't block! */
414 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
416 if (retVal < 0) { /* an error has occured */
417 wwarning(_("select failed. The inotify instance will be closed."
418 " Changes to the defaults database will require"
419 " a restart to take effect."));
420 close(inotifyFD);
421 continue;
423 if (FD_ISSET(inotifyFD, &rfds))
424 inotifyHandleEvents(inotifyFD, inotifyWD);
426 #endif
431 *----------------------------------------------------------------------
432 * ProcessPendingEvents --
433 * Processes the events that are currently pending (at the time
434 * this function is called) in the display's queue.
436 * Returns:
437 * After the pending events that were present at the function call
438 * are processed.
440 * Side effects:
441 * Many -- whatever handling events may involve.
443 *----------------------------------------------------------------------
445 void ProcessPendingEvents(void)
447 XEvent event;
448 int count;
450 XSync(dpy, False);
452 /* Take a snapshot of the event count in the queue */
453 count = XPending(dpy);
455 while (count > 0 && XPending(dpy)) {
456 WMNextEvent(dpy, &event);
457 WMHandleEvent(&event);
458 count--;
462 Bool IsDoubleClick(WScreen * scr, XEvent * event)
464 if ((scr->last_click_time > 0) &&
465 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
466 && (event->xbutton.button == scr->last_click_button)
467 && (event->xbutton.window == scr->last_click_window)) {
469 scr->flags.next_click_is_not_double = 1;
470 scr->last_click_time = 0;
471 scr->last_click_window = event->xbutton.window;
473 return True;
475 return False;
478 void NotifyDeadProcess(pid_t pid, unsigned char status)
480 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
481 wwarning("stack overflow: too many dead processes");
482 return;
484 /* stack the process to be handled later,
485 * as this is called from the signal handler */
486 deadProcesses[deadProcessPtr].pid = pid;
487 deadProcesses[deadProcessPtr].exit_status = status;
488 deadProcessPtr++;
491 static void handleDeadProcess(void *foo)
493 DeathHandler *tmp;
494 int i;
496 for (i = 0; i < deadProcessPtr; i++) {
497 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
500 if (!deathHandlers) {
501 deadProcessPtr = 0;
502 return;
505 /* get the pids on the queue and call handlers */
506 while (deadProcessPtr > 0) {
507 deadProcessPtr--;
509 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
510 tmp = WMGetFromArray(deathHandlers, i);
511 if (!tmp)
512 continue;
514 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
515 (*tmp->callback) (tmp->pid,
516 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
517 wDeleteDeathHandler(tmp);
523 static void saveTimestamp(XEvent * event)
526 * Never save CurrentTime as LastTimestamp because CurrentTime
527 * it's not a real timestamp (it's the 0L constant)
530 switch (event->type) {
531 case ButtonRelease:
532 case ButtonPress:
533 LastTimestamp = event->xbutton.time;
534 break;
535 case KeyPress:
536 case KeyRelease:
537 LastTimestamp = event->xkey.time;
538 break;
539 case MotionNotify:
540 LastTimestamp = event->xmotion.time;
541 break;
542 case PropertyNotify:
543 LastTimestamp = event->xproperty.time;
544 break;
545 case EnterNotify:
546 case LeaveNotify:
547 LastTimestamp = event->xcrossing.time;
548 break;
549 case SelectionClear:
550 LastTimestamp = event->xselectionclear.time;
551 break;
552 case SelectionRequest:
553 LastTimestamp = event->xselectionrequest.time;
554 break;
555 case SelectionNotify:
556 LastTimestamp = event->xselection.time;
557 #ifdef XDND
558 wXDNDProcessSelection(event);
559 #endif
560 break;
564 static int matchWindow(const void *item, const void *cdata)
566 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
569 static void handleExtensions(XEvent * event)
571 #ifdef KEEP_XKB_LOCK_STATUS
572 XkbEvent *xkbevent;
573 xkbevent = (XkbEvent *) event;
574 #endif /*KEEP_XKB_LOCK_STATUS */
575 #ifdef SHAPE
576 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
577 handleShapeNotify(event);
579 #endif
580 #ifdef KEEP_XKB_LOCK_STATUS
581 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
582 handleXkbIndicatorStateNotify(event);
584 #endif /*KEEP_XKB_LOCK_STATUS */
585 #ifdef HAVE_XRANDR
586 if (has_randr && event->type == (randr_event_base + RRScreenChangeNotify)) {
587 /* From xrandr man page: "Clients must call back into Xlib using
588 * XRRUpdateConfiguration when screen configuration change notify
589 * events are generated */
590 XRRUpdateConfiguration(event);
591 WCHANGE_STATE(WSTATE_RESTARTING);
592 Shutdown(WSRestartPreparationMode);
593 Restart(NULL,True);
595 #endif
598 static void handleMapRequest(XEvent * ev)
600 WWindow *wwin;
601 WScreen *scr = NULL;
602 Window window = ev->xmaprequest.window;
604 if ((wwin = wWindowFor(window))) {
605 if (wwin->flags.shaded) {
606 wUnshadeWindow(wwin);
608 /* deiconify window */
609 if (wwin->flags.miniaturized) {
610 wDeiconifyWindow(wwin);
611 } else if (wwin->flags.hidden) {
612 WApplication *wapp = wApplicationOf(wwin->main_window);
613 /* go to the last workspace that the user worked on the app */
614 if (wapp) {
615 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
617 wUnhideApplication(wapp, False, False);
619 return;
622 scr = wScreenForRootWindow(ev->xmaprequest.parent);
624 wwin = wManageWindow(scr, window);
627 * This is to let the Dock know that the application it launched
628 * has already been mapped (eg: it has finished launching).
629 * It is not necessary for normally docked apps, but is needed for
630 * apps that were forcedly docked (like with dockit).
632 if (scr->last_dock) {
633 if (wwin && wwin->main_window != None && wwin->main_window != window)
634 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
635 else
636 wDockTrackWindowLaunch(scr->last_dock, window);
639 if (wwin) {
640 wClientSetState(wwin, NormalState, None);
641 if (wwin->flags.maximized) {
642 wMaximizeWindow(wwin, wwin->flags.maximized);
644 if (wwin->flags.shaded) {
645 wwin->flags.shaded = 0;
646 wwin->flags.skip_next_animation = 1;
647 wShadeWindow(wwin);
649 if (wwin->flags.miniaturized) {
650 wwin->flags.miniaturized = 0;
651 wwin->flags.skip_next_animation = 1;
652 wIconifyWindow(wwin);
654 if (wwin->flags.fullscreen) {
655 wwin->flags.fullscreen = 0;
656 wFullscreenWindow(wwin);
658 if (wwin->flags.hidden) {
659 WApplication *wapp = wApplicationOf(wwin->main_window);
661 wwin->flags.hidden = 0;
662 wwin->flags.skip_next_animation = 1;
663 if (wapp) {
664 wHideApplication(wapp);
670 static void handleDestroyNotify(XEvent * event)
672 WWindow *wwin;
673 WApplication *app;
674 Window window = event->xdestroywindow.window;
675 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
676 int widx;
678 wwin = wWindowFor(window);
679 if (wwin) {
680 wUnmanageWindow(wwin, False, True);
683 if (scr != NULL) {
684 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
685 WFakeGroupLeader *fPtr;
687 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
688 if (fPtr->retainCount > 0) {
689 fPtr->retainCount--;
690 if (fPtr->retainCount == 0 && fPtr->leader != None) {
691 XDestroyWindow(dpy, fPtr->leader);
692 fPtr->leader = None;
693 XFlush(dpy);
696 fPtr->origLeader = None;
700 app = wApplicationOf(window);
701 if (app) {
702 if (window == app->main_window) {
703 app->refcount = 0;
704 wwin = app->main_window_desc->screen_ptr->focused_window;
705 while (wwin) {
706 if (wwin->main_window == window) {
707 wwin->main_window = None;
709 wwin = wwin->prev;
712 wApplicationDestroy(app);
716 static void handleExpose(XEvent * event)
718 WObjDescriptor *desc;
719 XEvent ev;
721 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
723 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
724 return;
727 if (desc->handle_expose) {
728 (*desc->handle_expose) (desc, event);
732 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
734 switch (action) {
735 case WA_SELECT_WINDOWS:
736 wUnselectWindows(scr);
737 wSelectWindows(scr, event);
738 break;
739 case WA_OPEN_APPMENU:
740 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
741 /* ugly hack */
742 if (scr->root_menu) {
743 if (scr->root_menu->brother->flags.mapped)
744 event->xbutton.window = scr->root_menu->brother->frame->core->window;
745 else
746 event->xbutton.window = scr->root_menu->frame->core->window;
748 break;
749 case WA_OPEN_WINLISTMENU:
750 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
751 if (scr->switch_menu) {
752 if (scr->switch_menu->brother->flags.mapped)
753 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
754 else
755 event->xbutton.window = scr->switch_menu->frame->core->window;
757 break;
758 default:
759 break;
763 /* bindable */
764 static void handleButtonPress(XEvent * event)
766 WObjDescriptor *desc;
767 WScreen *scr;
769 scr = wScreenForRootWindow(event->xbutton.root);
771 #ifdef BALLOON_TEXT
772 wBalloonHide(scr);
773 #endif
775 if (event->xbutton.window == scr->root_win) {
776 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
777 executeButtonAction(scr, event, wPreferences.mouse_button1);
778 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
779 executeButtonAction(scr, event, wPreferences.mouse_button2);
780 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
781 executeButtonAction(scr, event, wPreferences.mouse_button3);
782 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
783 wWorkspaceRelativeChange(scr, 1);
784 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
785 wWorkspaceRelativeChange(scr, -1);
789 desc = NULL;
790 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
791 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
792 return;
796 if (desc->parent_type == WCLASS_WINDOW) {
797 XSync(dpy, 0);
799 if (event->xbutton.state & ( MOD_MASK | ControlMask )) {
800 XAllowEvents(dpy, AsyncPointer, CurrentTime);
801 } else {
802 /* if (wPreferences.focus_mode == WKF_CLICK) { */
803 if (wPreferences.ignore_focus_click) {
804 XAllowEvents(dpy, AsyncPointer, CurrentTime);
806 XAllowEvents(dpy, ReplayPointer, CurrentTime);
807 /* } */
809 XSync(dpy, 0);
810 } else if (desc->parent_type == WCLASS_APPICON
811 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
812 if (event->xbutton.state & MOD_MASK) {
813 XSync(dpy, 0);
814 XAllowEvents(dpy, AsyncPointer, CurrentTime);
815 XSync(dpy, 0);
819 if (desc->handle_mousedown != NULL) {
820 (*desc->handle_mousedown) (desc, event);
823 /* save double-click information */
824 if (scr->flags.next_click_is_not_double) {
825 scr->flags.next_click_is_not_double = 0;
826 } else {
827 scr->last_click_time = event->xbutton.time;
828 scr->last_click_button = event->xbutton.button;
829 scr->last_click_window = event->xbutton.window;
833 static void handleMapNotify(XEvent * event)
835 WWindow *wwin;
837 wwin = wWindowFor(event->xmap.event);
838 if (wwin && wwin->client_win == event->xmap.event) {
839 if (wwin->flags.miniaturized) {
840 wDeiconifyWindow(wwin);
841 } else {
842 XGrabServer(dpy);
843 wWindowMap(wwin);
844 wClientSetState(wwin, NormalState, None);
845 XUngrabServer(dpy);
850 static void handleUnmapNotify(XEvent * event)
852 WWindow *wwin;
853 XEvent ev;
854 Bool withdraw = False;
856 /* only process windows with StructureNotify selected
857 * (ignore SubstructureNotify) */
858 wwin = wWindowFor(event->xunmap.window);
859 if (!wwin)
860 return;
862 /* whether the event is a Withdrawal request */
863 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
864 withdraw = True;
866 if (wwin->client_win != event->xunmap.event && !withdraw)
867 return;
869 if (!wwin->flags.mapped && !withdraw
870 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
871 && !wwin->flags.miniaturized && !wwin->flags.hidden)
872 return;
874 XGrabServer(dpy);
875 XUnmapWindow(dpy, wwin->frame->core->window);
876 wwin->flags.mapped = 0;
877 XSync(dpy, 0);
878 /* check if the window was destroyed */
879 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
880 DispatchEvent(&ev);
881 } else {
882 Bool reparented = False;
884 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
885 reparented = True;
887 /* withdraw window */
888 wwin->flags.mapped = 0;
889 if (!reparented)
890 wClientSetState(wwin, WithdrawnState, None);
892 /* if the window was reparented, do not reparent it back to the
893 * root window */
894 wUnmanageWindow(wwin, !reparented, False);
896 XUngrabServer(dpy);
899 static void handleConfigureRequest(XEvent * event)
901 WWindow *wwin;
903 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
905 * Configure request for unmapped window
907 wClientConfigure(NULL, &(event->xconfigurerequest));
908 } else {
909 wClientConfigure(wwin, &(event->xconfigurerequest));
913 static void handlePropertyNotify(XEvent * event)
915 WWindow *wwin;
916 WApplication *wapp;
917 Window jr;
918 int ji;
919 unsigned int ju;
921 wwin = wWindowFor(event->xproperty.window);
922 if (wwin) {
923 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
924 return;
926 wClientCheckProperty(wwin, &event->xproperty);
928 wapp = wApplicationOf(event->xproperty.window);
929 if (wapp) {
930 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
934 static void handleClientMessage(XEvent * event)
936 WWindow *wwin;
937 WObjDescriptor *desc;
939 /* handle transition from Normal to Iconic state */
940 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
941 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
943 wwin = wWindowFor(event->xclient.window);
944 if (!wwin)
945 return;
946 if (!wwin->flags.miniaturized)
947 wIconifyWindow(wwin);
948 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
949 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
951 if (!scr)
952 return;
954 if (event->xclient.data.l[1] == 1) { /* starting */
955 wColormapAllowClientInstallation(scr, True);
956 } else { /* stopping */
957 wColormapAllowClientInstallation(scr, False);
959 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
961 char *command;
962 size_t len;
964 len = sizeof(event->xclient.data.b) + 1;
965 command = wmalloc(len);
966 memset(command, 0, len);
967 strncpy(command, event->xclient.data.b, sizeof(event->xclient.data.b));
969 if (strncmp(command, "Reconfigure", sizeof("Reconfigure")) == 0) {
970 wwarning(_("Got Reconfigure command"));
971 wDefaultsCheckDomains(NULL);
972 } else {
973 wwarning(_("Got unknown command %s"), command);
976 wfree(command);
978 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
979 WApplication *wapp;
980 int done = 0;
981 wapp = wApplicationOf(event->xclient.window);
982 if (wapp) {
983 switch (event->xclient.data.l[0]) {
984 case WMFHideOtherApplications:
985 wHideOtherApplications(wapp->main_window_desc);
986 done = 1;
987 break;
989 case WMFHideApplication:
990 wHideApplication(wapp);
991 done = 1;
992 break;
995 if (!done) {
996 wwin = wWindowFor(event->xclient.window);
997 if (wwin) {
998 switch (event->xclient.data.l[0]) {
999 case WMFHideOtherApplications:
1000 wHideOtherApplications(wwin);
1001 break;
1003 case WMFHideApplication:
1004 wHideApplication(wApplicationOf(wwin->main_window));
1005 break;
1009 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
1010 wwin = wWindowFor(event->xclient.window);
1011 if (!wwin)
1012 return;
1013 switch (event->xclient.data.l[0]) {
1014 case GSWindowLevelAttr:
1016 int level = (int)event->xclient.data.l[1];
1018 if (WINDOW_LEVEL(wwin) != level) {
1019 ChangeStackingLevel(wwin->frame->core, level);
1022 break;
1024 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
1025 wwin = wWindowFor(event->xclient.window);
1026 if (!wwin)
1027 return;
1028 switch (event->xclient.data.l[0]) {
1029 case WMTitleBarNormal:
1030 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1031 break;
1032 case WMTitleBarMain:
1033 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1034 break;
1035 case WMTitleBarKey:
1036 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1037 break;
1039 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1040 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1041 if (!scr)
1042 return;
1043 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1044 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1045 /* do nothing */
1046 #ifdef XDND
1047 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1048 /* do nothing */
1049 #endif /* XDND */
1050 } else {
1052 * Non-standard thing, but needed by OffiX DND.
1053 * For when the icon frame gets a ClientMessage
1054 * that should have gone to the icon_window.
1056 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1057 struct WIcon *icon = NULL;
1059 if (desc->parent_type == WCLASS_MINIWINDOW) {
1060 icon = (WIcon *) desc->parent;
1061 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1062 icon = ((WAppIcon *) desc->parent)->icon;
1064 if (icon && (wwin = icon->owner)) {
1065 if (wwin->client_win != event->xclient.window) {
1066 event->xclient.window = wwin->client_win;
1067 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1074 static void raiseWindow(WScreen * scr)
1076 WWindow *wwin;
1078 scr->autoRaiseTimer = NULL;
1080 wwin = wWindowFor(scr->autoRaiseWindow);
1081 if (!wwin)
1082 return;
1084 if (!wwin->flags.destroyed && wwin->flags.focused) {
1085 wRaiseFrame(wwin->frame->core);
1086 /* this is needed or a race condition will occur */
1087 XSync(dpy, False);
1091 static void handleEnterNotify(XEvent * event)
1093 WWindow *wwin;
1094 WObjDescriptor *desc = NULL;
1095 XEvent ev;
1096 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1098 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1099 /* already left the window... */
1100 saveTimestamp(&ev);
1101 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1102 return;
1106 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1107 if (desc->handle_enternotify)
1108 (*desc->handle_enternotify) (desc, event);
1111 /* enter to window */
1112 wwin = wWindowFor(event->xcrossing.window);
1113 if (!wwin) {
1114 if (wPreferences.colormap_mode == WCM_POINTER) {
1115 wColormapInstallForWindow(scr, NULL);
1117 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1118 WMDeleteTimerHandler(scr->autoRaiseTimer);
1119 scr->autoRaiseTimer = NULL;
1121 } else {
1122 /* set auto raise timer even if in focus-follows-mouse mode
1123 * and the event is for the frame window, even if the window
1124 * has focus already. useful if you move the pointer from a focused
1125 * window to the root window and back pretty fast
1127 * set focus if in focus-follows-mouse mode and the event
1128 * is for the frame window and window doesn't have focus yet */
1129 if (wPreferences.focus_mode == WKF_SLOPPY
1130 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1132 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1133 wSetFocusTo(scr, wwin);
1135 if (scr->autoRaiseTimer)
1136 WMDeleteTimerHandler(scr->autoRaiseTimer);
1137 scr->autoRaiseTimer = NULL;
1139 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1140 scr->autoRaiseWindow = wwin->frame->core->window;
1141 scr->autoRaiseTimer
1142 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1145 /* Install colormap for window, if the colormap installation mode
1146 * is colormap_follows_mouse */
1147 if (wPreferences.colormap_mode == WCM_POINTER) {
1148 if (wwin->client_win == event->xcrossing.window)
1149 wColormapInstallForWindow(scr, wwin);
1150 else
1151 wColormapInstallForWindow(scr, NULL);
1155 /* a little kluge to hide the clip balloon */
1156 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1157 if (!desc) {
1158 XUnmapWindow(dpy, scr->clip_balloon);
1159 scr->flags.clip_balloon_mapped = 0;
1160 } else {
1161 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1162 XUnmapWindow(dpy, scr->clip_balloon);
1163 scr->flags.clip_balloon_mapped = 0;
1168 if (event->xcrossing.window == event->xcrossing.root
1169 && event->xcrossing.detail == NotifyNormal
1170 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1172 wSetFocusTo(scr, scr->focused_window);
1174 #ifdef BALLOON_TEXT
1175 wBalloonEnteredObject(scr, desc);
1176 #endif
1179 static void handleLeaveNotify(XEvent * event)
1181 WObjDescriptor *desc = NULL;
1183 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1184 if (desc->handle_leavenotify)
1185 (*desc->handle_leavenotify) (desc, event);
1189 #ifdef SHAPE
1190 static void handleShapeNotify(XEvent * event)
1192 XShapeEvent *shev = (XShapeEvent *) event;
1193 WWindow *wwin;
1194 union {
1195 XEvent xevent;
1196 XShapeEvent xshape;
1197 } ev;
1199 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev.xevent)) {
1200 if (ev.xshape.kind == ShapeBounding) {
1201 if (ev.xshape.shaped == shev->shaped) {
1202 *shev = ev.xshape;
1203 } else {
1204 XPutBackEvent(dpy, &ev.xevent);
1205 break;
1210 wwin = wWindowFor(shev->window);
1211 if (!wwin || shev->kind != ShapeBounding)
1212 return;
1214 if (!shev->shaped && wwin->flags.shaped) {
1216 wwin->flags.shaped = 0;
1217 wWindowClearShape(wwin);
1219 } else if (shev->shaped) {
1221 wwin->flags.shaped = 1;
1222 wWindowSetShape(wwin);
1225 #endif /* SHAPE */
1227 #ifdef KEEP_XKB_LOCK_STATUS
1228 /* please help ]d if you know what to do */
1229 static void handleXkbIndicatorStateNotify(XEvent *event)
1231 WWindow *wwin;
1232 WScreen *scr;
1233 XkbStateRec staterec;
1234 int i;
1236 for (i = 0; i < wScreenCount; i++) {
1237 scr = wScreenWithNumber(i);
1238 wwin = scr->focused_window;
1239 if (wwin && wwin->flags.focused) {
1240 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1241 if (wwin->frame->languagemode != staterec.group) {
1242 wwin->frame->last_languagemode = wwin->frame->languagemode;
1243 wwin->frame->languagemode = staterec.group;
1245 #ifdef XKB_BUTTON_HINT
1246 if (wwin->frame->titlebar) {
1247 wFrameWindowPaint(wwin->frame);
1249 #endif
1253 #endif /*KEEP_XKB_LOCK_STATUS */
1255 static void handleColormapNotify(XEvent * event)
1257 WWindow *wwin;
1258 WScreen *scr;
1259 Bool reinstall = False;
1261 wwin = wWindowFor(event->xcolormap.window);
1262 if (!wwin)
1263 return;
1265 scr = wwin->screen_ptr;
1267 do {
1268 if (wwin) {
1269 if (event->xcolormap.new) {
1270 XWindowAttributes attr;
1272 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1274 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1275 scr->current_colormap = attr.colormap;
1277 reinstall = True;
1278 } else if (event->xcolormap.state == ColormapUninstalled &&
1279 scr->current_colormap == event->xcolormap.colormap) {
1281 /* some bastard app (like XV) removed our colormap */
1283 * can't enforce or things like xscreensaver wont work
1284 * reinstall = True;
1286 } else if (event->xcolormap.state == ColormapInstalled &&
1287 scr->current_colormap == event->xcolormap.colormap) {
1289 /* someone has put our colormap back */
1290 reinstall = False;
1293 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1294 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1296 if (reinstall && scr->current_colormap != None) {
1297 if (!scr->flags.colormap_stuff_blocked)
1298 XInstallColormap(dpy, scr->current_colormap);
1302 static void handleFocusIn(XEvent * event)
1304 WWindow *wwin;
1307 * For applications that like stealing the focus.
1309 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1310 saveTimestamp(event);
1311 if (event->xfocus.mode == NotifyUngrab
1312 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1313 return;
1316 wwin = wWindowFor(event->xfocus.window);
1317 if (wwin && !wwin->flags.focused) {
1318 if (wwin->flags.mapped)
1319 wSetFocusTo(wwin->screen_ptr, wwin);
1320 else
1321 wSetFocusTo(wwin->screen_ptr, NULL);
1322 } else if (!wwin) {
1323 WScreen *scr = wScreenForWindow(event->xfocus.window);
1324 if (scr)
1325 wSetFocusTo(scr, NULL);
1329 static WWindow *windowUnderPointer(WScreen * scr)
1331 unsigned int mask;
1332 int foo;
1333 Window bar, win;
1335 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1336 return wWindowFor(win);
1337 return NULL;
1340 static int CheckFullScreenWindowFocused(WScreen * scr)
1342 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1343 return 1;
1344 else
1345 return 0;
1348 static void handleKeyPress(XEvent * event)
1350 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1351 WWindow *wwin = scr->focused_window;
1352 short i, widx;
1353 int modifiers;
1354 int command = -1;
1355 #ifdef KEEP_XKB_LOCK_STATUS
1356 XkbStateRec staterec;
1357 #endif /*KEEP_XKB_LOCK_STATUS */
1359 /* ignore CapsLock */
1360 modifiers = event->xkey.state & ValidModMask;
1362 for (i = 0; i < WKBD_LAST; i++) {
1363 if (wKeyBindings[i].keycode == 0)
1364 continue;
1366 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1367 || */ wKeyBindings[i].modifier ==
1368 modifiers)) {
1369 command = i;
1370 break;
1374 if (command < 0) {
1376 if (!wRootMenuPerformShortcut(event)) {
1377 static int dontLoop = 0;
1379 if (dontLoop > 10) {
1380 wwarning("problem with key event processing code");
1381 return;
1383 dontLoop++;
1384 /* if the focused window is an internal window, try redispatching
1385 * the event to the managed window, as it can be a WINGs window */
1386 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1387 /* client_leader contains the WINGs toplevel */
1388 event->xany.window = wwin->client_leader;
1389 WMHandleEvent(event);
1391 dontLoop--;
1393 return;
1395 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1396 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1398 switch (command) {
1400 case WKBD_ROOTMENU:
1401 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1402 if (!CheckFullScreenWindowFocused(scr)) {
1403 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1404 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1405 True);
1407 break;
1408 case WKBD_WINDOWLIST:
1409 if (!CheckFullScreenWindowFocused(scr)) {
1410 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1411 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1412 True);
1414 break;
1416 case WKBD_WINDOWMENU:
1417 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1418 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1419 break;
1420 case WKBD_MINIMIZEALL:
1421 CloseWindowMenu(scr);
1422 wHideAll(scr);
1423 break;
1424 case WKBD_MINIATURIZE:
1425 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1426 && !WFLAGP(wwin, no_miniaturizable)) {
1427 CloseWindowMenu(scr);
1429 if (wwin->protocols.MINIATURIZE_WINDOW)
1430 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1431 else {
1432 wIconifyWindow(wwin);
1435 break;
1436 case WKBD_HIDE:
1437 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1438 WApplication *wapp = wApplicationOf(wwin->main_window);
1439 CloseWindowMenu(scr);
1441 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1442 wHideApplication(wapp);
1445 break;
1446 case WKBD_HIDE_OTHERS:
1447 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1448 CloseWindowMenu(scr);
1450 wHideOtherApplications(wwin);
1452 break;
1453 case WKBD_MAXIMIZE:
1454 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1455 CloseWindowMenu(scr);
1457 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_HORIZONTAL))
1458 wUnmaximizeWindow(wwin);
1459 else
1460 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL | MAX_KEYBOARD);
1462 break;
1463 case WKBD_VMAXIMIZE:
1464 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1465 CloseWindowMenu(scr);
1467 if (wwin->flags.maximized == MAX_VERTICAL)
1468 wUnmaximizeWindow(wwin);
1469 else
1470 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_KEYBOARD);
1472 break;
1473 case WKBD_HMAXIMIZE:
1474 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1475 CloseWindowMenu(scr);
1477 if (wwin->flags.maximized == MAX_HORIZONTAL)
1478 wUnmaximizeWindow(wwin);
1479 else
1480 wMaximizeWindow(wwin, MAX_HORIZONTAL | MAX_KEYBOARD);
1482 break;
1483 case WKBD_LHMAXIMIZE:
1484 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1485 CloseWindowMenu(scr);
1487 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_LEFTHALF))
1488 wUnmaximizeWindow(wwin);
1489 else
1490 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_LEFTHALF | MAX_KEYBOARD);
1492 break;
1493 case WKBD_RHMAXIMIZE:
1494 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1495 CloseWindowMenu(scr);
1497 if (wwin->flags.maximized == (MAX_VERTICAL | MAX_RIGHTHALF))
1498 wUnmaximizeWindow(wwin);
1499 else
1500 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_RIGHTHALF | MAX_KEYBOARD);
1502 break;
1503 case WKBD_MAXIMUS:
1504 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1505 CloseWindowMenu(scr);
1507 if (wwin->flags.maximized == MAX_MAXIMUS)
1508 wUnmaximizeWindow(wwin);
1509 else
1510 wMaximizeWindow(wwin, MAX_MAXIMUS | MAX_KEYBOARD);
1512 break;
1513 case WKBD_RAISE:
1514 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1515 CloseWindowMenu(scr);
1517 wRaiseFrame(wwin->frame->core);
1519 break;
1520 case WKBD_LOWER:
1521 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1522 CloseWindowMenu(scr);
1524 wLowerFrame(wwin->frame->core);
1526 break;
1527 case WKBD_RAISELOWER:
1528 /* raise or lower the window under the pointer, not the
1529 * focused one
1531 wwin = windowUnderPointer(scr);
1532 if (wwin)
1533 wRaiseLowerFrame(wwin->frame->core);
1534 break;
1535 case WKBD_SHADE:
1536 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1537 if (wwin->flags.shaded)
1538 wUnshadeWindow(wwin);
1539 else
1540 wShadeWindow(wwin);
1542 break;
1543 case WKBD_MOVERESIZE:
1544 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1545 CloseWindowMenu(scr);
1547 wKeyboardMoveResizeWindow(wwin);
1549 break;
1550 case WKBD_CLOSE:
1551 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1552 CloseWindowMenu(scr);
1553 if (wwin->protocols.DELETE_WINDOW)
1554 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1556 break;
1557 case WKBD_SELECT:
1558 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1559 wSelectWindow(wwin, !wwin->flags.selected);
1561 break;
1562 case WKBD_FOCUSNEXT:
1563 StartWindozeCycle(wwin, event, True, False);
1564 break;
1566 case WKBD_FOCUSPREV:
1567 StartWindozeCycle(wwin, event, False, False);
1568 break;
1570 case WKBD_GROUPNEXT:
1571 StartWindozeCycle(wwin, event, True, True);
1572 break;
1574 case WKBD_GROUPPREV:
1575 StartWindozeCycle(wwin, event, False, True);
1576 break;
1578 case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
1579 widx = command - WKBD_WORKSPACE1;
1580 i = (scr->current_workspace / 10) * 10 + widx;
1581 if (wPreferences.ws_advance || i < scr->workspace_count)
1582 wWorkspaceChange(scr, i);
1583 break;
1585 case WKBD_NEXTWORKSPACE:
1586 wWorkspaceRelativeChange(scr, 1);
1587 break;
1588 case WKBD_PREVWORKSPACE:
1589 wWorkspaceRelativeChange(scr, -1);
1590 break;
1592 case WKBD_WINDOW1:
1593 case WKBD_WINDOW2:
1594 case WKBD_WINDOW3:
1595 case WKBD_WINDOW4:
1596 case WKBD_WINDOW5:
1597 case WKBD_WINDOW6:
1598 case WKBD_WINDOW7:
1599 case WKBD_WINDOW8:
1600 case WKBD_WINDOW9:
1601 case WKBD_WINDOW10:
1603 widx = command - WKBD_WINDOW1;
1605 if (scr->shortcutWindows[widx]) {
1606 WMArray *list = scr->shortcutWindows[widx];
1607 int cw;
1608 int count = WMGetArrayItemCount(list);
1609 WWindow *twin;
1610 WMArrayIterator iter;
1611 WWindow *wwin;
1613 wUnselectWindows(scr);
1614 cw = scr->current_workspace;
1616 WM_ETARETI_ARRAY(list, wwin, iter) {
1617 if (count > 1)
1618 wWindowChangeWorkspace(wwin, cw);
1620 wMakeWindowVisible(wwin);
1622 if (count > 1)
1623 wSelectWindow(wwin, True);
1626 /* rotate the order of windows, to create a cycling effect */
1627 twin = WMGetFromArray(list, 0);
1628 WMDeleteFromArray(list, 0);
1629 WMAddToArray(list, twin);
1631 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1632 if (scr->shortcutWindows[widx]) {
1633 WMFreeArray(scr->shortcutWindows[widx]);
1634 scr->shortcutWindows[widx] = NULL;
1637 if (wwin->flags.selected && scr->selected_windows) {
1638 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1639 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1640 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1641 } else {
1642 scr->shortcutWindows[widx] = WMCreateArray(4);
1643 WMAddToArray(scr->shortcutWindows[widx], wwin);
1646 wSelectWindow(wwin, !wwin->flags.selected);
1647 XFlush(dpy);
1648 wusleep(3000);
1649 wSelectWindow(wwin, !wwin->flags.selected);
1650 XFlush(dpy);
1652 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1654 if (wwin->flags.selected && scr->selected_windows) {
1655 if (scr->shortcutWindows[widx]) {
1656 WMFreeArray(scr->shortcutWindows[widx]);
1658 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1662 break;
1664 case WKBD_SWITCH_SCREEN:
1665 if (wScreenCount > 1) {
1666 WScreen *scr2;
1667 int i;
1669 /* find index of this screen */
1670 for (i = 0; i < wScreenCount; i++) {
1671 if (wScreenWithNumber(i) == scr)
1672 break;
1674 i++;
1675 if (i >= wScreenCount) {
1676 i = 0;
1678 scr2 = wScreenWithNumber(i);
1680 if (scr2) {
1681 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1682 scr2->scr_width / 2, scr2->scr_height / 2);
1685 break;
1687 case WKBD_NEXTWSLAYER:
1688 case WKBD_PREVWSLAYER:
1690 int row, column;
1692 row = scr->current_workspace / 10;
1693 column = scr->current_workspace % 10;
1695 if (command == WKBD_NEXTWSLAYER) {
1696 if ((row + 1) * 10 < scr->workspace_count)
1697 wWorkspaceChange(scr, column + (row + 1) * 10);
1698 } else {
1699 if (row > 0)
1700 wWorkspaceChange(scr, column + (row - 1) * 10);
1703 break;
1704 case WKBD_CLIPRAISELOWER:
1705 if (!wPreferences.flags.noclip)
1706 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1707 break;
1708 case WKBD_DOCKRAISELOWER:
1709 if (!wPreferences.flags.nodock)
1710 wDockRaiseLower(scr->dock);
1711 break;
1712 #ifdef KEEP_XKB_LOCK_STATUS
1713 case WKBD_TOGGLE:
1714 if (wPreferences.modelock) {
1715 /*toggle */
1716 wwin = scr->focused_window;
1718 if (wwin && wwin->flags.mapped
1719 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1720 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1721 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1723 wwin->frame->languagemode = wwin->frame->last_languagemode;
1724 wwin->frame->last_languagemode = staterec.group;
1725 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1729 break;
1730 #endif /* KEEP_XKB_LOCK_STATUS */
1734 static void handleMotionNotify(XEvent * event)
1736 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1738 if (wPreferences.scrollable_menus) {
1739 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1740 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1742 if (scr->flags.jump_back_pending ||
1743 p.x <= (rect.pos.x + 1) ||
1744 p.x >= (rect.pos.x + rect.size.width - 2) ||
1745 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1746 WMenu *menu;
1748 menu = wMenuUnderPointer(scr);
1749 if (menu != NULL)
1750 wMenuScroll(menu, event);
1755 static void handleVisibilityNotify(XEvent * event)
1757 WWindow *wwin;
1759 wwin = wWindowFor(event->xvisibility.window);
1760 if (!wwin)
1761 return;
1762 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);