From 7adc21e2ca97e51f249cbcaaeb53da0fee96a506 Mon Sep 17 00:00:00 2001 From: Rocco Aliberti Date: Wed, 15 Jan 2014 23:47:50 +0100 Subject: [PATCH] wibox.layout.margin: Add margins color parameter This adds a :set_color() method so that the margin layout can color the margins, drawing a bordered widget. Signed-off-by: Uli Schlachter --- lib/wibox/layout/margin.lua.in | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/wibox/layout/margin.lua.in b/lib/wibox/layout/margin.lua.in index 1a278d0c3..79b42d3cc 100644 --- a/lib/wibox/layout/margin.lua.in +++ b/lib/wibox/layout/margin.lua.in @@ -9,6 +9,8 @@ local type = type local setmetatable = setmetatable local base = require("wibox.layout.base") local widget_base = require("wibox.widget.base") +local gcolor = require("gears.color") +local cairo = require("lgi").cairo -- wibox.layout.margin local margin = { mt = {} } @@ -19,11 +21,22 @@ function margin:draw(wibox, cr, width, height) local y = self.top local w = self.right local h = self.bottom + local color = self.color if not self.widget or width <= x + w or height <= y + h then return end + if color then + cr:save() + cr:set_source(color) + cr:rectangle(0, 0, width, height) + cr:rectangle(x, y, width - x - w, height - y - h) + cr:set_fill_rule(cairo.FillRule.EVEN_ODD) + cr:fill() + cr:restore() + end + base.draw_widget(wibox, cr, self.widget, x, y, width - x - w, height - y - h) end @@ -60,10 +73,18 @@ function margin:set_margins(val) self:emit_signal("widget::updated") end ---- Reset this layout. The widget will be unreferenced and the margins set to 0. +--- Set the margins color to color +function margin:set_color(color) + self.color = color and gcolor(color) + self._emit_updated() +end + +--- Reset this layout. The widget will be unreferenced, the margins set to 0 +-- and the color erased function margin:reset() self:set_widget(nil) self:set_margins(0) + self:set_color(nil) end --- Set the left margin that this layout adds to its widget. @@ -104,7 +125,8 @@ end -- @param right A margin to use on the right side of the widget (optional) -- @param top A margin to use on the top side of the widget (optional) -- @param bottom A margin to use on the bottom side of the widget (optional) -local function new(widget, left, right, top, bottom) +-- @param color A color for the margins (optional) +local function new(widget, left, right, top, bottom, color) local ret = widget_base.make_widget() for k, v in pairs(margin) do @@ -122,6 +144,8 @@ local function new(widget, left, right, top, bottom) ret:set_top(top or 0) ret:set_bottom(bottom or 0) + ret:set_color(color) + if widget then ret:set_widget(widget) end