AtlatestRepositorysigil-wm

sigil-wm / tree / src / cdevices.h

1/* SPDX-License-Identifier: BSD-3-Clause
2 * Input-device facts, lifetime cleanup and explicit libinput settings. */
3static struct device *find_device(struct server *s,uint64_t id) {
4 struct device *device;
5 wl_list_for_each(device,&s->devices,link) if(device->id==id) return device;
6 return NULL;
7}
8static void device_destroy(struct wl_listener *listener,void *data) {
9 (void)data;
10 struct device *device=wl_container_of(listener,device,destroy);
11 struct server *s=device->server;
12 if(s->scene_move.device==device->id) scene_move_finish(s);
13 for(int index=0;index<QUEUE_SIZE;index++) {
14 if(s->buttons[index].held && s->buttons[index].device==device->id) {
15 wlr_seat_pointer_notify_button(s->seat,now_ms(),s->buttons[index].target,0);
16 s->buttons[index].held=false;
17 }
18 }
19 if(!s->stopping) {
20 wlr_seat_pointer_notify_frame(s->seat);
21 route_motion(s,now_ms(),false);
22 }
23 EVENT(42,device->id);
24 wl_list_remove(&device->destroy.link); wl_list_remove(&device->link);
25 atomic_fetch_sub(&bridge.objects,1);
26 free(device);
28static bool configure_pointer(struct server *s,uint64_t token,const int64_t *words,size_t count) {
29 if(count!=5) return false;
30 for(int index=1;index<5;index++) if(words[index]<-1 || words[index]>1) return false;
31 struct device *device=find_device(s,words[0]);
32 if(!device || device->native->type!=WLR_INPUT_DEVICE_POINTER) return false;
33 struct libinput_device *native=wlr_input_device_is_libinput(device->native) ?
34 wlr_libinput_get_device_handle(device->native) : NULL;
35 int statuses[4]={-1,-1,-1,-1};
36 for(int index=0;index<4;index++) {
37 int value=words[index+1];
38 if(value<0) continue;
39 if(!native) { statuses[index]=LIBINPUT_CONFIG_STATUS_UNSUPPORTED; continue; }
40 switch(index) {
41 case 0: statuses[index]=libinput_device_config_tap_set_enabled(native,
42 value ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED); break;
43 case 1: statuses[index]=libinput_device_config_dwt_set_enabled(native,
44 value ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED); break;
45 case 2: statuses[index]=libinput_device_config_middle_emulation_set_enabled(native,
46 value ? LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED : LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); break;
47 case 3: statuses[index]=libinput_device_config_scroll_set_natural_scroll_enabled(native,value); break;
48 }
49 }
50 EVENT(44,token,device->id,statuses[0],statuses[1],statuses[2],statuses[3]);
51 return true;