Move wibox.layout.rect_to_device_geometry to wibox.widget

Having two modules named "base" is confusing and "wibox.layout" doesn't contain
much useful stuff. This is a first step for removing wibox.layout by moving a
function which should only ever be used internally in awesome.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-07-25 15:52:53 +02:00
parent 16a1ef0f48
commit 19b9bfc46e
3 changed files with 18 additions and 21 deletions

View File

@ -5,29 +5,12 @@
-- @classmod wibox.layout.base
---------------------------------------------------------------------------
local pairs = pairs
local pcall = pcall
local print = print
local min = math.min
local max = math.max
local wbase = require("wibox.widget.base")
local base = {}
--- Figure out the geometry in device coordinate space. This gives only tight
-- bounds if no rotations by non-multiples of 90° are used.
function base.rect_to_device_geometry(cr, x, y, width, height)
local x1, y1 = cr:user_to_device(x, y)
local x2, y2 = cr:user_to_device(x, y + height)
local x3, y3 = cr:user_to_device(x + width, y + height)
local x4, y4 = cr:user_to_device(x + width, y)
local x = min(x1, x2, x3, x4)
local y = min(y1, y2, y3, y4)
local width = max(x1, x2, x3, x4) - x
local height = max(y1, y2, y3, y4) - y
return x, y, width, height
end
--- Fit a widget for the given available width and height
-- @param widget The widget to fit (this uses widget:fit(width, height)).
-- @param width The available width for the widget
@ -73,7 +56,7 @@ function base.draw_widget(wibox, cr, widget, x, y, width, height)
end
-- Register the widget for input handling
wibox:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))
wibox:widget_at(widget, wbase.rect_to_device_geometry(cr, 0, 0, width, height))
cr:restore()
end

View File

@ -15,6 +15,21 @@ local table = table
local base = {}
--- Figure out the geometry in device coordinate space. This gives only tight
-- bounds if no rotations by non-multiples of 90° are used.
function base.rect_to_device_geometry(cr, x, y, width, height)
local x1, y1 = cr:user_to_device(x, y)
local x2, y2 = cr:user_to_device(x, y + height)
local x3, y3 = cr:user_to_device(x + width, y + height)
local x4, y4 = cr:user_to_device(x + width, y)
local x = math.min(x1, x2, x3, x4)
local y = math.min(y1, y2, y3, y4)
local width = math.max(x1, x2, x3, x4) - x
local height = math.max(y1, y2, y3, y4) - y
return x, y, width, height
end
--- Set/get a widget's buttons
function base:buttons(_buttons)
if _buttons then

View File

@ -6,7 +6,6 @@
---------------------------------------------------------------------------
local wbase = require("wibox.widget.base")
local lbase = require("wibox.layout.base")
local beautiful = require("beautiful")
local capi = { awesome = awesome }
local setmetatable = setmetatable
@ -20,7 +19,7 @@ local base_size = nil
local reverse = false
function systray:draw(wibox, cr, width, height)
local x, y, _, _ = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
local x, y, _, _ = wbase.rect_to_device_geometry(cr, 0, 0, width, height)
local num_entries = capi.awesome.systray()
local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000"
local spacing = beautiful.systray_icon_spacing or 0