-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osx: have ctrl-click simulate right mouse button
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/skelterjohn/go.wde" | ||
) | ||
|
||
func init() { | ||
eventFilter = ctrlClicks | ||
} | ||
|
||
func isCtrl(key string) bool { | ||
return key == wde.KeyLeftControl || key == wde.KeyRightControl | ||
} | ||
|
||
|
||
// converts left-click events to right-clicks while control is depressed | ||
func ctrlClicks(in <-chan interface{}) <-chan interface{} { | ||
out := make(chan interface{}) | ||
go func() { | ||
ctrl := false | ||
conv := false | ||
for ei := range in { | ||
if e, ok := ei.(wde.KeyDownEvent); ok && isCtrl(e.Key) { | ||
ctrl = true | ||
} else if e, ok := ei.(wde.KeyUpEvent); ok && isCtrl(e.Key) { | ||
ctrl = false | ||
} | ||
switch e := ei.(type) { | ||
case wde.MouseDownEvent: | ||
if ctrl && e.Which == wde.LeftButton { | ||
conv = true | ||
e.Which = wde.RightButton | ||
out <- e | ||
} else { | ||
out <- ei | ||
} | ||
case wde.MouseUpEvent: | ||
if conv && e.Which == wde.LeftButton { | ||
e.Which = wde.RightButton | ||
conv = false | ||
out <- e | ||
} else { | ||
out <- ei | ||
} | ||
case wde.MouseDraggedEvent: | ||
if conv && e.Which == wde.LeftButton { | ||
e.Which = wde.RightButton | ||
out <- e | ||
} else { | ||
out <- ei | ||
} | ||
default: | ||
out <- ei | ||
} | ||
} | ||
close(out) | ||
}() | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters