Skip to content

Commit

Permalink
Create virtual pointer on initialization (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaiya committed Jun 27, 2022
1 parent cd39c8e commit a26ea19
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions src/vkbd/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ static int create_virtual_pointer(const char *name)
return fd;
}

static void init_pfd(const struct vkbd *vkbd)
{
if (vkbd->pfd == -1) {
((struct vkbd *)vkbd)->pfd = create_virtual_pointer("keyd virtual pointer");
/* Give the device time to propagate up the input stack. */
usleep(100000);
}
}

static long get_time_ms()
{
struct timespec ts;
Expand Down Expand Up @@ -206,10 +197,8 @@ void write_key_event(const struct vkbd *vkbd, uint8_t code, int state)
* to prevent X from identifying the virtual
* keyboard as a mouse.
*/
if (is_btn) {
init_pfd(vkbd);
if (is_btn)
fd = vkbd->pfd;
}

ev.value = state;

Expand Down Expand Up @@ -257,24 +246,15 @@ struct vkbd *vkbd_init(const char *name)

struct vkbd *vkbd = calloc(1, sizeof vkbd);
vkbd->fd = create_virtual_keyboard(name);
vkbd->pfd = create_virtual_pointer("keyd virtual pointer");

/*
* lazily initialize the virtual pointer to avoid presenting an
* external mouse if it is unnecessary. This can cause issues higher
* up the input stack (e.g libinput touchpad disabling in the presence
* of an external mouse)
*/

vkbd->pfd = -1;
pthread_create(&tid, NULL, repeater, vkbd);

return vkbd;
}

void vkbd_mouse_move(const struct vkbd *vkbd, int x, int y)
{
init_pfd(vkbd);

struct input_event ev;

if (x) {
Expand Down Expand Up @@ -308,8 +288,6 @@ void vkbd_mouse_move(const struct vkbd *vkbd, int x, int y)

void vkbd_mouse_scroll(const struct vkbd *vkbd, int x, int y)
{
init_pfd(vkbd);

struct input_event ev;

ev.type = EV_REL;
Expand Down Expand Up @@ -339,8 +317,6 @@ void vkbd_mouse_scroll(const struct vkbd *vkbd, int x, int y)

void vkbd_mouse_move_abs(const struct vkbd *vkbd, int x, int y)
{
init_pfd(vkbd);

struct input_event ev;

ev.type = EV_ABS;
Expand Down

0 comments on commit a26ea19

Please sign in to comment.