Compare commits

...

3 Commits

Author SHA1 Message Date
Jakub
461498821f Replace "no border patch" with remove border patch
This reverts commit e6862bb55b.
2024-05-23 19:20:03 -04:00
Jakub
ede27072ae exit menu patch 2024-05-22 16:27:14 -04:00
2b289702da Add launchers patch to bottom bar
- removed left extra status
- removed/renamed some l/r specific variables
2024-05-22 16:23:34 -04:00
7 changed files with 378 additions and 94 deletions

View File

@ -44,6 +44,15 @@ static const char *const autostart[] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
/* launcher commands (They must be NULL terminated) */
static const char* browser[] = { "firefox", "search.brave.com", NULL };
static const char* terminal[] = { "st", NULL };
static const Launcher launchers[] = {
{ terminal, "st" },
{ browser, "firefox" }
};
static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
static const unsigned int ulinestroke = 2; /* thickness / height of the underline */
static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */
@ -95,7 +104,7 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
#include "exitdwm.c"
static const Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@ -138,8 +147,8 @@ static const Key keys[] = {
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
{ MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} },
{ MODKEY|ShiftMask, XK_e, exitdwm, {0} }
};
/* button definitions */

82
dwm.c
View File

@ -163,6 +163,12 @@ typedef struct {
int monitor;
} Rule;
typedef struct {
const char** command;
const char* name;
} Launcher;
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@ -239,7 +245,6 @@ static void showwin(Client *c);
static void showhide(Client *c);
static void sighup(int unused);
static void sigterm(int unused);
static int solitary(Client *c);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
@ -286,8 +291,7 @@ static pid_t winpid(Window w);
static Client *prevzoom = NULL;
static const char broken[] = "broken";
static char stext[256];
static char estextl[256];
static char estextr[256];
static char estext[256];
static char wfsymbol[2];
static int screen;
static int sw, sh; /* X display screen geometry width, height */
@ -619,6 +623,18 @@ buttonpress(XEvent *e)
arg.v = c;
}
}
} else if (ev->window == selmon->extrabarwin) {
i = x = 0;
for(i = 0; i < LENGTH(launchers); i++) {
x += TEXTW(launchers[i].name);
if (ev->x < x) {
Arg a;
a.v = launchers[i].command;
spawn(&a);
return;
} else if (ev->x > selmon->ww - TEXTW(estext))
click = ClkStatusText;
}
} else if ((c = wintoclient(ev->window))) {
focus(c);
restack(selmon);
@ -991,10 +1007,17 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]);
/* clear default bar draw buffer by drawing a blank rectangle */
drw_rect(drw, 0, 0, m->ww, bh, 1, 1);
etwr = TEXTW(estextr) - lrpad + 2; /* 2px right padding */
drw_text(drw, m->ww - etwr - 2 * sp, 0, etwr, bh, 0, estextr, 0);
etwl = TEXTW(estextl);
drw_text(drw, 0, 0, etwl + 2 * sp, bh, 0, estextl, 0);
w = TEXTW(estext) - lrpad + 2; /* 2px right padding */
drw_text(drw, m->ww - w - 2 * sp, 0, w, bh, 0, estext, 0);
x = 0;
for (i = 0; i < LENGTH(launchers); i++)
{
w = TEXTW(launchers[i].name);
drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, 0 );
x += w;
}
drw_map(drw, m->extrabarwin, 0, 0, m->ww, bh);
}
@ -1069,11 +1092,7 @@ focus(Client *c)
detachstack(c);
attachstack(c);
grabbuttons(c, 1);
/* Avoid flickering when another client appears and the border
* is restored */
if (!solitary(c)) {
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
}
setfocus(c);
} else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
@ -1727,17 +1746,26 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
unsigned int n;
Client *nbc;
c->oldx = c->x; c->x = wc.x = x;
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
if (solitary(c)) {
for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
} else {
if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
wc.border_width = 0;
c->w = wc.width += c->bw * 2;
c->h = wc.height += c->bw * 2;
wc.border_width = 0;
}
}
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@ -2240,15 +2268,6 @@ sigterm(int unused)
quit(&a);
}
int
solitary(Client *c)
{
return ((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
|| &monocle == c->mon->lt[c->mon->sellt]->arrange)
&& !c->isfullscreen && !c->isfloating
&& NULL != c->mon->lt[c->mon->sellt]->arrange;
}
void
spawn(const Arg *arg)
{
@ -2755,21 +2774,14 @@ updatestatus(void)
char text[768];
if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
strcpy(stext, "dwm-"VERSION);
estextl[0] = '\0';
estextr[0] = '\0';
estext[0] = '\0';
} else {
char *l = strchr(text, statussep);
if (l) {
*l = '\0'; l++;
strncpy(estextl, l, sizeof(estextl) - 1);
char *s = strchr(text, statussep);
if (s) {
*s = '\0'; s++;
strncpy(estext, s, sizeof(estext) - 1);
} else
estextl[0] = '\0';
char *r = strchr(estextl, statussep);
if (r) {
*r = '\0'; r++;
strncpy(estextr, r, sizeof(estextr) - 1);
} else
estextr[0] = '\0';
estext[0] = 'Christ is king';
strncpy(stext, text, sizeof(stext) - 1);
}
for(m = mons; m; m = m->next)

87
exitdwm.c Normal file
View File

@ -0,0 +1,87 @@
# include <stdio.h>
# include <string.h>
void exitdwm ()
{
# if \
defined S_LOCK || \
defined S_RESTART_DWM || \
defined S_OFFSCREEN || \
defined S_EXIT || \
defined S_REBOOT || \
defined S_SHUTDOWN || \
defined S_LOCK_ICON || \
defined S_RESTART_DWM_ICON || \
defined S_OFFSCREEN_ICON || \
defined S_EXIT_ICON || \
defined S_REBOOT_ICON || \
defined S_SHUTDOWN_ICON || \
defined S_FORMAT || \
defined S_FORMAT_CLEAR
# error (conflicting macro names)
# endif
# define S_LOCK "Lock"
# define S_RESTART_DWM "restart Dwm"
# define S_OFFSCREEN "Off-screen"
# define S_EXIT "Exit"
# define S_REBOOT "Reboot"
# define S_SHUTDOWN "Shutdown"
# define S_LOCK_ICON "\uf023" // <= FontAwesome icons
# define S_RESTART_DWM_ICON "\uf01e"
# define S_OFFSCREEN_ICON "\uf108"
# define S_EXIT_ICON "\uf2f5"
# define S_REBOOT_ICON "\uf021"
# define S_SHUTDOWN_ICON "\uf011"
# define S_FORMAT(ACTION) S_##ACTION##_ICON " " S_##ACTION
# define S_FORMAT_CLEAR "sed 's/^..//'"
FILE * exit_menu = popen (
"echo \""
S_FORMAT (LOCK) "\n"
S_FORMAT (RESTART_DWM) "\n"
S_FORMAT (OFFSCREEN) "\n"
S_FORMAT (EXIT) "\n"
S_FORMAT (REBOOT) "\n"
S_FORMAT (SHUTDOWN)
"\" | dmenu -p exit: | " S_FORMAT_CLEAR
,
"r"
);
char exit_action [16];
if (
exit_menu == NULL ||
fscanf (exit_menu, "%15[a-zA-Z -]", exit_action) == EOF
) {
fputs ("Error. Failure in exit_dwm.", stderr);
goto close_streams;
}
if (strcmp (exit_action, S_LOCK) == 0) system ("slock & sleep .5; xset dpms force off");
else if (strcmp (exit_action, S_RESTART_DWM) == 0) quit (& (const Arg) {1});
else if (strcmp (exit_action, S_OFFSCREEN) == 0) system ("sleep .5; xset dpms force off");
else if (strcmp (exit_action, S_EXIT) == 0) quit (& (const Arg) {0});
else if (strcmp (exit_action, S_REBOOT) == 0) system ("systemctl reboot");
else if (strcmp (exit_action, S_SHUTDOWN) == 0) system ("systemctl poweroff -i");
close_streams:
pclose (exit_menu);
# undef S_LOCK
# undef S_RESTART_DWM
# undef S_OFFSCREEN
# undef S_EXIT
# undef S_REBOOT
# undef S_SHUTDOWN
# undef S_LOCK_ICON
# undef S_RESTART_DWM_ICON
# undef S_OFFSCREEN_ICON
# undef S_EXIT_ICON
# undef S_REBOOT_ICON
# undef S_SHUTDOWN_ICON
# undef S_FORMAT
# undef S_FORMAT_CLEAR
}

View File

@ -1,53 +0,0 @@
diff --git dwm.c dwm.c
index 0fc328a..4a767bd 100644
--- dwm.c
+++ dwm.c
@@ -206,6 +206,7 @@ static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(int unused);
+static int solitary(Client *c);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
@@ -802,7 +803,11 @@ focus(Client *c)
detachstack(c);
attachstack(c);
grabbuttons(c, 1);
- XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
+ /* Avoid flickering when another client appears and the border
+ * is restored */
+ if (!solitary(c)) {
+ XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
+ }
setfocus(c);
} else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
@@ -1288,6 +1293,11 @@ resizeclient(Client *c, int x, int y, int w, int h)
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
+ if (solitary(c)) {
+ c->w = wc.width += c->bw * 2;
+ c->h = wc.height += c->bw * 2;
+ wc.border_width = 0;
+ }
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@@ -1642,6 +1652,15 @@ sigchld(int unused)
while (0 < waitpid(-1, NULL, WNOHANG));
}
+int
+solitary(Client *c)
+{
+ return ((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
+ || &monocle == c->mon->lt[c->mon->sellt]->arrange)
+ && !c->isfullscreen && !c->isfloating
+ && NULL != c->mon->lt[c->mon->sellt]->arrange;
+}
+
void
spawn(const Arg *arg)
{

View File

@ -0,0 +1,31 @@
diff --git a/dwm.c b/dwm.c
index 5646a5c..27e29df 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1283,12 +1283,26 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
+ unsigned int n;
+ Client *nbc;
c->oldx = c->x; c->x = wc.x = x;
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
+
+ for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
+
+ if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
+ } else {
+ if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
+ wc.border_width = 0;
+ c->w = wc.width += c->bw * 2;
+ c->h = wc.height += c->bw * 2;
+ }
+ }
+
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);

