Merge remote-tracking branch 'blueyed/remember-layout-across-restarts'

This commit is contained in:
Uli Schlachter 2014-04-21 11:35:16 +02:00
commit b6816aec2a
1 changed files with 36 additions and 0 deletions

View File

@ -18,6 +18,7 @@ local capi =
client = client, client = client,
mouse = mouse, mouse = mouse,
screen = screen, screen = screen,
awesome = awesome,
} }
-- we use require("awful.screen") inside functions to prevent circular dependencies. -- we use require("awful.screen") inside functions to prevent circular dependencies.
@ -34,6 +35,8 @@ client.data.focus = {}
client.data.urgent = {} client.data.urgent = {}
client.data.marked = {} client.data.marked = {}
client.data.properties = setmetatable({}, { __mode = 'k' }) client.data.properties = setmetatable({}, { __mode = 'k' })
client.data.persistent_properties_registered = {} -- keys are names of persistent properties, value always true
client.data.persistent_properties_loaded = setmetatable({}, { __mode = 'k' }) -- keys are clients, value always true
-- Functions -- Functions
client.urgent = {} client.urgent = {}
@ -869,6 +872,15 @@ end
-- @param prop The property name. -- @param prop The property name.
-- @return The property. -- @return The property.
function client.property.get(c, prop) function client.property.get(c, prop)
if not client.data.persistent_properties_loaded[c] then
client.data.persistent_properties_loaded[c] = true
for p in pairs(client.data.persistent_properties_registered) do
local value = c:get_xproperty("awful.client.property." .. prop)
if value ~= nil then
client.property.set(c, p, value)
end
end
end
if client.data.properties[c] then if client.data.properties[c] then
return client.data.properties[c][prop] return client.data.properties[c][prop]
end end
@ -883,10 +895,31 @@ function client.property.set(c, prop, value)
if not client.data.properties[c] then if not client.data.properties[c] then
client.data.properties[c] = {} client.data.properties[c] = {}
end end
if client.data.persistent_properties_registered[prop] then
c:set_xproperty("awful.client.property." .. prop, value)
end
client.data.properties[c][prop] = value client.data.properties[c][prop] = value
c:emit_signal("property::" .. prop) c:emit_signal("property::" .. prop)
end end
--- Set a client property to be persistent across restarts (via X properties).
-- @param c The client.
-- @param prop The property name.
-- @param type The type (used for register_xproperty).
-- One of "string", "number" or "boolean".
function client.property.persist(c, prop, type)
local xprop = "awful.client.property." .. prop
capi.awesome.register_xproperty(xprop, type)
client.data.persistent_properties_registered[prop] = true
-- Make already-set properties persistent
for c, tab in pairs(client.data.properties) do
if client.data.properties[c] and client.data.properties[c][prop] ~= nil then
c:set_xproperty(xprop, client.data.properties[c][prop])
end
end
end
--- ---
-- Returns an iterator to cycle through, starting from the client in focus or -- Returns an iterator to cycle through, starting from the client in focus or
-- the given index, all clients that match a given criteria. -- the given index, all clients that match a given criteria.
@ -961,6 +994,9 @@ capi.client.connect_signal("unmanage", client.urgent.delete)
capi.client.connect_signal("unmanage", client.floating.delete) capi.client.connect_signal("unmanage", client.floating.delete)
-- Register persistent properties
client.property.persist(c, "floating", "boolean")
return client return client
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80