Click to See Complete Forum and Search --> : ncurses and mouse in xterm


bwkaz
12-09-2001, 07:31 PM
OK, I've been trying to make a console Minesweeper with ncurses (I have v5.2) and, well, that's about it. Basically, the problem I have is that I set up the console for ncurses, and then enable mouse events for buttons 1, 2, and 3 (just the clicked event, not presses/releases), and then sit in a loop and getch() until it returns 'q' (oh yeah, I'm doing it in C). So far, so good. From my understanding, the getch() should return KEY_MOUSE when a mouse event that you have unmasked happens. Then I should call get_mouse() to get the info (x, y, button state, and device number).

Originally, I had no mouse clicks coming through at all on the straight console, but I had left-button only in an xterm (well, a KDE Konsole window, actually). I have since recompiled ncurses and enabled GPM support, and now the console version does get all three buttons. But the Konsole window version still only gets button 1. The right button pops up a KDE shortcut menu, and the middle button does nothing.

Anyone seen this before? Anyone know where to look for a solution? Or should I just hack on the Konsole source code for a while and see if I can get it to pass along something other than button 1?

Oh, my $TERM is set to "linux" on the console, and "xterm" in KDE. The terminfo for both of them has the correct mouse event escape code ("\E[M") set. The "xterm" file in /usr/share/terminfo is actually a symlink to xterm-xf86-v40, as I am running X 4.1.0. Is this set right? I can't find an entry for Konsole anywhere in the terminfo database.

Thanks to all in advance.

Stuka
12-10-2001, 11:04 AM
Your problem is probably NOT the konsole, but KDE itself. The typical paradigm in a window system is that the window system catches ALL mouse events, and passes on to the appropriate window any which it doesn't handle (like the left button). I don't know why the middle button is disappearing, but I'm sure it's KDE catching it.

bwkaz
12-10-2001, 01:18 PM
I checked into the Konsole source, and found a point where it was sending the appropriate escape codes on all mouse events to the shell. I don't know why that isn't happening, though....

There's a comment in there to try to turn on MOUSE_1000 mode or something like that, so I'll see if I can't find a way to do that through escape codes or something.

Oh, and I tried just running straight xterm, also, and everything worked just fine, all 3 buttons.

bwkaz
12-10-2001, 06:53 PM
Never mind, I searched some more and found a spot in the widget code that passed along the mouse events, and sure enough, it only passes along left button clicks. I can change it so that it passes right and middle, and even make it conditional on another variable, so I had an idea.

What I'm considering is having some sort of menu choice for whether or not to consume (or, equivalently, pass on) middle and right buttons. How big of a project d'ya think this would be? Because I think I'd be able to get the KDE people to put it into their distribution -- at least, it sounds like a Good Thing to me. And if I could understand the Qt menu stuff, it wouldn't be too hard to add a menu choice for it.

Stuka
12-11-2001, 11:20 AM
Sounds like a darn good idea. Maybe make it a configuration (.conf) type of option? This seems to me like something you wouldn't need to switch on and off regularly, but then again, having it close at hand might be better (and fit better in the GUI way of doing things). So this was actually in the Qt widget code? Interesting....

bwkaz
12-11-2001, 02:10 PM
If you want to see it, it's in <kdebase source directory>/konsole/src/TEWidget.C

It's in the Mouse section, in the function TEWidget::mousePressEvent. I'd add some stuff to the "if(ev->Button == MiddleButton)" and "if(ev->Button = RightButton)" sections.

The only problem with making it a non-GUI setting (a settings file thing), would be that I have no idea how on earth KDE does persistence with that type of thing. I'd have to look at the konsole.C file to see when it loads the settings (or even if it does.....) and set the default then. Maybe not hard, it kinda depends. We'll see. I'm installing KDE 2.2.2 now, just so I have a relatively recent source to diff against once it works.

CVS, here I come! or.. uh.... something like that.