]> Dogcows Code - chaz/openbox/blob - python/windowplacement.py
merge the C branch into HEAD
[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 x = Random().randrange(sx, sw - cw - 1)
21 y = Random().randrange(sy, sh - ch - 1)
22 client.setArea((x, y, cw, ch))
23
24 def cascade(client):
25 """Place windows in a cascading order from top-left to bottom-right."""
26 if ob.Openbox.state() == ob.State.Starting: return
27 #if data.client.positionRequested(): return
28 cx, cy, cw, ch = client.area()
29 sx, sy, sw, sh = ob.Openbox.screenArea(client.desktop())
30 width = sw - cw
31 height = sh - ch
32 global _cascade_x, _cascade_y
33 if _cascade_x < sx or _cascade_y < sy or \
34 _cascade_x >= width or _cascade_y >= height:
35 _cascade_x = sx
36 _cascade_y = sy
37 client.setArea((_cascade_x, _cascade_y, cw, ch))
38 frame_size = client.frameSize()
39 _cascade_x += frame_size[1]
40 _cascade_y += frame_size[1]
41
42 _cascade_x = 0
43 _cascade_y = 0
44
45 export_functions = random, cascade
46
47 print "Loaded windowplacement.py"
This page took 0.035752 seconds and 4 git commands to generate.