Skip to content

Instantly share code, notes, and snippets.

@malfario
Last active December 30, 2015 22:53
Show Gist options
  • Save malfario/101b98b7b76c6a232e22 to your computer and use it in GitHub Desktop.
Save malfario/101b98b7b76c6a232e22 to your computer and use it in GitHub Desktop.
border = nil
function writeActiveTitle(win, appTitle, event)
if win ~= hs.window.focusedWindow() then return end
local activeTitle = appTitle
local winTitle = win:title()
if winTitle ~= "" then
activeTitle = activeTitle.." - "..winTitle
end
file = io.open("/tmp/focus.kwm", "w")
io.output(file)
io.write(activeTitle)
io.close(file)
end
function drawBorder()
if border then
border:delete()
end
local win = hs.window.focusedWindow()
if win == nil then return end
writeActiveTitle(win, win:application():title(), "")
local f = win:frame()
local fx = f.x - 2
local fy = f.y - 2
local fw = f.w + 4
local fh = f.h + 4
border = hs.drawing.rectangle(hs.geometry.rect(fx, fy, fw, fh))
border:setStrokeWidth(3)
border:setStrokeColor({["red"]=0.75,["blue"]=0.14,["green"]=0.83,["alpha"]=0.80})
border:setRoundedRectRadii(5.0, 5.0)
border:setStroke(true):setFill(false)
border:setLevel("normal")
border:show()
end
drawBorder()
windows = hs.window.filter.new(nil)
windows:subscribe(hs.window.filter.windowFocused, function () drawBorder() end)
windows:subscribe(hs.window.filter.windowUnfocused, function () drawBorder() end)
windows:subscribe(hs.window.filter.windowMoved, function () drawBorder() end)
windows:subscribe(hs.window.filter.windowTitleChanged, writeActiveTitle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment