From 88b98789a055616aece6df5422dcbedf1dadd4e0 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 8 Aug 2015 13:18:54 +0200 Subject: [PATCH] Rename the first argument to :draw to "context" Signed-off-by: Uli Schlachter --- lib/awful/widget/graph.lua | 2 +- lib/awful/widget/progressbar.lua | 2 +- lib/wibox/layout/align.lua | 12 ++++++------ lib/wibox/layout/base.lua | 9 +++++---- lib/wibox/layout/constraint.lua | 4 ++-- lib/wibox/layout/fixed.lua | 6 +++--- lib/wibox/layout/flex.lua | 6 +++--- lib/wibox/layout/margin.lua | 4 ++-- lib/wibox/layout/mirror.lua | 8 +++----- lib/wibox/layout/rotate.lua | 6 +++--- lib/wibox/widget/background.lua | 4 ++-- lib/wibox/widget/imagebox.lua | 2 +- lib/wibox/widget/systray.lua | 4 ++-- lib/wibox/widget/textbox.lua | 2 +- 14 files changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/awful/widget/graph.lua b/lib/awful/widget/graph.lua index abe464fb..a1252fad 100644 --- a/lib/awful/widget/graph.lua +++ b/lib/awful/widget/graph.lua @@ -69,7 +69,7 @@ local properties = { "width", "height", "border_color", "stack", "stack_colors", "color", "background_color", "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 values = data[_graph].values diff --git a/lib/awful/widget/progressbar.lua b/lib/awful/widget/progressbar.lua index e85d1d95..1e92326a 100644 --- a/lib/awful/widget/progressbar.lua +++ b/lib/awful/widget/progressbar.lua @@ -71,7 +71,7 @@ local properties = { "width", "height", "border_color", "vertical", "value", "max_value", "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_size = data[pbar].ticks_size or 4 diff --git a/lib/wibox/layout/align.lua b/lib/wibox/layout/align.lua index de4682e9..3b6d4431 100644 --- a/lib/wibox/layout/align.lua +++ b/lib/wibox/layout/align.lua @@ -16,11 +16,11 @@ local widget_base = require("wibox.widget.base") local align = {} --- 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 width The available width. -- @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 -- 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 @@ -42,7 +42,7 @@ function align:draw(wibox, cr, width, height) -- if all the space is taken, skip the rest, and draw just the middle -- widget 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 else -- the middle widget is sized first, the outside widgets are given @@ -81,7 +81,7 @@ function align:draw(wibox, cr, width, height) w = size_remains 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 -- size_remains will be <= 0 if first used all the space if self.third and size_remains > 0 then @@ -107,7 +107,7 @@ function align:draw(wibox, cr, width, height) end end 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 -- 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" @@ -130,7 +130,7 @@ function align:draw(wibox, cr, width, height) x = floor( (width -w)/2 ) 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 diff --git a/lib/wibox/layout/base.lua b/lib/wibox/layout/base.lua index 3842a6b6..117cafd7 100644 --- a/lib/wibox/layout/base.lua +++ b/lib/wibox/layout/base.lua @@ -45,17 +45,18 @@ function base.fit_widget(widget, width, height) end --- 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 widget The widget to draw (this uses widget:draw(cr, width, height)). -- @param x The position that the widget should get -- @param y The position that the widget should get -- @param width The widget's width -- @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 return end + -- Use save() / restore() so that our modifications aren't permanent cr:save() @@ -68,13 +69,13 @@ function base.draw_widget(wibox, cr, widget, x, y, width, height) -- Let the widget draw itself xpcall(function() - widget:draw(wibox, cr, width, height) + widget:draw(context, cr, width, height) end, function(err) print(debug.traceback("Error while drawing widget: "..tostring(err), 2)) end) -- 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() end diff --git a/lib/wibox/layout/constraint.lua b/lib/wibox/layout/constraint.lua index 34b552bd..b4e0e377 100644 --- a/lib/wibox/layout/constraint.lua +++ b/lib/wibox/layout/constraint.lua @@ -15,12 +15,12 @@ local math = math local constraint = { mt = {} } --- Draw a constraint layout -function constraint:draw(wibox, cr, width, height) +function constraint:draw(context, cr, width, height) if not self.widget then return end - base.draw_widget(wibox, cr, self.widget, 0, 0, width, height) + base.draw_widget(context, cr, self.widget, 0, 0, width, height) end --- Fit a constraint layout into the given space diff --git a/lib/wibox/layout/fixed.lua b/lib/wibox/layout/fixed.lua index 5329e1fd..a5cce63b 100644 --- a/lib/wibox/layout/fixed.lua +++ b/lib/wibox/layout/fixed.lua @@ -13,12 +13,12 @@ local pairs = pairs local fixed = {} --- 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 width The available width. -- @param height The available height. -- @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 for k, v in pairs(self.widgets) do @@ -46,7 +46,7 @@ function fixed:draw(wibox, cr, width, height) (self.dir ~= "y" and pos-spacing > width) then break end - base.draw_widget(wibox, cr, v, x, y, w, h) + base.draw_widget(context, cr, v, x, y, w, h) end end diff --git a/lib/wibox/layout/flex.lua b/lib/wibox/layout/flex.lua index 55107c9d..a24af0be 100644 --- a/lib/wibox/layout/flex.lua +++ b/lib/wibox/layout/flex.lua @@ -18,12 +18,12 @@ local function round(x) end --- 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 width The available width. -- @param height The available height. -- @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 num = #self.widgets local total_spacing = (spacing*(num-1)) @@ -48,7 +48,7 @@ function flex:draw(wibox, cr, width, height) x, y = round(pos), 0 w, h = floor(space_per_item), height 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 diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index 2a1a0df3..7e164b50 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -16,7 +16,7 @@ local cairo = require("lgi").cairo local margin = { mt = {} } --- Draw a margin layout -function margin:draw(wibox, cr, width, height) +function margin:draw(context, cr, width, height) local x = self.left local y = self.top local w = self.right @@ -37,7 +37,7 @@ function margin:draw(wibox, cr, width, height) cr:restore() 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 --- Fit a margin layout into the given space diff --git a/lib/wibox/layout/mirror.lua b/lib/wibox/layout/mirror.lua index 78162d49..cace8c0b 100644 --- a/lib/wibox/layout/mirror.lua +++ b/lib/wibox/layout/mirror.lua @@ -16,10 +16,8 @@ local widget_base = require("wibox.widget.base") local mirror = { mt = {} } --- Draw this layout -function mirror:draw(wibox, cr, width, height) - if not self.widget then - return { width = 0, height = 0 } - end +function mirror:draw(context, cr, width, height) + if not self.widget then return end if not self.horizontal and not self.vertical then base.draw_widget(wibox, cr, self.widget, 0, 0, width, height) return -- nothing changed @@ -40,7 +38,7 @@ function mirror:draw(wibox, cr, width, height) cr:translate(t.x, t.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. cr:restore() diff --git a/lib/wibox/layout/rotate.lua b/lib/wibox/layout/rotate.lua index 22d3c646..3e687525 100644 --- a/lib/wibox/layout/rotate.lua +++ b/lib/wibox/layout/rotate.lua @@ -25,9 +25,9 @@ local function transform(layout, width, height) end --- 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 - return { width = 0, height = 0 } + return end local dir = self:get_direction() @@ -45,7 +45,7 @@ function rotate:draw(wibox, cr, width, height) -- Since we rotated, we might have to swap width and height. -- 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 --- Fit this layout into the given area diff --git a/lib/wibox/widget/background.lua b/lib/wibox/widget/background.lua index 8dd7f435..940dff20 100644 --- a/lib/wibox/widget/background.lua +++ b/lib/wibox/widget/background.lua @@ -17,7 +17,7 @@ local type = type local background = { mt = {} } --- 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 return end @@ -40,7 +40,7 @@ function background:draw(wibox, cr, width, height) cr:save() cr:set_source(self.foreground) 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 cr:restore() end diff --git a/lib/wibox/widget/imagebox.lua b/lib/wibox/widget/imagebox.lua index a8374372..24a03cc9 100644 --- a/lib/wibox/widget/imagebox.lua +++ b/lib/wibox/widget/imagebox.lua @@ -16,7 +16,7 @@ local print = print local imagebox = { mt = {} } --- 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 width == 0 or height == 0 then return end diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 1414cd75..1c692b05 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -19,7 +19,7 @@ local horizontal = true local base_size = nil 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 num_entries = capi.awesome.systray() local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" @@ -41,7 +41,7 @@ function systray:draw(wibox, cr, width, height) else base = in_dir / num_entries end - capi.awesome.systray(wibox.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) end diff --git a/lib/wibox/widget/textbox.lua b/lib/wibox/widget/textbox.lua index c8096c53..6b99b16e 100644 --- a/lib/wibox/widget/textbox.lua +++ b/lib/wibox/widget/textbox.lua @@ -27,7 +27,7 @@ local function setup_layout(box, width, height) end --- 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) setup_layout(self, width, height) local ink, logical = self._layout:get_pixel_extents()