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