Compare commits

...

6 Commits

3 changed files with 85 additions and 37 deletions

View File

@ -46,6 +46,7 @@ static const unsigned int alphas[][3] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
static const Rule rules[] = {
/* xprop(1):

View File

@ -1,10 +1,12 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const char center_command[] = "/home/aselimov/bin/title_text.sh";
static const unsigned int borderpx = 2; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const unsigned int gappih = 15; /* horiz inner gap between windows */
static const unsigned int gappiv = 15; /* vert inner gap between windows */
static const int vertpadbar = 5; /* vertical padding for statusbar */
static const unsigned int gappoh =
10; /* horiz outer gap between windows and screen edge */
static const unsigned int gappov =
@ -17,26 +19,26 @@ static int smartgaps =
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = {
"FiraCode Nerd Font:size=11:antialias=true:autohint=true"};
"DepartureMono Nerd Font:size=13:antialias=true:autohint=true"};
static const char dmenufont[] =
"SauceCodePro Nerd Font:size=10:antialias=true:autohint=true";
static const char col_gray1[] = "#191919";
static const char col_gray2[] = "#3d3839";
static const char col_gray3[] = "#B4bdc3";
static const char col_gray4[] = "#8e8e8e";
static const char col_gray4[] = "#3d3839";
static const char col_cyan[] = "#6099C0";
static const char col_green[] = "#819b69";
static const char col_red[] = "#de6e76";
static const char col_yellow[] = "#d68c67";
static const char col_teal[] = "#8ec07c";
static const char col_purple[] = "#b16286";
static const unsigned int baralpha = 175;
static const unsigned int baralpha = OPAQUE;
static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = {col_gray3, col_gray1, "#000000"},
[SchemeSel] = {col_gray3, col_cyan, col_cyan},
[SchemeStatus] = {col_gray3, col_gray1, "#000000"},
[SchemeNorm] = {col_gray3, col_gray1, col_gray1},
[SchemeSel] = {col_gray3, col_cyan, col_gray3},
[SchemeStatus] = {col_gray3, col_gray1, col_gray1},
[SchemeTagsSel] = {col_gray3, col_gray1, col_gray1},
// Tagbar left unselected {text,background,not used but cannot be empty}
[SchemeTagsNorm] = {col_gray4, col_gray1, col_gray1},
@ -50,7 +52,7 @@ static const char *colors[][3] = {
static const unsigned int alphas[][3] = {
/* fg bg border */
[SchemeNorm] = {OPAQUE, baralpha, borderalpha},
[SchemeNorm] = {OPAQUE, baralpha, 0},
[SchemeSel] = {OPAQUE, baralpha, borderalpha},
[SchemeStatus] = {OPAQUE, baralpha, borderalpha},
[SchemeTagsSel] = {OPAQUE, baralpha, borderalpha},
@ -61,7 +63,8 @@ static const unsigned int alphas[][3] = {
[SchemeUrgent] = {OPAQUE, baralpha, borderalpha}};
/* tagging */
static const char *tags[] = {"󰭹", "", "󰈙", "󰏘", "", ""};
static const char *tags[] = {"", "", "", "", "", ""};
static const char *alttags[] = {"", "", "", "", "", ""};
static const Rule rules[] = {
/* xprop(1):
@ -77,6 +80,7 @@ static const Rule rules[] = {
{"Sxiv", NULL, NULL, 0, 1, 0, 1, -1},
{"matplotlib", NULL, NULL, 0, 1, 0, 1, -1},
{"Matplotlib", NULL, NULL, 0, 1, 0, 1, -1},
{"xcom2.exe", NULL, NULL, 0, 1, 0, 1, -1},
{NULL, NULL, "Figure 1", 0, 1, 0, 1, -1},
{NULL, NULL, "Figure 2", 0, 1, 0, 1, -1},
{NULL, NULL, "Figure 3", 0, 1, 0, 1, -1},
@ -93,6 +97,8 @@ static const Rule rules[] = {
//{ "" , NULL , NULL , 0 , 1 , 0 , 1 , -1 } ,
{"St", NULL, NULL, 0, 0, 1, 0, -1},
{"Firefox", NULL, NULL, 1 << 5, 0, 0, 0, -1},
{"Navigator", NULL, NULL, 1 << 5, 0, 0, 0, -1},
{"zen", NULL, NULL, 1 << 5, 0, 0, 0, -1},
{"dragon", NULL, NULL, 0, 1, 0, 1, -1},
{"Dragon", NULL, NULL, 0, 1, 0, 1, -1},
{"zbar", NULL, NULL, 0, 1, 0, 1, -1},
@ -102,7 +108,7 @@ static const Rule rules[] = {
};
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const int resizehints =
0; /* 1 means respect size hints in tiled resizals */
@ -112,10 +118,10 @@ static const int resizehints =
static const Layout layouts[] = {
/* symbol arrange function */
{"[]=", tile}, /* first entry is default */
{"><>", NULL}, /* no layout function means floating behavior */
{"[M]", monocle},
{"H[]", deck},
{"󰋁", tile}, /* first entry is default */
{"", NULL}, /* no layout function means floating behavior */
{"", monocle},
{"󰘹", deck},
};
/* key definitions */

87
dwm.c
View File

@ -51,6 +51,7 @@
#include "util.h"
/* macros */
#define MAX_LINE_LENGTH 1024
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
#define CLEANMASK(mask) \
(mask & ~(numlockmask | LockMask) & \
@ -198,6 +199,7 @@ typedef struct {
} Rule;
/* function declarations */
char *exec_command_last_line(const char *command);
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw,
int interact);
@ -550,7 +552,7 @@ void unswallow(Client *c) {
}
void buttonpress(XEvent *e) {
unsigned int i, x, click;
unsigned int i, x, click, occ;
Arg arg = {0};
Client *c;
Monitor *m;
@ -564,9 +566,13 @@ void buttonpress(XEvent *e) {
focus(NULL);
}
if (ev->window == selmon->barwin) {
i = x = 0;
i = x = occ = 0;
/* Bitmask of occupied tags */
for (c = m->clients; c; c = c->next)
occ |= c->tags;
do
x += TEXTW(tags[i]);
x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
@ -839,6 +845,7 @@ void drawbar(Monitor *m) {
int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
const char *tagtext;
char *ts = stext;
char *tp = stext;
int tx = 0;
@ -887,32 +894,29 @@ void drawbar(Monitor *m) {
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
w = TEXTW(tags[i]);
tagtext = occ & 1 << i ? alttags[i] : tags[i];
w = TEXTW(tagtext);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel
: SchemeTagsNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
if (occ & 1 << i)
drw_rect(drw, x + boxs, boxs, boxw, boxw,
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
urg & 1 << i);
drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i);
x += w;
}
w = blw = TEXTW(m->ltsymbol);
drw_setscheme(drw, scheme[SchemeTagsNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
drw_setscheme(drw, scheme[SchemeTagsSel]);
static char text[MAX_LINE_LENGTH];
strcpy(text, exec_command_last_line(center_command));
int center_length = TEXTW(text);
int center_x = (m->ww - center_length) / 2;
x = drw_text(drw, x, 0, center_x - x, bh, lrpad / 2, m->ltsymbol, 0);
x = center_x;
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
// drw_setscheme(drw, scheme[m == selmon ?
// SchemeInfoSel : SchemeInfoNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, " ", 0);
if (m->sel->isfloating)
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
} else {
drw_setscheme(drw, scheme[SchemeInfoNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1);
}
}
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
}
@ -1373,8 +1377,8 @@ void moveresize(const Arg *arg) {
&wAbs, &h, &hAbs) != 8)
return;
/* compute new window position; prevent window from be positioned outside the
* current monitor */
/* compute new window position; prevent window from be positioned outside
* the current monitor */
nw = c->w + w;
if (wAbs == 'W')
nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw;
@ -1603,9 +1607,11 @@ void run(void) {
XEvent ev;
/* main event loop */
XSync(dpy, False);
while (running && !XNextEvent(dpy, &ev))
int ticks = 0;
while (running && !XNextEvent(dpy, &ev)) {
if (handler[ev.type])
handler[ev.type](&ev); /* call handler */
}
}
void scan(void) {
@ -1781,7 +1787,7 @@ void setup(void) {
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
bh = drw->fonts->h + 2;
bh = drw->fonts->h + vertpadbar;
updategeom();
/* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
@ -2601,3 +2607,38 @@ void runAutostart(void) {
system("cd ~/.dwm; ./autostart_blocking.sh");
system("cd ~/.dwm; ./autostart.sh &");
}
char *exec_command_last_line(const char *command) {
static char last_line[MAX_LINE_LENGTH];
if (!command) {
return NULL;
}
FILE *pipe = popen(command, "r");
if (!pipe) {
return NULL;
}
char buffer[MAX_LINE_LENGTH];
int found_line = 0;
// Read all lines and keep track of the last non-empty one
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
// Remove trailing newline if present
size_t len = strlen(buffer);
if (len > 0 && buffer[len - 1] == '\n') {
buffer[len - 1] = '\0';
len--;
}
// Skip empty lines
if (len > 0) {
strcpy(last_line, buffer);
found_line = 1;
}
}
pclose(pipe);
return found_line ? last_line : NULL;
}