awful: move hooks to signals

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-11 15:27:31 +02:00
parent be066ca196
commit 65825bdd22
8 changed files with 141 additions and 120 deletions

View File

@ -19,9 +19,7 @@ local capi =
client = client, client = client,
mouse = mouse, mouse = mouse,
screen = screen, screen = screen,
hooks = hooks
} }
local hooks = require("awful.hooks")
--- Client module for awful --- Client module for awful
module("awful.client") module("awful.client")
@ -42,10 +40,6 @@ floating = {}
dockable = {} dockable = {}
property = {} property = {}
-- User hooks
hooks.user.create('marked')
hooks.user.create('unmarked')
--- Get the first client that got the urgent hint. --- Get the first client that got the urgent hint.
-- @return The first urgent client. -- @return The first urgent client.
function urgent.get() function urgent.get()
@ -493,7 +487,7 @@ function mark(c)
table.insert(data.marked, cl) table.insert(data.marked, cl)
-- Call callback -- Call callback
hooks.user.call('marked', cl) cl:emit_signal("marked")
return true return true
end end
end end
@ -507,7 +501,7 @@ function unmark(c)
for k, v in pairs(data.marked) do for k, v in pairs(data.marked) do
if cl == v then if cl == v then
table.remove(data.marked, k) table.remove(data.marked, k)
hooks.user.call('unmarked', cl) cl:emit_signal("unmarked")
return true return true
end end
end end
@ -543,7 +537,7 @@ end
-- @return A table with all marked clients. -- @return A table with all marked clients.
function getmarked() function getmarked()
for k, v in pairs(data.marked) do for k, v in pairs(data.marked) do
hooks.user.call('unmarked', v) v:emit_signal("unmarked")
end end
t = data.marked t = data.marked
@ -761,7 +755,7 @@ function setwfact(wfact, c)
end end
end end
hooks.user.call("property", t, "windowfact") t:emit_signal("property::windowfact")
end end
--- Increment a client's window factor --- Increment a client's window factor
@ -784,7 +778,7 @@ function incwfact(add, c)
-- keep our ratios normalized -- keep our ratios normalized
normalize(colfact, w.num) normalize(colfact, w.num)
hooks.user.call("property", t, "windowfact") t:emit_signal("property::windowfact")
end end
--- Get a client dockable state. --- Get a client dockable state.
@ -836,7 +830,7 @@ function property.set(c, prop, value)
data.properties[c] = {} data.properties[c] = {}
end end
data.properties[c][prop] = value data.properties[c][prop] = value
hooks.user.call("property", c, prop) c:emit_signal("property::floating")
end end
-- Register standards signals -- Register standards signals

View File

