Ported wibox.widget to lua 5.2
Tested with 5.1: all good Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
This commit is contained in:
parent
4e67027a97
commit
f73e0b44c0
|
@ -13,10 +13,11 @@ local setmetatable = setmetatable
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local type = type
|
local type = type
|
||||||
|
|
||||||
module("wibox.widget.background")
|
-- wibox.widget.background
|
||||||
|
local background = { mt = {} }
|
||||||
|
|
||||||
--- Draw this widget
|
--- Draw this widget
|
||||||
function draw(box, wibox, cr, width, height)
|
function background.draw(box, wibox, cr, width, height)
|
||||||
if not box.widget then
|
if not box.widget then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -46,7 +47,7 @@ function draw(box, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit this widget into the given area
|
--- Fit this widget into the given area
|
||||||
function fit(box, width, height)
|
function background.fit(box, width, height)
|
||||||
if not box.widget then
|
if not box.widget then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
|
@ -55,7 +56,7 @@ function fit(box, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the widget that is drawn on top of the background
|
--- Set the widget that is drawn on top of the background
|
||||||
function set_widget(box, widget)
|
function background.set_widget(box, widget)
|
||||||
if box.widget then
|
if box.widget then
|
||||||
box.widget:disconnect_signal("widget::updated", box._emit_updated)
|
box.widget:disconnect_signal("widget::updated", box._emit_updated)
|
||||||
end
|
end
|
||||||
|
@ -68,7 +69,7 @@ function set_widget(box, widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the background to use
|
--- Set the background to use
|
||||||
function set_bg(box, bg)
|
function background.set_bg(box, bg)
|
||||||
if bg then
|
if bg then
|
||||||
box.background = color(bg)
|
box.background = color(bg)
|
||||||
else
|
else
|
||||||
|
@ -78,7 +79,7 @@ function set_bg(box, bg)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the foreground to use
|
--- Set the foreground to use
|
||||||
function set_fg(box, fg)
|
function background.set_fg(box, fg)
|
||||||
if fg then
|
if fg then
|
||||||
box.foreground = color(fg)
|
box.foreground = color(fg)
|
||||||
else
|
else
|
||||||
|
@ -88,7 +89,7 @@ function set_fg(box, fg)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the background image to use
|
--- Set the background image to use
|
||||||
function set_bgimage(box, image)
|
function background.set_bgimage(box, image)
|
||||||
box.bgimage = surface.load(image)
|
box.bgimage = surface.load(image)
|
||||||
box._emit_updated()
|
box._emit_updated()
|
||||||
end
|
end
|
||||||
|
@ -96,7 +97,7 @@ end
|
||||||
local function new()
|
local function new()
|
||||||
local ret = base.make_widget()
|
local ret = base.make_widget()
|
||||||
|
|
||||||
for k, v in pairs(_M) do
|
for k, v in pairs(background) do
|
||||||
if type(v) == "function" then
|
if type(v) == "function" then
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
end
|
end
|
||||||
|
@ -109,6 +110,10 @@ local function new()
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
function background.mt:__call(...)
|
||||||
|
return new(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(background, background.mt)
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -10,19 +10,20 @@ local pairs = pairs
|
||||||
local type = type
|
local type = type
|
||||||
local table = table
|
local table = table
|
||||||
|
|
||||||
module("wibox.widget.base")
|
-- wibox.widget.base
|
||||||
|
local base = {}
|
||||||
|
|
||||||
--- Set/get a widget's buttons
|
--- Set/get a widget's buttons
|
||||||
function buttons(widget, buttons)
|
function base.buttons(widget, _buttons)
|
||||||
if buttons then
|
if _buttons then
|
||||||
widget.widget_buttons = buttons
|
widget.widget_buttons = _buttons
|
||||||
end
|
end
|
||||||
|
|
||||||
return widget.widget_buttons
|
return widget.widget_buttons
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Handle a button event on a widget. This is used internally.
|
--- Handle a button event on a widget. This is used internally.
|
||||||
function handle_button(event, widget, x, y, button, modifiers)
|
function base.handle_button(event, widget, x, y, button, modifiers)
|
||||||
local function is_any(mod)
|
local function is_any(mod)
|
||||||
return #mod == 1 and mod[1] == "Any"
|
return #mod == 1 and mod[1] == "Any"
|
||||||
end
|
end
|
||||||
|
@ -62,7 +63,7 @@ end
|
||||||
-- that the needed signals are added and mouse input handling is set up.
|
-- that the needed signals are added and mouse input handling is set up.
|
||||||
-- @param proxy If this is set, the returned widget will be a proxy for this
|
-- @param proxy If this is set, the returned widget will be a proxy for this
|
||||||
-- widget. It will be equivalent to this widget.
|
-- widget. It will be equivalent to this widget.
|
||||||
function make_widget(proxy)
|
function base.make_widget(proxy)
|
||||||
local ret = object()
|
local ret = object()
|
||||||
|
|
||||||
-- This signal is used by layouts to find out when they have to update.
|
-- This signal is used by layouts to find out when they have to update.
|
||||||
|
@ -75,14 +76,14 @@ function make_widget(proxy)
|
||||||
|
|
||||||
-- No buttons yet
|
-- No buttons yet
|
||||||
ret.widget_buttons = {}
|
ret.widget_buttons = {}
|
||||||
ret.buttons = buttons
|
ret.buttons = base.buttons
|
||||||
|
|
||||||
-- Make buttons work
|
-- Make buttons work
|
||||||
ret:connect_signal("button::press", function(...)
|
ret:connect_signal("button::press", function(...)
|
||||||
return handle_button("press", ...)
|
return base.handle_button("press", ...)
|
||||||
end)
|
end)
|
||||||
ret:connect_signal("button::release", function(...)
|
ret:connect_signal("button::release", function(...)
|
||||||
return handle_button("release", ...)
|
return base.handle_button("release", ...)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if proxy then
|
if proxy then
|
||||||
|
@ -98,7 +99,7 @@ end
|
||||||
|
|
||||||
--- Do some sanity checking on widget. This function raises a lua error if
|
--- Do some sanity checking on widget. This function raises a lua error if
|
||||||
-- widget is not a valid widget.
|
-- widget is not a valid widget.
|
||||||
function check_widget(widget)
|
function base.check_widget(widget)
|
||||||
debug.assert(type(widget) == "table")
|
debug.assert(type(widget) == "table")
|
||||||
for k, func in pairs({ "draw", "fit", "add_signal", "connect_signal", "disconnect_signal" }) do
|
for k, func in pairs({ "draw", "fit", "add_signal", "connect_signal", "disconnect_signal" }) do
|
||||||
debug.assert(type(widget[func]) == "function", func .. " is not a function")
|
debug.assert(type(widget[func]) == "function", func .. " is not a function")
|
||||||
|
@ -109,4 +110,6 @@ function check_widget(widget)
|
||||||
debug.assert(type(height) == "number")
|
debug.assert(type(height) == "number")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return base
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -12,10 +12,11 @@ local type = type
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
local print = print
|
local print = print
|
||||||
|
|
||||||
module("wibox.widget.imagebox")
|
-- wibox.widget.imagebox
|
||||||
|
local imagebox = { mt = {} }
|
||||||
|
|
||||||
--- Draw an imagebox with the given cairo context in the given geometry.
|
--- Draw an imagebox with the given cairo context in the given geometry.
|
||||||
function draw(box, wibox, cr, width, height)
|
function imagebox.draw(box, wibox, cr, width, height)
|
||||||
if not box.image then return end
|
if not box.image then return end
|
||||||
|
|
||||||
cr:save()
|
cr:save()
|
||||||
|
@ -37,7 +38,7 @@ function draw(box, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the imagebox into the given geometry
|
--- Fit the imagebox into the given geometry
|
||||||
function fit(box, width, height)
|
function imagebox.fit(box, width, height)
|
||||||
if not box.image then
|
if not box.image then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
|
@ -70,7 +71,7 @@ end
|
||||||
--- Set an imagebox' image
|
--- Set an imagebox' image
|
||||||
-- @param image Either a string or a cairo image surface. A string is
|
-- @param image Either a string or a cairo image surface. A string is
|
||||||
-- interpreted as the path to a png image file.
|
-- interpreted as the path to a png image file.
|
||||||
function set_image(box, image)
|
function imagebox.set_image(box, image)
|
||||||
local image = image
|
local image = image
|
||||||
|
|
||||||
if type(image) == "string" then
|
if type(image) == "string" then
|
||||||
|
@ -101,7 +102,7 @@ end
|
||||||
--- Should the image be resized to fit into the available space?
|
--- Should the image be resized to fit into the available space?
|
||||||
-- @param allowed If false, the image will be clipped, else it will be resized
|
-- @param allowed If false, the image will be clipped, else it will be resized
|
||||||
-- to fit into the available space.
|
-- to fit into the available space.
|
||||||
function set_resize(box, allowed)
|
function imagebox.set_resize(box, allowed)
|
||||||
box.resize_forbidden = not allowed
|
box.resize_forbidden = not allowed
|
||||||
box:emit_signal("widget::updated")
|
box:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
|
@ -110,7 +111,7 @@ end
|
||||||
local function new()
|
local function new()
|
||||||
local ret = base.make_widget()
|
local ret = base.make_widget()
|
||||||
|
|
||||||
for k, v in pairs(_M) do
|
for k, v in pairs(imagebox) do
|
||||||
if type(v) == "function" then
|
if type(v) == "function" then
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
end
|
end
|
||||||
|
@ -119,6 +120,10 @@ local function new()
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
function imagebox.mt:__call(...)
|
||||||
|
return new(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(imagebox, imagebox.mt)
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -4,12 +4,15 @@
|
||||||
-- @release @AWESOME_VERSION@
|
-- @release @AWESOME_VERSION@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
require("wibox.widget.base")
|
-- wibox.widget
|
||||||
require("wibox.widget.textbox")
|
|
||||||
require("wibox.widget.imagebox")
|
|
||||||
require("wibox.widget.background")
|
|
||||||
require("wibox.widget.systray")
|
|
||||||
|
|
||||||
module("wibox.widget")
|
return
|
||||||
|
{
|
||||||
|
base = require("wibox.widget.base");
|
||||||
|
textbox = require("wibox.widget.textbox");
|
||||||
|
imagebox = require("wibox.widget.imagebox");
|
||||||
|
background = require("wibox.widget.background");
|
||||||
|
systray = require("wibox.widget.systray");
|
||||||
|
}
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -11,13 +11,14 @@ local capi = { awesome = awesome }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local error = error
|
local error = error
|
||||||
|
|
||||||
module("wibox.widget.systray")
|
-- wibox.widget.systray
|
||||||
|
local systray = { mt = {} }
|
||||||
|
|
||||||
local created_systray = false
|
local created_systray = false
|
||||||
local horizontal = true
|
local horizontal = true
|
||||||
local base_size = nil
|
local base_size = nil
|
||||||
|
|
||||||
function draw(box, wibox, cr, width, height)
|
function systray.draw(box, wibox, cr, width, height)
|
||||||
local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
||||||
local num_entries = capi.awesome.systray()
|
local num_entries = capi.awesome.systray()
|
||||||
local bg = beautiful.bg_systray or beautiful.bg_normal
|
local bg = beautiful.bg_systray or beautiful.bg_normal
|
||||||
|
@ -36,7 +37,7 @@ function draw(box, wibox, cr, width, height)
|
||||||
capi.awesome.systray(wibox.drawin, x, y, base, horizontal, bg)
|
capi.awesome.systray(wibox.drawin, x, y, base, horizontal, bg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fit(box, width, height)
|
function systray.fit(box, width, height)
|
||||||
local num_entries = capi.awesome.systray()
|
local num_entries = capi.awesome.systray()
|
||||||
local base = base_size
|
local base = base_size
|
||||||
if base == nil then
|
if base == nil then
|
||||||
|
@ -60,8 +61,8 @@ local function new()
|
||||||
end
|
end
|
||||||
created_systray = true
|
created_systray = true
|
||||||
|
|
||||||
ret.fit = fit
|
ret.fit = systray.fit
|
||||||
ret.draw = draw
|
ret.draw = systray.draw
|
||||||
ret.set_base_size = function(_, size) base_size = size end
|
ret.set_base_size = function(_, size) base_size = size end
|
||||||
ret.set_horizontal = function(_, horiz) horizontal = horiz end
|
ret.set_horizontal = function(_, horiz) horizontal = horiz end
|
||||||
|
|
||||||
|
@ -72,6 +73,10 @@ local function new()
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
function systray.mt:__call(...)
|
||||||
|
return new(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(systray, systray.mt)
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
|
@ -16,7 +16,8 @@ local setmetatable = setmetatable
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local error = error
|
local error = error
|
||||||
|
|
||||||
module("wibox.widget.textbox")
|
-- wibox.widget.textbox
|
||||||
|
local textbox = { mt = {} }
|
||||||
|
|
||||||
-- Setup a pango layout for the given textbox and cairo context
|
-- Setup a pango layout for the given textbox and cairo context
|
||||||
local function setup_layout(box, width, height)
|
local function setup_layout(box, width, height)
|
||||||
|
@ -26,7 +27,7 @@ local function setup_layout(box, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Draw the given textbox on the given cairo context in the given geometry
|
--- Draw the given textbox on the given cairo context in the given geometry
|
||||||
function draw(box, wibox, cr, width, height)
|
function textbox.draw(box, wibox, cr, width, height)
|
||||||
cr:update_layout(box._layout)
|
cr:update_layout(box._layout)
|
||||||
setup_layout(box, width, height)
|
setup_layout(box, width, height)
|
||||||
local ink, logical = box._layout:get_pixel_extents()
|
local ink, logical = box._layout:get_pixel_extents()
|
||||||
|
@ -41,7 +42,7 @@ function draw(box, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the given textbox
|
--- Fit the given textbox
|
||||||
function fit(box, width, height)
|
function textbox.fit(box, width, height)
|
||||||
setup_layout(box, width, height)
|
setup_layout(box, width, height)
|
||||||
local ink, logical = box._layout:get_pixel_extents()
|
local ink, logical = box._layout:get_pixel_extents()
|
||||||
return logical.width, logical.height
|
return logical.width, logical.height
|
||||||
|
@ -49,7 +50,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' text.
|
--- Set a textbox' text.
|
||||||
-- @param text The text to set. This can contain pango markup (e.g. <b>bold</b>)
|
-- @param text The text to set. This can contain pango markup (e.g. <b>bold</b>)
|
||||||
function set_markup(box, text)
|
function textbox.set_markup(box, text)
|
||||||
local attr, parsed = Pango.parse_markup(text, -1, 0)
|
local attr, parsed = Pango.parse_markup(text, -1, 0)
|
||||||
-- In case of error, attr is false and parsed is an error message
|
-- In case of error, attr is false and parsed is an error message
|
||||||
if not attr then error(parsed) end
|
if not attr then error(parsed) end
|
||||||
|
@ -61,7 +62,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' text.
|
--- Set a textbox' text.
|
||||||
-- @param text The text to display. Pango markup is ignored and shown as-is.
|
-- @param text The text to display. Pango markup is ignored and shown as-is.
|
||||||
function set_text(box, text)
|
function textbox.set_text(box, text)
|
||||||
box._layout.text = text
|
box._layout.text = text
|
||||||
box._layout.attributes = nil
|
box._layout.attributes = nil
|
||||||
box:emit_signal("widget::updated")
|
box:emit_signal("widget::updated")
|
||||||
|
@ -69,7 +70,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' ellipsize mode.
|
--- Set a textbox' ellipsize mode.
|
||||||
-- @param mode Where should long lines be shortened? "start", "middle" or "end"
|
-- @param mode Where should long lines be shortened? "start", "middle" or "end"
|
||||||
function set_ellipsize(box, mode)
|
function textbox.set_ellipsize(box, mode)
|
||||||
local allowed = { none = "NONE", start = "START", middle = "MIDDLE", ["end"] = "END" }
|
local allowed = { none = "NONE", start = "START", middle = "MIDDLE", ["end"] = "END" }
|
||||||
if allowed[mode] then
|
if allowed[mode] then
|
||||||
box._layout:set_ellipsize(allowed[mode])
|
box._layout:set_ellipsize(allowed[mode])
|
||||||
|
@ -79,7 +80,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' wrap mode.
|
--- Set a textbox' wrap mode.
|
||||||
-- @param mode Where to wrap? After "word", "char" or "word_char"
|
-- @param mode Where to wrap? After "word", "char" or "word_char"
|
||||||
function set_wrap(box, mode)
|
function textbox.set_wrap(box, mode)
|
||||||
local allowed = { word = "WORD", char = "CHAR", word_char = "WORD_CHAR" }
|
local allowed = { word = "WORD", char = "CHAR", word_char = "WORD_CHAR" }
|
||||||
if allowed[mode] then
|
if allowed[mode] then
|
||||||
box._layout:set_wrap(allowed[mode])
|
box._layout:set_wrap(allowed[mode])
|
||||||
|
@ -89,7 +90,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' vertical alignment
|
--- Set a textbox' vertical alignment
|
||||||
-- @param mode Where should the textbox be drawn? "top", "center" or "bottom"
|
-- @param mode Where should the textbox be drawn? "top", "center" or "bottom"
|
||||||
function set_valign(box, mode)
|
function textbox.set_valign(box, mode)
|
||||||
local allowed = { top = true, center = true, bottom = true }
|
local allowed = { top = true, center = true, bottom = true }
|
||||||
if allowed[mode] then
|
if allowed[mode] then
|
||||||
box._valign = mode
|
box._valign = mode
|
||||||
|
@ -99,7 +100,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' horizontal alignment
|
--- Set a textbox' horizontal alignment
|
||||||
-- @param mode Where should the textbox be drawn? "left", "center" or "right"
|
-- @param mode Where should the textbox be drawn? "left", "center" or "right"
|
||||||
function set_align(box, mode)
|
function textbox.set_align(box, mode)
|
||||||
local allowed = { left = "LEFT", center = "CENTER", right = "RIGHT" }
|
local allowed = { left = "LEFT", center = "CENTER", right = "RIGHT" }
|
||||||
if allowed[mode] then
|
if allowed[mode] then
|
||||||
box._layout:set_alignment(allowed[mode])
|
box._layout:set_alignment(allowed[mode])
|
||||||
|
@ -109,7 +110,7 @@ end
|
||||||
|
|
||||||
--- Set a textbox' font
|
--- Set a textbox' font
|
||||||
-- @param font The font description as string
|
-- @param font The font description as string
|
||||||
function set_font(box, font)
|
function textbox.set_font(box, font)
|
||||||
box._layout:set_font_description(beautiful.get_font(font))
|
box._layout:set_font_description(beautiful.get_font(font))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ end
|
||||||
local function new()
|
local function new()
|
||||||
local ret = base.make_widget()
|
local ret = base.make_widget()
|
||||||
|
|
||||||
for k, v in pairs(_M) do
|
for k, v in pairs(textbox) do
|
||||||
if type(v) == "function" then
|
if type(v) == "function" then
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
end
|
end
|
||||||
|
@ -135,6 +136,10 @@ local function new()
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
function textbox.mt:__call(...)
|
||||||
|
return new(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(textbox, textbox.mt)
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue