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
];
48 static void raiseWindow(WSwitchPanel
*swpanel
, WWindow
*wwin
)
50 if (wwin
->flags
.mapped
) {
53 win
[0]= wSwitchPanelGetWindow(swpanel
);
54 win
[1]= wwin
->frame
->core
->window
;
56 XRestackWindows(dpy
, win
, 2);
63 StartWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
65 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
70 XModifierKeymap
*keymap
= NULL
;
72 Bool somethingElse
= False
;
74 WSwitchPanel
*swpanel
= NULL
;
75 KeyCode leftKey
, rightKey
, homeKey
, endKey
;
80 leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
81 rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
82 homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
83 endKey
= XKeysymToKeycode(dpy
, XK_End
);
86 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
88 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
91 keymap
= XGetModifierMapping(dpy
);
94 printf("Grabbing keyboard\n");
96 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
100 scr
->flags
.doing_alt_tab
= 1;
102 swpanel
= wInitSwitchPanel(scr
, wwin
, scr
->current_workspace
);
106 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
);
108 wWindowFocus(newFocused
, oldFocused
);
109 oldFocused
= newFocused
;
111 if (wPreferences
.circ_raise
)
112 raiseWindow(swpanel
, newFocused
);
117 if (wwin
->frame
->workspace
== scr
->current_workspace
)
123 while (hasModifier
&& !done
) {
126 WMMaskEvent(dpy
, KeyPressMask
|KeyReleaseMask
|ExposureMask
127 |PointerMotionMask
|EnterWindowMask
|LeaveWindowMask
128 |ButtonReleaseMask
, &ev
);
130 /* ignore CapsLock */
131 modifiers
= ev
.xkey
.state
& ValidModMask
;
136 printf("Got key press\n");
138 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
139 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
140 || ev
.xkey
.keycode
== rightKey
) {
143 newFocused
= wSwitchPanelSelectNext(swpanel
, False
);
145 wWindowFocus(newFocused
, oldFocused
);
146 oldFocused
= newFocused
;
148 if (wPreferences
.circ_raise
) {
150 raiseWindow(swpanel
, newFocused
);
154 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
155 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
156 || ev
.xkey
.keycode
== leftKey
) {
159 newFocused
= wSwitchPanelSelectNext(swpanel
, True
);
161 wWindowFocus(newFocused
, oldFocused
);
162 oldFocused
= newFocused
;
164 if (wPreferences
.circ_raise
) {
166 raiseWindow(swpanel
, newFocused
);
170 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
172 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
174 wWindowFocus(newFocused
, oldFocused
);
175 oldFocused
= newFocused
;
177 if (wPreferences
.circ_raise
) {
179 raiseWindow(swpanel
, newFocused
);
185 printf("Got something else\n");
187 somethingElse
= True
;
193 printf("Got key release\n");
195 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
196 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
197 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
198 & 1<<(i
/keymap
->max_keypermod
)) {
211 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
214 wWindowFocus(newFocused
, oldFocused
);
215 oldFocused
= newFocused
;
217 if (wPreferences
.circ_raise
) {
219 raiseWindow(swpanel
, newFocused
);
222 if (ev
.type
== ButtonRelease
)
235 XFreeModifiermap(keymap
);
239 printf("Ungrabbing keyboard\n");
241 XUngrabKeyboard(dpy
, CurrentTime
);
245 wRaiseFrame(newFocused
->frame
->core
);
247 if (!newFocused
->flags
.mapped
)
248 wMakeWindowVisible(newFocused
);
249 wSetFocusTo(scr
, newFocused
);
253 wSwitchPanelDestroy(swpanel
);
255 scr
->flags
.doing_alt_tab
= 0;