]> icculus.org git repositories - mikachu/openbox.git/blob - scripts/builtins.py
comment the new desktop functions
[mikachu/openbox.git] / scripts / builtins.py
1 ###########################################################################
2 ### Functions that can be used as callbacks for mouse/keyboard bindings ###
3 ###########################################################################
4
5 def close(data):
6     """Closes the window on which the event occured"""
7     client = Openbox_findClient(openbox, data.window())
8     if client: OBClient_close(client)
9
10 def focus(data):
11     """Focuses the window on which the event occured"""
12     client = Openbox_findClient(openbox, data.window())
13     if not client: return
14     type = OBClient_type(client)
15     # !normal windows dont get focus from window enter events
16     if data.action() == EventEnterWindow and not OBClient_normal(client):
17         return
18     OBClient_focus(client)
19
20 def move(data):
21     """Moves the window interactively. This should only be used with
22        MouseMotion events"""
23     client = Openbox_findClient(openbox, data.window())
24     if not client: return
25
26     # !normal windows dont get moved
27     if not OBClient_normal(client): return
28
29     dx = data.xroot() - data.pressx()
30     dy = data.yroot() - data.pressy()
31     OBClient_move(client, data.press_clientx() + dx, data.press_clienty() + dy)
32
33 def resize(data):
34     """Resizes the window interactively. This should only be used with
35        MouseMotion events"""
36     client = Openbox_findClient(openbox, data.window())
37     if not client: return
38
39     # !normal windows dont get moved
40     if not OBClient_normal(client): return
41
42     px = data.pressx()
43     py = data.pressy()
44     dx = data.xroot() - px
45     dy = data.yroot() - py
46
47     # pick a corner to anchor
48     if not (resize_nearest or data.context() == MC_Grip):
49         corner = OBClient_TopLeft
50     else:
51         x = px - data.press_clientx()
52         y = py - data.press_clienty()
53         if y < data.press_clientheight() / 2:
54             if x < data.press_clientwidth() / 2:
55                 corner = OBClient_BottomRight
56                 dx *= -1
57             else:
58                 corner = OBClient_BottomLeft
59             dy *= -1
60         else:
61             if x < data.press_clientwidth() / 2:
62                 corner = OBClient_TopRight
63                 dx *= -1
64             else:
65                 corner = OBClient_TopLeft
66
67     OBClient_resize(client, corner,
68                     data.press_clientwidth() + dx,
69                     data.press_clientheight() + dy);
70
71 def restart(data):
72     """Restarts openbox"""
73     Openbox_restart(openbox, "")
74
75 def raise_win(data):
76     """Raises the window on which the event occured"""
77     client = Openbox_findClient(openbox, data.window())
78     if not client: return
79     screen = Openbox_screen(openbox, OBClient_screen(client))
80     OBScreen_restack(screen, 1, client)
81
82 def lower_win(data):
83     """Lowers the window on which the event occured"""
84     client = Openbox_findClient(openbox, data.window())
85     if not client: return
86     screen = Openbox_screen(openbox, OBClient_screen(client))
87     OBScreen_restack(screen, 0, client)
88
89 def toggle_shade(data):
90     """Toggles the shade status of the window on which the event occured"""
91     client = Openbox_findClient(openbox, data.window())
92     if not client: return
93     print "toggle_shade"
94     OBClient_shade(client, not OBClient_shaded(client))
95
96 def shade(data):
97     """Shades the window on which the event occured"""
98     client = Openbox_findClient(openbox, data.window())
99     if not client: return
100     OBClient_shade(client, 1)
101
102 def unshade(data):
103     """Unshades the window on which the event occured"""
104     client = Openbox_findClient(openbox, data.window())
105     if not client: return
106     OBClient_shade(client, 0)
107
108 def next_desktop(data, no_wrap=0):
109     """Switches to the next desktop, optionally (by default) cycling around to
110        the first when going past the last."""
111     screen = Openbox_screen(openbox, data.screen())
112     d = OBScreen_desktop(screen)
113     n = OBScreen_numDesktops(screen)
114     if (d < (n-1)):
115         d = d + 1
116     elif not no_wrap:
117         d = 0
118     OBScreen_changeDesktop(screen, d)
119     
120 def prev_desktop(data, no_wrap=0):
121     """Switches to the previous desktop, optionally (by default) cycling around
122        to the last when going past the first."""
123     screen = Openbox_screen(openbox, data.screen())
124     d = OBScreen_desktop(screen)
125     n = OBScreen_numDesktops(screen)
126     if (d > 0):
127         d = d - 1
128     elif not no_wrap:
129         d = n - 1
130     OBScreen_changeDesktop(screen, d)
131
132 def change_desktop(data, num):
133     """Switches to a specified desktop"""
134     screen = Openbox_screen(openbox, data.screen())
135     OBScreen_changeDesktop(screen, num)
136     
137 #########################################
138 ### Convenience functions for scripts ###
139 #########################################
140
141 def execute(bin, screen = 0):
142     """Executes a command on the specified screen. It is recommended that you
143        use this call instead of a python system call. If the specified screen
144        is beyond your range of screens, the default is used instead."""
145     Openbox_execute(openbox, screen, bin)
146
147 print "Loaded builtins.py"