2016-05-08 08:10:35 +02:00
|
|
|
---------------------------------------------------------------------------
|
2021-07-06 10:19:13 +02:00
|
|
|
--- The main AwesomeWM "bar" module.
|
|
|
|
--
|
2016-05-08 08:10:35 +02:00
|
|
|
-- This module allows you to easily create wibox and attach them to the edge of
|
|
|
|
-- a screen.
|
|
|
|
--
|
2020-02-19 16:16:46 +01:00
|
|
|
--@DOC_awful_wibar_default_EXAMPLE@
|
|
|
|
--
|
|
|
|
-- You can even have vertical bars too.
|
2021-07-06 10:19:13 +02:00
|
|
|
--
|
2020-02-19 16:16:46 +01:00
|
|
|
--@DOC_awful_wibar_left_EXAMPLE@
|
|
|
|
--
|
2016-05-08 08:10:35 +02:00
|
|
|
-- @author Emmanuel Lepage Vallee <elv1313@gmail.com>
|
|
|
|
-- @copyright 2016 Emmanuel Lepage Vallee
|
2019-06-06 08:44:00 +02:00
|
|
|
-- @popupmod awful.wibar
|
2021-03-29 09:39:46 +02:00
|
|
|
-- @supermodule awful.popup
|
2016-05-08 08:10:35 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
screen = screen,
|
|
|
|
client = client
|
|
|
|
}
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local tostring = tostring
|
|
|
|
local ipairs = ipairs
|
|
|
|
local error = error
|
|
|
|
local wibox = require("wibox")
|
|
|
|
local beautiful = require("beautiful")
|
2017-03-15 06:08:40 +01:00
|
|
|
local gdebug = require("gears.debug")
|
2016-05-08 08:10:35 +02:00
|
|
|
local placement = require("awful.placement")
|
2021-07-06 00:49:02 +02:00
|
|
|
local gtable = require("gears.table")
|
2016-05-08 08:10:35 +02:00
|
|
|
|
|
|
|
local function get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
|
|
|
local awfulwibar = { mt = {} }
|
|
|
|
|
|
|
|
--- Array of table with wiboxes inside.
|
|
|
|
-- It's an array so it is ordered.
|
|
|
|
local wiboxes = setmetatable({}, {__mode = "v"})
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
local opposite_margin = {
|
|
|
|
top = "bottom",
|
|
|
|
bottom = "top",
|
|
|
|
left = "right",
|
|
|
|
right = "left"
|
|
|
|
}
|
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
local align_map = {
|
|
|
|
top = "left",
|
|
|
|
left = "top",
|
|
|
|
bottom = "right",
|
|
|
|
right = "bottom",
|
|
|
|
centered = "centered"
|
|
|
|
}
|
|
|
|
|
2017-02-26 21:56:09 +01:00
|
|
|
--- If the wibar needs to be stretched to fill the screen.
|
2021-07-06 10:19:13 +02:00
|
|
|
--
|
|
|
|
-- @DOC_awful_wibar_stretch_EXAMPLE@
|
|
|
|
--
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @property stretch
|
2017-02-27 22:10:45 +01:00
|
|
|
-- @tparam boolean stretch
|
2019-12-22 05:55:38 +01:00
|
|
|
-- @propbeautiful
|
|
|
|
-- @propemits true false
|
2021-09-07 23:00:15 +02:00
|
|
|
-- @see align
|
2021-07-06 01:40:58 +02:00
|
|
|
|
|
|
|
--- How to align non-stretched wibars.
|
|
|
|
--
|
|
|
|
-- Values are:
|
|
|
|
--
|
2021-07-07 09:42:31 +02:00
|
|
|
-- * `"top"`
|
|
|
|
-- * `"bottom"`
|
|
|
|
-- * `"left"`
|
|
|
|
-- * `"right"`
|
|
|
|
-- * `"centered"`
|
2021-07-06 01:40:58 +02:00
|
|
|
--
|
2021-07-06 10:19:13 +02:00
|
|
|
-- @DOC_awful_wibar_align_EXAMPLE@
|
|
|
|
--
|
2021-07-06 01:40:58 +02:00
|
|
|
-- @property align
|
|
|
|
-- @tparam string align
|
|
|
|
-- @propbeautiful
|
|
|
|
-- @propemits true false
|
|
|
|
-- @see stretch
|
2017-02-27 22:10:45 +01:00
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
--- Margins on each side of the wibar.
|
|
|
|
--
|
2021-07-07 09:42:31 +02:00
|
|
|
-- It can either be a table with `top`, `bottom`, `left` and `right`
|
2021-09-07 23:00:15 +02:00
|
|
|
-- properties, or a single number that applies to all four sides.
|
2021-07-06 00:49:02 +02:00
|
|
|
--
|
2021-07-06 10:19:13 +02:00
|
|
|
-- @DOC_awful_wibar_margins_EXAMPLE@
|
|
|
|
--
|
2021-07-06 00:49:02 +02:00
|
|
|
-- @property margins
|
|
|
|
-- @tparam number|table margins
|
|
|
|
-- @propbeautiful
|
|
|
|
-- @propemits true false
|
|
|
|
|
2017-02-27 22:10:45 +01:00
|
|
|
--- If the wibar needs to be stretched to fill the screen.
|
2021-07-06 10:19:13 +02:00
|
|
|
--
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_stretch
|
2017-02-27 22:10:45 +01:00
|
|
|
-- @tparam boolean stretch
|
2017-02-26 21:56:09 +01:00
|
|
|
|
2021-07-06 03:08:06 +02:00
|
|
|
--- Allow or deny the tiled clients to cover the wibar.
|
|
|
|
--
|
2021-07-06 10:19:13 +02:00
|
|
|
-- In the example below, we can see that the first screen workarea
|
|
|
|
-- shrunk by the height of the wibar while the second screen is
|
|
|
|
-- unchanged.
|
|
|
|
--
|
|
|
|
-- @DOC_screen_wibar_workarea_EXAMPLE@
|
|
|
|
--
|
2021-09-07 23:00:15 +02:00
|
|
|
-- @property restrict_workarea
|
|
|
|
-- @tparam[opt=true] boolean restrict_workarea
|
2021-07-06 03:08:06 +02:00
|
|
|
-- @propemits true false
|
|
|
|
-- @see client.struts
|
|
|
|
-- @see screen.workarea
|
|
|
|
|
2021-07-06 07:18:28 +02:00
|
|
|
--- If there is both vertical and horizontal wibar, give more space to vertical ones.
|
|
|
|
--
|
2021-07-06 10:19:13 +02:00
|
|
|
-- By default, if multiple wibars risk overlapping, it will be resolved
|
|
|
|
-- by giving more space to the horizontal one:
|
|
|
|
--
|
|
|
|
-- ![wibar position](../images/AUTOGEN_awful_wibar_position.svg)
|
|
|
|
--
|
|
|
|
-- If this variable is to to `true`, it will behave like:
|
|
|
|
--
|
|
|
|
-- @DOC_awful_wibar_position2_EXAMPLE@
|
|
|
|
--
|
2021-07-06 07:18:28 +02:00
|
|
|
-- @beautiful beautiful.wibar_favor_vertical
|
|
|
|
-- @tparam[opt=false] boolean favor_vertical
|
|
|
|
|
2017-02-26 21:56:09 +01:00
|
|
|
--- The wibar border width.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_border_width
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam integer border_width
|
|
|
|
|
|
|
|
--- The wibar border color.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_border_color
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam string border_color
|
|
|
|
|
|
|
|
--- If the wibar is to be on top of other windows.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_ontop
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam boolean ontop
|
|
|
|
|
|
|
|
--- The wibar's mouse cursor.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_cursor
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam string cursor
|
|
|
|
|
|
|
|
--- The wibar opacity, between 0 and 1.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_opacity
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam number opacity
|
|
|
|
|
|
|
|
--- The window type (desktop, normal, dock, …).
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_type
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam string type
|
|
|
|
|
|
|
|
--- The wibar's width.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_width
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam integer width
|
|
|
|
|
|
|
|
--- The wibar's height.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_height
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam integer height
|
|
|
|
|
|
|
|
--- The wibar's background color.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_bg
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam color bg
|
|
|
|
|
|
|
|
--- The wibar's background image.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_bgimage
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam surface bgimage
|
|
|
|
|
|
|
|
--- The wibar's foreground (text) color.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_fg
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam color fg
|
|
|
|
|
|
|
|
--- The wibar's shape.
|
2017-02-27 22:20:47 +01:00
|
|
|
-- @beautiful beautiful.wibar_shape
|
2017-02-26 21:56:09 +01:00
|
|
|
-- @tparam gears.shape shape
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
--- The wibar's margins.
|
|
|
|
-- @beautiful beautiful.wibar_margins
|
|
|
|
-- @tparam number|table margins
|
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
--- The wibar's alignments.
|
|
|
|
-- @beautiful beautiful.wibar_align
|
|
|
|
-- @tparam string align
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
-- Compute the margin on one side
|
|
|
|
local function get_margin(w, position, auto_stop)
|
|
|
|
local h_or_w = (position == "top" or position == "bottom") and "height" or "width"
|
|
|
|
local ret = 0
|
|
|
|
|
|
|
|
for _, v in ipairs(wiboxes) do
|
|
|
|
-- Ignore the wibars placed after this one
|
|
|
|
if auto_stop and v == w then break end
|
|
|
|
|
|
|
|
if v.position == position and v.screen == w.screen and v.visible then
|
|
|
|
ret = ret + v[h_or_w]
|
2021-07-06 00:49:02 +02:00
|
|
|
|
|
|
|
local wb_margins = v.margins
|
|
|
|
|
|
|
|
if wb_margins then
|
|
|
|
ret = ret + wb_margins[position] + wb_margins[opposite_margin[position]]
|
|
|
|
end
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
2021-07-06 00:49:02 +02:00
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- `honor_workarea` cannot be used as it does modify the workarea itself.
|
|
|
|
-- a manual padding has to be generated.
|
|
|
|
local function get_margins(w)
|
|
|
|
local position = w.position
|
|
|
|
assert(position)
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
local margins = gtable.clone(w._private.margins)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
margins[position] = margins[position] + get_margin(w, position, true)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
|
|
|
-- Avoid overlapping wibars
|
2021-07-06 07:18:28 +02:00
|
|
|
if (position == "left" or position == "right") and not beautiful.wibar_favor_vertical then
|
2016-05-08 08:10:35 +02:00
|
|
|
margins.top = get_margin(w, "top" )
|
|
|
|
margins.bottom = get_margin(w, "bottom")
|
2021-07-06 07:18:28 +02:00
|
|
|
elseif (position == "top" or position == "bottom") and beautiful.wibar_favor_vertical then
|
|
|
|
margins.left = get_margin(w, "left" )
|
|
|
|
margins.right = get_margin(w, "right")
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return margins
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create the placement function
|
2021-07-06 01:40:58 +02:00
|
|
|
local function gen_placement(position, align, stretch)
|
2016-05-08 08:10:35 +02:00
|
|
|
local maximize = (position == "right" or position == "left") and
|
|
|
|
"maximize_vertically" or "maximize_horizontally"
|
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
local corner = nil
|
|
|
|
|
|
|
|
if align ~= "centered" then
|
|
|
|
if position == "right" or position == "left" then
|
|
|
|
corner = placement[align .. "_" .. position]
|
|
|
|
or placement[align_map[align] .. "_" .. position]
|
|
|
|
else
|
|
|
|
corner = placement[position .. "_" .. align]
|
|
|
|
or placement[position .. "_" .. align_map[align]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
corner = corner or placement[position]
|
|
|
|
|
|
|
|
return corner + (stretch and placement[maximize] or nil)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Attach the placement function.
|
2021-07-06 01:40:58 +02:00
|
|
|
local function attach(wb, position)
|
|
|
|
gen_placement(position, wb._private.align, wb._stretch)(wb, {
|
2016-05-08 08:10:35 +02:00
|
|
|
attach = true,
|
2021-09-07 23:00:15 +02:00
|
|
|
update_workarea = wb._private.restrict_workarea,
|
2016-05-08 08:10:35 +02:00
|
|
|
margins = get_margins(wb)
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Re-attach all wibars on a given wibar screen
|
|
|
|
local function reattach(wb)
|
|
|
|
local s = wb.screen
|
|
|
|
for _, w in ipairs(wiboxes) do
|
|
|
|
if w ~= wb and w.screen == s then
|
|
|
|
if w.detach_callback then
|
|
|
|
w.detach_callback()
|
|
|
|
w.detach_callback = nil
|
|
|
|
end
|
|
|
|
attach(w, w.position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- The wibox position.
|
2019-12-22 05:55:38 +01:00
|
|
|
--
|
|
|
|
-- The valid values are:
|
|
|
|
--
|
|
|
|
-- * left
|
|
|
|
-- * right
|
|
|
|
-- * top
|
|
|
|
-- * bottom
|
|
|
|
--
|
2021-07-06 10:19:13 +02:00
|
|
|
-- @DOC_awful_wibar_position_EXAMPLE@
|
|
|
|
--
|
2016-05-08 08:10:35 +02:00
|
|
|
-- @property position
|
2019-12-22 05:55:38 +01:00
|
|
|
-- @tparam string position Either "left", right", "top" or "bottom"
|
|
|
|
-- @propemits true false
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.get_position(wb)
|
2016-05-08 08:10:35 +02:00
|
|
|
return wb._position or "top"
|
|
|
|
end
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.set_position(wb, position, screen)
|
|
|
|
if position == wb._position then return end
|
|
|
|
|
|
|
|
if screen then
|
|
|
|
gdebug.deprecate("Use `wb.screen = screen` instead of awful.wibar.set_position", {deprecated_in=4})
|
|
|
|
end
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
-- Detach first to avoid any uneeded callbacks
|
|
|
|
if wb.detach_callback then
|
|
|
|
wb.detach_callback()
|
|
|
|
|
|
|
|
-- Avoid disconnecting twice, this produces a lot of warnings
|
|
|
|
wb.detach_callback = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Move the wibar to the end of the list to avoid messing up the others in
|
|
|
|
-- case there is stacked wibars on one side.
|
2021-07-06 02:00:11 +02:00
|
|
|
for k, w in ipairs(wiboxes) do
|
|
|
|
if w == wb then
|
|
|
|
table.remove(wiboxes, k)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
end
|
2021-07-06 02:00:11 +02:00
|
|
|
table.insert(wiboxes, wb)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
|
|
|
-- In case the position changed, it may be necessary to reset the size
|
|
|
|
if (wb._position == "left" or wb._position == "right")
|
|
|
|
and (position == "top" or position == "bottom") then
|
|
|
|
wb.height = math.ceil(beautiful.get_font_height(wb.font) * 1.5)
|
|
|
|
elseif (wb._position == "top" or wb._position == "bottom")
|
|
|
|
and (position == "left" or position == "right") then
|
|
|
|
wb.width = math.ceil(beautiful.get_font_height(wb.font) * 1.5)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set the new position
|
|
|
|
wb._position = position
|
|
|
|
|
|
|
|
-- Attach to the new position
|
|
|
|
attach(wb, position)
|
2017-02-13 22:08:30 +01:00
|
|
|
|
|
|
|
-- A way to skip reattach is required when first adding a wibar as it's not
|
|
|
|
-- in the `wiboxes` table yet and can't be added until it's attached.
|
2021-07-06 02:00:11 +02:00
|
|
|
if not wb._private.skip_reattach then
|
2017-02-13 22:08:30 +01:00
|
|
|
-- Changing the position will also cause the other margins to be invalidated.
|
|
|
|
-- For example, adding a wibar to the top will change the margins of any left
|
|
|
|
-- or right wibars. To solve, this, they need to be re-attached.
|
|
|
|
reattach(wb)
|
|
|
|
end
|
2019-12-22 05:55:38 +01:00
|
|
|
|
|
|
|
wb:emit_signal("property::position", position)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.get_stretch(w)
|
2016-05-08 08:10:35 +02:00
|
|
|
return w._stretch
|
|
|
|
end
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.set_stretch(w, value)
|
2016-05-08 08:10:35 +02:00
|
|
|
w._stretch = value
|
|
|
|
|
|
|
|
attach(w, w.position)
|
2019-12-22 05:55:38 +01:00
|
|
|
|
|
|
|
w:emit_signal("property::stretch", value)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
|
2021-09-07 23:00:15 +02:00
|
|
|
function awfulwibar.get_restrict_workarea(w)
|
|
|
|
return w._private.restrict_workarea
|
2021-07-06 03:08:06 +02:00
|
|
|
end
|
|
|
|
|
2021-09-07 23:00:15 +02:00
|
|
|
function awfulwibar.set_restrict_workarea(w, value)
|
|
|
|
w._private.restrict_workarea = value
|
2021-07-06 03:08:06 +02:00
|
|
|
|
|
|
|
attach(w, w.position)
|
|
|
|
|
2021-09-07 23:00:15 +02:00
|
|
|
w:emit_signal("property::restrict_workarea", value)
|
2021-07-06 03:08:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
function awfulwibar.set_margins(w, value)
|
|
|
|
if type(value) == "number" then
|
|
|
|
value = {
|
|
|
|
top = value,
|
|
|
|
bottom = value,
|
|
|
|
right = value,
|
|
|
|
left = value,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-07 23:00:15 +02:00
|
|
|
local old = gtable.crush({
|
2021-07-06 00:49:02 +02:00
|
|
|
left = 0,
|
|
|
|
right = 0,
|
|
|
|
top = 0,
|
|
|
|
bottom = 0
|
2021-09-07 23:00:15 +02:00
|
|
|
}, w._private.margins or {}, true)
|
|
|
|
|
|
|
|
value = gtable.crush(old, value or {}, true)
|
2021-07-06 00:49:02 +02:00
|
|
|
|
|
|
|
w._private.margins = value
|
|
|
|
|
|
|
|
attach(w, w.position)
|
|
|
|
|
|
|
|
w:emit_signal("property::margins", value)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Allow each margins to be set individually.
|
|
|
|
local function meta_margins(self)
|
|
|
|
return setmetatable({}, {
|
|
|
|
__index = self._private.margins,
|
|
|
|
__newindex = function(_, k, v)
|
|
|
|
self._private.margins[k] = v
|
|
|
|
awfulwibar.set_margins(self, self._private.margins)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function awfulwibar.get_margins(self)
|
|
|
|
return self._private.meta_margins
|
|
|
|
end
|
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
|
|
|
|
function awfulwibar.get_align(self)
|
|
|
|
return self._private.align
|
|
|
|
end
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.set_align(self, value, screen)
|
|
|
|
if value == "center" then
|
|
|
|
gdebug.deprecate("awful.wibar.align(wb, 'center' is deprecated, use 'centered'", {deprecated_in=4})
|
|
|
|
value = "centered"
|
|
|
|
end
|
|
|
|
|
|
|
|
if screen then
|
|
|
|
gdebug.deprecate("awful.wibar.align 'screen' argument is deprecated", {deprecated_in=4})
|
|
|
|
end
|
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
assert(align_map[value])
|
|
|
|
|
|
|
|
self._private.align = value
|
|
|
|
|
|
|
|
attach(self, self.position)
|
|
|
|
|
|
|
|
self:emit_signal("property::align", value)
|
|
|
|
end
|
|
|
|
|
2016-05-15 09:50:39 +02:00
|
|
|
--- Remove a wibar.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @method remove
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.remove(self)
|
2016-05-15 09:50:39 +02:00
|
|
|
self.visible = false
|
|
|
|
|
|
|
|
if self.detach_callback then
|
|
|
|
self.detach_callback()
|
|
|
|
self.detach_callback = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, w in ipairs(wiboxes) do
|
|
|
|
if w == self then
|
|
|
|
table.remove(wiboxes, k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self._screen = nil
|
|
|
|
end
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
--- Attach a wibox to a screen.
|
2016-05-19 06:49:44 +02:00
|
|
|
--
|
|
|
|
-- This function has been moved to the `awful.placement` module. Calling this
|
|
|
|
-- no longer does anything.
|
|
|
|
--
|
2016-05-08 08:10:35 +02:00
|
|
|
-- @param wb The wibox to attach.
|
|
|
|
-- @param position The position of the wibox: top, bottom, left or right.
|
|
|
|
-- @param screen The screen to attach to
|
2016-05-19 06:49:44 +02:00
|
|
|
-- @see awful.placement
|
2016-05-08 08:10:35 +02:00
|
|
|
-- @deprecated awful.wibar.attach
|
2021-07-06 02:00:11 +02:00
|
|
|
local function legacy_attach(wb, position, screen) --luacheck: no unused args
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("awful.wibar.attach is deprecated, use the 'attach' property"..
|
|
|
|
" of awful.placement. This method doesn't do anything anymore",
|
|
|
|
{deprecated_in=4}
|
2016-05-08 08:10:35 +02:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Align a wibox.
|
|
|
|
--
|
|
|
|
-- Supported alignment are:
|
|
|
|
--
|
|
|
|
-- * top_left
|
|
|
|
-- * top_right
|
|
|
|
-- * bottom_left
|
|
|
|
-- * bottom_right
|
|
|
|
-- * left
|
|
|
|
-- * right
|
|
|
|
-- * top
|
|
|
|
-- * bottom
|
|
|
|
-- * centered
|
|
|
|
-- * center_vertical
|
|
|
|
-- * center_horizontal
|
|
|
|
--
|
|
|
|
-- @param wb The wibox.
|
|
|
|
-- @param align The alignment
|
|
|
|
-- @param screen This argument is deprecated. It is not used. Use wb.screen
|
|
|
|
-- directly.
|
|
|
|
-- @deprecated awful.wibar.align
|
|
|
|
-- @see awful.placement.align
|
2021-07-06 02:00:11 +02:00
|
|
|
local function legacy_align(wb, align, screen) --luacheck: no unused args
|
2016-05-08 08:10:35 +02:00
|
|
|
if align == "center" then
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("awful.wibar.align(wb, 'center' is deprecated, use 'centered'", {deprecated_in=4})
|
2016-05-08 08:10:35 +02:00
|
|
|
align = "centered"
|
|
|
|
end
|
|
|
|
|
|
|
|
if screen then
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("awful.wibar.align 'screen' argument is deprecated", {deprecated_in=4})
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
2016-05-19 06:49:44 +02:00
|
|
|
if placement[align] then
|
|
|
|
return placement[align](wb)
|
|
|
|
end
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Stretch a wibox so it takes all screen width or height.
|
|
|
|
--
|
|
|
|
-- **This function has been removed.**
|
|
|
|
--
|
|
|
|
-- @deprecated awful.wibox.stretch
|
|
|
|
-- @see awful.placement
|
2016-12-09 18:03:03 +01:00
|
|
|
-- @see awful.wibar.stretch
|
2016-05-08 08:10:35 +02:00
|
|
|
|
|
|
|
--- Create a new wibox and attach it to a screen edge.
|
|
|
|
-- You can add also position key with value top, bottom, left or right.
|
|
|
|
-- You can also use width or height in % and set align to center, right or left.
|
|
|
|
-- You can also set the screen key with a screen number to attach the wibox.
|
2016-05-19 06:40:40 +02:00
|
|
|
-- If not specified, the primary screen is assumed.
|
|
|
|
-- @see wibox
|
2017-11-24 05:19:41 +01:00
|
|
|
-- @tparam[opt=nil] table args
|
|
|
|
-- @tparam string args.position The position.
|
|
|
|
-- @tparam string args.stretch If the wibar need to be stretched to fill the screen.
|
2021-09-07 23:00:15 +02:00
|
|
|
-- @tparam boolean args.restrict_workarea Allow or deny the tiled clients to cover the wibar.
|
2021-07-06 10:19:13 +02:00
|
|
|
-- @tparam string args.align How to align non-stretched wibars.
|
|
|
|
-- @tparam table|number args.margins The wibar margins.
|
2017-11-24 05:19:41 +01:00
|
|
|
--@DOC_wibox_constructor_COMMON@
|
2016-05-19 06:40:40 +02:00
|
|
|
-- @return The new wibar
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct awful.wibar
|
2017-11-24 05:19:41 +01:00
|
|
|
function awfulwibar.new(args)
|
|
|
|
args = args or {}
|
|
|
|
local position = args.position or "top"
|
2016-05-08 08:10:35 +02:00
|
|
|
local has_to_stretch = true
|
2017-11-24 05:19:41 +01:00
|
|
|
local screen = get_screen(args.screen or 1)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2017-11-24 05:19:41 +01:00
|
|
|
args.type = args.type or "dock"
|
2016-05-08 08:10:35 +02:00
|
|
|
|
|
|
|
if position ~= "top" and position ~="bottom"
|
|
|
|
and position ~= "left" and position ~= "right" then
|
|
|
|
error("Invalid position in awful.wibar(), you may only use"
|
|
|
|
.. " 'top', 'bottom', 'left' and 'right'")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set default size
|
|
|
|
if position == "left" or position == "right" then
|
2017-11-24 05:19:41 +01:00
|
|
|
args.width = args.width or beautiful["wibar_width"]
|
|
|
|
or math.ceil(beautiful.get_font_height(args.font) * 1.5)
|
|
|
|
if args.height then
|
2016-05-08 08:10:35 +02:00
|
|
|
has_to_stretch = false
|
2017-11-24 05:19:41 +01:00
|
|
|
if args.screen then
|
|
|
|
local hp = tostring(args.height):match("(%d+)%%")
|
2016-05-08 08:10:35 +02:00
|
|
|
if hp then
|
2017-11-24 05:19:41 +01:00
|
|
|
args.height = math.ceil(screen.geometry.height * hp / 100)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2017-11-24 05:19:41 +01:00
|
|
|
args.height = args.height or beautiful["wibar_height"]
|
|
|
|
or math.ceil(beautiful.get_font_height(args.font) * 1.5)
|
|
|
|
if args.width then
|
2016-05-08 08:10:35 +02:00
|
|
|
has_to_stretch = false
|
2017-11-24 05:19:41 +01:00
|
|
|
if args.screen then
|
|
|
|
local wp = tostring(args.width):match("(%d+)%%")
|
2016-05-08 08:10:35 +02:00
|
|
|
if wp then
|
2017-11-24 05:19:41 +01:00
|
|
|
args.width = math.ceil(screen.geometry.width * wp / 100)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-24 05:19:41 +01:00
|
|
|
args.screen = nil
|
2016-05-19 06:05:47 +02:00
|
|
|
|
2017-02-26 21:56:09 +01:00
|
|
|
-- The C code scans the table directly, so metatable magic cannot be used.
|
|
|
|
for _, prop in ipairs {
|
2017-02-27 22:10:45 +01:00
|
|
|
"border_width", "border_color", "font", "opacity", "ontop", "cursor",
|
2021-07-06 01:40:58 +02:00
|
|
|
"bgimage", "bg", "fg", "type", "stretch", "shape", "margins", "align"
|
2017-02-26 21:56:09 +01:00
|
|
|
} do
|
2017-11-24 05:19:41 +01:00
|
|
|
if (args[prop] == nil) and beautiful["wibar_"..prop] ~= nil then
|
|
|
|
args[prop] = beautiful["wibar_"..prop]
|
2017-02-26 21:56:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-24 05:19:41 +01:00
|
|
|
local w = wibox(args)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 01:40:58 +02:00
|
|
|
w._private.align = (args.align and align_map[args.align]) and args.align or "centered"
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
w._private.margins = {
|
|
|
|
left = 0,
|
|
|
|
right = 0,
|
|
|
|
top = 0,
|
|
|
|
bottom = 0
|
|
|
|
}
|
|
|
|
w._private.meta_margins = meta_margins(w)
|
|
|
|
|
2021-09-07 23:00:15 +02:00
|
|
|
w._private.restrict_workarea = true
|
2021-07-06 03:08:06 +02:00
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
-- `w` needs to be inserted in `wiboxes` before reattach or its own offset
|
|
|
|
-- will not be taken into account by the "older" wibars when `reattach` is
|
|
|
|
-- called. `skip_reattach` is required.
|
|
|
|
w._private.skip_reattach = true
|
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
w.screen = screen
|
2016-05-15 09:50:39 +02:00
|
|
|
w._screen = screen --HACK When a screen is removed, then getbycoords wont work
|
2017-11-24 05:19:41 +01:00
|
|
|
w._stretch = args.stretch == nil and has_to_stretch or args.stretch
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
if args.visible == nil then w.visible = true end
|
2021-07-06 01:40:58 +02:00
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
gtable.crush(w, awfulwibar, true)
|
|
|
|
gtable.crush(w, args, false)
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
-- Now, let set_position behave normally.
|
|
|
|
w._private.skip_reattach = false
|
2016-05-08 08:10:35 +02:00
|
|
|
|
2021-07-06 00:49:02 +02:00
|
|
|
awfulwibar.set_margins(w, args.margins)
|
|
|
|
|
2017-02-13 22:08:30 +01:00
|
|
|
-- Force all the wibars to be moved
|
|
|
|
reattach(w)
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
w:connect_signal("property::visible", function() reattach(w) end)
|
|
|
|
|
2018-12-27 03:16:33 +01:00
|
|
|
assert(w.buttons)
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.screen.connect_signal("removed", function(s)
|
2017-02-02 22:42:20 +01:00
|
|
|
local wibars = {}
|
2016-05-08 08:10:35 +02:00
|
|
|
for _, wibar in ipairs(wiboxes) do
|
2016-05-15 09:50:39 +02:00
|
|
|
if wibar._screen == s then
|
2017-02-02 22:42:20 +01:00
|
|
|
table.insert(wibars, wibar)
|
2016-05-08 08:10:35 +02:00
|
|
|
end
|
|
|
|
end
|
2017-02-02 22:42:20 +01:00
|
|
|
for _, wibar in ipairs(wibars) do
|
|
|
|
wibar:remove()
|
|
|
|
end
|
2016-05-08 08:10:35 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
function awfulwibar.mt:__call(...)
|
|
|
|
return awfulwibar.new(...)
|
|
|
|
end
|
|
|
|
|
2021-07-06 02:00:11 +02:00
|
|
|
function awfulwibar.mt:__index(_, k)
|
|
|
|
if k == "align" then
|
|
|
|
return legacy_align
|
|
|
|
elseif k == "attach" then
|
|
|
|
return legacy_attach
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
--@DOC_wibox_COMMON@
|
|
|
|
|
2019-12-22 05:55:38 +01:00
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
2016-05-08 08:10:35 +02:00
|
|
|
return setmetatable(awfulwibar, awfulwibar.mt)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|