From b9259c32db13ddaa4be10eddf0b1cffd972398e7 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 3 Dec 2022 17:54:18 +0100 Subject: [PATCH] rename old title, add awesomebar title --- bar.h | 7 ++--- bar/items.c | 1 + bar/items.h | 1 + bar/title-basic.c | 31 +++++++++++++++++++++ bar/title-basic.h | 3 +++ bar/title.c | 69 ++++++++++++++++++++++++++++++++++++----------- bar/title.h | 6 ++--- 7 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 bar/title-basic.c create mode 100644 bar/title-basic.h diff --git a/bar.h b/bar.h index de1efe2..8362592 100644 --- a/bar.h +++ b/bar.h @@ -12,9 +12,10 @@ */ static const BarRule barrules[] = { /* monitor bar alignment widthfunc drawfunc clickfunc name */ - { -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" }, { -1, 0, BAR_ALIGN_LEFT, width_ltsymbol, draw_ltsymbol, click_ltsymbol, "layout" }, - //{ 'A', 0, BAR_ALIGN_RIGHT, width_status, draw_status, click_status, "status" }, + { -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" }, { 'A', 0, BAR_ALIGN_RIGHT, width_systray, draw_systray, click_systray, "systray" }, - { -1, 0, BAR_ALIGN_NONE, width_wintitle, draw_wintitle, click_wintitle, "wintitle" }, + { 'A', 0, BAR_ALIGN_RIGHT, width_status, draw_status, click_status, "status" }, + //{ -1, 0, BAR_ALIGN_NONE, width_title_basic, draw_title_basic, click_title_basic, "basic title" }, + { -1, 0, BAR_ALIGN_NONE, width_title, draw_title, click_title, "title" }, }; diff --git a/bar/items.c b/bar/items.c index 304f47b..22d2c2a 100644 --- a/bar/items.c +++ b/bar/items.c @@ -2,6 +2,7 @@ #include "tags.c" #include "layoutindicator.c" #include "statusbar.c" +#include "title-basic.c" #include "title.c" #if USESYSTRAY #include "systray.c" diff --git a/bar/items.h b/bar/items.h index 218aee5..762f9aa 100644 --- a/bar/items.h +++ b/bar/items.h @@ -2,6 +2,7 @@ #include "tags.h" #include "layoutindicator.h" #include "statusbar.h" +#include "title-basic.h" #include "title.h" #if USESYSTRAY #include "systray.h" diff --git a/bar/title-basic.c b/bar/title-basic.c new file mode 100644 index 0000000..efb11c6 --- /dev/null +++ b/bar/title-basic.c @@ -0,0 +1,31 @@ +int +width_title_basic(Bar *bar, BarWidthArg *a) +{ + return a->max_width; +} + +int +draw_title_basic(Bar *bar, BarDrawArg *a) +{ + int boxs = drw->font->h / 9; + int boxw = drw->font->h / 6 + 2; + int x = a->x, w = a->w; + Monitor *m = bar->mon; + + if (m->sel) { + drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); + drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False); + if (m->sel->isfloating) + drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); + } else { + drw_setscheme(drw, scheme[SchemeBar]); + drw_rect(drw, x, 0, w, bh, 1, 1); + } + return x + w; +} + +int +click_title_basic(Bar *bar, Arg *arg, BarClickArg *a) +{ + return ClkWinTitle; +} diff --git a/bar/title-basic.h b/bar/title-basic.h new file mode 100644 index 0000000..0684902 --- /dev/null +++ b/bar/title-basic.h @@ -0,0 +1,3 @@ +static int width_title_basic(Bar *bar, BarWidthArg *a); +static int draw_title_basic(Bar *bar, BarDrawArg *a); +static int click_title_basic(Bar *bar, Arg *arg, BarClickArg *a); diff --git a/bar/title.c b/bar/title.c index e5ad91b..c5d1e24 100644 --- a/bar/title.c +++ b/bar/title.c @@ -1,31 +1,68 @@ int -width_wintitle(Bar *bar, BarWidthArg *a) +width_title(Bar *bar, BarWidthArg *a) { return a->max_width; } int -draw_wintitle(Bar *bar, BarDrawArg *a) +draw_title(Bar *bar, BarDrawArg *a) { - int boxs = drw->font->h / 9; - int boxw = drw->font->h / 6 + 2; + int n = 0, scm, remainder = 0, tabw, padding; + unsigned int i; int x = a->x, w = a->w; - Monitor *m = bar->mon; - if (m->sel) { - drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False); - if (m->sel->isfloating) - drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); - } else { - drw_setscheme(drw, scheme[SchemeBar]); - drw_rect(drw, x, 0, w, bh, 1, 1); + Client *c; + for (c = bar->mon->clients; c; c = c->next) + if (ISVISIBLE(c)) + n++; + + if (n > 0) { + remainder = w % n; + tabw = w / n; + for (i = 0, c = bar->mon->clients; c; c = c->next, i++) { + if (!ISVISIBLE(c)) + continue; + if (bar->mon->sel == c) + scm = SchemeTitleSel; + else if (HIDDEN(c)) + scm = SchemeTitleHidden; + else + scm = SchemeTitleNorm; + + padding = lrpad / 2; + if (TEXTW(c->name) < tabw && titleposition) + padding = (tabw - TEXTW(c->name) + lrpad) / 2; + + drw_setscheme(drw, scheme[scm]); + drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, padding, c->name, 0, False); + x += tabw + (i < remainder ? 1 : 0); + } } - return x + w; + return a->x + a->w; } int -click_wintitle(Bar *bar, Arg *arg, BarClickArg *a) +click_title(Bar *bar, Arg *arg, BarClickArg *a) { - return ClkWinTitle; + int x = 0, n = 0; + Client *c; + + for (c = bar->mon->clients; c; c = c->next) + if (ISVISIBLE(c)) + n++; + + c = bar->mon->clients; + + do { + if (!c || !ISVISIBLE(c)) + continue; + else + x += (1.0 / (double)n) * a->rel_w; + } while (c && a->rel_x > x && (c = c->next)); + + if (c) { + arg->v = c; + return ClkWinTitle; + } + return -1; } diff --git a/bar/title.h b/bar/title.h index 266404c..f87c124 100644 --- a/bar/title.h +++ b/bar/title.h @@ -1,3 +1,3 @@ -static int width_wintitle(Bar *bar, BarWidthArg *a); -static int draw_wintitle(Bar *bar, BarDrawArg *a); -static int click_wintitle(Bar *bar, Arg *arg, BarClickArg *a); +static int width_title(Bar *bar, BarWidthArg *a); +static int draw_title(Bar *bar, BarDrawArg *a); +static int click_title(Bar *bar, Arg *arg, BarClickArg *a);