tag: Add a request::layouts signal and append/remove layout.
This commit is contained in:
parent
668ed6135c
commit
6b427e73a8
|
@ -259,6 +259,8 @@ end
|
||||||
|
|
||||||
--- Remove a layout from the list of default layouts.
|
--- Remove a layout from the list of default layouts.
|
||||||
--
|
--
|
||||||
|
-- @DOC_text_awful_layout_remove_EXAMPLE@
|
||||||
|
--
|
||||||
-- @staticfct awful.layout.remove_default_layout
|
-- @staticfct awful.layout.remove_default_layout
|
||||||
-- @tparam layout to_remove A valid tag layout.
|
-- @tparam layout to_remove A valid tag layout.
|
||||||
-- @treturn boolean True if the layout was found and removed.
|
-- @treturn boolean True if the layout was found and removed.
|
||||||
|
@ -455,13 +457,27 @@ local mt = {
|
||||||
end,
|
end,
|
||||||
__newindex = function(_, key, value)
|
__newindex = function(_, key, value)
|
||||||
if key == "layouts" then
|
if key == "layouts" then
|
||||||
gdebug.print_warning(
|
assert(type(value) == "table", "`awful.layout.layouts` needs a table.")
|
||||||
"`awful.layout.layouts` was set before `request::default_layouts` could "..
|
|
||||||
"be called. Please use `awful.layout.append_default_layouts` to "..
|
-- Do not ask for layouts if they were already provided.
|
||||||
" avoid this problem"
|
if init_layouts then
|
||||||
)
|
gdebug.print_warning(
|
||||||
capi.tag.disconnect_signal("new", init_layouts)
|
"`awful.layout.layouts` was set before `request::default_layouts` could "..
|
||||||
init_layouts = nil
|
"be called. Please use `awful.layout.append_default_layouts` to "..
|
||||||
|
" avoid this problem"
|
||||||
|
)
|
||||||
|
|
||||||
|
capi.tag.disconnect_signal("new", init_layouts)
|
||||||
|
init_layouts = nil
|
||||||
|
elseif #default_layouts > 0 then
|
||||||
|
gdebug.print_warning(
|
||||||
|
"`awful.layout.layouts` was set after `request::default_layouts` was "..
|
||||||
|
"used to get the layouts. This is probably an accident. Use "..
|
||||||
|
"`awful.layout.remove_default_layout` to get rid of this warning."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
default_layouts = value
|
||||||
else
|
else
|
||||||
rawset(layout, key, value)
|
rawset(layout, key, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -867,6 +867,22 @@ function tag.object.get_layouts(self)
|
||||||
|
|
||||||
local cls = custom_layouts(self)
|
local cls = custom_layouts(self)
|
||||||
|
|
||||||
|
-- Request some layouts. Maybe a new module was added?
|
||||||
|
if #cls == 0 and not tag.getproperty(self, "_layouts_requested") then
|
||||||
|
tag.setproperty(self, "_layouts_requested", true)
|
||||||
|
local old_count = #cls
|
||||||
|
self:emit_signal("request::layouts", "awful", {})
|
||||||
|
|
||||||
|
-- When request::layouts is used, assume it takes precedence over
|
||||||
|
-- the fallback.
|
||||||
|
if #cls > old_count then
|
||||||
|
tag.setproperty(self, "_layouts", gtable.clone(cls, false))
|
||||||
|
return tag.getproperty(self, "_layouts")
|
||||||
|
end
|
||||||
|
|
||||||
|
return tag.object.get_layouts(self)
|
||||||
|
end
|
||||||
|
|
||||||
-- Without the clone, the custom_layouts would grow
|
-- Without the clone, the custom_layouts would grow
|
||||||
return #cls > 0 and gtable.merge(gtable.clone(cls, false), alayout.layouts) or
|
return #cls > 0 and gtable.merge(gtable.clone(cls, false), alayout.layouts) or
|
||||||
alayout.layouts
|
alayout.layouts
|
||||||
|
@ -882,6 +898,60 @@ function tag.object.set_layouts(self, layouts)
|
||||||
self:emit_signal("property::layouts")
|
self:emit_signal("property::layouts")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function tag.object.append_layout(self, layout)
|
||||||
|
-- If the layouts are manually modified, don't request more.
|
||||||
|
tag.setproperty(self, "_layouts_requested", true)
|
||||||
|
|
||||||
|
local cls = tag.getproperty(self, "_layouts")
|
||||||
|
|
||||||
|
if not cls then
|
||||||
|
cls = custom_layouts(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(cls, layout)
|
||||||
|
self:emit_signal("property::layouts")
|
||||||
|
end
|
||||||
|
|
||||||
|
function tag.object.append_layouts(self, layouts)
|
||||||
|
-- If the layouts are manually modified, don't request more.
|
||||||
|
tag.setproperty(self, "_layouts_requested", true)
|
||||||
|
|
||||||
|
local cls = tag.getproperty(self, "_layouts")
|
||||||
|
|
||||||
|
if not cls then
|
||||||
|
cls = custom_layouts(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, l in ipairs(layouts) do
|
||||||
|
table.insert(cls, l)
|
||||||
|
end
|
||||||
|
self:emit_signal("property::layouts")
|
||||||
|
end
|
||||||
|
|
||||||
|
function tag.object.remove_layout(self, layout)
|
||||||
|
local cls = tag.getproperty(self, "_layouts")
|
||||||
|
|
||||||
|
if not cls then
|
||||||
|
cls = custom_layouts(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = {}
|
||||||
|
for k, l in ipairs(cls) do
|
||||||
|
if l == layout then
|
||||||
|
table.insert(pos, k)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #pos > 0 then
|
||||||
|
for i=#pos, 1, -1 do
|
||||||
|
table.remove(cls, i)
|
||||||
|
end
|
||||||
|
self:emit_signal("property::layouts")
|
||||||
|
end
|
||||||
|
|
||||||
|
return #pos > 0
|
||||||
|
end
|
||||||
|
|
||||||
function tag.object.get_layout(t)
|
function tag.object.get_layout(t)
|
||||||
local l = tag.getproperty(t, "layout")
|
local l = tag.getproperty(t, "layout")
|
||||||
if l then return l end
|
if l then return l end
|
||||||
|
|
|
@ -220,6 +220,15 @@
|
||||||
* @see awful.layout.remove_default_layout
|
* @see awful.layout.remove_default_layout
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** This signals is emitted when a tag needs layouts for the first time.
|
||||||
|
*
|
||||||
|
* If no handler implement it, it will fallback to the content added by
|
||||||
|
* `request::default_layouts`
|
||||||
|
*
|
||||||
|
* @signal request::layouts
|
||||||
|
* @tparam string context The context (currently always "awful").
|
||||||
|
* @tparam table hints A, currently empty, table with hints.
|
||||||
|
*/
|
||||||
|
|
||||||
/** When a client gets tagged with this tag.
|
/** When a client gets tagged with this tag.
|
||||||
* @signal tagged
|
* @signal tagged
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
--DOC_GEN_OUTPUT --DOC_HIDE
|
||||||
|
local awful = { layout = require("awful.layout"), --DOC_HIDE
|
||||||
|
suit= require("awful.layout.suit")} --DOC_HIDE
|
||||||
|
|
||||||
|
awful.layout.append_default_layouts({
|
||||||
|
awful.layout.suit.floating,
|
||||||
|
awful.layout.suit.tile,
|
||||||
|
awful.layout.suit.max,
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, l in ipairs(awful.layout.layouts) do
|
||||||
|
print("Before:", l.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
awful.layout.remove_default_layout(awful.layout.suit.tile)
|
||||||
|
|
||||||
|
--DOC_NEWLINE
|
||||||
|
|
||||||
|
for _, l in ipairs(awful.layout.layouts) do
|
||||||
|
print("After:", l.name)
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
Before: floating
|
||||||
|
Before: tile
|
||||||
|
Before: max
|
||||||
|
After: floating
|
||||||
|
After: max
|
Loading…
Reference in New Issue