index.md - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       index.md (2360B)
       ---
            1 Workspaces
            2 ==========
            3 Adds to dwm the functionality of remembering tagset, layout and mfact for a
            4 given number of workspaces. You can also define preconfigured workspaces.
            5 
            6 Code
            7 ----
            8 Insert this code before your keys definitions in config.h or in an included .c
            9 file:
           10 
           11         typedef struct Workspace Workspace;
           12         struct Workspace {
           13                 unsigned int tagset;
           14                 Layout *lt;
           15                 float mfact;
           16         };
           17         
           18         static Workspace workspaces[] = {
           19                 /* tagset                                                layout                        fact */
           20                 { (1 << 0),                                                &layouts[0],        0.55},
           21                 { (1 << 0) | (1<< 8),                        &layouts[0],        0.75},
           22                 { (1 << 0) | (1<< 1) | (1<< 8),        &layouts[1],        0},
           23                 { (1<< 8),                                                &layouts[2],        0},
           24         };
           25         
           26         static unsigned int ws = 0;
           27         
           28         static void
           29         setws(int nws) {
           30                 workspaces[ws].tagset = tagset[seltags];
           31                 workspaces[ws].lt = lt[sellt];
           32                 workspaces[ws].mfact = (workspaces[ws].lt == &layouts[0]) ? mfact : 0;
           33                 if(nws < LENGTH(workspaces))
           34                         ws = nws;
           35                 if(workspaces[ws].tagset) {
           36                         tagset[seltags] = workspaces[ws].tagset;
           37                         lt[sellt] = workspaces[ws].lt;
           38                         if(workspaces[ws].mfact != 0)
           39                                 mfact = workspaces[ws].mfact;
           40                         arrange();
           41                 }
           42         }
           43         
           44         static void
           45         prevws(const Arg *arg) {
           46                 setws((ws == 0) ? LENGTH(workspaces) - 1 : ws - 1);
           47         }
           48         
           49         static void
           50         nextws(const Arg *arg) {
           51                 setws((ws == LENGTH(workspaces) - 1) ? 0 : ws + 1);
           52         }
           53 
           54 And then, you can define keys:
           55 
           56                 { MODKEY,                       XK_Tab,    nextws,         {0} },
           57                 { MODKEY|ShiftMask,             XK_Tab,    prevws,         {0} },
           58 
           59 Or mouse buttons:
           60 
           61                 { ClkTagBar,            0,              Button4,        prevws,         {0} },
           62                 { ClkTagBar,            0,              Button5,        nextws,         {0} },
           63 
           64 Comments
           65 --------
           66 It is so easy to change the viewed tags, layout and mfact in dwm than having
           67 artifacts to remember them are not necessary, this patch is just an example of
           68 how it could be implemented, but it won't be updated for future releases.
           69 
           70 It should be easy to add to the workspaces the possibility to remember bar
           71 position too.
           72 
           73 It is not necessary to define all your workspaces (or any of them). You can
           74 perfectly do:
           75 
           76         static Workspace workspaces[16] = {
           77                 /* tagset                                                layout                        fact */
           78                 { (1 << 0),                                                &layouts[0],        0.55},
           79                 { (1 << 0) | (1<< 8),                        &layouts[0],        0.75},
           80         };
           81 
           82 or:
           83 
           84         static Workspace workspaces[16];
           85 
           86 Authors
           87 -------
           88 * [Jesus Galan (yiyus)](mailto:yiyu dot jgl at gmail>) (aug 30 21:41:42 CEST 2008)*