feat: hide panel when hyprpicker triggered from panel (#16)
This commit is contained in:
+49
-13
@@ -17,6 +17,13 @@ local SERVICE = "oldirtty/color_picker:service"
|
|||||||
local swatch_radius = noctalia.getConfig("swatch-radius")
|
local swatch_radius = noctalia.getConfig("swatch-radius")
|
||||||
local tr_color_picker = noctalia.tr("color_picker")
|
local tr_color_picker = noctalia.tr("color_picker")
|
||||||
|
|
||||||
|
-- Set right before closing the panel to hand off to hyprpicker (so the
|
||||||
|
-- panel doesn't cover the screen area being sampled). onClose() checks
|
||||||
|
-- this to skip committing the stale selection on that technical close,
|
||||||
|
-- and the selectedColor watch checks it to reopen the panel once the
|
||||||
|
-- service reports a result -- instead of just re-rendering a closed panel.
|
||||||
|
local waitingForPanelPick = false
|
||||||
|
|
||||||
--==============================================
|
--==============================================
|
||||||
-- TRANSLATION HELPER
|
-- TRANSLATION HELPER
|
||||||
--==============================================
|
--==============================================
|
||||||
@@ -354,10 +361,14 @@ end
|
|||||||
-- CALLBACKS: picking (delegates to the service)
|
-- CALLBACKS: picking (delegates to the service)
|
||||||
--==============================================
|
--==============================================
|
||||||
|
|
||||||
-- Panel's own pick button: asks the service to pick and update the
|
-- Panel's own pick button: just closes the panel (so it doesn't cover the
|
||||||
-- selection only. No history commit until the panel closes.
|
-- area being sampled). The actual pick is triggered from onClose(), which
|
||||||
|
-- only fires once the close animation has actually finished -- firing the
|
||||||
|
-- pick here instead would race the animation and hyprpicker would freeze
|
||||||
|
-- mid-transition.
|
||||||
function onPickClickedFromPanel()
|
function onPickClickedFromPanel()
|
||||||
sendToService("pick-panel")
|
waitingForPanelPick = true
|
||||||
|
panel.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function onNativePickerClicked()
|
function onNativePickerClicked()
|
||||||
@@ -368,18 +379,43 @@ function onCloseClicked()
|
|||||||
panel.close()
|
panel.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Panel closed (any path: close button, Esc, click outside). Commits
|
-- Panel closed. Two cases:
|
||||||
-- whatever is currently selected to the service's history.
|
-- - Technical close to hand off to hyprpicker (waitingForPanelPick): ask
|
||||||
|
-- the service to pick now that the close animation is done, then wait
|
||||||
|
-- for the selectedColor watch to reopen the panel. No commit yet --
|
||||||
|
-- the selection isn't final until the panel closes for real.
|
||||||
|
--
|
||||||
|
-- - Real close (close button, Esc, click outside): commit whatever is
|
||||||
|
-- currently selected to the service's history.
|
||||||
function onClose()
|
function onClose()
|
||||||
local hex = getSelectedColor()
|
if waitingForPanelPick then
|
||||||
if hex == nil then return end
|
sendToService("pick-panel")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local payload = hex .. ":" .. tostring(getSelectedOpacity())
|
local hex = getSelectedColor()
|
||||||
sendToService("commit", payload)
|
if hex == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local payload = hex .. ":" .. tostring(getSelectedOpacity())
|
||||||
|
sendToService("commit", payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onOpen(context)
|
function onOpen(context)
|
||||||
noctalia.state.watch("selectedColor", function() render() end)
|
-- Wait user pick a color to render panel
|
||||||
noctalia.state.watch("colorHistory", function() render() end)
|
-- when launching hyprpicker from panel's button
|
||||||
render()
|
noctalia.state.watch("selectedColor", function()
|
||||||
end
|
if waitingForPanelPick then
|
||||||
|
waitingForPanelPick = false
|
||||||
|
noctalia.togglePanel("oldirtty/color_picker:panel")
|
||||||
|
else
|
||||||
|
render()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
noctalia.state.watch("colorHistory", function()
|
||||||
|
render()
|
||||||
|
end)
|
||||||
|
render()
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user