feat(hammerspoon): show app name on focus and command key
Extract window highlighting into a dedicated module and centralize shared configuration. Add a configurable app name toast triggered by focus changes and Command key presses.
This commit is contained in:
1 parent
592e4a838c
commit
6d5b84db51
4 files changed
+425
-301
No files matched your search
@@ -0,0 +1,58 @@
|
||||
local AppNameToast = {}
|
||||
AppNameToast.__index = AppNameToast
|
||||
|
||||
function AppNameToast.new(config)
|
||||
return setmetatable({
|
||||
config = config,
|
||||
alertId = nil,
|
||||
commandKeyDown = false,
|
||||
commandKeyWatcher = nil,
|
||||
shouldShow = nil,
|
||||
}, AppNameToast)
|
||||
end
|
||||
|
||||
function AppNameToast:setShouldShow(predicate)
|
||||
self.shouldShow = predicate
|
||||
end
|
||||
|
||||
function AppNameToast:show()
|
||||
if not self.config.enabled then return end
|
||||
if self.shouldShow and not self.shouldShow() then return end
|
||||
|
||||
local win = hs.window.focusedWindow()
|
||||
local app = win and win:application() or nil
|
||||
if not app then return end
|
||||
|
||||
if self.alertId then
|
||||
hs.alert.closeSpecific(self.alertId, 0)
|
||||
end
|
||||
|
||||
self.alertId = hs.alert.show(
|
||||
app:name(),
|
||||
self.config.style,
|
||||
win:screen(),
|
||||
self.config.duration
|
||||
)
|
||||
end
|
||||
|
||||
function AppNameToast:start()
|
||||
if not self.config.showOnCommand then return self end
|
||||
|
||||
self.commandKeyWatcher = hs.eventtap.new({
|
||||
hs.eventtap.event.types.flagsChanged,
|
||||
}, function(event)
|
||||
local isCommandDown = event:getFlags().cmd == true
|
||||
|
||||
if isCommandDown and not self.commandKeyDown then
|
||||
self:show()
|
||||
end
|
||||
|
||||
self.commandKeyDown = isCommandDown
|
||||
return false
|
||||
end)
|
||||
self.commandKeyWatcher:start()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return AppNameToast
|
||||
Reference in new issue
Block a user