neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

tablets.patch (3375B)


      1 Subject: seat: a tablet pen drives the pointer
      2 
      3 diff --git a/libswc/seat.c b/libswc/seat.c
      4 index 02d43a0..76decec 100644
      5 --- a/libswc/seat.c
      6 +++ b/libswc/seat.c
      7 @@ -240,7 +240,9 @@ device_capabilities(struct libinput_device *device)
      8  	if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
      9  		capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
     10  	}
     11 -	if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) {
     12 +	/* a tablet's pen drives the pointer (see tablet_tool below) */
     13 +	if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER) ||
     14 +	    libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
     15  		capabilities |= WL_SEAT_CAPABILITY_POINTER;
     16  	}
     17  	/* TODO: Add touch device support
     18 @@ -262,6 +264,7 @@ handle_libinput_data(int fd, uint32_t mask, void *data)
     19  	union {
     20  		struct libinput_event_keyboard *k;
     21  		struct libinput_event_pointer *p;
     22 +		struct libinput_event_tablet_tool *t;
     23  	} event;
     24  	wl_fixed_t x, y, value;
     25  	uint32_t time, key, state;
     26 @@ -311,6 +314,42 @@ handle_libinput_data(int fd, uint32_t mask, void *data)
     27  			pointer_handle_absolute_motion(&seat->pointer, time, x, y);
     28  			pointer_handle_frame(&seat->pointer);
     29  			break;
     30 +		/* A tablet's pen as the pointer until clients are told of tablets:
     31 +		 * where it points, its tip the left button and its barrel's two
     32 +		 * buttons the middle and right ones, as a mouse would have them. */
     33 +		case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
     34 +		case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
     35 +		case LIBINPUT_EVENT_TABLET_TOOL_TIP:
     36 +			screen = wl_container_of(swc.screens.next, screen, link);
     37 +			rect = &screen->base.geometry;
     38 +			event.t = libinput_event_get_tablet_tool_event(generic_event);
     39 +			time = libinput_event_tablet_tool_get_time(event.t);
     40 +			x = wl_fixed_from_double(
     41 +			    libinput_event_tablet_tool_get_x_transformed(event.t, rect->width));
     42 +			y = wl_fixed_from_double(
     43 +			    libinput_event_tablet_tool_get_y_transformed(event.t, rect->height));
     44 +			pointer_handle_absolute_motion(&seat->pointer, time, x, y);
     45 +			if (libinput_event_get_type(generic_event) == LIBINPUT_EVENT_TABLET_TOOL_TIP) {
     46 +				pointer_handle_button(&seat->pointer, time, BTN_LEFT,
     47 +				                      libinput_event_tablet_tool_get_tip_state(event.t) ==
     48 +				                              LIBINPUT_TABLET_TOOL_TIP_DOWN
     49 +				                          ? WL_POINTER_BUTTON_STATE_PRESSED
     50 +				                          : WL_POINTER_BUTTON_STATE_RELEASED);
     51 +			}
     52 +			pointer_handle_frame(&seat->pointer);
     53 +			break;
     54 +		case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
     55 +			event.t = libinput_event_get_tablet_tool_event(generic_event);
     56 +			time = libinput_event_tablet_tool_get_time(event.t);
     57 +			key = libinput_event_tablet_tool_get_button(event.t);
     58 +			key = key == BTN_STYLUS ? BTN_MIDDLE : key == BTN_STYLUS2 ? BTN_RIGHT : key;
     59 +			pointer_handle_button(&seat->pointer, time, key,
     60 +			                      libinput_event_tablet_tool_get_button_state(event.t) ==
     61 +			                              LIBINPUT_BUTTON_STATE_PRESSED
     62 +			                          ? WL_POINTER_BUTTON_STATE_PRESSED
     63 +			                          : WL_POINTER_BUTTON_STATE_RELEASED);
     64 +			pointer_handle_frame(&seat->pointer);
     65 +			break;
     66  		case LIBINPUT_EVENT_POINTER_BUTTON:
     67  			event.p = libinput_event_get_pointer_event(generic_event);
     68  			time = libinput_event_pointer_get_time(event.p);