]>
Dogcows Code - chaz/openbox/blob - scripts/historyplacement.py
8f44030aeb6a95cc693a84da1d970763b8dc9f48
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
###
15 # filename - The name of the file where history data will be stored. The ###
16 ### number of the screen is appended onto this filename. ###
17 filename
= 'historydb' ###
19 ##############################################################################
29 def __init__(self
, appname
, appclass
, role
, x
, y
):
30 self
.appname
= appname
31 self
.appclass
= appclass
35 def __eq__(self
, other
):
36 if self
.appname
== other
.appname
and \
37 self
.appclass
== other
.appclass
and \
38 self
.role
== other
.role
:
43 file = open(os
.environ
['HOME']+'/.openbox/'+filename
+"."+str(data
.screen
),
48 for line
in file.readlines():
49 line
= line
[:-1] # drop the '\n'
51 print string
.split(line
, '\0')
52 print line
.count('\0')
53 s
= string
.split(line
, '\0')
54 state
= _state(s
[0], s
[1], s
[2],
55 string
.atoi(s
[3]), string
.atoi(s
[4]))
57 while len(_data
)-1 < data
.screen
:
59 _data
[data
.screen
].append(state
)
61 print " "+s
[0]+" "+s
[1]+" "+s
[2]
62 print " " + str(s
[3]) + "," + str(s
[4])
73 file = open(os
.environ
['HOME']+'/.openbox/'+filename
+"."+str(data
.screen
),
77 while len(_data
)-1 < data
.screen
:
79 for i
in _data
[data
.screen
]:
80 file.write(i
.appname
+ '\0' +
85 print " "+i
.appname
+" "+i
.appclass
+" "+i
.role
86 print " " + str(i
.x
) + "," + str(i
.y
)
93 state
= _state(data
.client
.appName(), data
.client
.appClass(),
94 data
.client
.role(), 0, 0)
95 while len(_data
)-1 < data
.screen
:
98 print " " + state
.appname
99 print " " + state
.appclass
100 print " " + state
.role
102 i
= _data
[data
.screen
].index(state
)
104 coords
= _data
[data
.screen
][i
]
105 print "Found in history ("+str(coords
.x
)+","+str(coords
.y
)+")"
106 data
.client
.move(coords
.x
, coords
.y
)
108 print "No match in history"
111 def _save_window(data
):
114 area
= data
.client
.area()
115 state
= _state(data
.client
.appName(), data
.client
.appClass(),
116 data
.client
.role(), area
.x(), area
.y())
117 while len(_data
)-1 < data
.screen
:
119 print "looking for :"
120 print " " + state
.appname
121 print " " + state
.appclass
122 print " " + state
.role
124 i
= _data
[data
.screen
].index(state
)
126 _data
[data
.screen
][i
] = state
# replace it
129 _data
[data
.screen
].append(state
)
131 ob
.ebind(ob
.EventAction
.CloseWindow
, _save_window
)
132 ob
.ebind(ob
.EventAction
.Startup
, _load
)
133 ob
.ebind(ob
.EventAction
.Shutdown
, _save
)
135 print "Loaded historyplacement.py"
This page took 0.043318 seconds and 4 git commands to generate.