sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 8fbb6ab3d8e6434c456afc9bccd7b1eb1a14a60b
parent dbeb07de0104958fcbd6f51238c6092b54549779
Author: elbachir-one <bachiralfa@gmail.com>
Date:   Thu, 19 Sep 2024 07:24:26 +0100

[dwm][patch][autoswitch] Auto switch to monocle mode after opening N window

Diffstat:
Adwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240919-5096afab.diff | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/autoswitch/index.md | 21+++++++++++++++++++++
2 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240919-5096afab.diff b/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240919-5096afab.diff @@ -0,0 +1,141 @@ +From 5096afab5ccc582ba8c25f795e44a5e4c4761925 Mon Sep 17 00:00:00 2001 +From: elbachir-one <bachiralfa@gmail.com> +Date: Thu, 19 Sep 2024 05:28:42 +0100 +Subject: [PATCH] Automatically switch to monocle mode after opening N window + +--- + config.def.h | 7 +++--- + dwm.c | 62 ++++++++++++++++++++++++++++++++++++++-------------- + 2 files changed, 49 insertions(+), 20 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 9efa774..32fafc9 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ + static const unsigned int snap = 32; /* snap pixel */ + static const int showbar = 1; /* 0 means no bar */ + static const int topbar = 1; /* 0 means bottom bar */ ++static const int monoclemode = 4; /* automatically switch to monocle mode after opening 4 windows */ + static const char *fonts[] = { "monospace:size=10" }; + static const char dmenufont[] = "monospace:size=10"; + static const char col_gray1[] = "#222222"; +@@ -40,8 +41,8 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win + static const Layout layouts[] = { + /* symbol arrange function */ + { "[]=", tile }, /* first entry is default */ +- { "><>", NULL }, /* no layout function means floating behavior */ + { "[M]", monocle }, ++ { "><>", NULL }, /* no layout function means floating behavior */ + }; + + /* key definitions */ +@@ -75,8 +76,8 @@ static const Key keys[] = { + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, +- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, +- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY, XK_m, setlayout, {.v = &layouts[1]} }, ++ { MODKEY, XK_f, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, +diff --git a/dwm.c b/dwm.c +index 67c6b2b..f8add6d 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -227,6 +227,7 @@ static void updatetitle(Client *c); + static void updatewindowtype(Client *c); + static void updatewmhints(Client *c); + static void view(const Arg *arg); ++static int visibleclientcount(Monitor *m); + static Client *wintoclient(Window w); + static Monitor *wintomon(Window w); + static int xerror(Display *dpy, XErrorEvent *ee); +@@ -382,15 +383,25 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) + void + arrange(Monitor *m) + { +- if (m) +- showhide(m->stack); +- else for (m = mons; m; m = m->next) ++ if (!m) ++ for (m = mons; m; m = m->next) ++ showhide(m->stack); ++ else + showhide(m->stack); +- if (m) { +- arrangemon(m); +- restack(m); +- } else for (m = mons; m; m = m->next) +- arrangemon(m); ++ ++ for (Monitor *mon = (m ? m : mons); mon; mon = (m ? NULL : mon->next)) { ++ unsigned int n = visibleclientcount(mon); ++ ++ if (n >= monoclemode && mon->lt[mon->sellt]->arrange != monocle) ++ setlayout(&(Arg) {.v = &layouts[1]}); ++ ++ if (n < monoclemode && mon->lt[mon->sellt]->arrange == monocle) ++ setlayout(&(Arg) {.v = &layouts[0]}); ++ ++ arrangemon(mon); ++ if (!m) ++ restack(mon); ++ } + } + + void +@@ -1510,15 +1521,19 @@ setfullscreen(Client *c, int fullscreen) + void + setlayout(const Arg *arg) + { +- if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) +- selmon->sellt ^= 1; +- if (arg && arg->v) +- selmon->lt[selmon->sellt] = (Layout *)arg->v; +- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); +- if (selmon->sel) +- arrange(selmon); +- else +- drawbar(selmon); ++ if (!arg || !arg->v) ++ return; ++ ++ Layout *newlayout = (Layout *)arg->v; ++ if (newlayout != selmon->lt[selmon->sellt]) { ++ selmon->lt[selmon->sellt] = newlayout; ++ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol)); ++ selmon->ltsymbol[sizeof(selmon->ltsymbol) - 1] = '\0'; ++ if (selmon->sel) ++ arrange(selmon); ++ else ++ drawbar(selmon); ++ } + } + + /* arg > 1.0 will set mfact absolutely */ +@@ -2062,6 +2077,19 @@ view(const Arg *arg) + arrange(selmon); + } + ++int ++visibleclientcount(Monitor *m) ++{ ++ unsigned int count = 0; ++ Client *c; ++ for (c = m->clients; c; c = c->next) { ++ if (ISVISIBLE(c)) { ++ count++; ++ } ++ } ++ return count; ++} ++ + Client * + wintoclient(Window w) + { +-- +2.46.0 + diff --git a/dwm.suckless.org/patches/autoswitch/index.md b/dwm.suckless.org/patches/autoswitch/index.md @@ -0,0 +1,21 @@ +autoswitch +============ + +Description +----------- + +The **AutoSwitch** patch for the Dynamic Window Manager (dwm) +offers a convenient way to optimize your workflow. +It automatically switches between monocle and tiling modes after N windows are opened. +You can specify N in the configuration file, with 4 as the default, +but it can be customized to fit your preferences. + +This patch is inspired by a Reddit post [this post](https://www.reddit.com/r/suckless/comments/1fk6ogn/dwm_auto_monocle_mode/). + +Download +-------- +* [dwm-autoswitch-20240919-5096afab.diff](dwm-autoswitch-20240919-5096afab.diff) (2024-09-19) + +Author +------ +* [El Bachir](mailto:bachiralfa@gmail.com)