---
- name: Set up sway
  vars:
    uid: "{{ lookup('env','USER') }}"
    TZ: "{{ lookup('env','TZ') }}"
    wallpaper_path: /home/{{ uid }}/.config/wallpaper/savannah-landscape-with-acacia-trees.jpeg
  hosts: localhost
  connection: local
  become: false
  tasks:
    - name: Install autotiling
      ansible.builtin.command:
        cmd: pipx install autotiling
        creates: /home/{{ uid }}/.local/bin/autotiling
    - name: Create sway dir
      ansible.builtin.file:
        dest: /home/{{ uid }}/.config/sway
        state: directory
    - name: Install sway config
      ansible.builtin.template:
        src: ../templates/sway_config.j2
        dest: /home/{{ uid }}/.config/sway/config
        owner: '{{ uid }}'
        group: '{{ uid }}'
        mode: '0640'
      notify: Reload sway
    - name: Create waybar dir
      ansible.builtin.file:
        dest: /home/{{ uid }}/.config/waybar
        state: directory
    - name: Install waybar config
      ansible.builtin.template:
        src: ../templates/waybar_config.j2
        dest: /home/{{ uid }}/.config/waybar/config
        owner: '{{ uid }}'
        group: '{{ uid }}'
        mode: '0640'
      notify: Reload sway
    - name: Create wallpaper dir
      ansible.builtin.file:
        dest: /home/{{ uid }}/.config/wallpaper
        state: directory
    # Image by upklyak on Freepik
    # https://www.freepik.com/free-vector/savannah-landscape-with-acacia-trees-night-vector-cartoon-illustration-african-savanna-with-full-moon-stars-dark-sky-concept-safari-vacation-trip-travel_25694514.htm
    - name: Setup wall paper
      ansible.builtin.copy:
        dest: '{{ wallpaper_path }}'
        src: ../data/savannah-landscape-with-acacia-trees.jpeg
      notify: Reload sway
  handlers:
    - name: Reload sway
      ansible.builtin.command:
        cmd: swaymsg reload
