]> icculus.org git repositories - mikachu/openbox.git/blob - scripts/windowplacement.py
add cascade placement
[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 ##############################################################################
11 ### Options for the windowplacement module:                                ###
12 ###                                                                        ###
13 # ignore_requested_positions - When true, the placement algorithm will     ###
14 ###                            attempt to place windows even when they     ###
15 ###                            request a position (like XMMS).             ###
16 ignore_requested_positions = 0                                             ###
17 ###                                                                        ###
18 ##############################################################################
19
20 import otk
21 import ob
22 import random
23
24 _rand = random.Random()
25
26 def random(data):
27     """Place windows randomly around the screen."""
28     if not data.client: return
29     if not ignore_requested_positions:
30         if data.client.positionRequested(): return
31     client_area = data.client.area()
32     frame_size = data.client.frame.size()
33     screen_area = ob.openbox.screen(data.screen).area()
34     width = screen_area.width() - (client_area.width() +
35                                    frame_size.left + frame_size.right)
36     height = screen_area.height() - (client_area.height() + 
37                                      frame_size.top + frame_size.bottom)
38     global _rand
39     x = _rand.randrange(screen_area.x(), width-1)
40     y = _rand.randrange(screen_area.y(), height-1)
41     data.client.move(x, y)
42
43 _cascade_x = 0
44 _cascade_y = 0
45
46 def cascade(data):
47     """Place windows in a cascading order from top-left to bottom-right."""
48     if not data.client: return
49     if not ignore_requested_positions:
50         if data.client.positionRequested(): return
51     client_area = data.client.area()
52     frame_size = data.client.frame.size()
53     screen_area = ob.openbox.screen(data.screen).area()
54     width = screen_area.width() - (client_area.width() +
55                                    frame_size.left + frame_size.right)
56     height = screen_area.height() - (client_area.height() + 
57                                      frame_size.top + frame_size.bottom)
58     global _cascade_x, _cascade_y
59     if _cascade_x < screen_area.x() or _cascade_y < screen_area.y() or \
60            _cascade_x >= width or _cascade_y >= height:
61         _cascade_x = screen_area.x()
62         _cascade_y = screen_area.y()
63     data.client.move(_cascade_x, _cascade_y)
64     _cascade_x += frame_size.top
65     _cascade_y += frame_size.top
66
67 print "Loaded windowplacement.py"