Skip to content

Commit

Permalink
Make AClock recalculate canvas on screen change (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhata authored Aug 7, 2024
1 parent e3768d5 commit ea1f07a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Source/AClock.spoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ for k, v in pairs(obj._attribs) do obj[k] = v end
---
--- Returns:
--- * The AClock object
function getframe(width, height)
local mainScreen = hs.screen.primaryScreen()
local mainRes = mainScreen:fullFrame()
return {
x = (mainRes.w - width) / 2,
y = (mainRes.h - height) / 2,
w = width,
h = height
}
end

function obj:init()
if not self.canvas then self.canvas = hs.canvas.new({x=0, y=0, w=0, h=0}) end
self.canvas[1] = {
Expand All @@ -72,16 +83,19 @@ function obj:init()
}
local mainScreen = hs.screen.primaryScreen()
local mainRes = mainScreen:fullFrame()
self.canvas:frame({
x = (mainRes.w-self.width)/2,
y = (mainRes.h-self.height)/2,
w = self.width,
h = self.height,
})
self.canvas:frame(getframe(self.width, self.height))
self._screen_watcher = hs.screen.watcher.new(function()
self:update_canvas()
end)
self._screen_watcher:start()
self._init_done = true
return self
end

function obj:update_canvas()
self.canvas:frame(getframe(self.width, self.height))
end

function obj:update_clock_text()
self.canvas[1].text = os.date(self.format)
end
Expand Down

0 comments on commit ea1f07a

Please sign in to comment.