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 static void raiseWindow(WSwitchPanel
* swpanel
, WWindow
* wwin
)
44 Window swwin
= wSwitchPanelGetWindow(swpanel
);
46 if (wwin
->flags
.mapped
) {
51 win
[1] = wwin
->frame
->core
->window
;
53 XRestackWindows(dpy
, win
, 2);
55 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
59 static WWindow
*change_focus_and_raise(WWindow
*newFocused
, WWindow
*oldFocused
,
60 WSwitchPanel
*swpanel
, WScreen
*scr
, Bool esc_cancel
)
65 wWindowFocus(newFocused
, oldFocused
);
66 oldFocused
= newFocused
;
68 if (wPreferences
.circ_raise
) {
72 raiseWindow(swpanel
, newFocused
);
78 void StartWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
, Bool class_only
)
82 WSwitchPanel
*swpanel
= NULL
;
83 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
84 KeyCode leftKey
= XKeysymToKeycode(dpy
, XK_Left
);
85 KeyCode rightKey
= XKeysymToKeycode(dpy
, XK_Right
);
86 KeyCode homeKey
= XKeysymToKeycode(dpy
, XK_Home
);
87 KeyCode endKey
= XKeysymToKeycode(dpy
, XK_End
);
88 KeyCode shiftLKey
= XKeysymToKeycode(dpy
, XK_Shift_L
);
89 KeyCode shiftRKey
= XKeysymToKeycode(dpy
, XK_Shift_R
);
90 KeyCode escapeKey
= XKeysymToKeycode(dpy
, XK_Escape
);
91 KeyCode returnKey
= XKeysymToKeycode(dpy
, XK_Return
);
92 Bool esc_cancel
= False
;
93 Bool somethingElse
= False
;
107 binding
= wKeyBindings
[WKBD_GROUPNEXT
];
109 binding
= wKeyBindings
[WKBD_FOCUSNEXT
];
112 binding
= wKeyBindings
[WKBD_GROUPPREV
];
114 binding
= wKeyBindings
[WKBD_FOCUSPREV
];
117 hasModifier
= (binding
.modifier
!= 0);
119 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
121 scr
->flags
.doing_alt_tab
= 1;
123 swpanel
= wInitSwitchPanel(scr
, wwin
, class_only
);
127 if (wwin
->flags
.mapped
&& !wPreferences
.panel_only_open
)
128 newFocused
= wSwitchPanelSelectNext(swpanel
, !next
, True
, False
);
130 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
132 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
134 if (wwin
->frame
->workspace
== w_global
.workspace
.current
)
140 while (hasModifier
&& !done
) {
141 WMMaskEvent(dpy
, KeyPressMask
| KeyReleaseMask
| ExposureMask
142 | PointerMotionMask
| ButtonReleaseMask
| EnterWindowMask
, &ev
);
144 /* ignore CapsLock */
145 modifiers
= ev
.xkey
.state
& w_global
.shortcut
.modifiers_mask
;
152 if ((wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
153 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
)
154 || (wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
155 && wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
)
156 || ev
.xkey
.keycode
== rightKey
) {
158 newFocused
= wSwitchPanelSelectNext(swpanel
, False
, ev
.xkey
.keycode
!= rightKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPNEXT
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPNEXT
].modifier
== modifiers
));
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 || (wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
164 && wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
)
165 || ev
.xkey
.keycode
== leftKey
) {
167 newFocused
= wSwitchPanelSelectNext(swpanel
, True
, ev
.xkey
.keycode
!= leftKey
, (!class_only
&& wKeyBindings
[WKBD_GROUPPREV
].keycode
== ev
.xkey
.keycode
&& wKeyBindings
[WKBD_GROUPPREV
].modifier
== modifiers
));
168 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
170 } else if (ev
.xkey
.keycode
== homeKey
|| ev
.xkey
.keycode
== endKey
) {
172 newFocused
= wSwitchPanelSelectFirst(swpanel
, ev
.xkey
.keycode
!= homeKey
);
173 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
175 } else if (ev
.xkey
.keycode
== escapeKey
) {
177 /* Focus the first window of the swpanel, despite the 'False' */
178 newFocused
= wSwitchPanelSelectFirst(swpanel
, False
);
179 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, True
);
183 } else if (ev
.xkey
.keycode
== returnKey
) {
185 /* Close the switchpanel without eating the keypress */
188 } else if (ev
.xkey
.keycode
!= shiftLKey
&& ev
.xkey
.keycode
!= shiftRKey
) {
190 somethingElse
= True
;
196 if (ev
.xkey
.keycode
== shiftLKey
|| ev
.xkey
.keycode
== shiftRKey
)
197 if (wPreferences
.strict_windoze_cycle
)
200 if (ev
.xkey
.keycode
== XK_Return
)
203 if (ev
.xkey
.keycode
!= binding
.keycode
)
210 /* ignore unwanted EnterNotify's */
219 tmp
= wSwitchPanelHandleEvent(swpanel
, &ev
);
222 oldFocused
= change_focus_and_raise(newFocused
, oldFocused
, swpanel
, scr
, False
);
224 if (ev
.type
== ButtonRelease
)
237 XUngrabKeyboard(dpy
, CurrentTime
);
240 wSwitchPanelDestroy(swpanel
);
242 if (newFocused
&& !esc_cancel
) {
243 wRaiseFrame(newFocused
->frame
->core
);
245 if (!newFocused
->flags
.mapped
)
246 wMakeWindowVisible(newFocused
);
247 wSetFocusTo(scr
, newFocused
);
250 scr
->flags
.doing_alt_tab
= 0;