Merge pull request #3 from speediegq/main

Fix bugs, codebase improvements, misc
This commit is contained in:
Alexis Jhon Gaspar 2023-09-08 06:25:10 +08:00 committed by GitHub
commit da39686524
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 133 additions and 140 deletions

View file

@ -39,8 +39,8 @@ or
## Current bugs
- ~~Taskbar not working properly~~ (fixed in commit [e9015f2](https://github.com/Lucas-mother3/suckless-utils/commit/e9015f2d2a09ef66f1c9e188b277c89d23635195) & [7085f9](https://github.com/Lucas-mother3/suckless-utils/commit/7085f97d80fc203d6f54d0209af07007c0347880)). Thanks, [Speedie](https://speedie.gq)!
- Unhiding a hidden window (using the show/hide function) and if it's the only program running, crashes dwm
- Alt-tab crashes dwm altogther (idk man)
- ~~Unhiding a hidden window (using the show/hide function) and if it's the only program running, crashes dwm~~
- ~~Alt-tab crashes dwm altogther (idk man)~~
## Patching even further

3
dwm/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.o
dwm
config.h

View file

@ -53,7 +53,7 @@ static const int ulineall = 0; /* 1 to show underline on all tags, 0 for just
static const char ptagf[] = "[%s %s]"; /* format of a tag label */
static const char etagf[] = "[%s]"; /* format of an empty tag */
static const int lcaselbl = 0; /* 1 means make tag label lowercase */
static const int lcaselbl = 0; /* 1 means make tag label lowercase */
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
@ -77,9 +77,6 @@ static const int resizehints = 1; /* 1 means respect size hints in tiled resi
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int decorhints = 1; /* 1 means respect decoration hints */
#include "layouts.c"
#include "horizgrid.c"
#include "gaplessgrid.c"
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
@ -101,26 +98,15 @@ static const Layout layouts[] = {
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
/* replace the values with ones on col_color as an workaround */
static const char *dmenucmd[] = { "j4-dmenu-desktop", "--dmenu", "dmenu -fn 'Hack Nerd Font:size=14' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6 ", "--term", "st", NULL };
static const char *dmenualt[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_color1, "-nf", col_color3, "-sb", col_color5, "-sf", col_color4, "-g", "6", "-l", "6", NULL};
static const char *termcmd[] = { "st", NULL };
static const char *tabtermcmd[] = { "tabbed", "-r 2", "st", "-w", "''", NULL };
static const char *firefoxcmd[] = { "firefox", NULL };
static const char *thunarcmd[] = { "dolphin", NULL };
#include "shiftview.c"
static Key keys[] = {
/* modifier key function argument */
{ Mod4Mask, XK_s, spawn, {.v = dmenucmd } },
{ Mod4Mask|ShiftMask, XK_s, spawn, {.v = dmenualt } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY|ShiftMask, XK_t, spawn, {.v = tabtermcmd } },
{ MODKEY|ShiftMask, XK_i, spawn, {.v = firefoxcmd } },
{ Mod4Mask, XK_e, spawn, {.v = thunarcmd } },
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
{ Mod4Mask, XK_s, spawn, SHCMD("j4-dmenu-desktop --dmenu dmenu -fn 'Hack Nerd Font:size=14' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6 --term st") },
{ Mod4Mask|ShiftMask, XK_s, spawn, SHCMD("dmenu_run -fn 'Hack Nerd Font:size=14' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6") },
{ MODKEY|ShiftMask, XK_Return, spawn, SHCMD("st -e") },
{ MODKEY|ShiftMask, XK_t, spawn, SHCMD("tabbed -r 2 st -w ''") },
{ MODKEY|ShiftMask, XK_i, spawn, SHCMD("firefox") },
{ Mod4Mask, XK_e, spawn, SHCMD("dolphin") },
{ Mod4Mask, XK_Print, spawn, SHCMD("maim ~/Pictures/Screenshot_$(date +%s).png") },
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
{ MODKEY|ShiftMask, XK_n, togglefollow, {0} },
{ MODKEY, XK_j, focusstackvis, {.i = +1 } },
@ -156,9 +142,9 @@ static Key keys[] = {
{ MODKEY, XK_minus, setgaps, {.i = -1 } },
{ MODKEY, XK_equal, setgaps, {.i = +1 } },
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
{ MODKEY, XK_Tab, altTabStart, {0} },
{ MODKEY, XK_n, shiftview, { .i = +1 } },
{ MODKEY, XK_b, shiftview, { .i = -1 } },
{ MODKEY, XK_Tab, altTabStart, {0} },
{ MODKEY, XK_n, shiftview, { .i = +1 } },
{ MODKEY, XK_b, shiftview, { .i = -1 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
@ -175,13 +161,13 @@ static Key keys[] = {
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
/* click event mask button function argument */
{ ClkButton, 0, Button1, spawn, {.v = dmenucmd } },
{ ClkButton, 0, Button1, spawn, SHCMD("j4-dmenu-desktop --dmenu dmenu -fn 'Hack Nerd Font:size=14' -nb '#173f4f' -nf '#ffffff' -sb '#124f5f' -sf '#eeeeee' -g 6 -l 6 --term st") },
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkFollowSymbol, 0, Button1, togglefollow, {0} },
{ ClkWinTitle, 0, Button1, togglewin, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkStatusText, 0, Button2, spawn, SHCMD("st -e") },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },

BIN
dwm/drw.o

Binary file not shown.

BIN
dwm/dwm

Binary file not shown.

View file

@ -242,6 +242,7 @@ static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
static void show(const Arg *arg);
static void shiftview(const Arg *arg);
static void showwin(Client *c);
static void showhide(Client *c);
static void sigchld(int unused);
@ -321,6 +322,8 @@ static Visual *visual;
static int depth;
static Colormap cmap;
#include "layouts.c"
/* configuration, allows nested code to access above variables */
#include "config.h"
@ -1041,7 +1044,7 @@ focusstack(int inc, int hid)
if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
c = i;
}
if (c) {
focus(c);
@ -1084,9 +1087,9 @@ geticonprop(Window win, unsigned int *picw, unsigned int *pich)
unsigned long n, extra, *p = NULL;
Atom real;
if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
if (XGetWindowProperty(dpy, win, netatom[NetWMIcon], 0L, LONG_MAX, False, AnyPropertyType,
&real, &format, &n, &extra, (unsigned char **)&p) != Success)
return None;
return None;
if (n == 0 || format != 32) { XFree(p); return None; }
unsigned long *bstp = NULL;
@ -1261,7 +1264,7 @@ incnmaster(const Arg *arg)
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
selmon->pertag->nmasters[i+1] = selmon->nmaster;
if(selmon->pertag->curtag == 0)
{
selmon->pertag->nmasters[0] = selmon->nmaster;
@ -1842,13 +1845,13 @@ setlayout(const Arg *arg)
for(i=0; i<LENGTH(tags); ++i)
if(selmon->tagset[selmon->seltags] & 1<<i)
{
selmon->pertag->ltidxs[i+1][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->ltidxs[i+1][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->sellts[i+1] = selmon->sellt;
}
if(selmon->pertag->curtag == 0)
{
selmon->pertag->ltidxs[0][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->ltidxs[0][selmon->sellt] = selmon->lt[selmon->sellt];
selmon->pertag->sellts[0] = selmon->sellt;
}
@ -1979,6 +1982,21 @@ show(const Arg *arg)
showwin(selmon->sel);
}
void
shiftview(const Arg *arg) {
Arg shifted;
if(arg->i > 0) // left circular shift
shifted.ui = (selmon->tagset[selmon->seltags] << arg->i)
| (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
else // right circular shift
shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i)
| selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
view(&shifted);
}
void
showwin(Client *c)
{
@ -2019,8 +2037,6 @@ sigchld(int unused)
void
spawn(const Arg *arg)
{
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@ -2040,7 +2056,7 @@ altTab()
selmon->altTabN++;
if (selmon->altTabN >= selmon->nTabs)
selmon->altTabN = 0; /* reset altTabN */
focus(selmon->altsnext[selmon->altTabN]);
restack(selmon);
}
@ -2056,9 +2072,9 @@ altTabEnd()
if (selmon->isAlt == 0)
return;
/*
/*
* move all clients between 1st and choosen position,
* one down in stack and put choosen client to the first position
* one down in stack and put choosen client to the first position
* so they remain in right order for the next time that alt-tab is used
*/
if (selmon->nTabs > 1) {
@ -2103,7 +2119,9 @@ drawTab(int nwins, int first, Monitor *m)
Monitor *m = selmon;
XSetWindowAttributes wa = {
.override_redirect = True,
.background_pixmap = ParentRelative,
.background_pixel = 0,
.border_pixel = 0,
.colormap = cmap,
.event_mask = ButtonPressMask|ExposureMask
};
@ -2129,9 +2147,9 @@ drawTab(int nwins, int first, Monitor *m)
h = selmon->maxHTab;
/* XCreateWindow(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes); just reference */
m->tabwin = XCreateWindow(dpy, root, posX, posY, selmon->maxWTab, selmon->maxHTab, 2, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); /* create tabwin */
m->tabwin = XCreateWindow(dpy, root, posX, posY, selmon->maxWTab, selmon->maxHTab, 2, depth,
InputOutput, visual,
CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
XDefineCursor(dpy, m->tabwin, cursor[CurNormal]->cursor);
XMapRaised(dpy, m->tabwin);
@ -2224,7 +2242,7 @@ altTabStart(const Arg *arg)
}
}
c = selmon->sel;
c = selmon->sel;
altTabEnd(); /* end the alt-tab functionality */
/* XUngrabKeyboard(display, time); just a reference */
XUngrabKeyboard(dpy, CurrentTime); /* stop taking all input from keyboard */
@ -2394,17 +2412,20 @@ void
togglewin(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (!c)
c = selmon->sel;
if (!c)
return;
if (c == selmon->sel) {
hidewin(c);
focus(NULL);
arrange(c->mon);
if (HIDDEN(c)) {
showwin(c);
} else {
if (HIDDEN(c))
showwin(c);
focus(c);
restack(selmon);
hidewin(c);
}
restack(c->mon);
focus(c);
arrange(selmon);
}
void

BIN
dwm/dwm.o

Binary file not shown.

View file

@ -1,35 +0,0 @@
void
gaplessgrid(Monitor *m) {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
Client *c;
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
if(n == 0)
return;
/* grid dimensions */
for(cols = 0; cols <= n/2; cols++)
if(cols*cols >= n)
break;
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2;
rows = n/cols;
/* window geometries */
cw = cols ? m->ww / cols : m->ww;
cn = 0; /* current column number */
rn = 0; /* current row number */
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if(i/rows + 1 > cols - n%cols)
rows = n/cols + 1;
ch = rows ? m->wh / rows : m->wh;
cx = m->wx + cn*cw;
cy = m->wy + rn*ch;
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
rn++;
if(rn >= rows) {
rn = 0;
cn++;
}
}
}

View file

@ -1,32 +0,0 @@
void
horizgrid(Monitor *m) {
Client *c;
unsigned int n, i;
int w = 0;
int ntop, nbottom = 0;
/* Count windows */
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;
else if(n == 1) { /* Just fill the whole screen */
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, m->ww - (2*c->bw), m->wh - (2*c->bw), False);
} else if(n == 2) { /* Split vertically */
w = m->ww / 2;
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
c = nexttiled(c->next);
resize(c, m->wx + w, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
} else {
ntop = n / 2;
nbottom = n - ntop;
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if(i < ntop)
resize(c, m->wx + i * m->ww / ntop, m->wy, m->ww / ntop - (2*c->bw), m->wh / 2 - (2*c->bw), False);
else
resize(c, m->wx + (i - ntop) * m->ww / nbottom, m->wy + m->wh / 2, m->ww / nbottom - (2*c->bw), m->wh / 2 - (2*c->bw), False);
}
}
}

View file

@ -25,3 +25,72 @@ grid(Monitor *m) {
i++;
}
}
void
gaplessgrid(Monitor *m) {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
Client *c;
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
if(n == 0)
return;
/* grid dimensions */
for(cols = 0; cols <= n/2; cols++)
if(cols*cols >= n)
break;
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2;
rows = n/cols;
/* window geometries */
cw = cols ? m->ww / cols : m->ww;
cn = 0; /* current column number */
rn = 0; /* current row number */
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if(i/rows + 1 > cols - n%cols)
rows = n/cols + 1;
ch = rows ? m->wh / rows : m->wh;
cx = m->wx + cn*cw;
cy = m->wy + rn*ch;
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
rn++;
if(rn >= rows) {
rn = 0;
cn++;
}
}
}
void
horizgrid(Monitor *m) {
Client *c;
unsigned int n, i;
int w = 0;
int ntop, nbottom = 0;
/* Count windows */
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;
else if(n == 1) { /* Just fill the whole screen */
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, m->ww - (2*c->bw), m->wh - (2*c->bw), False);
} else if(n == 2) { /* Split vertically */
w = m->ww / 2;
c = nexttiled(m->clients);
resize(c, m->wx, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
c = nexttiled(c->next);
resize(c, m->wx + w, m->wy, w - (2*c->bw), m->wh - (2*c->bw), False);
} else {
ntop = n / 2;
nbottom = n - ntop;
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
if(i < ntop)
resize(c, m->wx + i * m->ww / ntop, m->wy, m->ww / ntop - (2*c->bw), m->wh / 2 - (2*c->bw), False);
else
resize(c, m->wx + (i - ntop) * m->ww / nbottom, m->wy + m->wh / 2, m->ww / nbottom - (2*c->bw), m->wh / 2 - (2*c->bw), False);
}
}
}

View file

@ -1,19 +0,0 @@
/** Function to shift the current view to the left/right
*
* @param: "arg->i" stores the number of tags to shift right (positive value)
* or left (negative value)
*/
void
shiftview(const Arg *arg) {
Arg shifted;
if(arg->i > 0) // left circular shift
shifted.ui = (selmon->tagset[selmon->seltags] << arg->i)
| (selmon->tagset[selmon->seltags] >> (LENGTH(tags) - arg->i));
else // right circular shift
shifted.ui = selmon->tagset[selmon->seltags] >> (- arg->i)
| selmon->tagset[selmon->seltags] << (LENGTH(tags) + arg->i);
view(&shifted);
}

Binary file not shown.