Skip to content

Commit

Permalink
Allow shortcut for multiple use of clipboard data
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Nov 15, 2024
1 parent 89d0254 commit 6198368
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions gui-daemon/guid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ global: {
#
# secure_copy_sequence = "Ctrl-Shift-c";
# secure_paste_sequence = "Ctrl-Shift-v";
#
# Secure paste key sequence clears global clipboard after pasting. User could
# set another key sequence for multiple-use of clipboard data. This could be
# potentially a security risk and is disabled by default.
#
# secure_multipaste_sequence = "None";

# Limit number of windows
#
Expand Down
34 changes: 29 additions & 5 deletions gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ static Time get_clipboard_xevent_timestamp(bool logging) {

/* fetch clippboard content from file */
/* lock already taken in is_special_keypress() */
static void get_qubes_clipboard(Ghandles *g, char **data, int *len)
static void get_qubes_clipboard(Ghandles *g, char **data, int *len, bool multipaste)
{
FILE *file;
*len = 0;
Expand Down Expand Up @@ -1041,7 +1041,19 @@ static void get_qubes_clipboard(Ghandles *g, char **data, int *len)
fclose(file);
metadata.sent_size = *len;
metadata.successful = true;
clear_clipboard(&metadata);
if (multipaste) {
FILE *file;
// triggering notification by updating file modification time
file = fopen(QUBES_CLIPBOARD_FILENAME, "a");
if (!file) {
show_error_message(g, "secure multi-paste: failed to update modification time of file " QUBES_CLIPBOARD_FILENAME);
} else {
metadata.cleared = false;
save_clipboard_metadata(&metadata);
}
fclose(file);
} else
clear_clipboard(&metadata);
}

/* This is specific to Microsoft Windows and non-X11 compliant OS */
Expand Down Expand Up @@ -1513,8 +1525,13 @@ static int is_special_keypress(Ghandles * g, const XKeyEvent * ev, XID remote_wi
}

/* paste */
if (((int)ev->state & SPECIAL_KEYS_MASK) == g->paste_seq_mask
&& ev->keycode == XKeysymToKeycode(g->display, g->paste_seq_key)) {
bool multipaste = false;
if (((int)ev->state & SPECIAL_KEYS_MASK) == g->multipaste_seq_mask
&& ev->keycode == XKeysymToKeycode(g->display, g->multipaste_seq_key)) {
multipaste = true;
}
if (multipaste || (((int)ev->state & SPECIAL_KEYS_MASK) == g->paste_seq_mask
&& ev->keycode == XKeysymToKeycode(g->display, g->paste_seq_key))) {
if (ev->type != KeyPress)
return 1;
inter_appviewer_lock(g, 1);
Expand All @@ -1541,7 +1558,7 @@ static int is_special_keypress(Ghandles * g, const XKeyEvent * ev, XID remote_wi
hdr.type = MSG_CLIPBOARD_DATA;
if (g->log_level > 0)
fprintf(stderr, "secure paste\n");
get_qubes_clipboard(g, &data, &len);
get_qubes_clipboard(g, &data, &len, multipaste);
if (len > 0) {
/* MSG_CLIPBOARD_DATA used to use the window field to pass the length
of the blob, be aware when working with old implementations. */
Expand Down Expand Up @@ -4345,6 +4362,8 @@ static void load_default_config_values(Ghandles * g)
g->copy_seq_key = XK_c;
g->paste_seq_mask = ControlMask | ShiftMask;
g->paste_seq_key = XK_v;
g->multipaste_seq_mask = 0;
g->multipaste_seq_key = NoSymbol;
g->clipboard_buffer_size = DEFAULT_CLIPBOARD_BUFFER_SIZE;
g->allow_fullscreen = 0;
g->override_redirect_protection = 1;
Expand Down Expand Up @@ -4416,6 +4435,11 @@ static void parse_vm_config(Ghandles * g, config_setting_t * group)
parse_key_sequence(config_setting_get_string(setting),
&g->paste_seq_mask, &g->paste_seq_key);
}
if ((setting =
config_setting_get_member(group, "secure_multipaste_sequence"))) {
parse_key_sequence(config_setting_get_string(setting),
&g->multipaste_seq_mask, &g->multipaste_seq_key);
}

if ((setting =
config_setting_get_member(group, "max_clipboard_size"))) {
Expand Down
2 changes: 2 additions & 0 deletions gui-daemon/xside.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ struct _global_handles {
KeySym copy_seq_key; /* key for secure-copy key sequence */
int paste_seq_mask; /* modifiers mask for secure-paste key sequence */
KeySym paste_seq_key; /* key for secure-paste key sequence */
int multipaste_seq_mask; /* modifiers mask for secure-multipaste key sequence */
KeySym multipaste_seq_key; /* key for secure-multipaste key sequence */
unsigned int clipboard_buffer_size; /* maximum clipboard size limit */
int qrexec_clipboard; /* 0: use GUI protocol to fetch/put clipboard, 1: use qrexec */
int use_kdialog; /* use kdialog for prompts (default on KDE) or zenity (default on non-KDE) */
Expand Down

0 comments on commit 6198368

Please sign in to comment.