1 ##############################################################################
2 ### The history window placement algorithm. ebind historyplacement.place ###
3 ### to the ob.EventAction.PlaceWindow event to use it. ###
4 ##############################################################################
6 import windowplacement # fallback routines
8 ##############################################################################
9 ### Options for the historyplacement module: ###
11 # fallback - The window placement algorithm that will be used when history ###
12 ### placement does not have a place for the window. ###
13 fallback = windowplacement.random ###
14 # ignore_requested_positions - When true, the history algorithm will ###
15 ### attempt to place windows even when they ###
16 ### request a position (like XMMS). ###
17 ignore_requested_positions = 0 ###
19 # filename - The name of the file where history data will be stored. The ###
20 ### number of the screen is appended onto this filename. ###
21 filename = 'historydb' ###
23 ##############################################################################
33 def __init__(self, appname, appclass, role, x, y):
34 self.appname = appname
35 self.appclass = appclass
39 def __eq__(self, other):
40 if self.appname == other.appname and \
41 self.appclass == other.appclass and \
42 self.role == other.role:
48 file = open(os.environ['HOME']+'/.openbox/'+filename+"."+str(data.screen),
52 for line in file.readlines():
53 line = line[:-1] # drop the '\n'
55 s = string.split(line, '\0')
56 state = _state(s[0], s[1], s[2],
57 string.atoi(s[3]), string.atoi(s[4]))
59 while len(_data)-1 < data.screen:
61 _data[data.screen].append(state)
71 file = open(os.environ['HOME']+'/.openbox/'+filename+"."+str(data.screen),
74 while len(_data)-1 < data.screen:
76 for i in _data[data.screen]:
77 file.write(i.appname + '\0' +
84 def _create_state(data):
86 area = data.client.area()
87 return _state(data.client.appName(), data.client.appClass(),
88 data.client.role(), area.x(), area.y())
90 def _find(screen, state):
93 return _data[screen].index(state)
97 while len(_data)-1 < screen:
99 return _find(screen, state) # try again
104 if not ignore_requested_positions:
105 if data.client.positionRequested(): return
106 state = _create_state(data)
107 print "looking for : " + state.appname + " : " + state.appclass + \
110 i = _find(data.screen, state)
112 coords = _data[data.screen][i]
113 print "Found in history ("+str(coords.x)+","+str(coords.y)+")"
114 data.client.move(coords.x, coords.y)
116 print "No match in history"
117 if fallback: fallback(data)
119 def _save_window(data):
122 state = _create_state(data)
123 print "looking for : " + state.appname + " : " + state.appclass + \
126 i = _find(data.screen, state)
129 _data[data.screen][i] = state # replace it
132 _data[data.screen].append(state)
134 ob.ebind(ob.EventAction.CloseWindow, _save_window)
135 ob.ebind(ob.EventAction.Startup, _load)
136 ob.ebind(ob.EventAction.Shutdown, _save)
138 print "Loaded historyplacement.py"