From 1091771455f69f9ada0aa7c29ce26014a73fe1ac Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Fri, 9 Apr 2021 20:46:32 -0700 Subject: [PATCH] Anims Added awestore support for scratchpad --- module/scratchpad.lua | 72 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/module/scratchpad.lua b/module/scratchpad.lua index db1528a..55efada 100644 --- a/module/scratchpad.lua +++ b/module/scratchpad.lua @@ -50,11 +50,45 @@ function Scratchpad:turn_on() if self.reapply then self:apply(c) end -- c.sticky was set to false in turn_off so it has to be reapplied anyway c.sticky = self.sticky + local new_y = c.y + local new_x = c.x + + -- Get the tweens + local anim_x = self.awestore.x + local anim_y = self.awestore.y + + -- Subscribe + if anim_x then + anim_x:subscribe(function(x) if c then c.x = x end end) + end + if anim_y then + anim_y:subscribe(function(y) if c then c.y = y end end) + end + helpers.client.turn_on(c) - return + + -- Unsubscribe + if anim_x then + anim_x:set(new_x) + local unsub + unsub = anim_x.ended:subscribe( + function() + unsub() + return + end) + end + if anim_y then + anim_y:set(new_y) + local unsub_y + unsub_y = anim_y.ended:subscribe( + function() + unsub_y() + return + end) + end else -- if no client was found, spawn one, find the corresponding window, - -- apply the properties only once (until the next closing) + -- apply the properties only once (until the next closing) local pid = awful.spawn.with_shell(self.command) local function inital_apply(c) if helpers.client.is_child_of(c, pid) then self:apply(c) end @@ -71,7 +105,39 @@ function Scratchpad:turn_off() local c = matches[1] if c then c.sticky = false - helpers.client.turn_off(c) + + -- Get the tweens + local anim_x = self.awestore.x + local anim_y = self.awestore.y + + -- Subscribe + if anim_x then + anim_x:subscribe(function(x) if c then c.x = x end end) + end + if anim_y then + anim_y:subscribe(function(y) if c then c.y = y end end) + end + + -- Unsubscribe + if anim_x then + anim_x:set(anim_x:initial()) + local unsub + unsub = anim_x.ended:subscribe( + function() + helpers.client.turn_off(c) + unsub() + end) + end + if anim_y then + anim_y:set(anim_y:initial()) + + local unsub + unsub = anim_y.ended:subscribe( + function() + helpers.client.turn_off(c) + unsub() + end) + end end end