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