>From c196805f9fed6e5a62cb606a417605df5648f3ad Mon Sep 17 00:00:00 2001 From: Hritik Vijay <hr1...@protonmail.com> Date: Mon, 4 Jan 2021 20:38:37 +0530 Subject: [PATCH] Print Screen using maim
This patch uses maim to take screenshots with some intuitive keybindings. Look at config.def.h for the defaults. Note that you'd need to #define #WINKEY to proper ModnMask on your hardware. These are default masks with the PrintScr key ShiftMask starts with S i.e. Select ControlMask starts with C i.e. Copy to clipboard WINKEY starts with W i.e. current window --- config.def.h | 8 ++++++++ dwm.c | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/config.def.h b/config.def.h index 1c0b587..dba9bbb 100644 --- a/config.def.h +++ b/config.def.h @@ -45,6 +45,7 @@ static const Layout layouts[] = { /* key definitions */ #define MODKEY Mod1Mask +#define WINKEY Mod4Mask #define TAGKEYS(KEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ @@ -94,6 +95,13 @@ static Key keys[] = { TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quit, {0} }, + { 0 , XK_Print , printscr , {.ui = 0}} , + { ControlMask , XK_Print, printscr , {.ui = ControlMask}} , + { ShiftMask , XK_Print, printscr , {.ui = ShiftMask}} , + { ControlMask|ShiftMask, XK_Print, printscr , {.ui = ControlMask|ShiftMask}} , + { WINKEY , XK_Print, printscr , {.ui = WINKEY}} , + { WINKEY|ControlMask , XK_Print, printscr , {.ui = WINKEY|ShiftMask|ControlMask}} , + }; /* button definitions */ diff --git a/dwm.c b/dwm.c index 664c527..7735671 100644 --- a/dwm.c +++ b/dwm.c @@ -186,6 +186,7 @@ static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); static void pop(Client *); +static void printscr(const Arg *arg); static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); @@ -2127,6 +2128,32 @@ zoom(const Arg *arg) pop(c); } +void +printscr(const Arg *arg){ + /* + ShiftMask starts with S i.e. Select + ControlMask starts with C i.e. Copy to clipboard + WINKEY starts with W i.e. current Window + */ + + char maim[128] = "maim"; + char *bash[] = {"/bin/bash", "-c", maim, NULL }; + + if (arg->ui & ShiftMask) + strcat(maim, " -s"); + + if (arg->ui & WINKEY) + strcat(maim, " -i $(xdotool getactivewindow)"); + + if (arg->ui & ControlMask) + strcat(maim, " | xclip -selection clipboard -t image/png"); + else + strcat(maim, " ~/Pictures/screenshots/$(date +%Y%m%d%H%M%S).jpg"); + + const Arg sbash = {.v = bash}; + spawn(&sbash); +} + int main(int argc, char *argv[]) { -- 2.29.2