dwm-layoutmonitorrules-20211216-a786211d6cb7.diff - sites - public wiki content… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-layoutmonitorrules-20211216-a786211d6cb7.diff (2609B) | |
--- | |
1 diff --git config.def.h config.def.h | |
2 index a2ac963..9af5393 100644 | |
3 --- config.def.h | |
4 +++ config.def.h | |
5 @@ -37,6 +37,11 @@ static const int nmaster = 1; /* number of cli… | |
6 static const int resizehints = 1; /* 1 means respect size hints in t… | |
7 static const int lockfullscreen = 1; /* 1 will force focus on the fulls… | |
8 | |
9 +static const LayoutMonitorRule lm_rules[] = { | |
10 + /* >=w, >=h, req'd layout, new nmaster, new mfact */ | |
11 + { 3000, 0, 0, 2, 0.66 }, | |
12 +}; | |
13 + | |
14 static const Layout layouts[] = { | |
15 /* symbol arrange function */ | |
16 { "[]=", tile }, /* first entry is default */ | |
17 diff --git dwm.c dwm.c | |
18 index 5e4d494..d462775 100644 | |
19 --- dwm.c | |
20 +++ dwm.c | |
21 @@ -111,6 +111,13 @@ typedef struct { | |
22 void (*arrange)(Monitor *); | |
23 } Layout; | |
24 | |
25 +typedef struct { | |
26 + int mw, mh; /* >= matching */ | |
27 + int layout; /* only apply if this is the current layout, <0 … | |
28 + int nmaster; /* the new nmaster to apply */ | |
29 + float mfact; /* the new mfact to apply */ | |
30 +} LayoutMonitorRule; | |
31 + | |
32 struct Monitor { | |
33 char ltsymbol[16]; | |
34 float mfact; | |
35 @@ -142,6 +149,7 @@ typedef struct { | |
36 } Rule; | |
37 | |
38 /* function declarations */ | |
39 +static void applylmrules(void); | |
40 static void applyrules(Client *c); | |
41 static int applysizehints(Client *c, int *x, int *y, int *w, int *h, in… | |
42 static void arrange(Monitor *m); | |
43 @@ -276,6 +284,31 @@ static Window root, wmcheckwin; | |
44 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; | |
45 | |
46 /* function implementations */ | |
47 +void | |
48 +applylmrules(void) | |
49 +{ | |
50 + float new_mfact = mfact; | |
51 + int new_nmaster = nmaster; | |
52 + size_t i; | |
53 + | |
54 + for (i = 0; i < LENGTH(lm_rules); i++) { | |
55 + const LayoutMonitorRule *lmr = &lm_rules[i]; | |
56 + | |
57 + if (selmon->mw >= lmr->mw && | |
58 + selmon->mh >= lmr->mh && | |
59 + selmon->sellt == lmr->layout) | |
60 + { | |
61 + new_mfact = lmr->mfact; | |
62 + new_nmaster = lmr->nmaster; | |
63 + break; | |
64 + } | |
65 + } | |
66 + | |
67 + selmon->mfact = new_mfact; | |
68 + selmon->nmaster = new_nmaster; | |
69 + arrange(selmon); | |
70 +} | |
71 + | |
72 void | |
73 applyrules(Client *c) | |
74 { | |
75 @@ -572,6 +605,7 @@ configurenotify(XEvent *e) | |
76 } | |
77 focus(NULL); | |
78 arrange(NULL); | |
79 + applylmrules(); | |
80 } | |
81 } | |
82 } | |
83 @@ -1506,9 +1540,8 @@ setlayout(const Arg *arg) | |
84 if (arg && arg->v) | |
85 selmon->lt[selmon->sellt] = (Layout *)arg->v; | |
86 strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, si… | |
87 - if (selmon->sel) | |
88 - arrange(selmon); | |
89 - else | |
90 + applylmrules(); | |
91 + if (!selmon->sel) | |
92 drawbar(selmon); | |
93 } | |
94 | |
95 @@ -1595,6 +1628,7 @@ setup(void) | |
96 XSelectInput(dpy, root, wa.event_mask); | |
97 grabkeys(); | |
98 focus(NULL); | |
99 + applylmrules(); | |
100 } | |
101 | |
102 |