From f5c9b65592327c2094d5981bb95d3e4afdf76344 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 18 Oct 2023 17:10:22 -0700 Subject: parseargs,error: add --need-shortcuts When you depend on the shortcuts as _the_ means of stopping/pausing a recording, like in a WM integration scenario, it's preferable to have rmd exit fatally when the grabs can't be setup. (usually this occurs when you've accidentally tried starting multiple recordings, and the shortcuts collide) This way, the integration can detect the failure and throw up a dialog or something informing the user that the recording wasn't started. All that's needed is including --need-shortcuts. Note this is a little janky in how it's implemented, because XSetErrorHandler() is janky and doesn't even support a user pointer payload. Rather than introducing global variables to either communicate the grab failures to other parts of rmd, or exposing the parsed args struct to the error handler globally in the other direction, I just made a grab-errors-are-fatal variant of the handler which gets installed when --need-shortcuts is specified. --- src/rmd_error.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/rmd_error.c') diff --git a/src/rmd_error.c b/src/rmd_error.c index aaef20a..f8c137e 100644 --- a/src/rmd_error.c +++ b/src/rmd_error.c @@ -35,7 +35,7 @@ -int rmdErrorHandler(Display *dpy, XErrorEvent *e) +static int rmdSharedErrorHandler(Display *dpy, XErrorEvent *e, boolean grabsfatal) { char error_desc[1024]; @@ -49,8 +49,19 @@ int rmdErrorHandler(Display *dpy, XErrorEvent *e) if ((e->error_code == BadAccess) && (e->request_code == X_GrabKey)) { fprintf(stderr, "Bad Access on XGrabKey.\n" "Shortcut already assigned.\n"); - return 0; + if (!grabsfatal) + return 0; } exit(1); } + +int rmdErrorHandler(Display *dpy, XErrorEvent *e) +{ + return rmdSharedErrorHandler(dpy, e, FALSE /* grabsfatal */); +} + +int rmdGrabErrorsFatalErrorHandler(Display *dpy, XErrorEvent *e) +{ + return rmdSharedErrorHandler(dpy, e, TRUE /* grabsfatal */); +} -- cgit v1.2.1