commit 3e88db90450f2537870286b4b487527b008e13a8 Author: Yorick Barbanneau Date: Tue Nov 29 00:27:56 2022 +0100 First commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..c6cbe5d --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +Mako Ansible role +------------------- + +This role install and configure [Mako](https://github.com/emersion/mako) +notifiction daemon. + +## Variables + +This role needs two variables for creating Mako configuration file + + * `mako_options`: list of lkey-value abour default Mako options; + * `mako_rules`: list of mako criteria-driven Mako configuration; + +The former ils a simple list like in example below: + +```yaml +mako_options: + max_history: 5 + sort: -time + on-button-left: + on-button-middle: + on-button-right: + on-touch: + on-notify: + # [...] +``` + +The latter is a little bit more complex: + +```yaml +mako_rules: + - criterias: + - field: app-name + value: Firefox + options: + border-color: '#FF0000' + - criterias: + - field: app-name + value: Thunderbird + - field: urgency + value: low + options: + border-color: '#00FFFF' +``` + +Each rule is divided into 2 parts: *criterias* and *options*. *Criterias* +contains list of field (selector) and values to target notifications. *Options* +contains list of options to apply on targeted notifications. + +## Licence + +This script is released under le [MIT licence][l_mit] + +Copyright © 2021 Yorick Barbanneau + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[l_mit]:https://opensource.org/licenses/mit-license.php diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..4d54cd4 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,38 @@ +--- +mako_options: + max_history: 5 + sort: -time + on-button-left: + on-button-middle: + on-button-right: + on-touch: + on-notify: + font: monospace 10 + background-color: '#285577FF' + text-color: '#FFFFFFFF' + width: 300 + height: 100 + outer-margin: 10 + padding: 5 + border-size: 2 + border-color: '#4C7899FF' + border-radius: 0 + progress-color: 'over #5588AAFF' + icons: 1 + max-icon-size: 64 + icon-path: + icon-location: left + markup: 1 + actions: 1 + history: 1 + format: '%s\n%b' + text-alignement: left + default-timeout: 0 + ignore-timeout: 0 + group-by: none + max-visible: 5 + output: + layer: top + anchor: top-right + +mako_rules: [] diff --git a/files/mako.service b/files/mako.service new file mode 100644 index 0000000..d68b002 --- /dev/null +++ b/files/mako.service @@ -0,0 +1,15 @@ +[Unit] +Description=Lightweight Wayland notification daemon +Documentation=man:mako(1) +PartOf=graphical-session.target +After=graphical-session.target + +[Service] +Type=dbus +BusName=org.freedesktop.Notifications +ExecCondition=/bin/sh -c '[ -n "$WAYLAND_DISPLAY" ]' +ExecStart=/usr/bin/mako +ExecReload=/usr/bin/makoctl reload + +[Install] +WantedBy=sway-session.target diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..eb7b3bd --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Install Mako package + ansible.builtin.package: + name: mako + state: present + become: true + +- name: Create Mako config dirs + ansible.builtin.file: + path: '{{ ansible_user_dir ~ "/.config/mako" }}' + state: directory + mode: 0750 + owner: '{{ ansible_user_uid }}' + group: '{{ ansible_user_gid }}' + +- name: Render templates for Mako config file + ansible.builtin.template: + src: mako.j2 + dest: '{{ ansible_user_dir}}/.config/mako/config' + owner: '{{ ansible_user_uid }}' + group: '{{ ansible_user_gid }}' + lstrip_blocks: yes + trim_blocks: yes + mode: 0640 + +- name: Copy Mako systemd service file + ansible.builtin.copy: + src: 'mako.service' + dest: '{{ ansible_user_dir }}/.config/systemd/user/' + mode: 0640 + register: service_file + +- block: + - name: Reload Systemd daemon + ansible.builtin.systemd: + scope: user + daemon-reload: true + + - name: Activate Mako service + ansible.builtin.systemd: + name: 'mako.service' + scope: user + state: started + when: service_file is changed diff --git a/templates/mako.j2 b/templates/mako.j2 new file mode 100644 index 0000000..e58f73a --- /dev/null +++ b/templates/mako.j2 @@ -0,0 +1,20 @@ +{% if mako_options is defined %} +{% for option, value in mako_options.items() %} +{{ option }}="{{ value }}" +{% endfor %} +{% endif %} +{% if mako_rules %} + +{% for rule in mako_rules %} +[ {%- for criteria in rule['criterias'] %} +{{ criteria.field ~ '="' ~ criteria.value ~ '"' }} +{%- if not loop.last %}{{ ' ' }}{% endif %} +{%- endfor %}] +{% for option, value in rule['options'].items() %} +{{ option }}={{ value }} +{% endfor %} +{% if not loop.last %} + +{% endif %} +{% endfor %} +{% endif %}