]> icculus.org git repositories - mikachu/openbox.git/blob - scripts/windowplacement.py
all events are dispatched
[mikachu/openbox.git] / scripts / 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 otk, ob, random
11
12 _rand = random.Random()
13
14 def random(data):
15     """Place windows randomly around the screen."""
16     if not data.client: return
17     if data.client.positionRequested(): return
18     client_area = data.client.frame.area()
19     screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
20     width = screen_area.width() - client_area.width()
21     height = screen_area.height() - client_area.height()
22     global _rand
23     x = _rand.randrange(screen_area.x(), width-1)
24     y = _rand.randrange(screen_area.y(), height-1)
25     data.client.move(x, y)
26
27 _cascade_x = 0
28 _cascade_y = 0
29
30 def cascade(data):
31     """Place windows in a cascading order from top-left to bottom-right."""
32     if not data.client: return
33     if data.client.positionRequested(): return
34     client_area = data.client.frame.area()
35     screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
36     width = screen_area.width() - client_area.width()
37     height = screen_area.height() - client_area.height()
38     global _cascade_x, _cascade_y
39     if _cascade_x < screen_area.x() or _cascade_y < screen_area.y() or \
40            _cascade_x >= width or _cascade_y >= height:
41         _cascade_x = screen_area.x()
42         _cascade_y = screen_area.y()
43     data.client.move(_cascade_x, _cascade_y)
44     frame_size = data.client.frame.size()
45     _cascade_x += frame_size.top
46     _cascade_y += frame_size.top
47
48 export_functions = random, cascade
49
50 print "Loaded windowplacement.py"