Getting rid of absolute mouse.

It seems like XTEST protocol handler explicitly uses mouse with only relative axes to send absolute mouse coordinates so I am assuming it is safe.
This commit is contained in:
Twaik Yont 2024-04-14 22:41:26 +03:00
parent ecd3a3e292
commit 67abb3c144
3 changed files with 11 additions and 54 deletions

View File

@ -39,7 +39,7 @@ from The Open Group.
#define unused __attribute__((unused))
unused DeviceIntPtr lorieMouse, lorieMouseRelative, lorieTouch, lorieKeyboard;
unused DeviceIntPtr lorieMouse, lorieTouch, lorieKeyboard;
void
ProcessInputEvents(void) {
@ -98,43 +98,8 @@ lorieInitPointerButtons(DeviceIntPtr device)
#undef NBUTTONS
}
static int
lorieMouseProc(DeviceIntPtr device, int onoff) {
#define NAXES 2
DevicePtr pDev = (DevicePtr) device;
switch (onoff) {
case DEVICE_INIT: {
Atom axes_labels[NAXES] = { 0 };
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
if (!lorieInitPointerButtons(device)
|| !InitValuatorClassDeviceStruct(device, NAXES, axes_labels, GetMotionHistorySize(), Absolute)
|| !InitValuatorAxisStruct(device, 0, axes_labels[0], 0, 0xFFFF, 10000, 0, 10000, Absolute)
|| !InitValuatorAxisStruct(device, 1, axes_labels[1], 0, 0xFFFF, 10000, 0, 10000, Absolute)
|| !InitPointerAccelerationScheme(device, PtrAccelNoOp))
return BadValue;
break;
}
case DEVICE_ON:
pDev->on = TRUE;
break;
case DEVICE_OFF:
pDev->on = FALSE;
break;
case DEVICE_CLOSE:
break;
default:
return BadMatch;
}
return Success;
#undef NAXES
}
unused static int
lorieMouseRelativeProc(DeviceIntPtr device, int what)
lorieMouseProc(DeviceIntPtr device, int what)
{
#define NAXES 4
Atom axes_labels[NAXES] = { 0 };
@ -222,12 +187,10 @@ lorieTouchProc(DeviceIntPtr device, int what)
void
InitInput(unused int argc, unused char *argv[]) {
lorieMouseRelative = AddInputDevice(serverClient, lorieMouseRelativeProc, TRUE);
lorieMouse = AddInputDevice(serverClient, lorieMouseProc, TRUE);
lorieTouch = AddInputDevice(serverClient, lorieTouchProc, TRUE);
lorieKeyboard = AddInputDevice(serverClient, lorieKeybdProc, TRUE);
AssignTypeAndName(lorieMouseRelative, MakeAtom(XI_MOUSE, sizeof(XI_MOUSE) - 1, TRUE), "Lorie mouse");
AssignTypeAndName(lorieMouse, MakeAtom(XI_MOUSE, sizeof(XI_MOUSE) - 1, FALSE), "Lorie absolute mouse");
AssignTypeAndName(lorieMouse, MakeAtom(XI_MOUSE, sizeof(XI_MOUSE) - 1, TRUE), "Lorie mouse");
AssignTypeAndName(lorieTouch, MakeAtom(XI_TOUCHSCREEN, sizeof(XI_TOUCHSCREEN) - 1, TRUE), "Lorie touch");
AssignTypeAndName(lorieKeyboard, MakeAtom(XI_KEYBOARD, sizeof(XI_KEYBOARD) - 1, TRUE), "Lorie keyboard");
(void) mieqInit();

View File

@ -29,7 +29,7 @@ static int argc = 0;
static char** argv = NULL;
static int conn_fd = -1;
extern char *__progname; // NOLINT(bugprone-reserved-identifier)
extern DeviceIntPtr lorieMouse, lorieMouseRelative, lorieTouch, lorieKeyboard;
extern DeviceIntPtr lorieMouse, lorieTouch, lorieKeyboard;
extern ScreenPtr pScreenPtr;
extern int ucs2keysym(long ucs);
void lorieKeysymKeyboardEvent(KeySym keysym, int down);
@ -331,32 +331,26 @@ void handleLorieEvents(int fd, __unused int ready, __unused void *ignored) {
int flags;
switch(e.mouse.detail) {
case 0: // BUTTON_UNDEFINED
if (e.mouse.relative) {
valuator_mask_set_double(&mask, 0, (double) e.mouse.x);
valuator_mask_set_double(&mask, 1, (double) e.mouse.y);
QueuePointerEvents(lorieMouseRelative, MotionNotify, 0, POINTER_RELATIVE | POINTER_ACCELERATE, &mask);
} else {
flags = POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW;
valuator_mask_set_double(&mask, 0, (double) e.mouse.x);
valuator_mask_set_double(&mask, 1, (double) e.mouse.y);
QueuePointerEvents(lorieMouse, MotionNotify, 0, flags, &mask);
}
flags = (e.mouse.relative) ? POINTER_RELATIVE | POINTER_ACCELERATE : POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW;
valuator_mask_set_double(&mask, 0, (double) e.mouse.x);
valuator_mask_set_double(&mask, 1, (double) e.mouse.y);
QueuePointerEvents(lorieMouse, MotionNotify, 0, flags, &mask);
break;
case 1: // BUTTON_LEFT
case 2: // BUTTON_MIDDLE
case 3: // BUTTON_RIGHT
QueuePointerEvents(e.mouse.relative ? lorieMouseRelative : lorieMouse, e.mouse.down ? ButtonPress : ButtonRelease, e.mouse.detail, 0, &mask);
QueuePointerEvents(lorieMouse, e.mouse.down ? ButtonPress : ButtonRelease, e.mouse.detail, 0, &mask);
break;
case 4: // BUTTON_SCROLL
if (e.mouse.x) {
valuator_mask_zero(&mask);
valuator_mask_set_double(&mask, 2, (double) e.mouse.x / 120);
QueuePointerEvents(lorieMouseRelative, MotionNotify, 0, POINTER_RELATIVE, &mask);
QueuePointerEvents(lorieMouse, MotionNotify, 0, POINTER_RELATIVE, &mask);
}
if (e.mouse.y) {
valuator_mask_zero(&mask);
valuator_mask_set_double(&mask, 3, (double) e.mouse.y / 120);
QueuePointerEvents(lorieMouseRelative, MotionNotify, 0, POINTER_RELATIVE, &mask);
QueuePointerEvents(lorieMouse, MotionNotify, 0, POINTER_RELATIVE, &mask);
}
break;
}

0
termux-x11-preference Normal file → Executable file
View File