]> Dogcows Code - chaz/openbox/blob - scripts/builtins.py
separate off execute, since its not a callback function
[chaz/openbox] / 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 # these types of windows dont get focus from window enter events
16 if data.action() == EventEnterWindow:
17 print "enter window"
18 if (type == OBClient_Type_Dock or \
19 type == OBClient_Type_Desktop):
20 return
21 OBClient_focus(client)
22
23 def move(data):
24 """Moves the window interactively. This should only be used with
25 MouseMotion events"""
26 client = Openbox_findClient(openbox, data.window())
27 if not 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 px = data.pressx()
40 py = data.pressy()
41 dx = data.xroot() - px
42 dy = data.yroot() - py
43
44 # pick a corner to anchor
45 if not (resize_nearest or data.context() == MC_Grip):
46 corner = OBClient_TopLeft
47 else:
48 x = px - data.press_clientx()
49 y = py - data.press_clienty()
50 if y < data.press_clientheight() / 2:
51 if x < data.press_clientwidth() / 2:
52 corner = OBClient_BottomRight
53 dx *= -1
54 else:
55 corner = OBClient_BottomLeft
56 dy *= -1
57 else:
58 if x < data.press_clientwidth() / 2:
59 corner = OBClient_TopRight
60 dx *= -1
61 else:
62 corner = OBClient_TopLeft
63
64 OBClient_resize(client, corner,
65 data.press_clientwidth() + dx,
66 data.press_clientheight() + dy);
67
68 def restart(data):
69 Openbox_restart(openbox, "")
70
71 def toggle_shade(data):
72 print "toggle_shade"
73
74 def raise_win(data):
75 client = Openbox_findClient(openbox, data.window())
76 if not client: return
77 screen = Openbox_screen(openbox, OBClient_screen(client))
78 OBScreen_restack(screen, 1, client)
79
80 def lower_win(data):
81 client = Openbox_findClient(openbox, data.window())
82 if not client: return
83 screen = Openbox_screen(openbox, OBClient_screen(client))
84 OBScreen_restack(screen, 0, client)
85
86 def toggle_shade(data):
87 client = Openbox_findClient(openbox, data.window())
88 if not client: return
89 print "toggle_shade"
90 OBClient_shade(client, not OBClient_shaded(client))
91
92 def shade(data):
93 client = Openbox_findClient(openbox, data.window())
94 if not client: return
95 OBClient_shade(client, 1)
96
97 def unshade(data):
98 client = Openbox_findClient(openbox, data.window())
99 if not client: return
100 OBClient_shade(client, 0)
101
102 #########################################
103 ### Convenience functions for scripts ###
104 #########################################
105
106 def execute(bin, screen = 0):
107 Openbox_execute(openbox, screen, bin)
108
109 print "Loaded builtins.py"
This page took 0.040557 seconds and 5 git commands to generate.