Adding bartabgroups patch

This commit is contained in:
bakkeby
2020-08-13 15:42:49 +02:00
parent 57e727b498
commit de47bd8839
12 changed files with 439 additions and 165 deletions

View File

@ -48,13 +48,12 @@ draw_awesomebar(Bar *bar, BarDrawArg *a)
#endif // BAR_VTCOLORS_PATCH
drw_setscheme(drw, scheme[scm]);
tabw += (i < remainder ? 1 : 0);
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0, False);
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, lrpad / 2, c->name, 0, False);
#else
drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0);
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, lrpad / 2, c->name, 0);
#endif // BAR_PANGO_PATCH
x += tabw;
x += tabw + (i < remainder ? 1 : 0);
}
}
return a->x + a->w;
@ -84,94 +83,4 @@ click_awesomebar(Bar *bar, Arg *arg, BarClickArg *a)
return ClkWinTitle;
}
return -1;
}
void
hide(Client *c) {
Client *n;
if (!c || HIDDEN(c))
return;
Window w = c->win;
static XWindowAttributes ra, ca;
// more or less taken directly from blackbox's hide() function
XGrabServer(dpy);
XGetWindowAttributes(dpy, root, &ra);
XGetWindowAttributes(dpy, w, &ca);
// prevent UnmapNotify events
XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
XUnmapWindow(dpy, w);
setclientstate(c, IconicState);
XSelectInput(dpy, root, ra.your_event_mask);
XSelectInput(dpy, w, ca.your_event_mask);
XUngrabServer(dpy);
if (c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
for (n = c->snext; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
if (!n)
for (n = c->mon->stack; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
} else {
n = nexttiled(c);
if (!n)
n = prevtiled(c);
}
focus(n);
arrange(c->mon);
}
void
show(Client *c)
{
if (!c || !HIDDEN(c))
return;
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
arrange(c->mon);
}
void
togglewin(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (!c)
return;
if (c == selmon->sel)
hide(c);
else {
if (HIDDEN(c))
show(c);
focus(c);
restack(selmon);
}
}
Client *
prevtiled(Client *c)
{
Client *p, *i;
for (p = NULL, i = c->mon->clients; c && i != c; i = i->next)
if (ISVISIBLE(i) && !HIDDEN(i))
p = i;
return p;
}
void
showhideclient(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (!c)
c = selmon->sel;
if (!c)
return;
if (HIDDEN(c)) {
show(c);
restack(selmon);
} else {
hide(c);
}
}

View File

@ -1,9 +1,3 @@
static int width_awesomebar(Bar *bar, BarWidthArg *a);
static int draw_awesomebar(Bar *bar, BarDrawArg *a);
static int click_awesomebar(Bar *bar, Arg *arg, BarClickArg *a);
static void hide(Client *c);
static void show(Client *c);
static void togglewin(const Arg *arg);
static Client *prevtiled(Client *c);
static void showhideclient(const Arg *arg);
static int click_awesomebar(Bar *bar, Arg *arg, BarClickArg *a);

170
patch/bar_tabgroups.c Normal file
View File

@ -0,0 +1,170 @@
int
width_bartabgroups(Bar *bar, BarWidthArg *a)
{
return a->max_width;
}
int
draw_bartabgroups(Bar *bar, BarDrawArg *a)
{
drw_rect(drw, a->x, 0, a->w, bh, 1, 1);
bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL);
return a->x + a->w;
}
int
click_bartabgroups(Bar *bar, Arg *arg, BarClickArg *a)
{
bartabcalculate(bar->mon, 0, a->rel_w, a->rel_x, bartabclick, arg);
return ClkWinTitle;
}
void
bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg)
{
if (!c)
return;
int i, nclienttags = 0, nviewtags = 0;
drw_setscheme(drw, scheme[
m->sel == c
? SchemeSel
#if BAR_WINTITLEACTIONS_PATCH
: HIDDEN(c)
? SchemeHid
#endif // BAR_WINTITLEACTIONS_PATCH
: groupactive
? SchemeTabActive
: SchemeTabInactive
]);
drw_text(drw, x, 0, w, bh, lrpad / 2, c->name, 0);
if (c->isfloating)
drw_rect(drw, x + 2, 2, 5, 5, 0, 0);
if (BARTAB_BORDERS) {
XSetForeground(drw->dpy, drw->gc, scheme[SchemeSel][ColBorder].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, 0, 1, bh);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w, 0, 1, bh);
}
/* Optional tags icons */
for (i = 0; i < LENGTH(tags); i++) {
if ((m->tagset[m->seltags] >> i) & 1)
nviewtags++;
if ((c->tags >> i) & 1)
nclienttags++;
}
if (BARTAB_TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1) {
for (i = 0; i < LENGTH(tags); i++) {
drw_rect(drw,
( x + w - 2 - ((LENGTH(tags) / BARTAB_TAGSROWS) * BARTAB_TAGSPX)
- (i % (LENGTH(tags)/BARTAB_TAGSROWS)) + ((i % (LENGTH(tags) / BARTAB_TAGSROWS)) * BARTAB_TAGSPX)
),
( 2 + ((i / (LENGTH(tags)/BARTAB_TAGSROWS)) * BARTAB_TAGSPX)
- ((i / (LENGTH(tags)/BARTAB_TAGSROWS)))
),
BARTAB_TAGSPX, BARTAB_TAGSPX, (c->tags >> i) & 1, 0
);
}
}
}
void
bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg)
{
if (passx >= x && passx <= x + w)
arg->v = c;
}
void
bartabcalculate(
Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
) {
Client *c;
int
i, clientsnmaster = 0, clientsnstack = 0, clientsnfloating = 0,
masteractive = 0, fulllayout = 0,
x = offx, w, r, num = 0, den, tgactive;
for (i = 0; i < LENGTH(bartabmonfns); i++)
if (m ->lt[m->sellt]->arrange == bartabmonfns[i]) {
fulllayout = 1;
break;
}
for (i = 0, c = m->clients; c; c = c->next) {
if (!ISVISIBLE(c))
continue;
if (c->isfloating) {
clientsnfloating++;
continue;
}
if (m->sel == c)
masteractive = i < m->nmaster;
if (i < m->nmaster)
clientsnmaster++;
else
clientsnstack++;
i++;
}
if (!i)
return;
/* floating mode */
if (clientsnmaster + clientsnstack == 0 || !m->lt[m->sellt]->arrange) {
tgactive = 1;
num = tabw;
den = clientsnmaster + clientsnstack + clientsnfloating;
r = num % den;
w = num / den;
for (c = m->clients, i = 0; c; c = c->next) {
if (!ISVISIBLE(c))
continue;
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg);
x += w + (i < r ? 1 : 0);
i++;
}
/* monocle mode */
} else if (fulllayout || ((clientsnmaster == 0) ^ (clientsnstack == 0))) {
tgactive = 1;
num = tabw;
den = clientsnmaster + clientsnstack;
r = num % den;
w = num / den;
for (c = m->clients, i = 0; c; c = c->next) {
if (!ISVISIBLE(c) || c->isfloating)
continue;
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg);
x += w + (i < r ? 1 : 0);
i++;
}
/* tiled mode */
} else {
tgactive = masteractive;
num = clientsnstack ? tabw * m->mfact : tabw;
den = clientsnmaster;
r = num % den;
w = num / den;
for (c = m->clients, i = 0; c && i < m->nmaster; c = c->next) {
if (!ISVISIBLE(c) || c->isfloating)
continue;
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg);
x += w + (i < r ? 1 : 0);
i++;
}
tgactive = !tgactive;
num = tabw - num;
den = clientsnstack;
r = num % den;
w = num / den;
for (; c; c = c->next) {
if (!ISVISIBLE(c) || c->isfloating)
continue;
tabfn(m, c, passx, x, w + (i - m->nmaster < r ? 1 : 0), tgactive, arg);
x += w + (i - m->nmaster < r ? 1 : 0);
i++;
}
}
}

