mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	input: add tablet pad setup and button handler
Split pad initialization from tablet initialization to avoid conflicting handler names. Also reuse 'get_mapped_button'.
This commit is contained in:
		
							parent
							
								
									28e7cd3006
								
							
						
					
					
						commit
						c2687d9281
					
				
					 6 changed files with 90 additions and 29 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
labwc_sources += files(
 | 
			
		||||
  'cursor.c',
 | 
			
		||||
  'tablet.c',
 | 
			
		||||
  'tablet_pad.c',
 | 
			
		||||
  'gestures.c',
 | 
			
		||||
  'input.c',
 | 
			
		||||
  'keyboard.c',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -86,8 +86,8 @@ handle_axis(struct wl_listener *listener, void *data)
 | 
			
		|||
	// Ignore other events
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
get_mapped_button(uint32_t src_button)
 | 
			
		||||
uint32_t
 | 
			
		||||
tablet_get_mapped_button(uint32_t src_button)
 | 
			
		||||
{
 | 
			
		||||
	struct button_map_entry *map_entry;
 | 
			
		||||
	for (size_t i = 0; i < rc.tablet.button_map_count; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +106,7 @@ handle_tip(struct wl_listener *listener, void *data)
 | 
			
		|||
	struct wlr_tablet_tool_tip_event *ev = data;
 | 
			
		||||
	struct drawing_tablet *tablet = ev->tablet->data;
 | 
			
		||||
 | 
			
		||||
	uint32_t button = get_mapped_button(BTN_TOOL_PEN);
 | 
			
		||||
	uint32_t button = tablet_get_mapped_button(BTN_TOOL_PEN);
 | 
			
		||||
	if (!button) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -125,7 +125,7 @@ handle_button(struct wl_listener *listener, void *data)
 | 
			
		|||
	struct wlr_tablet_tool_button_event *ev = data;
 | 
			
		||||
	struct drawing_tablet *tablet = ev->tablet->data;
 | 
			
		||||
 | 
			
		||||
	uint32_t button = get_mapped_button(ev->button);
 | 
			
		||||
	uint32_t button = tablet_get_mapped_button(ev->button);
 | 
			
		||||
	if (!button) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -141,14 +141,8 @@ handle_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
	free(tablet);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
setup_pad(struct seat *seat, struct wlr_input_device *wlr_device)
 | 
			
		||||
{
 | 
			
		||||
	wlr_log(WLR_INFO, "not setting up pad");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
setup_pen(struct seat *seat, struct wlr_input_device *wlr_device)
 | 
			
		||||
void
 | 
			
		||||
tablet_init(struct seat *seat, struct wlr_input_device *wlr_device)
 | 
			
		||||
{
 | 
			
		||||
	wlr_log(WLR_DEBUG, "setting up tablet");
 | 
			
		||||
	struct drawing_tablet *tablet = znew(*tablet);
 | 
			
		||||
| 
						 | 
				
			
			@ -164,18 +158,3 @@ setup_pen(struct seat *seat, struct wlr_input_device *wlr_device)
 | 
			
		|||
	CONNECT_SIGNAL(tablet->tablet, &tablet->handlers, button);
 | 
			
		||||
	CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
tablet_setup_handlers(struct seat *seat, struct wlr_input_device *device)
 | 
			
		||||
{
 | 
			
		||||
	switch (device->type) {
 | 
			
		||||
	case WLR_INPUT_DEVICE_TABLET_PAD:
 | 
			
		||||
		setup_pad(seat, device);
 | 
			
		||||
		break;
 | 
			
		||||
	case WLR_INPUT_DEVICE_TABLET_TOOL:
 | 
			
		||||
		setup_pen(seat, device);
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		assert(false && "tried to add non-tablet as tablet");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										46
									
								
								src/input/tablet_pad.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/input/tablet_pad.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,46 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <wlr/types/wlr_tablet_pad.h>
 | 
			
		||||
#include <wlr/util/log.h>
 | 
			
		||||
#include "common/macros.h"
 | 
			
		||||
#include "common/mem.h"
 | 
			
		||||
#include "config/rcxml.h"
 | 
			
		||||
#include "input/cursor.h"
 | 
			
		||||
#include "input/tablet.h"
 | 
			
		||||
#include "input/tablet_pad.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_button(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct drawing_tablet_pad *tablet_pad =
 | 
			
		||||
		wl_container_of(listener, tablet_pad, handlers.button);
 | 
			
		||||
	struct wlr_tablet_pad_button_event *ev = data;
 | 
			
		||||
 | 
			
		||||
	uint32_t button = tablet_get_mapped_button(ev->button);
 | 
			
		||||
	if (!button) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cursor_emulate_button(tablet_pad->seat, button, ev->state, ev->time_msec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct drawing_tablet_pad *tablet =
 | 
			
		||||
		wl_container_of(listener, tablet, handlers.destroy);
 | 
			
		||||
	free(tablet);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_device)
 | 
			
		||||
{
 | 
			
		||||
	wlr_log(WLR_DEBUG, "setting up tablet pad");
 | 
			
		||||
	struct drawing_tablet_pad *tablet = znew(*tablet);
 | 
			
		||||
	tablet->seat = seat;
 | 
			
		||||
	tablet->tablet = wlr_tablet_pad_from_input_device(wlr_device);
 | 
			
		||||
	tablet->tablet->data = tablet;
 | 
			
		||||
	CONNECT_SIGNAL(tablet->tablet, &tablet->handlers, button);
 | 
			
		||||
	CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue