-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
227 additions
and
225 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package.path = "/usr/local/share/lua/5.2/?.lua;"..package.path | ||
_ = require 'underscore' | ||
utils = require 'utils' | ||
layout = require 'layout' | ||
|
||
hs.grid.setGrid('6x6') | ||
hs.grid.setMargins(hs.geometry.new(10,10)) | ||
|
||
grid = {} | ||
grid.GRIDHEIGHT = 6 | ||
grid.GRIDWIDTH = 6 | ||
grid.MARGINX = 10 | ||
grid.MARGINY = 10 | ||
|
||
positions = { | ||
leftHalf = {x=0, y=0, w=grid.GRIDWIDTH / 2, h=grid.GRIDHEIGHT}, | ||
rightHalf = {x=grid.GRIDWIDTH / 2, y=0, w=grid.GRIDWIDTH / 2, h=grid.GRIDHEIGHT}, | ||
rightThird = {x=grid.GRIDWIDTH / 3 * 2, y=0, w=grid.GRIDWIDTH / 3, h=grid.GRIDHEIGHT}, | ||
leftThird = {x=0, y=0, w=grid.GRIDWIDTH / 3, h=grid.GRIDHEIGHT}, | ||
rightTwoThird = {x=grid.GRIDWIDTH / 3, y=0, w=grid.GRIDWIDTH / 3 * 2, h=grid.GRIDHEIGHT}, | ||
leftTwoThird = {x=0, y=0, w=grid.GRIDWIDTH / 3 * 2, h=grid.GRIDHEIGHT}, | ||
full = {x=0, y=0, w=grid.GRIDWIDTH, h=grid.GRIDHEIGHT}, | ||
|
||
lowerRight = {x=grid.GRIDWIDTH / 2, y=grid.GRIDWIDTH / 2, w=grid.GRIDWIDTH / 2, h=grid.GRIDWIDTH / 2}, | ||
upperRight = {x=grid.GRIDWIDTH / 2, y=0, w=grid.GRIDWIDTH / 2, h=grid.GRIDWIDTH / 2}, | ||
lowerLeft = {x=0, y=grid.GRIDWIDTH / 2, w=grid.GRIDWIDTH / 2, h=grid.GRIDWIDTH / 2}, | ||
upperLeft = {x=0, y=0, w=grid.GRIDWIDTH / 2, h=grid.GRIDWIDTH / 2}, | ||
} | ||
|
||
hs.hotkey.bind(utils.modifier, 'return', function () | ||
local win = hs.window.focusedWindow() | ||
local app = win:application() | ||
if string.match(app:title(), "iTerm") then | ||
win:maximize() | ||
else | ||
local frame = win:screen():frame() | ||
layout.setWindow(win, positions.full, win:screen()) | ||
end | ||
end) | ||
|
||
utils.setGrid('H', positions.leftHalf) | ||
utils.setGrid('L', positions.rightHalf) | ||
utils.setGrid('P', positions.rightThird) | ||
utils.setGrid('U', positions.leftThird) | ||
utils.setGrid('O', positions.rightTwoThird) | ||
utils.setGrid('I', positions.leftTwoThird) | ||
|
||
utils.setGrid(',', positions.lowerRight) | ||
utils.setGrid('K', positions.upperRight) | ||
utils.setGrid('M', positions.lowerRight) | ||
utils.setGrid('J', positions.upperRight) | ||
|
||
hs.hotkey.bind(utils.modifier, '=', function () | ||
local win = hs.window.focusedWindow() | ||
hs.grid.set(win, hs.grid.get(win), win:screen():next()) | ||
end) | ||
|
||
hs.hotkey.bind(utils.modifier, '-', function () | ||
local win = hs.window.focusedWindow() | ||
hs.grid.set(win, hs.grid.get(win), win:screen():previous()) | ||
end) | ||
|
||
layout.bind('Path Finder', { | ||
one = { main = positions.rightTwoThird }, | ||
two = { main = positions.rightHalf }, | ||
}) | ||
|
||
layout.bind('iTerm2', { | ||
one = { | ||
['custom'] = function (layout, screen, windows) | ||
_.each(windows, function(win) | ||
utils.setWindow(win, positions.full, layout.getScreens()[1].screen) | ||
win:maximize() | ||
end) | ||
end | ||
}, | ||
}) | ||
|
||
layout.bind('Dash', { | ||
one = { main = positions.rightTwoThird }, | ||
two = { alt1 = positions.rightTwoThird }, | ||
}) | ||
|
||
layout.bind('Mailplane 3', { | ||
one = { main = positions.rightTwoThird }, | ||
two = { main = positions.rightHalf }, | ||
}) | ||
|
||
layout.bind('Slack', { | ||
one = { main = positions.rightTwoThird }, | ||
two = { alt1 = positions.rightTwoThird }, | ||
}) | ||
|
||
layout.bind('Tweetbot', { | ||
one = { main = {x=0, y=0, w=grid.GRIDWIDTH / 3, h=grid.GRIDHEIGHT - 0.1} }, | ||
two = { alt1 = positions.leftThird }, | ||
}) | ||
|
||
layout.bind('iTunes', { | ||
one = { main = positions.full }, | ||
two = { alt1 = positions.full }, | ||
}) | ||
|
||
layout.bind('Messages', { | ||
one = { main = positions.upperRight }, | ||
two = { alt1 = positions.upperRight }, | ||
}) | ||
|
||
layout.bind('Dash', { | ||
one = { main = positions.rightHalf }, | ||
two = { alt1 = positions.rightTwoThird }, | ||
}) | ||
|
||
layout.bind('Google Chrome', { | ||
one = { main = positions.full }, | ||
two = { alt1 = positions.full }, | ||
}) | ||
|
||
layout.bind('Lightroom', { | ||
one = { main = positions.full }, | ||
two = { alt1 = positions.full }, | ||
}) | ||
|
||
hs.hotkey.bind(utils.modifier, 'e', function () | ||
layout.doChanges() | ||
end) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
layout = {} | ||
-- contains a table indexed by screen name and grid instructions | ||
layout.apps = {} | ||
|
||
local screens = hs.screen.allScreens() | ||
|
||
function length(tbl) | ||
local count = 0 | ||
for i, b in pairs(tbl) do | ||
count = count + 1 | ||
end | ||
return count | ||
end | ||
|
||
function layout.bind(app, locations) | ||
layout.apps[app] = _.extend(locations, { name = app }) | ||
end | ||
|
||
function layout.getScreens() | ||
local screens = hs.screen.allScreens() | ||
|
||
local scr = hs.screen.primaryScreen() | ||
|
||
local orderedScreens = {} | ||
layout.screens = {} | ||
|
||
orderedScreens[1] = { name='main',screen=scr } | ||
layout.screens[scr:name()] = 'main' | ||
local count = 1 | ||
while count < length(screens) and length(screens) > 1 do | ||
layout.screens[scr:name()] = 'alt' .. count | ||
scr = scr:next() | ||
orderedScreens[count + 1] = { name='alt' .. count,screen=scr } | ||
count = count + 1 | ||
end | ||
|
||
return orderedScreens | ||
end | ||
|
||
function layout.getLayout() | ||
local l = 'one' | ||
if length(hs.screen.allScreens()) == 2 then | ||
l = 'two' | ||
end | ||
return l | ||
end | ||
|
||
function layout.doChanges() | ||
local focused = hs.window.focusedWindow() | ||
hs.fnutils.each(layout.apps, function (app) | ||
layout.changeApp(app['name']) | ||
end) | ||
focused:focus() | ||
end | ||
|
||
function layout.changeApp(a) | ||
hs.fnutils.each(layout.getScreens(), function (s) | ||
local app = hs.application.find(a) | ||
local windows | ||
if app then windows = app:allWindows() else return end | ||
local activeLayout = layout.getLayout() | ||
local app = layout.apps[a] | ||
local screenName = s.name | ||
if app[activeLayout] then | ||
if app[activeLayout]['custom'] then | ||
layout.changeWindowCustom(app[activeLayout]['custom'], app[activeLayout], s.screen, windows) | ||
else | ||
if app[activeLayout][screenName] then | ||
hs.fnutils.each(windows, function (w) | ||
layout.changeWindow(app[activeLayout][screenName], app[activeLayout], s.screen, w) | ||
end) | ||
end | ||
end | ||
end | ||
end) | ||
end | ||
|
||
function layout.changeWindowCustom(value, layout, screen, windows) | ||
value(layout, screen, windows) | ||
end | ||
|
||
function layout.setWindow(win, cell, screen) | ||
local active = layout.getLayout() | ||
--local itermscreen = find.app_from_name('iTerm2'):allwindows()[1]:screen() | ||
--if layout.screens[screen:name()] == itermscreen:name() and cell.h == 6 then | ||
--cell.h = cell.h - 10 | ||
--end | ||
hs.grid.set(win, cell, screen) | ||
end | ||
|
||
function layout.changeWindow(value, _layout, screen, window) | ||
if window then | ||
layout.setWindow(window, value, screen) | ||
end | ||
end | ||
|
||
return layout |
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.