1 /* cycling.c- window cycling
3 * Window Maker window manager
5 * Copyright (c) 2000 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>
29 #include "WindowMaker.h"
41 extern WPreferences wPreferences
;
43 extern WShortKey wKeyBindings
[WKBD_LAST
];
53 nextToFocusAfter(WWindow
*wwin
)
55 WWindow
*tmp
= wwin
->prev
;
58 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
65 /* start over from the beginning of the list */
69 while (tmp
&& tmp
!= wwin
) {
70 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
81 nextToFocusBefore(WWindow
*wwin
)
83 WWindow
*tmp
= wwin
->next
;
86 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
92 /* start over from the beginning of the list */
97 while (tmp
&& tmp
!= wwin
) {
98 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
110 StartWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
112 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
114 Bool openedSwitchMenu
= False
;
118 XModifierKeymap
*keymap
;
119 Bool somethingElse
= False
;
125 keymap
= XGetModifierMapping(dpy
);
128 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
132 newFocused
= nextToFocusAfter(wwin
);
134 newFocused
= nextToFocusBefore(wwin
);
137 scr
->flags
.doing_alt_tab
= 1;
140 if (wPreferences
.circ_raise
)
141 XRaiseWindow(dpy
, newFocused
->frame
->core
->window
);
142 wWindowFocus(newFocused
, scr
->focused_window
);
143 oldFocused
= newFocused
;
146 if (wPreferences
.popup_switchmenu
&&
147 (!scr
->switch_menu
|| !scr
->switch_menu
->flags
.mapped
)) {
149 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
150 openedSwitchMenu
= True
;
154 WMMaskEvent(dpy
,KeyPressMask
|KeyReleaseMask
|ExposureMask
, &ev
);
156 if (ev
.type
!= KeyRelease
&& ev
.type
!= KeyPress
) {
160 /* ignore CapsLock */
161 modifiers
= ev
.xkey
.state
& ValidModMask
;
163 if (ev
.type
== KeyPress
) {
164 if (wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
165 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
) {
167 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
168 newFocused
= nextToFocusAfter(newFocused
);
169 wWindowFocus(newFocused
, oldFocused
);
170 oldFocused
= newFocused
;
172 if (wPreferences
.circ_raise
) {
175 XRaiseWindow(dpy
, newFocused
->frame
->core
->window
);
178 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
180 } else if (wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
181 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
) {
183 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
184 newFocused
= nextToFocusBefore(newFocused
);
185 wWindowFocus(newFocused
, oldFocused
);
186 oldFocused
= newFocused
;
188 if (wPreferences
.circ_raise
) {
191 XRaiseWindow(dpy
, newFocused
->frame
->core
->window
);
193 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
196 somethingElse
= True
;
199 } else if (ev
.type
== KeyRelease
) {
202 for (i
= 0; i
< 8 * keymap
->max_keypermod
; i
++) {
203 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
204 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
205 & 1<<(i
/keymap
->max_keypermod
)) {
212 XFreeModifiermap(keymap
);
214 XUngrabKeyboard(dpy
, CurrentTime
);
215 wSetFocusTo(scr
, newFocused
);
217 if (wPreferences
.circ_raise
) {
218 wRaiseFrame(newFocused
->frame
->core
);
222 scr
->flags
.doing_alt_tab
= 0;
223 if (openedSwitchMenu
)
224 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
237 nextFocusWindow(WScreen
*scr
)
239 WWindow
*tmp
, *wwin
, *closest
, *min
;
242 if (!(wwin
= scr
->focused_window
))
249 if (wWindowCanReceiveFocus(tmp
)
250 && (!WFLAGP(tmp
, skip_window_list
)|| tmp
->flags
.internal_window
)) {
251 if (min
->client_win
> tmp
->client_win
)
253 if (tmp
->client_win
> wwin
->client_win
255 || (tmp
->client_win
- wwin
->client_win
) < d
)) {
257 d
= tmp
->client_win
- wwin
->client_win
;
262 if (!closest
||closest
==wwin
)
269 prevFocusWindow(WScreen
*scr
)
271 WWindow
*tmp
, *wwin
, *closest
, *max
;
274 if (!(wwin
= scr
->focused_window
))
281 if (wWindowCanReceiveFocus(tmp
) &&
282 (!WFLAGP(tmp
, skip_window_list
) || tmp
->flags
.internal_window
)) {
283 if (max
->client_win
< tmp
->client_win
)
285 if (tmp
->client_win
< wwin
->client_win
287 || (wwin
->client_win
- tmp
->client_win
) < d
)) {
289 d
= wwin
->client_win
- tmp
->client_win
;
294 if (!closest
||closest
==wwin
)
300 void CycleWindow(WScreen
*scr
, Bool forward
)
305 wwin
= nextFocusWindow(scr
);
307 wwin
= prevFocusWindow(scr
);
310 wSetFocusTo(scr
, wwin
);