Skip to content

Commit

Permalink
Clear global clipboard after specified seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Nov 12, 2024
1 parent 89d0254 commit b62251d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,38 @@ static void handle_clipboard_data(Ghandles * g, unsigned int untrusted_len)
save_clipboard_file_xevent_timestamp(g->clipboard_xevent_time);
metadata.successful = true;
save_clipboard_metadata(&metadata);

if (g->clipboard_timeout > 0) {
switch (fork()) {
case -1:
perror("fork");
exit(1);
case 0:
struct stat st0, st1;
if (lstat(QUBES_CLIPBOARD_FILENAME, &st0) == -1) {
perror("Can not get clipboard data file status");
exit(1);
}
sleep(g->clipboard_timeout);
if (lstat(QUBES_CLIPBOARD_FILENAME, &st1) == -1) {
perror("Can not get clipboard data file status");
exit(1);
}
if (st0.st_mtime == st1.st_mtime) {
inter_appviewer_lock(g, 1);
old_umask = umask(0007);
metadata.copy_action = false;
clear_clipboard(&metadata);
umask(old_umask);
inter_appviewer_lock(g, 0);
if (g->log_level > 1)
fprintf(stderr, "Clipboard cleared after %d seconds\n",
g->clipboard_timeout);
}
_exit(1);
}
}

error:
umask(old_umask);
inter_appviewer_lock(g, 0);
Expand Down Expand Up @@ -4346,6 +4378,7 @@ static void load_default_config_values(Ghandles * g)
g->paste_seq_mask = ControlMask | ShiftMask;
g->paste_seq_key = XK_v;
g->clipboard_buffer_size = DEFAULT_CLIPBOARD_BUFFER_SIZE;
g->clipboard_timeout = 0;
g->allow_fullscreen = 0;
g->override_redirect_protection = 1;
g->startup_timeout = 45;
Expand Down Expand Up @@ -4430,6 +4463,11 @@ static void parse_vm_config(Ghandles * g, config_setting_t * group)
}
}

if ((setting =
config_setting_get_member(group, "clipboard_timeout"))) {
g->clipboard_timeout = config_setting_get_int(setting);
}

if ((setting =
config_setting_get_member(group, "allow_utf8_titles"))) {
g->allow_utf8_titles = config_setting_get_bool(setting);
Expand Down
1 change: 1 addition & 0 deletions gui-daemon/xside.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ struct _global_handles {
KeySym paste_seq_key; /* key for secure-paste 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 clipboard_timeout; /* x: clear global clipboard after x seconds, 0: do not clear */
int use_kdialog; /* use kdialog for prompts (default on KDE) or zenity (default on non-KDE) */
int prefix_titles; /* prefix windows titles with VM name (for WM without support for _QUBES_VMNAME property) */
enum trayicon_mode trayicon_mode; /* trayicon coloring mode */
Expand Down

0 comments on commit b62251d

Please sign in to comment.