]> Dogcows Code - chaz/openbox/blob - scripts/callbacks.py
4d5092680d3cc2baa98395f7ecc5d483c014c6fc
[chaz/openbox] / scripts / callbacks.py
1 ############################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ############################################################################
4
5 #############################################################################
6 ### Options that can be modified to change the default hooks' behaviors. ###
7 ### ###
8 #############################################################################
9
10 import ob
11 import otk
12
13 def state_above(data, add=2):
14 """Toggles, adds or removes the 'above' state on a window."""
15 if not data.client: return
16 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
17 otk.Property_atoms().net_wm_state, data.client.window(),
18 add, otk.Property_atoms().net_wm_state_above)
19
20 def state_below(data, add=2):
21 """Toggles, adds or removes the 'below' state on a window."""
22 if not data.client: return
23 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
24 otk.Property_atoms().net_wm_state, data.client.window(),
25 add, otk.Property_atoms().net_wm_state_below)
26
27 def state_shaded(data, add=2):
28 """Toggles, adds or removes the 'shaded' state on a window."""
29 if not data.client: return
30 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
31 otk.Property_atoms().net_wm_state, data.client.window(),
32 add, otk.Property_atoms().net_wm_state_shaded)
33
34 def iconify(data):
35 """Iconifies the window on which the event occured"""
36 if not data.client: return
37 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
38 otk.Property_atoms().wm_change_state,
39 data.client.window(), 3) # IconicState
40
41 def restore(data):
42 """Un-iconifies the window on which the event occured, but does not focus
43 if. If you want to focus the window too, it is recommended that you
44 use the activate() function."""
45 if not data.client: return
46 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
47 otk.Property_atoms().wm_change_state,
48 data.client.window(), 1) # NormalState
49
50 def close(data):
51 """Closes the window on which the event occured"""
52 if not data.client: return
53 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
54 otk.Property_atoms().net_close_window,
55 data.client.window(), 0)
56
57 def focus(data):
58 """Focuses the window on which the event occured"""
59 if not data.client: return
60 # !normal windows dont get focus from window enter events
61 if data.action == ob.EventAction.EnterWindow and not data.client.normal():
62 return
63 data.client.focus()
64
65 def restart(data, other = ""):
66 """Restarts openbox, optionally starting another window manager."""
67 ob.openbox.restart(other)
68
69 def raise_win(data):
70 """Raises the window on which the event occured"""
71 if not data.client: return
72 ob.openbox.screen(data.screen).raiseWindow(data.client)
73
74 def lower_win(data):
75 """Lowers the window on which the event occured"""
76 if not data.client: return
77 ob.openbox.screen(data.screen).lowerWindow(data.client)
78
79 def toggle_shade(data):
80 """Toggles the shade status of the window on which the event occured"""
81 state_shaded(data)
82
83 def shade(data):
84 """Shades the window on which the event occured"""
85 state_shaded(data, 1)
86
87 def unshade(data):
88 """Unshades the window on which the event occured"""
89 state_shaded(data, 0)
90
91 def change_desktop(data, num):
92 """Switches to a specified desktop"""
93 root = otk.display.screenInfo(data.screen).rootWindow()
94 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
95 root, num)
96
97 def next_desktop(data, no_wrap=0):
98 """Switches to the next desktop, optionally (by default) cycling around to
99 the first when going past the last."""
100 screen = ob.openbox.screen(data.screen)
101 d = screen.desktop()
102 n = screen.numDesktops()
103 if (d < (n-1)):
104 d = d + 1
105 elif not no_wrap:
106 d = 0
107 change_desktop(data, d)
108
109 def prev_desktop(data, no_wrap=0):
110 """Switches to the previous desktop, optionally (by default) cycling around
111 to the last when going past the first."""
112 screen = ob.openbox.screen(data.screen)
113 d = screen.desktop()
114 n = screen.numDesktops()
115 if (d > 0):
116 d = d - 1
117 elif not no_wrap:
118 d = n - 1
119 change_desktop(data, d)
120
121 def send_to_desktop(data, num):
122 """Sends a client to a specified desktop"""
123 if not data.client: return
124 ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
125 otk.Property_atoms().net_wm_desktop,
126 data.client.window(),num)
127
128 def toggle_all_desktops(data):
129 """Toggles between sending a client to all desktops and to the current
130 desktop."""
131 if not data.client: return
132 if not data.client.desktop() == 0xffffffff:
133 send_to_desktop(data, 0xffffffff)
134 else:
135 send_to_desktop(data, openbox.screen(data.screen).desktop())
136
137 def send_to_all_desktops(data):
138 """Sends a client to all desktops"""
139 if not data.client: return
140 send_to_desktop(data, 0xffffffff)
141
142 def send_to_next_desktop(data, no_wrap=0, follow=1):
143 """Sends a window to the next desktop, optionally (by default) cycling
144 around to the first when going past the last. Also optionally moving to
145 the new desktop after sending the window."""
146 if not data.client: return
147 screen = ob.openbox.screen(data.screen)
148 d = screen.desktop()
149 n = screen.numDesktops()
150 if (d < (n-1)):
151 d = d + 1
152 elif not no_wrap:
153 d = 0
154 send_to_desktop(data, d)
155 if follow:
156 change_desktop(data, d)
157
158 def send_to_prev_desktop(data, no_wrap=0, follow=1):
159 """Sends a window to the previous desktop, optionally (by default) cycling
160 around to the last when going past the first. Also optionally moving to
161 the new desktop after sending the window."""
162 if not data.client: return
163 screen = ob.openbox.screen(data.screen)
164 d = screen.desktop()
165 n = screen.numDesktops()
166 if (d > 0):
167 d = d - 1
168 elif not no_wrap:
169 d = n - 1
170 send_to_desktop(data, d)
171 if follow:
172 change_desktop(data, d)
173
174 print "Loaded callbacks.py"
This page took 0.047605 seconds and 3 git commands to generate.