326 lines
7.8 KiB
Lua
326 lines
7.8 KiB
Lua
--------------------------------------------------------------------------
|
|
hyperModeAppMappings = {
|
|
{ 'a', 'Alacritty' }, -- "A" for "Apple Music"
|
|
{ 's', 'Safari' }, -- "S" for "Safari"
|
|
{ 'c', 'Telegram' }, -- "C for "Chat"
|
|
{ 'd', 'Discord' }, -- "D for "Discord"
|
|
{ 'f', 'Finder' }, -- "F" for "Finder"
|
|
{ 'g', 'Mail' }, -- "G" for "Gmail"
|
|
{ 'z', 'Slack' }, -- "Z" for "zzz"
|
|
{ 'n', 'Notion' }, -- "N" for "Notion"
|
|
{ 'm', 'Music' }, -- "M" for "Music"
|
|
{ 'w', 'World of Warcraft Classic' }, -- "W" for "World of Warcraft"
|
|
}
|
|
|
|
for i, mapping in ipairs(hyperModeAppMappings) do
|
|
local key = mapping[1]
|
|
local app = mapping[2]
|
|
hs.hotkey.bind({'shift', 'ctrl', 'alt', 'cmd'}, key, function()
|
|
if (type(app) == 'string') then
|
|
hs.application.open(app)
|
|
elseif (type(app) == 'function') then
|
|
app()
|
|
else
|
|
hs.logger.new('hyper'):e('Invalid mapping for Hyper +', key)
|
|
end
|
|
end)
|
|
end
|
|
--------------------------------------------------------------------------
|
|
hs.window.animationDuration = 0
|
|
|
|
-- +-----------------+
|
|
-- | | |
|
|
-- | HERE | |
|
|
-- | | |
|
|
-- +-----------------+
|
|
function hs.window.left(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x
|
|
f.y = max.y
|
|
f.w = max.w / 2
|
|
f.h = max.h
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | | |
|
|
-- | | HERE |
|
|
-- | | |
|
|
-- +-----------------+
|
|
function hs.window.right(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x + (max.w / 2)
|
|
f.y = max.y
|
|
f.w = max.w / 2
|
|
f.h = max.h
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | HERE |
|
|
-- +-----------------+
|
|
-- | |
|
|
-- +-----------------+
|
|
function hs.window.up(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x
|
|
f.w = max.w
|
|
f.y = max.y
|
|
f.h = max.h / 2
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | |
|
|
-- +-----------------+
|
|
-- | HERE |
|
|
-- +-----------------+
|
|
function hs.window.down(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x
|
|
f.w = max.w
|
|
f.y = max.y + (max.h / 2)
|
|
f.h = max.h / 2
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | HERE | |
|
|
-- +--------+ |
|
|
-- | |
|
|
-- +-----------------+
|
|
function hs.window.upLeft(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:fullFrame()
|
|
|
|
f.x = max.x
|
|
f.y = max.y
|
|
f.w = max.w/2
|
|
f.h = max.h/2
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | |
|
|
-- +--------+ |
|
|
-- | HERE | |
|
|
-- +-----------------+
|
|
function hs.window.downLeft(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:fullFrame()
|
|
|
|
f.x = max.x
|
|
f.y = max.y + (max.h / 2)
|
|
f.w = max.w/2
|
|
f.h = max.h/2
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | |
|
|
-- | +--------|
|
|
-- | | HERE |
|
|
-- +-----------------+
|
|
function hs.window.downRight(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:fullFrame()
|
|
|
|
f.x = max.x + (max.w / 2)
|
|
f.y = max.y + (max.h / 2)
|
|
f.w = max.w/2
|
|
f.h = max.h/2
|
|
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | | HERE |
|
|
-- | +--------|
|
|
-- | |
|
|
-- +-----------------+
|
|
function hs.window.upRight(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:fullFrame()
|
|
|
|
f.x = max.x + (max.w / 2)
|
|
f.y = max.y
|
|
f.w = max.w/2
|
|
f.h = max.h/2
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +--------------+
|
|
-- | | | |
|
|
-- | | HERE | |
|
|
-- | | | |
|
|
-- +---------------+
|
|
function hs.window.centerWithFullHeight(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:fullFrame()
|
|
|
|
f.x = max.x + (max.w / 5)
|
|
f.w = max.w * 3/5
|
|
f.y = max.y
|
|
f.h = max.h
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | | |
|
|
-- | HERE | |
|
|
-- | | |
|
|
-- +-----------------+
|
|
function hs.window.left40(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x
|
|
f.y = max.y
|
|
f.w = max.w * 0.4
|
|
f.h = max.h
|
|
win:setFrame(f)
|
|
end
|
|
|
|
-- +-----------------+
|
|
-- | | |
|
|
-- | | HERE |
|
|
-- | | |
|
|
-- +-----------------+
|
|
function hs.window.right60(win)
|
|
local f = win:frame()
|
|
local screen = win:screen()
|
|
local max = screen:frame()
|
|
|
|
f.x = max.x + (max.w * 0.4)
|
|
f.y = max.y
|
|
f.w = max.w * 0.6
|
|
f.h = max.h
|
|
win:setFrame(f)
|
|
end
|
|
|
|
function hs.window.nextScreen(win)
|
|
local currentScreen = win:screen()
|
|
local allScreens = hs.screen.allScreens()
|
|
currentScreenIndex = hs.fnutils.indexOf(allScreens, currentScreen)
|
|
nextScreenIndex = currentScreenIndex + 1
|
|
|
|
if allScreens[nextScreenIndex] then
|
|
win:moveToScreen(allScreens[nextScreenIndex])
|
|
else
|
|
win:moveToScreen(allScreens[1])
|
|
end
|
|
end
|
|
|
|
windowLayoutMode = hs.hotkey.modal.new({}, 'F16')
|
|
|
|
windowLayoutMode.entered = function()
|
|
windowLayoutMode.statusMessage:show()
|
|
end
|
|
windowLayoutMode.exited = function()
|
|
windowLayoutMode.statusMessage:hide()
|
|
end
|
|
|
|
-- Bind the given key to call the given function and exit WindowLayout mode
|
|
function windowLayoutMode.bindWithAutomaticExit(mode, modifiers, key, fn)
|
|
mode:bind(modifiers, key, function()
|
|
mode:exit()
|
|
fn()
|
|
end)
|
|
end
|
|
|
|
local status, windowMappings = pcall(require, 'keyboard.windows-bindings')
|
|
|
|
-- if not status then
|
|
-- windowMappings = require('keyboard.windows-bindings-defaults')
|
|
-- end
|
|
|
|
local windowMappings = {
|
|
modifiers = {'ctrl'},
|
|
showHelp = false,
|
|
trigger = 's',
|
|
mappings = {
|
|
{ {}, 'return', 'maximize' },
|
|
{ {}, 'space', 'centerWithFullHeight' },
|
|
{ {}, 'h', 'left' },
|
|
{ {}, 'j', 'down' },
|
|
{ {}, 'k', 'up' },
|
|
{ {}, 'l', 'right' },
|
|
{ {'shift'}, 'h', 'left40' },
|
|
{ {'shift'}, 'l', 'right60' },
|
|
{ {}, 'i', 'upLeft' },
|
|
{ {}, 'o', 'upRight' },
|
|
{ {}, ',', 'downLeft' },
|
|
{ {}, '.', 'downRight' },
|
|
{ {}, 'n', 'nextScreen' },
|
|
{ {}, 'right', 'moveOneScreenEast' },
|
|
{ {}, 'left', 'moveOneScreenWest' },
|
|
}
|
|
}
|
|
|
|
local modifiers = windowMappings.modifiers
|
|
local showHelp = windowMappings.showHelp
|
|
local trigger = windowMappings.trigger
|
|
local mappings = windowMappings.mappings
|
|
|
|
function getModifiersStr(modifiers)
|
|
local modMap = { shift = '⇧', ctrl = '⌃', alt = '⌥', cmd = '⌘' }
|
|
local retVal = ''
|
|
|
|
for i, v in ipairs(modifiers) do
|
|
retVal = retVal .. modMap[v]
|
|
end
|
|
|
|
return retVal
|
|
end
|
|
|
|
local msgStr = getModifiersStr(modifiers)
|
|
msgStr = 'Window Layout Mode (' .. msgStr .. (string.len(msgStr) > 0 and '+' or '') .. trigger .. ')'
|
|
|
|
for i, mapping in ipairs(mappings) do
|
|
local modifiers, trigger, winFunction = table.unpack(mapping)
|
|
local hotKeyStr = getModifiersStr(modifiers)
|
|
|
|
if showHelp == true then
|
|
if string.len(hotKeyStr) > 0 then
|
|
msgStr = msgStr .. (string.format('\n%10s+%s => %s', hotKeyStr, trigger, winFunction))
|
|
else
|
|
msgStr = msgStr .. (string.format('\n%11s => %s', trigger, winFunction))
|
|
end
|
|
end
|
|
|
|
windowLayoutMode:bindWithAutomaticExit(modifiers, trigger, function()
|
|
--example: hs.window.focusedWindow():upRight()
|
|
local fw = hs.window.focusedWindow()
|
|
fw[winFunction](fw)
|
|
end)
|
|
end
|
|
|
|
local message = require('keyboard.status-message')
|
|
windowLayoutMode.statusMessage = message.new(msgStr)
|
|
|
|
-- Use modifiers+trigger to toggle WindowLayout Mode
|
|
hs.hotkey.bind(modifiers, trigger, function()
|
|
windowLayoutMode:enter()
|
|
end)
|
|
windowLayoutMode:bind(modifiers, trigger, function()
|
|
windowLayoutMode:exit()
|
|
end)
|