1 -- Authors: Etan Reisner <deryni@gmail.com>
2 -- License: MIT, see http://opensource.org/licenses/mit-license.php
3 -- Last Changed: 2007-01-23
7 Email: deryni@gmail.com
8 Summary: Adds a handful of statusbar meters displaying the current workspace name, all workspace names, etc. in a variety of manners.
10 Last Updated: 2007-01-23
12 Copyright (c) Etan Reisner 2007
14 This software is released under the terms of the MIT license. For more
15 information, see http://opensource.org/licenses/mit-license.php .
19 -- Add %wsname (or %wsname_full) to your statusbar template.
21 -- For multiple head setups with multiple statusbars,
22 -- use %wsname_{screennum} in your template (%wsname is the same as %wsname_0).
24 -- The %wsname_fullall meter shows a combined %wsname_full display for all screens.
26 -- The %wsname_pre meter contains the workspaces earlier in the list than the
29 -- The %wsname_post meter contains the workspaces later in the list than the
32 if not mod_statusbar
then
38 template
= "xxxxxxxxxxx",
42 local wsname
= table.join(wsname
or {}, defaults
)
44 local function get_ws_name(t
)
47 if not obj_is(reg
, "WScreen") then
51 local ws_names_all
, wsname_pre
, wsname_post
= nil, "", ""
53 local function inform(screen
)
54 if screen
:mx_count() == 0 then
58 local ws_names
, before
, id
= nil, true, screen
:id()
60 local function compose_ws_names(ws
)
61 local marker
, current
= "", false
62 local wsn
= ws
:name() or "?"
64 if ws
== screen
:mx_current() then
65 marker
= wsname
.marker
71 ws_names
= marker
..wsn
..marker
73 ws_names
= ws_names
.." "..marker
..wsn
..marker
76 if before
and not current
then
77 if wsname_pre
== "" then
80 wsname_pre
= wsname_pre
.." "..wsn
82 elseif not current
then
83 if wsname_post
== "" then
86 wsname_post
= wsname_post
.." "..wsn
93 screen
:mx_i(compose_ws_names
)
95 mod_statusbar
.inform("wsname_"..id
, screen
:mx_current():name())
96 mod_statusbar
.inform("wsname_full_"..id
, ws_names
)
97 mod_statusbar
.inform("wsname_full_"..id
.."_template", ws_names
:len())
98 mod_statusbar
.inform("wsname_pre_"..id
, wsname_pre
)
99 mod_statusbar
.inform("wsname_pre_"..id
.."_template", wsname_pre
:len())
100 mod_statusbar
.inform("wsname_post_"..id
, wsname_post
)
101 mod_statusbar
.inform("wsname_post_"..id
.."_template", wsname_post
:len())
104 mod_statusbar
.inform("wsname", screen
:mx_current():name())
105 mod_statusbar
.inform("wsname_full", ws_names
)
106 mod_statusbar
.inform("wsname_full_template", ws_names
:len())
107 mod_statusbar
.inform("wsname_pre", wsname_pre
)
108 mod_statusbar
.inform("wsname_pre_template", wsname_pre
:len())
109 mod_statusbar
.inform("wsname_post", wsname_post
)
110 mod_statusbar
.inform("wsname_post_template", wsname_post
:len())
113 if not ws_names_all
then
114 ws_names_all
= ws_names
116 ws_names_all
= ws_names_all
..wsname
.all_marker
..ws_names
122 ioncore
.region_i(inform
, "WScreen")
124 mod_statusbar
.inform("wsname_fullall", ws_names_all
)
125 mod_statusbar
.inform("wsname_fullall_template", string.len(ws_names_all
))
127 ioncore
.defer(function() mod_statusbar
.update() end)
130 local function setup_hooks()
133 hook
= ioncore
.get_hook("screen_managed_changed_hook")
135 hook
:add(get_ws_name
)
142 local function inform(screen
)
144 local id
= screen
:id()
146 if wsname
[id
] and wsname
[id
].template
then
147 template
= wsname
[id
].template
149 template
= wsname
.template
152 mod_statusbar
.inform("wsname_"..id
.."_template", template
)
157 mod_statusbar
.inform("wsname_template", wsname
.template
)
158 ioncore
.region_i(inform
, "WScreen")
160 mod_statusbar
.update(true)