View File

@ -0,0 +1,114 @@
diff --git a/config.def.h b/config.def.h
index a2ac963..92a6a81 100644
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
+#include "exitdwm.c"
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@@ -94,7 +95,7 @@ static Key keys[] = {
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
- { MODKEY|ShiftMask, XK_q, quit, {0} },
+ { MODKEY|ShiftMask, XK_e, exitdwm, {0} },
};
/* button definitions */
diff --git a/exitdwm.c b/exitdwm.c
new file mode 100644
index 0000000..74c514f
--- /dev/null
+++ b/exitdwm.c
@@ -0,0 +1,87 @@
+# include <stdio.h>
+# include <string.h>
+
+void exitdwm ()
+{
+# if \
+ defined S_LOCK || \
+ defined S_RESTART_DWM || \
+ defined S_OFFSCREEN || \
+ defined S_EXIT || \
+ defined S_REBOOT || \
+ defined S_SHUTDOWN || \
+ defined S_LOCK_ICON || \
+ defined S_RESTART_DWM_ICON || \
+ defined S_OFFSCREEN_ICON || \
+ defined S_EXIT_ICON || \
+ defined S_REBOOT_ICON || \
+ defined S_SHUTDOWN_ICON || \
+ defined S_FORMAT || \
+ defined S_FORMAT_CLEAR
+# error (conflicting macro names)
+# endif
+
+# define S_LOCK "Lock"
+# define S_RESTART_DWM "restart Dwm"
+# define S_OFFSCREEN "Off-screen"
+# define S_EXIT "Exit"
+# define S_REBOOT "Reboot"
+# define S_SHUTDOWN "Shutdown"
+# define S_LOCK_ICON "\uf023" // <= FontAwesome icons
+# define S_RESTART_DWM_ICON "\uf01e"
+# define S_OFFSCREEN_ICON "\uf108"
+# define S_EXIT_ICON "\uf2f5"
+# define S_REBOOT_ICON "\uf021"
+# define S_SHUTDOWN_ICON "\uf011"
+
+# define S_FORMAT(ACTION) S_##ACTION##_ICON " " S_##ACTION
+# define S_FORMAT_CLEAR "sed 's/^..//'"
+
+ FILE * exit_menu = popen (
+ "echo \""
+ S_FORMAT (LOCK) "\n"
+ S_FORMAT (RESTART_DWM) "\n"
+ S_FORMAT (OFFSCREEN) "\n"
+ S_FORMAT (EXIT) "\n"
+ S_FORMAT (REBOOT) "\n"
+ S_FORMAT (SHUTDOWN)
+ "\" | dmenu -p exit: | " S_FORMAT_CLEAR
+ ,
+ "r"
+ );
+
+ char exit_action [16];
+
+ if (
+ exit_menu == NULL ||
+ fscanf (exit_menu, "%15[a-zA-Z -]", exit_action) == EOF
+ ) {
+ fputs ("Error. Failure in exit_dwm.", stderr);
+ goto close_streams;
+ }
+
+ if (strcmp (exit_action, S_LOCK) == 0) system ("slock & sleep .5; xset dpms force off");
+ else if (strcmp (exit_action, S_RESTART_DWM) == 0) quit (& (const Arg) {1});
+ else if (strcmp (exit_action, S_OFFSCREEN) == 0) system ("sleep .5; xset dpms force off");
+ else if (strcmp (exit_action, S_EXIT) == 0) quit (& (const Arg) {0});
+ else if (strcmp (exit_action, S_REBOOT) == 0) system ("systemctl reboot");
+ else if (strcmp (exit_action, S_SHUTDOWN) == 0) system ("systemctl poweroff -i");
+
+close_streams:
+ pclose (exit_menu);
+
+# undef S_LOCK
+# undef S_RESTART_DWM
+# undef S_OFFSCREEN
+# undef S_EXIT
+# undef S_REBOOT
+# undef S_SHUTDOWN
+# undef S_LOCK_ICON
+# undef S_RESTART_DWM_ICON
+# undef S_OFFSCREEN_ICON
+# undef S_EXIT_ICON
+# undef S_REBOOT_ICON
+# undef S_SHUTDOWN_ICON
+# undef S_FORMAT
+# undef S_FORMAT_CLEAR
+}

