aboutsummaryrefslogtreecommitdiffstats
path: root/gdrive_mouseover_item.lua
diff options
context:
space:
mode:
authorTeddy Wing2019-06-22 20:41:01 +0200
committerTeddy Wing2019-06-22 20:41:01 +0200
commit3f950676d49995d8300e9c0a472fdb9b52348a2b (patch)
treeef243c89dd9f6c63a582566a0eb3e3af2bd81651 /gdrive_mouseover_item.lua
parent7c0673f82057a405dba6f17416d10e3bdc5d4e17 (diff)
downloaddothammerspoon-3f950676d49995d8300e9c0a472fdb9b52348a2b.tar.bz2
Add gdrive_mouseover_item mode
A mode that selects a file row in Google Drive by its ID using keyboard shortcuts 1–0 and q–p. Makes it possible to select a file without using the mouse.
Diffstat (limited to 'gdrive_mouseover_item.lua')
-rw-r--r--gdrive_mouseover_item.lua79
1 files changed, 79 insertions, 0 deletions
diff --git a/gdrive_mouseover_item.lua b/gdrive_mouseover_item.lua
new file mode 100644
index 0000000..80473ed
--- /dev/null
+++ b/gdrive_mouseover_item.lua
@@ -0,0 +1,79 @@
+-- Copyright (c) 2019 Teddy Wing
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
+gdrive_mouseover_item_mode = hs.hotkey.modal.new(
+ {'ctrl', 'option'},
+ 'o',
+ 'GDrive Mouseover Item'
+)
+gdrive_mouseover_item_mode:bind(
+ {'ctrl', 'option'},
+ 'o',
+ 'GDrive Mouseover Item Off',
+ function() gdrive_mouseover_item_mode:exit() end
+)
+
+function gdrive_mouseover_item_select(id)
+ local x_delta = 250
+ local y_delta = 250
+
+ y_delta = y_delta + (id * 48)
+
+ local zoom_position = hs.window.frontmostWindow():zoomButtonRect()
+ zoom_position.x = zoom_position.x + x_delta
+ zoom_position.y = zoom_position.y + y_delta
+
+ hs.mouse.setRelativePosition(zoom_position)
+ hs.eventtap.leftClick(zoom_position)
+end
+
+function gdrive_mouseover_item_run_and_exit(f)
+ return function()
+ f()
+
+ gdrive_mouseover_item_mode:exit()
+ end
+end
+
+for i = 0, 8 do
+ local key = tostring(i + 1)
+
+ gdrive_mouseover_item_mode:bind(
+ {},
+ key,
+ gdrive_mouseover_item_run_and_exit(function()
+ gdrive_mouseover_item_select(i)
+ end)
+ )
+end
+
+gdrive_mouseover_item_mode:bind(
+ {},
+ '0',
+ gdrive_mouseover_item_run_and_exit(function()
+ gdrive_mouseover_item_select(9)
+ end)
+)
+
+for i, key in pairs({'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'}) do
+ gdrive_mouseover_item_mode:bind(
+ {},
+ key,
+ gdrive_mouseover_item_run_and_exit(function()
+ gdrive_mouseover_item_select(i + 9)
+ end)
+ )
+end