Skip to content

Instantly share code, notes, and snippets.

@dphase
Created September 10, 2014 13:08
Show Gist options
  • Save dphase/554d43f802f8205ad081 to your computer and use it in GitHub Desktop.
Save dphase/554d43f802f8205ad081 to your computer and use it in GitHub Desktop.
-- Modules
-- --------------------------------------------------------------------------------
local application = require "mjolnir.application"
local window = require "mjolnir.window"
local hotkey = require "mjolnir.hotkey"
local fnutils = require "mjolnir.fnutils"
local alert = require "mjolnir.alert"
local grid = require "mjolnir.sd.grid"
-- Grid Setup
-- --------------------------------------------------------------------------------
grid.GRIDWIDTH = 2
-- Keybinding Modifiers
-- --------------------------------------------------------------------------------
local kb = {"cmd", "alt", "ctrl"}
local kb_alt = {"cmd", "alt", "shift"}
local kb_mod = {"cmd", "ctrl"}
-- Window Management Functions
-- --------------------------------------------------------------------------------
-- Current window in focus
local function this_win()
return window.focusedwindow()
end
-- Move window by n @ x/y
local function wm_move(win, x, y)
local f = win:frame()
f.x = f.x + x
f.y = f.y + y
win:setframe(f)
end
-- Resize window by n @ w/h
local function wm_resize(win, w, h)
local f = win:frame()
f.w = f.w + w
f.h = f.h + h
win:setframe(f)
end
-- Keybindings
-- --------------------------------------------------------------------------------
-- Placement
-- --------------------------------------------------------------------------------
hotkey.bind(kb, 'down', grid.pushwindow_down)
hotkey.bind(kb, 'up', grid.pushwindow_up)
hotkey.bind(kb, 'left', function()
grid.resizewindow_thinner()
grid.pushwindow_left()
end)
hotkey.bind(kb, 'right', function()
grid.resizewindow_thinner()
grid.pushwindow_right()
end)
-- Sizing
-- --------------------------------------------------------------------------------
hotkey.bind(kb, 'm', grid.maximize_window)
hotkey.bind(kb, ',', grid.resizewindow_taller)
hotkey.bind(kb, '.', grid.resizewindow_wider)
hotkey.bind(kb, '/', grid.resizewindow_thinner)
-- Shrink/Grow width by 10
hotkey.bind(kb_alt, 'left', function() wm_resize(this_win(), -10, 0) end)
hotkey.bind(kb_alt, 'right', function() wm_resize(this_win(), 10, 0) end)
-- Grid
-- --------------------------------------------------------------------------------
hotkey.bind(kb, '=', function() grid.adjustwidth( 1) end)
hotkey.bind(kb, '-', function() grid.adjustwidth(-1) end)
hotkey.bind(kb, ';', function() grid.snap(window.focusedwindow()) end)
-- Desktops
-- --------------------------------------------------------------------------------
hotkey.bind(kb_mod, 'left', grid.pushwindow_prevscreen)
hotkey.bind(kb_mod, 'right', grid.pushwindow_nextscreen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment