Skip to content

Add Linux support (X11/XTest)#2

Draft
rikibbot wants to merge 4 commits intoantirez:mainfrom
rikibbot:linux-support
Draft

Add Linux support (X11/XTest)#2
rikibbot wants to merge 4 commits intoantirez:mainfrom
rikibbot:linux-support

Conversation

@rikibbot
Copy link
Copy Markdown

@rikibbot rikibbot commented Feb 6, 2026

Summary

  • Extract macOS-specific code from bot.c into platform_macos.c behind a clean platform abstraction (platform.h)
  • Add platform_linux.c using X11, XTest, and libpng for window enumeration, screenshots, keystroke injection, and window focus
  • bot.c is now fully platform-independent
  • Makefile auto-detects OS and links the correct platform backend
  • Add navigation key support: arrow keys (⬆️⬇️⬅️➡️) and PageUp/PageDown (🔼🔽)
  • Document headless/VM usage with Xvfb

Linux backend details

  • Window listing: _NET_CLIENT_LIST + WM_CLASS for terminal detection
  • Screenshots: XGetImage from root window at window coordinates, saved as PNG via libpng
  • Keystrokes: XTestFakeKeyEvent with automatic shift detection via XkbKeycodeToKeysym
  • Window focus: _NET_ACTIVE_WINDOW EWMH client message

Dependencies (Linux)

sudo apt install libx11-dev libxtst-dev libpng-dev libcurl4-openssl-dev libsqlite3-dev

Test plan

  • Builds cleanly on Linux (Ubuntu, gcc)
  • Window listing finds terminal windows (xterm, tested via Xvfb + openbox)
  • Screenshots capture correct window content as valid PNG
  • Keystroke injection types into focused terminal
  • Arrow keys and PageUp/PageDown work correctly (no spurious newline)
  • Full bot tested end-to-end via Telegram on headless VM
  • Verify macOS build still works (no macOS machine available in test environment)

Extract macOS-specific code from bot.c into platform_macos.c
and add platform_linux.c using X11, XTest, and libpng.

- platform.h: common interface for window listing, screenshots,
  keystroke injection, and window focus
- platform_linux.c: uses _NET_CLIENT_LIST for window enumeration,
  XGetImage for screenshots, XTestFakeKeyEvent for keystrokes,
  _NET_ACTIVE_WINDOW for window raising
- Makefile: auto-detects OS, links correct libraries
- bot.c: now platform-independent, calls plat_* functions
- README: Linux setup instructions and headless/VM usage guide
Emoji-based navigation keys:
- ⬆️⬇️⬅️➡️ for arrow keys (history, cursor movement)
- 🔼🔽 for Page Up/Down (scrolling in vim, less, etc.)
- Modifiers work with nav keys (e.g. Ctrl+Up)
Navigation keys (arrows, PageUp/PageDown) sent without modifiers
were getting an automatic Enter appended because had_mods was only
set when mods != 0. Now had_mods is set unconditionally for all
navigation keys, matching the behavior of ESC.

Restore inline comments that were inadvertently stripped during
the platform refactoring. Trim the README Xresources section to
avoid bloating it with a full color theme.
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.

1 participant