awful: move hooks to signals
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
be066ca196
commit
65825bdd22
|
@ -19,9 +19,7 @@ local capi =
|
|||
client = client,
|
||||
mouse = mouse,
|
||||
screen = screen,
|
||||
hooks = hooks
|
||||
}
|
||||
local hooks = require("awful.hooks")
|
||||
|
||||
--- Client module for awful
|
||||
module("awful.client")
|
||||
|
@ -42,10 +40,6 @@ floating = {}
|
|||
dockable = {}
|
||||
property = {}
|
||||
|
||||
-- User hooks
|
||||
hooks.user.create('marked')
|
||||
hooks.user.create('unmarked')
|
||||
|
||||
--- Get the first client that got the urgent hint.
|
||||
-- @return The first urgent client.
|
||||
function urgent.get()
|
||||
|
@ -493,7 +487,7 @@ function mark(c)
|
|||
table.insert(data.marked, cl)
|
||||
|
||||
-- Call callback
|
||||
hooks.user.call('marked', cl)
|
||||
cl:emit_signal("marked")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -507,7 +501,7 @@ function unmark(c)
|
|||
for k, v in pairs(data.marked) do
|
||||
if cl == v then
|
||||
table.remove(data.marked, k)
|
||||
hooks.user.call('unmarked', cl)
|
||||
cl:emit_signal("unmarked")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -543,7 +537,7 @@ end
|
|||
-- @return A table with all marked clients.
|
||||
function getmarked()
|
||||
for k, v in pairs(data.marked) do
|
||||
hooks.user.call('unmarked', v)
|
||||
v:emit_signal("unmarked")
|
||||
end
|
||||
|
||||
t = data.marked
|
||||
|
@ -761,7 +755,7 @@ function setwfact(wfact, c)
|
|||
end
|
||||
end
|
||||
|
||||
hooks.user.call("property", t, "windowfact")
|
||||
t:emit_signal("property::windowfact")
|
||||
end
|
||||
|
||||
--- Increment a client's window factor
|
||||
|
@ -784,7 +778,7 @@ function incwfact(add, c)
|
|||
-- keep our ratios normalized
|
||||
normalize(colfact, w.num)
|
||||
|
||||
hooks.user.call("property", t, "windowfact")
|
||||
t:emit_signal("property::windowfact")
|
||||
end
|
||||
|
||||
--- Get a client dockable state.
|
||||
|
@ -836,7 +830,7 @@ function property.set(c, prop, value)
|
|||
data.properties[c] = {}
|
||||
end
|
||||
data.properties[c][prop] = value
|
||||
hooks.user.call("property", c, prop)
|
||||
c:emit_signal("property::floating")
|
||||
end
|
||||
|
||||
-- Register standards signals
|
||||
|
|
|
@ -13,9 +13,9 @@ local util = require("awful.util")
|
|||
local suit = require("awful.layout.suit")
|
||||
local wibox = require("awful.wibox")
|
||||
local ascreen = require("awful.screen")
|
||||
local hooks = require("awful.hooks")
|
||||
local capi = {
|
||||
screen = screen,
|
||||
awesome = awesome,
|
||||
client = client
|
||||
}
|
||||
local client = require("awful.client")
|
||||
|
@ -23,9 +23,6 @@ local client = require("awful.client")
|
|||
--- Layout module for awful
|
||||
module("awful.layout")
|
||||
|
||||
-- Create a hook to call when changing layout
|
||||
hooks.user.create("layout")
|
||||
|
||||
--- Get the current layout.
|
||||
-- @param screen The screen number.
|
||||
-- @return The layout function.
|
||||
|
@ -61,11 +58,11 @@ end
|
|||
function set(layout, t)
|
||||
t = t or tag.selected()
|
||||
tag.setproperty(t, "layout", layout)
|
||||
hooks.user.call("layout", t, layout)
|
||||
end
|
||||
|
||||
-- Register an arrange hook.
|
||||
local function on_arrange (screen)
|
||||
--- Arrange a screen using its current layout.
|
||||
-- @param screen The screen to arrange.
|
||||
function arrange(screen)
|
||||
local p = {}
|
||||
p.workarea = wibox.get_workarea(screen)
|
||||
-- Handle padding
|
||||
|
@ -90,62 +87,68 @@ function getname(layout)
|
|||
return layout.name
|
||||
end
|
||||
|
||||
hooks.property.register(function (obj, prop)
|
||||
local objtype = type(obj)
|
||||
if objtype == "client" then
|
||||
if prop == "size_hints_honor"
|
||||
or prop == "struts"
|
||||
or prop == "minimized"
|
||||
or prop == "sticky"
|
||||
or prop == "fullscreen"
|
||||
or prop == "maximized_horizontal"
|
||||
or prop == "maximized_vertical"
|
||||
or prop == "border_width"
|
||||
or prop == "hide"
|
||||
or prop == "titlebar"
|
||||
or prop == "floating" then
|
||||
on_arrange(obj.screen)
|
||||
elseif prop == "screen" then
|
||||
-- If prop is screen, we do not know what was the previous screen, so
|
||||
-- let's arrange all screens :-(
|
||||
for screen = 1, capi.screen.count() do
|
||||
on_arrange(screen)
|
||||
end
|
||||
end
|
||||
elseif objtype == "wibox" then
|
||||
if prop == "screen"
|
||||
or prop == "visible" then
|
||||
on_arrange(obj.screen)
|
||||
end
|
||||
elseif objtype == "tag" then
|
||||
if prop == "mwfact"
|
||||
or prop == "nmaster"
|
||||
or prop == "ncol"
|
||||
or prop == "layout"
|
||||
or prop == "windowfact" then
|
||||
on_arrange(obj.screen)
|
||||
end
|
||||
end
|
||||
end)
|
||||
hooks.wibox_position.register(function(wibox)
|
||||
on_arrange(wibox.screen)
|
||||
local function arrange_prop(obj) arrange(obj.screen) end
|
||||
|
||||
capi.client.add_signal("new", function(c)
|
||||
c:add_signal("property::size_hints_honor", arrange_prop)
|
||||
c:add_signal("property::struts", arrange_prop)
|
||||
c:add_signal("property::minimized", arrange_prop)
|
||||
c:add_signal("property::sticky", arrange_prop)
|
||||
c:add_signal("property::fullscreen", arrange_prop)
|
||||
c:add_signal("property::maximized_horizontal", arrange_prop)
|
||||
c:add_signal("property::maximized_vertical", arrange_prop)
|
||||
c:add_signal("property::border_width", arrange_prop)
|
||||
c:add_signal("property::hidden", arrange_prop)
|
||||
c:add_signal("property::titlebar", arrange_prop)
|
||||
c:add_signal("property::floating", arrange_prop)
|
||||
-- If prop is screen, we do not know what was the previous screen, so
|
||||
-- let's arrange all screens :-(
|
||||
c:add_signal("property::screen", function(c)
|
||||
for screen = 1, capi.screen.count() do arrange(screen) end end)
|
||||
end)
|
||||
|
||||
hooks.padding.register(function(screen) on_arrange(screen) end)
|
||||
capi.client.add_signal("focus", function(c) on_arrange(c.screen) end)
|
||||
capi.client.add_signal("list", function()
|
||||
for screen = 1, capi.screen.count() do
|
||||
on_arrange(screen)
|
||||
end
|
||||
end)
|
||||
hooks.tags.register(function(screen, tag, action) on_arrange(screen) end)
|
||||
hooks.tagged.register(function(c, tag)
|
||||
local function arrange_on_tagged(c, tag)
|
||||
if not tag.screen then return end
|
||||
on_arrange(tag.screen)
|
||||
arrange(tag.screen)
|
||||
if not capi.client.focus or not capi.client.focus:isvisible() then
|
||||
local c = client.focus.history.get(tag.screen, 0)
|
||||
if c then capi.client.focus = c end
|
||||
end
|
||||
end
|
||||
|
||||
for s = 1, capi.screen.count() do
|
||||
capi.screen[s]:add_signal("tag::attach", function (screen, tag)
|
||||
arrange(screen.index)
|
||||
tag:add_signal("property::mwfact", arrange_prop)
|
||||
tag:add_signal("property::nmaster", arrange_prop)
|
||||
tag:add_signal("property::ncol", arrange_prop)
|
||||
tag:add_signal("property::layout", arrange_prop)
|
||||
tag:add_signal("property::windowfact", arrange_prop)
|
||||
tag:add_signal("property::selected", arrange_prop)
|
||||
tag:add_signal("tagged", arrange_on_tagged)
|
||||
end)
|
||||
capi.screen[s]:add_signal("tag::detach", function (screen, tag)
|
||||
arrange(screen.index)
|
||||
tag:remove_signal("property::mwfact", arrange_prop)
|
||||
tag:remove_signal("property::nmaster", arrange_prop)
|
||||
tag:remove_signal("property::ncol", arrange_prop)
|
||||
tag:remove_signal("property::layout", arrange_prop)
|
||||
tag:remove_signal("property::windowfact", arrange_prop)
|
||||
tag:remove_signal("property::selected", arrange_prop)
|
||||
tag:remove_signal("tagged", arrange_on_tagged)
|
||||
end)
|
||||
capi.screen[s]:add_signal("padding", arrange)
|
||||
end
|
||||
|
||||
capi.awesome.add_signal("arrange", function(screen)
|
||||
arrange(screen)
|
||||
end)
|
||||
|
||||
capi.client.add_signal("focus", function(c) arrange(c.screen) end)
|
||||
capi.client.add_signal("list", function()
|
||||
for screen = 1, capi.screen.count() do
|
||||
arrange(screen)
|
||||
end
|
||||
end)
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -13,7 +13,6 @@ local capi =
|
|||
}
|
||||
local util = require("awful.util")
|
||||
local client = require("awful.client")
|
||||
local hooks = require("awful.hooks")
|
||||
|
||||
--- Screen module for awful
|
||||
module("awful.screen")
|
||||
|
@ -21,9 +20,6 @@ module("awful.screen")
|
|||
local data = {}
|
||||
data.padding = {}
|
||||
|
||||
-- Create a hook for padding event
|
||||
hooks.user.create("padding")
|
||||
|
||||
--- Give the focus to a screen, and move pointer.
|
||||
-- @param i Relative screen number.
|
||||
function focus(i)
|
||||
|
@ -41,7 +37,7 @@ end
|
|||
function padding(i, padding)
|
||||
if padding then
|
||||
data.padding[i] = padding
|
||||
hooks.user.call("padding", i)
|
||||
capi.screen[i]:emit_signal("padding")
|
||||
end
|
||||
return data.padding[i]
|
||||
end
|
||||
|
|
|
@ -16,7 +16,6 @@ local capi =
|
|||
mouse = mouse,
|
||||
client = client
|
||||
}
|
||||
local hooks = require("awful.hooks")
|
||||
|
||||
--- Tag module for awful
|
||||
module("awful.tag")
|
||||
|
@ -267,7 +266,7 @@ function setproperty(tag, prop, value)
|
|||
data.tags[tag] = {}
|
||||
end
|
||||
data.tags[tag][prop] = value
|
||||
hooks.user.call("property", tag, prop)
|
||||
tag:emit_signal("property::" .. prop)
|
||||
end
|
||||
|
||||
--- Tag a client with the set of current tags.
|
||||
|
@ -285,8 +284,7 @@ function withcurrent(c, startup)
|
|||
end
|
||||
end
|
||||
|
||||
-- Register standards hooks
|
||||
hooks.tags.register(history.update)
|
||||
-- Register standards signals
|
||||
capi.client.add_signal("manage", withcurrent)
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
|
@ -17,7 +17,6 @@ local ipairs = ipairs
|
|||
local table = table
|
||||
local type = type
|
||||
local image = image
|
||||
local hooks = require("awful.hooks")
|
||||
|
||||
--- Wibox module for awful.
|
||||
module("awful.wibox")
|
||||
|
@ -26,8 +25,6 @@ module("awful.wibox")
|
|||
-- It's an array so it is ordered.
|
||||
local wiboxes = {}
|
||||
|
||||
hooks.user.create("wibox_position")
|
||||
|
||||
--- Get the workarea space without wiboxes geometry.
|
||||
-- @param s The screen number.
|
||||
-- @return The screen workarea.
|
||||
|
@ -127,10 +124,15 @@ end
|
|||
local function update_all_wiboxes_position()
|
||||
for _, wprop in ipairs(wiboxes) do
|
||||
set_position(wprop.wibox, wprop.position)
|
||||
hooks.user.call("wibox_position", wprop.wibox)
|
||||
capi.awesome.emit_signal("arrange", wprop.wibox.screen)
|
||||
end
|
||||
end
|
||||
|
||||
local function call_wibox_position_hook_on_prop_update(w)
|
||||
capi.awesome.emit_signal("arrange", w.screen)
|
||||
update_all_wiboxes_position()
|
||||
end
|
||||
|
||||
--- Attach a wibox to a screen.
|
||||
-- If a wibox is attached, it will be automatically be moved when other wiboxes
|
||||
-- will be attached.
|
||||
|
@ -166,6 +168,9 @@ function attach(wibox, position)
|
|||
if wibox.screen and wibox.visible then
|
||||
update_all_wiboxes_position()
|
||||
end
|
||||
|
||||
wibox:add_signal("property::screen", call_wibox_position_hook_on_prop_update)
|
||||
wibox:add_signal("property::visible", call_wibox_position_hook_on_prop_update)
|
||||
end
|
||||
|
||||
--- Align a wibox.
|
||||
|
@ -338,17 +343,6 @@ function rounded_corners(wibox, corner_size)
|
|||
wibox.shape_bounding = do_rounded_corners(wibox.width + border * 2, wibox.height + border * 2, corner_size + border)
|
||||
end
|
||||
|
||||
local function update_wiboxes_position(obj, prop)
|
||||
if (type(obj) == "wibox"
|
||||
and (prop == nil
|
||||
or prop == "visible"
|
||||
or prop == "screen"))
|
||||
or (type(obj) == "client"
|
||||
and prop == "struts") then
|
||||
update_all_wiboxes_position()
|
||||
end
|
||||
end
|
||||
|
||||
local function update_wiboxes_on_struts(c)
|
||||
local struts = c:struts()
|
||||
if struts.left ~= 0 or struts.right ~= 0
|
||||
|
@ -358,8 +352,10 @@ local function update_wiboxes_on_struts(c)
|
|||
end
|
||||
|
||||
-- Hook registered to reset all wiboxes position.
|
||||
hooks.property.register(update_wiboxes_position)
|
||||
capi.client.add_signal("manage", update_wiboxes_on_struts)
|
||||
capi.client.add_signal("manage", function(c)
|
||||
update_wiboxes_on_struts(c)
|
||||
c:add_signal("property::struts", update_wiboxes_on_struts)
|
||||
end)
|
||||
capi.client.add_signal("unmanage", update_wiboxes_on_struts)
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local button = require("awful.button")
|
||||
local layout = require("awful.layout")
|
||||
local beautiful = require("beautiful")
|
||||
|
@ -37,7 +38,7 @@ function new(screen, args)
|
|||
update(w, screen)
|
||||
|
||||
local function update_on_tag_selection(tag)
|
||||
return update(w, tag)
|
||||
return update(w, tag.screen)
|
||||
end
|
||||
|
||||
capi.screen[screen]:add_signal("tag::attach", function(s, tag)
|
||||
|
@ -48,6 +49,11 @@ function new(screen, args)
|
|||
tag:remove_signal("property::selected", update_on_tag_selection)
|
||||
tag:remove_signal("property::layout", update_on_tag_selection)
|
||||
end)
|
||||
|
||||
for _, tag in ipairs(capi.screen[screen]:tags()) do
|
||||
tag:add_signal("property::selected", update_on_tag_selection)
|
||||
tag:add_signal("property::layout", update_on_tag_selection)
|
||||
end
|
||||
return w
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ local setmetatable = setmetatable
|
|||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local table = table
|
||||
local hooks = require("awful.hooks")
|
||||
local common = require("awful.widget.common")
|
||||
local util = require("awful.util")
|
||||
local tag = require("awful.tag")
|
||||
|
@ -67,15 +66,34 @@ function new(screen, label, buttons)
|
|||
local uc = function (c) return u(c.screen) end
|
||||
capi.client.add_signal("focus", uc)
|
||||
capi.client.add_signal("unfocus", uc)
|
||||
hooks.tags.register(u)
|
||||
hooks.tagged.register(uc)
|
||||
hooks.property.register(function (c, prop)
|
||||
if (type(c) == "client" and prop == "urgent")
|
||||
or (type(c) == "tag" and
|
||||
(prop == "icon" or prop == "hide")) then
|
||||
u(c.screen)
|
||||
end
|
||||
capi.screen[screen]:add_signal("tag::attach", function(screen, tag)
|
||||
taglist_update(s, w, label, buttons, data, widgets)
|
||||
tag:add_signal("property::selected", uc)
|
||||
tag:add_signal("property::icon", uc)
|
||||
tag:add_signal("property::hide", uc)
|
||||
end)
|
||||
capi.screen[screen]:add_signal("tag::detach", function(screen, tag)
|
||||
taglist_update(s, w, label, buttons, data, widgets)
|
||||
tag:remove_signal("property::selected", uc)
|
||||
tag:remove_signal("property::icon", uc)
|
||||
tag:remove_signal("property::hide", uc)
|
||||
end)
|
||||
for _, tag in ipairs(capi.screen[screen]:tags()) do
|
||||
tag:add_signal("property::selected", uc)
|
||||
tag:add_signal("property::icon", uc)
|
||||
tag:add_signal("property::hide", uc)
|
||||
end
|
||||
capi.client.add_signal("new", function(c)
|
||||
c:add_signal("property::urgent", uc)
|
||||
c:add_signal("property::screen", function(c)
|
||||
-- If client change screen, refresh it anyway since we don't from
|
||||
-- which screen it was coming :-)
|
||||
u(screen)
|
||||
end)
|
||||
c:add_signal("tagged", uc)
|
||||
c:add_signal("untagged", uc)
|
||||
end)
|
||||
capi.client.add_signal("unmanage", uc)
|
||||
u(screen)
|
||||
return w
|
||||
end
|
||||
|
|
|
@ -12,7 +12,6 @@ local ipairs = ipairs
|
|||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local table = table
|
||||
local hooks = require("awful.hooks")
|
||||
local common = require("awful.widget.common")
|
||||
local beautiful = require("beautiful")
|
||||
local client = require("awful.client")
|
||||
|
@ -55,24 +54,35 @@ function new(label, buttons)
|
|||
}
|
||||
local data = setmetatable({}, { __mode = 'k' })
|
||||
local u = function () tasklist_update(w, buttons, label, data, widgets) end
|
||||
hooks.tags.register(u)
|
||||
for s = 1, capi.screen.count() do
|
||||
capi.screen[s]:add_signal("tag::attach", function (s, t)
|
||||
u()
|
||||
t:add_signal("property::selected", u)
|
||||
end)
|
||||
capi.screen[s]:add_signal("tag::detach", function (s, t)
|
||||
u()
|
||||
t:remove_signal("property::selected", u)
|
||||
end)
|
||||
for _, tag in ipairs(capi.screen[s]:tags()) do
|
||||
tag:add_signal("property::selected", u)
|
||||
end
|
||||
end
|
||||
capi.client.add_signal("new", function (c)
|
||||
c:add_signal("property::urgent", u)
|
||||
c:add_signal("property::floating", u)
|
||||
c:add_signal("property::maximized_horizontal", u)
|
||||
c:add_signal("property::maximized_vertical", u)
|
||||
c:add_signal("property::name", u)
|
||||
c:add_signal("property::name", u)
|
||||
c:add_signal("property::icon_name", u)
|
||||
c:add_signal("property::skip_taskbar", u)
|
||||
c:add_signal("tagged", u)
|
||||
c:add_signal("untagged", u)
|
||||
end)
|
||||
capi.client.add_signal("unmanage", u)
|
||||
capi.client.add_signal("list", u)
|
||||
hooks.tagged.register(u)
|
||||
capi.client.add_signal("focus", u)
|
||||
capi.client.add_signal("unfocus", u)
|
||||
hooks.property.register(function (c, prop)
|
||||
if type(c) ~= "client" then return end
|
||||
if prop == "urgent"
|
||||
or prop == "floating"
|
||||
or prop == "maximized_horizontal"
|
||||
or prop == "maximized_vertical"
|
||||
or prop == "icon"
|
||||
or prop == "name"
|
||||
or prop == "icon_name"
|
||||
or prop == "skip_taskbar" then
|
||||
u()
|
||||
end
|
||||
end)
|
||||
u()
|
||||
return w
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue