]> Dogcows Code - chaz/openbox/blob - scripts/focuscycle.py
highlight the popup
[chaz/openbox] / scripts / focuscycle.py
1 ###########################################################################
2 ### Functions for cycling focus (in a 'linear' order) between windows. ###
3 ###########################################################################
4
5 ###########################################################################
6 ### Options that affect the behavior of the focuscycle module. ###
7 ###########################################################################
8 RAISE_WINDOW = 1
9 """When cycling focus, raise the window chosen as well as focusing it. This
10 does not affect fallback focusing behavior."""
11 # See focus.AVOID_SKIP_TASKBAR
12 ###########################################################################
13
14 def next(data, num=1):
15 """Focus the next window."""
16 _cycle(data, num, 1)
17
18 def previous(data, num=1):
19 """Focus the previous window."""
20 _cycle(data, num, 0)
21
22 ###########################################################################
23 ###########################################################################
24
25 ###########################################################################
26 ### Internal stuff, should not be accessed outside the module. ###
27 ###########################################################################
28
29 import ob
30 import focus
31
32 def _cycle(data, num, forward):
33 screen = ob.openbox.screen(data.screen)
34 count = screen.clientCount()
35
36 if not count: return # no clients
37
38 target = 0
39 if data.client:
40 client_win = data.client.window()
41 found = 0
42 r = range(count)
43 if not forward:
44 r.reverse()
45 for i in r:
46 if found:
47 target = i
48 found = 2
49 break
50 elif screen.client(i).window() == client_win:
51 found = 1
52 if found == 1: # wraparound
53 if forward: target = 0
54 else: target = count - 1
55
56 t = target
57 desktop = screen.desktop()
58 while 1:
59 client = screen.client(t)
60 if client and focus._focusable(client, desktop) and client.focus():
61 if RAISE_WINDOW:
62 screen.raiseWindow(client)
63 return
64 if forward:
65 t += num
66 if t >= count: t -= count
67 else:
68 t -= num
69 if t < 0: t += count
70 if t == target: return # nothing to focus
71
72 print "Loaded focuscycle.py"
This page took 0.042931 seconds and 4 git commands to generate.