Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse on linux terminal without X11 #1074

Open
igrag opened this issue Feb 21, 2025 · 8 comments
Open

Mouse on linux terminal without X11 #1074

igrag opened this issue Feb 21, 2025 · 8 comments

Comments

@igrag
Copy link

igrag commented Feb 21, 2025

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

@digitallyserviced
Copy link
Contributor

digitallyserviced commented Feb 21, 2025

@igrag
You are enabling the mouse in your app correct?

app.EnableMouse(true)

Somewhere before your app.Run.

There are also methods for enabling paste and other possible features you may be looking for.

While you could do what you provided as an example and manually create events for the mouse and other such, there are actually methods with gdamore/tcell which is the underlying terminal terminfo backend which you can use (albeit with some added complexity for initializing along with tview) that would make handling all events including mouse, keyboard, paste, resize and others much easier than the possibile implementation you gave as an example. Not that they are even necessary if properly using thiew and letting it handle them.

Look through the demo, wiki, and API reference. You can see examples of all the things that are available and how to do them.

@igrag
Copy link
Author

igrag commented Feb 21, 2025

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

@digitallyserviced
Copy link
Contributor

Understood, can you not utilize,gpm or similar to enable mouse events on a tty?

https://wiki.archlinux.org/title/General_purpose_mouse

@igrag
Copy link
Author

igrag commented Feb 21, 2025

Yes, I tried but no response from tview.

@digitallyserviced
Copy link
Contributor

@igrag do you get any response at a regular shell prompt? Does the cursor move at least when sitting at your shell's prompt?

Sometimes you have to ensure the service is running before logging in or your virtual console daemon starts (getty/agetty)

@igrag
Copy link
Author

igrag commented Feb 22, 2025

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.

@digitallyserviced
Copy link
Contributor

@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.

What is your $TERM environment var set to? If you do an export TERM=xterm-256coloror something other than what I believe is usually just linux for the virtual console by default does that do anything? I know tcell will not load all the terminfo escapes if it doesn't find an xterm-like terminfo

@rivo
Copy link
Owner

rivo commented Mar 26, 2025

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants