]>
Dogcows Code - chaz/openbox/blob - scripts/historyplacement.py
1 ##############################################################################
2 ### The history window placement algorithm. ebind historyplacement.place ###
3 ### to the ob.EventAction.PlaceWindow event to use it. ###
4 ##############################################################################
6 import windowplacement
, config
9 """Place a window usingthe history placement algorithm."""
12 export_functions
= place
14 ##############################################################################
16 config
.add('historyplacement',
17 'ignore_requested_positions',
18 'Ignore Requested Positions',
19 "When true, the placement algorithm will attempt to place " + \
20 "windows even when they request a position (like XMMS can)." + \
21 "Note this only applies to 'normal' windows, not to special " + \
22 "cases like desktops and docks.",
25 config
.add('historyplacement',
28 "When true, if 2 copies of the same match in history are to be " + \
29 "placed before one of them is closed (so it would be placed " + \
30 "over-top of the last one), this will cause the second window to "+\
31 "not be placed via history, and the 'Fallback Algorithm' will be "+\
35 config
.add('historyplacement',
37 'History Database Filename',
38 "The name of the file where history data will be stored. The " + \
39 "number of the screen is appended onto this name. The file will " +\
40 "be placed in ~/.openbox/.",
43 config
.add('historyplacement',
46 "The window placement algorithm that will be used when history " + \
47 "placement does not have a place for the window.",
49 windowplacement
.random
,
50 options
= windowplacement
.export_functions
)
52 ###########################################################################
54 ###########################################################################
55 ### Internal stuff, should not be accessed outside the module. ###
56 ###########################################################################
66 def __init__(self
, appname
, appclass
, role
, x
, y
):
67 self
.appname
= appname
68 self
.appclass
= appclass
73 def __eq__(self
, other
):
74 if self
.appname
== other
.appname
and \
75 self
.appclass
== other
.appclass
and \
76 self
.role
== other
.role
:
83 file = open(os
.environ
['HOME'] + '/.openbox/' + \
84 config
.get('historyplacement', 'filename') + \
85 "." + str(data
.screen
), 'r')
87 for line
in file.readlines():
88 line
= line
[:-1] # drop the '\n'
90 s
= string
.split(line
, '\0')
91 state
= _state(s
[0], s
[1], s
[2],
92 string
.atoi(s
[3]), string
.atoi(s
[4]))
94 while len(_data
)-1 < data
.screen
:
96 _data
[data
.screen
].append(state
)
98 except ValueError: pass
99 except IndexError: pass
105 file = open(os
.environ
['HOME']+'/.openbox/'+ \
106 config
.get('historyplacement', 'filename') + \
107 "." + str(data
.screen
), 'w')
109 while len(_data
)-1 < data
.screen
:
111 for i
in _data
[data
.screen
]:
112 file.write(i
.appname
+ '\0' +
119 def _create_state(data
):
121 area
= data
.client
.area()
122 return _state(data
.client
.appName(), data
.client
.appClass(),
123 data
.client
.role(), area
.x(), area
.y())
125 def _find(screen
, state
):
128 return _data
[screen
].index(state
)
132 while len(_data
)-1 < screen
:
134 return _find(screen
, state
) # try again
139 if not (config
.get('historyplacement', 'ignore_requested_positions') \
140 and data
.client
.normal()):
141 if data
.client
.positionRequested(): return
142 state
= _create_state(data
)
144 print "looking for : " + state
.appname
+ " : " + \
145 state
.appclass
+ " : " + state
.role
147 i
= _find(data
.screen
, state
)
149 coords
= _data
[data
.screen
][i
]
150 print "Found in history ("+str(coords
.x
)+","+\
152 if not (config
.get('historyplacement', 'dont_duplicate') \
154 data
.client
.move(coords
.x
, coords
.y
)
158 print "Already placed another window there"
160 print "No match in history"
163 fallback
= config
.get('historyplacement', 'fallback')
164 if fallback
: fallback(data
)
166 def _save_window(data
):
169 state
= _create_state(data
)
170 print "looking for : " + state
.appname
+ " : " + state
.appclass
+ \
173 i
= _find(data
.screen
, state
)
176 _data
[data
.screen
][i
] = state
# replace it
179 _data
[data
.screen
].append(state
)
181 ob
.ebind(ob
.EventAction
.CloseWindow
, _save_window
)
182 ob
.ebind(ob
.EventAction
.Startup
, _load
)
183 ob
.ebind(ob
.EventAction
.Shutdown
, _save
)
185 print "Loaded historyplacement.py"
This page took 0.041246 seconds and 4 git commands to generate.