[Linux] Hide/show cursor in X at runtime?


  • BINNED

    Yes, I am still alive, despite the appearances. Hello!

    Anyway, I'm working on a kiosk-like device now. I solved all the common fullscreen all the things, prevent Alt+F4 and similar nonsense. I am, however, stuck on hiding and showing the cursor. Now, obviously as it is with these things, the cursor should be hidden by default. I'm accomplishing this by adding -nocursor switch to X server start command. Works fine, no problems.

    However, there will also be a "service mode" USB with a configuration app on it that will launch when an approved USB drive is plugged in. One of the features of it will have is touchscreen calibration (because touchscreens are weird and may be totally misconfigured by default). So, it would be nice if the technician using the app could use a mouse until the screen is calibrated (there also might be multiple screens connected to it with only the primary one having a touchscreen, so). Which brings up a problem of there being no cursor for them to see while using the mouse.

    I found some weird hacky applications that accomplish this but they all seem wonky and not really what I need. Technically, I could restart X when the stick is plugged in, but I'm trying to avoid that.

    I know that you can set the cursor to be hidden over a specific window when using X libraries in your own applications, but does anyone know if there's a way to force that on/off for all windows using calls to xinput or XCB stuff from shell or something so I could do it on the fly?



  • @Onyx I'm not really familiar with X itself so I have no idea if you can do what you're asking specifically, however maybe you can work around that by having a fully transparent cursor in normal use, and change it to a normal cursor in service mode?

    I only do these things through Qt but it's apparently possible to set a custom pixmap with bitmask for transparency as cursor, so I'm guessing you might be able to dig down into their code to see how it's done?


  • Discourse touched me in a no-no place

    @Onyx said in [Linux] Hide/show cursor in X at runtime?:

    I know that you can set the cursor to be hidden over a specific window when using X libraries in your own applications, but does anyone know if there's a way to force that on/off for all windows using calls to xinput or XCB stuff from shell or something so I could do it on the fly?

    It might be easier to relaunch the xserver in “screen configuration mode” in that case, in which case you don't use the -nocursor option.


  • 🚽 Regular

    I had kind of the same problem until we decided on no cursor at all, ever, with --nocursor. A lot of people suggested things that didn't work reliably or flickered, but I did find something that did seem to work well and that didn't bugger up writing directly to the screen buffer either:

    Then you can use modprobe to load/unload the usbhid kernel module so the mouse can't move when you want it to hide (and then hhpc does the hiding). If you have other usbhid devices and thus can't remove the module to disable the mouse, then I think you will have to get creative with xinput instead and add/remove the mouse with a bit more fine-grained control.


  • BINNED

    @dkf said in [Linux] Hide/show cursor in X at runtime?:

    It might be easier to relaunch the xserver in “screen configuration mode” in that case, in which case you don't use the -nocursor option.

    That is my fallback, yes, if all else fails I'll just figure out a sane-ish way of doing that.

    @Cursorkeys said in [Linux] Hide/show cursor in X at runtime?:

    If you have other usbhid devices and thus can't remove the module to disable the mouse, then I think you will have to get creative with xinput instead and add/remove the mouse with a bit more fine-grained control.

    That would probably be the case, pretty sure removing usbhid would also kill the touchscreen.


  • 🚽 Regular

    @Onyx said in [Linux] Hide/show cursor in X at runtime?:

    That would probably be the case, pretty sure removing usbhid would also kill the touchscreen.

    Sounds likely. How about this for a mouse toggle script (modified SO answer because I hate trying to get awk to do what I want...):

    #!/bin/bash -e
    
    # Find mouse device ID
    ID="$(xinput | grep -ioP 'mouse.*id=\K[0-9]*')"                                  
    
    if   [ "$(LANG=C xinput --list-props "$ID" | awk 'NR==2{print $4}')" == "0" ]; then 
            # If the device is disabled, then enable it
            xinput enable "$ID";
    elif [ "$(LANG=C xinput --list-props "$ID" | awk 'NR==2{print $4}')" == "1" ]; then
            # If the device is enabled, then disable it
            xinput disable "$ID";
    fi
    

  • Discourse touched me in a no-no place

    @Cursorkeys said in [Linux] Hide/show cursor in X at runtime?:

    awk

    Short for “awkward”…


  • BINNED

    @Cursorkeys I'll give it a go I guess, hhpc was in my list of "this sounds overly hacky" software but if you had it working properly I have at least one testimony of it being usable...



  • @Cursorkeys Tested that ... first, it doesn't find any mice on my system (not to mention that it assumes that there is only one). Manually xinput disableing the mice prevents the cursor from being moved, but it's still visible.

    I don't know if that's a problem with your setup ... but people bringing their own mouse and connecting it may or may not be an issue. I believe new mice would start out as enabled by default.


  • BINNED

    @cvi said in [Linux] Hide/show cursor in X at runtime?:

    I don't know if that's a problem with your setup ... but people bringing their own mouse and connecting it may or may not be an issue. I believe new mice would start out as enabled by default.

    I don't really care TBQH, it's not like they'll be able to do much. I blocked pretty much every keyboard shortcut (might even make plugged in ones do nothing using udev rules as well and enable them manually from the service-mode application), and stuff they could click are the same thing they could just tap on anyway, so meh.



  • @Onyx Fair.

    I'm not too familiar with the touch input on Linux -- do touch inputs warp the cursor to the input's location?



  • @remi said in [Linux] Hide/show cursor in X at runtime?:

    I'm not really familiar with X itself

    Don't worry, no one is.

    (I got 50 more jokes about X but since this is a help thread I'll stop here)


  • BINNED

    @cvi said in [Linux] Hide/show cursor in X at runtime?:

    @Onyx Fair.

    I'm not too familiar with the touch input on Linux -- do touch inputs warp the cursor to the input's location?

    Yes. I'm pretty sure you can set it to relative mode but that's not what it's set to by default and I'm good with that.


  • 🚽 Regular

    @cvi said in [Linux] Hide/show cursor in X at runtime?:

    , but it's still visible.

    Yeah, the disabling is just to stop the mouse from being moved. Then hhpc detects the mouse isn't moving and hides it for you.

    @cvi said in [Linux] Hide/show cursor in X at runtime?:

    first, it doesn't find any mice on my system

    I plagiarised most of that and it doesn't work? I want a refund... I'll debug it, and correct, once yum -y groupinstall "X Window System" finishes, I only have minimal CentOS installs running currently.I can get a working X install, why is this so hard.



  • @Onyx Is your app a Qt one?
    Is it running fullscreen?

    // hide cursor
    QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
    
    // show cursor
    QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
    
    

    N.B.: that was under Qt 4.x


  • BINNED

    @TimeBandit Not this time, no. It's a webapp, currently running under nwjs.

    It is fullscreened and yes, we could technically CSS it to cursor: none over the whole thing, but that only covers it if there won't be any other usecases for it. I guess that's at least a workable solution for now and I can fight against X if it becomes an issue later (it's only going to load one specific URL for now).



  • @Onyx said in [Linux] Hide/show cursor in X at runtime?:

    Yes, I am still alive, despite the appearances. Hello!

    Anyway, I'm working on a kiosk-like device now. I solved all the common fullscreen all the things, prevent Alt+F4 and similar nonsense. I am, however, stuck on hiding and showing the cursor. Now, obviously as it is with these things, the cursor should be hidden by default. I'm accomplishing this by adding -nocursor switch to X server start command. Works fine, no problems.

    However, there will also be a "service mode" USB with a configuration app on it that will launch when an approved USB drive is plugged in. One of the features of it will have is touchscreen calibration (because touchscreens are weird and may be totally misconfigured by default). So, it would be nice if the technician using the app could use a mouse until the screen is calibrated (there also might be multiple screens connected to it with only the primary one having a touchscreen, so). Which brings up a problem of there being no cursor for them to see while using the mouse.

    I found some weird hacky applications that accomplish this but they all seem wonky and not really what I need. Technically, I could restart X when the stick is plugged in, but I'm trying to avoid that.

    I know that you can set the cursor to be hidden over a specific window when using X libraries in your own applications, but does anyone know if there's a way to force that on/off for all windows using calls to xinput or XCB stuff from shell or something so I could do it on the fly?

    I interpreted this as they were forcing you to do your work on a kiosk-type thing. It wasn't until I realized that you were trying to make it even more kiosk-like that I realized the error I'd made.


Log in to reply