aboutsummaryrefslogtreecommitdiffstats
path: root/src/implementation.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-01 21:10:28 +0000
committerJoursoir <chat@joursoir.net>2021-03-01 21:10:28 +0000
commitce7c8411d7af66904da5e852f01fd95426ccf5c0 (patch)
tree29a0e1545cf2aa38d128e9031c9495f26582fa18 /src/implementation.c
parent10b676a2fee216cc00d2ca090a93a23d8b47241f (diff)
downloadlock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.tar.gz
lock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.tar.bz2
lock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.zip
use xlib for copy password
Diffstat (limited to 'src/implementation.c')
-rw-r--r--src/implementation.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/implementation.c b/src/implementation.c
index fb279fc..af9f79d 100644
--- a/src/implementation.c
+++ b/src/implementation.c
@@ -31,42 +31,41 @@
#include "xstd.h"
#include "easydir.h"
#include "r-gpgme.h"
+#if defined(DISPLAY)
+ #include "r-x11.h"
+#endif
/* define in implementation.h */
// GPG_PUBLICKEY_MAXLENGTH NNNN
-
-void copy_outside(char *password)
+int copy_outside(char *password)
{
- char *simple_path = malloc(sizeof(char) * (5 + 1));
- strcpy(simple_path, ".pass");
+ #if defined(DISPLAY)
+ int pid;
+ pid = fork();
+ if(pid == -1)
+ errprint(1, "X11 fork() failed\n");
+ if(pid == 0) /* new process */
+ exit(run_clipboard(password));
+ return 0;
+ #endif
- if(getenv("DISPLAY") != NULL)
- {
- FILE *f_pass;
- f_pass = fopen(simple_path, "w");
- if(f_pass == NULL) {
- callError(130);
+ if(getenv("WAYLAND_DISPLAY") != NULL) {
+ char * const wl_copy[] = {"wl-copy", password, NULL};
+ int pid;
+ pid = fork();
+ if(pid == -1)
+ errprint(1, "Wayland fork() failed\n");
+ if(pid == 0) { /* new process */
+ execvp("wl-copy", wl_copy);
+ perror("wl-copy");
+ exit(1);
}
- fputs(password, f_pass);
- fclose(f_pass);
-
- char *xclip[] = {"xclip", "-selection", "clipboard", "-i", simple_path, NULL};
- easyFork("xclip", xclip);
- remove(simple_path);
- free(simple_path);
+ return 0;
}
- else if(getenv("WAYLAND_DISPLAY") != NULL)
- {
- char *wl_copy[] = {"wl-copy", password, NULL};
- easyFork("wl-copy", wl_copy);
- }
- else printError("Error: No X11 or Wayland");
- #if defined(DEBUG)
- printf("Password copied to clipboard\n");
- #endif
+ errprint(1, "You didn't have x11 or wayland when app builded\n");
}
/* check two dot in path */