diff --git a/docs/src/configuration.md b/docs/src/configuration.md index b23da4a7c..bbb619886 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -248,6 +248,50 @@ Eww then reads the provided value and renders the resulting widget. Whenever it Note that this is not all that efficient. Make sure to only use `literal` when necessary! +## Dynamically generated windows with arguments and ids + +In some cases you may want to use the same window configuration for multiple widgets, e.g. for multiple windows. This is where arugments and ids come in. + +Firstly let us start off with ids. An id can be specified in the `open` command with `--id`, by default the id will be set to the name of the window configuration. These ids allow you to spawn multiple of the same windows. So for example you can do: + +```bash +eww open my_bar --screen 0 --id primary +eww open my_bar --screen 1 --id secondary +``` + +However you may want to have slight changes for each of these bars, e.g. spawning other windows on the same monitor. This is where the arguments come in. + +Defining arguments in a window is the exact same as in a widget so you can have: + +```lisp +(defwindow my_bar [arg1 ?arg2] + :geometry (geometry + :x "0%" + :y "6px" + :width "100%" + :height "30px" + :anchor "top center") + :stacking "bg" + :windowtype "dock" + :reserve (struts :distance "50px" :side "top") + ...) +``` + +Here we have two arguments, `arg1` and `arg2` (an optional parameter). + +Once we have these parameters, when opening a new window, we must specify them (unless they are required, like `arg2`), but how? Well, we use the `--args` option when running the `open` command: + +```bash +eww open my_bar --id primary --args arg1=some_value,arg2=another_value +``` + +You may notice that this is the same layout to set values with `update` and you'd be correct. + +So, now you know the basics, I shall introduce you to some of these "special" parameters, which are set slightly differently. However these can all be overridden by the `--args` option. + +- `id` - If `id` is included in the argument list, it will be set to the id specified by `--id` or will be set to the name of the config. This can be used when closing the current window through eww commands. +- `screen` - If `screen` is specified it will be set to the value given by `--screen`, so you can use this in other widgets to access screen specific information. + ## Generating a list of widgets from JSON using `for` If you want to display a list of values, you can use the `for`-Element to fill a container with a list of elements generated from a JSON-array.