Fix function prototype declaration
[wmaker-crm.git] / src / event.c
blobb6ed4f9c4a8f5f1a419f6d4bd5044dcb36762bf7
1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include <sys/inotify.h>
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33 #ifdef SHAPE
34 # include <X11/extensions/shape.h>
35 #endif
36 #ifdef XDND
37 #include "xdnd.h"
38 #endif
40 #ifdef KEEP_XKB_LOCK_STATUS
41 #include <X11/XKBlib.h>
42 #endif /* KEEP_XKB_LOCK_STATUS */
44 #include "WindowMaker.h"
45 #include "window.h"
46 #include "actions.h"
47 #include "client.h"
48 #include "funcs.h"
49 #include "keybind.h"
50 #include "application.h"
51 #include "stacking.h"
52 #include "defaults.h"
53 #include "workspace.h"
54 #include "dock.h"
55 #include "framewin.h"
56 #include "properties.h"
57 #include "balloon.h"
58 #include "xinerama.h"
60 #ifdef NETWM_HINTS
61 # include "wmspec.h"
62 #endif
64 /******** Global Variables **********/
65 extern XContext wWinContext;
66 extern XContext wVEdgeContext;
68 extern Cursor wCursor[WCUR_LAST];
70 extern WShortKey wKeyBindings[WKBD_LAST];
71 extern int wScreenCount;
72 extern Time LastTimestamp;
73 extern Time LastFocusChange;
75 extern WPreferences wPreferences;
77 #define MOD_MASK wPreferences.modifier_mask
79 extern Atom _XA_WM_COLORMAP_NOTIFY;
81 extern Atom _XA_WM_CHANGE_STATE;
82 extern Atom _XA_WM_DELETE_WINDOW;
83 extern Atom _XA_GNUSTEP_WM_ATTR;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
85 extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
86 extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
87 extern Atom _XA_WINDOWMAKER_COMMAND;
88 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
90 #ifdef SHAPE
91 extern Bool wShapeSupported;
92 extern int wShapeEventBase;
93 #endif
95 #ifdef KEEP_XKB_LOCK_STATUS
96 extern int wXkbEventBase;
97 #endif
99 /* special flags */
100 /*extern char WDelayedActionSet;*/
102 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent *event);
105 static void handleColormapNotify(XEvent *event);
106 static void handleMapNotify(XEvent *event);
107 static void handleUnmapNotify(XEvent *event);
108 static void handleButtonPress(XEvent *event);
109 static void handleExpose(XEvent *event);
110 static void handleDestroyNotify(XEvent *event);
111 static void handleConfigureRequest(XEvent *event);
112 static void handleMapRequest(XEvent *event);
113 static void handlePropertyNotify(XEvent *event);
114 static void handleEnterNotify(XEvent *event);
115 static void handleLeaveNotify(XEvent *event);
116 static void handleExtensions(XEvent *event);
117 static void handleClientMessage(XEvent *event);
118 static void handleKeyPress(XEvent *event);
119 static void handleFocusIn(XEvent *event);
120 static void handleMotionNotify(XEvent *event);
121 static void handleVisibilityNotify(XEvent *event);
123 #ifdef SHAPE
124 static void handleShapeNotify(XEvent *event);
125 #endif
127 /* called from the signal handler */
128 void NotifyDeadProcess(pid_t pid, unsigned char status);
130 /* real dead process handler */
131 static void handleDeadProcess(void *foo);
133 typedef struct DeadProcesses {
134 pid_t pid;
135 unsigned char exit_status;
136 } DeadProcesses;
138 /* stack of dead processes */
139 static DeadProcesses deadProcesses[MAX_DEAD_PROCESSES];
140 static int deadProcessPtr = 0;
142 typedef struct DeathHandler {
143 WDeathHandler *callback;
144 pid_t pid;
145 void *client_data;
146 } DeathHandler;
148 static WMArray *deathHandlers = NULL;
150 WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
152 DeathHandler *handler;
154 handler = malloc(sizeof(DeathHandler));
155 if (!handler)
156 return 0;
158 handler->pid = pid;
159 handler->callback = callback;
160 handler->client_data = cdata;
162 if (!deathHandlers)
163 deathHandlers = WMCreateArrayWithDestructor(8, wfree);
165 WMAddToArray(deathHandlers, handler);
167 return handler;
170 void wDeleteDeathHandler(WMagicNumber id)
172 DeathHandler *handler = (DeathHandler *) id;
174 if (!handler || !deathHandlers)
175 return;
177 /* array destructor will call wfree(handler) */
178 WMRemoveFromArray(deathHandlers, handler);
181 void DispatchEvent(XEvent * event)
183 if (deathHandlers)
184 handleDeadProcess(NULL);
186 if (WCHECK_STATE(WSTATE_NEED_EXIT)) {
187 WCHANGE_STATE(WSTATE_EXITING);
188 /* received SIGTERM */
190 * WMHandleEvent() can't be called from anything
191 * executed inside here, or we can get in a infinite
192 * recursive loop.
194 Shutdown(WSExitMode);
196 } else if (WCHECK_STATE(WSTATE_NEED_RESTART)) {
197 WCHANGE_STATE(WSTATE_RESTARTING);
199 Shutdown(WSRestartPreparationMode);
200 /* received SIGHUP */
201 Restart(NULL, True);
202 } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
203 WCHANGE_STATE(WSTATE_NORMAL);
204 wDefaultsCheckDomains();
207 /* for the case that all that is wanted to be dispatched is
208 * the stuff above */
209 if (!event)
210 return;
212 saveTimestamp(event);
213 switch (event->type) {
214 case MapRequest:
215 handleMapRequest(event);
216 break;
218 case KeyPress:
219 handleKeyPress(event);
220 break;
222 case MotionNotify:
223 handleMotionNotify(event);
224 break;
226 case ConfigureRequest:
227 handleConfigureRequest(event);
228 break;
230 case DestroyNotify:
231 handleDestroyNotify(event);
232 break;
234 case MapNotify:
235 handleMapNotify(event);
236 break;
238 case UnmapNotify:
239 handleUnmapNotify(event);
240 break;
242 case ButtonPress:
243 handleButtonPress(event);
244 break;
246 case Expose:
247 handleExpose(event);
248 break;
250 case PropertyNotify:
251 handlePropertyNotify(event);
252 break;
254 case EnterNotify:
255 handleEnterNotify(event);
256 break;
258 case LeaveNotify:
259 handleLeaveNotify(event);
260 break;
262 case ClientMessage:
263 handleClientMessage(event);
264 break;
266 case ColormapNotify:
267 handleColormapNotify(event);
268 break;
270 case MappingNotify:
271 if (event->xmapping.request == MappingKeyboard || event->xmapping.request == MappingModifier)
272 XRefreshKeyboardMapping(&event->xmapping);
273 break;
275 case FocusIn:
276 handleFocusIn(event);
277 break;
279 case VisibilityNotify:
280 handleVisibilityNotify(event);
281 break;
282 default:
283 handleExtensions(event);
284 break;
289 *----------------------------------------------------------------------
290 * inotifyHandleEvents-
291 * Check for inotify events
293 * Returns:
294 * After reading events for the given file descriptor (fd) and
295 * watch descriptor (wd)
297 * Side effects:
298 * Calls wDefaultsCheckDomains if config database is updated
299 *----------------------------------------------------------------------
302 #define BUFF_SIZE ((sizeof(struct inotify_event) + 16)*512)
303 void inotifyHandleEvents(int fd, int wd)
305 extern void wDefaultsCheckDomains(void);
306 ssize_t eventQLength, i = 0;
307 char buff[BUFF_SIZE] = { 0 };
308 /* Check config only once per read of the event queue */
309 int oneShotFlag = 0;
312 * Read off the queued events
313 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
314 * not occur; the block is on Xevents, but a config file change will normally
315 * occur as a result of an Xevent - so the event queue should never have more than
316 * a few entries before a read().
318 eventQLength = read(fd, buff, BUFF_SIZE);
320 /* check what events occured */
321 /* Should really check wd here too, but for now we only have one watch! */
322 while (i < eventQLength) {
323 struct inotify_event *pevent = (struct inotify_event *)&buff[i];
326 * see inotify.h for event types.
328 if (pevent->mask & IN_DELETE_SELF) {
329 wwarning(_("the defaults database has been deleted!"
330 " Restart Window Maker to create the database" " with the default settings"));
331 close(fd);
333 if (pevent->mask & IN_UNMOUNT) {
334 wwarning(_("the unit containing the defaults database has"
335 " been unmounted. Setting --static mode." " Any changes will not be saved."));
336 close(fd);
337 wPreferences.flags.noupdates = 1;
339 if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
340 fprintf(stdout, "wmaker: reading config files in defaults database.\n");
341 wDefaultsCheckDomains();
344 /* move to next event in the buffer */
345 i += sizeof(struct inotify_event) + pevent->len;
350 *----------------------------------------------------------------------
351 * EventLoop-
352 * Processes X and internal events indefinitely.
354 * Returns:
355 * Never returns
357 * Side effects:
358 * The LastTimestamp global variable is updated.
359 * Calls inotifyGetEvents if defaults database changes.
360 *----------------------------------------------------------------------
362 void EventLoop(void)
364 XEvent event;
365 extern int inotifyFD;
366 extern int inotifyWD;
367 struct timeval time;
368 fd_set rfds;
369 int retVal = 0;
371 if (inotifyFD < 0 || inotifyWD < 0)
372 retVal = -1;
374 for (;;) {
376 WMNextEvent(dpy, &event); /* Blocks here */
377 WMHandleEvent(&event);
379 if (retVal != -1) {
380 time.tv_sec = 0;
381 time.tv_usec = 0;
382 FD_ZERO(&rfds);
383 FD_SET(inotifyFD, &rfds);
385 /* check for available read data from inotify - don't block! */
386 retVal = select(inotifyFD + 1, &rfds, NULL, NULL, &time);
388 if (retVal < 0) { /* an error has occured */
389 wwarning(_("select failed. The inotify instance will be closed."
390 " Changes to the defaults database will require"
391 " a restart to take effect."));
392 close(inotifyFD);
393 continue;
395 if (FD_ISSET(inotifyFD, &rfds))
396 inotifyHandleEvents(inotifyFD, inotifyWD);
402 *----------------------------------------------------------------------
403 * ProcessPendingEvents --
404 * Processes the events that are currently pending (at the time
405 * this function is called) in the display's queue.
407 * Returns:
408 * After the pending events that were present at the function call
409 * are processed.
411 * Side effects:
412 * Many -- whatever handling events may involve.
414 *----------------------------------------------------------------------
416 void ProcessPendingEvents(void)
418 XEvent event;
419 int count;
421 XSync(dpy, False);
423 /* Take a snapshot of the event count in the queue */
424 count = XPending(dpy);
426 while (count > 0 && XPending(dpy)) {
427 WMNextEvent(dpy, &event);
428 WMHandleEvent(&event);
429 count--;
433 Bool IsDoubleClick(WScreen * scr, XEvent * event)
435 if ((scr->last_click_time > 0) &&
436 (event->xbutton.time - scr->last_click_time <= wPreferences.dblclick_time)
437 && (event->xbutton.button == scr->last_click_button)
438 && (event->xbutton.window == scr->last_click_window)) {
440 scr->flags.next_click_is_not_double = 1;
441 scr->last_click_time = 0;
442 scr->last_click_window = event->xbutton.window;
444 return True;
446 return False;
449 void NotifyDeadProcess(pid_t pid, unsigned char status)
451 if (deadProcessPtr >= MAX_DEAD_PROCESSES - 1) {
452 wwarning("stack overflow: too many dead processes");
453 return;
455 /* stack the process to be handled later,
456 * as this is called from the signal handler */
457 deadProcesses[deadProcessPtr].pid = pid;
458 deadProcesses[deadProcessPtr].exit_status = status;
459 deadProcessPtr++;
462 static void handleDeadProcess(void *foo)
464 DeathHandler *tmp;
465 int i;
467 for (i = 0; i < deadProcessPtr; i++) {
468 wWindowDeleteSavedStatesForPID(deadProcesses[i].pid);
471 if (!deathHandlers) {
472 deadProcessPtr = 0;
473 return;
476 /* get the pids on the queue and call handlers */
477 while (deadProcessPtr > 0) {
478 deadProcessPtr--;
480 for (i = WMGetArrayItemCount(deathHandlers) - 1; i >= 0; i--) {
481 tmp = WMGetFromArray(deathHandlers, i);
482 if (!tmp)
483 continue;
485 if (tmp->pid == deadProcesses[deadProcessPtr].pid) {
486 (*tmp->callback) (tmp->pid,
487 deadProcesses[deadProcessPtr].exit_status, tmp->client_data);
488 wDeleteDeathHandler(tmp);
494 static void saveTimestamp(XEvent * event)
497 * Never save CurrentTime as LastTimestamp because CurrentTime
498 * it's not a real timestamp (it's the 0L constant)
501 switch (event->type) {
502 case ButtonRelease:
503 case ButtonPress:
504 LastTimestamp = event->xbutton.time;
505 break;
506 case KeyPress:
507 case KeyRelease:
508 LastTimestamp = event->xkey.time;
509 break;
510 case MotionNotify:
511 LastTimestamp = event->xmotion.time;
512 break;
513 case PropertyNotify:
514 LastTimestamp = event->xproperty.time;
515 break;
516 case EnterNotify:
517 case LeaveNotify:
518 LastTimestamp = event->xcrossing.time;
519 break;
520 case SelectionClear:
521 LastTimestamp = event->xselectionclear.time;
522 break;
523 case SelectionRequest:
524 LastTimestamp = event->xselectionrequest.time;
525 break;
526 case SelectionNotify:
527 LastTimestamp = event->xselection.time;
528 #ifdef XDND
529 wXDNDProcessSelection(event);
530 #endif
531 break;
535 static int matchWindow(void *item, void *cdata)
537 return (((WFakeGroupLeader *) item)->origLeader == (Window) cdata);
540 static void handleExtensions(XEvent * event)
542 #ifdef KEEP_XKB_LOCK_STATUS
543 XkbEvent *xkbevent;
544 xkbevent = (XkbEvent *) event;
545 #endif /*KEEP_XKB_LOCK_STATUS */
546 #ifdef SHAPE
547 if (wShapeSupported && event->type == (wShapeEventBase + ShapeNotify)) {
548 handleShapeNotify(event);
550 #endif
551 #ifdef KEEP_XKB_LOCK_STATUS
552 if (wPreferences.modelock && (xkbevent->type == wXkbEventBase)) {
553 handleXkbIndicatorStateNotify(event);
555 #endif /*KEEP_XKB_LOCK_STATUS */
558 static void handleMapRequest(XEvent * ev)
560 WWindow *wwin;
561 WScreen *scr = NULL;
562 Window window = ev->xmaprequest.window;
564 #ifdef DEBUG
565 printf("got map request for %x\n", (unsigned)window);
566 #endif
567 if ((wwin = wWindowFor(window))) {
568 if (wwin->flags.shaded) {
569 wUnshadeWindow(wwin);
571 /* deiconify window */
572 if (wwin->flags.miniaturized) {
573 wDeiconifyWindow(wwin);
574 } else if (wwin->flags.hidden) {
575 WApplication *wapp = wApplicationOf(wwin->main_window);
576 /* go to the last workspace that the user worked on the app */
577 if (wapp) {
578 wWorkspaceChange(wwin->screen_ptr, wapp->last_workspace);
580 wUnhideApplication(wapp, False, False);
582 return;
585 scr = wScreenForRootWindow(ev->xmaprequest.parent);
587 wwin = wManageWindow(scr, window);
590 * This is to let the Dock know that the application it launched
591 * has already been mapped (eg: it has finished launching).
592 * It is not necessary for normally docked apps, but is needed for
593 * apps that were forcedly docked (like with dockit).
595 if (scr->last_dock) {
596 if (wwin && wwin->main_window != None && wwin->main_window != window)
597 wDockTrackWindowLaunch(scr->last_dock, wwin->main_window);
598 else
599 wDockTrackWindowLaunch(scr->last_dock, window);
602 if (wwin) {
603 wClientSetState(wwin, NormalState, None);
604 if (wwin->flags.maximized) {
605 wMaximizeWindow(wwin, wwin->flags.maximized);
607 if (wwin->flags.shaded) {
608 wwin->flags.shaded = 0;
609 wwin->flags.skip_next_animation = 1;
610 wShadeWindow(wwin);
612 if (wwin->flags.miniaturized) {
613 wwin->flags.miniaturized = 0;
614 wwin->flags.skip_next_animation = 1;
615 wIconifyWindow(wwin);
617 if (wwin->flags.fullscreen) {
618 wwin->flags.fullscreen = 0;
619 wFullscreenWindow(wwin);
621 if (wwin->flags.hidden) {
622 WApplication *wapp = wApplicationOf(wwin->main_window);
624 wwin->flags.hidden = 0;
625 wwin->flags.skip_next_animation = 1;
626 if (wapp) {
627 wHideApplication(wapp);
633 static void handleDestroyNotify(XEvent * event)
635 WWindow *wwin;
636 WApplication *app;
637 Window window = event->xdestroywindow.window;
638 WScreen *scr = wScreenForRootWindow(event->xdestroywindow.event);
639 int widx;
641 #ifdef DEBUG
642 printf("got destroy notify\n");
643 #endif
644 wwin = wWindowFor(window);
645 if (wwin) {
646 wUnmanageWindow(wwin, False, True);
649 if (scr != NULL) {
650 while ((widx = WMFindInArray(scr->fakeGroupLeaders, matchWindow, (void *)window)) != WANotFound) {
651 WFakeGroupLeader *fPtr;
653 fPtr = WMGetFromArray(scr->fakeGroupLeaders, widx);
654 if (fPtr->retainCount > 0) {
655 fPtr->retainCount--;
656 if (fPtr->retainCount == 0 && fPtr->leader != None) {
657 XDestroyWindow(dpy, fPtr->leader);
658 fPtr->leader = None;
659 XFlush(dpy);
662 fPtr->origLeader = None;
666 app = wApplicationOf(window);
667 if (app) {
668 if (window == app->main_window) {
669 app->refcount = 0;
670 wwin = app->main_window_desc->screen_ptr->focused_window;
671 while (wwin) {
672 if (wwin->main_window == window) {
673 wwin->main_window = None;
675 wwin = wwin->prev;
678 wApplicationDestroy(app);
682 static void handleExpose(XEvent * event)
684 WObjDescriptor *desc;
685 XEvent ev;
687 #ifdef DEBUG
688 printf("got expose\n");
689 #endif
690 while (XCheckTypedWindowEvent(dpy, event->xexpose.window, Expose, &ev)) ;
692 if (XFindContext(dpy, event->xexpose.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
693 return;
696 if (desc->handle_expose) {
697 (*desc->handle_expose) (desc, event);
701 static void executeButtonAction(WScreen * scr, XEvent * event, int action)
703 switch (action) {
704 case WA_SELECT_WINDOWS:
705 wUnselectWindows(scr);
706 wSelectWindows(scr, event);
707 break;
708 case WA_OPEN_APPMENU:
709 OpenRootMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
710 /* ugly hack */
711 if (scr->root_menu) {
712 if (scr->root_menu->brother->flags.mapped)
713 event->xbutton.window = scr->root_menu->brother->frame->core->window;
714 else
715 event->xbutton.window = scr->root_menu->frame->core->window;
717 break;
718 case WA_OPEN_WINLISTMENU:
719 OpenSwitchMenu(scr, event->xbutton.x_root, event->xbutton.y_root, False);
720 if (scr->switch_menu) {
721 if (scr->switch_menu->brother->flags.mapped)
722 event->xbutton.window = scr->switch_menu->brother->frame->core->window;
723 else
724 event->xbutton.window = scr->switch_menu->frame->core->window;
726 break;
727 default:
728 break;
732 /* bindable */
733 static void handleButtonPress(XEvent * event)
735 WObjDescriptor *desc;
736 WScreen *scr;
738 #ifdef DEBUG
739 printf("got button press\n");
740 #endif
741 scr = wScreenForRootWindow(event->xbutton.root);
743 #ifdef BALLOON_TEXT
744 wBalloonHide(scr);
745 #endif
747 #ifndef LITE
748 if (event->xbutton.window == scr->root_win) {
749 if (event->xbutton.button == Button1 && wPreferences.mouse_button1 != WA_NONE) {
750 executeButtonAction(scr, event, wPreferences.mouse_button1);
751 } else if (event->xbutton.button == Button2 && wPreferences.mouse_button2 != WA_NONE) {
752 executeButtonAction(scr, event, wPreferences.mouse_button2);
753 } else if (event->xbutton.button == Button3 && wPreferences.mouse_button3 != WA_NONE) {
754 executeButtonAction(scr, event, wPreferences.mouse_button3);
755 } else if (event->xbutton.button == Button4 && wPreferences.mouse_wheel != WA_NONE) {
756 wWorkspaceRelativeChange(scr, 1);
757 } else if (event->xbutton.button == Button5 && wPreferences.mouse_wheel != WA_NONE) {
758 wWorkspaceRelativeChange(scr, -1);
761 #endif /* !LITE */
763 desc = NULL;
764 if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *) & desc) == XCNOENT) {
765 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) == XCNOENT) {
766 return;
770 if (desc->parent_type == WCLASS_WINDOW) {
771 XSync(dpy, 0);
773 if (event->xbutton.state & MOD_MASK) {
774 XAllowEvents(dpy, AsyncPointer, CurrentTime);
777 /* if (wPreferences.focus_mode == WKF_CLICK) { */
778 if (wPreferences.ignore_focus_click) {
779 XAllowEvents(dpy, AsyncPointer, CurrentTime);
781 XAllowEvents(dpy, ReplayPointer, CurrentTime);
782 /* } */
783 XSync(dpy, 0);
784 } else if (desc->parent_type == WCLASS_APPICON
785 || desc->parent_type == WCLASS_MINIWINDOW || desc->parent_type == WCLASS_DOCK_ICON) {
786 if (event->xbutton.state & MOD_MASK) {
787 XSync(dpy, 0);
788 XAllowEvents(dpy, AsyncPointer, CurrentTime);
789 XSync(dpy, 0);
793 if (desc->handle_mousedown != NULL) {
794 (*desc->handle_mousedown) (desc, event);
797 /* save double-click information */
798 if (scr->flags.next_click_is_not_double) {
799 scr->flags.next_click_is_not_double = 0;
800 } else {
801 scr->last_click_time = event->xbutton.time;
802 scr->last_click_button = event->xbutton.button;
803 scr->last_click_window = event->xbutton.window;
807 static void handleMapNotify(XEvent * event)
809 WWindow *wwin;
810 #ifdef DEBUG
811 printf("got map\n");
812 #endif
813 wwin = wWindowFor(event->xmap.event);
814 if (wwin && wwin->client_win == event->xmap.event) {
815 if (wwin->flags.miniaturized) {
816 wDeiconifyWindow(wwin);
817 } else {
818 XGrabServer(dpy);
819 wWindowMap(wwin);
820 wClientSetState(wwin, NormalState, None);
821 XUngrabServer(dpy);
826 static void handleUnmapNotify(XEvent * event)
828 WWindow *wwin;
829 XEvent ev;
830 Bool withdraw = False;
831 #ifdef DEBUG
832 printf("got unmap\n");
833 #endif
834 /* only process windows with StructureNotify selected
835 * (ignore SubstructureNotify) */
836 wwin = wWindowFor(event->xunmap.window);
837 if (!wwin)
838 return;
840 /* whether the event is a Withdrawal request */
841 if (event->xunmap.event == wwin->screen_ptr->root_win && event->xunmap.send_event)
842 withdraw = True;
844 if (wwin->client_win != event->xunmap.event && !withdraw)
845 return;
847 if (!wwin->flags.mapped && !withdraw
848 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
849 && !wwin->flags.miniaturized && !wwin->flags.hidden)
850 return;
852 XGrabServer(dpy);
853 XUnmapWindow(dpy, wwin->frame->core->window);
854 wwin->flags.mapped = 0;
855 XSync(dpy, 0);
856 /* check if the window was destroyed */
857 if (XCheckTypedWindowEvent(dpy, wwin->client_win, DestroyNotify, &ev)) {
858 DispatchEvent(&ev);
859 } else {
860 Bool reparented = False;
862 if (XCheckTypedWindowEvent(dpy, wwin->client_win, ReparentNotify, &ev))
863 reparented = True;
865 /* withdraw window */
866 wwin->flags.mapped = 0;
867 if (!reparented)
868 wClientSetState(wwin, WithdrawnState, None);
870 /* if the window was reparented, do not reparent it back to the
871 * root window */
872 wUnmanageWindow(wwin, !reparented, False);
874 XUngrabServer(dpy);
877 static void handleConfigureRequest(XEvent * event)
879 WWindow *wwin;
880 #ifdef DEBUG
881 printf("got configure request\n");
882 #endif
883 if (!(wwin = wWindowFor(event->xconfigurerequest.window))) {
885 * Configure request for unmapped window
887 wClientConfigure(NULL, &(event->xconfigurerequest));
888 } else {
889 wClientConfigure(wwin, &(event->xconfigurerequest));
893 static void handlePropertyNotify(XEvent * event)
895 WWindow *wwin;
896 WApplication *wapp;
897 Window jr;
898 int ji;
899 unsigned int ju;
900 WScreen *scr;
901 #ifdef DEBUG
902 printf("got property notify\n");
903 #endif
905 wwin = wWindowFor(event->xproperty.window);
906 if (wwin) {
907 if (!XGetGeometry(dpy, wwin->client_win, &jr, &ji, &ji, &ju, &ju, &ju, &ju)) {
908 return;
910 wClientCheckProperty(wwin, &event->xproperty);
912 wapp = wApplicationOf(event->xproperty.window);
913 if (wapp) {
914 wClientCheckProperty(wapp->main_window_desc, &event->xproperty);
917 scr = wScreenForWindow(event->xproperty.window);
920 static void handleClientMessage(XEvent * event)
922 WWindow *wwin;
923 WObjDescriptor *desc;
924 #ifdef DEBUG
925 printf("got client message\n");
926 #endif
927 /* handle transition from Normal to Iconic state */
928 if (event->xclient.message_type == _XA_WM_CHANGE_STATE
929 && event->xclient.format == 32 && event->xclient.data.l[0] == IconicState) {
931 wwin = wWindowFor(event->xclient.window);
932 if (!wwin)
933 return;
934 if (!wwin->flags.miniaturized)
935 wIconifyWindow(wwin);
936 } else if (event->xclient.message_type == _XA_WM_COLORMAP_NOTIFY && event->xclient.format == 32) {
937 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
939 if (!scr)
940 return;
942 if (event->xclient.data.l[1] == 1) { /* starting */
943 wColormapAllowClientInstallation(scr, True);
944 } else { /* stopping */
945 wColormapAllowClientInstallation(scr, False);
947 } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
949 wDefaultsCheckDomains();
951 } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
952 WApplication *wapp;
953 int done = 0;
954 wapp = wApplicationOf(event->xclient.window);
955 if (wapp) {
956 switch (event->xclient.data.l[0]) {
957 case WMFHideOtherApplications:
958 wHideOtherApplications(wapp->main_window_desc);
959 done = 1;
960 break;
962 case WMFHideApplication:
963 wHideApplication(wapp);
964 done = 1;
965 break;
968 if (!done) {
969 wwin = wWindowFor(event->xclient.window);
970 if (wwin) {
971 switch (event->xclient.data.l[0]) {
972 case WMFHideOtherApplications:
973 wHideOtherApplications(wwin);
974 break;
976 case WMFHideApplication:
977 wHideApplication(wApplicationOf(wwin->main_window));
978 break;
982 } else if (event->xclient.message_type == _XA_GNUSTEP_WM_ATTR) {
983 wwin = wWindowFor(event->xclient.window);
984 if (!wwin)
985 return;
986 switch (event->xclient.data.l[0]) {
987 case GSWindowLevelAttr:
989 int level = (int)event->xclient.data.l[1];
991 if (WINDOW_LEVEL(wwin) != level) {
992 ChangeStackingLevel(wwin->frame->core, level);
995 break;
997 } else if (event->xclient.message_type == _XA_GNUSTEP_TITLEBAR_STATE) {
998 wwin = wWindowFor(event->xclient.window);
999 if (!wwin)
1000 return;
1001 switch (event->xclient.data.l[0]) {
1002 case WMTitleBarNormal:
1003 wFrameWindowChangeState(wwin->frame, WS_UNFOCUSED);
1004 break;
1005 case WMTitleBarMain:
1006 wFrameWindowChangeState(wwin->frame, WS_PFOCUSED);
1007 break;
1008 case WMTitleBarKey:
1009 wFrameWindowChangeState(wwin->frame, WS_FOCUSED);
1010 break;
1012 } else if (event->xclient.message_type == _XA_WM_IGNORE_FOCUS_EVENTS) {
1013 WScreen *scr = wScreenSearchForRootWindow(event->xclient.window);
1014 if (!scr)
1015 return;
1016 scr->flags.ignore_focus_events = event->xclient.data.l[0] ? 1 : 0;
1017 #ifdef NETWM_HINTS
1018 } else if (wNETWMProcessClientMessage(&event->xclient)) {
1019 /* do nothing */
1020 #endif
1021 #ifdef XDND
1022 } else if (wXDNDProcessClientMessage(&event->xclient)) {
1023 /* do nothing */
1024 #endif /* XDND */
1025 } else {
1027 * Non-standard thing, but needed by OffiX DND.
1028 * For when the icon frame gets a ClientMessage
1029 * that should have gone to the icon_window.
1031 if (XFindContext(dpy, event->xbutton.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1032 struct WIcon *icon = NULL;
1034 if (desc->parent_type == WCLASS_MINIWINDOW) {
1035 icon = (WIcon *) desc->parent;
1036 } else if (desc->parent_type == WCLASS_DOCK_ICON || desc->parent_type == WCLASS_APPICON) {
1037 icon = ((WAppIcon *) desc->parent)->icon;
1039 if (icon && (wwin = icon->owner)) {
1040 if (wwin->client_win != event->xclient.window) {
1041 event->xclient.window = wwin->client_win;
1042 XSendEvent(dpy, wwin->client_win, False, NoEventMask, event);
1049 static void raiseWindow(WScreen * scr)
1051 WWindow *wwin;
1053 scr->autoRaiseTimer = NULL;
1055 wwin = wWindowFor(scr->autoRaiseWindow);
1056 if (!wwin)
1057 return;
1059 if (!wwin->flags.destroyed && wwin->flags.focused) {
1060 wRaiseFrame(wwin->frame->core);
1061 /* this is needed or a race condition will occur */
1062 XSync(dpy, False);
1066 static void handleEnterNotify(XEvent * event)
1068 WWindow *wwin;
1069 WObjDescriptor *desc = NULL;
1070 #ifdef VIRTUAL_DESKTOP
1071 void (*vdHandler) (XEvent * event);
1072 #endif
1073 XEvent ev;
1074 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
1075 #ifdef DEBUG
1076 printf("got enter notify\n");
1077 #endif
1079 #ifdef VIRTUAL_DESKTOP
1080 if (XFindContext(dpy, event->xcrossing.window, wVEdgeContext, (XPointer *) & vdHandler) != XCNOENT) {
1081 (*vdHandler) (event);
1083 #endif
1085 if (XCheckTypedWindowEvent(dpy, event->xcrossing.window, LeaveNotify, &ev)) {
1086 /* already left the window... */
1087 saveTimestamp(&ev);
1088 if (ev.xcrossing.mode == event->xcrossing.mode && ev.xcrossing.detail == event->xcrossing.detail) {
1089 return;
1093 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1094 if (desc->handle_enternotify)
1095 (*desc->handle_enternotify) (desc, event);
1098 /* enter to window */
1099 wwin = wWindowFor(event->xcrossing.window);
1100 if (!wwin) {
1101 if (wPreferences.colormap_mode == WCM_POINTER) {
1102 wColormapInstallForWindow(scr, NULL);
1104 if (scr->autoRaiseTimer && event->xcrossing.root == event->xcrossing.window) {
1105 WMDeleteTimerHandler(scr->autoRaiseTimer);
1106 scr->autoRaiseTimer = NULL;
1108 } else {
1109 /* set auto raise timer even if in focus-follows-mouse mode
1110 * and the event is for the frame window, even if the window
1111 * has focus already. useful if you move the pointer from a focused
1112 * window to the root window and back pretty fast
1114 * set focus if in focus-follows-mouse mode and the event
1115 * is for the frame window and window doesn't have focus yet */
1116 if (wPreferences.focus_mode == WKF_SLOPPY
1117 && wwin->frame->core->window == event->xcrossing.window && !scr->flags.doing_alt_tab) {
1119 if (!wwin->flags.focused && !WFLAGP(wwin, no_focusable))
1120 wSetFocusTo(scr, wwin);
1122 if (scr->autoRaiseTimer)
1123 WMDeleteTimerHandler(scr->autoRaiseTimer);
1124 scr->autoRaiseTimer = NULL;
1126 if (wPreferences.raise_delay && !WFLAGP(wwin, no_focusable)) {
1127 scr->autoRaiseWindow = wwin->frame->core->window;
1128 scr->autoRaiseTimer
1129 = WMAddTimerHandler(wPreferences.raise_delay, (WMCallback *) raiseWindow, scr);
1132 /* Install colormap for window, if the colormap installation mode
1133 * is colormap_follows_mouse */
1134 if (wPreferences.colormap_mode == WCM_POINTER) {
1135 if (wwin->client_win == event->xcrossing.window)
1136 wColormapInstallForWindow(scr, wwin);
1137 else
1138 wColormapInstallForWindow(scr, NULL);
1142 /* a little kluge to hide the clip balloon */
1143 if (!wPreferences.flags.noclip && scr->flags.clip_balloon_mapped) {
1144 if (!desc) {
1145 XUnmapWindow(dpy, scr->clip_balloon);
1146 scr->flags.clip_balloon_mapped = 0;
1147 } else {
1148 if (desc->parent_type != WCLASS_DOCK_ICON || scr->clip_icon != desc->parent) {
1149 XUnmapWindow(dpy, scr->clip_balloon);
1150 scr->flags.clip_balloon_mapped = 0;
1155 if (event->xcrossing.window == event->xcrossing.root
1156 && event->xcrossing.detail == NotifyNormal
1157 && event->xcrossing.detail != NotifyInferior && wPreferences.focus_mode != WKF_CLICK) {
1159 wSetFocusTo(scr, scr->focused_window);
1161 #ifdef BALLOON_TEXT
1162 wBalloonEnteredObject(scr, desc);
1163 #endif
1166 static void handleLeaveNotify(XEvent * event)
1168 WObjDescriptor *desc = NULL;
1170 if (XFindContext(dpy, event->xcrossing.window, wWinContext, (XPointer *) & desc) != XCNOENT) {
1171 if (desc->handle_leavenotify)
1172 (*desc->handle_leavenotify) (desc, event);
1176 #ifdef SHAPE
1177 static void handleShapeNotify(XEvent * event)
1179 XShapeEvent *shev = (XShapeEvent *) event;
1180 WWindow *wwin;
1181 XEvent ev;
1182 #ifdef DEBUG
1183 printf("got shape notify\n");
1184 #endif
1185 while (XCheckTypedWindowEvent(dpy, shev->window, event->type, &ev)) {
1186 XShapeEvent *sev = (XShapeEvent *) & ev;
1188 if (sev->kind == ShapeBounding) {
1189 if (sev->shaped == shev->shaped) {
1190 *shev = *sev;
1191 } else {
1192 XPutBackEvent(dpy, &ev);
1193 break;
1198 wwin = wWindowFor(shev->window);
1199 if (!wwin || shev->kind != ShapeBounding)
1200 return;
1202 if (!shev->shaped && wwin->flags.shaped) {
1204 wwin->flags.shaped = 0;
1205 wWindowClearShape(wwin);
1207 } else if (shev->shaped) {
1209 wwin->flags.shaped = 1;
1210 wWindowSetShape(wwin);
1213 #endif /* SHAPE */
1215 #ifdef KEEP_XKB_LOCK_STATUS
1216 /* please help ]d if you know what to do */
1217 handleXkbIndicatorStateNotify(XEvent * event)
1219 WWindow *wwin;
1220 WScreen *scr;
1221 XkbStateRec staterec;
1222 int i;
1224 for (i = 0; i < wScreenCount; i++) {
1225 scr = wScreenWithNumber(i);
1226 wwin = scr->focused_window;
1227 if (wwin && wwin->flags.focused) {
1228 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1229 if (wwin->frame->languagemode != staterec.group) {
1230 wwin->frame->last_languagemode = wwin->frame->languagemode;
1231 wwin->frame->languagemode = staterec.group;
1233 #ifdef XKB_BUTTON_HINT
1234 if (wwin->frame->titlebar) {
1235 wFrameWindowPaint(wwin->frame);
1237 #endif
1241 #endif /*KEEP_XKB_LOCK_STATUS */
1243 static void handleColormapNotify(XEvent * event)
1245 WWindow *wwin;
1246 WScreen *scr;
1247 Bool reinstall = False;
1249 wwin = wWindowFor(event->xcolormap.window);
1250 if (!wwin)
1251 return;
1253 scr = wwin->screen_ptr;
1255 do {
1256 if (wwin) {
1257 if (event->xcolormap.new) {
1258 XWindowAttributes attr;
1260 XGetWindowAttributes(dpy, wwin->client_win, &attr);
1262 if (wwin == scr->cmap_window && wwin->cmap_window_no == 0)
1263 scr->current_colormap = attr.colormap;
1265 reinstall = True;
1266 } else if (event->xcolormap.state == ColormapUninstalled &&
1267 scr->current_colormap == event->xcolormap.colormap) {
1269 /* some bastard app (like XV) removed our colormap */
1271 * can't enforce or things like xscreensaver wont work
1272 * reinstall = True;
1274 } else if (event->xcolormap.state == ColormapInstalled &&
1275 scr->current_colormap == event->xcolormap.colormap) {
1277 /* someone has put our colormap back */
1278 reinstall = False;
1281 } while (XCheckTypedEvent(dpy, ColormapNotify, event)
1282 && ((wwin = wWindowFor(event->xcolormap.window)) || 1));
1284 if (reinstall && scr->current_colormap != None) {
1285 if (!scr->flags.colormap_stuff_blocked)
1286 XInstallColormap(dpy, scr->current_colormap);
1290 static void handleFocusIn(XEvent * event)
1292 WWindow *wwin;
1295 * For applications that like stealing the focus.
1297 while (XCheckTypedEvent(dpy, FocusIn, event)) ;
1298 saveTimestamp(event);
1299 if (event->xfocus.mode == NotifyUngrab
1300 || event->xfocus.mode == NotifyGrab || event->xfocus.detail > NotifyNonlinearVirtual) {
1301 return;
1304 wwin = wWindowFor(event->xfocus.window);
1305 if (wwin && !wwin->flags.focused) {
1306 if (wwin->flags.mapped)
1307 wSetFocusTo(wwin->screen_ptr, wwin);
1308 else
1309 wSetFocusTo(wwin->screen_ptr, NULL);
1310 } else if (!wwin) {
1311 WScreen *scr = wScreenForWindow(event->xfocus.window);
1312 if (scr)
1313 wSetFocusTo(scr, NULL);
1317 static WWindow *windowUnderPointer(WScreen * scr)
1319 unsigned int mask;
1320 int foo;
1321 Window bar, win;
1323 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask))
1324 return wWindowFor(win);
1325 return NULL;
1328 static int CheckFullScreenWindowFocused(WScreen * scr)
1330 if (scr->focused_window && scr->focused_window->flags.fullscreen)
1331 return 1;
1332 else
1333 return 0;
1336 static void handleKeyPress(XEvent * event)
1338 WScreen *scr = wScreenForRootWindow(event->xkey.root);
1339 WWindow *wwin = scr->focused_window;
1340 short i, widx;
1341 int modifiers;
1342 int command = -1;
1343 #ifdef KEEP_XKB_LOCK_STATUS
1344 XkbStateRec staterec;
1345 #endif /*KEEP_XKB_LOCK_STATUS */
1347 /* ignore CapsLock */
1348 modifiers = event->xkey.state & ValidModMask;
1350 for (i = 0; i < WKBD_LAST; i++) {
1351 if (wKeyBindings[i].keycode == 0)
1352 continue;
1354 if (wKeyBindings[i].keycode == event->xkey.keycode && ( /*wKeyBindings[i].modifier==0
1355 || */ wKeyBindings[i].modifier ==
1356 modifiers)) {
1357 command = i;
1358 break;
1362 if (command < 0) {
1363 #ifdef LITE
1365 #if 0
1367 #endif
1368 #else
1369 if (!wRootMenuPerformShortcut(event)) {
1370 #endif
1371 static int dontLoop = 0;
1373 if (dontLoop > 10) {
1374 wwarning("problem with key event processing code");
1375 return;
1377 dontLoop++;
1378 /* if the focused window is an internal window, try redispatching
1379 * the event to the managed window, as it can be a WINGs window */
1380 if (wwin && wwin->flags.internal_window && wwin->client_leader != None) {
1381 /* client_leader contains the WINGs toplevel */
1382 event->xany.window = wwin->client_leader;
1383 WMHandleEvent(event);
1385 dontLoop--;
1387 return;
1389 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1390 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1392 switch (command) {
1393 #ifndef LITE
1394 case WKBD_ROOTMENU:
1395 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1396 if (!CheckFullScreenWindowFocused(scr)) {
1397 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1398 OpenRootMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1399 True);
1401 break;
1402 case WKBD_WINDOWLIST:
1403 if (!CheckFullScreenWindowFocused(scr)) {
1404 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1405 OpenSwitchMenu(scr, rect.pos.x + rect.size.width / 2, rect.pos.y + rect.size.height / 2,
1406 True);
1408 break;
1409 #endif /* !LITE */
1410 case WKBD_WINDOWMENU:
1411 if (ISMAPPED(wwin) && ISFOCUSED(wwin))
1412 OpenWindowMenu(wwin, wwin->frame_x, wwin->frame_y + wwin->frame->top_width, True);
1413 break;
1414 case WKBD_MINIATURIZE:
1415 if (ISMAPPED(wwin) && ISFOCUSED(wwin)
1416 && !WFLAGP(wwin, no_miniaturizable)) {
1417 CloseWindowMenu(scr);
1419 if (wwin->protocols.MINIATURIZE_WINDOW)
1420 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, event->xbutton.time);
1421 else {
1422 wIconifyWindow(wwin);
1425 break;
1426 case WKBD_HIDE:
1427 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1428 WApplication *wapp = wApplicationOf(wwin->main_window);
1429 CloseWindowMenu(scr);
1431 if (wapp && !WFLAGP(wapp->main_window_desc, no_appicon)) {
1432 wHideApplication(wapp);
1435 break;
1436 case WKBD_HIDE_OTHERS:
1437 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1438 CloseWindowMenu(scr);
1440 wHideOtherApplications(wwin);
1442 break;
1443 case WKBD_MAXIMIZE:
1444 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1445 int newdir = (MAX_VERTICAL | MAX_HORIZONTAL);
1447 CloseWindowMenu(scr);
1449 if (wwin->flags.maximized == newdir) {
1450 wUnmaximizeWindow(wwin);
1451 } else {
1452 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1455 break;
1456 case WKBD_VMAXIMIZE:
1457 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1458 int newdir = (MAX_VERTICAL ^ wwin->flags.maximized);
1460 CloseWindowMenu(scr);
1462 if (newdir) {
1463 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1464 } else {
1465 wUnmaximizeWindow(wwin);
1468 break;
1469 case WKBD_HMAXIMIZE:
1470 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) {
1471 int newdir = (MAX_HORIZONTAL ^ wwin->flags.maximized);
1473 CloseWindowMenu(scr);
1475 if (newdir) {
1476 wMaximizeWindow(wwin, newdir | MAX_KEYBOARD);
1477 } else {
1478 wUnmaximizeWindow(wwin);
1481 break;
1482 case WKBD_RAISE:
1483 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1484 CloseWindowMenu(scr);
1486 wRaiseFrame(wwin->frame->core);
1488 break;
1489 case WKBD_LOWER:
1490 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1491 CloseWindowMenu(scr);
1493 wLowerFrame(wwin->frame->core);
1495 break;
1496 case WKBD_RAISELOWER:
1497 /* raise or lower the window under the pointer, not the
1498 * focused one
1500 wwin = windowUnderPointer(scr);
1501 if (wwin)
1502 wRaiseLowerFrame(wwin->frame->core);
1503 break;
1504 case WKBD_SHADE:
1505 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_shadeable)) {
1506 if (wwin->flags.shaded)
1507 wUnshadeWindow(wwin);
1508 else
1509 wShadeWindow(wwin);
1511 break;
1512 case WKBD_MOVERESIZE:
1513 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && (IS_RESIZABLE(wwin) || IS_MOVABLE(wwin))) {
1514 CloseWindowMenu(scr);
1516 wKeyboardMoveResizeWindow(wwin);
1518 break;
1519 case WKBD_CLOSE:
1520 if (ISMAPPED(wwin) && ISFOCUSED(wwin) && !WFLAGP(wwin, no_closable)) {
1521 CloseWindowMenu(scr);
1522 if (wwin->protocols.DELETE_WINDOW)
1523 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, event->xkey.time);
1525 break;
1526 case WKBD_SELECT:
1527 if (ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1528 wSelectWindow(wwin, !wwin->flags.selected);
1530 break;
1531 case WKBD_FOCUSNEXT:
1532 StartWindozeCycle(wwin, event, True);
1533 break;
1535 case WKBD_FOCUSPREV:
1536 StartWindozeCycle(wwin, event, False);
1537 break;
1539 case WKBD_WORKSPACE1...WKBD_WORKSPACE10:
1540 widx = command - WKBD_WORKSPACE1;
1541 i = (scr->current_workspace / 10) * 10 + widx;
1542 if (wPreferences.ws_advance || i < scr->workspace_count)
1543 wWorkspaceChange(scr, i);
1544 break;
1546 case WKBD_NEXTWORKSPACE:
1547 wWorkspaceRelativeChange(scr, 1);
1548 break;
1549 case WKBD_PREVWORKSPACE:
1550 wWorkspaceRelativeChange(scr, -1);
1551 break;
1552 case WKBD_WINDOW1:
1553 case WKBD_WINDOW2:
1554 case WKBD_WINDOW3:
1555 case WKBD_WINDOW4:
1556 case WKBD_WINDOW5:
1557 case WKBD_WINDOW6:
1558 case WKBD_WINDOW7:
1559 case WKBD_WINDOW8:
1560 case WKBD_WINDOW9:
1561 case WKBD_WINDOW10:
1563 widx = command - WKBD_WINDOW1;
1565 if (scr->shortcutWindows[widx]) {
1566 WMArray *list = scr->shortcutWindows[widx];
1567 int cw;
1568 int count = WMGetArrayItemCount(list);
1569 WWindow *twin;
1570 WMArrayIterator iter;
1571 WWindow *wwin;
1573 wUnselectWindows(scr);
1574 cw = scr->current_workspace;
1576 WM_ETARETI_ARRAY(list, wwin, iter) {
1577 if (count > 1)
1578 wWindowChangeWorkspace(wwin, cw);
1580 wMakeWindowVisible(wwin);
1582 if (count > 1)
1583 wSelectWindow(wwin, True);
1586 /* rotate the order of windows, to create a cycling effect */
1587 twin = WMGetFromArray(list, 0);
1588 WMDeleteFromArray(list, 0);
1589 WMAddToArray(list, twin);
1591 } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
1592 if (scr->shortcutWindows[widx]) {
1593 WMFreeArray(scr->shortcutWindows[widx]);
1594 scr->shortcutWindows[widx] = NULL;
1597 if (wwin->flags.selected && scr->selected_windows) {
1598 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1599 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1600 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1601 } else {
1602 scr->shortcutWindows[widx] = WMCreateArray(4);
1603 WMAddToArray(scr->shortcutWindows[widx], wwin);
1606 wSelectWindow(wwin, !wwin->flags.selected);
1607 XFlush(dpy);
1608 wusleep(3000);
1609 wSelectWindow(wwin, !wwin->flags.selected);
1610 XFlush(dpy);
1612 } else if (scr->selected_windows && WMGetArrayItemCount(scr->selected_windows)) {
1614 if (wwin->flags.selected && scr->selected_windows) {
1615 if (scr->shortcutWindows[widx]) {
1616 WMFreeArray(scr->shortcutWindows[widx]);
1618 scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
1622 break;
1624 case WKBD_SWITCH_SCREEN:
1625 if (wScreenCount > 1) {
1626 WScreen *scr2;
1627 int i;
1629 /* find index of this screen */
1630 for (i = 0; i < wScreenCount; i++) {
1631 if (wScreenWithNumber(i) == scr)
1632 break;
1634 i++;
1635 if (i >= wScreenCount) {
1636 i = 0;
1638 scr2 = wScreenWithNumber(i);
1640 if (scr2) {
1641 XWarpPointer(dpy, scr->root_win, scr2->root_win, 0, 0, 0, 0,
1642 scr2->scr_width / 2, scr2->scr_height / 2);
1645 break;
1647 case WKBD_NEXTWSLAYER:
1648 case WKBD_PREVWSLAYER:
1650 int row, column;
1652 row = scr->current_workspace / 10;
1653 column = scr->current_workspace % 10;
1655 if (command == WKBD_NEXTWSLAYER) {
1656 if ((row + 1) * 10 < scr->workspace_count)
1657 wWorkspaceChange(scr, column + (row + 1) * 10);
1658 } else {
1659 if (row > 0)
1660 wWorkspaceChange(scr, column + (row - 1) * 10);
1663 break;
1664 case WKBD_CLIPLOWER:
1665 if (!wPreferences.flags.noclip)
1666 wDockLower(scr->workspaces[scr->current_workspace]->clip);
1667 break;
1668 case WKBD_CLIPRAISE:
1669 if (!wPreferences.flags.noclip)
1670 wDockRaise(scr->workspaces[scr->current_workspace]->clip);
1671 break;
1672 case WKBD_CLIPRAISELOWER:
1673 if (!wPreferences.flags.noclip)
1674 wDockRaiseLower(scr->workspaces[scr->current_workspace]->clip);
1675 break;
1676 #ifdef KEEP_XKB_LOCK_STATUS
1677 case WKBD_TOGGLE:
1678 if (wPreferences.modelock) {
1679 /*toggle */
1680 wwin = scr->focused_window;
1682 if (wwin && wwin->flags.mapped
1683 && wwin->frame->workspace == wwin->screen_ptr->current_workspace
1684 && !wwin->flags.miniaturized && !wwin->flags.hidden) {
1685 XkbGetState(dpy, XkbUseCoreKbd, &staterec);
1687 wwin->frame->languagemode = wwin->frame->last_languagemode;
1688 wwin->frame->last_languagemode = staterec.group;
1689 XkbLockGroup(dpy, XkbUseCoreKbd, wwin->frame->languagemode);
1693 break;
1694 #endif /* KEEP_XKB_LOCK_STATUS */
1695 #ifdef VIRTUAL_DESKTOP
1696 case WKBD_VDESK_LEFT:
1697 wWorkspaceKeyboardMoveDesktop(scr, VEC_LEFT);
1698 break;
1700 case WKBD_VDESK_RIGHT:
1701 wWorkspaceKeyboardMoveDesktop(scr, VEC_RIGHT);
1702 break;
1704 case WKBD_VDESK_UP:
1705 wWorkspaceKeyboardMoveDesktop(scr, VEC_UP);
1706 break;
1708 case WKBD_VDESK_DOWN:
1709 wWorkspaceKeyboardMoveDesktop(scr, VEC_DOWN);
1710 break;
1711 #endif
1716 static void handleMotionNotify(XEvent * event)
1718 WScreen *scr = wScreenForRootWindow(event->xmotion.root);
1720 if (wPreferences.scrollable_menus) {
1721 WMPoint p = wmkpoint(event->xmotion.x_root, event->xmotion.y_root);
1722 WMRect rect = wGetRectForHead(scr, wGetHeadForPoint(scr, p));
1724 if (scr->flags.jump_back_pending ||
1725 p.x <= (rect.pos.x + 1) ||
1726 p.x >= (rect.pos.x + rect.size.width - 2) ||
1727 p.y <= (rect.pos.y + 1) || p.y >= (rect.pos.y + rect.size.height - 2)) {
1728 WMenu *menu;
1729 #ifdef DEBUG
1730 printf("pointer at screen edge\n");
1731 #endif
1732 menu = wMenuUnderPointer(scr);
1733 if (menu != NULL)
1734 wMenuScroll(menu, event);
1739 static void handleVisibilityNotify(XEvent * event)
1741 WWindow *wwin;
1743 wwin = wWindowFor(event->xvisibility.window);
1744 if (!wwin)
1745 return;
1746 wwin->flags.obscured = (event->xvisibility.state == VisibilityFullyObscured);