Skip to content

Set terminal tab title to scrcpy and device name#6825

Open
zxmpg41 wants to merge 1 commit into
Genymobile:devfrom
zxmpg41:feature/terminal-tab-title
Open

Set terminal tab title to scrcpy and device name#6825
zxmpg41 wants to merge 1 commit into
Genymobile:devfrom
zxmpg41:feature/terminal-tab-title

Conversation

@zxmpg41
Copy link
Copy Markdown

@zxmpg41 zxmpg41 commented May 11, 2026

Summary

Set the terminal tab/window title to scrcpy when the program starts, and update it to scrcpy - <device name> once a device is connected. This makes it easy to identify scrcpy tabs when multiple tabs are open in a terminal multiplexer or tabbed terminal emulator (e.g. Windows Terminal, macOS Terminal, tmux).

scrcpy_title

The title respects --window-title: if a custom window title is provided, the terminal tab title becomes scrcpy - <custom title> instead of using the device name.

The original terminal title is restored (cleared) when scrcpy exits, allowing the shell to reset its own title on the next prompt.

Changes

  • app/src/util/term.h — declared new function sc_term_set_title(const char *title)
  • app/src/util/term.c — implemented sc_term_set_title(): only emits output when stdout is a TTY (isatty() on Unix/macOS, _isatty() on Windows), so piping (e.g. scrcpy | tee logs.txt) is not affected; emits an OSC 0 escape sequence (\033]0;<title>\007) to stdout, supported by all modern terminal emulators; on Windows additionally calls SetConsoleTitleA() unconditionally as a fallback for legacy console hosts (cmd.exe, conhost) that do not process VT sequences
  • app/src/main.c — calls sc_term_set_title("scrcpy") immediately on startup; calls sc_term_set_title("") on exit to restore the terminal title
  • app/src/scrcpy.c — calls sc_term_set_title("scrcpy - <name>") after the device handshake completes (using --window-title if provided, otherwise the device name reported by the server); calls sc_term_set_title("") on exit
  • app/src/usb/scrcpy_otg.c — same behaviour in OTG mode: updates the terminal tab title to scrcpy - <USB product name> once the device is known; calls sc_term_set_title("") on exit

@rom1v
Copy link
Copy Markdown
Collaborator

rom1v commented May 12, 2026

Thank you, interesting. 👍

I think it should be printed only when the output is a tty (using isatty() I guess), otherwise with scrcpy | tee logs.txt the logs would include these special characters.

Also, please rebase onto dev.

On startup, set the terminal tab/window title to "scrcpy" so the tab
is immediately identifiable. Once the device is connected, update the
title to "scrcpy - <device name>" (or "scrcpy - <window-title>" if
--window-title is provided). On exit, clear the title so the shell can
restore its own.

OSC 0 escape sequences are used for cross-platform support (Windows
Terminal, macOS Terminal, xterm). On Windows, SetConsoleTitleA() is
also called as a fallback for legacy console hosts (cmd.exe, conhost).

The same behaviour applies in OTG mode.
@zxmpg41 zxmpg41 force-pushed the feature/terminal-tab-title branch from dfbefce to d98697a Compare May 12, 2026 21:56
@zxmpg41 zxmpg41 changed the base branch from master to dev May 12, 2026 21:56
@zxmpg41
Copy link
Copy Markdown
Author

zxmpg41 commented May 13, 2026

Good point. I've added isatty() and _isatty() for legacy windows check and rebased onto dev.
Ready for another look whenever you get a chance.

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