]> Dogcows Code - chaz/openbox/blob - scripts/windowplacement.py
add otk::MessageDialog
[chaz/openbox] / 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.frame.area()
27 screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
28 width = screen_area.width() - client_area.width()
29 height = screen_area.height() - client_area.height()
30 global _rand
31 x = _rand.randrange(screen_area.x(), width-1)
32 y = _rand.randrange(screen_area.y(), height-1)
33 data.client.move(x, y)
34
35 _cascade_x = 0
36 _cascade_y = 0
37
38 def cascade(data):
39 """Place windows in a cascading order from top-left to bottom-right."""
40 if not data.client: return
41 if data.client.positionRequested(): return
42 client_area = data.client.frame.area()
43 screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
44 width = screen_area.width() - client_area.width()
45 height = screen_area.height() - client_area.height()
46 global _cascade_x, _cascade_y
47 if _cascade_x < screen_area.x() or _cascade_y < screen_area.y() or \
48 _cascade_x >= width or _cascade_y >= height:
49 _cascade_x = screen_area.x()
50 _cascade_y = screen_area.y()
51 data.client.move(_cascade_x, _cascade_y)
52 frame_size = data.client.frame.size()
53 _cascade_x += frame_size.top
54 _cascade_y += frame_size.top
55
56 print "Loaded windowplacement.py"
This page took 0.033802 seconds and 4 git commands to generate.