Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option to show clipboard updates in verbose mode #3914

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum {
OPT_REQUIRE_AUDIO,
OPT_AUDIO_BUFFER,
OPT_AUDIO_OUTPUT_BUFFER,
OPT_SHOW_CLIPBOARD,
};

struct sc_option {
Expand Down Expand Up @@ -516,6 +517,12 @@ static const struct sc_option options[] = {
"shortcuts, pass \"lctrl+lalt,lsuper\".\n"
"Default is \"lalt,lsuper\" (left-Alt or left-Super).",
},
{
.longopt_id = OPT_SHOW_CLIPBOARD,
.longopt = "show-clipboard",
.text = "Print the content of a clipboard when it is changed if the "
"log level is high enough."
},
{
.shortopt = 'S',
.longopt = "turn-screen-off",
Expand Down Expand Up @@ -1861,6 +1868,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false;
}
break;
case OPT_SHOW_CLIPBOARD:
opts->show_clipboard = true;
break;
default:
// getopt prints the error message on stderr
return false;
Expand Down
4 changes: 2 additions & 2 deletions app/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ run_controller(void *data) {
}

bool
sc_controller_start(struct sc_controller *controller) {
sc_controller_start(struct sc_controller *controller, const bool show_clipboard_value) {
LOGD("Starting controller thread");

bool ok = sc_thread_create(&controller->thread, run_controller,
Expand All @@ -135,7 +135,7 @@ sc_controller_start(struct sc_controller *controller) {
return false;
}

if (!sc_receiver_start(&controller->receiver)) {
if (!sc_receiver_start(&controller->receiver, show_clipboard_value)) {
sc_controller_stop(controller);
sc_thread_join(&controller->thread, NULL);
return false;
Expand Down
2 changes: 1 addition & 1 deletion app/src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void
sc_controller_destroy(struct sc_controller *controller);

bool
sc_controller_start(struct sc_controller *controller);
sc_controller_start(struct sc_controller *controller, const bool show_clipboard_value);

void
sc_controller_stop(struct sc_controller *controller);
Expand Down
1 change: 1 addition & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ const struct scrcpy_options scrcpy_options_default = {
.require_audio = false,
.list_encoders = false,
.list_displays = false,
.show_clipboard = false,
};
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ struct scrcpy_options {
bool require_audio;
bool list_encoders;
bool list_displays;
bool show_clipboard;
};

extern const struct scrcpy_options scrcpy_options_default;
Expand Down
13 changes: 11 additions & 2 deletions app/src/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "device_msg.h"
#include "util/log.h"

bool show_clipboard;

bool
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket,
struct sc_acksync *acksync) {
Expand Down Expand Up @@ -37,8 +39,14 @@ process_msg(struct sc_receiver *receiver, struct device_msg *msg) {
return;
}

LOGI("Device clipboard copied");
SDL_SetClipboardText(msg->clipboard.text);
if (show_clipboard) {
LOGI("Device clipboard copied: %s", msg->clipboard.text);
LOGD("Computer clipboard set: %s", SDL_GetClipboardText());
} else {
LOGI("Device clipboard copied");
LOGD("Computer clipboard set");
}
break;
}
case DEVICE_MSG_TYPE_ACK_CLIPBOARD:
Expand Down Expand Up @@ -108,9 +116,10 @@ run_receiver(void *data) {
}

bool
sc_receiver_start(struct sc_receiver *receiver) {
sc_receiver_start(struct sc_receiver *receiver, const bool show_clipboard_value) {
LOGD("Starting receiver thread");

show_clipboard = show_clipboard_value;
bool ok = sc_thread_create(&receiver->thread, run_receiver,
"scrcpy-receiver", receiver);
if (!ok) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void
sc_receiver_destroy(struct sc_receiver *receiver);

bool
sc_receiver_start(struct sc_receiver *receiver);
sc_receiver_start(struct sc_receiver *receiver, const bool show_clipboard_value);

// no sc_receiver_stop(), it will automatically stop on control_socket shutdown

Expand Down
3 changes: 2 additions & 1 deletion app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ scrcpy(struct scrcpy_options *options) {
.power_on = options->power_on,
.list_encoders = options->list_encoders,
.list_displays = options->list_displays,
.show_clipboard = options->show_clipboard,
};

static const struct sc_server_callbacks cbs = {
Expand Down Expand Up @@ -625,7 +626,7 @@ scrcpy(struct scrcpy_options *options) {
}
controller_initialized = true;

if (!sc_controller_start(&s->controller)) {
if (!sc_controller_start(&s->controller, options->show_clipboard)) {
goto end;
}
controller_started = true;
Expand Down
3 changes: 3 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ execute_server(struct sc_server *server,
if (params->list_displays) {
ADD_PARAM("list_displays=true");
}
if (params->show_clipboard) {
ADD_PARAM("show_clipboard=true");
}

#undef ADD_PARAM

Expand Down
1 change: 1 addition & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct sc_server_params {
bool power_on;
bool list_encoders;
bool list_displays;
bool show_clipboard;
};

struct sc_server {
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Controller implements AsyncProcessor {
private final DeviceMessageSender sender;
private final boolean clipboardAutosync;
private final boolean powerOn;
private final boolean showClipboard;

private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

Expand All @@ -41,11 +42,12 @@ public class Controller implements AsyncProcessor {

private boolean keepPowerModeOff;

public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync, boolean powerOn) {
public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync, boolean powerOn, boolean showClipboard) {
this.device = device;
this.connection = connection;
this.clipboardAutosync = clipboardAutosync;
this.powerOn = powerOn;
this.showClipboard = showClipboard;
initPointers();
sender = new DeviceMessageSender(connection);
}
Expand Down Expand Up @@ -393,7 +395,11 @@ private void getClipboard(int copyKey) {
private boolean setClipboard(String text, boolean paste, long sequence) {
boolean ok = device.setClipboardText(text);
if (ok) {
Ln.i("Device clipboard set");
String deviceInfo = "Device clipboard set";
if (showClipboard) {
deviceInfo += ": " + text;
}
Ln.i(deviceInfo);
}

// On Android >= 7, also press the PASTE key if requested
Expand Down
8 changes: 8 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Options {
private boolean downsizeOnError = true;
private boolean cleanup = true;
private boolean powerOn = true;
private boolean showClipboard = false;

private boolean listEncoders;
private boolean listDisplays;
Expand Down Expand Up @@ -143,6 +144,10 @@ public boolean getPowerOn() {
return powerOn;
}

public boolean getShowClipboard() {
return showClipboard;
}

public boolean getListEncoders() {
return listEncoders;
}
Expand Down Expand Up @@ -280,6 +285,9 @@ public static Options parse(String... args) {
case "power_on":
options.powerOn = Boolean.parseBoolean(value);
break;
case "show_clipboard":
options.showClipboard = Boolean.parseBoolean(value);
break;
case "list_encoders":
options.listEncoders = Boolean.parseBoolean(value);
break;
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
}

if (control) {
Controller controller = new Controller(device, connection, options.getClipboardAutosync(), options.getPowerOn());
Controller controller = new Controller(device, connection, options.getClipboardAutosync(), options.getPowerOn(), options.getShowClipboard());
device.setClipboardListener(text -> controller.getSender().pushClipboardText(text));
asyncProcessors.add(controller);
}
Expand Down