1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_i3wm.git synced 2024-08-16 10:09:53 +02:00

Create first working sway config

This commit is contained in:
L3D 2024-07-17 15:45:32 +02:00
parent a41b16c525
commit 83b8c4a117
Signed by: l3d
GPG key ID: CD08445BFF4313D1
7 changed files with 328 additions and 338 deletions

View file

@ -1,4 +1,15 @@
---
# deploy config to these users:
sway__user_list:
- user: "{{ ansible_user_id }}"
home: "{{ ansible_env.HOME | default('/home/{{ ansible_user_id }}') }}"
sway__dynamic_names: true
# version check for this role?
submodules_versioncheck: true
# Here are the variables you may want to change
# to configure i3wm
i3_keybindings_extra: []
@ -28,10 +39,6 @@ i3_run_on_startup: []
# - foo
# - bar
# deploy config to these users:
i3wm_user_list:
- user: "{{ ansible_user_id }}"
home: "{{ ansible_env.HOME | default('/home/{{ ansible_user_id }}') }}"
## set default font size
i3_font_size: 11
@ -67,5 +74,3 @@ disable_screensaver: true
enable_lock_after_time: false
lock_after_time: '90' # minutes to wait until your screen is locked
# version check for this role?
submodules_versioncheck: true

View file

@ -1,91 +1,44 @@
---
- name: Creates directory
- name: Creates config directory if needed
become: true
ansible.builtin.file:
path: '{{ i3wm_usr.home }}/.config'
state: directory
mode: 0750
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
- name: Create i3 config folder
become: true
ansible.builtin.file:
path: '{{ i3wm_usr.home }}/.config/i3/'
state: directory
mode: 0750
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
- name: Copy multiple images
become: true
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0644
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
loop:
- { src: 'files/background.png', dest: "{{ i3wm_usr.home }}/.config/background.png" }
- { src: 'files/lockscreen.png', dest: '{{ i3wm_usr.home }}/.config/lockscreen.png' }
when: i3wm_copy_wallpapers | bool
- name: Copy and validate i3wm config file
become: true
ansible.builtin.template:
src: templates/config.j2
dest: "{{ i3wm_usr.home }}/.config/i3/config"
mode: 0600
backup: true
validate: i3 -C -c %s
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
- name: Create directory ~/.config/i3blocks/
become: true
ansible.builtin.file:
path: "{{ i3wm_usr.home }}/.config/i3blocks/"
path: "{{ swayusr.home }}/.config"
state: directory
mode: '0750'
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
owner: "{{ swayusr.user }}"
group: "{{ swayusr.user }}"
loop: "{{ sway__user_list | flatten(1) }}"
loop_control:
loop_var: swayusr
- name: Generate i3blocks config
become: true
ansible.builtin.template:
src: 'templates/i3blocks_config.j2'
dest: "{{ i3wm_usr.home }}/.config/i3blocks/config"
mode: 0640
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
- name: Copy i3blocks config
become: true
ansible.builtin.copy:
src: "files/i3blocks/{{ item }}"
dest: "{{ i3wm_usr.home }}/.config/i3blocks/{{ item }}"
mode: 0750
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
loop:
- 'volume.sh'
- 'wlan.py'
- 'battery.py'
- name: Create rofi config folder
- name: Create sway config folder
become: true
ansible.builtin.file:
path: '{{ i3wm_usr.home }}/.config/rofi/'
path: "{{ swayusr.home }}/.config/sway/"
state: directory
mode: 0750
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
mode: '0750'
owner: "{{ swayusr.user }}"
group: "{{ swayusr.user }}"
loop: "{{ sway__user_list | flatten(1) }}"
loop_control:
loop_var: swayusr
- name: Copy rofi config
- name: Create sway dynamic names
ansible.builtin.include_tasks:
file: "dynamic_names.yml"
loop: "{{ sway__user_list | flatten(1) }}"
loop_control:
loop_var: swayusr
when: sway__dynamic_names | bool
- name: Deploy sway config file
become: true
ansible.builtin.copy:
src: "{{ i3_rofi_config_file }}"
dest: "{{ i3wm_usr.home }}/.config/rofi/config.rasi"
mode: 0640
owner: "{{ i3wm_usr.user }}"
group: "{{ i3wm_usr.user }}"
ansible.builtin.template:
src: 'templates/config.j2'
dest: "{{ swayusr.home }}/.config/sway/config"
mode: '0640'
owner: "{{ swayusr.user }}"
group: "{{ swayusr.user }}"
loop: "{{ sway__user_list | flatten(1) }}"
loop_control:
loop_var: swayusr

16
tasks/dynamic_names.yml Normal file
View file

@ -0,0 +1,16 @@
---
- name: Install sway-dynamic-names-git
become: true
ansible.builtin.pip:
name: sway-dynamic-names
virtualenv: '{{ swayusr.home }}/.config/sway/venv'
- name: Make sure venv has user permissions
become: true
ansible.builtin.file:
path: '{{ swayusr.home }}/.config/sway/venv'
recurse: true
state: directory
mode: "u=rwX,g=rX"
owner: "{{ swayusr.user }}"
group: "{{ swayusr.user }}"

View file

@ -1,31 +1,35 @@
---
- name: Run optional versionscheck
ansible.builtin.include_tasks:
file: versioncheck.yml
file: "versioncheck.yml"
when: submodules_versioncheck | bool
- name: Register variables
ansible.builtin.import_tasks:
file: variables.yml
# - name: Register variables
# ansible.builtin.import_tasks:
# file: variables.yml
- name: Ensure i3 packages are installed [Debian]
ansible.builtin.include_tasks:
file: setup-Debian.yml
file: "setup-Debian.yml"
when: ansible_os_family == 'Debian'
- name: Ensure i3 packages are installed [Archlinux}
ansible.builtin.include_tasks:
file: setup-Archlinux.yml
when: ansible_os_family == 'Archlinux'
- name: Create sway configuration and features
ansible.builtin.import_tasks:
file: "config.yml"
- name: Ensure i3 packages are installed [RHEL].
ansible.builtin.include_tasks:
file: setup-RedHat.yml
when: ansible_os_family == 'Fedora' or ansible_os_family == 'RedHat'
#- name: Ensure i3 packages are installed [Archlinux}
# ansible.builtin.include_tasks:
# file: setup-Archlinux.yml
# when: ansible_os_family == 'Archlinux'
#
#- name: Ensure i3 packages are installed [RHEL].
# ansible.builtin.include_tasks:
# file: setup-RedHat.yml
# when: ansible_os_family == 'Fedora' or ansible_os_family == 'RedHat'
- name: Create i3 config file
ansible.builtin.include_tasks:
file: config.yml
loop: "{{ i3wm_user_list | flatten(1) }}"
loop_control:
loop_var: i3wm_usr
# - name: Create i3 config file
# ansible.builtin.include_tasks:
# file: config.yml
# loop: "{{ i3wm_user_list | flatten(1) }}"
# loop_control:
# loop_var: i3wm_usr

View file

@ -7,8 +7,26 @@
when:
- ansible_pkg_mgr == "apt"
- name: Ensure i3 packages are installed.
# - name: Ensure i3 packages are installed.
# ansible.builtin.apt:
# name: "{{ i3_packages }}"
# state: "present"
# become: true
- name: Ensure swaywm is installed.
ansible.builtin.apt:
name: "{{ i3_packages }}"
name: "{{ item }}"
state: "present"
become: true
with_items:
- "sway"
- name: Ensure font-awesome is installed
ansible.builtin.apt:
name: "{{ item }}"
state: "present"
become: true
with_items:
- "fonts-font-awesome"
- "virtualenv"
when: sway__dynamic_names | bool

View file

@ -1,208 +1,236 @@
# config File for sway
#
{{ ansible_managed | comment }}
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
set $term foot
# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
set $menu dmenu_path | dmenu | xargs swaymsg exec --
set $term {{ i3_terminal }}
include /etc/sway/config-vars.d/*
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:monospace {{ i3_font_size }}
focus_follows_mouse {{ i3_focus_follows_mouse | ansible.builtin.ternary('yes', 'no' ) }}
### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
#
# Example configuration:
#
# output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
# timeout 300 'swaylock -f -c 000000' \
# timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
# before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
# startup apps and window decs
default_orientation horizontal
workspace_layout tabbed
### Input configuration
#
# input <identifier> xkb_layout <layout_name>
# Sets the layout of the keyboard like us or de.
#
# Multiple layouts can be specified by separating them with commas
#
input type:keyboard {
xkb_layout de
}
# Example configuration:
#
# input "2:14:SynPS/2_Synaptics_TouchPad" {
# dwt enabled
# tap enabled
# natural_scroll enabled
# middle_emulation enabled
# }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
# Hide borders
hide_edge_borders smart
# start a terminal
### Key bindings
#
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
bindsym $mod+Shift+Return exec $term -e tmux
# kill focused window
# Kill focused window
bindsym $mod+Shift+q kill
{% if ansible_distribution == 'Redhat' or ansible_distribution == 'CentOS' %}
# bindsym $mod+d exec dmenu_run (a program launcher)
bindsym $mod+d exec dmenu_run
{% else %}
bindsym $mod+d exec rofi -show run
# bindsym $mod+d exec rofi (a program launcher)
bindsym $mod+Shift+d exec rofi -show drun
bindsym $mod+Shift+y exec rofi -show window
bindsym $mod+Shift+s exec rofi -show ssh
{% endif %}
# Start your launcher
bindsym $mod+d exec $menu
# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+odiaeresis focus right
# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal
# alternatively, you can use the cursor keys:
# Reload the configuration file
bindsym $mod+Shift+c reload
# Exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
# Move your focus around
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right
# Or use $mod+[up|down|left|right]
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+odiaeresis move right
# alternatively, you can use the cursor keys:
# Move the focused window with the same, but add Shift
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right
# Ditto, with arrow keys
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
#
# Workspaces:
#
# split in horizontal orientation
bindsym $mod+h split h
# Switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+0 workspace number 10
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
# split in vertical orientation
# dynamic workspaces
# https://pypi.org/project/sway-dynamic-names/
{% if sway__dynamic_names %}
exec_always --no-startup-id exec {{ swayusr.home }}/.config/sway/venv/bin/sway-dynamic-names
{% else %}
exec_always --no-startup-id exec {{ swayusr.home }}/.config/sway/venv/bin/sway-dynamic-names
{% endif %}
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv
# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle
# change container layout (stacked, tabbed, toggle split)
# Switch the current container between different layout styles
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# toggle tiling / floating
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# change focus between tiling / floating windows
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# focus the parent container
# Move focus to the parent container
bindsym $mod+a focus parent
#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
# focus the child container
#bindsym $mod+d focus child
# Move the currently focused window to the scratchpad
bindsym $mod+Shift+minus move scratchpad
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
# Custom Bindings
bindsym $mod+Shift+x exec {{ i3lock_options }}
# workspace variables
{% for workspace in i3_workspaces %}
set $workspace{{ workspace.id }} "{{ workspace.name }}"
{% endfor %}
# switch to workspace
{% for workspace in i3_workspaces %}
bindsym $mod+{{ workspace.id }} workspace $workspace{{ workspace.id }}
{% endfor %}
# toggle workspace
bindsym $mod+Tab workspace next_on_output
bindsym $mod+Shift+Tab workspace prev_on_output
# move focused container to workspace
{% for workspace in i3_workspaces %}
bindsym $mod+Shift+{{ workspace.id }} move container to workspace $workspace{{ workspace.id }}
{% endfor %}
{% for monitor in i3_monitors %}
{% for workspace in monitor.workspaces %}
workspace $workspace{{ workspace }} output {{ monitor.output }}
{% endfor %}
{% endfor %}
{% for application in i3_applications %}
assign [class="{{ application.class }}"] $workspace{{ application.workspace }}
{% endfor %}
for_window [instance="dropdown"] floating enable
for_window [instance="dropdown"] resize set 1024 800
for_window [instance="dropdown"] move position center
for_window [instance="dropdown"] move scratchpad
exec --no-startup-id $term -name dropdown -e tmux
bindsym $mod+t [instance="dropdown"] scratchpad show; move position center
# reload the configuration file
bindsym $mod+Shift+c reload
# resize window (you can also use the mouse for that)
# Show the next scratchpad window or hide the focused scratchpad window.
# If there are multiple scratchpad windows, this command cycles through them.
bindsym $mod+minus scratchpad show
#
# Resizing containers:
#
mode "resize" {
# These bindings trigger as soon as you enter the resize mode
# left will shrink the containers width
# right will grow the containers width
# up will shrink the containers height
# down will grow the containers height
bindsym $left resize shrink width 10px
bindsym $down resize grow height 10px
bindsym $up resize shrink height 10px
bindsym $right resize grow width 10px
# Pressing left will shrink the windows width.
# Pressing right will grow the windows width.
# Pressing up will shrink the windows height.
# Pressing down will grow the windows height.
bindsym j resize shrink width 10 px or 10 ppt
bindsym k resize grow height 10 px or 10 ppt
bindsym l resize shrink height 10 px or 10 ppt
bindsym odiaeresis resize grow width 10 px or 10 ppt
# Ditto, with arrow keys
bindsym Left resize shrink width 10px
bindsym Down resize grow height 10px
bindsym Up resize shrink height 10px
bindsym Right resize grow width 10px
# same bindings, but for the arrow keys
bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt
bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
font pango:mono {{ i3_font_size }}
status_command i3blocks
position top
mode dock
modifier None
# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
status_command while date +'%Y-%m-%d %I:%M:%S %p'; do sleep 1; done
colors {
statusline #ffffff
background #323232
inactive_workspace #32323200 #32323200 #5c5c5c
}
}
# Setup Monitors
exec_always sleep 1 && xrandr \
{% for monitor in i3_monitors %} \
--output {{ monitor.output }} \
--mode {{ monitor.mode }} \
--pos {{ monitor.pos }} \
--rotate {{ monitor.rotate }}
{% endfor %}
# Background
{% if i3_desktop_background is defined %}
exec_always feh --bg-scale {{ i3_desktop_background }}
{% endif %}
{% if disable_screensaver | bool %}
# Disable screensaver by default
exec_always xset s off
exec xset -dpms
{% endif %}
{% if enable_lock_after_time | bool %}
exec xautolock -time {{ lock_after_time }} -locker 'maim /tmp/screen_locked.png; mogrify -scale 10% -scale 1000% /tmp/screen_locked.png; i3lock -i /tmp/screen_locked.png'
{% endif %}
# Start Default Applications
{% for application in i3_applications if application.on_startup %}
exec sleep 5 && {{ application.name }}
{% endfor %}
{% for app in i3_run_on_startup %}
exec sleep 12 && {{ app }}
{% endfor %}
# Register Keybindings
{% for keybinding in i3_keybindings %}
bindsym {{ keybinding.key }} exec {{ keybinding.exec }}
{% endfor %}
include /etc/sway/config.d/*

View file

@ -1,37 +1,3 @@
---
__i3_workspaces:
- workspace:
id: 1
name: " 1 "
- workspace:
id: 2
name: " 2 "
- workspace:
id: 3
name: " 3 "
- workspace:
id: 4
name: " 4 "
- workspace:
id: 5
name: " 5 "
- workspace:
id: 6
name: " 6 "
- workspace:
id: 7
name: " 7 "
- workspace:
id: 8
name: " 8 "
- workspace:
id: 9
name: " 9 "
- workspace:
id: 0
name: " 0 "
user: "{{ i3wm_user }}"
playbook_version_number: 9027 # should be int
playbook_version_path: 'role-i3wm_chaos-bodensee_github.com.version'
playbook_version_number: 3 # should be int
playbook_version_path: 'role-roles-ansible.sway.version'