First commit
This commit is contained in:
commit
ae4c3b85c0
5 changed files with 139 additions and 0 deletions
60
README.md
Normal file
60
README.md
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
Swayidle ansible role
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Install and configure [swayidle](https://github.com/swaywm/swayidle)
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
This role only need one variable: `swayidle_config`. Here is an example :
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
swayidle_config:
|
||||||
|
timeouts:
|
||||||
|
- seconds: 300
|
||||||
|
command: swaylock -f
|
||||||
|
- seconds: 600
|
||||||
|
command: swaymsg "output * dpms off"
|
||||||
|
resume: 'swaymsg "output * dpms on"'
|
||||||
|
events:
|
||||||
|
before-sleep: swaylock -f
|
||||||
|
lock: swaylock -f
|
||||||
|
```
|
||||||
|
|
||||||
|
This variable contains two others: `timeouts` and `events`.
|
||||||
|
|
||||||
|
`timeouts` is an array of:
|
||||||
|
|
||||||
|
* `seconds`: numbers of second to wait before trigger the event
|
||||||
|
* `command`: command to execute when the event trigger
|
||||||
|
* `resume`: command to execute when resume
|
||||||
|
|
||||||
|
`events` contains keys:values about others events. Key contains event name and
|
||||||
|
value command to execute.
|
||||||
|
|
||||||
|
Please refer to man page for details: `man 1 swayidle`.
|
||||||
|
|
||||||
|
## Licence
|
||||||
|
|
||||||
|
This script is released under le [MIT licence][l_mit]
|
||||||
|
|
||||||
|
Copyright © 2022 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
|
11
files/swayidle.service
Normal file
11
files/swayidle.service
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Swayidle service
|
||||||
|
Documentation=https://github.com/swaywm/swayidle
|
||||||
|
BindsTo=sway-session.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/swayidle -w
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sway-session.target
|
8
meta/main.yml
Normal file
8
meta/main.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
role_name: ansible_swayidle
|
||||||
|
author: ephase
|
||||||
|
description: install and configure Swayidle
|
||||||
|
issue_tracker_url: https://git.epha.se/ephase/ansible-swayidle
|
||||||
|
license: MIT
|
||||||
|
min_ansible_version: '1.4'
|
43
tasks/main.yml
Normal file
43
tasks/main.yml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
---
|
||||||
|
- name: Install Swayidle package
|
||||||
|
ansible.builtin.package:
|
||||||
|
name: swayidle
|
||||||
|
state: present
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Create Swayidle config dirs
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: '{{ ansible_user_dir ~ "/.config/swayidle" }}'
|
||||||
|
state: directory
|
||||||
|
mode: 0750
|
||||||
|
owner: '{{ ansible_user_uid }}'
|
||||||
|
group: '{{ ansible_user_gid }}'
|
||||||
|
|
||||||
|
- name: Render templates for Swayidle config file
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: config.j2
|
||||||
|
dest: '{{ ansible_user_dir}}/.config/swayidle/config'
|
||||||
|
owner: '{{ ansible_user_uid }}'
|
||||||
|
group: '{{ ansible_user_gid }}'
|
||||||
|
lstrip_blocks: yes
|
||||||
|
trim_blocks: yes
|
||||||
|
mode: 0640
|
||||||
|
|
||||||
|
- name: copy Swayidle systemd service file
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: 'swayidle.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 Swayidle service
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: 'swayidle.service'
|
||||||
|
scope: user
|
||||||
|
state: started
|
||||||
|
when: service_file is changed and not ansible_check_mode
|
17
templates/config.j2
Normal file
17
templates/config.j2
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
{% if swayidle_config is defined %}
|
||||||
|
{% if swayidle_config['timeouts'] is defined %}
|
||||||
|
{% for timeout in swayidle_config['timeouts'] %}
|
||||||
|
timeout {{ timeout['seconds'] }} '{{ timeout['command'] }}'
|
||||||
|
{%- if timeout['resume'] is defined %}
|
||||||
|
{{ ' resume' }} '{{ timeout['resume'] }}'
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if swayidle_config['events'] is defined %}
|
||||||
|
{% for event, command in swayidle_config['events'].items() %}
|
||||||
|
{{ event }} '{{ command }}'
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
Loading…
Add table
Add a link
Reference in a new issue