1 /* cycling.c- window cycling
3 * Window Maker window manager
5 * Copyright (c) 2000-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,
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
29 // TODO: remove non-MOX_CYCLING junk
30 // fix the stacking/window raising during alt-tabbing
31 // allow selection of icons with mouse
33 #include "WindowMaker.h"
44 #include "switchpanel.h"
47 extern WPreferences wPreferences
;
49 extern WShortKey wKeyBindings
[WKBD_LAST
];
52 static void raiseWindow(WSwitchPanel
*swpanel
, WWindow
*wwin
)
54 if (wwin
->flags
.mapped
) {
57 win
[0]= wSwitchPanelGetWindow(swpanel
);
58 win
[1]= wwin
->frame
->core
->window
;
60 XRestackWindows(dpy
, win
, 2);
67 StartWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
69 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
74 XModifierKeymap
*keymap
= NULL
;
76 Bool somethingElse
= False
;
78 WSwitchPanel
*swpanel
= NULL
;
79 KeyCode leftKey
, rightKey
, homeKey
, endKey
;
84 leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
85 rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
86 homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
87 endKey
= XKeysymToKeycode(dpy
, XK_End
);
90 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
92 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
95 keymap
= XGetModifierMapping(dpy
);
98 printf("Grabbing keyboard\n");
100 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
104 scr
->flags
.doing_alt_tab
= 1;
106 swpanel
= wInitSwitchPanel(scr
, wwin
, scr
->current_workspace
);
110 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
);
112 wWindowFocus(newFocused
, oldFocused
);
113 oldFocused
= newFocused
;
115 if (wPreferences
.circ_raise
)
116 raiseWindow(swpanel
, newFocused
);
121 if (wwin
->frame
->workspace
== scr
->current_workspace
)
127 while (hasModifier
&& !done
) {
128 WMMaskEvent(dpy
, KeyPressMask
|KeyReleaseMask
|ExposureMask
|PointerMotionMask
, &ev
);
130 if (ev
.type
!= KeyRelease
&& ev
.type
!= KeyPress
) {
134 /* ignore CapsLock */
135 modifiers
= ev
.xkey
.state
& ValidModMask
;
137 if (ev
.type
== KeyPress
) {
139 printf("Got key press\n");
141 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
142 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
143 || ev
.xkey
.keycode
== rightKey
) {
146 newFocused
= wSwitchPanelSelectNext(swpanel
, False
);
148 wWindowFocus(newFocused
, oldFocused
);
149 oldFocused
= newFocused
;
151 if (wPreferences
.circ_raise
) {
153 raiseWindow(swpanel
, newFocused
);
157 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
158 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
159 || ev
.xkey
.keycode
== leftKey
) {
162 newFocused
= wSwitchPanelSelectNext(swpanel
, True
);
164 wWindowFocus(newFocused
, oldFocused
);
165 oldFocused
= newFocused
;
167 if (wPreferences
.circ_raise
) {
169 raiseWindow(swpanel
, newFocused
);
173 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
175 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
177 wWindowFocus(newFocused
, oldFocused
);
178 oldFocused
= newFocused
;
180 if (wPreferences
.circ_raise
) {
182 raiseWindow(swpanel
, newFocused
);
186 } else if (ev
.type
== MotionNotify
) {
189 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
192 wWindowFocus(newFocused
, oldFocused
);
193 oldFocused
= newFocused
;
198 printf("Got something else\n");
200 somethingElse
= True
;
203 } else if (ev
.type
== KeyRelease
) {
207 printf("Got key release\n");
209 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
210 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
211 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
212 & 1<<(i
/keymap
->max_keypermod
)) {
220 XFreeModifiermap(keymap
);
224 printf("Ungrabbing keyboard\n");
226 XUngrabKeyboard(dpy
, CurrentTime
);
231 if (!newFocused
->flags
.mapped
)
232 wMakeWindowVisible(newFocused
);
233 wSetFocusTo(scr
, newFocused
);
234 wRaiseFrame(newFocused
->frame
->core
);
238 wSwitchPanelDestroy(swpanel
);
240 scr
->flags
.doing_alt_tab
= 0;