]> Dogcows Code - chaz/openbox/blob - python/windowplacement.py
afeff2ed489da4a2f5a1e7150bc40846afbc2737
[chaz/openbox] / python / windowplacement.py
1 ############################################################################
2 ### Window placement algorithms, choose one of these and ebind it to the ###
3 ### ob.EventAction.PlaceWindow event. ###
4 ### ###
5 ### Also see historyplacement.py for the history placement module which ###
6 ### provides an algorithm that can be used in place of, or alongside, ###
7 ### these. ###
8 ############################################################################
9
10 import ob
11 from random import Random
12
13 def random(client):
14 """Place windows randomly around the screen."""
15 if ob.Openbox.state() == ob.State.Starting: return
16 #if data.client.positionRequested(): return
17 cx, cy, cw, ch = client.area()
18 sx, sy, sw, sh = ob.Openbox.screenArea(client.desktop())
19 global _rand
20 if sw - cw - 1 <= 0: x = 0
21 else: x = Random().randrange(sx, sw - cw - 1)
22 if (sh - ch - 1 <= 0: y = 0
23 else: y = Random().randrange(sy, sh - ch - 1)
24 client.setArea((x, y, cw, ch))
25
26 def cascade(client):
27 """Place windows in a cascading order from top-left to bottom-right."""
28 if ob.Openbox.state() == ob.State.Starting: return
29 #if data.client.positionRequested(): return
30 cx, cy, cw, ch = client.area()
31 sx, sy, sw, sh = ob.Openbox.screenArea(client.desktop())
32 width = sw - cw
33 height = sh - ch
34 global _cascade_x, _cascade_y
35 if _cascade_x < sx or _cascade_y < sy or \
36 _cascade_x >= width or _cascade_y >= height:
37 _cascade_x = sx
38 _cascade_y = sy
39 client.setArea((_cascade_x, _cascade_y, cw, ch))
40 frame_size = client.frameSize()
41 _cascade_x += frame_size[1]
42 _cascade_y += frame_size[1]
43
44 _cascade_x = 0
45 _cascade_y = 0
46
47 export_functions = random, cascade
48
49 print "Loaded windowplacement.py"
This page took 0.036539 seconds and 4 git commands to generate.