@ -13,9 +13,9 @@ local util = require("awful.util")
local suit = require("awful.layout.suit") local suit = require("awful.layout.suit")
local wibox = require("awful.wibox") local wibox = require("awful.wibox")
local ascreen = require("awful.screen") local ascreen = require("awful.screen")
local hooks = require("awful.hooks")
local capi = { local capi = {
screen = screen, screen = screen,
awesome = awesome,
client = client client = client
} }
local client = require("awful.client") local client = require("awful.client")
@ -23,9 +23,6 @@ local client = require("awful.client")
--- Layout module for awful --- Layout module for awful
module("awful.layout") module("awful.layout")
-- Create a hook to call when changing layout
hooks.user.create("layout")
--- Get the current layout. --- Get the current layout.
-- @param screen The screen number. -- @param screen The screen number.
-- @return The layout function. -- @return The layout function.
@ -61,11 +58,11 @@ end
function set(layout, t) function set(layout, t)
t = t or tag.selected() t = t or tag.selected()
tag.setproperty(t, "layout", layout) tag.setproperty(t, "layout", layout)
hooks.user.call("layout", t, layout)
end end
-- Register an arrange hook. --- Arrange a screen using its current layout.
local function on_arrange (screen) -- @param screen The screen to arrange.
function arrange(screen)
local p = {} local p = {}
p.workarea = wibox.get_workarea(screen) p.workarea = wibox.get_workarea(screen)
-- Handle padding -- Handle padding
@ -90,62 +87,68 @@ function getname(layout)
return layout.name return layout.name
end end
hooks.property.register(function (obj, prop) local function arrange_prop(obj) arrange(obj.screen) end
local objtype = type(obj)
if objtype == "client" then capi.client.add_signal("new", function(c)
if prop == "size_hints_honor" c:add_signal("property::size_hints_honor", arrange_prop)
or prop == "struts" c:add_signal("property::struts", arrange_prop)
or prop == "minimized" c:add_signal("property::minimized", arrange_prop)
or prop == "sticky" c:add_signal("property::sticky", arrange_prop)
or prop == "fullscreen" c:add_signal("property::fullscreen", arrange_prop)
or prop == "maximized_horizontal" c:add_signal("property::maximized_horizontal", arrange_prop)
or prop == "maximized_vertical" c:add_signal("property::maximized_vertical", arrange_prop)
or prop == "border_width" c:add_signal("property::border_width", arrange_prop)
or prop == "hide" c:add_signal("property::hidden", arrange_prop)
or prop == "titlebar" c:add_signal("property::titlebar", arrange_prop)
or prop == "floating" then c:add_signal("property::floating", arrange_prop)
on_arrange(obj.screen)
elseif prop == "screen" then
-- If prop is screen, we do not know what was the previous screen, so -- If prop is screen, we do not know what was the previous screen, so
-- let's arrange all screens :-( -- let's arrange all screens :-(
for screen = 1, capi.screen.count() do c:add_signal("property::screen", function(c)
on_arrange(screen) for screen = 1, capi.screen.count() do arrange(screen) end end)
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)
end) end)
hooks.padding.register(function(screen) on_arrange(screen) end) local function arrange_on_tagged(c, tag)
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)
if not tag.screen then return end 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 if not capi.client.focus or not capi.client.focus:isvisible() then
local c = client.focus.history.get(tag.screen, 0) local c = client.focus.history.get(tag.screen, 0)
if c then capi.client.focus = c end if c then capi.client.focus = c end
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) end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -13,7 +13,6 @@ local capi =
} }
local util = require("awful.util") local util = require("awful.util")
local client = require("awful.client") local client = require("awful.client")
local hooks = require("awful.hooks")
--- Screen module for awful --- Screen module for awful
module("awful.screen") module("awful.screen")
@ -21,9 +20,6 @@ module("awful.screen")
local data = {} local data = {}
data.padding = {} data.padding = {}
-- Create a hook for padding event
hooks.user.create("padding")
--- Give the focus to a screen, and move pointer. --- Give the focus to a screen, and move pointer.
-- @param i Relative screen number. -- @param i Relative screen number.
function focus(i) function focus(i)
@ -41,7 +37,7 @@ end
function padding(i, padding) function padding(i, padding)
if padding then if padding then
data.padding[i] = padding data.padding[i] = padding
hooks.user.call("padding", i) capi.screen[i]:emit_signal("padding")
end end
return data.padding[i] return data.padding[i]
end end

View File

@ -16,7 +16,6 @@ local capi =
mouse = mouse, mouse = mouse,
client = client client = client
} }
local hooks = require("awful.hooks")
--- Tag module for awful --- Tag module for awful
module("awful.tag") module("awful.tag")
@ -267,7 +266,7 @@ function setproperty(tag, prop, value)
data.tags[tag] = {} data.tags[tag] = {}
end end
data.tags[tag][prop] = value data.tags[tag][prop] = value
hooks.user.call("property", tag, prop) tag:emit_signal("property::" .. prop)
end end
--- Tag a client with the set of current tags. --- Tag a client with the set of current tags.
@ -285,8 +284,7 @@ function withcurrent(c, startup)
end end
end end
-- Register standards hooks -- Register standards signals
hooks.tags.register(history.update)
capi.client.add_signal("manage", withcurrent) capi.client.add_signal("manage", withcurrent)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -17,7 +17,6 @@ local ipairs = ipairs
local table = table local table = table
local type = type local type = type
local image = image local image = image
local hooks = require("awful.hooks")
--- Wibox module for awful. --- Wibox module for awful.
module("awful.wibox") module("awful.wibox")
@ -26,8 +25,6 @@ module("awful.wibox")
-- It's an array so it is ordered. -- It's an array so it is ordered.
local wiboxes = {} local wiboxes = {}
hooks.user.create("wibox_position")
--- Get the workarea space without wiboxes geometry. --- Get the workarea space without wiboxes geometry.
-- @param s The screen number. -- @param s The screen number.
-- @return The screen workarea. -- @return The screen workarea.
@ -127,10 +124,15 @@ end
local function update_all_wiboxes_position() local function update_all_wiboxes_position()
for _, wprop in ipairs(wiboxes) do for _, wprop in ipairs(wiboxes) do
set_position(wprop.wibox, wprop.position) set_position(wprop.wibox, wprop.position)
hooks.user.call("wibox_position", wprop.wibox) capi.awesome.emit_signal("arrange", wprop.wibox.screen)
end end
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. --- Attach a wibox to a screen.
-- If a wibox is attached, it will be automatically be moved when other wiboxes -- If a wibox is attached, it will be automatically be moved when other wiboxes
-- will be attached. -- will be attached.
@ -166,6 +168,9 @@ function attach(wibox, position)
if wibox.screen and wibox.visible then if wibox.screen and wibox.visible then
update_all_wiboxes_position() update_all_wiboxes_position()
end 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 end
--- Align a wibox. --- 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) wibox.shape_bounding = do_rounded_corners(wibox.width + border * 2, wibox.height + border * 2, corner_size + border)
end 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 function update_wiboxes_on_struts(c)
local struts = c:struts() local struts = c:struts()
if struts.left ~= 0 or struts.right ~= 0 if struts.left ~= 0 or struts.right ~= 0
@ -358,8 +352,10 @@ local function update_wiboxes_on_struts(c)
end end
-- Hook registered to reset all wiboxes position. -- Hook registered to reset all wiboxes position.
hooks.property.register(update_wiboxes_position) capi.client.add_signal("manage", function(c)
capi.client.add_signal("manage", update_wiboxes_on_struts) update_wiboxes_on_struts(c)
c:add_signal("property::struts", update_wiboxes_on_struts)
end)
capi.client.add_signal("unmanage", update_wiboxes_on_struts) capi.client.add_signal("unmanage", update_wiboxes_on_struts)
setmetatable(_M, { __call = function(_, ...) return new(...) end }) setmetatable(_M, { __call = function(_, ...) return new(...) end })

