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 #include "WindowMaker.h"
40 #include "switchpanel.h"
43 extern WPreferences wPreferences
;
45 extern WShortKey wKeyBindings
[WKBD_LAST
];
47 static void raiseWindow(WSwitchPanel
* swpanel
, WWindow
* wwin
)
49 Window swwin
= wSwitchPanelGetWindow(swpanel
);
51 if (wwin
->flags
.mapped
) {
56 win
[1] = wwin
->frame
->core
->window
;
58 XRestackWindows(dpy
, win
, 2);
60 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
64 static WWindow
*change_focus_and_raise(WWindow
*newFocused
, WWindow
*oldFocused
,
65 WSwitchPanel
*swpanel
, WScreen
*scr
, Bool esc_cancel
)
70 wWindowFocus(newFocused
, oldFocused
);
71 oldFocused
= newFocused
;
73 if (wPreferences
.circ_raise
) {
77 raiseWindow(swpanel
, newFocused
);
83 void StartWindozeCycle(WWindow
* wwin
, XEvent
* event
, Bool next
)
86 XModifierKeymap
*keymap
= NULL
;
87 WSwitchPanel
*swpanel
= NULL
;
88 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
89 KeyCode leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
90 KeyCode rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
91 KeyCode homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
92 KeyCode endKey
= XKeysymToKeycode(dpy
, XK_End
);
93 KeyCode shiftLKey
= XKeysymToKeycode(dpy
, XK_Shift_L
);
94 KeyCode shiftRKey
= XKeysymToKeycode(dpy
, XK_Shift_R
);
95 KeyCode escapeKey
= XKeysymToKeycode(dpy
, XK_Escape
);
96 Bool esc_cancel
= False
;
97 Bool somethingElse
= False
;
110 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
112 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
115 keymap
= XGetModifierMapping(dpy
);
118 printf("Grabbing keyboard\n");
120 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
123 scr
->flags
.doing_alt_tab
= 1;
125 swpanel
= wInitSwitchPanel(scr
, wwin
, scr
->current_workspace
);
129 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
);
130 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
132 if (wwin
->frame
->workspace
== scr
->current_workspace
)
138 while (hasModifier
&& !done
) {
141 WMMaskEvent(dpy
, KeyPressMask
| KeyReleaseMask
| ExposureMask
142 | PointerMotionMask
| ButtonReleaseMask
| EnterWindowMask
, &ev
);
144 /* ignore CapsLock */
145 modifiers
= ev
.xkey
.state
& ValidModMask
;
154 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
155 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
156 || ev
.xkey
.keycode
== rightKey
) {
158 newFocused
= wSwitchPanelSelectNext(swpanel
, False
);
159 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
161 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
162 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
163 || ev
.xkey
.keycode
== leftKey
) {
165 newFocused
= wSwitchPanelSelectNext(swpanel
, True
);
166 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
168 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
170 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
171 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
173 } else if (ev
.xkey
.keycode
== escapeKey
) {
175 /* Focus the first window of the swpanel, despite the 'False' */
176 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
177 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, True
);
181 } else if (ev
.xkey
.keycode
!= shiftLKey
&& ev
.xkey
.keycode
!= shiftRKey
) {
183 somethingElse
= True
;
190 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
192 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
193 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
& 1 << (i
/ keymap
->max_keypermod
)) {
202 /* ignore unwanted EnterNotify's */
210 newFocused
= wSwitchPanelHandleEvent(swpanel
, &ev
);
211 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
213 if (ev
.type
== ButtonRelease
)
223 XFreeModifiermap(keymap
);
227 XUngrabKeyboard(dpy
, CurrentTime
);
231 wSwitchPanelDestroy(swpanel
);
233 if (newFocused
&& !esc_cancel
) {
234 wRaiseFrame(newFocused
->frame
->core
);
236 if (!newFocused
->flags
.mapped
)
237 wMakeWindowVisible(newFocused
);
238 wSetFocusTo(scr
, newFocused
);
241 scr
->flags
.doing_alt_tab
= 0;