diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1bd6806 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hhtwm"] + path = hhtwm-upstream + url = https://github.com/szymonkaliski/hhtwm diff --git a/config.example.fnl b/config.example.fnl index fa32dd9..15e3155 100644 --- a/config.example.fnl +++ b/config.example.fnl @@ -1,6 +1,7 @@ (require-macros :lib.macros) (require-macros :lib.advice.macros) (local windows (require :windows)) +(local tiling (require :tiling)) (local emacs (require :emacs)) (local slack (require :slack)) (local vim (require :vim)) @@ -164,6 +165,16 @@ :action "windows:resize-inc-right" :repeatable true}]) +(local window-swaps + [{:key :h + :action "tiling:swap-window-left"} + {:key :j + :action "tiling:swap-window-above"} + {:key :k + :action "tiling:swap-window-below"} + {:key :l + :action "tiling:swap-window-right"}]) + (local window-resize [{:mods [:shift] :key "hjkl" @@ -217,7 +228,10 @@ window-increments window-resize window-move-screens - [{:key :m + [{:key :s + :title "Swap" + :items window-swaps} + {:key :m :title "Maximize" :action "windows:maximize-window-frame"} {:key :c diff --git a/core.fnl b/core.fnl index f588700..1d4b263 100644 --- a/core.fnl +++ b/core.fnl @@ -216,6 +216,7 @@ Returns nil. This function causes side-effects. (local modules [:lib.hyper :vim :windows + :tiling :apps :lib.bind :lib.modal diff --git a/hhtwm b/hhtwm new file mode 120000 index 0000000..3655605 --- /dev/null +++ b/hhtwm @@ -0,0 +1 @@ +hhtwm-upstream/hhtwm \ No newline at end of file diff --git a/hhtwm-upstream b/hhtwm-upstream new file mode 160000 index 0000000..0322674 --- /dev/null +++ b/hhtwm-upstream @@ -0,0 +1 @@ +Subproject commit 0322674a7665c0c8b9d3396efc98551142808a5c diff --git a/hs/_asm/undocumented/spaces/init.lua b/hs/_asm/undocumented/spaces/init.lua new file mode 100644 index 0000000..ea1d14e --- /dev/null +++ b/hs/_asm/undocumented/spaces/init.lua @@ -0,0 +1,575 @@ +--- === hs._asm.undocumented.spaces === +--- +--- These functions utilize private API's within the OS X internals, and are known to have unpredictable behavior under Mavericks and Yosemite when "Displays have separate Spaces" is checked under the Mission Control system preferences. +--- + +local USERDATA_TAG = "hs._asm.undocumented.spaces" +-- some of the commands can really get you in a bit of a fix, so this file will be mostly wrappers and +-- predefined, common actions. +local internal = require(USERDATA_TAG..".internal") +local module = {} + +local basePath = package.searchpath(USERDATA_TAG, package.path) +if basePath then + basePath = basePath:match("^(.+)/init.lua$") + if require"hs.fs".attributes(basePath .. "/docs.json") then + require"hs.doc".registerJSONFile(basePath .. "/docs.json") + end +end + +-- local log = require("hs.logger").new(USERDATA_TAG, require"hs.settings".get(USERDATA_TAG .. ".logLevel") or "warning") + +local screen = require("hs.screen") +local window = require("hs.window") +local settings = require("hs.settings") +local inspect = require("hs.inspect") +local application = require("hs.application") + +-- private variables and methods ----------------------------------------- + +-- flag is checked to see if certain functions are called from module or from module.raw to prevent doing +-- dangerous/unexpected/unknown things unless explicitly enabled +local _BE_DANGEROUS_FLAG_ = false + +local _kMetaTable = {} +_kMetaTable._k = {} +_kMetaTable.__index = function(obj, key) + if _kMetaTable._k[obj] then + if _kMetaTable._k[obj][key] then + return _kMetaTable._k[obj][key] + else + for k,v in pairs(_kMetaTable._k[obj]) do + if v == key then return k end + end + end + end + return nil + end +_kMetaTable.__newindex = function(obj, key, value) + error("attempt to modify a table of constants",2) + return nil + end +_kMetaTable.__pairs = function(obj) return pairs(_kMetaTable._k[obj]) end +_kMetaTable.__tostring = function(obj) + local result = "" + if _kMetaTable._k[obj] then + local width = 0 + for k,v in pairs(_kMetaTable._k[obj]) do width = width < #k and #k or width end + for k,v in pairs(_kMetaTable._k[obj]) do + result = result..string.format("%-"..tostring(width).."s %s\n", k, tostring(v)) + end + else + result = "constants table missing" + end + return result + end +_kMetaTable.__metatable = _kMetaTable -- go ahead and look, but don't unset this + +local _makeConstantsTable = function(theTable) + local results = setmetatable({}, _kMetaTable) + _kMetaTable._k[results] = theTable + return results +end + +local reverseWithoutSystemSpaces = function(list) + local results = {} + for i,v in ipairs(list) do + if internal.spaceType(v) ~= internal.types.system then + table.insert(results, 1, v) + end + end + return results +end + +local isSpaceSafe = function(spaceID, func) + func = func or "undocumented.spaces" + if not _BE_DANGEROUS_FLAG_ then + local t = internal.spaceType(spaceID) + if t ~= internal.types.fullscreen and t ~= internal.types.tiled and t ~= internal.types.user then + _BE_DANGEROUS_FLAG_ = false + error(func..":must be user-created or fullscreen application space", 3) + end + end + _BE_DANGEROUS_FLAG_ = false + return spaceID +end + +local screenMT = hs.getObjectMetatable("hs.screen") +local windowMT = hs.getObjectMetatable("hs.window") + +-- Public interface ------------------------------------------------------ + +module.types = _makeConstantsTable(internal.types) +module.masks = _makeConstantsTable(internal.masks) + +-- replicate legacy functions + +--- hs._asm.undocumented.spaces.count() -> number +--- Function +--- LEGACY: The number of spaces you currently have. +--- +--- Notes: +--- * this function may go away in a future update +--- +--- * this functions is included for backwards compatibility. It is not recommended because it worked by indexing the spaces ignoring that fullscreen applications are included in the list twice, and only worked with one monitor. Use `hs._asm.undocumented.spaces.query` or `hs._asm.undocumented.spaces.spacesByScreenUUID`. +module.count = function() + return #reverseWithoutSystemSpaces(module.query(internal.masks.allSpaces)) +end + +--- hs._asm.undocumented.spaces.currentSpace() -> number +--- Function +--- LEGACY: The index of the space you're currently on, 1-indexed (as usual). +--- +--- Notes: +--- * this function may go away in a future update +--- +--- * this functions is included for backwards compatibility. It is not recommended because it worked by indexing the spaces, which can be rearranged by the operating system anyways. Use `hs._asm.undocumented.spaces.query` or `hs._asm.undocumented.spaces.spacesByScreenUUID`. +module.currentSpace = function() + local theSpaces = reverseWithoutSystemSpaces(module.query(internal.masks.allSpaces)) + local currentID = internal.query(internal.masks.currentSpaces)[1] + for i,v in ipairs(theSpaces) do + if v == currentID then return i end + end + return nil +end + +--- hs._asm.undocumented.spaces.moveToSpace(number) +--- Function +--- LEGACY: Switches to the space at the given index, 1-indexed (as usual). +--- +--- Notes: +--- * this function may go away in a future update +--- +--- * this functions is included for backwards compatibility. It is not recommended because it was never really reliable and worked by indexing the spaces, which can be rearranged by the operating system anyways. Use `hs._asm.undocumented.spaces.changeToSpace`. +module.moveToSpace = function(whichIndex) + local theID = internal.query(internal.masks.allSpaces)[whichIndex] + if theID then + internal._changeToSpace(theID, false) + return true + else + return false + end +end + +--- hs._asm.undocumented.spaces.isAnimating([screen]) -> bool +--- Function +--- Returns the state of space changing animation for the specified monitor, or for any monitor if no parameter is specified. +--- +--- Parameters: +--- * screen - an optional hs.screen object specifying the specific monitor to check the animation status for. +--- +--- Returns: +--- * a boolean value indicating whether or not a space changing animation is currently active. +--- +--- Notes: +--- * This function can be used in `hs.eventtap` based space changing functions to determine when to release the mouse and key events. +--- +--- * This function is also added to the `hs.screen` object metatable so that you can check a specific screen's animation status with `hs.screen:spacesAnimating()`. +module.isAnimating = function(...) + local args = table.pack(...) + if args.n == 0 then + local isAnimating = false + for i,v in ipairs(screen.allScreens()) do + isAnimating = isAnimating or internal.screenUUIDisAnimating(internal.UUIDforScreen(v)) + end + return isAnimating + elseif args.n == 1 then + return internal.screenUUIDisAnimating(internal.UUIDforScreen(args[1])) + else + error("isAnimating:invalid argument, none or hs.screen object expected", 2) + end +end + +module.spacesByScreenUUID = function(...) + local args = table.pack(...) + if args.n == 0 or args.n == 1 then + local masks = args[1] or internal.masks.allSpaces + local theSpaces = module.query(masks) + local holding = {} + for i,v in ipairs(theSpaces) do + local myScreen = internal.spaceScreenUUID(v) or "screenUndefined" + if not holding[myScreen] then holding[myScreen] = {} end + table.insert(holding[myScreen], v) + end + return holding + else + error("spacesByScreenUUID:invalid argument, none or integer expected", 2) + end +end + +-- need to make sure its a user accessible space +module.changeToSpace = function(...) + local args = table.pack(...) + if args.n == 1 or args.n == 2 then + local spaceID = isSpaceSafe(args[1], "changeToSpace") + if type(args[2]) == "boolean" then resetDock = args[2] else resetDock = true end + local fromID, uuid = 0, internal.spaceScreenUUID(spaceID) + for i, v in ipairs(module.query(internal.masks.currentSpaces)) do + if uuid == internal.spaceScreenUUID(v) then + fromID = v + break + end + end + if fromID == 0 then + error("changeToSpace:unable to identify screen for space id "..spaceID, 2) + end + + -- this is where you could do some sort of animation with the transform functions + -- may add that in the future + + internal.disableUpdates() + for i,v in ipairs(module.query(internal.masks.currentOSSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + internal.spaceLevel(v, internal.spaceLevel(v) + 1) + end + end + internal.spaceLevel(spaceID, internal.spaceLevel(spaceID) + 1) + -- doesn't seem to be necessary, _changeToSpace does it for us, though you would need + -- it if you did any animation for the switch +-- internal.showSpaces(spaceID) + internal._changeToSpace(spaceID) + internal.hideSpaces(fromID) + internal.spaceLevel(spaceID, internal.spaceLevel(spaceID) - 1) + for i,v in ipairs(module.query(internal.masks.currentOSSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + internal.spaceLevel(v, internal.spaceLevel(v) - 1) + end + end + internal.enableUpdates() + + if resetDock then hs.execute("killall Dock") end + else + error("changeToSpace:invalid argument, spaceID and optional boolean expected", 2) + end + return internal.query(internal.masks.currentSpaces) +end + +module.mainScreenUUID = function(...) + local UUID = internal.mainScreenUUID(...) + if #UUID ~= 36 then -- on one screen machines, it returns "Main" which doesn't work for spaceCreate + UUID = internal.spaceScreenUUID(internal.activeSpace()) + end + return UUID +end + +-- -need a way to determine/specify which screen +module.createSpace = function(...) + local args = table.pack(...) + if args.n <= 2 then + local uuid, resetDock + if type(args[1]) == "string" then uuid = args[1] else uuid = module.mainScreenUUID() end + if type(args[#args]) == "boolean" then resetDock = args[#args] else resetDock = true end + local newID = internal.createSpace(uuid) + if resetDock then hs.execute("killall Dock") end + return newID + else + error("createSpace:invalid argument, screenUUID and optional boolean expected", 2) + end +end + +-- -need to make sure no windows are only there +-- -need to make sure its a user window +-- ?check for how to do tiled/fullscreen? +module.removeSpace = function(...) + local args = table.pack(...) + if args.n == 1 or args.n == 2 then + local _Are_We_Being_Dangerous_ = _BE_DANGEROUS_FLAG_ + local spaceID = isSpaceSafe(args[1], "removeSpace") + local resetDock + if type(args[2]) == "boolean" then resetDock = args[2] else resetDock = true end + + if internal.spaceType(spaceID) ~= internal.types.user then + error("removeSpace:you can only remove user created spaces", 2) + end + for i,v in ipairs(module.query(internal.masks.currentSpaces)) do + if spaceID == v then + error("removeSpace:you can't remove one of the currently active spaces", 2) + end + end + local targetUUID = internal.spaceScreenUUID(spaceID) + local sameScreenSpaces = module.spacesByScreenUUID()[targetUUID] + local userSpacesCount = 0 + for i,v in ipairs(sameScreenSpaces) do + if internal.spaceType(v) == internal.types.user then + userSpacesCount = userSpacesCount + 1 + end + end + if userSpacesCount < 2 then + error("removeSpace:there must be at least one user space on each screen", 2) + end + + -- Probably not necessary, with above checks, but if I figure out how to safely + -- "remove" fullscreen/tiled spaces, I may remove them for experimenting + _BE_DANGEROUS_FLAG_ = _Are_We_Being_Dangerous_ + -- check for windows which need to be moved + local theWindows = {} + for i, v in ipairs(module.allWindowsForSpace(spaceID)) do if v:id() then table.insert(theWindows, v:id()) end end + + -- get id of screen to move them to + local baseID = 0 + for i,v in ipairs(module.query(internal.masks.currentSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + baseID = v + break + end + end + + for i,v in ipairs(theWindows) do + -- only add windows that exist in only one place + if #internal.windowsOnSpaces(v) == 1 then + internal.windowsAddTo(v, baseID) + end + end + + + internal.windowsRemoveFrom(theWindows, spaceID) + internal._removeSpace(spaceID) + if resetDock then hs.execute("killall Dock") end + else + error("removeSpace:invalid argument, spaceID and optional boolean expected", 2) + end +end + +module.allWindowsForSpace = function(...) + local args = table.pack(...) + if args.n == 1 then + local ok, spaceID = pcall(isSpaceSafe, args[1], "allWindowsForSpace") + if not ok then + if internal.spaceName(args[1]) == "dashboard" then spaceID = args[1] else error(spaceID, 2) end + end + local isCurrent, windowIDs = false, {} + for i,v in ipairs(module.query(internal.masks.currentSpaces)) do + if v == spaceID then + isCurrent = true + break + end + end + if isCurrent then + windowIDs = window.allWindows() + else + local targetUUID = internal.spaceScreenUUID(spaceID) + local baseID = 0 + for i,v in ipairs(module.query(internal.masks.currentSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + baseID = v + break + end + end + internal.disableUpdates() + for i,v in ipairs(module.query(internal.masks.currentOSSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + internal.spaceLevel(v, internal.spaceLevel(v) + 1) + end + end + internal.spaceLevel(baseID, internal.spaceLevel(baseID) + 1) + + internal._changeToSpace(spaceID) + windowIDs = window.allWindows() + internal.hideSpaces(spaceID) + internal._changeToSpace(baseID) + + internal.spaceLevel(baseID, internal.spaceLevel(baseID) - 1) + for i,v in ipairs(module.query(internal.masks.currentOSSpaces)) do + if internal.spaceScreenUUID(v) == targetUUID then + internal.spaceLevel(v, internal.spaceLevel(v) - 1) + end + end + internal.enableUpdates() + + end + local realWindowIDs = {} + for i,v in ipairs(windowIDs) do + if v:id() then + for j,k in ipairs(internal.windowsOnSpaces(v:id())) do + if k == spaceID then + table.insert(realWindowIDs, v) + end + end + end + end + windowIDs = realWindowIDs + return windowIDs + else + error("allWindowsForSpace:invalid argument, spaceID expected", 2) + end +end + +module.windowOnSpaces = function(...) + local args = table.pack(...) + if args.n == 1 then + windowIDs = internal.windowsOnSpaces(args[1]) + return windowIDs + else + error("windowOnSpaces:invalid argument, windowID expected", 2) + end +end + +module.moveWindowToSpace = function(...) + local args = table.pack(...) + if args.n == 2 then + local windowID = args[1] + local spaceID = isSpaceSafe(args[2], "moveWindowToSpace") + local currentSpaces = internal.windowsOnSpaces(windowID) + if #currentSpaces == 0 then + error("moveWindowToSpace:no spaceID found for window", 2) + elseif #currentSpaces > 1 then + error("moveWindowToSpace:window on multiple spaces", 2) + end + if currentSpaces[1] ~= spaceID then + internal.windowsAddTo(windowID, spaceID) + internal.windowsRemoveFrom(windowID, currentSpaces[1]) + end + return internal.windowsOnSpaces(windowID)[1] + else + error("moveWindowToSpace:invalid argument, windowID and spaceID expected", 2) + end +end + +module.layout = function() + local results = {} + for i,v in ipairs(internal.details()) do + local screenID = v["Display Identifier"] + if screenID == "Main" then + screenID = module.mainScreenUUID() + end + results[screenID] = {} + for j,k in ipairs(v.Spaces) do + table.insert(results[screenID], k.ManagedSpaceID) + end + end + return results +end + +module.query = function(...) + local args = table.pack(...) + if args.n <= 2 then + local mask, flatten = internal.masks.allSpaces, true + if type(args[1]) == "number" then mask = args[1] end + if type(args[#args]) == "boolean" then flatten = args[#args] end + local results = internal.query(mask) + if not flatten then + return results + else + local userWants, seen = {}, {} + for i, v in ipairs(results) do + if not seen[v] then + seen[v] = true + table.insert(userWants, v) + end + end + return userWants + end + else + error("query:invalid argument, mask and optional boolean expected", 2) + end +end + +-- map the basic functions to the main module spaceID + +module.screensHaveSeparateSpaces = internal.screensHaveSeparateSpaces +module.activeSpace = internal.activeSpace +module.spaceType = internal.spaceType +module.spaceName = internal.spaceName +module.spaceOwners = internal.spaceOwners +module.spaceScreenUUID = internal.spaceScreenUUID + +-- generate debugging information +module.debug = {} + +module.debug.layout = function(...) return inspect(internal.details(...)) end + +module.debug.report = function(...) + local mask = 7 -- user accessible spaces + local _ = table.pack(...)[1] + if type(_) == "boolean" and _ then + mask = 31 -- I think this gets user and "system" spaces like expose, etc. + elseif type(_) == "boolean" then + mask = 917519 -- I think this gets *everything*, but it may change as I dig + elseif type(_) == "number" then + mask = _ -- user specified mask + elseif table.pack(...).n ~= 0 then + error("debugReport:bad mask type provided, expected number", 2) + end + + local list, report = module.query(mask), "" + + report = "Screens have separate spaces: "..tostring(internal.screensHaveSeparateSpaces()).."\n".. + "Spaces for mask "..string.format("0x%08x", mask)..": "..(inspect(internal.query(mask)):gsub("%s+"," ")).. + "\n\n" + + for i,v in ipairs(list) do + report = report..module.debug.spaceInfo(v).."\n" + end + + -- see if mask included any of the users accessible spaces flag + if (mask & (1 << 2) ~= 0) then report = report.."\nLayout: "..inspect(internal.details()).."\n" end + return report +end + +module.debug.spaceInfo = function(v) + local results = + "Space: "..v.." ("..inspect(internal.spaceName(v))..")\n".. + " Type: "..(module.types[internal.spaceType(v)] and module.types[internal.spaceType(v)] or "-- unknown --") + .." ("..internal.spaceType(v)..")\n".. + " Level: ".. internal.spaceLevel(v).."\n".. + " CompatID: ".. internal.spaceCompatID(v).."\n".. + " Screen: ".. inspect(internal.spaceScreenUUID(v)).."\n".. + " Shape: "..(inspect(internal.spaceShape(v)):gsub("%s+"," ")).."\n".. + " MShape: "..(inspect(internal.spaceManagedShape(v)):gsub("%s+"," ")).."\n".. + " Transform: "..(inspect(internal.spaceTransform(v)):gsub("%s+"," ")).."\n".. + " Values: "..(inspect(internal.spaceValues(v)):gsub("%s+"," ")).."\n".. + " Owners: "..(inspect(internal.spaceOwners(v)):gsub("%s+"," ")).."\n" + if #internal.spaceOwners(v) > 0 then + local apps = {} + for i,v in ipairs(internal.spaceOwners(v)) do + table.insert(apps, (application.applicationForPID(v) and + application.applicationForPID(v):title() or "n/a")) + end + results = results.." : "..(inspect(apps):gsub("%s+"," ")).."\n" + end + return results +end + +-- extend built in modules + +screenMT.__index.spaces = function(obj) return module.spacesByScreenUUID()[internal.UUIDforScreen(obj)] end +screenMT.__index.spacesUUID = internal.UUIDforScreen +screenMT.__index.spacesAnimating = function(obj) return internal.screenUUIDisAnimating(internal.UUIDforScreen(obj)) end + +windowMT.__index.spaces = function(obj) return obj:id() and internal.windowsOnSpaces(obj:id()) or nil end +windowMT.__index.spacesMoveTo = function(obj, ...) + if obj:id() then + module.moveWindowToSpace(obj:id(), ...) + return obj + end + return nil +end + +-- add raw subtable if the user has enabled it + +if settings.get("_ASMundocumentedSpacesRaw") then + module.raw = internal + module.raw.changeToSpace = function(...) + _BE_DANGEROUS_FLAG_ = true + local result = module.changeToSpace(...) + _BE_DANGEROUS_FLAG_ = false -- should be already, but just in case + return result + end + module.raw.removeSpace = function(...) + _BE_DANGEROUS_FLAG_ = true + local result = module.changeToSpace(...) + _BE_DANGEROUS_FLAG_ = false -- should be already, but just in case + return result + end + module.raw.allWindowsForSpace = function(...) + _BE_DANGEROUS_FLAG_ = true + local result = module.allWindowsForSpace(...) + _BE_DANGEROUS_FLAG_ = false -- should be already, but just in case + return result + end +end + +-- Return Module Object -------------------------------------------------- + + +return module diff --git a/hs/_asm/undocumented/spaces/internal.so b/hs/_asm/undocumented/spaces/internal.so new file mode 100644 index 0000000..0158e89 Binary files /dev/null and b/hs/_asm/undocumented/spaces/internal.so differ diff --git a/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Info.plist b/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Info.plist new file mode 100644 index 0000000..3994716 --- /dev/null +++ b/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.internal.so + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Resources/DWARF/internal.so b/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Resources/DWARF/internal.so new file mode 100644 index 0000000..db6fd31 Binary files /dev/null and b/hs/_asm/undocumented/spaces/internal.so.dSYM/Contents/Resources/DWARF/internal.so differ diff --git a/tiling.fnl b/tiling.fnl new file mode 100644 index 0000000..8b07c0e --- /dev/null +++ b/tiling.fnl @@ -0,0 +1,126 @@ +(local hhtwm (require :hhtwm)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Swap Windows +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(fn swap-window + [arrow] + " + Swap window using hhtwm. + " + (let [dir {:h "west" :j "south" :k "north" :l "east"} + win (hs.window.focusedWindow)] + (hhtwm.swapInDirection win (. dir arrow)))) + +(fn swap-window-left + [] + (swap-window :h)) + +(fn swap-window-above + [] + (swap-window :j)) + +(fn swap-window-below + [] + (swap-window :k)) + +(fn swap-window-right + [] + (swap-window :l)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Resize layout +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(fn resize-layout-left + [] + (hhtwm.resizeLayout "thinner")) + +(fn resize-layout-right + [] + (hhtwm.resizeLayout "wider")) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Spaces +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; (fn throw-window +;; [index] +;; " +;; Throw window to space using hhtwm +;; " +;; (let [win (hs.window.focusedWindow)] +;; (hhtwm.throwToSpace win index))) + +;; (fn throw-window1 +;; [] +;; (throw-window 1)) + +;; (fn throw-window2 +;; [] +;; (throw-window 2)) + +;; (fn throw-window3 +;; [] +;; (throw-window 3)) + +;; (fn throw-window4 +;; [] +;; (throw-window 4)) + +;; (fn throw-window5 +;; [] +;; (throw-window 5)) + +;; (fn throw-window6 +;; [] +;; (throw-window 6)) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Filtering +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(tset hhtwm :filters + [{:app "Emacs" :title "edit" :tile false} + {:app "Emacs" :title "capture" :tile false}]) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Layout +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Initialization +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(fn init + [config] + " + Initializes the tiling module + Performs side effects: + - Set layout as the main window comes to the right half of current display + - Start tiling + " + (hhtwm.setLayout "main-right") + (hhtwm.start)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Export +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +{: hhtwm + : swap-window-above + : swap-window-below + : swap-window-left + : swap-window-right + : resize-layout-left + : resize-layout-right + : init + ;; : throw-window1 + ;; : throw-window2 + ;; : throw-window3 + ;; : throw-window4 + ;; : throw-window5 + ;; : throw-window6 + }