1 -- -*- coding: utf-8 -*-
2 --------------------------------------------------------------------------------
3 -- @author Nicolas Berthier <nberthier@gmail.com>
4 -- @copyright 2010 Nicolas Berthier
5 --------------------------------------------------------------------------------
7 -- This is a module for defining infolines in awesome. An infoline is a wibox
8 -- attached to a region (typically, a client or the root window).
12 -- - It has not been tested with multiple screens yet.
14 -- Example usage: (TODO --- read the comments for now, there are not many
17 --------------------------------------------------------------------------------
19 --{{{ Grab environment (mostly aliases)
20 local setmetatable = setmetatable
30 local awesome = awesome
40 -- Privata data: we use weak keys in order to allow collection of private data
41 -- if keys (clients) are collected (i.e., no longer used, after having been
42 -- killed for instance).
44 -- XXX: For now, we have at most one infoline per client, but it could be
45 -- interesting to create several types of infolines (identified by indexes to be
46 -- allocated by this module), and associated to, e.g., different configuration
47 -- flags and positioning routine...
48 local data = setmetatable ({}, { __mode = 'k' })
50 --{{{ Infoline positioning
52 -- XXX: this is a hack that positions an infoline at the bottom of a given area.
53 local function setup_position (wb, geom)
54 local b = wb:geometry ()
57 b.y = geom.y + geom.height - awesome.font_height
58 b.height = awesome.font_height
66 -- When true, this flag indicates that an infoline is hidden if its attached
67 -- client loses its focus. Otherwise, it remains always visible.
72 --{{{ Infoline updates
74 function get_text (il) return il.wb.widgets[1].text end
75 function set_text (il, text) il.wb.widgets[1].text = text end
77 -- Forces a refresh of the given infoline.
83 -- XXX: Note this could be much better if we had some sort of root and
84 -- client interface unification: the following involves a priori useless
85 -- code duplication...
87 wb.screen = mouse.screen -- XXX: is this the behavior we need?
89 setup_position (wb, screen[mouse.screen].workarea)
91 if c:isvisible () and (not follow_focus or client.focus == c) then
94 setup_position (wb, c:geometry ())
95 else -- do we have to hide it?
99 elseif wb.visible then --otherwise we need to hide it.
104 local function update_from_client (c)
105 -- Note we may not have any infoline for this client, hence the
107 if data[c] then update (data[c]) end
110 -- Force execution of the above function on client state modification.
111 client.add_signal ("focus", update_from_client)
112 client.add_signal ("unfocus", update_from_client)
113 client.add_signal ("unmanage", update_from_client)
117 --{{{ Infoline management
119 --- Creates a new infoline, with the given initial text. Note it is not visible
120 --- by default, and not attached to any client.
124 ontop = true, -- XXX: setting a depth when attaching to
125 --a client would be much better
127 widget ({ type = "textbox", align="left" })
131 -- these will remain false until the infoline is attached to a client.
132 il.wb.visible = false
134 set_text (il, text or "")
138 -- Attached infolines will react to the following client-related signals, and
139 -- automatically setup their position according to the client's geometry.
140 local csignals = { "property::geometry", "property::minimized",
141 "property::visible", "property::focus", "property::screen", }
143 -- Attaches an infoline to a client. Note the infoline becomes visible at that
144 -- time, if the client is currently visible (and if it has focus, when
145 -- `follow_focus' holds).
146 function attach (il, c)
152 -- subscribe to client-related signals
153 for _, s in ipairs (csignals) do
154 c:add_signal (s, update_from_client)
159 --- Detach the given infoline from its client, if any.
160 function dispose (il)
162 if c then -- note c can be nil here, if the given infoline has not been
163 --attached to any client...
165 update (il) -- a shortcut here would be: `il.wb.visible = false'
168 -- unsubscribe from client-related signals
169 for _, s in ipairs (csignals) do
170 c:remove_signal (s, update_from_client)
179 -- indent-tabs-mode: nil
181 -- lua-indent-level: 4
183 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80