Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 26, 2025

This PR implements the missing KeyboardMonitor class for Linux platforms, completing the cross-platform keyboard monitoring functionality.

Overview

The Linux implementation uses X11 with the XInput2 extension to provide global keyboard event monitoring, following the same architectural patterns as the existing Windows and macOS implementations.

Key Features

  • Global keyboard monitoring: Captures key press/release events system-wide using XInput2
  • Modifier key detection: Tracks changes to Shift, Ctrl, Alt, Meta, Caps Lock, Num Lock, and Scroll Lock
  • Thread-safe operation: Background monitoring thread prevents blocking the main application
  • Graceful error handling: Properly handles cases where X11 display is unavailable (headless environments)
  • Resource management: Automatic cleanup of X11 resources on stop/destruction

Technical Implementation

The implementation follows the established PIMPL pattern used by other platforms:

class KeyboardMonitor::Impl {
  Display* display_;
  std::atomic<bool> monitoring_;
  std::thread monitoring_thread_;
  // X11/XInput2 event handling
};

Key aspects:

  • Uses XISelectEvents to register for keyboard events on the root window
  • Processes XI_KeyPress and XI_KeyRelease events in a dedicated monitoring thread
  • Converts X11 keycodes to the common event handler interface
  • Resolves naming conflicts between X11's None macro and the ModifierKey::None enum

Dependencies

Adds the following Linux-specific dependencies to the build system:

  • libx11-dev - Core X11 library
  • libxi-dev - XInput2 extension for input device handling
  • pthread - Threading support

Testing

The implementation has been validated to:

  • Build successfully on Linux with GTK3/X11 dependencies
  • Properly integrate with the existing cross-platform CMake build system
  • Handle start/stop operations correctly
  • Manage monitoring state appropriately
  • Gracefully handle missing X11 display connections

This completes the keyboard monitoring functionality across all supported platforms (Windows, macOS, and Linux).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
Copilot AI changed the title [WIP] [Linux] Implement KeyboardMonitor class [Linux] Implement KeyboardMonitor class using X11/XInput2 Aug 26, 2025
Copilot AI requested a review from lijy91 August 26, 2025 00:20
@lijy91 lijy91 marked this pull request as ready for review August 26, 2025 01:33
@lijy91 lijy91 merged commit 913e1ed into main Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants