commit c2387aff03b0b73c488eab42ea9f6bd9b8bbc275 Author: Yorick Barbanneau Date: Thu Nov 17 22:49:38 2022 +0100 First commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c35788 --- /dev/null +++ b/README.md @@ -0,0 +1,140 @@ +Sway Ansible role +------------------ + +Role to configure Sway window manager + +## Variables + +This role have multiples variables for managing all configurations + +### output + +Manage displays and options + +```yaml +sway_outputs: + - id: 'all' + name: '*' + options: + - option: 'bg' + value: '/usr/share/backgrounds/sway/sway_wallpaper_blue_1920x1080.png fill' +`````` +This example reproduce default beaviour: + + * `id`: display id, useful for (future) kanshi configuration role + * `name`: name of display, this can be found with `swaymsg -t get_outputs` + * `options`: list of options + +### Input + +Manage input configuration + +```yaml +sway_inputs: + - name: '*' + options: + - option: 'xkb_layout' + value: 'us' + - option: 'xkb_variant' + value: 'altgr-intl' +``` + + * `name`: name of input, can be found with `swaymsg -t get_inputs` + * `options`: list of options + +### Keybinding + +Manage keybinding + +```yaml +sway_keybindings: + - mode: 'normal' + bindings: + - bindsym: '$mod+Return' + action: 'exec $term' + - bindsym: '$mod+Shift+q' + action: 'kill' + # ... + - mode: 'resize' + bindings: + - bindsym: '$left' + action: 'resize shrink width 10 px or 10 ppt' + - bindsym: '$down' + action: 'resize grow height 10 px or 10 ppt' + # ... +``` + +You can define different modes, `normal` mode is mandatory, others are +optionnals. This example reflect the default configuration with `normal` and +`resize` modes. `bindings` contains a list of keyboard shortcuts and actions + +### theme configuration + +This part is divided in two parts, one for theme options, one for colors + +```yaml +sway_theme_parameters: + default_orientation: 'auto' + workspace_layout: 'default' + # ... + +sway_theme_colors: + focused: + border: '#4c7899' + backgound: '#385579' + text: '#ffffff' + indicator: '#2efef4' + child_border: '#285577' + focused_inactive: + # ... +``` + +`theme_parameters` contains a list of key:value, each `key` represent a +configuration parameter, `value` represent ... his value. + +`theme_colors` represent a list of client classes, each classe contains list of +colors. Check sway manual with `man 5 sway`. + +### Workspaces + +Like theming, there is two list for two puposes: + + 1. The first to manage workspaces name + 2. The second to manage assign and rules: + + +``` yaml +sway_workspaces: + 1: '1' + 2: '2' + 3: '3' + # ... +sway_rules: + - verb: 'assign' + query: '[app_id="^firefox$"]' + action: 3 + - verb: 'assign' + query: '[app_id="KeePassXC$"]' + action: 3 + # ... + - verb: 'for_window' + query: '[app_id="org.pwmt.zathura"]' + action: 'floating enable' + - verb: 'for_window' + query: '[app_id="^launcher$"]' + action: 'floating enable, resize set 800px 400px' + # ... +``` + +`sway_workspace` represent a list of workspaces defined by a *key* that represent the +keyboard key to press with `$mod` to access this workspace and a *value* that +represent the workspace name. + +`sway_rules` reprensents the list of rules for managing windows : + + * `verb`: type of rule - `assign` to assign a program to a specific + workspace and `for_windows` for managing windows rules (float, size etc.) + * `query`: witch windows to target + * `action`: what you want to do with window + +Sway manual can be useful : `man 5 sway` diff --git a/defaults/main/input.config.j2 b/defaults/main/input.config.j2 new file mode 100644 index 0000000..099d683 --- /dev/null +++ b/defaults/main/input.config.j2 @@ -0,0 +1,12 @@ +" Press ? for help + +.. (up a dir) +- + 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" + - bindsym: '$mod+$left' + action: 'focus left' + - bindsym: '$mod+$down' + action: 'focus down' + - bindsym: '$mod+$up' + action: 'focus up' + - bindsym: '$mod+$right' + action: 'focus right' + + # Focus + - bindsym: '$mod+$left' + action: 'focus left' + - bindsym: '$mod+$down' + action: 'focus down' + - bindsym: '$mod+$up' + action: 'focus up' + - bindsym: '$mod+$right' + action: 'focus right' + + # Use regular direction bindsym + - bindsym: '$mod+Left' + action: 'focus left' + - bindsym: '$mod+Down' + action: 'focus down' + - bindsym: '$mod+Up' + action: 'focus up' + - bindsym: '$mod+Right' + action: 'focus right' + + # move the focused window with the same, but add Shift + - bindsym: '$mod+Shift+$left' + action: 'move left' + - bindsym: '$mod+Shift+$down' + action: 'move down' + - bindsym: '$mod+Shift+$up' + action: 'move up' + - bindsym: '$mod+Shift+$right' + action: 'move right' + + - bindsym: '$mod+Shift+Left' + action: 'move left' + - bindsym: '$mod+Shift+Down' + action: 'move down' + - bindsym: '$mod+Shift+Up' + action: 'move up' + - bindsym: '$mod+Shift+Right' + action: 'move right' + + # split + - bindsym: '$mod+b' + action: 'splith' + - bindsym: '$mod+v' + action: 'splitv' + + # layout + - bindsym: '$mod+s' + action: 'layout stacking' + - bindsym: '$mod+w' + action: 'layout tabbed' + - bindsym: '$mod+e' + action: layout toggle split + + # Fullscreen + - bindsym: '$mod+f' + action: 'fullscreen' + + # Toggle floating mode + - bindsym: '$mod+Shift+space' + action: 'floating toggle' + # Swap focus between the tiling area and the floating area + - bindsym: '$mod+space' + action: 'focus mode_toggle' + # move focus to the parent container + - bindsym: '$mod+a' + action: 'focus parent' + + # Scratchpad + - bindsym: '$mod+Shift+p' + action: 'move scratchpad' + - bindsym: '$mod+p' + action: 'scratchpad show' + - mode: 'resize' + bindings: + - bindsym: '$left' + action: 'resize shrink width 10 px or 10 ppt' + - bindsym: '$down' + action: 'resize grow height 10 px or 10 ppt' + - bindsym: '$up' + action: 'resize shrink height 10 px or 10 ppt' + - bindsym: '$right' + action: 'resize grow width 10 px or 10 ppt' + - bindsym: 'Return' + action: 'mode "default"' + - bindsym: Escape + action: 'mode "default"' diff --git a/defaults/main/output.yml b/defaults/main/output.yml new file mode 100644 index 0000000..4e28f5c --- /dev/null +++ b/defaults/main/output.yml @@ -0,0 +1,7 @@ +--- +sway_outputs: + - id: 'all' + name: '*' + options: + - option: 'bg' + value: '/usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill' diff --git a/defaults/main/theme.yml b/defaults/main/theme.yml new file mode 100644 index 0000000..4d218f8 --- /dev/null +++ b/defaults/main/theme.yml @@ -0,0 +1,40 @@ +--- +sway_theme_parameters: + default_orientation: 'auto' + workspace_layout: 'default' + gaps: 'inner 3' + smart_gaps: 'on' + smart_borders: 'on' + font: 'pango:FuraCode Nerd Font Mono 10' + default_border: 'pixel 1' + default_floating_border: 'pixel 1' + title_align: 'center' +sway_theme_colors: + focused: + border: '#4c7899' + backgound: '#385579' + text: '#ffffff' + indicator: '#2efef4' + child_border: '#285577' + focused_inactive: + border: '#333333' + backgound: '#5f676a' + text: '#ffffff' + indicator: '#484e50' + child_border: '#5f676a' + focused_tab_title: + border: '#2f343a' + backgound: '5f676a' + text: '#ffffff' + unfocused: + border: '#333333' + backgound: '#222222' + text: '#888888' + indicator: '#292d2e' + child_border: '#222222' + urgent: + border: '#2f343a' + backgound: '#900000' + text: '#cccccc' + indicator: '#900000' + child_border: '#900000' diff --git a/defaults/main/workspaces.yml b/defaults/main/workspaces.yml new file mode 100644 index 0000000..1bbb3ca --- /dev/null +++ b/defaults/main/workspaces.yml @@ -0,0 +1,12 @@ +--- +sway_workspaces: + 1: '1' + 2: '2' + 3: '3' + 4: '4' + 5: '5' + 6: '6' + 7: '7' + 8: '8' + 9: '9' + 0: '0' diff --git a/files/sway-session.target b/files/sway-session.target new file mode 100644 index 0000000..a6dadf9 --- /dev/null +++ b/files/sway-session.target @@ -0,0 +1,6 @@ +[Unit] +Description=Sway compositor session +Documentation=man:systemd.special +BindsTo=graphical-session.target +Wants=graphical-session-pre.target +After=graphical-session-pre.target diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..80337ee --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: Copy systemd Sway target + ansible.builtin.copy: + src: 'sway-session.target' + dest: '{{ ansible_user_dir }}/.config/systemd/user/' + mode: 0640 + +- name: Create Sway config dirs + ansible.builtin.file: + path: '{{ ansible_user_dir ~ "/.config/sway/test.d" }}' + state: directory + mode: 0750 + owner: '{{ ansible_user_uid }}' + group: '{{ ansible_user_gid }}' + +- name: Render templates for sway config files + ansible.builtin.template: + src: '{{ item }}.config.j2' + dest: '{{ ansible_user_dir ~ "/.config/sway/test.d/" ~ item ~ ".config" }}' + owner: '{{ ansible_user_uid }}' + group: '{{ ansible_user_gid }}' + lstrip_blocks: yes + trim_blocks: yes + mode: 0640 + validate: >- + sh -c "if sway --config %s --validate 2>&1 | grep -q sway/config.c; then >&2 echo \"Error validating sway configuration\"; exit 1; else exit 0; fi" + loop: + - keybindings + - theme + - output + - input + any_errors_fatal: true diff --git a/templates/input.config.j2 b/templates/input.config.j2 new file mode 100644 index 0000000..8e803f3 --- /dev/null +++ b/templates/input.config.j2 @@ -0,0 +1,9 @@ +{% if sway_inputs is defined %} +{% for input in sway_inputs %} +input {{ input.name }} { + {% for option in input.options %} + {{ option.option }} {{ option.value }} + {% endfor %} +} +{% endfor %} +{% endif %} diff --git a/templates/keybindings.config.j2 b/templates/keybindings.config.j2 new file mode 100644 index 0000000..4d79fa4 --- /dev/null +++ b/templates/keybindings.config.j2 @@ -0,0 +1,25 @@ +set $mod Mod4 +set $left h +set $down j +set $up k +set $right l + +# Dynamic workspace keybindings +{% for k,v in sway_workspaces.items() %} +bindsym $mod+{{ k }} workspace $ws{{ k }} +bindsym $mod+Shift+{{ k }} move container to workspace $ws{{ k }} +{% endfor %} + +{% for section in sway_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 %} diff --git a/templates/output.config.j2 b/templates/output.config.j2 new file mode 100644 index 0000000..321be65 --- /dev/null +++ b/templates/output.config.j2 @@ -0,0 +1,9 @@ +{% if sway_outputs %} +{% for output in sway_outputs %} +output {{ output.name ~ " " }} +{%- for option in output.options %} +{{ option.option }} {{ option.value }} +{% endfor %} + +{% endfor %} +{% endif %} diff --git a/templates/theme.config.j2 b/templates/theme.config.j2 new file mode 100644 index 0000000..9752822 --- /dev/null +++ b/templates/theme.config.j2 @@ -0,0 +1,11 @@ +{% for k,v in sway_theme_parameters.items() %} +{{ k }} {{ v }} +{% endfor %} + +{% for client, c in sway_theme_colors.items() %} +client.{{ client }} {{ c.border }} {{ c.backgound}} {{ c.text }} +{%- if c.indicator is defined %} {{ c.indicator }} +{%- if c.child_border is defined %} {{ c.child_border }}{% endif %} +{% endif %} + +{% endfor %} diff --git a/templates/workspaces.config.j2 b/templates/workspaces.config.j2 new file mode 100644 index 0000000..1f79ae2 --- /dev/null +++ b/templates/workspaces.config.j2 @@ -0,0 +1,9 @@ +{% for k,v in sway_workspaces.items() %} +set $ws{{ k }} {{ v }} +{% endfor %} + +{% if sway_rules is defined %} +{% for i in rules %} +{{ i.verb }} {{ i.query }} {% if i.verb == 'assign' %}$ws{% endif %}{{ i.action }} +{% endfor %} +{% endif %}