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

Set CLIPBOARD_STATE to sensitive if x-kde-passwordManagerHint is in the MIME list #204

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
subprojects/
9 changes: 9 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
name = "wl-clipboard-shell";
buildInputs = [
pkgs.meson
pkgs.ninja
];
}
6 changes: 6 additions & 0 deletions src/util/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ int mime_type_is_text(const char *mime_type) {
return basic || common || special;
}

int mime_type_is_sensitive(const char *mime_type) {
/* A heuristic to detect sensitive mime types */

return strcmp(mime_type, "x-kde-passwordManagerHint");
}

int str_has_prefix(const char *string, const char *prefix) {
size_t prefix_length = strlen(prefix);
return strncmp(string, prefix, prefix_length) == 0;
Expand Down
1 change: 1 addition & 0 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
typedef char * const *argv_t;

int mime_type_is_text(const char *mime_type);
int mime_type_is_sensitive(const char *mime_type);

int str_has_prefix(const char *string, const char *prefix);
int str_has_suffix(const char *string, const char *suffix);
Expand Down
11 changes: 10 additions & 1 deletion src/wl-paste.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ static void selection_callback(struct offer *offer, int primary) {
exit(0);
}

int sensitive = 0;

offer_for_each_mime_type(offer, mime_type) {
if (mime_type_is_sensitive(mime_type) == 0) {
sensitive = 1;
break;
}
}

struct types types = classify_offer_types(offer);
const char *mime_type = mime_type_to_request(types);

Expand Down Expand Up @@ -319,7 +328,7 @@ static void selection_callback(struct offer *offer, int primary) {
wl_display_flush(wl_display);

close(pipefd[1]);
rc = run_paste_command(pipefd[0], "data");
rc = run_paste_command(pipefd[0], sensitive == 1 ? "sensitive" : "data");
if (!rc) {
if (options.watch) {
/* Try to cope without exiting completely */
Expand Down