21
patch/bar_tabgroups.h Normal file
View File

@ -0,0 +1,21 @@
/* Bartabgroups properties, you can override these in your config.h if you want. */
#ifndef BARTAB_BORDERS
#define BARTAB_BORDERS 1 // 0 = off, 1 = on
#endif
#ifndef BARTAB_TAGSINDICATOR
#define BARTAB_TAGSINDICATOR 1 // 0 = off, 1 = on if >1 client/view tag, 2 = always on
#endif
#ifndef BARTAB_TAGSPX
#define BARTAB_TAGSPX 5 // # pixels for tag grid boxes
#endif
#ifndef BARTAB_TAGSROWS
#define BARTAB_TAGSROWS 3 // # rows in tag grid (9 tags, e.g. 3x3)
#endif
static int width_bartabgroups(Bar *bar, BarWidthArg *a);
static int draw_bartabgroups(Bar *bar, BarDrawArg *a);
static int click_bartabgroups(Bar *bar, Arg *arg, BarClickArg *a);
static void bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg);
static void bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg);
static void bartabcalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg);

View File

@ -0,0 +1,89 @@
void
hide(Client *c) {
Client *n;
if (!c || HIDDEN(c))
return;
Window w = c->win;
static XWindowAttributes ra, ca;
// more or less taken directly from blackbox's hide() function
XGrabServer(dpy);
XGetWindowAttributes(dpy, root, &ra);
XGetWindowAttributes(dpy, w, &ca);
// prevent UnmapNotify events
XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
XUnmapWindow(dpy, w);
setclientstate(c, IconicState);
XSelectInput(dpy, root, ra.your_event_mask);
XSelectInput(dpy, w, ca.your_event_mask);
XUngrabServer(dpy);
if (c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
for (n = c->snext; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
if (!n)
for (n = c->mon->stack; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
} else {
n = nexttiled(c);
if (!n)
n = prevtiled(c);
}
focus(n);
arrange(c->mon);
}
void
show(Client *c)
{
if (!c || !HIDDEN(c))
return;
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
arrange(c->mon);
}
void
togglewin(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (!c)
return;
if (c == selmon->sel)
hide(c);
else {
if (HIDDEN(c))
show(c);
focus(c);
restack(selmon);
}
}
Client *
prevtiled(Client *c)
{
Client *p, *i;
for (p = NULL, i = c->mon->clients; c && i != c; i = i->next)
if (ISVISIBLE(i) && !HIDDEN(i))
p = i;
return p;
}
void
showhideclient(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (!c)
c = selmon->sel;
if (!c)
return;
if (HIDDEN(c)) {
show(c);
restack(selmon);
} else {
hide(c);
}
}

View File

@ -0,0 +1,7 @@
#define HIDDEN(C) ((getstate(C->win) == IconicState))
static void hide(Client *c);
static void show(Client *c);
static void togglewin(const Arg *arg);
static Client * prevtiled(Client *c);
static void showhideclient(const Arg *arg);

View File

@ -41,6 +41,9 @@
#if BAR_STATUSCOLORS_PATCH
#include "bar_statuscolors.c"
#endif
#if BAR_TABGROUPS_PATCH
#include "bar_tabgroups.c"
#endif
#if BAR_TAGS_PATCH
#include "bar_tags.c"
#endif
@ -62,6 +65,9 @@
#if BAR_VTCOLORS_PATCH
#include "bar_vtcolors.c"
#endif
#if BAR_WINTITLEACTIONS_PATCH
#include "bar_wintitleactions.c"
#endif
/* Other patches */
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH

View File

@ -38,6 +38,9 @@
#if BAR_STATUSCMD_PATCH
#include "bar_statuscmd.h"
#endif
#if BAR_TABGROUPS_PATCH
#include "bar_tabgroups.h"
#endif
#if BAR_TAGS_PATCH
#include "bar_tags.h"
#endif
@ -59,6 +62,9 @@
#if BAR_VTCOLORS_PATCH
#include "bar_vtcolors.h"
#endif
#if BAR_WINTITLEACTIONS_PATCH
#include "bar_wintitleactions.h"
#endif
/* Other patches */
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH