Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endif
#include "util/log.h"
#include "util/net.h"
#include "util/term.h"
#include "version.h"

#ifdef _WIN32
Expand All @@ -32,6 +33,8 @@ main_scrcpy(int argc, char *argv[]) {
setbuf(stderr, NULL);
#endif

sc_term_set_title("scrcpy");

printf("scrcpy " SCRCPY_VERSION
" <https://github.com/Genymobile/scrcpy>\n");

Expand Down Expand Up @@ -108,6 +111,8 @@ main_scrcpy(int argc, char *argv[]) {
getchar();
}

sc_term_set_title("");

return ret;
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "util/acksync.h"
#include "util/log.h"
#include "util/rand.h"
#include "util/term.h"
#include "util/timeout.h"
#include "util/tick.h"
#ifdef HAVE_V4L2
Expand Down Expand Up @@ -493,6 +494,14 @@ scrcpy(struct scrcpy_options *options) {
const char *serial = s->server.serial;
assert(serial);

// Update the terminal tab title now that we know the device name.
// Use --window-title if provided, otherwise fall back to the device name.
const char *title_suffix =
options->window_title ? options->window_title : info->device_name;
char term_title[256];
snprintf(term_title, sizeof(term_title), "scrcpy - %s", title_suffix);
sc_term_set_title(term_title);

struct sc_file_pusher *fp = NULL;

if (options->window && options->control) {
Expand Down Expand Up @@ -1009,5 +1018,7 @@ scrcpy(struct scrcpy_options *options) {

sc_server_destroy(&s->server);

sc_term_set_title("");

return ret;
}
11 changes: 11 additions & 0 deletions app/src/usb/scrcpy_otg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL3/SDL.h>

Expand All @@ -16,6 +17,7 @@
#include "usb/keyboard_aoa.h"
#include "usb/mouse_aoa.h"
#include "util/log.h"
#include "util/term.h"

struct scrcpy_otg {
struct sc_usb usb;
Expand Down Expand Up @@ -182,6 +184,13 @@ scrcpy_otg(struct scrcpy_options *options) {
window_title = usb_device.product ? usb_device.product : "scrcpy";
}

// Update the terminal tab title now that we know the device name.
if (options->window_title || usb_device.product) {
char term_title[256];
snprintf(term_title, sizeof(term_title), "scrcpy - %s", window_title);
sc_term_set_title(term_title);
}

struct sc_screen_params params = {
.video = false,
.camera = false,
Expand Down Expand Up @@ -270,5 +279,7 @@ scrcpy_otg(struct scrcpy_options *options) {
sc_screen_destroy(&s->screen);
}

sc_term_set_title("");

return ret;
}
23 changes: 23 additions & 0 deletions app/src/util/term.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "term.h"

#include <assert.h>
#include <stdio.h>

#ifdef _WIN32
# include <io.h>
# include <windows.h>
#else
# include <unistd.h>
Expand Down Expand Up @@ -49,3 +51,24 @@ sc_term_get_size(unsigned *rows, unsigned *cols) {
return true;
#endif
}

void
sc_term_set_title(const char *title) {
#ifdef _WIN32
// Fallback for legacy Windows console hosts (cmd.exe / conhost) that do
// not process VT escape sequences.
SetConsoleTitleA(title);

if (!_isatty(_fileno(stdout))) {
return;
}
#else
if (!isatty(STDOUT_FILENO)) {
return;
}
#endif
// OSC 0 sets both the icon name and the window/tab title; recognized by
// Windows Terminal, macOS Terminal, xterm, and most modern emulators.
printf("\033]0;%s\007", title);
fflush(stdout);
}
14 changes: 14 additions & 0 deletions app/src/util/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@
bool
sc_term_get_size(unsigned *rows, unsigned *cols);

/**
* Set the terminal tab/window title.
*
* Emits an OSC 0 escape sequence (\033]0;<title>\007) recognized by Windows
* Terminal, macOS Terminal, xterm, and most modern terminal emulators.
* On Windows, also calls SetConsoleTitleA() as a fallback for legacy hosts
* (cmd.exe, conhost) that do not process VT sequences.
*
* Pass an empty string ("") to clear the title and let the shell restore its
* own title on the next prompt.
*/
void
sc_term_set_title(const char *title);

#endif