Patch to allow custom command for bar center text
This commit is contained in:
parent
56ddeea9aa
commit
0d3cf443d9
1
config.h
1
config.h
@ -1,6 +1,7 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
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 */
|
||||
|
63
dwm.c
63
dwm.c
@ -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);
|
||||
@ -899,20 +901,20 @@ void drawbar(Monitor *m) {
|
||||
}
|
||||
w = blw = TEXTW(m->ltsymbol);
|
||||
drw_setscheme(drw, scheme[SchemeTagsNorm]);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
|
||||
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 +1375,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,10 +1605,12 @@ 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) {
|
||||
unsigned int i, num;
|
||||
@ -2601,3 +2605,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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user