-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: integrating hhtwm and custom wm-related module
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
- Loading branch information
1 parent
721fa97
commit 016e568
Showing
11 changed files
with
1,069 additions
and
113 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,22 @@ | ||
local cache = {} | ||
local module = { cache = cache } | ||
|
||
-- modifiers in use: | ||
-- * cltr+alt: move focus between windows | ||
-- * ctrl+shift: do things to windows | ||
-- * ultra: custom/global bindings | ||
|
||
module.start = function() | ||
hs.fnutils.each(bindings.enabled, function(binding) | ||
cache[binding] = require('bindings.' .. binding) | ||
cache[binding].start() | ||
end) | ||
end | ||
|
||
module.stop = function() | ||
hs.fnutils.each(cache, function(binding) | ||
binding.stop() | ||
end) | ||
end | ||
|
||
return module |
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,129 @@ | ||
local module = {} | ||
local wm = wm.cache.wm | ||
local move = function(dir) | ||
local win = hs.window.frontmostWindow() | ||
if wm.isFloating(win) then | ||
local directions = { | ||
west = 'left', | ||
south = 'down', | ||
north = 'up', | ||
east = 'right' | ||
} | ||
hs.grid['pushWindow' .. capitalize(directions[dir])](win) | ||
else | ||
wm.swapInDirection(win, dir) | ||
end | ||
|
||
end | ||
local throw = function(dir) | ||
local win = hs.window.frontmostWindow() | ||
if wm.isFloating(win) then | ||
hs.grid['pushWindow' .. capitalize(dir) .. 'Screen'](win) | ||
else | ||
wm.throwToScreenUsingSpaces(win, dir) | ||
end | ||
|
||
end | ||
local resize = function(resize) | ||
local win = hs.window.frontmostWindow() | ||
if wm.isFloating(win) then | ||
hs.grid['resizeWindow' .. capitalize(resize)](win) | ||
|
||
else | ||
wm.resizeLayout(resize) | ||
end | ||
end | ||
module.start = function() | ||
local bind = function(key, fn) | ||
hs.hotkey.bind({ 'ctrl', 'shift' }, key, fn, nil, fn) | ||
end | ||
-- move window | ||
hs.fnutils.each({ | ||
{ key = 'h', dir = "west" }, | ||
{ key = 'j', dir = "south" }, | ||
{ key = 'k', dir = "north" }, | ||
{ key = 'l', dir = "east" }, | ||
}, function(obj) | ||
bind(obj.key, function() move(obj.dir) end) | ||
end) | ||
-- throw between screens | ||
hs.fnutils.each({ | ||
{ key = ']', dir = 'prev' }, | ||
{ key = '[', dir = 'next' }, | ||
}, function(obj) | ||
bind(obj.key, function() throw(obj.dir) end) | ||
end) | ||
-- resize (floating only) | ||
hs.fnutils.each({ | ||
{ key = ',', dir = 'thinner' }, | ||
{ key = '.', dir = 'wider' }, | ||
{ key = '-', dir = 'shorter' }, | ||
{ key = '=', dir = 'taller' } | ||
}, function(obj) | ||
bind(obj.key, function() resize(obj.dir) end) | ||
end) | ||
-- toggle [f]loat | ||
bind('f', function() | ||
local win = hs.window.frontmostWindow() | ||
if not win then return end | ||
wm.toggleFloat(win) | ||
if wm.isFloating(win) then | ||
hs.grid.center(win) | ||
end | ||
|
||
end) | ||
-- [r]eset | ||
bind('r', wm.reset) | ||
-- re[t]ile | ||
bind('t', wm.tile) | ||
-- [e]qualize | ||
bind('e', wm.equalizeLayout) | ||
-- [c]enter window | ||
bind('c', function() | ||
local win = hs.window.frontmostWindow() | ||
if not wm.isFloating(win) then | ||
wm.toggleFloat(win) | ||
end | ||
-- win:centerOnScreen() | ||
hs.grid.center(win) | ||
|
||
end) | ||
-- toggle [z]oom window | ||
bind('z', function() | ||
local win = hs.window.frontmostWindow() | ||
if not wm.isFloating(win) then | ||
wm.toggleFloat(win) | ||
hs.grid.maximizeWindow(win) | ||
else | ||
wm.toggleFloat(win) | ||
end | ||
|
||
end) | ||
-- throw window to space (and move) | ||
for n = 0, 9 do | ||
local idx = tostring(n) | ||
-- important: use this with onKeyReleased, not onKeyPressed | ||
hs.hotkey.bind({ 'ctrl', 'shift' }, idx, nil, function() | ||
local win = hs.window.focusedWindow() | ||
-- if there's no focused window, just move to that space | ||
if not win then | ||
hs.eventtap.keyStroke({ 'ctrl' }, idx) | ||
return | ||
end | ||
local isFloating = wm.isFloating(win) | ||
local success = wm.throwToSpace(win, n) | ||
-- if window switched space, then follow it (ctrl + 0..9) and focus | ||
if success then | ||
hs.eventtap.keyStroke({ 'ctrl' }, idx) | ||
-- retile and re-highlight window after we switch space | ||
hs.timer.doAfter(0.05, function() | ||
if not isFloating then wm.tile() end | ||
highlightWindow(win) | ||
end) | ||
end | ||
end) | ||
end | ||
end | ||
module.stop = function() | ||
end | ||
return module |
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,51 @@ | ||
local axuiWindowElement = require('hs.axuielement').windowElement | ||
local reloadHS = require('ext.system').reloadHS | ||
local module = {} | ||
module.init = function() | ||
-- some global functions for console | ||
inspect = hs.inspect | ||
reload = reloadHS | ||
dumpWindows = function() | ||
hs.fnutils.each(hs.window.allWindows(), function(win) | ||
print(hs.inspect({ | ||
id = win:id(), | ||
title = win:title(), | ||
app = win:application():name(), | ||
role = win:role(), | ||
subrole = win:subrole(), | ||
frame = win:frame(), | ||
buttonZoom = axuiWindowElement(win):attributeValue('AXZoomButton'), | ||
buttonFullScreen = axuiWindowElement(win):attributeValue('AXFullScreenButton'), | ||
isResizable = axuiWindowElement(win):isAttributeSettable('AXSize') | ||
})) | ||
end) | ||
end | ||
dumpScreens = function() | ||
hs.fnutils.each(hs.screen.allScreens(), function(s) | ||
print(s:id(), s:position(), s:frame(), s:name()) | ||
end) | ||
end | ||
timestamp = function(date) | ||
date = date or hs.timer.secondsSinceEpoch() | ||
return os.date("%F %T" .. ((tostring(date):match("(%.%d+)$")) or ""), math.floor(date)) | ||
end | ||
-- console styling | ||
local grayColor = { | ||
red = 24 * 4 / 255, | ||
green = 24 * 4 / 255, | ||
blue = 24 * 4 / 255, | ||
alpha = 1 | ||
} | ||
local blackColor = { | ||
red = 24 / 255, | ||
green = 24 / 255, | ||
blue = 24 / 255, | ||
alpha = 1 | ||
} | ||
hs.console.consoleCommandColor(blackColor) | ||
hs.console.consoleResultColor(grayColor) | ||
hs.console.consolePrintColor(grayColor) | ||
-- no toolbar | ||
hs.console.toolbar(nil) | ||
end | ||
return module |
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
Oops, something went wrong.