Conver the rotate layout to the new widget system

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-06-14 16:35:01 +02:00
parent 85ab3f045b
commit b83eaf5915
1 changed files with 13 additions and 19 deletions

View File

@ -13,6 +13,7 @@ local setmetatable = setmetatable
local tostring = tostring local tostring = tostring
local base = require("wibox.layout.base") local base = require("wibox.layout.base")
local widget_base = require("wibox.widget.base") local widget_base = require("wibox.widget.base")
local Matrix = require("lgi").cairo.Matrix
local rotate = { mt = {} } local rotate = { mt = {} }
@ -24,28 +25,29 @@ local function transform(layout, width, height)
return width, height return width, height
end end
--- Draw this layout --- Layout this layout
function rotate:draw(context, cr, width, height) function rotate:layout(context, 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
local dir = self:get_direction() local dir = self:get_direction()
local m = Matrix.create_identity()
if dir == "west" then if dir == "west" then
cr:rotate(pi / 2) m:rotate(pi / 2)
cr:translate(0, -width) m:translate(0, -width)
elseif dir == "south" then elseif dir == "south" then
cr:rotate(pi) m:rotate(pi)
cr:translate(-width, -height) m:translate(-width, -height)
elseif dir == "east" then elseif dir == "east" then
cr:rotate(3 * pi / 2) m:rotate(3 * pi / 2)
cr:translate(-height, 0) m:translate(-height, 0)
end end
-- 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(context, cr, self.widget, 0, 0, transform(self, width, height)) return { base.place_widget_via_matrix(self.widget, m, transform(self, width, height)) }
end end
--- Fit this layout into the given area --- Fit this layout into the given area
@ -58,15 +60,11 @@ end
--- Set the widget that this layout rotates. --- Set the widget that this layout rotates.
function rotate:set_widget(widget) function rotate:set_widget(widget)
if self.widget then
self.widget:disconnect_signal("widget::updated", self._emit_updated)
end
if widget then if widget then
widget_base.check_widget(widget) widget_base.check_widget(widget)
widget:weak_connect_signal("widget::updated", self._emit_updated)
end end
self.widget = widget self.widget = widget
self._emit_updated() self:emit_signal("widget::layout_changed")
end end
--- Reset this layout. The widget will be removed and the rotation reset. --- Reset this layout. The widget will be removed and the rotation reset.
@ -90,7 +88,7 @@ function rotate:set_direction(dir)
end end
self.direction = dir self.direction = dir
self._emit_updated() self:emit_signal("widget::layout_changed")
end end
--- Get the direction of this rotating layout --- Get the direction of this rotating layout
@ -112,10 +110,6 @@ local function new(widget, dir)
end end
end end
ret._emit_updated = function()
ret:emit_signal("widget::updated")
end
ret:set_widget(widget) ret:set_widget(widget)
ret:set_direction(dir or "north") ret:set_direction(dir or "north")