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

Add a fallback solution for unsupported desktop environments #2

Closed
Mi-La opened this issue Mar 25, 2021 · 5 comments
Closed

Add a fallback solution for unsupported desktop environments #2

Mi-La opened this issue Mar 25, 2021 · 5 comments

Comments

@Mi-La
Copy link

Mi-La commented Mar 25, 2021

Since the main logic of the touchpad HW switch is in the ioctl, and tuxedo-control.cpp already implements set_touchpad_state, it is unfortunate that is simply does nothing on desktop environments which are not supported.
I would propose to provide a fallback which should work for all environments.
Either just provide a simple daemon listening on the key for touchpad toggling or just provide an utility which will do simple HW toggling and let users to set-up their keyboard shortcut.

From my research there are only two necessary features for minimal functionality:

  • udev rule which changes permissions to allow the utility to toggle HW state
  • utility implementing the touchpad toggle

See related discussion here: tuxedocomputers/tuxedo-keyboard#60.

@Mi-La
Copy link
Author

Mi-La commented Mar 25, 2021

For others, here is my modification of set_touchpad_state which actually works:

int toggle_touchpad_state() {
    std::vector<std::string> devnodes;
    int touchpad_count = get_touchpad_hidraw_devices(&devnodes);
    if (touchpad_count < 0) {
        cerr << "get_touchpad_hidraw_devices failed." << endl;
        return EXIT_FAILURE;
    }
    if (touchpad_count == 0) {
        cout << "No compatible touchpads found." << endl;
        return EXIT_FAILURE;
    }

    int result = EXIT_SUCCESS;

    for (auto it = devnodes.begin(); it != devnodes.end(); ++it) {
        int hidraw = open((*it).c_str(), O_WRONLY|O_NONBLOCK);
        if (hidraw < 0) {
            cerr << "open(\"" << *it << "\", O_WRONLY|O_NONBLOCK) failed." << endl;
            result = EXIT_FAILURE;
        }
        else {
            // get the device's state first (feature report nr.7 - 0x07)
            char buffer[2] = {0x07, 0x00};
            ioctl(hidraw, HIDIOCGFEATURE(2), buffer);

            // toggle the state
            if (buffer[1] == 0x00) {
                buffer[1] = 0x03; // enable touchpad
            } else {
                buffer[1] = 0x00; // disable touchpad
            }

            int result = ioctl(hidraw, HIDIOCSFEATURE(2), buffer);
            if (result < 0) {
                cerr << "ioctl on " << *it << " failed." << endl;
                result = EXIT_FAILURE;
            }

            close(hidraw);
        }
    }

    return result;
}

@Matombo
Copy link
Contributor

Matombo commented Apr 28, 2021

Problem is: when pressing the disable-touchpad-button, most DEs also software toggle the touchpad. So directly toggling the hardware could result in the software toggle and the hardware toggle getting out of sync (for example when toggling on the loginscreen).

Out of sync means either software or hardware disable is active so the touchpad does not function regardless of how often the button is pressed.

More general solutions were discussed here: https://gitlab.freedesktop.org/libinput/libinput/-/issues/558, but a good idea that always works has yet to be found.

@Mi-La
Copy link
Author

Mi-La commented Apr 28, 2021

I understand the SW/HW blocking problem. It becomes more difficult to provide a working daemon. However I still think that providing a simple toggling utility which would allow users to set-up keyboard shortcuts on their own can be better than do nothing in case of unsupported environment. E.g. with my Xubuntu, I didn't find any other solution than to modify sources and compile the utility by myself. The important feature which is already implemented in tuxedo-touchpad-switch sources and which I needed is the ioctl call. With the toggling utility I just set-up keyboard shortcut on XF86TouchpadToggle to execute the toggling utility and the HW switch starts to work. (I still need tuxedo-keyboard installed to get XF86TouchpadToggle key event for the touchpad switch keys)

@jluttine
Copy link

jluttine commented Jan 17, 2023

I created a PR based on @Mi-La comment: #13

@kyllingstad
Copy link

I've extracted the HW switching code from Tuxedo Touchpad Switch and made a simple program that only does this, in case anyone is interested: https://git.sr.ht/~kyllingstad/uwtpctl (I wasn't aware of PR #13 when I made it.)

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

4 participants