Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Commit

Permalink
sliding panels updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asmagill committed Oct 30, 2017
1 parent 0d3b779 commit 633a816
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 104 deletions.
27 changes: 5 additions & 22 deletions _Spoons/SlidingPanels.spoon/README.md
Expand Up @@ -3,38 +3,21 @@ SlidingPanels

Create sliding panels which can emerge from the sides of your monitor to display canvas and guitk element objects

Also requires [hs._asm.guitk](https://github.com/asmagill/hammerspoon_asm/tree/master/guitk) version 0.1.4.1alpha or newer to be installed. GUITK is a candidate for future inclusion in the Hammerspoon core modules, so hopefully this requirement is temporary
Also requires [hs._asm.guitk](https://github.com/asmagill/hammerspoon_asm/tree/master/guitk) version 0.1.5alpha or newer to be installed. GUITK is a candidate for future inclusion in the Hammerspoon core modules, so hopefully this requirement is temporary

TODO:
* Document, including docs.json file and slidingPanelObject.lua version
* Add methods to add/remove canvas and guitk element objects, including slidingPanelObject.lua version

Download: `svn export https://github.com/asmagill/hammerspoon-config/trunk/_Spoons/SlidingPanels.spoon`

This is so much a work in progress that I hesitate to even recommend that you look at it. An example can be tried by saving the following in a file and the loading it with `require` or `dofile`:
### Status

~~~lua
local slidingPanels = hs.loadSpoon("SlidingPanels")

slidingPanels:addPanel("infoPanel", {
size = 1/3,
modifiers = { "fn" },
persistent = true,
animationDuration = 0.1,
color = { white = .35 },
fillAlpha = .95,
}):enable()

slidingPanels:panel("infoPanel"):addWidget("HCalendar", { rX = "100%", bY = "100%" })
slidingPanels:panel("infoPanel"):addWidget("CircleClock", { rX = "100%", y = 0 })
slidingPanels:panel("infoPanel"):addWidget("MountedVolumes", { x = 0, bY = "100%" }, { cornerRadius = 20 })

return slidingPanels:panel("infoPanel")
~~~
This is so much a work in progress that I hesitate to even recommend that you look at it. An example of how to use it can be found at https://github.com/asmagill/hammerspoon-config/tree/master/utils/_panels/infoPanel.lua.

You will also need the `MountedVolumes` spoon for the example (or remove the third `addWidget` line) which is currently available at https://github.com/asmagill/hammerspoon-config/tree/master/_Spoons/MountedVolumes.spoon (the MountedVolumes spoon doesn't require `hs._asm.guitk`, so it may be moved to the core spoon repository soon)
You will also need the `MountedVolumes` spoon for the example (or remove the third `addWidget` line) which is currently available at https://github.com/asmagill/Spoons/raw/MountedVolumes/Spoons/MountedVolumes.spoon.zip (a pull request to the Hammerspoon master spoon repository has been submitted, but hasn't been merged yet)

To trigger the panel, hold down the `fn` key on your keyboard and move the mouse pointer to the bottom of the screen and wait a second or two. If you are not on a laptop, you can remove (or change) the requirement to use the `fn` key by removing the `modifiers` line above.
To trigger the panel, hold down the `fn` key on your keyboard and move the mouse pointer to the bottom of the screen and wait a second or two. If you are not on a laptop, you can remove (or change) the requirement to use the `fn` key by removing the `modifiers` line.

To release the panel, move the mouse up and then back to the bottom of the screen (`fn` is not required to release the panel).

Expand Down
60 changes: 0 additions & 60 deletions _Spoons/SlidingPanels.spoon/widgets/CircleClock.lua

This file was deleted.

61 changes: 60 additions & 1 deletion _Spoons/SlidingPanels.spoon/widgets/FromSpoon.lua
Expand Up @@ -7,6 +7,10 @@
-- * canvas - string specifying the name of the canvas as stored within the spoon (usually "canvas" or similar)
-- * start - string naming method to invoke to start/show/build the canvas or function(spoon) ... end which does the starting
-- * vars - table of key-value pairs for spoon to be set before "start", if present, is invoked
-- * background - a table specifying a canvas element, e.g. a rectangle or an image, to use as the background for the spoon canvas. This can be useful to provide contrast if the spoon's coloring is hard to see against the panel's background.

local guitk = require("hs._asm.guitk")
local canvas = require("hs.canvas")

return function(name, frameDetails, config)
local s, spoon = pcall(hs.loadSpoon, name)
Expand All @@ -31,5 +35,60 @@ return function(name, frameDetails, config)
frameDetails = frameDetails or {}
frameDetails.id = frameDetails.id or name

return spoon[config.canvas or "canvas"], frameDetails
local spoonCanvas = spoon[config.canvas or "canvas"]
local spoonWrapper

if config.background then
local spoonCanvasSize = spoonCanvas:size()
spoonWrapper = guitk.manager.new(spoonCanvasSize)
spoonWrapper[1] = {
id = "background",
frameDetails = { x = 0, y = 0, h = "100%", w = "100%" },
_element = canvas.new{}:insertElement(config.background),
}
spoonWrapper[2] = {
id = "spoon",
frameDetails = { x = 0, y = 0, h = "100%", w = "100%" },
_element = spoonCanvas,
}
frameDetails.h = frameDetails.h or spoonCanvasSize.h
frameDetails.w = frameDetails.w or spoonCanvasSize.w

-- The wrappers for canvas's :topLeft, :size, and :frame methods update the frameDetails for the canvas object.
-- If the spoon code changes the frame in any way (timers, changing content, etc.) we need to convert that into
-- a change to the guitk wrapper we've created to allow for the background could be inserted for this widget
-- instead.

spoonWrapper:frameChangeCallback(function(manager, target)
-- the spoon only knows about the canvas it created, so that's the only one we need to worry about
-- in this callback
if target == spoonCanvas then
local managerFrameDetails = manager:frameDetails()
local changedFrame = spoonCanvas:frame()
-- even without the x and y keys, since guitk imports the table into an NSDictionary, including this key
-- would cause LuaSkin to treat the partial rect table as a rect, filling in a 0 for the x and y keys.
changedFrame.__luaSkinType = nil

-- NOTE: GUITK cannot distinguish between a change in size or a change in location or both -- they all
-- generate the same notification.
--
-- For SlidingPanels, it's safe to ignore the x and y components completely -- you're supposed
-- to only move the object by using SlidingPanel methods. However, if you're looking at this code
-- as an example for your own designs, be aware that this callback cannot determine *what* changed
-- unless you've saved the old frame information (frameDetails._effective) for comparison here.
--
-- Hopefully this will all become moot once GUITK is in core and canvas is updated to be more
-- tightly integrated with it.
--
changedFrame.x, changedFrame.y = nil, nil

-- change the manager first or you'll get multiple callbacks -- a callback is triggered *only*
-- when the effective frame changes, not simply because frameDetails was invoked.
manager:frameDetails(changedFrame)
manager:elementFrameDetails(spoonCanvas, { x = 0, y = 0, h = "100%", w = "100%" })
end
end)
end

return (spoonWrapper or spoonCanvas), frameDetails
end
19 changes: 0 additions & 19 deletions infoPanel.lua

This file was deleted.

4 changes: 2 additions & 2 deletions init.lua
Expand Up @@ -84,9 +84,11 @@ _asm.hexstring2ascii = function(stuff)
end
_asm.watchables = require("utils.watchables")

_asm._panels = requirePlus.requirePath("utils._panels")
_asm._keys = requirePlus.requirePath("utils._keys")
_asm._actions = requirePlus.requirePath("utils._actions")
_asm._menus = requirePlus.requirePath("utils._menus")

-- need to rethink requirePlus so that it can handle folders with name/init.lua
_asm._menus.XProtectStatus = require"utils._menus.XprotectStatus"

Expand Down Expand Up @@ -214,8 +216,6 @@ _asm.tbi = touchbar.item.newButton(image.imageFromName(image.systemImageNames.Ap
:callback(function(obj) hs.openConsole() end)
:addToSystemTray(true)

_asm.infoPanel = require("infoPanel")

if package.searchpath("hs.network.ping", package.path) then
ping = require("hs.network.ping")
end
Expand Down
38 changes: 38 additions & 0 deletions utils/_panels/infoPanel.lua
@@ -0,0 +1,38 @@
local slidingPanels = hs.loadSpoon("SlidingPanels")

slidingPanels:addPanel("infoPanel", {
size = 1/3,
modifiers = { "fn" },
persistent = true,
animationDuration = 0.1,
color = { white = .35 },
fillAlpha = .95,
}):enable()

-- the "FromSpoon" widget takes the following arguments:
--
-- * spoonName - string
-- * frameDetails - table containing frameDetails describing where to place canvas within panel (see guitk.manager)
-- * spoonConfig - table
-- * canvas - string specifying the name of the canvas as stored within the spoon (usually "canvas" or similar)
-- * start - string naming method to invoke to start/show/build the canvas or function(spoon) ... end which does the starting
-- * vars - table of key-value pairs for spoon to be set before "start", if present, is invoked
-- * background - a table specifying a canvas element, e.g. a rectangle or an image, to use as the background for the spoon canvas. This can be useful to provide contrast if the spoon's coloring is hard to see against the panel's background.

slidingPanels:panel("infoPanel"):addWidget("FromSpoon", "HCalendar", { rX = "100%", bY = "100%" })

slidingPanels:panel("infoPanel"):addWidget("FromSpoon", "CircleClock", { rX = "100%", y = 0 }, {
background = {
type = "rectangle",
action = "fill",
roundedRectRadii = { xRadius = 20, yRadius = 20 },
fillColor = { red = .4, blue = .32, green = .32, alpha = .7 },
},
})

slidingPanels:panel("infoPanel"):addWidget("FromSpoon", "MountedVolumes", { x = 0, bY = "100%" }, {
start = "show", -- could also be `function(spoon) spoon:show() end``
vars = { cornerRadius = 20 },
})

return slidingPanels:panel("infoPanel")

0 comments on commit 633a816

Please sign in to comment.