1212import importlib .metadata
1313import inspect
1414import os
15- import re
1615import subprocess
1716import sys
1817import threading
@@ -266,47 +265,6 @@ def get_double_click_interval_seconds() -> float:
266265 raise Exception (f"Unsupported platform: { sys .platform } " )
267266
268267
269- def get_linux_device_id (device_name : str ) -> int | None :
270- """Get the device ID for a device containing the given name.
271-
272- Args:
273- device_name (str): The name to search for in device listings.
274-
275- Returns:
276- Optional[int]: The device ID if found, None otherwise.
277- """
278- try :
279- output = subprocess .check_output (["xinput" , "list" ], text = True )
280- match = re .search (f"\\ b{ re .escape (device_name )} \\ b.*?id=(\\ d+)" , output )
281- if match :
282- return int (match .group (1 ))
283- except (subprocess .CalledProcessError , FileNotFoundError ):
284- pass
285- return None
286-
287-
288- def get_xinput_property (device_id : int , property_name : str ) -> int | None :
289- """Get a specific property value from xinput for a given device.
290-
291- Args:
292- device_id (int): The ID of the device.
293- property_name (str): The name of the property to search for.
294-
295- Returns:
296- Optional[int]: The property value if found, None otherwise.
297- """
298- try :
299- output = subprocess .check_output (
300- ["xinput" , "list-props" , str (device_id )], text = True
301- )
302- match = re .search (rf"{ property_name } \((\d+)\):\s+(\d+)" , output )
303- if match :
304- return int (match .group (2 ))
305- except (subprocess .CalledProcessError , FileNotFoundError ):
306- pass
307- return None
308-
309-
310268def get_double_click_distance_pixels () -> int :
311269 """Get the double click distance in pixels.
312270
@@ -332,12 +290,14 @@ def get_double_click_distance_pixels() -> int:
332290 logger .warning (f"{ x = } != { y = } " )
333291 return max (x , y )
334292 elif sys .platform .startswith ("linux" ):
335- device_id = get_linux_device_id ("Mouse" )
336- if device_id is not None :
337- value = get_xinput_property (device_id , "libinput Scrolling Pixel Distance" )
338- if value is not None :
339- return value
340- return DEFAULT_DOUBLE_CLICK_DISTANCE_PIXELS
293+ # Use 'drag-threshold' as a proxy for double-click distance
294+ gnome_cmd = "gsettings get org.gnome.desktop.peripherals.mouse drag-threshold"
295+ kde_cmd = "kreadconfig5 --group KDE --key DoubleClickDistance"
296+ return get_linux_setting (
297+ gnome_cmd ,
298+ kde_cmd ,
299+ DEFAULT_DOUBLE_CLICK_DISTANCE_PIXELS ,
300+ )
341301 else :
342302 raise Exception (f"Unsupported platform: { sys .platform } " )
343303
0 commit comments