Skip to content

Commit

Permalink
Fix cursor issue in KDE and implement local cursor size accessibility…
Browse files Browse the repository at this point in the history
… settings (#72)

* Prevent cursor issues in KDE desktop environments

* Improve cursor exception handling

* Cursor size accessibility

* Change command line option help
  • Loading branch information
ehfd authored Jan 15, 2023
1 parent 07c4dca commit c17e64f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ services:
WEBRTC_ENABLE_RESIZE: ${WEBRTC_ENABLE_RESIZE}

# DEBUG remote cursors
DEBUG_CURSORS: ${DEBUG_CURSORS:-false}
WEBRTC_DEBUG_CURSORS: ${WEBRTC_DEBUG_CURSORS:-false}

# Start full XFCE4 session, vs just X11 server.
START_XFCE4: ${START_XFCE4:-true}
Expand Down
12 changes: 10 additions & 2 deletions src/selkies_gstreamer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,14 @@ def main():
parser.add_argument('--enable_cursors',
default=os.environ.get('WEBRTC_ENABLE_CURSORS', 'true'),
help='Enable passing remote cursors to client')
parser.add_argument('--debug_cursors',
default=os.environ.get('WEBRTC_DEBUG_CURSORS', 'false'),
help='Enable cursor debug logging')
parser.add_argument('--cursor_size',
default=os.environ.get('WEBRTC_CURSOR_SIZE', '24'),
help='Cursor size in points for the local cursor, configure the remote cursor size in the remote desktop environment')
parser.add_argument('--metrics_port',
default=os.environ.get('METRICS_PORT', '8000'),
default=os.environ.get('WEBRTC_METRICS_PORT', '8000'),
help='Port to start metrics server on')
parser.add_argument('--debug', action='store_true',
help='Enable debug logging')
Expand Down Expand Up @@ -510,6 +516,8 @@ async def on_signalling_error(e):
curr_video_bitrate = int(args.video_bitrate)
curr_audio_bitrate = int(args.audio_bitrate)
enable_cursors = args.enable_cursors.lower() == "true"
cursor_debug = args.debug_cursors.lower() == "true"
cursor_size = int(args.cursor_size)

# Create instance of app
app = GSTWebRTCApp(stun_servers, turn_servers, enable_audio, curr_fps, args.encoder, curr_video_bitrate, curr_audio_bitrate)
Expand All @@ -532,7 +540,7 @@ async def on_signalling_error(e):
signalling.on_session = app.start_pipeline

# Initialize the Xinput instance
webrtc_input = WebRTCInput(args.uinput_mouse_socket, args.uinput_js_socket, args.enable_clipboard.lower(), enable_cursors)
webrtc_input = WebRTCInput(args.uinput_mouse_socket, args.uinput_js_socket, args.enable_clipboard.lower(), enable_cursors, cursor_size, cursor_debug)

# Handle changed cursors
webrtc_input.on_cursor_change = lambda data: app.send_cursor_data(data)
Expand Down
38 changes: 22 additions & 16 deletions src/selkies_gstreamer/webrtc_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WebRTCInputError(Exception):


class WebRTCInput:
def __init__(self, uinput_mouse_socket_path="", uinput_js_socket_path="", enable_clipboard="", enable_cursors=True):
def __init__(self, uinput_mouse_socket_path="", uinput_js_socket_path="", enable_clipboard="", enable_cursors=True, cursor_size=24, cursor_debug=False):
"""Initializes WebRTC input instance
"""
self.clipboard_running = False
Expand All @@ -111,9 +111,9 @@ def __init__(self, uinput_mouse_socket_path="", uinput_js_socket_path="", enable
self.enable_cursors = enable_cursors
self.cursors_running = False
self.cursor_cache = {}
self.cursor_resize_width = 24
self.cursor_resize_height = 24
self.cursor_debug = os.environ.get("DEBUG_CURSORS", "false").lower() == "true"
self.cursor_resize_width = cursor_size
self.cursor_resize_height = cursor_size
self.cursor_debug = cursor_debug

self.keyboard = None
self.mouse = None
Expand Down Expand Up @@ -425,26 +425,32 @@ def start_cursor_monitor(self):
logger.info("watching for cursor changes")

# Fetch initial cursor
image = self.xdisplay.xfixes_get_cursor_image(screen.root)
self.cursor_cache[image.cursor_serial] = self.cursor_to_msg(image, self.cursor_resize_width, self.cursor_resize_height)
self.on_cursor_change(self.cursor_cache[image.cursor_serial])
try:
image = self.xdisplay.xfixes_get_cursor_image(screen.root)
self.cursor_cache[image.cursor_serial] = self.cursor_to_msg(image, self.cursor_resize_width, self.cursor_resize_height)
self.on_cursor_change(self.cursor_cache[image.cursor_serial])
except Exception as e:
logger.warning("exception from fetching cursor image: %s" % e)

while self.cursors_running:
e = self.xdisplay.next_event()
if (e.type, 0) == self.xdisplay.extension_event.DisplayCursorNotify:
cache_key = e.cursor_serial
event = self.xdisplay.next_event()
if (event.type, 0) == self.xdisplay.extension_event.DisplayCursorNotify:
cache_key = event.cursor_serial
if cache_key in self.cursor_cache:
if self.cursor_debug:
logger.warning("cursor changed to cached serial: {}".format(cache_key))
else:
# Request the cursor image.
cursor = self.xdisplay.xfixes_get_cursor_image(screen.root)
try:
# Request the cursor image.
cursor = self.xdisplay.xfixes_get_cursor_image(screen.root)

# Convert cursor image and cache.
self.cursor_cache[cache_key] = self.cursor_to_msg(cursor, self.cursor_resize_width, self.cursor_resize_height)
# Convert cursor image and cache.
self.cursor_cache[cache_key] = self.cursor_to_msg(cursor, self.cursor_resize_width, self.cursor_resize_height)

if self.cursor_debug:
logger.warning("New cursor: position={},{}, size={}x{}, length={}, xyhot={},{}, cursor_serial={}".format(cursor.x, cursor.y, cursor.width,cursor.height, len(cursor.cursor_image), cursor.xhot, cursor.yhot, cursor.cursor_serial))
if self.cursor_debug:
logger.warning("New cursor: position={},{}, size={}x{}, length={}, xyhot={},{}, cursor_serial={}".format(cursor.x, cursor.y, cursor.width,cursor.height, len(cursor.cursor_image), cursor.xhot, cursor.yhot, cursor.cursor_serial))
except Exception as e:
logger.warning("exception from fetching cursor image: %s" % e)

self.on_cursor_change(self.cursor_cache.get(cache_key))

Expand Down

0 comments on commit c17e64f

Please sign in to comment.