]> icculus.org git repositories - mikachu/openbox.git/blob - scripts/callbacks.py
add functions to set the skipTaskbar/Pager state
[mikachu/openbox.git] / 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 state_skip_taskbar(data, add=2):
35     """Toggles, adds or removes the 'skip_taskbar' state on a window."""
36     if not data.client: return
37     ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
38                        otk.Property_atoms().net_wm_state, data.client.window(),
39                        add, otk.Property_atoms().net_wm_state_skip_taskbar)
40     
41 def state_skip_pager(data, add=2):
42     """Toggles, adds or removes the 'skip_pager' state on a window."""
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_pager)
47     
48 def iconify(data):
49     """Iconifies the window on which the event occured"""
50     if not data.client: return
51     ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
52                        otk.Property_atoms().wm_change_state,
53                        data.client.window(), 3) # IconicState
54     
55 def restore(data):
56     """Un-iconifies the window on which the event occured, but does not focus
57        if. If you want to focus the window too, it is recommended that you
58        use the activate() function."""
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(), 1) # NormalState
63     
64 def close(data):
65     """Closes the window on which the event occured"""
66     if not data.client: return
67     ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
68                        otk.Property_atoms().net_close_window,
69                        data.client.window(), 0)
70
71 def focus(data):
72     """Focuses the window on which the event occured"""
73     if not data.client: return
74     # !normal windows dont get focus from window enter events
75     if data.action == ob.EventAction.EnterWindow and not data.client.normal():
76         return
77     data.client.focus()
78
79 def restart(data, other = ""):
80     """Restarts openbox, optionally starting another window manager."""
81     ob.openbox.restart(other)
82
83 def raise_win(data):
84     """Raises the window on which the event occured"""
85     if not data.client: return
86     ob.openbox.screen(data.screen).raiseWindow(data.client)
87
88 def lower_win(data):
89     """Lowers the window on which the event occured"""
90     if not data.client: return
91     ob.openbox.screen(data.screen).lowerWindow(data.client)
92
93 def toggle_shade(data):
94     """Toggles the shade status of the window on which the event occured"""
95     state_shaded(data)
96
97 def shade(data):
98     """Shades the window on which the event occured"""
99     state_shaded(data, 1)
100
101 def unshade(data):
102     """Unshades the window on which the event occured"""
103     state_shaded(data, 0)
104
105 def change_desktop(data, num):
106     """Switches to a specified desktop"""
107     root = otk.display.screenInfo(data.screen).rootWindow()
108     ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
109                        root, num)
110
111 def next_desktop(data, no_wrap=0):
112     """Switches to the next desktop, optionally (by default) cycling around to
113        the first when going past the last."""
114     screen = ob.openbox.screen(data.screen)
115     d = screen.desktop()
116     n = screen.numDesktops()
117     if (d < (n-1)):
118         d = d + 1
119     elif not no_wrap:
120         d = 0
121     change_desktop(data, d)
122     
123 def prev_desktop(data, no_wrap=0):
124     """Switches to the previous desktop, optionally (by default) cycling around
125        to the last when going past the first."""
126     screen = ob.openbox.screen(data.screen)
127     d = screen.desktop()
128     n = screen.numDesktops()
129     if (d > 0):
130         d = d - 1
131     elif not no_wrap:
132         d = n - 1
133     change_desktop(data, d)
134
135 def send_to_desktop(data, num):
136     """Sends a client to a specified desktop"""
137     if not data.client: return
138     ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
139                        otk.Property_atoms().net_wm_desktop,
140                        data.client.window(),num)
141
142 def toggle_all_desktops(data):
143     """Toggles between sending a client to all desktops and to the current
144        desktop."""
145     if not data.client: return
146     if not data.client.desktop() == 0xffffffff:
147         send_to_desktop(data, 0xffffffff)
148     else:
149         send_to_desktop(data, openbox.screen(data.screen).desktop())
150     
151 def send_to_all_desktops(data):
152     """Sends a client to all desktops"""
153     if not data.client: return
154     send_to_desktop(data, 0xffffffff)
155     
156 def send_to_next_desktop(data, no_wrap=0, follow=1):
157     """Sends a window to the next desktop, optionally (by default) cycling
158        around to the first when going past the last. Also optionally moving to
159        the new desktop after sending the window."""
160     if not data.client: return
161     screen = ob.openbox.screen(data.screen)
162     d = screen.desktop()
163     n = screen.numDesktops()
164     if (d < (n-1)):
165         d = d + 1
166     elif not no_wrap:
167         d = 0
168     send_to_desktop(data, d)
169     if follow:
170         change_desktop(data, d)
171     
172 def send_to_prev_desktop(data, no_wrap=0, follow=1):
173     """Sends a window to the previous desktop, optionally (by default) cycling
174        around to the last when going past the first. Also optionally moving to
175        the new desktop after sending the window."""
176     if not data.client: return
177     screen = ob.openbox.screen(data.screen)
178     d = screen.desktop()
179     n = screen.numDesktops()
180     if (d > 0):
181         d = d - 1
182     elif not no_wrap:
183         d = n - 1
184     send_to_desktop(data, d)
185     if follow:
186         change_desktop(data, d)
187
188 print "Loaded callbacks.py"