Skip to content

Commit 9efc9eb

Browse files
authored
feat: new action to move mouse to a position (#46)
1 parent 7ebfaef commit 9efc9eb

6 files changed

Lines changed: 37 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ This is an intentional design choice to keep the project lean, maintainable, and
6666
- Find a way to auto deduplicate hints that are targeting the same point
6767
- Scroll areas are hardcoded from 1-9, do we ever need more than that and make it dynamic upon query? We can still use <Tab> to cycle next tho
6868
- Homerow supports `continuous clicks`, is that something important?
69-
- Maybe a new action (move_mouse), that just move the mouse to the point after clicking the hint, maybe useful for trying to hover something?
7069
- Maybe forces to certain input source? I normally just use English, but maybe it's useful for others
7170
- Electron apps does not show hints on the first activation. Maybe there's some manual work need to be done after setting up electron support?
7271
- Cant actually make scroll works in Electron apps, what is the best approach? There are tons of random `AXGroup` where some is scrollable and some is not...
@@ -258,6 +257,7 @@ govim launch
258257
- **Right click** (context menu)
259258
- **Double click**
260259
- **Middle click**
260+
- **Go to a position** (move mouse)
261261
4. Press `Esc` to cancel
262262

263263
### Scroll Mode

cmd/govim/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ func (a *App) showActionMenu(hint *hints.Hint) {
616616
{"r", "ight"},
617617
{"d", "ouble"},
618618
{"m", "iddle"},
619+
{"g", "oto pos"},
619620
}
620621

621622
// Create hints for each action, positioned horizontally with consistent gaps
@@ -724,6 +725,9 @@ func (a *App) handleActionKey(key string) {
724725
case "m": // Middle click
725726
a.logger.Info("Performing middle click", zap.String("label", hint.Label))
726727
err = hint.Element.Element.MiddleClick()
728+
case "g": // Move mouse to a position
729+
a.logger.Info("Performing go to position", zap.String("label", hint.Label))
730+
err = hint.Element.Element.GoToPosition()
727731
default:
728732
a.logger.Debug("Unknown action key, ignoring", zap.String("key", key))
729733
return

configs/default-config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ action_border_color = "#000000"
164164
action_opacity = 0.95
165165

166166
# Action keys for hint mode with actions (hardcoded):
167-
# l = left click, r = right click, d = double click, m = middle click
167+
# l = left click, r = right click, d = double click, m = middle click, g = go to pos
168168

169169
[scroll]
170170
# Base scroll amount for j/k keys in pixels

internal/accessibility/element.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ func (e *Element) MiddleClick() error {
320320
return nil
321321
}
322322

323+
// GoToPosition performs a move mouse action to the element
324+
func (e *Element) GoToPosition() error {
325+
if e.ref == nil {
326+
return fmt.Errorf("element is nil")
327+
}
328+
329+
result := C.performMoveMouseToPosition(e.ref)
330+
if result == 1 {
331+
return nil
332+
}
333+
334+
return fmt.Errorf("left-click action failed")
335+
}
336+
323337
// SetFocus sets focus to the element
324338
func (e *Element) SetFocus() error {
325339
if e.ref == nil {

internal/bridge/accessibility.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ int performRightClick(void* element);
4444
int performDoubleClick(void* element);
4545
int performMiddleClick(void* element);
4646

47+
int performMoveMouseToPosition(void* element);
48+
4749
int hasClickAction(void* element);
4850
int setFocus(void* element);
4951

internal/bridge/accessibility.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,21 @@ int performDoubleClick(void* element) {
760760
return 1;
761761
}
762762

763+
// Perform middle click
764+
int performMoveMouseToPosition(void* element) {
765+
if (!element) return 0;
766+
767+
CGPoint clickPoint;
768+
769+
if (!getElementCenter(element, &clickPoint)) {
770+
return 0;
771+
}
772+
773+
moveMouse(clickPoint);
774+
775+
return 1;
776+
}
777+
763778
// Set focus
764779
int setFocus(void* element) {
765780
if (!element) return 0;

0 commit comments

Comments
 (0)