diff --git a/application.go b/application.go index 151fec0..7b9dee0 100644 --- a/application.go +++ b/application.go @@ -45,7 +45,7 @@ func (application *Application) OnQuit ( // OnPress registers an event handler to be called when a key or mouse button // is pressed. func (application *Application) OnPress ( - onPress func (button Button), + onPress func (button Button, modifiers Modifiers), ) { application.callbackManager.onPress = onPress } diff --git a/backends/x/event.go b/backends/x/event.go index 0508407..b2b55a4 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -91,7 +91,9 @@ func (backend *Backend) handleButtonPress ( backend.compressScrollSum(&sum) backend.callbackManager.RunScroll(sum.x, sum.y) } else { - backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127)) + backend.callbackManager.RunPress ( + stone.Button(buttonEvent.Detail + 127), + stone.Modifiers { }) } } @@ -110,7 +112,15 @@ func (backend *Backend) handleKeyPress ( ) { keyEvent := *event.KeyPressEvent button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) - backend.callbackManager.RunPress(button) + backend.callbackManager.RunPress (button, stone.Modifiers { + // FIXME these may not be correct in all cases + Shift: (keyEvent.State & xproto.ModMaskShift) > 0, + Control: (keyEvent.State & xproto.ModMaskControl) > 0, + Alt: (keyEvent.State & xproto.ModMask1) > 0, + // Meta: (keyEvent.State & xproto.??) > 0, + Super: (keyEvent.State & xproto.ModMask4) > 0, + // Hyper: (keyEvent.State & xproto.??) > 0, + }) } func (backend *Backend) handleKeyRelease ( diff --git a/backends/x/unicode.go b/backends/x/unicode.go index 8d186b0..47c9d61 100644 --- a/backends/x/unicode.go +++ b/backends/x/unicode.go @@ -1,6 +1,6 @@ package x -import "fmt" +// import "fmt" import "unicode" import "github.com/jezek/xgb/xproto" import "github.com/jezek/xgbutil/keybind" @@ -138,7 +138,7 @@ func (backend *Backend) keycodeToButton ( var selectedKeysym xproto.Keysym var selectedRune rune - fmt.Printf("AAA\t%X\t%X\t%X\t%X\n", symbol1, symbol2, symbol3, symbol4) + // fmt.Printf("AAA\t%X\t%X\t%X\t%X\n", symbol1, symbol2, symbol3, symbol4) // big ol list in the middle switch { diff --git a/event.go b/event.go index edbaf2c..5e5cb79 100644 --- a/event.go +++ b/event.go @@ -2,7 +2,7 @@ package stone type CallbackManager struct { onQuit func () - onPress func (button Button) + onPress func (button Button, modifiers Modifiers) onRelease func (button Button) onResize func () onMouseMove func (x, y int) @@ -15,9 +15,9 @@ func (manager *CallbackManager) RunQuit () { manager.onQuit() } -func (manager *CallbackManager) RunPress (button Button) { +func (manager *CallbackManager) RunPress (button Button, modifiers Modifiers) { if manager.onPress == nil { return } - manager.onPress(button) + manager.onPress(button, modifiers) } func (manager *CallbackManager) RunRelease (button Button) { diff --git a/examples/draw/main.go b/examples/draw/main.go index 3bab734..b4846b6 100644 --- a/examples/draw/main.go +++ b/examples/draw/main.go @@ -34,7 +34,7 @@ func main () { if err != nil { panic(err) } } -func onPress (button stone.Button) { +func onPress (button stone.Button, modifiers stone.Modifiers) { if button == stone.MouseButtonLeft { mousePressed = true application.SetRune(0, 0, '+') diff --git a/examples/printbuttons/main.go b/examples/printbuttons/main.go index fc2a779..88439f0 100644 --- a/examples/printbuttons/main.go +++ b/examples/printbuttons/main.go @@ -32,7 +32,7 @@ func main () { if err != nil { panic(err) } } -func onPress (button stone.Button) { +func onPress (button stone.Button, modifiers stone.Modifiers) { println("press", button) } diff --git a/examples/type/main.go b/examples/type/main.go index a8285c7..bbb1966 100644 --- a/examples/type/main.go +++ b/examples/type/main.go @@ -55,7 +55,7 @@ func drawCaret () { application.SetColor(caretX, caretY, stone.ColorDim) } -func onPress (button stone.Button) { +func onPress (button stone.Button, modifiers stone.Modifiers) { width, height := application.Size() if button == stone.KeyEnter { diff --git a/input.go b/input.go index 78adbe9..026a5d1 100644 --- a/input.go +++ b/input.go @@ -33,10 +33,10 @@ const ( KeyRightShift Button = 21 KeyLeftControl Button = 22 KeyRightControl Button = 23 - KeyLeftMeta Button = 24 - KeyRightMeta Button = 25 - KeyLeftAlt Button = 26 - KeyRightAlt Button = 27 + KeyLeftAlt Button = 24 + KeyRightAlt Button = 25 + KeyLeftMeta Button = 26 + KeyRightMeta Button = 27 KeyLeftSuper Button = 28 KeyRightSuper Button = 29 KeyLeftHyper Button = 30 @@ -82,3 +82,16 @@ func (button Button) Printable () (printable bool) { printable = unicode.IsPrint(rune(button)) return } + +// Modifiers lists what modifier keys are being pressed. This is used in +// conjunction with a button code in a button press event. These should be used +// instead of attempting to track the state of the modifier keys, because there +// is no guarantee that one press event will be coupled with one release event. +type Modifiers struct { + Shift bool + Control bool + Alt bool + Meta bool + Super bool + Hyper bool +}