mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-10 23:20:17 +01:00
touchpad: add a struct for handling physical button event state changes
On ClickPads (touchpads without phys. middle/right buttons) it is important to know whether a physical click is queued up. The finger position or number of fingers decide which button event to send. This isn't currently used, we still just send the button number at the moment. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
b9dda43c04
commit
1f656f12cf
2 changed files with 53 additions and 6 deletions
|
|
@ -230,16 +230,20 @@ tp_process_key(struct tp_dispatch *tp,
|
|||
const struct input_event *e,
|
||||
uint32_t time)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
switch (e->code) {
|
||||
case BTN_LEFT:
|
||||
case BTN_MIDDLE:
|
||||
case BTN_RIGHT:
|
||||
pointer_notify_button(
|
||||
&tp->device->base,
|
||||
time,
|
||||
e->code,
|
||||
e->value ? LIBINPUT_POINTER_BUTTON_STATE_PRESSED :
|
||||
LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
|
||||
mask = 1 << (e->code - BTN_LEFT);
|
||||
if (e->value) {
|
||||
tp->buttons.state |= mask;
|
||||
tp->queued |= TOUCHPAD_EVENT_BUTTON_PRESS;
|
||||
} else {
|
||||
tp->buttons.state &= ~mask;
|
||||
tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -275,6 +279,8 @@ tp_post_process_state(struct tp_dispatch *tp, uint32_t time)
|
|||
t->dirty = false;
|
||||
}
|
||||
|
||||
tp->buttons.old_state = tp->buttons.state;
|
||||
|
||||
tp->queued = TOUCHPAD_EVENT_NONE;
|
||||
}
|
||||
|
||||
|
|
@ -316,6 +322,40 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint32_t time)
|
|||
li_fixed_from_double(dy));
|
||||
}
|
||||
|
||||
static void
|
||||
tp_post_button_events(struct tp_dispatch *tp, uint32_t time)
|
||||
{
|
||||
uint32_t current, old, button;
|
||||
|
||||
if ((tp->queued &
|
||||
(TOUCHPAD_EVENT_BUTTON_PRESS|TOUCHPAD_EVENT_BUTTON_RELEASE)) == 0)
|
||||
return;
|
||||
|
||||
current = tp->buttons.state;
|
||||
old = tp->buttons.old_state;
|
||||
button = BTN_LEFT;
|
||||
|
||||
while (current || old) {
|
||||
enum libinput_pointer_button_state state;
|
||||
|
||||
if ((current & 0x1) ^ (old & 0x1)) {
|
||||
if (!!(current & 0x1))
|
||||
state = LIBINPUT_POINTER_BUTTON_STATE_PRESSED;
|
||||
else
|
||||
state = LIBINPUT_POINTER_BUTTON_STATE_RELEASED;
|
||||
|
||||
pointer_notify_button(&tp->device->base,
|
||||
time,
|
||||
button,
|
||||
state);
|
||||
}
|
||||
|
||||
button++;
|
||||
current >>= 1;
|
||||
old >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tp_post_events(struct tp_dispatch *tp, uint32_t time)
|
||||
{
|
||||
|
|
@ -342,6 +382,8 @@ tp_post_events(struct tp_dispatch *tp, uint32_t time)
|
|||
time,
|
||||
li_fixed_from_double(dx),
|
||||
li_fixed_from_double(dy));
|
||||
|
||||
tp_post_button_events(tp, time);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ struct tp_dispatch {
|
|||
double max_factor;
|
||||
} accel;
|
||||
|
||||
struct {
|
||||
uint32_t state;
|
||||
uint32_t old_state;
|
||||
} buttons; /* physical buttons */
|
||||
|
||||
enum touchpad_event queued;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue