Skip to content

Commit

Permalink
Fix unneeded current_modifier_mask when using XTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed Mar 20, 2022
1 parent b340984 commit 61b9ca9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/x11/post_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "input_helper.h"
#include "logger.h"

#ifndef USE_XTEST
static long current_modifier_mask = NoEventMask;
#endif

static int post_key_event(uiohook_event * const event) {
KeyCode keycode = scancode_to_keycode(event->data.keyboard.keycode);
Expand Down Expand Up @@ -202,6 +204,15 @@ static int post_mouse_button_event(uiohook_event * const event) {

switch (event->type) {
case EVENT_MOUSE_PRESSED:
#ifdef USE_XTEST
if (event->data.mouse.button < MOUSE_BUTTON1 || event->data.mouse.button > MOUSE_BUTTON5) {
logger(LOG_LEVEL_WARN, "%s [%u]: Invalid button specified for mouse pressed event! (%u)\n",
__FUNCTION__, __LINE__, event->data.mouse.button);
return UIOHOOK_FAILURE;
}

XTestFakeButtonEvent(helper_disp, event->data.mouse.button, True, 0);
#else
if (event->data.mouse.button == MOUSE_BUTTON1) {
current_modifier_mask |= Button1MotionMask;
} else if (event->data.mouse.button == MOUSE_BUTTON2) {
Expand All @@ -218,9 +229,6 @@ static int post_mouse_button_event(uiohook_event * const event) {
return UIOHOOK_FAILURE;
}

#ifdef USE_XTEST
XTestFakeButtonEvent(helper_disp, event->data.mouse.button, True, 0);
#else
btn_event.type = ButtonPress;
btn_event.button = event->data.mouse.button;
btn_event.state = current_modifier_mask;
Expand All @@ -229,6 +237,15 @@ static int post_mouse_button_event(uiohook_event * const event) {
break;

case EVENT_MOUSE_RELEASED:
#ifdef USE_XTEST
if (event->data.mouse.button < MOUSE_BUTTON1 || event->data.mouse.button > MOUSE_BUTTON5) {
logger(LOG_LEVEL_WARN, "%s [%u]: Invalid button specified for mouse released event! (%u)\n",
__FUNCTION__, __LINE__, event->data.mouse.button);
return UIOHOOK_FAILURE;
}

XTestFakeButtonEvent(helper_disp, event->data.mouse.button, False, 0);
#else
if (event->data.mouse.button == MOUSE_BUTTON1) {
current_modifier_mask &= ~Button1MotionMask;
} else if (event->data.mouse.button == MOUSE_BUTTON2) {
Expand All @@ -245,9 +262,6 @@ static int post_mouse_button_event(uiohook_event * const event) {
return UIOHOOK_FAILURE;
}

#ifdef USE_XTEST
XTestFakeButtonEvent(helper_disp, event->data.mouse.button, False, 0);
#else
btn_event.type = ButtonRelease;
btn_event.button = event->data.mouse.button;
btn_event.state = current_modifier_mask;
Expand Down

0 comments on commit 61b9ca9

Please sign in to comment.