-
Hello everyone. I would like to improve my window management keymaps to not only move/resize windows to, for example, the left half of the screen, but also the left one_third ord two_thirds. There’s probably some rather easy and very elegant solution to this, but I did not find anything helpful during my research. Here’s my prototypical code, which … is definitely not very elegant. Also I would like to implement the same behavior for other keymaps, so the
Maybe someone could help out, please? PS: I could use https://github.com/peterklijn/hammerspoon-shiftit for my purposes, but from a learning-perspective I’d still be interested if there’s an easy and elegant solution besides something rather complex as the following examples: Or maybe, well, there is not easier solution to this problem … |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@fooness perhaps ask over on Discord too: https://discord.gg/3KxPBF9v |
Beta Was this translation helpful? Give feedback.
-
you can do this with a helper: function hotkeybindcycle(modifier, key, message, callbackMap)
local currentIndex = 1
local maxIndex = #callbackMap
local hotkeyHandler
hotkeyHandler = hs.hotkey.bind(modifier, key, message, function()
callbackMap[currentIndex]()
currentIndex = (currentIndex % maxIndex) + 1
end)
end source: https://github.com/muescha/dot_hammerspoon/blob/master/Helpers/HotkeyBindCycle.lua require("Helpers.HotkeyBindCycle")
fileInfo()
hotkeybindcycle(hyper, "v", keyInfo("Cycle abc"), {
function() print("a") end,
function() print("b") end,
function() print("c") end,
})
hotkeybindcycle(hyper, "b", keyInfo("Cycle defg"), {
function() print("d") end,
function() print("e") end,
function() print("f") end,
function() print("g") end,
}) source: https://github.com/muescha/dot_hammerspoon/blob/master/Functions/HotkeybindCycleTest.lua you need to adjust the |
Beta Was this translation helpful? Give feedback.
-
if you like to have an variable for all keys you can do a table with the key cycleIndex = {}
modifier = { "cmd", "ctrl" }
key = "h"
cycleIndex[{modifier,key}] = 1 -- init index
hs.hotkey.bind(modifier,key, function()
var currentIndex = cycleIndex[{modifier,key}] -- get the current index
if currentIndex == 1 then
-- do something
elseif currentIndex == 2 then
-- do something
elseif currentIndex == 3 then
-- do something
end
cycleIndex[{modifier,key}] = (cycleIndex[{modifier,key}] % maxIndex) + 1
end) |
Beta Was this translation helpful? Give feedback.
you can do this with a helper:
source: https://github.com/muescha/dot_hammerspoon/blob/master/Helpers/HotkeyBindCycle.lua