View File

@ -0,0 +1,84 @@
From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001
From: Adham Zahran <adhamzahranfms@gmail.com>
Date: Wed, 27 May 2020 18:07:57 +0200
Subject: [PATCH] Top bar now has buttons that launches programs
---
config.def.h | 8 ++++++++
dwm.c | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1c0b587..9231cd5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -21,6 +21,14 @@ static const char *colors[][3] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+/* launcher commands (They must be NULL terminated) */
+static const char* surf[] = { "surf", "duckduckgo.com", NULL };
+
+static const Launcher launchers[] = {
+ /* command name to display */
+ { surf, "surf" },
+};
+
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
diff --git a/dwm.c b/dwm.c
index 9fd0286..79e7e20 100644
--- a/dwm.c
+++ b/dwm.c
@@ -141,6 +141,11 @@ typedef struct {
int monitor;
} Rule;
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -438,9 +443,26 @@ buttonpress(XEvent *e)
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
- } else if (ev->x < x + blw)
+ goto execute_handler;
+ } else if (ev->x < x + blw) {
click = ClkLtSymbol;
- else if (ev->x > selmon->ww - TEXTW(stext))
+ goto execute_handler;
+ }
+
+ if (ev->x > selmon->ww - TEXTW(stext))
click = ClkStatusText;
else
click = ClkWinTitle;
@@ -450,6 +472,9 @@ buttonpress(XEvent *e)
XAllowEvents(dpy, ReplayPointer, CurrentTime);
click = ClkClientWin;
}
+
+execute_handler:
+
for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
@@ -728,6 +753,13 @@ drawbar(Monitor *m)
w = blw = TEXTW(m->ltsymbol);
drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+
+ for (i = 0; i < LENGTH(launchers); i++)
+ {
+ w = TEXTW(launchers[i].name);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, urg & 1 << i);
+ x += w;
+ }
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
--
2.17.1