View File

@ -5,6 +5,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local setmetatable = setmetatable local setmetatable = setmetatable
local ipairs = ipairs
local button = require("awful.button") local button = require("awful.button")
local layout = require("awful.layout") local layout = require("awful.layout")
local beautiful = require("beautiful") local beautiful = require("beautiful")
@ -37,7 +38,7 @@ function new(screen, args)
update(w, screen) update(w, screen)
local function update_on_tag_selection(tag) local function update_on_tag_selection(tag)
return update(w, tag) return update(w, tag.screen)
end end
capi.screen[screen]:add_signal("tag::attach", function(s, tag) 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::selected", update_on_tag_selection)
tag:remove_signal("property::layout", update_on_tag_selection) tag:remove_signal("property::layout", update_on_tag_selection)
end) 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 return w
end end

View File

@ -14,7 +14,6 @@ local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local ipairs = ipairs local ipairs = ipairs
local table = table local table = table
local hooks = require("awful.hooks")
local common = require("awful.widget.common") local common = require("awful.widget.common")
local util = require("awful.util") local util = require("awful.util")
local tag = require("awful.tag") local tag = require("awful.tag")
@ -67,15 +66,34 @@ function new(screen, label, buttons)
local uc = function (c) return u(c.screen) end local uc = function (c) return u(c.screen) end
capi.client.add_signal("focus", uc) capi.client.add_signal("focus", uc)
capi.client.add_signal("unfocus", uc) capi.client.add_signal("unfocus", uc)
hooks.tags.register(u) capi.screen[screen]:add_signal("tag::attach", function(screen, tag)
hooks.tagged.register(uc) taglist_update(s, w, label, buttons, data, widgets)
hooks.property.register(function (c, prop) tag:add_signal("property::selected", uc)
if (type(c) == "client" and prop == "urgent") tag:add_signal("property::icon", uc)
or (type(c) == "tag" and tag:add_signal("property::hide", uc)
(prop == "icon" or prop == "hide")) then
u(c.screen)
end
end) 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) u(screen)
return w return w
end end

View File

@ -12,7 +12,6 @@ local ipairs = ipairs
local type = type local type = type
local setmetatable = setmetatable local setmetatable = setmetatable
local table = table local table = table
local hooks = require("awful.hooks")
local common = require("awful.widget.common") local common = require("awful.widget.common")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local client = require("awful.client") local client = require("awful.client")
@ -55,24 +54,35 @@ function new(label, buttons)
} }
local data = setmetatable({}, { __mode = 'k' }) local data = setmetatable({}, { __mode = 'k' })
local u = function () tasklist_update(w, buttons, label, data, widgets) end 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) capi.client.add_signal("list", u)
hooks.tagged.register(u)
capi.client.add_signal("focus", u) capi.client.add_signal("focus", u)
capi.client.add_signal("unfocus", 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() u()
return w return w
end end