Last active
March 29, 2023 09:46
-
-
Save alexanderflink/a40a43d9a025553e3cfd36f618c688dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local spaces = require('hs.spaces') -- https://github.com/asmagill/hs._asm.undocumented.spaces | |
-- Switch alacritty | |
hs.hotkey.bind({'alt'}, 'space', function () | |
local APP_NAME = 'Alacritty' | |
function moveWindow(alacritty, space, mainScreen) | |
-- move to main space | |
local win = nil | |
while win == nil do | |
win = alacritty:mainWindow() | |
end | |
print(win) | |
print(space) | |
print(win:screen()) | |
print(mainScreen) | |
local fullScreen = not win:isStandard() | |
if fullScreen then | |
hs.eventtap.keyStroke('cmd', 'return', 0, alacritty) | |
end | |
winFrame = win:frame() | |
scrFrame = mainScreen:fullFrame() | |
print(winFrame) | |
print(scrFrame) | |
winFrame.w = scrFrame.w | |
winFrame.y = scrFrame.y | |
winFrame.x = scrFrame.x | |
print(winFrame) | |
win:setFrame(winFrame, 0) | |
print(win:frame()) | |
spaces.moveWindowToSpace(win, space) | |
if fullScreen then | |
hs.eventtap.keyStroke('cmd', 'return', 0, alacritty) | |
end | |
win:focus() | |
end | |
local alacritty = hs.application.get(APP_NAME) | |
if alacritty ~= nil and alacritty:isFrontmost() then | |
alacritty:hide() | |
else | |
local space = spaces.activeSpaceOnScreen() | |
local mainScreen = hs.screen.mainScreen() | |
if alacritty == nil and hs.application.launchOrFocus(APP_NAME) then | |
local appWatcher = nil | |
print('create app watcher') | |
appWatcher = hs.application.watcher.new(function(name, event, app) | |
print(name) | |
print(event) | |
if event == hs.application.watcher.launched and name == APP_NAME then | |
app:hide() | |
moveWindow(app, space, mainScreen) | |
appWatcher:stop() | |
end | |
end) | |
print('start watcher') | |
appWatcher:start() | |
end | |
if alacritty ~= nil then | |
moveWindow(alacritty, space, mainScreen) | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment