You are not logged in.

#1 2010-08-23 07:32:10

choogi
Member
Registered: 2009-10-06
Posts: 60

[Solved] DWM Cycle Between Layouts

Is there a DWM patch to let modkey+space cycle between layouts like in XMonad and Awesome?  I saw the thread here that suggests using cycle.c: https://bbs.archlinux.org/viewtopic.php … 18#p761018

However, cycle.c allows cycling across tags rather than layouts.  Does anyone else know how to enable this functionality?

Last edited by choogi (2010-08-30 17:20:01)

Offline

#2 2010-08-23 08:12:38

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] DWM Cycle Between Layouts

I don't think so - but if it is implemented in Awesome, it shouldn't be a big deal to do it in dwm.

If it is something you really want, you should also ask on the suckless ML or in #suckless.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2010-08-29 11:37:27

bob127
Member
Registered: 2010-08-28
Posts: 2
Website

Re: [Solved] DWM Cycle Between Layouts

This is how I did it:

void
nextlayout(const Arg *arg) {
    Layout *l;
    for (l=(Layout *)layouts;l != selmon->lt[selmon->sellt];l++);
    if (l->symbol && (l + 1)->symbol)
        setlayout(&((Arg) { .v = (l + 1) }));
    else
        setlayout(&((Arg) { .v = layouts }));
}

void
prevlayout(const Arg *arg) {
    Layout *l;
    for (l=(Layout *)layouts;l != selmon->lt[selmon->sellt];l++);
    if (l != layouts && (l - 1)->symbol)
        setlayout(&((Arg) { .v = (l - 1) }));
    else
        setlayout(&((Arg) { .v = &layouts[LENGTH(layouts) - 2] }));
}

and you should NULL terminate the layouts by adding:

{ .symbol = NULL,   .arrange = NULL    },

to your layouts in config.h

Offline

#4 2010-08-29 17:38:18

apefish
Member
From: Vancouver
Registered: 2010-07-13
Posts: 47

Re: [Solved] DWM Cycle Between Layouts

what version are you using? I'm using 5.8.2 and this works out of the box.

Offline

#5 2010-08-29 18:53:11

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: [Solved] DWM Cycle Between Layouts

apefish wrote:

what version are you using? I'm using 5.8.2 and this works out of the box.

I believe the out of box behaviour is to cylce between two of the three default layouts (float and tile).


thayer williams ~ cinderwick.ca

Offline

#6 2010-08-30 17:19:50

choogi
Member
Registered: 2009-10-06
Posts: 60

Re: [Solved] DWM Cycle Between Layouts

My default behavior in 5.8.2 toggled between the current layout and the last layout that I used.

bob127's functions works perfectly for me on 5.8.2.

Thanks all!

Offline

#7 2011-01-14 10:20:59

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [Solved] DWM Cycle Between Layouts

sorry to bump this thread, but i too want the same behaviour as choogi, but can't seem to get bob127's suggestion to work.

do i need to add this to dwm.c ?

void
nextlayout(const Arg *arg) {
    Layout *l;
    for (l=(Layout *)layouts;l != selmon->lt[selmon->sellt];l++);
    if (l->symbol && (l + 1)->symbol)
        setlayout(&((Arg) { .v = (l + 1) }));
    else
        setlayout(&((Arg) { .v = layouts }));
}

void
prevlayout(const Arg *arg) {
    Layout *l;
    for (l=(Layout *)layouts;l != selmon->lt[selmon->sellt];l++);
    if (l != layouts && (l - 1)->symbol)
        setlayout(&((Arg) { .v = (l - 1) }));
    else
        setlayout(&((Arg) { .v = &layouts[LENGTH(layouts) - 2] }));
}

and i didn't understand about this, either:

{ .symbol = NULL,   .arrange = NULL    },

sorry, i am new to c.

EDIT: so i just looked at bob127's configs at his website, and added the code accordingly to my configs, and now cyclelayouts works great.

Thanks bob, for the patch.

Last edited by x33a (2011-01-14 10:59:49)

Offline

#8 2013-08-02 15:35:10

defer
Member
From: Finland
Registered: 2013-06-25
Posts: 46
Website

Re: [Solved] DWM Cycle Between Layouts

Im also interested about cycle layouts. Wouldnt it be better approach to modify setlayout() to cycle through layouts? Ill see if i can do it. Any tips are welcome.

Offline

#9 2013-08-02 16:59:32

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [Solved] DWM Cycle Between Layouts

This thread is nearly 3 years old, with 2 years since the penultimate post. Normally this would be closed as a zombie but the thread is short and to the point. Adding a possibly better solution here makes sense.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#10 2013-08-02 17:28:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [Solved] DWM Cycle Between Layouts

I had a couple line function to do this when I used dwm.  I thought I posted it on these forums somewhere, but I can't find it now.  I scoured the dwm hackers thread, so it must have been somewhere else.

But here's the main idea recreated from memory and *not* tested.

int cycle_layout(const Arg *arg) {
    static unsigned short int layout = 0;
    if (layout++ > sizeof(layouts)/sizeof(layouts[0])) layout = 0;
    setlayout( &((Arg) {.v = &layouts[layout]}));
}
...
    { MODKEY,                       XK_Space,      cylce_layout,          {0} },

You could also replace layout++ with layout+=arg->i then pass a +1 or -1 .i parameter to cycle forward or back.  But that would require a second conditional in the function to check "if (layout < 0) layout = sizeof(layouts)/sizeof(layouts[0])".

Last edited by Trilby (2013-08-02 17:32:27)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB