Code Monkey home page Code Monkey logo

dwm's Issues

How to automatically reset to default layout for a tag once it is empty?

Hi Arie,

I have searched on internet and find this post: https://www.reddit.com/r/suckless/comments/s2ch3f/dwm_how_to_reset_to_tiled_layout_when_all_windows/

diff --git a/dwm.c b/dwm.c
index a96f33c..787cd2a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -189,6 +189,7 @@ static void pop(Client *);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
 static Monitor *recttomon(int x, int y, int w, int h);
+static void resetlayout(const Arg *arg);
 static void resize(Client *c, int x, int y, int w, int h, int interact);
 static void resizeclient(Client *c, int x, int y, int w, int h);
 static void resizemouse(const Arg *arg);
@@ -1269,6 +1270,16 @@ recttomon(int x, int y, int w, int h)
    return r;
 }
 
+void
+resetlayout(const Arg *arg)
+{
+   Arg default_layout = {.v = &layouts[0]};
+   Arg default_mfact = {.f = mfact + 1};
+
+   setlayout(&default_layout);
+   setmfact(&default_mfact);
+}
+
 void
 resize(Client *c, int x, int y, int w, int h, int interact)
 {
@@ -1788,6 +1799,8 @@ unmanage(Client *c, int destroyed)
    focus(NULL);
    updateclientlist();
    arrange(m);
+   if (!(nexttiled(m->clients)))
+       resetlayout(NULL);
 }
 
 void

Thanks for your instruction! But I think it seems not a good way. Beacuse It will check all clients in a monitor instead of a specific tag. And this might be dangerous, beacuse we have focus(NULL); updateclientlist(); arrange(m); in the above of resetlayout(), the current focus tag might be already changed. Then it calls resetlayout(), the setlayout() subfunction (in resetlayout()) calls arrange() if the selmon->sel is not empty. So it might cause potential duplicate arrange() call.

So I wonder if there has a safe way to achieve the goal? Thanks ! :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.