From 05c74dd3badde4b90f5ab8d316f51ed9a43da741 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sat, 15 Apr 2023 01:44:46 +0200 Subject: [PATCH] Add keybinding for sway WM --- defaults/main.yml | 2 ++ tasks/main.yml | 15 +++++++++++++++ templates/51-mako_keybindings.config.j2 | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 templates/51-mako_keybindings.config.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 0a1a3f0..2f0355e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -39,3 +39,5 @@ mako_options: anchor: top-right mako_rules: [] + +mako_keybindings: [] diff --git a/tasks/main.yml b/tasks/main.yml index d85912c..f93742c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -42,3 +42,18 @@ scope: user state: started when: service_file is change and not ansible_check_mode + +- name: Render Mako keybinding for sway config file + ansible.builtin.template: + src: '{{ item }}.config.j2' + dest: '{{ ansible_user_dir ~ "/.config/sway/conf.d/" ~ item ~ ".config" }}' + owner: '{{ ansible_user_uid }}' + group: '{{ ansible_user_gid }}' + lstrip_blocks: true + trim_blocks: true + mode: 0640 + validate: >- + sh -c "cat {{ansible_user_dir}}/.config/sway/conf.d/* %s > /tmp/sway; if sway --config /tmp/sway --validate 2>&1 | grep -q sway/config.c; then >&2 echo \"Error validating sway configuration\"; rm /tmp/sway; exit 1; else rm /tmp/sway; exit 0; fi" + loop: + - 51-mako_keybindings + any_errors_fatal: true diff --git a/templates/51-mako_keybindings.config.j2 b/templates/51-mako_keybindings.config.j2 new file mode 100644 index 0000000..bb268ef --- /dev/null +++ b/templates/51-mako_keybindings.config.j2 @@ -0,0 +1,13 @@ +{% for section in mako_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 %}