Menu

#962 LOCATE without column+GETMOUSE+INKEY bug in Linux terminal

open
nobody
rtlib
2022-06-24
2022-06-22
TeeEmCee
No

I don't know how I have the bad luck to find such obscure bugs, but I found that in console mode under Linux (this bug is likely specific to the Linux GPM GETMOUSE implementation), calling INKEY at a moment that the mouse is being moved, after having previously called LOCATE with only a row, not a column number, and having called GETMOUSE causes INKEY to start producing a stream of garbage characters, and additionally breaks GETMOUSE (it returns 0,0). It seems that all three functions have to be called to cause the bug.

cls

while true
    locate 5  'Causes bug
    'locate 5,1  'Doesn't cause bug
    dim as integer x,y
    getmouse x, y
    ? x & "," & y, inkey
    sleep 1
wend

Discussion

  • dkl

    dkl - 2022-06-22

    fb_ConsoleGetMouse() has two possible sources of data: GPM in case of TERM=linux, or terminal escape sequences in case of TERM=xterm. I'm also seeing the bug with the xterm case. (I can't even test the GPM case though, because FB looks for libgpm.so.1 and Ubuntu has libgpm.so.2, so getmouse doesn't work at all in that case.)

     

    Last edit: dkl 2022-10-03
  • dkl

    dkl - 2022-06-23

    I think the problem is fb_hTermQuery() - it can read and skip escape codes received from the terminal, while waiting for its expected response. The problem is that it will silently drop unexpected escape codes, such as (presumably) those for GETMOUSE, which would normally be handled by the INKEY mechanism (look for KEY_MOUSE).

    That should be relatively easy to fix, I might try to make a patch for this later... But another question is, why does fb_hTermQuery() read from stdin directly in the first place, instead of using __fb_con.keyboard_getch() or fb_hGetCh() like everything else?

     
  • TeeEmCee

    TeeEmCee - 2022-06-24

    Sorry, yes, I was wrong to mention GPM. I forgot that GPM is used for Linux ttys, not xterm-compatible emulators. I noticed the mouse wasn't working in a Linux tty but neglected to mention that. I actually tested for & see the bug under xfce4-terminal, xterm and konsole (except that even when the bug isn't triggered, konsole only updates the reported the mouse position while a mouse button is down).

    Also, instead of using INKEY, here's an alternative testcase using GETKEY. Moving the mouse causes spurious keypresses and breaks GETMOUSE.

    declare function fb_KeyHit alias "fb_KeyHit" () as long
    
    cls
    
    do
        locate 5  'Triggers bug
        'locate 5,1  'Doesn't trigger bug
        dim as integer x, y
        getmouse x, y
        ? x & "," & y
        while fb_keyhit
            dim a as integer = getkey
            'Two getkey values equivalent to inkey = "\255k"
            if a = &h100 or a = &h6bff then end
            ? "pressed " & a & "   "
        wend
        sleep 1
    loop
    

    (Off-topic, but how come fb_KeyHit isn't exposed as a keyword or at least in a header? It's very useful)

     

Log in to post a comment.

MongoDB Logo MongoDB