From 50c485a8cf79d51ec8adb11d3eb2bfb605d0247d Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 18 Nov 2022 22:07:09 +0100 Subject: [PATCH] Order sway configuration file --- tasks/main.yml | 11 ++++++----- templates/10-input.config.j2 | 9 +++++++++ templates/20-output.config.j2 | 9 +++++++++ templates/30-theme.config.j2 | 11 +++++++++++ templates/40-workspaces.config.j2 | 9 +++++++++ templates/50-keybindings.config.j2 | 25 +++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 templates/10-input.config.j2 create mode 100644 templates/20-output.config.j2 create mode 100644 templates/30-theme.config.j2 create mode 100644 templates/40-workspaces.config.j2 create mode 100644 templates/50-keybindings.config.j2 diff --git a/tasks/main.yml b/tasks/main.yml index 7ea7506..8d362cb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,7 +14,7 @@ - name: Create Sway config dirs ansible.builtin.file: - path: '{{ ansible_user_dir ~ "/.config/sway/test.d" }}' + path: '{{ ansible_user_dir ~ "/.config/sway/conf.d" }}' state: directory mode: 0750 owner: '{{ ansible_user_uid }}' @@ -38,8 +38,9 @@ validate: >- sh -c "if sway --config %s --validate 2>&1 | grep -q sway/config.c; then >&2 echo \"Error validating sway configuration\"; exit 1; else exit 0; fi" loop: - - keybindings - - theme - - output - - input + - 10-input + - 20-output + - 30-theme + - 40-workspaces + - 50-keybindings any_errors_fatal: true diff --git a/templates/10-input.config.j2 b/templates/10-input.config.j2 new file mode 100644 index 0000000..8e803f3 --- /dev/null +++ b/templates/10-input.config.j2 @@ -0,0 +1,9 @@ +{% if sway_inputs is defined %} +{% for input in sway_inputs %} +input {{ input.name }} { + {% for option in input.options %} + {{ option.option }} {{ option.value }} + {% endfor %} +} +{% endfor %} +{% endif %} diff --git a/templates/20-output.config.j2 b/templates/20-output.config.j2 new file mode 100644 index 0000000..321be65 --- /dev/null +++ b/templates/20-output.config.j2 @@ -0,0 +1,9 @@ +{% if sway_outputs %} +{% for output in sway_outputs %} +output {{ output.name ~ " " }} +{%- for option in output.options %} +{{ option.option }} {{ option.value }} +{% endfor %} + +{% endfor %} +{% endif %} diff --git a/templates/30-theme.config.j2 b/templates/30-theme.config.j2 new file mode 100644 index 0000000..9752822 --- /dev/null +++ b/templates/30-theme.config.j2 @@ -0,0 +1,11 @@ +{% for k,v in sway_theme_parameters.items() %} +{{ k }} {{ v }} +{% endfor %} + +{% for client, c in sway_theme_colors.items() %} +client.{{ client }} {{ c.border }} {{ c.backgound}} {{ c.text }} +{%- if c.indicator is defined %} {{ c.indicator }} +{%- if c.child_border is defined %} {{ c.child_border }}{% endif %} +{% endif %} + +{% endfor %} diff --git a/templates/40-workspaces.config.j2 b/templates/40-workspaces.config.j2 new file mode 100644 index 0000000..1f79ae2 --- /dev/null +++ b/templates/40-workspaces.config.j2 @@ -0,0 +1,9 @@ +{% for k,v in sway_workspaces.items() %} +set $ws{{ k }} {{ v }} +{% endfor %} + +{% if sway_rules is defined %} +{% for i in rules %} +{{ i.verb }} {{ i.query }} {% if i.verb == 'assign' %}$ws{% endif %}{{ i.action }} +{% endfor %} +{% endif %} diff --git a/templates/50-keybindings.config.j2 b/templates/50-keybindings.config.j2 new file mode 100644 index 0000000..4d79fa4 --- /dev/null +++ b/templates/50-keybindings.config.j2 @@ -0,0 +1,25 @@ +set $mod Mod4 +set $left h +set $down j +set $up k +set $right l + +# Dynamic workspace keybindings +{% for k,v in sway_workspaces.items() %} +bindsym $mod+{{ k }} workspace $ws{{ k }} +bindsym $mod+Shift+{{ k }} move container to workspace $ws{{ k }} +{% endfor %} + +{% for section in sway_keybindings %} +{% if section.mode != "normal" %} +mode {{ section.mode }} { +{% endif %} + +{% for bind in section.bindings %} +bindsym {{ bind.bindsym }} {{ bind.action}} +{% endfor %} + +{% if section.mode != "normal" %} +} +{% endif %} +{% endfor %}