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 void StartWindozeCycle(WWindow
* wwin
, XEvent
* event
, Bool next
)
66 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
71 XModifierKeymap
*keymap
= NULL
;
73 Bool somethingElse
= False
;
75 WSwitchPanel
*swpanel
= NULL
;
76 KeyCode leftKey
, rightKey
, homeKey
, endKey
, shiftLKey
, shiftRKey
;
81 leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
82 rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
83 homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
84 endKey
= XKeysymToKeycode(dpy
, XK_End
);
85 shiftLKey
= XKeysymToKeycode(dpy
, XK_Shift_L
);
86 shiftRKey
= XKeysymToKeycode(dpy
, XK_Shift_R
);
89 hasModifier
= (wKeyBindings
[WKBD_FOCUSNEXT
].modifier
!= 0);
91 hasModifier
= (wKeyBindings
[WKBD_FOCUSPREV
].modifier
!= 0);
94 keymap
= XGetModifierMapping(dpy
);
97 printf("Grabbing keyboard\n");
99 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
102 scr
->flags
.doing_alt_tab
= 1;
104 swpanel
= wInitSwitchPanel(scr
, wwin
, scr
->current_workspace
);
108 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
);
110 wWindowFocus(newFocused
, oldFocused
);
111 oldFocused
= newFocused
;
113 if (wPreferences
.circ_raise
)
114 raiseWindow(swpanel
, newFocused
);
117 if (wwin
->frame
->workspace
== scr
->current_workspace
)
123 while (hasModifier
&& !done
) {
126 WMMaskEvent(dpy
, KeyPressMask
| KeyReleaseMask
| ExposureMask
127 | PointerMotionMask
| ButtonReleaseMask
, &ev
);
129 /* ignore CapsLock */
130 modifiers
= ev
.xkey
.state
& ValidModMask
;
135 printf("Got key press\n");
137 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
138 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
139 || ev
.xkey
.keycode
== rightKey
) {
142 newFocused
= wSwitchPanelSelectNext(swpanel
, False
);
144 wWindowFocus(newFocused
, oldFocused
);
145 oldFocused
= newFocused
;
147 if (wPreferences
.circ_raise
) {
149 raiseWindow(swpanel
, newFocused
);
153 } else if ((wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
154 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
)
155 || ev
.xkey
.keycode
== leftKey
) {
158 newFocused
= wSwitchPanelSelectNext(swpanel
, True
);
160 wWindowFocus(newFocused
, oldFocused
);
161 oldFocused
= newFocused
;
163 if (wPreferences
.circ_raise
) {
165 raiseWindow(swpanel
, newFocused
);
169 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
171 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
173 wWindowFocus(newFocused
, oldFocused
);
174 oldFocused
= newFocused
;
176 if (wPreferences
.circ_raise
) {
178 raiseWindow(swpanel
, newFocused
);
182 } else if (ev
.xkey
.keycode
!= shiftLKey
&& ev
.xkey
.keycode
!= shiftRKey
) {
184 printf("Got something else\n");
186 somethingElse
= True
;
192 printf("Got key release\n");
194 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
195 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
196 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
& 1 << (i
/ keymap
->max_keypermod
)) {
209 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
212 wWindowFocus(newFocused
, oldFocused
);
213 oldFocused
= newFocused
;
215 if (wPreferences
.circ_raise
) {
217 raiseWindow(swpanel
, newFocused
);
220 if (ev
.type
== ButtonRelease
)
233 XFreeModifiermap(keymap
);
237 printf("Ungrabbing keyboard\n");
239 XUngrabKeyboard(dpy
, CurrentTime
);
243 wSwitchPanelDestroy(swpanel
);
246 wRaiseFrame(newFocused
->frame
->core
);
248 if (!newFocused
->flags
.mapped
)
249 wMakeWindowVisible(newFocused
);
250 wSetFocusTo(scr
, newFocused
);
253 scr
->flags
.doing_alt_tab
= 0;