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