This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / configs / desktops / lib / gamescope_libinput.patch
17 kB 459 lines
1From 8518bc9b6ce13b0beffde1e59dae347e25adec84 Mon Sep 17 00:00:00 2001 2From: honjow <honjow311@gmail.com> 3Date: Tue, 25 Jun 2024 21:52:11 +0800 4Subject: [PATCH 1/3] feat: Support libinput pointer settings. 5 6--- 7 src/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 8 src/main.hpp | 12 ++++++++++++ 9 src/wlserver.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 10 3 files changed, 99 insertions(+) 11 12diff --git a/src/main.cpp b/src/main.cpp 13index e8ebd66a30..37dfb8ebcb 100644 14--- a/src/main.cpp 15+++ b/src/main.cpp 16@@ -145,6 +145,12 @@ const struct option *gamescope_options = (struct option[]){ 17 // Steam Deck options 18 { "mura-map", required_argument, nullptr, 0 }, 19 20+ // Pointer options 21+ { "tap-to-click", no_argument, nullptr, 0 }, 22+ { "tap-to-drag", no_argument, nullptr, 0 }, 23+ { "drag-lock", no_argument, nullptr, 0 }, 24+ { "natural-scrolling", required_argument, nullptr, 0 }, 25+ 26 {} // keep last 27 }; 28 29@@ -256,6 +262,16 @@ const char usage[] = 30 "Steam Deck options:\n" 31 " --mura-map Set the mura compensation map to use for the display. Takes in a path to the mura map.\n" 32 "\n" 33+ "Libinput Pointer options:\n" 34+ " --tap-to-click enable tap-to-click feature for pointer devices\n" 35+ " --tap-and-drag enable tap-and-drag feature for pointer devices\n" 36+ " --drag-lock enable drag-lock feature for pointer devices\n" 37+ " --natural-scrolling enable natural scrolling for ...\n" 38+ " none => No pointer device\n" 39+ " touchpad => Only for touchpad\n" 40+ " mouse => Only for mouse\n" 41+ " all => All pointer device\n" 42+ "\n" 43 "Keyboard shortcuts:\n" 44 " Super + F toggle fullscreen\n" 45 " Super + N toggle nearest neighbour filtering\n" 46@@ -305,6 +321,11 @@ float g_flMaxWindowScale = FLT_MAX; 47 uint32_t g_preferVendorID = 0; 48 uint32_t g_preferDeviceID = 0; 49 50+bool g_tapToClick = false; 51+bool g_tapAndDrag = false; 52+bool g_dragLock = false; 53+SelectedPointerType g_naturalScrolling = SelectedPointerType::NONE; 54+ 55 pthread_t g_mainThread; 56 57 static void steamCompMgrThreadRun(int argc, char **argv); 58@@ -438,6 +459,20 @@ static gamescope::ConCommand cc_shutdown( "shutdown", "Cleanly shutdown gamescop 59 console_log.infof( "Shutting down..." ); 60 ShutdownGamescope(); 61 }); 62+static SelectedPointerType parse_selected_pointer_type(const char* str) 63+{ 64+ if (!str || !*str) 65+ return SelectedPointerType::NONE; 66+ 67+ if (!strcmp(str, "all")) 68+ return SelectedPointerType::ALL; 69+ else if (!strcmp(str, "touchpad")) 70+ return SelectedPointerType::TOUCHPAD; 71+ else if (!strcmp(str, "mouse")) 72+ return SelectedPointerType::MOUSE; 73+ else 74+ return SelectedPointerType::NONE; 75+} 76 77 static void handle_signal( int sig ) 78 { 79@@ -754,6 +789,14 @@ int main(int argc, char **argv) 80 g_nCursorScaleHeight = atoi(optarg); 81 } else if (strcmp(opt_name, "mangoapp") == 0) { 82 g_bLaunchMangoapp = true; 83+ } else if (strcmp(opt_name, "tap-to-click") == 0) { 84+ g_tapToClick = true; 85+ } else if (strcmp(opt_name, "tap-and-drag") == 0) { 86+ g_tapAndDrag = true; 87+ } else if (strcmp(opt_name, "drag-lock") == 0) { 88+ g_dragLock = true; 89+ } else if (strcmp(opt_name, "natural-scrolling") == 0) { 90+ g_naturalScrolling = parse_selected_pointer_type( optarg ); 91 } 92 break; 93 case '?': 94diff --git a/src/main.hpp b/src/main.hpp 95index 8cfe62915f..c8948f7bdc 100644 96--- a/src/main.hpp 97+++ b/src/main.hpp 98@@ -66,3 +66,15 @@ extern int g_nXWaylandCount; 99 extern uint32_t g_preferVendorID; 100 extern uint32_t g_preferDeviceID; 101 102+enum class SelectedPointerType : uint32_t 103+{ 104+ NONE, 105+ TOUCHPAD, 106+ MOUSE, 107+ ALL, 108+}; 109+ 110+extern bool g_tapToClick; 111+extern bool g_tapAndDrag; 112+extern bool g_dragLock; 113+extern SelectedPointerType g_naturalScrolling; 114diff --git a/src/wlserver.cpp b/src/wlserver.cpp 115index ee6891d103..95b250ec4a 100644 116--- a/src/wlserver.cpp 117+++ b/src/wlserver.cpp 118@@ -484,6 +484,48 @@ static void wlserver_handle_touch_motion(struct wl_listener *listener, void *dat 119 wlserver_touchmotion( event->x, event->y, event->touch_id, event->time_msec ); 120 } 121 122+static void wlserver_set_libinput_pointer(struct wlr_input_device *device) 123+{ 124+#ifdef WLR_BACKEND_LIBINPUT_H 125+ if (device->type != WLR_INPUT_DEVICE_POINTER || !wlr_input_device_is_libinput(device)) 126+ return; 127+ 128+ struct libinput_device* libinput_device = wlr_libinput_get_device_handle(device); 129+ 130+ if (g_tapToClick) 131+ libinput_device_config_tap_set_enabled(libinput_device, LIBINPUT_CONFIG_TAP_ENABLED); 132+ else 133+ libinput_device_config_tap_set_enabled(libinput_device, LIBINPUT_CONFIG_TAP_DISABLED); 134+ 135+ if (g_tapAndDrag) 136+ libinput_device_config_tap_set_drag_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_ENABLED); 137+ else 138+ libinput_device_config_tap_set_drag_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_DISABLED); 139+ 140+ if (g_dragLock) 141+ libinput_device_config_tap_set_drag_lock_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); 142+ else 143+ libinput_device_config_tap_set_drag_lock_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); 144+ 145+ if (libinput_device_config_scroll_has_natural_scroll(libinput_device) != 0) 146+ switch (g_naturalScrolling) 147+ { 148+ case SelectedPointerType::TOUCHPAD: 149+ if (libinput_device_config_tap_get_finger_count(libinput_device) != 0) 150+ libinput_device_config_scroll_set_natural_scroll_enabled(libinput_device, true); 151+ break; 152+ case SelectedPointerType::MOUSE: 153+ if (libinput_device_config_tap_get_finger_count(libinput_device) == 0) 154+ libinput_device_config_scroll_set_natural_scroll_enabled(libinput_device, true); 155+ break; 156+ case SelectedPointerType::ALL: 157+ libinput_device_config_scroll_set_natural_scroll_enabled(libinput_device, true); 158+ case SelectedPointerType::NONE: 159+ break; 160+ } 161+#endif 162+} 163+ 164 static void wlserver_new_input(struct wl_listener *listener, void *data) 165 { 166 struct wlr_input_device *device = (struct wlr_input_device *) data; 167@@ -534,6 +576,8 @@ static void wlserver_new_input(struct wl_listener *listener, void *data) 168 wl_signal_add( &pointer->wlr->events.axis, &pointer->axis); 169 pointer->frame.notify = wlserver_handle_pointer_frame; 170 wl_signal_add( &pointer->wlr->events.frame, &pointer->frame); 171+ 172+ wlserver_set_libinput_pointer(device); 173 } 174 break; 175 case WLR_INPUT_DEVICE_TOUCH: 176 177From 8f3bd1747ec3f72e8f5598e4de6a962ec44eecf4 Mon Sep 17 00:00:00 2001 178From: Chenx Dust <chenx_dust@outlook.com> 179Date: Fri, 5 Jul 2024 14:30:07 +0000 180Subject: [PATCH 2/3] feat: Add more options for libinput pointer device 181 182--- 183 src/main.cpp | 53 +++++++++++++++++++++++++--- 184 src/main.hpp | 14 ++++++++ 185 src/wlserver.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++------ 186 3 files changed, 142 insertions(+), 15 deletions(-) 187 188diff --git a/src/main.cpp b/src/main.cpp 189index 37dfb8ebcb..5eda5e8133 100644 190--- a/src/main.cpp 191+++ b/src/main.cpp 192@@ -145,11 +145,17 @@ const struct option *gamescope_options = (struct option[]){ 193 // Steam Deck options 194 { "mura-map", required_argument, nullptr, 0 }, 195 196- // Pointer options 197+ // Libinput options 198 { "tap-to-click", no_argument, nullptr, 0 }, 199 { "tap-to-drag", no_argument, nullptr, 0 }, 200 { "drag-lock", no_argument, nullptr, 0 }, 201+ { "middle-emulation", no_argument, nullptr, 0 }, 202+ { "disable-while-typing", no_argument, nullptr, 0 }, 203+ { "disable-while-trackpointing", no_argument, nullptr, 0 }, 204+ { "left-handed", no_argument, nullptr, 0 }, 205 { "natural-scrolling", required_argument, nullptr, 0 }, 206+ { "pointer-accel-profile", required_argument, nullptr, 0 }, 207+ { "pointer-accel-speed", required_argument, nullptr, 0 }, 208 209 {} // keep last 210 }; 211@@ -266,11 +272,19 @@ const char usage[] = 212 " --tap-to-click enable tap-to-click feature for pointer devices\n" 213 " --tap-and-drag enable tap-and-drag feature for pointer devices\n" 214 " --drag-lock enable drag-lock feature for pointer devices\n" 215+ " --middle-emulation enable middle button emulation for pointer devices\n" 216+ " --left-handed enable left handed mode for pointer devices\n" 217+ " --disable-while-typing disable pointer devices while typing\n" 218+ " --disable-while-trackpointing disable pointer devices while trackpointing\n" 219 " --natural-scrolling enable natural scrolling for ...\n" 220- " none => No pointer device\n" 221- " touchpad => Only for touchpad\n" 222- " mouse => Only for mouse\n" 223+ " none => No pointer device (default)\n" 224+ " touchpad => Only touchpad\n" 225+ " mouse => Only mouse\n" 226 " all => All pointer device\n" 227+ " --pointer-accel-profile set acceleration profile for pointer devices to ...\n" 228+ " adaptive => takes the current speed of the device into account when deciding on acceleration (default)\n" 229+ " flat => simply a constant factor applied to all device deltas, regardless of the speed of motion\n" 230+ " --pointer-accel-speed set acceleration speed for pointer devices within [-1, 1] (default 0)\n" 231 "\n" 232 "Keyboard shortcuts:\n" 233 " Super + F toggle fullscreen\n" 234@@ -324,7 +338,13 @@ uint32_t g_preferDeviceID = 0; 235 bool g_tapToClick = false; 236 bool g_tapAndDrag = false; 237 bool g_dragLock = false; 238+bool g_middleEmu = false; 239+bool g_leftHanded = false; 240+bool g_dwt = false; 241+bool g_dwtp = false; 242 SelectedPointerType g_naturalScrolling = SelectedPointerType::NONE; 243+PointerAccelProfileType g_accelProfile = PointerAccelProfileType::ADAPTIVE; 244+double g_accelSpeed = false; 245 246 pthread_t g_mainThread; 247 248@@ -474,6 +494,19 @@ static SelectedPointerType parse_selected_pointer_type(const char* str) 249 return SelectedPointerType::NONE; 250 } 251 252+static PointerAccelProfileType parse_pointer_accel_profile(const char* str) 253+{ 254+ if (!str || !*str) 255+ return PointerAccelProfileType::ADAPTIVE; 256+ 257+ if (!strcmp(str, "adaptive")) 258+ return PointerAccelProfileType::ADAPTIVE; 259+ else if (!strcmp(str, "flat")) 260+ return PointerAccelProfileType::FLAT; 261+ else 262+ return PointerAccelProfileType::ADAPTIVE; 263+} 264+ 265 static void handle_signal( int sig ) 266 { 267 switch ( sig ) { 268@@ -795,8 +828,20 @@ int main(int argc, char **argv) 269 g_tapAndDrag = true; 270 } else if (strcmp(opt_name, "drag-lock") == 0) { 271 g_dragLock = true; 272+ } else if (strcmp(opt_name, "middle-emulation") == 0) { 273+ g_middleEmu = true; 274+ } else if (strcmp(opt_name, "left-handed") == 0) { 275+ g_leftHanded = true; 276+ } else if (strcmp(opt_name, "disable-while-typing") == 0) { 277+ g_dwt = true; 278+ } else if (strcmp(opt_name, "disable-while-trackpointing") == 0) { 279+ g_dwtp = true; 280 } else if (strcmp(opt_name, "natural-scrolling") == 0) { 281 g_naturalScrolling = parse_selected_pointer_type( optarg ); 282+ } else if (strcmp(opt_name, "pointer-accel-profile") == 0) { 283+ g_accelProfile = parse_pointer_accel_profile( optarg ); 284+ } else if (strcmp(opt_name, "pointer-accel-speed") == 0) { 285+ g_accelSpeed = atof( optarg ); 286 } 287 break; 288 case '?': 289diff --git a/src/main.hpp b/src/main.hpp 290index c8948f7bdc..58eed11701 100644 291--- a/src/main.hpp 292+++ b/src/main.hpp 293@@ -74,7 +74,21 @@ enum class SelectedPointerType : uint32_t 294 ALL, 295 }; 296 297+enum class PointerAccelProfileType : uint32_t 298+{ 299+ NONE, 300+ FLAT, 301+ ADAPTIVE, 302+ CUSTOM, 303+}; 304+ 305 extern bool g_tapToClick; 306 extern bool g_tapAndDrag; 307 extern bool g_dragLock; 308+extern bool g_middleEmu; 309+extern bool g_leftHanded; 310+extern bool g_dwt; 311+extern bool g_dwtp; 312 extern SelectedPointerType g_naturalScrolling; 313+extern PointerAccelProfileType g_accelProfile; 314+extern double g_accelSpeed; 315diff --git a/src/wlserver.cpp b/src/wlserver.cpp 316index 95b250ec4a..7d7778f6ee 100644 317--- a/src/wlserver.cpp 318+++ b/src/wlserver.cpp 319@@ -486,28 +486,76 @@ static void wlserver_handle_touch_motion(struct wl_listener *listener, void *dat 320 321 static void wlserver_set_libinput_pointer(struct wlr_input_device *device) 322 { 323-#ifdef WLR_BACKEND_LIBINPUT_H 324+#ifdef HAVE_DRM 325 if (device->type != WLR_INPUT_DEVICE_POINTER || !wlr_input_device_is_libinput(device)) 326 return; 327 328 struct libinput_device* libinput_device = wlr_libinput_get_device_handle(device); 329 330- if (g_tapToClick) 331+ if (g_tapToClick) { 332 libinput_device_config_tap_set_enabled(libinput_device, LIBINPUT_CONFIG_TAP_ENABLED); 333- else 334+ } else { 335 libinput_device_config_tap_set_enabled(libinput_device, LIBINPUT_CONFIG_TAP_DISABLED); 336- 337- if (g_tapAndDrag) 338+ } 339+ if (g_tapAndDrag) { 340 libinput_device_config_tap_set_drag_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_ENABLED); 341- else 342+ } else { 343 libinput_device_config_tap_set_drag_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_DISABLED); 344- 345- if (g_dragLock) 346+ } 347+ if (g_dragLock) { 348 libinput_device_config_tap_set_drag_lock_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); 349- else 350+ } else { 351 libinput_device_config_tap_set_drag_lock_enabled(libinput_device, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); 352- 353- if (libinput_device_config_scroll_has_natural_scroll(libinput_device) != 0) 354+ } 355+ if (libinput_device_config_middle_emulation_is_available(libinput_device)) { 356+ if (g_middleEmu) { 357+ libinput_device_config_middle_emulation_set_enabled(libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); 358+ } else { 359+ libinput_device_config_middle_emulation_set_enabled(libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); 360+ } 361+ } else { 362+ if (device->name) { 363+ printf("Libinput pointer \"%s\": Middle button emulation not supported", device->name); 364+ } else { 365+ printf("Unnamed libinput pointer: Middle button emulation not supported"); 366+ } 367+ } 368+ if (libinput_device_config_left_handed_is_available(libinput_device)) { 369+ libinput_device_config_left_handed_set(libinput_device, g_leftHanded); 370+ } else { 371+ if (device->name) { 372+ printf("Libinput pointer \"%s\": Left handed mode not supported", device->name); 373+ } else { 374+ printf("Unnamed libinput pointer: Left handed mode not supported"); 375+ } 376+ } 377+ if (libinput_device_config_dwt_is_available(libinput_device)) { 378+ if (g_dwt) { 379+ libinput_device_config_dwt_set_enabled(libinput_device, LIBINPUT_CONFIG_DWT_ENABLED); 380+ } else { 381+ libinput_device_config_dwt_set_enabled(libinput_device, LIBINPUT_CONFIG_DWT_DISABLED); 382+ } 383+ } else { 384+ if (device->name) { 385+ printf("Libinput pointer \"%s\": Disable while typing not supported", device->name); 386+ } else { 387+ printf("Unnamed libinput pointer: Disable while typing not supported"); 388+ } 389+ } 390+ if (libinput_device_config_dwtp_is_available(libinput_device)) { 391+ if (g_dwtp) { 392+ libinput_device_config_dwtp_set_enabled(libinput_device, LIBINPUT_CONFIG_DWTP_ENABLED); 393+ } else { 394+ libinput_device_config_dwtp_set_enabled(libinput_device, LIBINPUT_CONFIG_DWTP_DISABLED); 395+ } 396+ } else { 397+ if (device->name) { 398+ printf("Libinput pointer \"%s\": Disable while track pointing not supported", device->name); 399+ } else { 400+ printf("Unnamed libinput pointer: Disable while track pointing not supported"); 401+ } 402+ } 403+ if (libinput_device_config_scroll_has_natural_scroll(libinput_device) != 0) { 404 switch (g_naturalScrolling) 405 { 406 case SelectedPointerType::TOUCHPAD: 407@@ -520,9 +568,29 @@ static void wlserver_set_libinput_pointer(struct wlr_input_device *device) 408 break; 409 case SelectedPointerType::ALL: 410 libinput_device_config_scroll_set_natural_scroll_enabled(libinput_device, true); 411+ break; 412 case SelectedPointerType::NONE: 413 break; 414 } 415+ } 416+ if (libinput_device_config_accel_is_available(libinput_device)) { 417+ switch (g_accelProfile) { 418+ case PointerAccelProfileType::FLAT: 419+ libinput_device_config_accel_set_profile(libinput_device, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); 420+ break; 421+ case PointerAccelProfileType::ADAPTIVE: 422+ default: 423+ libinput_device_config_accel_set_profile(libinput_device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); 424+ break; 425+ } 426+ libinput_device_config_accel_set_speed(libinput_device, g_accelSpeed); 427+ } else { 428+ if (device->name) { 429+ printf("Libinput pointer \"%s\": Accelation not supported", device->name); 430+ } else { 431+ printf("Unnamed libinput pointer: Accelation not supported"); 432+ } 433+ } 434 #endif 435 } 436 437 438From f69e6bcb2d1c49911f9e9aaf1a6f8e0f182eb29c Mon Sep 17 00:00:00 2001 439From: Chenx Dust <chenx_dust@outlook.com> 440Date: Thu, 17 Oct 2024 04:41:02 +0000 441Subject: [PATCH 3/3] fix: Fix typo of "tap and drag" option in `main.cpp` 442 443--- 444 src/main.cpp | 2 +- 445 1 file changed, 1 insertion(+), 1 deletion(-) 446 447diff --git a/src/main.cpp b/src/main.cpp 448index 5eda5e8133..05f8d26517 100644 449--- a/src/main.cpp 450+++ b/src/main.cpp 451@@ -147,7 +147,7 @@ const struct option *gamescope_options = (struct option[]){ 452 453 // Libinput options 454 { "tap-to-click", no_argument, nullptr, 0 }, 455- { "tap-to-drag", no_argument, nullptr, 0 }, 456+ { "tap-and-drag", no_argument, nullptr, 0 }, 457 { "drag-lock", no_argument, nullptr, 0 }, 458 { "middle-emulation", no_argument, nullptr, 0 }, 459 { "disable-while-typing", no_argument, nullptr, 0 },