Skip to content

Commit

Permalink
osx: have ctrl-click simulate right mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
sqweek committed Apr 16, 2016
1 parent 85bb28d commit 805bb27
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
59 changes: 59 additions & 0 deletions sqribe_darwin.go
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
}
6 changes: 6 additions & 0 deletions sqribe_wde.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ type DragState struct {
button wde.Button
}

// overridden on OSX; see sqribe_darwin.go
var eventFilter func(<-chan interface{}) <-chan interface{} = nil

func event(win wde.Window, redraw chan Widget, done chan bool, wg *sync.WaitGroup) {
openDlg := dialog.File().Title("sqribe - Open").Filter("Audio Files", "mp3", "ogg", "m4a", "wma", "mov", "mp4", "flv", "wmv").Filter("Sqribe Save", "sqs")
exportDlg := dialog.File().Title("sqribe - Export to MusicXML").Filter("MXML Files", "xml", "mxl")
events := win.EventChan()
if eventFilter != nil {
events = eventFilter(events)
}
defer func() {
done <- true
wg.Done()
Expand Down

0 comments on commit 805bb27

Please sign in to comment.