From bce7f0db3280d0ac7265d203fb6c7b42919a866f Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Mon, 25 Oct 2021 14:23:35 -0300 Subject: [PATCH] Add shiftview and some keybindings --- .gitignore | 3 +++ config.def.h | 54 ++++++++++++++++++++++++++++++-------------- shiftview.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100644 shiftview.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a283f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +config.h +*.o +dwm diff --git a/config.def.h b/config.def.h index 53d4c75..456f815 100644 --- a/config.def.h +++ b/config.def.h @@ -12,12 +12,13 @@ static const int swallowfloating = 0; /* 1 means swallow floating wind static const unsigned int gappiv = 10; /* vert inner gap between windows */ static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ //static const unsigned int gappov = 30; /* vert outer gap between windows and screen edge */ -static const unsigned int gappov = 15; /* vert outer gap between windows and screen edge */ +//static const unsigned int gappov = 15; /* vert outer gap between windows and screen edge */ +static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ static int smartgaps = 0; /* 1 means no outer gap when there is only one window */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ //static const char *fonts[] = { "monospace:size=10"}; -static const char *fonts[] = { "monospace:size=10", "Noto Emoji:pixelsize=12:antialias=true:autohint=true" }; +static const char *fonts[] = { "monospace:size=10", "Noto Color Emoji:pixelsize=12:antialias=true:autohint=true" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; static const char col_gray2[] = "#444444"; @@ -52,12 +53,15 @@ typedef struct { } Sp; const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL }; const char *spcmd2[] = {"st", "-n", "spranger", "-g", "144x41", "-e", "ranger", NULL }; -const char *spcmd3[] = {"keepassxc", NULL }; +//const char *spcmd2[] = {"st", "-n", "sppcmanfm", "-g", "144x41", "-e", "/home/slococo/launchPcmanfm", NULL }; +//const char *spcmd2[] = {"pcmanfm", NULL }; +const char *spcmd3[] = {"bitwarden-desktop", NULL }; static Sp scratchpads[] = { /* name cmd */ {"spterm", spcmd1}, {"spranger", spcmd2}, - {"keepassxc", spcmd3}, + //{"sppcmanfm", spcmd2}, + {"bitwarden", spcmd3}, }; /* tagging */ @@ -73,9 +77,15 @@ static const Rule rules[] = { { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, { "st", NULL, NULL, 0, 0, 1, 0, -1 }, { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ - { NULL, "spterm", NULL, SPTAG(0), 1, 0, 0, -1 }, - { NULL, "spranger", NULL, SPTAG(1), 1, 0, 0, -1 }, - { NULL, "keepassxc", NULL, SPTAG(2), 0, 0, 0, -1 }, + { NULL, NULL, "zathura", 0, 0, 0, 1, -1 }, + //{ "pcmanfm", NULL, NULL, 0, 1, 0, 0, -1 }, + //{ NULL, NULL, "pcmanfm", 0, 1, 0, 0, -1 }, + //{ NULL, NULL, "KeePass", 0, 0, 0, 1, -1 }, + { "KeePass2", NULL, NULL, 0, 1, 0, 1, -1 }, + { NULL, "spterm", NULL, SPTAG(0), 1, 0, 0, -1 }, + { NULL, "spranger", NULL, SPTAG(1), 1, 0, 0, -1 }, + //{ NULL, "sppcmanfm", NULL, SPTAG(1), 1, 0, 0, -1 }, + { NULL, "bitwarden", NULL, SPTAG(2), 1, 0, 0, -1 }, }; /* layout(s) */ @@ -87,6 +97,7 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win #define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */ #include "vanitygaps.c" +#include "shiftview.c" static const Layout layouts[] = { /* symbol arrange function */ @@ -140,20 +151,24 @@ static const char *mutevol[] = { "pulsemixer" , "--toggle-mute", NULL }; static Key keys[] = { /* modifier key function argument */ //{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, - { MODKEY, XK_p, spawn, SHCMD("dmenu_run") }, + { MODKEY, XK_p, spawn, SHCMD("dmenu_run_history") }, { MODKEY|ShiftMask, XK_p, spawn, SHCMD("dmenu_terminal") }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_b, togglebar, {0} }, STACKKEYS(MODKEY, focus) STACKKEYS(MODKEY|ShiftMask, push) - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY|ShiftMask, XK_i, incnmaster, {.i = +1 } }, + { MODKEY|ShiftMask, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY|ShiftMask, XK_h, setcfact, {.f = +0.25} }, { MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} }, { MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} }, { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_g, shiftview, { .i = -1 } }, + { MODKEY|ShiftMask, XK_g, shifttag, { .i = -1 } }, + { MODKEY, XK_semicolon, shiftview, { .i = +1 } }, + { MODKEY|ShiftMask, XK_semicolon, shifttag, { .i = +1 } }, { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } }, { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } }, @@ -185,9 +200,9 @@ static Key keys[] = { { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - { MODKEY, XK_y, togglescratch, {.ui = 0 } }, - { MODKEY, XK_u, togglescratch, {.ui = 1 } }, - { MODKEY, XK_x, togglescratch, {.ui = 2 } }, + { MODKEY, XK_x, togglescratch, {.ui = 0 } }, + { MODKEY, XK_y, togglescratch, {.ui = 1 } }, + { MODKEY, XK_u, togglescratch, {.ui = 2 } }, TAGKEYS( XK_1, 0) TAGKEYS( XK_2, 1) TAGKEYS( XK_3, 2) @@ -198,7 +213,7 @@ static Key keys[] = { TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quit, {0} }, - { MODKEY, XK_q, spawn, SHCMD("kill -15 $(ps -u $USER -o pid,%mem,%cpu,command | sort -b -k2 -r | sed -n '1!p' | cut -b 1-75 | dmenu -l 15") }, + { MODKEY, XK_q, spawn, SHCMD("kill -15 $(ps -u $USER -o pid,%mem,%cpu,command | sort -b -k2 -r | sed -n '1!p' | cut -b 1-75 | dmenu -l 15)") }, // https://gist.github.com/palopezv/efd34059af6126ad970940bcc6a90f2e // In my case, these XF86XK keys are FN+F2, FN+F4, FN+F3 respectively... @@ -208,13 +223,18 @@ static Key keys[] = { { 0, XF86XK_AudioRaiseVolume, spawn, {.v = upvol } }, */ - // It says that SHCMD is deprecated? { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pulsemixer --change-volume -1; sigdwmblocks 2") }, { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pulsemixer --change-volume +1; sigdwmblocks 2") }, { 0, XF86XK_AudioMute, spawn, SHCMD("pulsemixer --toggle-mute; sigdwmblocks 2") }, + { 0, XF86XK_HomePage, spawn, SHCMD("pcmanfm") }, + { 0, XF86XK_Tools, spawn, SHCMD("pkill imwheel && imwheel -b 45") }, + { 0, XF86XK_AudioStop, spawn, SHCMD("dunstctl set-paused toggle; sigdwmblocks 2") }, //{ 0, XF86XK_Favorites, spawn, SHCMD("maim -s | xclip -selection clipboard -t image/png") }, - { 0, XK_Print, spawn, SHCMD("maim -s | xclip -selection clipboard -t image/png") }, - { MODKEY, XK_Print, spawn, SHCMD("maim | xclip -selection clipboard -t image/png") }, + //{ 0, XK_Print, spawn, SHCMD("maim -s | xclip -selection clipboard -t image/png") }, + //{ MODKEY, XK_Print, spawn, SHCMD("maim | xclip -selection clipboard -t image/png") }, + //{ 0, XK_Print, spawn, SHCMD("( flameshot & ) && ( sleep 0.5s && flameshot gui )") }, + //{ 0, XK_Print, spawn, SHCMD("flameshot gui") }, + { 0, XK_Print, spawn, SHCMD("$HOME/.local/bin/screenshot") }, { MODKEY, XK_v, spawn, SHCMD("clipmenu") }, diff --git a/shiftview.c b/shiftview.c new file mode 100644 index 0000000..3d2706b --- /dev/null +++ b/shiftview.c @@ -0,0 +1,64 @@ +/** Function to shift the current view to the left/right + * + * @param: "arg->i" stores the number of tags to shift right (positive value) + * or left (negative value) + */ +void +shiftview(const Arg *arg) +{ + Arg shifted; + Client *c; + unsigned int tagmask = 0; + + for (c = selmon->clients; c; c = c->next) + if (!(c->tags & SPTAGMASK)) + tagmask = tagmask | c->tags; + + shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK; + if (arg->i > 0) /* left circular shift */ + do { + shifted.ui = (shifted.ui << arg->i) + | (shifted.ui >> (LENGTH(tags) - arg->i)); + shifted.ui &= ~SPTAGMASK; + } while (tagmask && !(shifted.ui & tagmask)); + else /* right circular shift */ + do { + shifted.ui = (shifted.ui >> (- arg->i) + | shifted.ui << (LENGTH(tags) + arg->i)); + shifted.ui &= ~SPTAGMASK; + } while (tagmask && !(shifted.ui & tagmask)); + + view(&shifted); +} + +void +shifttag(const Arg *arg) +{ + Arg a; + Client *c; + unsigned visible = 0; + int i = arg->i; + int count = 0; + int nextseltags, curseltags = selmon->tagset[selmon->seltags]; + + do { + if(i > 0) // left circular shift + nextseltags = (curseltags << i) | (curseltags >> (LENGTH(tags) - i)); + + else // right circular shift + nextseltags = curseltags >> (- i) | (curseltags << (LENGTH(tags) + i)); + + // Check if tag is visible + for (c = selmon->clients; c && !visible; c = c->next) + if (nextseltags & c->tags) { + visible = 1; + break; + } + i += arg->i; + } while (!visible && ++count < 10); + + if (count < 10) { + a.i = nextseltags; + tag(&a); + } +}