tview icon indicating copy to clipboard operation
tview copied to clipboard

Mouse on linux terminal without X11

Open igrag opened this issue 10 months ago • 9 comments

Hello. we are trying to develop a simple console gui on a system that doesn't have X11. Everhtning works excpet the mouse events. Logical because the terminal does not support mouse. But the mouse is there and we can see it in /dev/input and also it works with evtest.

Is it possible to inject MouseEvents in tview like this? mouseEvent := tcell.NewEventMouse(x+offset, y, tcell.ButtonPrimary, tcell.ModNone)

If yes how could we send it globally to the app to the mainloop for dispatching? Of course we will first start a goroutine watching the /dev/input/mice device.

Thank you. Best Regards, Giannis

igrag avatar Feb 21 '25 09:02 igrag

First of all thank you for your reply. Yes I have seen all the examples that are related to mouse handle, but my problem is more primitive. The machine that this gui will run has no graphics stack like x11 or wayland or whatever. So the tty console hasn't native mouse support.

What I have done and it seems that tview started to respond to mouse is this:

  1. I used this "github.com/holoplot/go-evdev" to run a goroutine that monitors /dev/input/event0.
  2. When a mouse event occurs it creates a mouse event like this:

mouseEvent := tcell.NewEventMouse(x, y, tcell.ButtonPrimary, tcell.ModNone)

  1. Then I send the event to tview like this app.QueueEvent(mouseEvent)

and tview responded, for example a button was pressed.

Maybe it is usefull to add this kind of funtionallity in the future for cases like this.

Best Regards, Giannis

igrag avatar Feb 21 '25 18:02 igrag

Yes, I tried but no response from tview.

igrag avatar Feb 21 '25 20:02 igrag

Yes, I have response from the regular prompt with gpm. I can see the cursor moving at various locations. What I also did is to set the SetMouseCapture callback to have some feedback from mouse, but the callback never fired from gpm. This callback works fine in a typical ubuntu desktop console.

igrag avatar Feb 22 '25 09:02 igrag

@igrag You could create your own tcell.Screen class which includes your functionality. Specifically, you will need to override the PollEvent() method.

Then you call Application.SetScreen() in tview to set the application to your own implementation.

rivo avatar Mar 26 '25 17:03 rivo

Thnak you @rivo for your suggestion. I will try to do it.

igrag avatar Mar 27 '25 18:03 igrag

Will close this for now. Feel to open a new issue if needed.

rivo avatar Aug 27 '25 19:08 rivo