Merge branch 'widget_context'
This commit is contained in:
commit
56c22cde77
|
@ -76,7 +76,11 @@ local function new(c, args)
|
||||||
|
|
||||||
local ret
|
local ret
|
||||||
if not bars[position] then
|
if not bars[position] then
|
||||||
ret = drawable(d, nil, "awful.titlebar")
|
local context = {
|
||||||
|
client = c,
|
||||||
|
position = position
|
||||||
|
}
|
||||||
|
ret = drawable(d, context, "awful.titlebar")
|
||||||
local function update_colors()
|
local function update_colors()
|
||||||
local args = bars[position].args
|
local args = bars[position].args
|
||||||
ret:set_bg(get_color("bg", c, args))
|
ret:set_bg(get_color("bg", c, args))
|
||||||
|
|
|
@ -83,7 +83,7 @@ end
|
||||||
local function set_geometry(self)
|
local function set_geometry(self)
|
||||||
local my_geo = self.wibox:geometry()
|
local my_geo = self.wibox:geometry()
|
||||||
-- calculate width / height
|
-- calculate width / height
|
||||||
local n_w, n_h = self.textbox:fit(-1, -1)
|
local n_w, n_h = self.textbox:fit(nil, -1, -1) -- Hack! :(
|
||||||
n_w = n_w + self.marginbox.left + self.marginbox.right
|
n_w = n_w + self.marginbox.left + self.marginbox.right
|
||||||
n_h = n_h + self.marginbox.top + self.marginbox.bottom
|
n_h = n_h + self.marginbox.top + self.marginbox.bottom
|
||||||
if my_geo.width ~= n_w or my_geo.height ~= n_h then
|
if my_geo.width ~= n_w or my_geo.height ~= n_h then
|
||||||
|
|
|
@ -69,7 +69,7 @@ local properties = { "width", "height", "border_color", "stack",
|
||||||
"stack_colors", "color", "background_color",
|
"stack_colors", "color", "background_color",
|
||||||
"max_value", "scale" }
|
"max_value", "scale" }
|
||||||
|
|
||||||
function graph.draw(_graph, wibox, cr, width, height)
|
function graph.draw(_graph, context, cr, width, height)
|
||||||
local max_value = data[_graph].max_value
|
local max_value = data[_graph].max_value
|
||||||
local values = data[_graph].values
|
local values = data[_graph].values
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ function graph.draw(_graph, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function graph.fit(_graph, width, height)
|
function graph.fit(_graph)
|
||||||
return data[_graph].width, data[_graph].height
|
return data[_graph].width, data[_graph].height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ local properties = { "width", "height", "border_color",
|
||||||
"vertical", "value", "max_value",
|
"vertical", "value", "max_value",
|
||||||
"ticks", "ticks_gap", "ticks_size" }
|
"ticks", "ticks_gap", "ticks_size" }
|
||||||
|
|
||||||
function progressbar.draw(pbar, wibox, cr, width, height)
|
function progressbar.draw(pbar, context, cr, width, height)
|
||||||
local ticks_gap = data[pbar].ticks_gap or 1
|
local ticks_gap = data[pbar].ticks_gap or 1
|
||||||
local ticks_size = data[pbar].ticks_size or 4
|
local ticks_size = data[pbar].ticks_size or 4
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ function progressbar.draw(pbar, wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function progressbar.fit(pbar, width, height)
|
function progressbar.fit(pbar)
|
||||||
return data[pbar].width, data[pbar].height
|
return data[pbar].width, data[pbar].height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ capi.awesome.connect_signal("refresh", function()
|
||||||
local success, message = xpcall(function()
|
local success, message = xpcall(function()
|
||||||
callback[1](unpack(callback, 2))
|
callback[1](unpack(callback, 2))
|
||||||
end, function(err)
|
end, function(err)
|
||||||
print(debug.traceback("Error during delayed call: "..tostring(err)))
|
print(debug.traceback("Error during delayed call: "..tostring(err), 2))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
delayed_calls = {}
|
delayed_calls = {}
|
||||||
|
|
|
@ -526,7 +526,7 @@ function naughty.notify(args)
|
||||||
actiontextbox:set_font(font)
|
actiontextbox:set_font(font)
|
||||||
actiontextbox:set_markup(string.format('<b>%s</b>', action))
|
actiontextbox:set_markup(string.format('<b>%s</b>', action))
|
||||||
-- calculate the height and width
|
-- calculate the height and width
|
||||||
local w, h = actiontextbox:fit(-1, -1)
|
local w, h = actiontextbox:fit(nil, -1, -1) -- Hack! :(
|
||||||
local height = h + 2 * margin
|
local height = h + 2 * margin
|
||||||
local width = w + 2 * margin
|
local width = w + 2 * margin
|
||||||
|
|
||||||
|
@ -596,7 +596,7 @@ function naughty.notify(args)
|
||||||
|
|
||||||
-- calculate the height
|
-- calculate the height
|
||||||
if not height then
|
if not height then
|
||||||
local w, h = textbox:fit(-1, -1)
|
local w, h = textbox:fit(nil, -1, -1) -- Hack! :-(
|
||||||
if iconbox and icon_h + 2 * margin > h + 2 * margin then
|
if iconbox and icon_h + 2 * margin > h + 2 * margin then
|
||||||
height = icon_h + 2 * margin
|
height = icon_h + 2 * margin
|
||||||
else
|
else
|
||||||
|
@ -608,7 +608,7 @@ function naughty.notify(args)
|
||||||
|
|
||||||
-- calculate the width
|
-- calculate the width
|
||||||
if not width then
|
if not width then
|
||||||
local w, h = textbox:fit(-1, -1)
|
local w, h = textbox:fit(nil, -1, -1) -- Hack! :-(
|
||||||
width = w + (iconbox and icon_w + 2 * margin or 0) + 2 * margin
|
width = w + (iconbox and icon_w + 2 * margin or 0) + 2 * margin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,43 @@ local timer = require("gears.timer")
|
||||||
local drawables = setmetatable({}, { __mode = 'k' })
|
local drawables = setmetatable({}, { __mode = 'k' })
|
||||||
local wallpaper = nil
|
local wallpaper = nil
|
||||||
|
|
||||||
|
-- This is awful.screen.getbycoord() which we sadly cannot use from here (cyclic
|
||||||
|
-- dependencies are bad!)
|
||||||
|
function screen_getbycoord(x, y)
|
||||||
|
for i = 1, screen:count() do
|
||||||
|
local geometry = screen[i].geometry
|
||||||
|
if x >= geometry.x and x < geometry.x + geometry.width
|
||||||
|
and y >= geometry.y and y < geometry.y + geometry.height then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get the widget context. This should always return the same table (if
|
||||||
|
-- possible), so that our draw and fit caches can work efficiently.
|
||||||
|
local function get_widget_context(self)
|
||||||
|
local geom = self.drawable:geometry()
|
||||||
|
local s = screen_getbycoord(geom.x, geom.y)
|
||||||
|
local context = self._widget_context
|
||||||
|
local dpi = beautiful.xresources.get_dpi(s)
|
||||||
|
if (not context) or context.screen ~= s or context.dpi ~= dpi then
|
||||||
|
context = {
|
||||||
|
screen = s,
|
||||||
|
dpi = dpi,
|
||||||
|
drawable = self,
|
||||||
|
widget_at = function(_, ...)
|
||||||
|
self:widget_at(...)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
for k, v in pairs(self._widget_context_skeleton) do
|
||||||
|
context[k] = v
|
||||||
|
end
|
||||||
|
self._widget_context = context
|
||||||
|
end
|
||||||
|
return context
|
||||||
|
end
|
||||||
|
|
||||||
local function do_redraw(self)
|
local function do_redraw(self)
|
||||||
local surf = surface(self.drawable.surface)
|
local surf = surface(self.drawable.surface)
|
||||||
-- The surface can be nil if the drawable's parent was already finalized
|
-- The surface can be nil if the drawable's parent was already finalized
|
||||||
|
@ -63,7 +100,7 @@ local function do_redraw(self)
|
||||||
if self.widget.opacity ~= 1 then
|
if self.widget.opacity ~= 1 then
|
||||||
cr:push_group()
|
cr:push_group()
|
||||||
end
|
end
|
||||||
self.widget:draw(self.widget_arg, cr, width, height)
|
self.widget:draw(get_widget_context(self), cr, width, height)
|
||||||
if self.widget.opacity ~= 1 then
|
if self.widget.opacity ~= 1 then
|
||||||
cr:pop_group_to_source()
|
cr:pop_group_to_source()
|
||||||
cr.operator = cairo.Operator.OVER
|
cr.operator = cairo.Operator.OVER
|
||||||
|
@ -239,10 +276,10 @@ local function setup_signals(_drawable)
|
||||||
clone_signal("property::y")
|
clone_signal("property::y")
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawable.new(d, widget_arg, drawable_name)
|
function drawable.new(d, widget_context_skeleton, drawable_name)
|
||||||
local ret = object()
|
local ret = object()
|
||||||
ret.drawable = d
|
ret.drawable = d
|
||||||
ret.widget_arg = widget_arg or ret
|
ret._widget_context_skeleton = widget_context_skeleton
|
||||||
setup_signals(ret)
|
setup_signals(ret)
|
||||||
|
|
||||||
for k, v in pairs(drawable) do
|
for k, v in pairs(drawable) do
|
||||||
|
|
|
@ -108,7 +108,7 @@ local function new(args)
|
||||||
local ret = object()
|
local ret = object()
|
||||||
local w = capi.drawin(args)
|
local w = capi.drawin(args)
|
||||||
ret.drawin = w
|
ret.drawin = w
|
||||||
ret._drawable = wibox.drawable(w.drawable, ret,
|
ret._drawable = wibox.drawable(w.drawable, { wibox = ret },
|
||||||
"wibox drawable (" .. object.modulename(3) .. ")")
|
"wibox drawable (" .. object.modulename(3) .. ")")
|
||||||
|
|
||||||
for k, v in pairs(wibox) do
|
for k, v in pairs(wibox) do
|
||||||
|
|
|
@ -16,11 +16,11 @@ local widget_base = require("wibox.widget.base")
|
||||||
local align = {}
|
local align = {}
|
||||||
|
|
||||||
--- Draw an align layout.
|
--- Draw an align layout.
|
||||||
-- @param wibox The wibox that this widget is drawn to.
|
-- @param context The context in which we are drawn.
|
||||||
-- @param cr The cairo context to use.
|
-- @param cr The cairo context to use.
|
||||||
-- @param width The available width.
|
-- @param width The available width.
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
function align:draw(wibox, cr, width, height)
|
function align:draw(context, cr, width, height)
|
||||||
-- Draw will have to deal with all three align modes and should work in a
|
-- Draw will have to deal with all three align modes and should work in a
|
||||||
-- way that makes sense if one or two of the widgets are missing (if they
|
-- way that makes sense if one or two of the widgets are missing (if they
|
||||||
-- are all missing, it won't draw anything.) It should also handle the case
|
-- are all missing, it won't draw anything.) It should also handle the case
|
||||||
|
@ -37,12 +37,12 @@ function align:draw(wibox, cr, width, height)
|
||||||
-- if the second widget doesn't exist, we will prioritise the first one
|
-- if the second widget doesn't exist, we will prioritise the first one
|
||||||
-- instead
|
-- instead
|
||||||
if self._expand ~= "inside" and self.second then
|
if self._expand ~= "inside" and self.second then
|
||||||
local w, h = base.fit_widget(self.second, width, height)
|
local w, h = base.fit_widget(context, self.second, width, height)
|
||||||
local size_second = self.dir == "y" and h or w
|
local size_second = self.dir == "y" and h or w
|
||||||
-- if all the space is taken, skip the rest, and draw just the middle
|
-- if all the space is taken, skip the rest, and draw just the middle
|
||||||
-- widget
|
-- widget
|
||||||
if size_second >= size_remains then
|
if size_second >= size_remains then
|
||||||
base.draw_widget(wibox, cr, self.second, 0, 0, width, height)
|
base.draw_widget(context, cr, self.second, 0, 0, width, height)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
-- the middle widget is sized first, the outside widgets are given
|
-- the middle widget is sized first, the outside widgets are given
|
||||||
|
@ -57,7 +57,7 @@ function align:draw(wibox, cr, width, height)
|
||||||
-- into the remaining space
|
-- into the remaining space
|
||||||
if self._expand ~= "outside" then
|
if self._expand ~= "outside" then
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
_, h = base.fit_widget(self.first, width, size_remains)
|
_, h = base.fit_widget(context, self.first, width, size_remains)
|
||||||
size_first = h
|
size_first = h
|
||||||
-- for "inside", the third widget will get a chance to use the
|
-- for "inside", the third widget will get a chance to use the
|
||||||
-- remaining space, then the middle widget. For "none" we give
|
-- remaining space, then the middle widget. For "none" we give
|
||||||
|
@ -68,7 +68,7 @@ function align:draw(wibox, cr, width, height)
|
||||||
size_remains = size_remains - h
|
size_remains = size_remains - h
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
w, _ = base.fit_widget(self.first, size_remains, height)
|
w, _ = base.fit_widget(context, self.first, size_remains, height)
|
||||||
size_first = w
|
size_first = w
|
||||||
if self._expand == "inside" or not self.second then
|
if self._expand == "inside" or not self.second then
|
||||||
size_remains = size_remains - w
|
size_remains = size_remains - w
|
||||||
|
@ -81,20 +81,20 @@ function align:draw(wibox, cr, width, height)
|
||||||
w = size_remains
|
w = size_remains
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, self.first, 0, 0, w, h)
|
base.draw_widget(context, cr, self.first, 0, 0, w, h)
|
||||||
end
|
end
|
||||||
-- size_remains will be <= 0 if first used all the space
|
-- size_remains will be <= 0 if first used all the space
|
||||||
if self.third and size_remains > 0 then
|
if self.third and size_remains > 0 then
|
||||||
local w, h, _ = width, height, nil
|
local w, h, _ = width, height, nil
|
||||||
if self._expand ~= "outside" then
|
if self._expand ~= "outside" then
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
_, h = base.fit_widget(self.third, width, size_remains)
|
_, h = base.fit_widget(context, self.third, width, size_remains)
|
||||||
-- give the middle widget the rest of the space for "inside" mode
|
-- give the middle widget the rest of the space for "inside" mode
|
||||||
if self._expand == "inside" then
|
if self._expand == "inside" then
|
||||||
size_remains = size_remains - h
|
size_remains = size_remains - h
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
w, _ = base.fit_widget(self.third, size_remains, height)
|
w, _ = base.fit_widget(context, self.third, size_remains, height)
|
||||||
if self._expand == "inside" then
|
if self._expand == "inside" then
|
||||||
size_remains = size_remains - w
|
size_remains = size_remains - w
|
||||||
end
|
end
|
||||||
|
@ -107,7 +107,7 @@ function align:draw(wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local x, y = width - w, height - h
|
local x, y = width - w, height - h
|
||||||
base.draw_widget(wibox, cr, self.third, x, y, w, h)
|
base.draw_widget(context, cr, self.third, x, y, w, h)
|
||||||
end
|
end
|
||||||
-- here we either draw the second widget in the space set aside for it
|
-- here we either draw the second widget in the space set aside for it
|
||||||
-- in the beginning, or in the remaining space, if it is "inside"
|
-- in the beginning, or in the remaining space, if it is "inside"
|
||||||
|
@ -123,14 +123,14 @@ function align:draw(wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
_, h = base.fit_widget(self.second, width, size_remains)
|
_, h = base.fit_widget(context, self.second, width, size_remains)
|
||||||
y = floor( (height - h)/2 )
|
y = floor( (height - h)/2 )
|
||||||
else
|
else
|
||||||
w, _ = base.fit_widget(self.second, width, size_remains)
|
w, _ = base.fit_widget(context, self.second, width, size_remains)
|
||||||
x = floor( (width -w)/2 )
|
x = floor( (width -w)/2 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, self.second, x, y, w, h)
|
base.draw_widget(context, cr, self.second, x, y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -166,14 +166,15 @@ end
|
||||||
--- Fit the align layout into the given space. The align layout will
|
--- Fit the align layout into the given space. The align layout will
|
||||||
-- ask for the sum of the sizes of its sub-widgets in its direction
|
-- ask for the sum of the sizes of its sub-widgets in its direction
|
||||||
-- and the largest sized sub widget in the other direction.
|
-- and the largest sized sub widget in the other direction.
|
||||||
|
-- @param context The context in which we are fit.
|
||||||
-- @param orig_width The available width.
|
-- @param orig_width The available width.
|
||||||
-- @param orig_height The available height.
|
-- @param orig_height The available height.
|
||||||
function align:fit(orig_width, orig_height)
|
function align:fit(context, orig_width, orig_height)
|
||||||
local used_in_dir = 0
|
local used_in_dir = 0
|
||||||
local used_in_other = 0
|
local used_in_other = 0
|
||||||
|
|
||||||
for k, v in pairs{self.first, self.second, self.third} do
|
for k, v in pairs{self.first, self.second, self.third} do
|
||||||
local w, h = base.fit_widget(v, orig_width, orig_height)
|
local w, h = base.fit_widget(context, v, orig_width, orig_height)
|
||||||
|
|
||||||
local max = self.dir == "y" and w or h
|
local max = self.dir == "y" and w or h
|
||||||
if max > used_in_other then
|
if max > used_in_other then
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local pcall = pcall
|
local xpcall = xpcall
|
||||||
local print = print
|
local print = print
|
||||||
local min = math.min
|
local min = math.min
|
||||||
local max = math.max
|
local max = math.max
|
||||||
|
@ -30,11 +30,12 @@ function base.rect_to_device_geometry(cr, x, y, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit a widget for the given available width and height
|
--- Fit a widget for the given available width and height
|
||||||
|
-- @param context The context in which we are fit.
|
||||||
-- @param widget The widget to fit (this uses widget:fit(width, height)).
|
-- @param widget The widget to fit (this uses widget:fit(width, height)).
|
||||||
-- @param width The available width for the widget
|
-- @param width The available width for the widget
|
||||||
-- @param height The available height for the widget
|
-- @param height The available height for the widget
|
||||||
-- @return The width and height that the widget wants to use
|
-- @return The width and height that the widget wants to use
|
||||||
function base.fit_widget(widget, width, height)
|
function base.fit_widget(context, widget, width, height)
|
||||||
if not widget.visible then
|
if not widget.visible then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
|
@ -42,21 +43,22 @@ function base.fit_widget(widget, width, height)
|
||||||
local width = math.max(0, width)
|
local width = math.max(0, width)
|
||||||
local height = math.max(0, height)
|
local height = math.max(0, height)
|
||||||
|
|
||||||
return widget._fit_geometry_cache:get(width, height)
|
return widget._fit_geometry_cache:get(context, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Draw a widget via a cairo context
|
--- Draw a widget via a cairo context
|
||||||
-- @param wibox The wibox on which we are drawing
|
-- @param context The context in which we are drawn.
|
||||||
-- @param cr The cairo context used
|
-- @param cr The cairo context used
|
||||||
-- @param widget The widget to draw (this uses widget:draw(cr, width, height)).
|
-- @param widget The widget to draw (this uses widget:draw(cr, width, height)).
|
||||||
-- @param x The position that the widget should get
|
-- @param x The position that the widget should get
|
||||||
-- @param y The position that the widget should get
|
-- @param y The position that the widget should get
|
||||||
-- @param width The widget's width
|
-- @param width The widget's width
|
||||||
-- @param height The widget's height
|
-- @param height The widget's height
|
||||||
function base.draw_widget(wibox, cr, widget, x, y, width, height)
|
function base.draw_widget(context, cr, widget, x, y, width, height)
|
||||||
if not widget.visible then
|
if not widget.visible then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use save() / restore() so that our modifications aren't permanent
|
-- Use save() / restore() so that our modifications aren't permanent
|
||||||
cr:save()
|
cr:save()
|
||||||
|
|
||||||
|
@ -71,18 +73,19 @@ function base.draw_widget(wibox, cr, widget, x, y, width, height)
|
||||||
cr:push_group()
|
cr:push_group()
|
||||||
end
|
end
|
||||||
-- Let the widget draw itself
|
-- Let the widget draw itself
|
||||||
local success, msg = pcall(widget.draw, widget, wibox, cr, width, height)
|
xpcall(function()
|
||||||
|
widget:draw(context, cr, width, height)
|
||||||
|
end, function(err)
|
||||||
|
print(debug.traceback("Error while drawing widget: "..tostring(err), 2))
|
||||||
|
end)
|
||||||
if widget.opacity ~= 1 then
|
if widget.opacity ~= 1 then
|
||||||
cr:pop_group_to_source()
|
cr:pop_group_to_source()
|
||||||
cr.operator = cairo.Operator.OVER
|
cr.operator = cairo.Operator.OVER
|
||||||
cr:paint_with_alpha(widget.opacity)
|
cr:paint_with_alpha(widget.opacity)
|
||||||
end
|
end
|
||||||
if not success then
|
|
||||||
print("Error while drawing widget: " .. msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Register the widget for input handling
|
-- Register the widget for input handling
|
||||||
wibox:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))
|
context:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))
|
||||||
|
|
||||||
cr:restore()
|
cr:restore()
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,22 +15,22 @@ local math = math
|
||||||
local constraint = { mt = {} }
|
local constraint = { mt = {} }
|
||||||
|
|
||||||
--- Draw a constraint layout
|
--- Draw a constraint layout
|
||||||
function constraint:draw(wibox, cr, width, height)
|
function constraint:draw(context, cr, width, height)
|
||||||
if not self.widget then
|
if not self.widget then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
base.draw_widget(context, cr, self.widget, 0, 0, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit a constraint layout into the given space
|
--- Fit a constraint layout into the given space
|
||||||
function constraint:fit(width, height)
|
function constraint:fit(context, width, height)
|
||||||
local w, h
|
local w, h
|
||||||
if self.widget then
|
if self.widget then
|
||||||
w = self._strategy(width, self._width)
|
w = self._strategy(width, self._width)
|
||||||
h = self._strategy(height, self._height)
|
h = self._strategy(height, self._height)
|
||||||
|
|
||||||
w, h = base.fit_widget(self.widget, w, h)
|
w, h = base.fit_widget(context, self.widget, w, h)
|
||||||
else
|
else
|
||||||
w, h = 0, 0
|
w, h = 0, 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,12 +13,12 @@ local pairs = pairs
|
||||||
local fixed = {}
|
local fixed = {}
|
||||||
|
|
||||||
--- Draw a fixed layout. Each widget gets just the space it asks for.
|
--- Draw a fixed layout. Each widget gets just the space it asks for.
|
||||||
-- @param wibox The wibox that this widget is drawn to.
|
-- @param context The context in which we are drawn.
|
||||||
-- @param cr The cairo context to use.
|
-- @param cr The cairo context to use.
|
||||||
-- @param width The available width.
|
-- @param width The available width.
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
-- @return The total space needed by the layout.
|
-- @return The total space needed by the layout.
|
||||||
function fixed:draw(wibox, cr, width, height)
|
function fixed:draw(context, cr, width, height)
|
||||||
local pos,spacing = 0,self._spacing or 0
|
local pos,spacing = 0,self._spacing or 0
|
||||||
|
|
||||||
for k, v in pairs(self.widgets) do
|
for k, v in pairs(self.widgets) do
|
||||||
|
@ -28,7 +28,7 @@ function fixed:draw(wibox, cr, width, height)
|
||||||
x, y = 0, pos
|
x, y = 0, pos
|
||||||
w, h = width, height - pos
|
w, h = width, height - pos
|
||||||
if k ~= #self.widgets or not self._fill_space then
|
if k ~= #self.widgets or not self._fill_space then
|
||||||
_, h = base.fit_widget(v, w, h);
|
_, h = base.fit_widget(context, v, w, h);
|
||||||
end
|
end
|
||||||
pos = pos + h + spacing
|
pos = pos + h + spacing
|
||||||
in_dir = h
|
in_dir = h
|
||||||
|
@ -36,7 +36,7 @@ function fixed:draw(wibox, cr, width, height)
|
||||||
x, y = pos, 0
|
x, y = pos, 0
|
||||||
w, h = width - pos, height
|
w, h = width - pos, height
|
||||||
if k ~= #self.widgets or not self._fill_space then
|
if k ~= #self.widgets or not self._fill_space then
|
||||||
w, _ = base.fit_widget(v, w, h);
|
w, _ = base.fit_widget(context, v, w, h);
|
||||||
end
|
end
|
||||||
pos = pos + w + spacing
|
pos = pos + w + spacing
|
||||||
in_dir = w
|
in_dir = w
|
||||||
|
@ -46,7 +46,7 @@ function fixed:draw(wibox, cr, width, height)
|
||||||
(self.dir ~= "y" and pos-spacing > width) then
|
(self.dir ~= "y" and pos-spacing > width) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, v, x, y, w, h)
|
base.draw_widget(context, cr, v, x, y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,14 +59,15 @@ function fixed:add(widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the fixed layout into the given space
|
--- Fit the fixed layout into the given space
|
||||||
|
-- @param context The context in which we are fit.
|
||||||
-- @param orig_width The available width.
|
-- @param orig_width The available width.
|
||||||
-- @param orig_height The available height.
|
-- @param orig_height The available height.
|
||||||
function fixed:fit(orig_width, orig_height)
|
function fixed:fit(context, orig_width, orig_height)
|
||||||
local width, height = orig_width, orig_height
|
local width, height = orig_width, orig_height
|
||||||
local used_in_dir, used_max = 0, 0
|
local used_in_dir, used_max = 0, 0
|
||||||
|
|
||||||
for k, v in pairs(self.widgets) do
|
for k, v in pairs(self.widgets) do
|
||||||
local w, h = base.fit_widget(v, width, height)
|
local w, h = base.fit_widget(context, v, width, height)
|
||||||
local in_dir, max
|
local in_dir, max
|
||||||
if self.dir == "y" then
|
if self.dir == "y" then
|
||||||
max, in_dir = w, h
|
max, in_dir = w, h
|
||||||
|
|
|
@ -15,12 +15,12 @@ local round = require("awful.util").round
|
||||||
local flex = {}
|
local flex = {}
|
||||||
|
|
||||||
--- Draw a flex layout. Each widget gets an equal share of the available space.
|
--- Draw a flex layout. Each widget gets an equal share of the available space.
|
||||||
-- @param wibox The wibox that this widget is drawn to.
|
-- @param context The context in which we are drawn.
|
||||||
-- @param cr The cairo context to use.
|
-- @param cr The cairo context to use.
|
||||||
-- @param width The available width.
|
-- @param width The available width.
|
||||||
-- @param height The available height.
|
-- @param height The available height.
|
||||||
-- @return The total space needed by the layout.
|
-- @return The total space needed by the layout.
|
||||||
function flex:draw(wibox, cr, width, height)
|
function flex:draw(context, cr, width, height)
|
||||||
local pos,spacing = 0,self._spacing or 0
|
local pos,spacing = 0,self._spacing or 0
|
||||||
local num = #self.widgets
|
local num = #self.widgets
|
||||||
local total_spacing = (spacing*(num-1))
|
local total_spacing = (spacing*(num-1))
|
||||||
|
@ -45,7 +45,7 @@ function flex:draw(wibox, cr, width, height)
|
||||||
x, y = round(pos), 0
|
x, y = round(pos), 0
|
||||||
w, h = floor(space_per_item), height
|
w, h = floor(space_per_item), height
|
||||||
end
|
end
|
||||||
base.draw_widget(wibox, cr, v, x, y, w, h)
|
base.draw_widget(context, cr, v, x, y, w, h)
|
||||||
|
|
||||||
pos = pos + space_per_item + spacing
|
pos = pos + space_per_item + spacing
|
||||||
|
|
||||||
|
@ -72,9 +72,10 @@ function flex:set_max_widget_size(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the flex layout into the given space.
|
--- Fit the flex layout into the given space.
|
||||||
|
-- @param context The context in which we are fit.
|
||||||
-- @param orig_width The available width.
|
-- @param orig_width The available width.
|
||||||
-- @param orig_height The available height.
|
-- @param orig_height The available height.
|
||||||
function flex:fit(orig_width, orig_height)
|
function flex:fit(context, orig_width, orig_height)
|
||||||
local used_in_dir = 0
|
local used_in_dir = 0
|
||||||
local used_in_other = 0
|
local used_in_other = 0
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ function flex:fit(orig_width, orig_height)
|
||||||
local sub_width = self.dir == "y" and orig_width or floor(orig_width / #self.widgets)
|
local sub_width = self.dir == "y" and orig_width or floor(orig_width / #self.widgets)
|
||||||
|
|
||||||
for k, v in pairs(self.widgets) do
|
for k, v in pairs(self.widgets) do
|
||||||
local w, h = base.fit_widget(v, sub_width, sub_height)
|
local w, h = base.fit_widget(context, v, sub_width, sub_height)
|
||||||
|
|
||||||
local max = self.dir == "y" and w or h
|
local max = self.dir == "y" and w or h
|
||||||
if max > used_in_other then
|
if max > used_in_other then
|
||||||
|
|
|
@ -16,7 +16,7 @@ local cairo = require("lgi").cairo
|
||||||
local margin = { mt = {} }
|
local margin = { mt = {} }
|
||||||
|
|
||||||
--- Draw a margin layout
|
--- Draw a margin layout
|
||||||
function margin:draw(wibox, cr, width, height)
|
function margin:draw(context, cr, width, height)
|
||||||
local x = self.left
|
local x = self.left
|
||||||
local y = self.top
|
local y = self.top
|
||||||
local w = self.right
|
local w = self.right
|
||||||
|
@ -37,16 +37,16 @@ function margin:draw(wibox, cr, width, height)
|
||||||
cr:restore()
|
cr:restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
base.draw_widget(wibox, cr, self.widget, x, y, width - x - w, height - y - h)
|
base.draw_widget(context, cr, self.widget, x, y, width - x - w, height - y - h)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit a margin layout into the given space
|
--- Fit a margin layout into the given space
|
||||||
function margin:fit(width, height)
|
function margin:fit(context, width, height)
|
||||||
local extra_w = self.left + self.right
|
local extra_w = self.left + self.right
|
||||||
local extra_h = self.top + self.bottom
|
local extra_h = self.top + self.bottom
|
||||||
local w, h = 0, 0
|
local w, h = 0, 0
|
||||||
if self.widget then
|
if self.widget then
|
||||||
w, h = base.fit_widget(self.widget, width - extra_w, height - extra_h)
|
w, h = base.fit_widget(context, self.widget, width - extra_w, height - extra_h)
|
||||||
end
|
end
|
||||||
return w + extra_w, h + extra_h
|
return w + extra_w, h + extra_h
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,10 +16,8 @@ local widget_base = require("wibox.widget.base")
|
||||||
local mirror = { mt = {} }
|
local mirror = { mt = {} }
|
||||||
|
|
||||||
--- Draw this layout
|
--- Draw this layout
|
||||||
function mirror:draw(wibox, cr, width, height)
|
function mirror:draw(context, cr, width, height)
|
||||||
if not self.widget then
|
if not self.widget then return end
|
||||||
return { width = 0, height = 0 }
|
|
||||||
end
|
|
||||||
if not self.horizontal and not self.vertical then
|
if not self.horizontal and not self.vertical then
|
||||||
base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
||||||
return -- nothing changed
|
return -- nothing changed
|
||||||
|
@ -40,18 +38,18 @@ function mirror:draw(wibox, cr, width, height)
|
||||||
cr:translate(t.x, t.y)
|
cr:translate(t.x, t.y)
|
||||||
cr:scale(s.x, s.y)
|
cr:scale(s.x, s.y)
|
||||||
|
|
||||||
self.widget:draw(wibox, cr, width, height)
|
self.widget:draw(context, cr, width, height)
|
||||||
|
|
||||||
-- Undo the scale and translation from above.
|
-- Undo the scale and translation from above.
|
||||||
cr:restore()
|
cr:restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit this layout into the given area
|
--- Fit this layout into the given area
|
||||||
function mirror:fit(...)
|
function mirror:fit(context, ...)
|
||||||
if not self.widget then
|
if not self.widget then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
return base.fit_widget(self.widget, ...)
|
return base.fit_widget(context, self.widget, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the widget that this layout mirrors.
|
--- Set the widget that this layout mirrors.
|
||||||
|
|
|
@ -25,9 +25,9 @@ local function transform(layout, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Draw this layout
|
--- Draw this layout
|
||||||
function rotate:draw(wibox, cr, width, height)
|
function rotate:draw(context, cr, width, height)
|
||||||
if not self.widget or not self.widget.visible then
|
if not self.widget or not self.widget.visible then
|
||||||
return { width = 0, height = 0 }
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = self:get_direction()
|
local dir = self:get_direction()
|
||||||
|
@ -45,15 +45,15 @@ function rotate:draw(wibox, cr, width, height)
|
||||||
|
|
||||||
-- Since we rotated, we might have to swap width and height.
|
-- Since we rotated, we might have to swap width and height.
|
||||||
-- transform() does that for us.
|
-- transform() does that for us.
|
||||||
base.draw_widget(wibox, cr, self.widget, 0, 0, transform(self, width, height))
|
base.draw_widget(context, cr, self.widget, 0, 0, transform(self, width, height))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit this layout into the given area
|
--- Fit this layout into the given area
|
||||||
function rotate:fit(width, height)
|
function rotate:fit(context, width, height)
|
||||||
if not self.widget then
|
if not self.widget then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
return transform(self, base.fit_widget(self.widget, transform(self, width, height)))
|
return transform(self, base.fit_widget(context, self.widget, transform(self, width, height)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set the widget that this layout rotates.
|
--- Set the widget that this layout rotates.
|
||||||
|
|
|
@ -17,7 +17,7 @@ local type = type
|
||||||
local background = { mt = {} }
|
local background = { mt = {} }
|
||||||
|
|
||||||
--- Draw this widget
|
--- Draw this widget
|
||||||
function background:draw(wibox, cr, width, height)
|
function background:draw(context, cr, width, height)
|
||||||
if not self.widget or not self.widget.visible then
|
if not self.widget or not self.widget.visible then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -40,19 +40,19 @@ function background:draw(wibox, cr, width, height)
|
||||||
cr:save()
|
cr:save()
|
||||||
cr:set_source(self.foreground)
|
cr:set_source(self.foreground)
|
||||||
end
|
end
|
||||||
layout_base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
layout_base.draw_widget(context, cr, self.widget, 0, 0, width, height)
|
||||||
if self.foreground then
|
if self.foreground then
|
||||||
cr:restore()
|
cr:restore()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit this widget into the given area
|
--- Fit this widget into the given area
|
||||||
function background:fit(width, height)
|
function background:fit(context, width, height)
|
||||||
if not self.widget then
|
if not self.widget then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.widget:fit(width, height)
|
return layout_base.fit_widget(context, self.widget, 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
|
||||||
|
|
|
@ -151,7 +151,7 @@ function base.check_widget(widget)
|
||||||
debug.assert(type(widget[func]) == "function", func .. " is not a function")
|
debug.assert(type(widget[func]) == "function", func .. " is not a function")
|
||||||
end
|
end
|
||||||
|
|
||||||
local width, height = widget:fit(0, 0)
|
local width, height = widget:fit({}, 0, 0)
|
||||||
debug.assert(type(width) == "number")
|
debug.assert(type(width) == "number")
|
||||||
debug.assert(type(height) == "number")
|
debug.assert(type(height) == "number")
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ local print = print
|
||||||
local imagebox = { mt = {} }
|
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 imagebox:draw(wibox, cr, width, height)
|
function imagebox:draw(context, cr, width, height)
|
||||||
if not self._image then return end
|
if not self._image then return end
|
||||||
if width == 0 or height == 0 then return end
|
if width == 0 or height == 0 then return end
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ function imagebox:draw(wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the imagebox into the given geometry
|
--- Fit the imagebox into the given geometry
|
||||||
function imagebox:fit(width, height)
|
function imagebox:fit(context, width, height)
|
||||||
if not self._image then
|
if not self._image then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ local horizontal = true
|
||||||
local base_size = nil
|
local base_size = nil
|
||||||
local reverse = false
|
local reverse = false
|
||||||
|
|
||||||
function systray:draw(wibox, cr, width, height)
|
function systray:draw(context, cr, width, height)
|
||||||
local x, y, _, _ = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
local x, y, _, _ = 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 or "#000000"
|
local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000"
|
||||||
|
@ -41,11 +41,11 @@ function systray:draw(wibox, cr, width, height)
|
||||||
else
|
else
|
||||||
base = in_dir / num_entries
|
base = in_dir / num_entries
|
||||||
end
|
end
|
||||||
capi.awesome.systray(wibox.drawin, math.ceil(x), math.ceil(y),
|
capi.awesome.systray(context.wibox.drawin, math.ceil(x), math.ceil(y),
|
||||||
base, is_rotated, bg, reverse, spacing)
|
base, is_rotated, bg, reverse, spacing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function systray:fit(width, height)
|
function systray:fit(context, width, height)
|
||||||
local num_entries = capi.awesome.systray()
|
local num_entries = capi.awesome.systray()
|
||||||
local base = base_size
|
local base = base_size
|
||||||
local spacing = beautiful.systray_icon_spacing or 0
|
local spacing = beautiful.systray_icon_spacing or 0
|
||||||
|
|
|
@ -27,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 textbox:draw(wibox, cr, width, height)
|
function textbox:draw(context, cr, width, height)
|
||||||
cr:update_layout(self._layout)
|
cr:update_layout(self._layout)
|
||||||
setup_layout(self, width, height)
|
setup_layout(self, width, height)
|
||||||
local ink, logical = self._layout:get_pixel_extents()
|
local ink, logical = self._layout:get_pixel_extents()
|
||||||
|
@ -42,7 +42,7 @@ function textbox:draw(wibox, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit the given textbox
|
--- Fit the given textbox
|
||||||
function textbox:fit(width, height)
|
function textbox:fit(context, width, height)
|
||||||
setup_layout(self, width, height)
|
setup_layout(self, width, height)
|
||||||
local ink, logical = self._layout:get_pixel_extents()
|
local ink, logical = self._layout:get_pixel_extents()
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ local function widget_fit(state, arguments)
|
||||||
local widget = arguments[1]
|
local widget = arguments[1]
|
||||||
local given = arguments[2]
|
local given = arguments[2]
|
||||||
local expected = arguments[3]
|
local expected = arguments[3]
|
||||||
local w, h = widget:fit(given[1], given[2])
|
local w, h = widget:fit({ "fake context" }, given[1], given[2])
|
||||||
|
|
||||||
local fits = expected[1] == w and expected[2] == h
|
local fits = expected[1] == w and expected[2] == h
|
||||||
if state.mod == fits then
|
if state.mod == fits then
|
||||||
|
|
Loading…
Reference in New Issue