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 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.
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
29 #include "WindowMaker.h"
39 #include "switchpanel.h"
42 extern WShortKey wKeyBindings
[WKBD_LAST
];
44 static void raiseWindow(WSwitchPanel
* swpanel
, WWindow
* wwin
)
46 Window swwin
= wSwitchPanelGetWindow(swpanel
);
48 if (wwin
->flags
.mapped
) {
53 win
[1] = wwin
->frame
->core
->window
;
55 XRestackWindows(dpy
, win
, 2);
57 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
61 static WWindow
*change_focus_and_raise(WWindow
*newFocused
, WWindow
*oldFocused
,
62 WSwitchPanel
*swpanel
, WScreen
*scr
, Bool esc_cancel
)
67 wWindowFocus(newFocused
, oldFocused
);
68 oldFocused
= newFocused
;
70 if (wPreferences
.circ_raise
) {
74 raiseWindow(swpanel
, newFocused
);
80 void StartWindozeCycle(WWindow
* wwin
, XEvent
* event
, Bool next
, Bool class_only
)
83 XModifierKeymap
*keymap
= NULL
;
84 WSwitchPanel
*swpanel
= NULL
;
85 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
86 KeyCode leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
87 KeyCode rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
88 KeyCode homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
89 KeyCode endKey
= XKeysymToKeycode(dpy
, XK_End
);
90 KeyCode shiftLKey
= XKeysymToKeycode(dpy
, XK_Shift_L
);
91 KeyCode shiftRKey
= XKeysymToKeycode(dpy
, XK_Shift_R
);
92 KeyCode escapeKey
= XKeysymToKeycode(dpy
, XK_Escape
);
93 KeyCode returnKey
= XKeysymToKeycode(dpy
, XK_Return
);
94 Bool esc_cancel
= False
;
95 Bool somethingElse
= False
;
109 hasModifier
= (wKeyBindings
[WKBD_GROUPNEXT
].modifier
!= 0);
111 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
114 hasModifier
= (wKeyBindings
[WKBD_GROUPPREV
].modifier
!= 0);
116 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
120 keymap
= XGetModifierMapping(dpy
);
121 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
124 scr
->flags
.doing_alt_tab
= 1;
126 swpanel
= wInitSwitchPanel(scr
, wwin
, class_only
);
131 if (wwin
->flags
.mapped
&& !wPreferences
.panel_only_open
)
132 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
, True
, False
);
134 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
136 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
138 if (wwin
->frame
->workspace
== scr
->current_workspace
)
144 while (hasModifier
&& !done
) {
147 WMMaskEvent(dpy
, KeyPressMask
| KeyReleaseMask
| ExposureMask
148 | PointerMotionMask
| ButtonReleaseMask
| EnterWindowMask
, &ev
);
150 /* ignore CapsLock */
151 modifiers
= ev
.xkey
.state
& ValidModMask
;
160 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
161 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
162 || (wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
163 && wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
)
164 || ev
.xkey
.keycode
== rightKey
) {
166 newFocused
= wSwitchPanelSelectNext(swpanel
, False
, ev
.xkey
.keycode
!= rightKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
));
167 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
169 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
170 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
171 || (wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
172 && wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
)
173 || ev
.xkey
.keycode
== leftKey
) {
175 newFocused
= wSwitchPanelSelectNext(swpanel
, True
, ev
.xkey
.keycode
!= leftKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
));
176 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
178 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
180 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
181 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
183 } else if (ev
.xkey
.keycode
== escapeKey
) {
185 /* Focus the first window of the swpanel, despite the 'False' */
186 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
187 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, True
);
191 } else if (ev
.xkey
.keycode
== returnKey
) {
193 /* Close the switchpanel without eating the keypress */
196 } else if (ev
.xkey
.keycode
!= shiftLKey
&& ev
.xkey
.keycode
!= shiftRKey
) {
198 somethingElse
= True
;
205 if (ev
.xkey
.keycode
== shiftLKey
|| ev
.xkey
.keycode
== shiftRKey
)
206 if (wPreferences
.strict_windoze_cycle
)
209 if (ev
.xkey
.keycode
== XK_Return
)
212 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
214 int mask
= 1 << (i
/ keymap
->max_keypermod
);
216 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
217 ((wKeyBindings
[WKBD_FOCUSNEXT
].modifier
& mask
)
218 || (wKeyBindings
[WKBD_FOCUSPREV
].modifier
& mask
)
219 || (wKeyBindings
[WKBD_GROUPNEXT
].modifier
& mask
)
220 || (wKeyBindings
[WKBD_GROUPPREV
].modifier
& mask
))) {
229 /* ignore unwanted EnterNotify's */
238 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
241 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
243 if (ev
.type
== ButtonRelease
)
255 XFreeModifiermap(keymap
);
259 XUngrabKeyboard(dpy
, CurrentTime
);
263 wSwitchPanelDestroy(swpanel
);
265 if (newFocused
&& !esc_cancel
) {
266 wRaiseFrame(newFocused
->frame
->core
);
268 if (!newFocused
->flags
.mapped
)
269 wMakeWindowVisible(newFocused
);
270 wSetFocusTo(scr
, newFocused
);
273 scr
->flags
.doing_alt_tab
= 0;