allow random placement to override window placements
[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     if not data.client: return
28     if not ignore_requested_positions:
29         if data.client.positionRequested(): return
30     client_area = data.client.area()
31     frame_size = data.client.frame.size()
32     screen_area = ob.openbox.screen(data.screen).area()
33     width = screen_area.width() - (client_area.width() +
34                                    frame_size.left + frame_size.right)
35     height = screen_area.height() - (client_area.height() + 
36                                      frame_size.top + frame_size.bottom)
37     global _rand
38     x = _rand.randrange(screen_area.x(), width-1)
39     y = _rand.randrange(screen_area.y(), height-1)
40     data.client.move(x, y)
41
42 print "Loaded windowplacement.py"