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