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 WPreferences wPreferences
;
44 extern WShortKey wKeyBindings
[WKBD_LAST
];
46 static void raiseWindow(WSwitchPanel
* swpanel
, WWindow
* wwin
)
48 Window swwin
= wSwitchPanelGetWindow(swpanel
);
50 if (wwin
->flags
.mapped
) {
55 win
[1] = wwin
->frame
->core
->window
;
57 XRestackWindows(dpy
, win
, 2);
59 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
63 static WWindow
*change_focus_and_raise(WWindow
*newFocused
, WWindow
*oldFocused
,
64 WSwitchPanel
*swpanel
, WScreen
*scr
, Bool esc_cancel
)
69 wWindowFocus(newFocused
, oldFocused
);
70 oldFocused
= newFocused
;
72 if (wPreferences
.circ_raise
) {
76 raiseWindow(swpanel
, newFocused
);
82 void StartWindozeCycle(WWindow
* wwin
, XEvent
* event
, Bool next
, Bool class_only
)
85 XModifierKeymap
*keymap
= NULL
;
86 WSwitchPanel
*swpanel
= NULL
;
87 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
88 KeyCode leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
89 KeyCode rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
90 KeyCode homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
91 KeyCode endKey
= XKeysymToKeycode(dpy
, XK_End
);
92 KeyCode shiftLKey
= XKeysymToKeycode(dpy
, XK_Shift_L
);
93 KeyCode shiftRKey
= XKeysymToKeycode(dpy
, XK_Shift_R
);
94 KeyCode escapeKey
= XKeysymToKeycode(dpy
, XK_Escape
);
95 KeyCode returnKey
= XKeysymToKeycode(dpy
, XK_Return
);
96 Bool esc_cancel
= False
;
97 Bool somethingElse
= False
;
111 hasModifier
= (wKeyBindings
[WKBD_GROUPNEXT
].modifier
!= 0);
113 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
116 hasModifier
= (wKeyBindings
[WKBD_GROUPPREV
].modifier
!= 0);
118 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
122 keymap
= XGetModifierMapping(dpy
);
123 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
126 scr
->flags
.doing_alt_tab
= 1;
128 swpanel
= wInitSwitchPanel(scr
, wwin
, class_only
);
133 if (wwin
->flags
.mapped
&& !wPreferences
.panel_only_open
)
134 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
, True
, False
);
136 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
138 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
140 if (wwin
->frame
->workspace
== scr
->current_workspace
)
146 while (hasModifier
&& !done
) {
149 WMMaskEvent(dpy
, KeyPressMask
| KeyReleaseMask
| ExposureMask
150 | PointerMotionMask
| ButtonReleaseMask
| EnterWindowMask
, &ev
);
152 /* ignore CapsLock */
153 modifiers
= ev
.xkey
.state
& ValidModMask
;
162 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
163 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
164 || (wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
165 && wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
)
166 || ev
.xkey
.keycode
== rightKey
) {
168 newFocused
= wSwitchPanelSelectNext(swpanel
, False
, ev
.xkey
.keycode
!= rightKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
));
169 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
171 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
172 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
173 || (wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
174 && wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
)
175 || ev
.xkey
.keycode
== leftKey
) {
177 newFocused
= wSwitchPanelSelectNext(swpanel
, True
, ev
.xkey
.keycode
!= leftKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
));
178 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
180 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
182 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
183 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
185 } else if (ev
.xkey
.keycode
== escapeKey
) {
187 /* Focus the first window of the swpanel, despite the 'False' */
188 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
189 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, True
);
193 } else if (ev
.xkey
.keycode
== returnKey
) {
195 /* Close the switchpanel without eating the keypress */
198 } else if (ev
.xkey
.keycode
!= shiftLKey
&& ev
.xkey
.keycode
!= shiftRKey
) {
200 somethingElse
= True
;
207 if (ev
.xkey
.keycode
== shiftLKey
|| ev
.xkey
.keycode
== shiftRKey
)
208 if (wPreferences
.strict_windoze_cycle
)
211 if (ev
.xkey
.keycode
== XK_Return
)
214 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
216 int mask
= 1 << (i
/ keymap
->max_keypermod
);
218 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
219 ((wKeyBindings
[WKBD_FOCUSNEXT
].modifier
& mask
)
220 || (wKeyBindings
[WKBD_FOCUSPREV
].modifier
& mask
)
221 || (wKeyBindings
[WKBD_GROUPNEXT
].modifier
& mask
)
222 || (wKeyBindings
[WKBD_GROUPPREV
].modifier
& mask
))) {
231 /* ignore unwanted EnterNotify's */
240 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
243 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
245 if (ev
.type
== ButtonRelease
)
257 XFreeModifiermap(keymap
);
261 XUngrabKeyboard(dpy
, CurrentTime
);
265 wSwitchPanelDestroy(swpanel
);
267 if (newFocused
&& !esc_cancel
) {
268 wRaiseFrame(newFocused
->frame
->core
);
270 if (!newFocused
->flags
.mapped
)
271 wMakeWindowVisible(newFocused
);
272 wSetFocusTo(scr
, newFocused
);
275 scr
->flags
.doing_alt_tab
= 0;