Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Add layoutmenu patch
Browse files Browse the repository at this point in the history
  • Loading branch information
unclamped committed Nov 15, 2022
1 parent 9563bd9 commit bbace2a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 77,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 };
static const char *layoutmenu_cmd = "layoutmenu.sh";

static const Key keys[] = {
/* modifier key function argument */
Expand Down Expand Up @@ -130,7 131,7 @@ static const Key keys[] = {
static const Button buttons[] = {
/* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkLtSymbol, 0, Button3, layoutmenu, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
Expand Down
6 changes: 3 additions & 3 deletions config.def.h.orig
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 43,9 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
/* class instance title tags mask isfloating monitor */
{ "Gimp", NULL, NULL, 0, 1, -1 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
/* class instance title tags mask isfloating monitor ignoretransient */
{ "Gimp", NULL, NULL, 0, 1, -1, 0 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1, 0 },
};

/* layout(s) */
Expand Down
19 changes: 19 additions & 0 deletions dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 202,7 @@ static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void keyrelease(XEvent *e);
static void killclient(const Arg *arg);
static void layoutmenu(const Arg *arg);
static void manage(Window w, XWindowAttributes *wa);
static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
Expand Down Expand Up @@ -1094,6 1095,24 @@ killclient(const Arg *arg)
}
}

void
layoutmenu(const Arg *arg) {
FILE *p;
char c[3], *s;
int i;

if (!(p = popen(layoutmenu_cmd, "r")))
return;
s = fgets(c, sizeof(c), p);
pclose(p);

if (!s || *s == '\0' || c == '\0')
return;

i = atoi(c);
setlayout(&((Arg) { .v = &layouts[i] }));
}

void
manage(Window w, XWindowAttributes *wa)
{
Expand Down
11 changes: 7 additions & 4 deletions dwm.c.orig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 104,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, needresize;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, needresize, ignoretransient;
Client *next;
Client *snext;
Monitor *mon;
Expand Down Expand Up @@ -161,6 161,7 @@ typedef struct {
unsigned int tags;
int isfloating;
int monitor;
int ignoretransient;
} Rule;

/* function declarations */
Expand Down Expand Up @@ -338,6 339,7 @@ applyrules(Client *c)
&& (!r->instance || strstr(instance, r->instance)))
{
c->isfloating = r->isfloating;
c->ignoretransient = r->ignoretransient;
c->tags |= r->tags;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
Expand Down Expand Up @@ -1298,9 1300,10 @@ propertynotify(XEvent *e)
switch(ev->atom) {
default: break;
case XA_WM_TRANSIENT_FOR:
if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
(c->isfloating = (wintoclient(trans)) != NULL))
arrange(c->mon);
if (!c->ignoretransient && !c->isfloating &&
(XGetTransientForHint(dpy, c->win, &trans)) &&
(c->isfloating = (wintoclient(trans)) != NULL))
arrange(c->mon);
break;
case XA_WM_NORMAL_HINTS:
c->hintsvalid = 0;
Expand Down
7 changes: 7 additions & 0 deletions layoutmenu.sh
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
#!/bin/sh

cat <<EOF | xmenu
[]= Tiled Layout 0
><> Floating Layout 1
[M] Monocle Layout 2
EOF

0 comments on commit bbace2a

Please sign in to comment.