X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=hammerspoon%2Finit.lua;h=2228bdcc6978c0da2873cff5fe9bd6814005af1a;hb=be4017091a741b544d0a7761429fdd9f6635b128;hp=c163548739e9772dd59726dfb66f3bb0016b0ec3;hpb=2b15905600b261fc878b5852f71d6f04f926e347;p=dotfiles.git diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index c163548..2228bdc 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -10,42 +10,55 @@ hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function() end) hs.alert.show("Config loaded") - --- Sample - Drawing on the screen - http://www.hammerspoon.org/go/#simplereload -mouseCircle = nil -mouseCircleTimer = nil - -function mouseHighlight() - -- Delete an existing highlight if it exists - if mouseCircle then - mouseCircle:delete() - if mouseCircleTimer then - mouseCircleTimer:stop() +-- Reacting to application events +-- Move all Finder in front +function applicationWatcher(appName, eventType, appObject) + if (eventType == hs.application.watcher.activated) then + if (appName == "Finder") then + -- Bring all Finder windows forward when one gets activated + appObject:selectMenuItem({"Window", "Bring All to Front"}) end end - -- Get the current co-ordinates of the mouse pointer - mousepoint = hs.mouse.getAbsolutePosition() - -- Prepare a big red circle around the mouse pointer - mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-40, mousepoint.y-40, 80, 80)) - mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1}) - mouseCircle:setFill(false) - mouseCircle:setStrokeWidth(5) - mouseCircle:show() - - -- Set a timer to delete the circle after 3 seconds - mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end) end -hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight) - - --- window movement -hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function() - local win = hs.window.focusedWindow() - local f = win:frame() - - f.x = f.x - 10 - win:setFrame(f) -end) +appWatcher = hs.application.watcher.new(applicationWatcher) +appWatcher:start() + + + +---- Sample - Drawing on the screen - http://www.hammerspoon.org/go/#simplereload +--mouseCircle = nil +--mouseCircleTimer = nil +--function mouseHighlight() +-- -- Delete an existing highlight if it exists +-- if mouseCircle then +-- mouseCircle:delete() +-- if mouseCircleTimer then +-- mouseCircleTimer:stop() +-- end +-- end +-- -- Get the current co-ordinates of the mouse pointer +-- mousepoint = hs.mouse.getAbsolutePosition() +-- -- Prepare a big red circle around the mouse pointer +-- mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-40, mousepoint.y-40, 80, 80)) +-- mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1}) +-- mouseCircle:setFill(false) +-- mouseCircle:setStrokeWidth(5) +-- mouseCircle:show() +-- +-- -- Set a timer to delete the circle after 3 seconds +-- mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end) +--end +--hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight) +-- +-- +---- window movement +--hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function() +-- local win = hs.window.focusedWindow() +-- local f = win:frame() +-- +-- f.x = f.x - 10 +-- win:setFrame(f) +--end) -- Window Movement -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/ @@ -85,15 +98,17 @@ function move_window(direction) f.w = max.w f.h = max.h / 2 elseif direction == "max" then - f.x = max.x - f.y = max.y - f.w = max.w - f.h = max.h - elseif direction == "center" then - f.x = max.x + (max.w / 6) - f.y = max.y + (max.h / 6) - f.w = max.w * 2 / 3 - f.h = max.h * 2 / 3 + if f.w > (max.w * 3/4) and f.h > (max.h * 3/4) then + f.x = max.x + (max.w / 6) + f.y = max.y + (max.h / 6) + f.w = max.w * 2 / 3 + f.h = max.h * 2 / 3 + else + f.x = max.x + f.y = max.y + f.w = max.w + f.h = max.h + end else hs.alert.show("move_window(): Freaky parameter received " .. direction) end @@ -108,7 +123,6 @@ hs.hotkey.bind(hyper, "l", move_window("right")) hs.hotkey.bind(hyper, "k", move_window("up")) hs.hotkey.bind(hyper, "j", move_window("down")) hs.hotkey.bind(hyper, "m", move_window("max")) -hs.hotkey.bind(hyper, "c", move_window("center")) -- Search and dictionary -- Past and copy @@ -168,7 +182,7 @@ INSTALL:andUse("Seal", ["Hammerspoon docs webpage"] = { url = "http://hammerspoon.org/docs/", icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon), - hotkey = { hyper, "h" } + -- hotkey = { hyper, "h" } }, ["Leave corpnet"] = { fn = function()