-
. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I know you are not so much into C programming, but I'm sure you can appreciate the irony here. One of the core fundamentals of dwm is the desire to get to below 2000 SLOC (source lines of code), and sometimes corners are cut to make the code more "clean" but mostly to save on a few lines of code. The default keybinding to set the monocle layout, for example, is { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, This is passing the third row of the layouts array as a reference to the Everything that you are referring to above is a lot of effort, a lot of code, and a lot of wasted time for many many people trying to work around the elegant solution to save those few lines of code. dwmcThe dwmc patch is really just a shell script that uses the fsignal patch to communicate with dwm via the X root name. While you can pass integers and float values with the fsignal patch just fine, passing references is not that straightforward. Also, for that matter, we have no idea what the reference is. So a wrapper function void
setlayoutex(const Arg *arg)
{
setlayout(&((Arg) { .v = &layouts[arg->i] }));
} This allows the user to run $ dwmc setlayout # to toggle between current and previous layout
$ dwmc setlayoutex 2 # to change to monocle layout IPCWith the IPC patch you can pass integers, floats and references just fine when communicating with dwm. There is a command binding for IPCCOMMAND( setlayoutsafe, 1, {ARG_TYPE_PTR} ), The As an example in dwm if you set up a new keybinding to call To set the layout you first need the layout reference, which you can get as JSON through dwm-msg. $ dwm-msg get_layouts
[
{
"symbol": "[]=",
"address": 93853405567552
},
{
"symbol": "><>",
"address": 93853405567568
},
{
"symbol": "[M]",
"address": 93853405567584
}
] Great, now you just need to just get the address of the monocle layout for the next step. You can use bash, awk, perl, python or whatever you are more comfortable using in cases like this. Here we'll use jq. $ dwm-msg get_layouts | jq '.[2].address'
93853405567584 Now putting it all together we get: $ dwm-msg run_command setlayoutsafe $(dwm-msg get_layouts | jq '.[2].address')
{"result":"success"} You see, simple right. AlternativeFor those reading this and have particular interest - in principle it would be possible to pass integers to config.h { MODKEY, XK_t, setlayout, {0} },
{ MODKEY, XK_f, setlayout, {1} },
{ MODKEY, XK_m, setlayout, {2} },
{ MODKEY, XK_space, setlayout, {-1} },
...
{ ClkLtSymbol, 0, Button1, setlayout, {-1} },
{ ClkLtSymbol, 0, Button3, setlayout, {2} }, dwm.c void
setlayout(const Arg *arg)
{
if (arg->i < 0 || (arg->i >= 0 && arg->i < LENGTH(layouts) && selmon->lt[selmon->sellt] != &layouts[arg->i]))
selmon->sellt ^= 1;
if (arg->i >= 0 && arg->i < LENGTH(layouts))
selmon->lt[selmon->sellt] = &layouts[arg->i];
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel)
arrange(selmon);
else
drawbar(selmon);
} |
Beta Was this translation helpful? Give feedback.
I know you are not so much into C programming, but I'm sure you can appreciate the irony here.
One of the core fundamentals of dwm is the desire to get to below 2000 SLOC (source lines of code), and sometimes corners are cut to make the code more "clean" but mostly to save on a few lines of code.
The default keybinding to set the monocle layout, for example, is
This is passing the third row of the layouts array as a reference to the
setlayout
function. This could very well have just passed{.i = 2 }
, but that would have required maybe three extra lines of code insetlayout
.Everything that you…