Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh

Yuichiroh/mouse_point.lua

Last active Jul 30, 2020
Embed
What would you like to do?
そこそこ便利そうなマウス強調表示できた
-- mouse highlighting
_c = require("hs.canvas")
function createCanvas(screen)
local cp = hs.mouse.getAbsolutePosition()
local f = screen:frame()
canvas = _c.new(f):show()
canvas[1] = {
action = "build",
type = "circle",
padding = 0,
center = { x = cp.x+2 - f.x, y = cp.y+2 - f.y },
radius = 31,
reversePath = true
}
canvas[2] = {
action = "fill",
center = { x = cp.x - f.x, y = cp.y - f.y },
-- fillGradient = "radial",
fillGradient = "linear",
fillGradientColors = { { alpha = 0.8, red = 233/255, green = 166/255, blue = 165/255 },
{ alpha = 0.0, red = 233/255, green = 166/255, blue = 165/255 } },
radius = 35,
type = "circle",
shadow = { blurRadius = 5.0,
color = { alpha = 0.5, red = 233/255, green = 166/255, blue = 165/255 },
offset = { h = -5.0, w = 5.0 } },
withShadow = false
}
return canvas
end
mouseIsHighlighted = false
function toggleMouseHighlight()
if mouseIsHighlighted then
mouseIsHighlighted = not mouseIsHighlighted
for i, c in ipairs(canvases) do
c:delete()
end
else
mouseIsHighlighted = not mouseIsHighlighted
screens = hs.screen.allScreens()
canvases = {}
z = 0
for i, s in ipairs(screens) do
print(i, s)
local c = createCanvas(s)
local sp = hs.mouse.getAbsolutePosition()
timer = hs.timer.doWhile(function()
return mouseIsHighlighted
end, function()
local cp = hs.mouse.getAbsolutePosition()
local ms = hs.mouse.getCurrentScreen()
local f = ms:frame()
if s == ms then
c:show()
local sz = c:size()
c:transformation(_c.matrix.translate(cp.x - sp.x, cp.y - sp.y)
:translate(sp.x - f.x, sp.y - f.y)
:rotate(z)
:translate(-sp.x + f.x, -sp.y + f.y))
z = (z + 6) % 360
else
c:hide()
end
end, .05)
table.insert(canvases, c)
end
end
end
spacesWatcher = hs.spaces.watcher.new(function()
if mouseIsHighlighted then
toggleMouseHighlight()
toggleMouseHighlight()
end
end
):start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.