Created
June 29, 2018 08:01
-
-
Save krystofbe/b961a98de8ab00ac12250ed9d0d0a24d 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
-- None of this animation shit: | |
hs.window.animationDuration = 0 | |
-- Get list of screens and refresh that list whenever screens are plugged or unplugged: | |
local screens = hs.screen.allScreens() | |
local screenwatcher = hs.screen.watcher.new(function() | |
screens = hs.screen.allScreens() | |
end) | |
screenwatcher:start() | |
-- Modifier shortcuts | |
local alt = {"⌥"} | |
local hyper = {"⌘", "⌥", "⌃", "⇧"} | |
local nudgekey = {"⌥", "⌃"} | |
local yankkey = {"⌥", "⌃","⇧"} | |
local pushkey = {"⌃", "⌘"} | |
local shiftpushkey= {"⌃", "⌘", "⇧"} | |
-- -------------------------------------------------------- | |
-- Helper functions - these do all the heavy lifting below. | |
-- Names are roughly stolen from same functions in Slate :) | |
-- -------------------------------------------------------- | |
-- Move a window a number of pixels in x and y | |
function nudge(xpos, ypos) | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.x = f.x + xpos | |
f.y = f.y + ypos | |
win:setFrame(f) | |
end | |
-- Resize a window by moving the bottom | |
function yank(xpixels,ypixels) | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
f.w = f.w + xpixels | |
f.h = f.h + ypixels | |
win:setFrame(f) | |
end | |
-- Resize window for chunk of screen. | |
-- For x and y: use 0 to expand fully in that dimension, 0.5 to expand halfway | |
-- For w and h: use 1 for full, 0.5 for half | |
function push(x, y, w, h) | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w*x) | |
f.y = max.y + (max.h*y) | |
f.w = max.w*w | |
f.h = max.h*h | |
win:setFrame(f) | |
end | |
-- Move to monitor x. Checks to make sure monitor exists, if not moves to last monitor that exists | |
function moveToMonitor(x) | |
local win = hs.window.focusedWindow() | |
local newScreen = nil | |
while not newScreen do | |
newScreen = screens[x] | |
x = x-1 | |
end | |
win:moveToScreen(newScreen) | |
end | |
-- ----------------- | |
-- Window management | |
-- ----------------- | |
-- Movement hotkeys | |
hs.hotkey.bind(nudgekey, 'down', function() nudge(0,100) end) --down | |
hs.hotkey.bind(nudgekey, "up", function() nudge(0,-100) end) --up | |
hs.hotkey.bind(nudgekey, "right", function() nudge(100,0) end) --right | |
hs.hotkey.bind(nudgekey, "left", function() nudge(-100,0) end) --left | |
-- Resize hotkeys | |
hs.hotkey.bind(yankkey, "up", function() yank(0,-100) end) -- yank bottom up | |
hs.hotkey.bind(yankkey, "down", function() yank(0,100) end) -- yank bottom down | |
hs.hotkey.bind(yankkey, "right", function() yank(100,0) end) -- yank right side right | |
hs.hotkey.bind(yankkey, "left", function() yank(-100,0) end) -- yank right side left | |
-- Push to screen edge | |
hs.hotkey.bind(pushkey,"left", function() push(0,0,0.5,1) end) -- left side | |
hs.hotkey.bind(pushkey,"right", function() push(0.5,0,0.5,1) end) -- right side | |
hs.hotkey.bind(pushkey,"up", function() push(0,0,1,0.5) end) -- top half | |
hs.hotkey.bind(pushkey,"down", function() push(0,0.5,1,0.5) end) -- bottom half | |
-- Center window with some room to see the desktop | |
hs.hotkey.bind(pushkey, "m", function() push(0.05,0.05,0.9,0.9) end) | |
-- Fullscreen | |
hs.hotkey.bind(pushkey, "f", function() push(0,0,1,1) end) | |
-- Chat windows (arrange in grid of 3 screen) | |
hs.hotkey.bind(pushkey, "7", function() push(0,0,0.3,1) end) | |
hs.hotkey.bind(pushkey, "8", function() push(0.3,0,0.4,1) end) | |
hs.hotkey.bind(pushkey, "9", function() push(0.7,0,0.3,1) end) | |
-- Quarters | |
hs.hotkey.bind(pushkey, "6", function() push(0,0,0.3,0.5) end) | |
hs.hotkey.bind(pushkey,"5", function() push(0,0.5,0.3,0.5) end) -- bottom half | |
-- Move a window between monitors | |
hs.hotkey.bind(pushkey,"1", function() moveToMonitor(1) end) -- Move to first monitor | |
hs.hotkey.bind(shiftpushkey,"1", function() -- Move to first monitor and fullscreen | |
moveToMonitor(1) | |
push(0,0,1,1) | |
end) | |
hs.hotkey.bind(pushkey,"2", function() moveToMonitor(2) end) -- Move to second monitor | |
hs.hotkey.bind(shiftpushkey,"2", function() -- Move to second monitor and fullscreen | |
moveToMonitor(2) | |
push(0,0,1,1) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment