~eliasnaur/gio#177: 
Support right-click

Currently, the gesture.Click is limited for left-click:

if e.Source == pointer.Mouse && e.Buttons != pointer.ButtonLeft { break }

So what is the alternative to handle right-click? If doesn't exists, what would be the best way of doing that? Adding an field of Button into the existent ClickEvent?

Status
REPORTED
Submitter
~inkeliz
Assigned to
No-one
Submitted
4 months ago
Updated
a month ago
Labels
No labels applied.

~inkeliz 4 months ago

Using the pointer.InputOp is the alternative for now. But I would suggest to have another simpler option to do that.

~eliasnaur 4 months ago

On Thu Nov 19, 2020 at 2:59 AM CET, ~inkeliz wrote:

Using the pointer.InputOp is the alternative for now. But I would suggest to have another simpler option to do that.

I like that users of gesture.Click don't have to worry about which button was reported. How about adding a gesture.RightClick for your purpose?

Elias

masala@riseup.net a month ago · edit

Hi again, I wanted to comment on this issue but sadly could not register an account.

Here is what I did to extend gesture.Click to support other buttons: https://github.com/katzenpost/catchat/blob/wip_gioui_interface/gesture.go

I am not sure this is totally correct - but seems to work :-).

diff --git a/gesture/gesture.go b/gesture/gesture.go index 763183c..38a38d7 100644 --- a/gesture/gesture.go +++ b/gesture/gesture.go @@ -36,7 +36,7 @@ type Click struct { // are performed within a fixed duration. clicks int // pressed tracks whether the pointer is pressed.

  •   pressed bool
    
  •   pressed pointer.Buttons
      // entered tracks whether the pointer is inside the gesture.
      entered bool
      // pid is the pointer.ID.
    
    @@ -53,6 +53,7 @@ type ClickEvent struct { Position f32.Point Source pointer.Source Modifiers key.Modifiers
  •   Buttons   pointer.Buttons
      // NumClicks records successive clicks occurring
      // within a short duration of each other.
      NumClicks int
    
    @@ -132,8 +133,8 @@ func (c *Click) Hovered() bool { }

// Pressed returns whether a pointer is pressing. -func (c *Click) Pressed() bool {

  •   return c.pressed
    
    +func (c *Click) Pressed(button pointer.Buttons) bool {
  •   return c.pressed.Contain(button)
    
    }

// Events returns the next click event, if any. @@ -146,10 +147,11 @@ func (c *Click) Events(q event.Queue) []ClickEvent { } switch e.Type { case pointer.Release:

  •                   if !c.pressed || c.pid != e.PointerID {
    
  •                   if c.pid != e.PointerID {
                              break
                      }
    
  •                   c.pressed = false
    
  •                   b := c.pressed ^ e.Buttons
    
  •                   c.pressed = e.Buttons
                      if c.entered {
                              if e.Time-c.clickedAt <
    
    doubleClickDuration { c.clicks++ @@ -157,22 +159,20 @@ func (c *Click) Events(q event.Queue) []ClickEvent { c.clicks = 1 } c.clickedAt = e.Time
  •                           events = append(events, ClickEvent{Type:
    
    TypeClick, Position: e.Position, Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
  •                           events = append(events, ClickEvent{Type:
    
    TypeClick, Position: e.Position, Source: e.Source, Buttons: b, Modifiers: e.Modifiers, NumClicks: c.clicks}) } else {
  •                           events = append(events, ClickEvent{Type:
    
    TypeCancel})
  •                           events = append(events, ClickEvent{Type:
    
    TypeCancel, Buttons: b}) } case pointer.Cancel:
  •                   wasPressed := c.pressed
    
  •                   c.pressed = false
    
  •                   b := e.Buttons ^ c.pressed
    
  •                   wasPressed := c.pressed.Contain(b)
    
  •                   c.pressed = e.Buttons
                      c.entered = false
                      if wasPressed {
    
  •                           events = append(events, ClickEvent{Type:
    
    TypeCancel})
  •                           events = append(events, ClickEvent{Type:
    
    TypeCancel, Buttons: b}) } case pointer.Press:
  •                   if c.pressed {
    
  •                           break
    
  •                   }
    
  •                   if e.Source == pointer.Mouse && e.Buttons !=
    
    pointer.ButtonLeft {
  •                   if c.pressed == e.Buttons {
                              break
                      }
                      if !c.entered {
    
    @@ -181,17 +181,17 @@ func (c *Click) Events(q event.Queue) []ClickEvent { if c.pid != e.PointerID { break }
  •                   c.pressed = true
    
  •                   events = append(events, ClickEvent{Type:
    
    TypePress, Position: e.Position, Source: e.Source, Modifiers: e.Modifiers})
  •                   c.pressed = e.Buttons
    
  •                   events = append(events, ClickEvent{Type:
    
    TypePress, Position: e.Position, Source: e.Source, Buttons: e.Buttons, Modifiers: e.Modifiers}) case pointer.Leave:
  •                   if !c.pressed {
    
  •                   if !c.pressed.Contain(c.pressed ^ e.Buttons) {
                              c.pid = e.PointerID
                      }
                      if c.pid == e.PointerID {
                              c.entered = false
                      }
              case pointer.Enter:
    
  •                   if !c.pressed {
    
  •                   if !c.pressed.Contain(c.pressed ^ e.Buttons) {
                              c.pid = e.PointerID
                      }
                      if c.pid == e.PointerID {
    
    EOF

On 2021-01-29 21:01, ~eliasnaur wrote:

Your work sounds very interesting, and seems even more ambitious; I

merely wanted a federated Signal and e-mail seemed like a good option.

Unfortunately, Scatter served another purpose, a show-case for Gio,

and I find that most of my time and motivation lies in completing

that work.

I've updated the README to note the discontinued state of the Scatter project and linked to Delta Chat and Arbor Chat for maintained versions of signal-over-email and chat-in-gio, respectively.

I'll archive this issue tracker as well.

Elias

~eliasnaur a month ago

Please send any patches to the gio-patches mailing list as described by https://gioui.org/doc/contribute. You can also send it through the GitHub mirror, also described on the contribution guide.

Register here or Log in to comment, or comment via email.