0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-12 09:41:18 +02:00

add text to avoid empty input for workaround

For the `input` workaround, we add a space key event to input some text
before pressing the enter key. This avoid the error that happens due to
gtk preventing empty input.

Signed-off-by: Tin Lai <oscar@tinyiu.com>
This commit is contained in:
Tin Lai 2024-02-06 17:19:00 +10:00
parent 344eb342f7
commit b2e718f5a7
3 changed files with 30 additions and 0 deletions

View file

@ -11,6 +11,7 @@ EnterDevice::EnterDevice()
libevdev_set_name(dev_ptr, "enter device");
libevdev_enable_event_type(dev_ptr, EV_KEY);
libevdev_enable_event_code(dev_ptr, EV_KEY, KEY_SPACE, nullptr);
libevdev_enable_event_code(dev_ptr, EV_KEY, KEY_ENTER, nullptr);
int err;
@ -24,6 +25,30 @@ EnterDevice::EnterDevice()
raw_uinput_device.reset(uinput_dev_ptr);
};
void EnterDevice::send_space_press() const {
auto *uinput_dev_ptr = raw_uinput_device.get();
int err;
if ((err = libevdev_uinput_write_event(uinput_dev_ptr, EV_KEY, KEY_SPACE,
1)) != 0) {
throw std::runtime_error(std::string("Failed to write event: ") +
strerror(-err));
}
if ((err = libevdev_uinput_write_event(uinput_dev_ptr, EV_KEY, KEY_SPACE,
0)) != 0) {
throw std::runtime_error(std::string("Failed to write event: ") +
strerror(-err));
}
if ((err = libevdev_uinput_write_event(uinput_dev_ptr, EV_SYN, SYN_REPORT,
0)) != 0)
{
throw std::runtime_error(std::string("Failed to write event: ") +
strerror(-err));
};
}
void EnterDevice::send_enter_press() const {
auto *uinput_dev_ptr = raw_uinput_device.get();

View file

@ -12,6 +12,7 @@ class EnterDevice {
public:
EnterDevice();
void send_space_press() const;
void send_enter_press() const;
~EnterDevice() = default;
};

View file

@ -409,6 +409,10 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
enter_device.send_enter_press();
}
// try it one more time with an non-empty input field
enter_device.send_space_press();
enter_device.send_enter_press();
if (retries == MAX_RETRIES) {
syslog(LOG_WARNING,
"Failed to send enter input before the retries limit");