Port shiftview

This commit is contained in:
Guido Cella 2023-05-03 09:34:28 +02:00
parent 960c32a7d8
commit 50914b9eb9
2 changed files with 39 additions and 0 deletions

View File

@ -107,6 +107,8 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
static const char *termcmd[] = { "foot", NULL };
static const char *menucmd[] = { "bemenu-run", NULL };
#include "shiftview.c"
static const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
/* modifier key function argument */
@ -120,6 +122,8 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05} },
{ MODKEY, XKB_KEY_Return, zoom, {0} },
{ MODKEY, XKB_KEY_Tab, view, {0} },
{ MODKEY, XKB_KEY_a, shiftview, { .i = -1 } },
{ MODKEY, XKB_KEY_semicolon, shiftview, { .i = 1 } },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },

35
shiftview.c Normal file
View File

@ -0,0 +1,35 @@
// "arg->i" stores the number of tags to shift right (positive value)
// or left (negative value)
void
shiftview(const Arg *arg)
{
Arg a;
Client *c;
size_t ntags = tagcount;
bool visible = false;
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 >> (ntags - i));
else // right circular shift
nextseltags = curseltags >> (- i) | (curseltags << (ntags + i));
// Check if the tag is visible
wl_list_for_each(c, &clients, link) {
if (c->mon == selmon && nextseltags & c->tags) {
visible = true;
break;
}
}
i += arg->i;
} while (!visible && ++count <= ntags);
if (count <= ntags) {
a.i = nextseltags;
view(&a);
}
}