From cf600a33ab9bd92bec1c988fbeae21dcdcb24940 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 9 Oct 2024 15:31:02 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B3=E3=83=94=E3=83=BC=E3=82=BF=E3=82=A4?= =?utf8?q?=E3=83=A0=E3=82=A2=E3=82=A6=E3=83=88=E3=81=AE=E9=96=93=E3=81=ABC?= =?utf8?q?TRL+C=E3=82=92=E6=8A=BC=E3=81=97=E3=81=9F=E3=82=89=E3=80=81?= =?utf8?q?=E3=82=AF=E3=83=AA=E3=83=83=E3=83=97=E3=83=9C=E3=83=BC=E3=83=89?= =?utf8?q?=E3=81=8B=E3=82=89=E5=8F=96=E3=82=8A=E6=B6=88=E3=81=99=E6=A7=98?= =?utf8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/common.c | 18 ++++++++++++++++++ src/common.h | 2 ++ src/otppass.c | 5 +++++ src/yankpass.c | 3 +++ 5 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4ef4e6..f3a67eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * パスワードコピーの期間を設定出来る様に * ワンタイムパスワード(OTP)を表示せずにコピー機能性の追加 * Wayland対応の追加 +* コピータイムアウトの間にCTRL+Cを押したら、クリップボードから取り消す様に # 1.4.0 * Haiku対応 diff --git a/src/common.c b/src/common.c index 58c975e..4253a9d 100644 --- a/src/common.c +++ b/src/common.c @@ -253,3 +253,21 @@ void freeList(List *list) { list->tail = NULL; list->size = 0; } + +void handle_sigint(int sig) { + (void)sig; + + if (getenv("WAYLAND_DISPLAY") != NULL) { + system("echo -n \"\" | wl-copy"); + } else { + system("echo -n \"\" | xclip -selection clipboard"); + } + + if (strncmp(getlang(), "en", 2) == 0) { + printf("\nClipboard cleared and program aborted.\n"); + } else { + printf("\nクリップボードをクリアし、プログラムが中止されました。\n"); + } + + exit(0); +} diff --git a/src/common.h b/src/common.h index dead7fe..2e06fd5 100644 --- a/src/common.h +++ b/src/common.h @@ -1,6 +1,7 @@ #ifndef COMMON_H #define COMMON_H +#include #include #include #include @@ -27,6 +28,7 @@ int mkdir_r(const char *path, mode_t mode); int tmpcopy(const char *inpath, const char *outpath); void scanDir(const char *dpath, const char *rpath, List *fpaths, List *fullpaths, List *dispaths); +void handle_sigint(int sig); // C言語のvector void initList(List *list); diff --git a/src/otppass.c b/src/otppass.c index 39aaec8..1124fc1 100644 --- a/src/otppass.c +++ b/src/otppass.c @@ -124,6 +124,11 @@ void otppass(char *file, int isCopy, int copyTimeout) { return; } + // CTRL + Cを押す場合 + if (isCopy) { + signal(SIGINT, handle_sigint); + } + gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; diff --git a/src/yankpass.c b/src/yankpass.c index d79463c..c1b5435 100644 --- a/src/yankpass.c +++ b/src/yankpass.c @@ -39,6 +39,9 @@ void yankpass(char *file, int copyTimeout) { return; } + // CTRL + Cを押す場合 + signal(SIGINT, handle_sigint); + // OpenPGPプロトコールを設定 gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP); -- 2.43.0