2003-01-26 03:45:24 +00:00
|
|
|
############################################################################
|
|
|
|
### Window placement algorithms, choose one of these and ebind it to the ###
|
|
|
|
### ob.EventAction.PlaceWindow event. ###
|
2003-02-01 10:03:29 +00:00
|
|
|
### ###
|
|
|
|
### Also see historyplacement.py for the history placement module which ###
|
2003-02-01 10:36:34 +00:00
|
|
|
### provides an algorithm that can be used in place of, or alongside, ###
|
2003-02-01 10:03:29 +00:00
|
|
|
### these. ###
|
2003-01-26 03:45:24 +00:00
|
|
|
############################################################################
|
|
|
|
|
2003-02-19 19:28:11 +00:00
|
|
|
import otk, ob, random
|
2003-01-26 03:45:24 +00:00
|
|
|
|
|
|
|
_rand = random.Random()
|
|
|
|
|
|
|
|
def random(data):
|
2003-02-01 11:54:38 +00:00
|
|
|
"""Place windows randomly around the screen."""
|
2003-01-26 03:45:24 +00:00
|
|
|
if not data.client: return
|
2003-02-02 22:27:51 +00:00
|
|
|
if data.client.positionRequested(): return
|
2003-02-12 00:39:15 +00:00
|
|
|
client_area = data.client.frame.area()
|
2003-02-10 06:50:19 +00:00
|
|
|
screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
|
2003-02-12 00:40:25 +00:00
|
|
|
width = screen_area.width() - client_area.width()
|
|
|
|
height = screen_area.height() - client_area.height()
|
2003-01-26 03:45:24 +00:00
|
|
|
global _rand
|
|
|
|
x = _rand.randrange(screen_area.x(), width-1)
|
|
|
|
y = _rand.randrange(screen_area.y(), height-1)
|
|
|
|
data.client.move(x, y)
|
|
|
|
|
2003-02-01 11:54:38 +00:00
|
|
|
_cascade_x = 0
|
|
|
|
_cascade_y = 0
|
|
|
|
|
|
|
|
def cascade(data):
|
|
|
|
"""Place windows in a cascading order from top-left to bottom-right."""
|
|
|
|
if not data.client: return
|
2003-02-02 22:27:51 +00:00
|
|
|
if data.client.positionRequested(): return
|
2003-02-12 00:39:15 +00:00
|
|
|
client_area = data.client.frame.area()
|
2003-02-10 06:50:19 +00:00
|
|
|
screen_area = ob.openbox.screen(data.screen).area(data.client.desktop())
|
2003-02-12 00:40:25 +00:00
|
|
|
width = screen_area.width() - client_area.width()
|
|
|
|
height = screen_area.height() - client_area.height()
|
2003-02-01 11:54:38 +00:00
|
|
|
global _cascade_x, _cascade_y
|
|
|
|
if _cascade_x < screen_area.x() or _cascade_y < screen_area.y() or \
|
|
|
|
_cascade_x >= width or _cascade_y >= height:
|
|
|
|
_cascade_x = screen_area.x()
|
|
|
|
_cascade_y = screen_area.y()
|
|
|
|
data.client.move(_cascade_x, _cascade_y)
|
2003-02-12 00:40:25 +00:00
|
|
|
frame_size = data.client.frame.size()
|
2003-02-01 11:54:38 +00:00
|
|
|
_cascade_x += frame_size.top
|
|
|
|
_cascade_y += frame_size.top
|
|
|
|
|
2003-02-19 19:28:11 +00:00
|
|
|
export_functions = random, cascade
|
|
|
|
|
2003-01-26 03:45:24 +00:00
|
|
|
print "Loaded windowplacement.py"
|