forked from mogenson/PaperWM.spoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
137 lines (117 loc) · 3.95 KB
/
init.lua
File metadata and controls
137 lines (117 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--- === PaperWM.spoon ===
---
--- Tile windows horizontally. Inspired by PaperWM Gnome extension.
---
--- # Usage
---
--- `PaperWM:start()` will begin automatically tiling new and existing windows.
--- `PaperWM:stop()` will release control over windows.
---
--- Set window gaps using `PaperWM.window_gap`:
--- - As a single number: same gap for all sides
--- - As a table with specific sides: `{top=8, bottom=8, left=8, right=8}`
---
--- For example:
--- ```
--- PaperWM.window_gap = 10 -- 10px gap on all sides
--- -- or
--- PaperWM.window_gap = {top=10, bottom=8, left=12, right=12}
--- ```
---
--- Overwrite `PaperWM.window_filter` to ignore specific applications. For example:
---
--- ```
--- PaperWM.window_filter = PaperWM.window_filter:setAppFilter("Finder", false)
--- PaperWM:start() -- restart for new window filter to take effect
--- ```
---
--- # Limitations
---
--- MacOS does not allow a window to be moved fully off-screen. Windows that would
--- be tiled off-screen are placed in a margin on the left and right edge of the
--- screen. They are still visible and clickable.
---
--- It's difficult to detect when a window is dragged from one space or screen to
--- another. Use the move_window_N commands to move windows between spaces and
--- screens.
---
--- Arrange screens vertically to prevent windows from bleeding into other screens.
---
---
--- Download: [https://github.com/mogenson/PaperWM.spoon](https://github.com/mogenson/PaperWM.spoon)
local Spaces <const> = hs.spaces
local PaperWM = {}
PaperWM.__index = PaperWM
-- Metadata
PaperWM.name = "PaperWM"
PaperWM.version = "1.0"
PaperWM.author = "Michael Mogenson"
PaperWM.homepage = "https://github.com/mogenson/PaperWM.spoon"
PaperWM.license = "MIT - https://opensource.org/licenses/MIT"
-- Types
---@alias PaperWM table PaperWM module object
---@alias Window userdata a ui.window
---@alias Frame table hs.geometry.rect
---@alias Index { row: number, col: number, space: number }
---@alias Space number a Mission Control space ID
---@alias Screen userdata hs.screen
---@alias Mapping { [string]: (table | string)[]}
-- logger
PaperWM.logger = hs.logger.new(PaperWM.name)
-- Load modules
PaperWM.config = dofile(hs.spoons.resourcePath("config.lua"))
PaperWM.state = dofile(hs.spoons.resourcePath("state.lua"))
PaperWM.windows = dofile(hs.spoons.resourcePath("windows.lua"))
PaperWM.space = dofile(hs.spoons.resourcePath("space.lua"))
PaperWM.events = dofile(hs.spoons.resourcePath("events.lua"))
PaperWM.actions = dofile(hs.spoons.resourcePath("actions.lua"))
PaperWM.floating = dofile(hs.spoons.resourcePath("floating.lua"))
PaperWM.tiling = dofile(hs.spoons.resourcePath("tiling.lua"))
-- Initialize modules
PaperWM.windows.init(PaperWM)
PaperWM.space.init(PaperWM)
PaperWM.events.init(PaperWM)
PaperWM.actions.init(PaperWM)
PaperWM.state.init(PaperWM)
PaperWM.floating.init(PaperWM)
PaperWM.tiling.init(PaperWM)
-- Apply config
for k, v in pairs(PaperWM.config) do
PaperWM[k] = v
end
---start automatic window tiling
---@return PaperWM
function PaperWM:start()
-- check for some settings
if not Spaces.screensHaveSeparateSpaces() then
self.logger.e(
"please check 'Displays have separate Spaces' in System Preferences -> Mission Control")
end
-- clear state
self.state.clear();
-- restore floating windows
self.floating.restoreFloating()
-- populate window list, index table, ui_watchers, and set initial layout
self.windows.refreshWindows()
-- start event listeners
self.events.start()
return self
end
---stop automatic window tiling
---@return PaperWM
function PaperWM:stop()
-- stop events
self.events.stop()
-- fit all windows within the bounds of the screen
for _, window in ipairs(self.window_filter:getWindows()) do
window:setFrameInScreenBounds()
end
return self
end
function PaperWM:tileSpace(space)
self.tiling.tileSpace(space)
end
function PaperWM:bindHotkeys(mapping)
self.actions.bindHotkeys(mapping)
end
return PaperWM