-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
193 lines (182 loc) · 5.75 KB
/
init.lua
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
local spaces = require("hs.spaces") -- https://github.com/asmagill/hs._asm.spaces
local windows = dofile("bind_windows.lua")
-- dofile("app_chooser.lua")
local function app_bind(windowTable)
hs.hotkey.bind(windowTable["modifier"], windowTable["key"], function() -- hotkey config
local BUNDLE_ID = windowTable["bundle_ID"] -- more accurate to avoid mismatching on browser titles
function getMainWindow(app)
-- get main window from app
local win = nil
while win == nil do
win = app:mainWindow()
end
return win
end
function moveWindow(title, space, mainScreen)
-- move to main space
local win = getMainWindow(title)
if win:isFullScreen() then
hs.eventtap.keyStroke("fn", "f", 0, title)
end
winFrame = win:frame()
scrFrame = mainScreen:fullFrame()
if windowTable["manage_size"] then
print("TRUTH")
winFrame.w = windowTable["frame_properties"]["width"]
winFrame.h = windowTable["frame_properties"]["height"]
winFrame.x = windowTable["frame_properties"]["xPos"]
winFrame.y = windowTable["frame_properties"]["yPos"]
end
win:setFrame(winFrame, 0)
spaces.moveWindowToSpace(win, space)
if win:isFullScreen() then
hs.eventtap.keyStroke("fn", "f", 0, title)
end
win:focus()
end
local title = hs.application.get(BUNDLE_ID)
if title ~= nil and title:isFrontmost() then
title:hide()
else
local space = spaces.activeSpaceOnScreen()
local mainScreen = hs.screen.mainScreen()
if title == nil and hs.application.launchOrFocusByBundleID(BUNDLE_ID) then
local appWatcher = nil
appWatcher = hs.application.watcher.new(function(name, event, app)
if event == hs.application.watcher.launched and app:bundleID() == BUNDLE_ID then
getMainWindow(app):move(hs.geometry({ x = 0, y = 0, w = 1, h = 0.4 }))
app:hide()
moveWindow(app, space, mainScreen)
appWatcher:stop()
end
end)
appWatcher:start()
end
if title ~= nil then
moveWindow(title, space, mainScreen)
end
end
end)
end
for k, v in pairs(windows) do
app_bind(v)
end
-- Switch kitty
--hs.hotkey.bind({'option'}, 'return', function () -- hotkey config
-- local BUNDLE_ID = 'net.kovidgoyal.kitty' -- more accurate to avoid mismatching on browser titles
--
-- function getMainWindow(app)
-- -- get main window from app
-- local win = nil
-- while win == nil do
-- win = app:mainWindow()
-- end
-- return win
-- end
--
-- function moveWindow(kitty, space, mainScreen)
-- -- move to main space
-- local win = getMainWindow(kitty)
-- if win:isFullScreen() then
-- hs.eventtap.keyStroke('fn', 'f', 0, kitty)
-- end
-- winFrame = win:frame()
-- scrFrame = mainScreen:fullFrame()
-- winFrame.w = scrFrame.w
-- winFrame.y = scrFrame.y
-- winFrame.x = scrFrame.x
-- win:setFrame(winFrame, 0)
-- spaces.moveWindowToSpace(win, space)
-- if win:isFullScreen() then
-- hs.eventtap.keyStroke('fn', 'f', 0, kitty)
-- end
-- win:focus()
-- end
--
-- local kitty = hs.application.get(BUNDLE_ID)
-- if kitty ~= nil and kitty:isFrontmost() then
-- kitty:hide()
-- else
-- local space = spaces.activeSpaceOnScreen()
-- local mainScreen = hs.screen.mainScreen()
-- if kitty == nil and hs.application.launchOrFocusByBundleID(BUNDLE_ID) then
-- local appWatcher = nil
-- appWatcher = hs.application.watcher.new(function(name, event, app)
-- if event == hs.application.watcher.launched and app:bundleID() == BUNDLE_ID then
-- getMainWindow(app):move(hs.geometry({x=0,y=0,w=1,h=0.4}))
-- app:hide()
-- moveWindow(app, space, mainScreen)
-- appWatcher:stop()
-- end
-- end)
-- appWatcher:start()
-- end
-- if kitty ~= nil then
-- moveWindow(kitty, space, mainScreen)
-- end
-- end
--end)
--hs.hotkey.bind({'option'}, 'm', function () -- hotkey config
-- local BUNDLE_ID = 'com.apple.MobileSMS' -- more accurate to avoid mismatching on browser titles
--
-- function getMainWindow(app)
-- -- get main window from app
-- local win = nil
-- while win == nil do
-- win = app:mainWindow()
-- end
-- return win
-- end
--
-- function moveWindow(Messages, space, mainScreen)
-- -- move to main space
-- local win = getMainWindow(Messages)
-- if win:isFullScreen() then
-- hs.eventtap.keyStroke('fn', 'f', 0, Messages)
-- end
-- winFrame = win:frame()
-- scrFrame = mainScreen:fullFrame()
-- win:setFrame(winFrame, 0)
-- spaces.moveWindowToSpace(win, space)
-- if win:isFullScreen() then
-- hs.eventtap.keyStroke('fn', 'f', 0, Messages)
-- end
-- win:focus()
-- end
--
-- local Messages = hs.application.get(BUNDLE_ID)
-- if Messages ~= nil and Messages:isFrontmost() then
-- Messages:hide()
-- else
-- local space = spaces.activeSpaceOnScreen()
-- local mainScreen = hs.screen.mainScreen()
-- if Messages == nil and hs.application.launchOrFocusByBundleID(BUNDLE_ID) then
-- local appWatcher = nil
-- appWatcher = hs.application.watcher.new(function(name, event, app)
-- if event == hs.application.watcher.launched and app:bundleID() == BUNDLE_ID then
-- getMainWindow(app):move(hs.geometry({x=0,y=0,w=1,h=0.4}))
-- app:hide()
-- moveWindow(app, space, mainScreen)
-- appWatcher:stop()
-- end
-- end)
-- appWatcher:start()
-- end
-- if Messages ~= nil then
-- moveWindow(Messages, space, mainScreen)
-- end
-- end
--end)
local function reloadConfig(files)
local doReload = false
for _, file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
-- hs.alert.show("Config Loaded", { atScreenEdge = 1 })