sxmo: fold the sway config fully into sane.gui.sway

This commit is contained in:
2023-09-05 04:25:58 +00:00
parent cd9f05b8e1
commit ab776d7fc8
5 changed files with 173 additions and 341 deletions

View File

@@ -26,6 +26,63 @@ in
populate ~/.config/sway/config & co with defaults provided by this module.
'';
};
sane.gui.sway.config = {
extra_lines = mkOption {
type = types.lines;
default = "";
description = ''
extra lines to append to the sway config
'';
};
font = mkOption {
type = types.string;
default = "pango:monospace 11";
description = ''
default font (for e.g. window titles)
'';
};
mod = mkOption {
type = types.string;
default = "Mod4";
description = ''
Super key (for non-application shortcuts).
- "Mod1" for Alt
- "Mod4" for logo key
'';
};
workspace_layout = mkOption {
type = types.string;
default = "default";
description = ''
how to arrange windows within new workspaces, by default:
- "default" (split)
- "tabbed"
- etc
'';
};
# TODO: split these into their own option scope
brightness_down_cmd = mkOption {
type = types.string;
default = "${pkgs.brightnessctl}/bin/brightnessctl set -2%";
description = "command to run when use wants to decrease screen brightness";
};
brightness_up_cmd = mkOption {
type = types.string;
default = "${pkgs.brightnessctl}/bin/brightnessctl set +2%";
description = "command to run when use wants to increase screen brightness";
};
screenshot_cmd = mkOption {
type = types.string;
default = "${pkgs.sway-contrib.grimshot}/bin/grimshot copy area";
description = "command to run when user wants to take a screenshot";
};
status_cmd = mkOption {
type = types.string;
default = "${pkgs.i3status}/bin/i3status";
description = "command to run that populates the status section of the topbar";
};
};
sane.gui.sway.waybar.top = mkOption {
type = types.submodule {
# `attrsOf types.anything` (v.s. plain `attrs`) causes merging of the toplevel items.
@@ -165,7 +222,10 @@ in
builtins.readFile ./waybar-style.css;
".config/sway/config" = lib.mkIf cfg.installConfigs {
symlink.target = import ./sway-config.nix { inherit pkgs; };
symlink.target = import ./sway-config.nix {
inherit pkgs;
inherit (cfg) config;
};
};
};
})

View File

@@ -18,9 +18,10 @@ set $brightness_down @brightness_down_cmd@
set $volume_up @vol_up_cmd@
set $volume_down @vol_down_cmd@
set $mute @mute_cmd@
set $default_workspace_layout @workspace_layout@
### default font (for e.g. window titles)
font pango:monospace 11
font @font@
### tab colors (#border #background #text [#indicator #childBorder])
# focused & unfocused are the main interest
@@ -44,20 +45,24 @@ title_align center
#### no => preserve last focus. helpful mostly when `focus_follows_mouse yes`
focus_wrapping no
focus_follows_mouse yes
### workspace_layout default => workspaces use splits by default (as opposed to e.g. tabbed)
workspace_layout default
workspace_layout $default_workspace_layout
### key bindings
floating_modifier $mod
## media keys
#### media keys
bindsym XF86AudioRaiseVolume exec $volume_up
bindsym XF86AudioLowerVolume exec $volume_down
bindsym $mod+Page_Up exec $volume_up
bindsym $mod+Page_Down exec $volume_down
bindsym XF86AudioMute exec $mute
bindsym XF86AudioPlay exec @playerctl@ play-pause
bindsym XF86AudioStop exec @playerctl@ stop
bindsym XF86AudioNext exec @playerctl@ next
bindsym XF86AudioPrev exec @playerctl@ previous
bindsym XF86MonBrightnessUp exec $brightness_up
bindsym XF86MonBrightnessDown exec $brightness_down
## special functions
#### special functions
bindsym $mod+Print exec $screenshot
bindsym $mod+l exec $locker
bindsym $mod+s exec $snippets_picker
@@ -67,7 +72,8 @@ bindsym $mod+Return exec $term
bindsym $mod+Shift+q kill
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'
bindsym $mod+Shift+c reload
## layout
#### layout
bindsym $mod+b splith
bindsym $mod+v splitv
bindsym $mod+f fullscreen toggle
@@ -77,7 +83,8 @@ bindsym $mod+e layout toggle split
bindsym $mod+Shift+space floating toggle
bindsym $mod+space focus mode_toggle
bindsym $mod+r mode resize
## movement
#### movement
bindsym $mod+Up focus up
bindsym $mod+Down focus down
bindsym $mod+Left focus left
@@ -86,7 +93,8 @@ bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Right move right
## workspaces
#### workspaces
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
@@ -105,36 +113,44 @@ 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
## "scratchpad" = ??
#### "scratchpad" = ??
bindsym $mod+Shift+minus move scratchpad
bindsym $mod+minus scratchpad show
### defaults
mode "resize" {
bindsym Down resize grow height 10 px
bindsym Down resize grow height 30 px
bindsym Escape mode default
bindsym Left resize shrink width 10 px
bindsym Left resize shrink width 30 px
bindsym Return mode default
bindsym Right resize grow width 10 px
bindsym Up resize shrink height 10 px
bindsym h resize shrink width 10 px
bindsym j resize grow height 10 px
bindsym k resize shrink height 10 px
bindsym l resize grow width 10 px
bindsym Right resize grow width 30 px
bindsym Up resize shrink height 30 px
bindsym h resize shrink width 30 px
bindsym j resize grow height 30 px
bindsym k resize shrink height 30 px
bindsym l resize grow width 30 px
}
### lightly modified bars
bar {
mode dock
hidden_state hide
position top
status_command @status@
swaybar_command @waybar@
# XXX Colin: *probably* necessary for sxmo
pango_markup enabled
# XXX Colin: not sure if all of these are necessary
mode dock
hidden_state hide
workspace_buttons yes
strip_workspace_numbers no
tray_output primary
}
### application-specific settings
for_window [app_id="pinentry-.*"] floating true
for_window [app_id="foot" title=".*sxmo/modem/.*/draft.txt.*"] resize set height 25
for_window [title="megapixels"] inhibit_idle open
### displays
## DESKTOP
output "Samsung Electric Company S22C300 0x00007F35" {
@@ -166,3 +182,5 @@ output "Unknown 0x0637 0x00000000" {
# - XDG_CURRENT_DESKTOP
# for more, see: <repo:nixos/nixpkgs:nixos/modules/programs/wayland/sway.nix>
include /etc/sway/config.d/*
@extra_lines@

View File

@@ -1,4 +1,4 @@
{ pkgs }:
{ config, pkgs }:
let
fuzzel = "${pkgs.fuzzel}/bin/fuzzel";
sed = "${pkgs.gnused}/bin/sed";
@@ -6,12 +6,10 @@ let
launcher_cmd = fuzzel;
terminal_cmd = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec";
lock_cmd = "${pkgs.swaylock}/bin/swaylock --indicator-idle-visible --indicator-radius 100 --indicator-thickness 30";
# TODO: use pipewire controls?
vol_up_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume +5";
vol_down_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --change-volume -5";
mute_cmd = "${pkgs.pulsemixer}/bin/pulsemixer --toggle-mute";
brightness_up_cmd = "${pkgs.brightnessctl}/bin/brightnessctl set +2%";
brightness_down_cmd = "${pkgs.brightnessctl}/bin/brightnessctl set 2%-";
screenshot_cmd = "${pkgs.sway-contrib.grimshot}/bin/grimshot copy area";
# "bookmarking"/snippets inspired by Luke Smith:
# - <https://www.youtube.com/watch?v=d_11QaTlf1I>
snip_cmd = pkgs.writeShellScript "type_snippet.sh" ''
@@ -23,26 +21,29 @@ let
# TODO: splatmoji release > 1.2.0 should allow `-s none` to disable skin tones
emoji_cmd = "${pkgs.splatmoji}/bin/splatmoji -s medium-light type";
# mod = "Mod1"; # Alt
mod = "Mod4"; # Super (Logo key)
xwayland = "disable";
in pkgs.substituteAll {
src = ./sway-config;
inherit
brightness_down_cmd
brightness_up_cmd
emoji_cmd
launcher_cmd
lock_cmd
mod
mute_cmd
screenshot_cmd
snip_cmd
terminal_cmd
vol_down_cmd
vol_up_cmd
xwayland
;
status = "${pkgs.i3status}/bin/i3status";
inherit (config)
brightness_down_cmd
brightness_up_cmd
extra_lines
screenshot_cmd
font
mod
workspace_layout
;
playerctl = "${pkgs.playerctl}/bin/playerctl";
waybar = "${pkgs.waybar}/bin/waybar";
}

View File

@@ -189,10 +189,70 @@ in
{
sane.gui.sway = {
enable = true;
# we manage these ourselves (TODO: merge these into sway config as well)
# we manage the greeter ourselves (TODO: merge this into sway config as well)
useGreeter = false;
installConfigs = false;
waybar.top = import ./waybar-top.nix;
config = {
# N.B. missing from upstream sxmo config here is:
# - `bindsym $mod+g exec sxmo_hook_locker.sh`
# - `bindsym $mod+t exec sxmo_appmenu.sh power`
# - `bindsym $mod+i exec sxmo_wmmenu.sh windowswitcher`
# - `bindsym $mod+p exec sxmo_appmenu.sh`
# - `bindsym $mod+Shift+p exec sxmo_appmenu.sh sys`
# - `input * xkb_options compose:ralt`
# these could be added, but i don't see much benefit.
mod = "Mod1"; # prefer Alt
font = "Sxmo 10";
workspace_layout = "tabbed";
brightness_down_cmd = "sxmo_brightness.sh down";
brightness_up_cmd = "sxmo_brightness.sh up";
screenshot_cmd = "sxmo_screenshot.sh";
status_cmd = "sxmo_status_watch.sh -o pango";
extra_lines =
let
sxmo_init = pkgs.writeShellScript "sxmo_init.sh" ''
# perform the same behavior as sxmo_{x,w}init.sh -- but without actually launching wayland/X11
# this amounts to:
# - setting env vars (e.g. getting the hooks onto PATH)
# - placing default configs in ~ for sxmo-launched services (sxmo_migrate.sh)
# - binding vol/power buttons (sxmo_swayinitconf.sh)
# - launching sxmo_hook_start.sh
source ${cfg.package}/etc/profile.d/sxmo_init.sh
# XXX: upstream sources `profile` later (after sxmo_migrate)
# but _sxmo_load_environments uses `SXMO_DEVICE_NAME`,
# and i ship that via the profile, so order it such
source "$XDG_CONFIG_HOME/sxmo/profile"
_sxmo_load_environments
_sxmo_prepare_dirs
sxmo_migrate.sh sync
# kill anything leftover from the previous sxmo run. this way we can (try to) be reentrant
echo "sxmo_init: killing stale daemons (if active)"
sxmo_daemons.sh stop all
pkill bemenu
pkill wvkbd
pkill superd
# configure vol/power-button input mapping (upstream SXMO has this in sway config)
sxmo_swayinitconf.sh
echo "sxmo_init: invoking sxmo_hook_start.sh with:"
echo "PATH: $PATH"
sxmo_hook_start.sh
'';
in ''
# TODO: some of this is probably unnecessary
mode "menu" {
# just a placeholder for "menu" mode
bindsym --input-device=1:1:1c21800.lradc XF86AudioMute exec nothing
}
bindsym button2 kill
bindswitch lid:on exec sxmo_wm.sh dpms on
bindswitch lid:off exec sxmo_wm.sh dpms off
exec 'printf %s "$SWAYSOCK" > "$XDG_RUNTIME_DIR"/sxmo.swaysock'
exec_always ${sxmo_init}
'';
};
};
sane.programs.sxmoApps.enableFor.user.colin = true;
@@ -279,43 +339,6 @@ in
in
lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings;
sane.user.fs.".config/sway/config".symlink.target = pkgs.substituteAll {
src = ./sway-config;
waybar = "${pkgs.waybar}/bin/waybar";
bemenu_run = "${pkgs.bemenu}/bin/bemenu-run";
term = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec";
sxmo_init = pkgs.writeShellScript "sxmo_init.sh" ''
# perform the same behavior as sxmo_{x,w}init.sh -- but without actually launching wayland/X11
# this amounts to:
# - setting env vars (e.g. getting the hooks onto PATH)
# - placing default configs in ~ for sxmo-launched services (sxmo_migrate.sh)
# - binding vol/power buttons (sxmo_swayinitconf.sh)
# - launching sxmo_hook_start.sh
source ${cfg.package}/etc/profile.d/sxmo_init.sh
# XXX: upstream sources `profile` later (after sxmo_migrate)
# but _sxmo_load_environments uses `SXMO_DEVICE_NAME`,
# and i ship that via the profile, so order it such
source "$XDG_CONFIG_HOME/sxmo/profile"
_sxmo_load_environments
_sxmo_prepare_dirs
sxmo_migrate.sh sync
# kill anything leftover from the previous sxmo run. this way we can (try to) be reentrant
echo "sxmo_init: killing stale daemons (if active)"
sxmo_daemons.sh stop all
pkill bemenu
pkill wvkbd
pkill superd
# configure vol/power-button input mapping (upstream SXMO has this in sway config)
sxmo_swayinitconf.sh
echo "sxmo_init: invoking sxmo_hook_start.sh with:"
echo "PATH: $PATH"
sxmo_hook_start.sh
'';
};
sane.user.fs.".config/sxmo/conky.conf".symlink.target = let
battery_estimate = pkgs.static-nix-shell.mkBash {
pname = "battery_estimate";

View File

@@ -1,270 +0,0 @@
# Read `man 5 sway` for a complete reference.
# TODO: use stock sxmo config & override via /etc/sway/config.d/*
# especially, this will let me avoid issues around `configversion`
### Variables
#
# Mod4 = Logo key
# Mod1 = Alt.
set $mod Mod1
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
# set $term sxmo_terminal.sh
set $term @term@
# 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.
# N.B. bemenu-run relies on BEMENU_OPTS being set: without this it won't even be visible.
set $menu @bemenu_run@
# xwayland enable|disable|force
# - enable: lazily launch xwayland on first client connection
# - disable: never launch xwayland
# - force: launch xwayland immediately on boot
# XWayland uses about 35MB RSS even when idle
xwayland disable
font "Sxmo 10"
# configure vol/power-button input maps
# XXX: this references env vars like SXMO_VOLUME_BUTTON => needs to happen after sourcing profile
# exec_always sxmo_swayinitconf.sh
exec_always dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
mode "menu" {
bindsym --input-device=1:1:1c21800.lradc XF86AudioMute exec nothing # just a placeholder for "menu" mode
}
hide_edge_borders smart
default_border pixel 1
titlebar_border_thickness 1
# XX YY distance from edge of window title to edge of text
# the YY distance here determines the heigh of the overall title
titlebar_padding 12 1
title_align center
# tabbed windows by default
workspace_layout tabbed
### tab colors (#border #background #text [#indicator #childBorder])
# focused & unfocused are the main interest
# urgent is used when an inactive window wants attention (e.g. terminal rings a bell)
# colors are synchronized with waybar and mpv
client.focused #1f5e54 #418379 #ffffff
client.focused_inactive #1f5e54 #5f676a #ffffff
client.unfocused #1f5e54 #1f554c #b4b4b4
client.urgent #ff8080 #ff8080 #ffffff
### Key bindings
#
# Basics:
#
input * xkb_options compose:ralt
# Start a terminal
bindsym $mod+Return exec $term
# Launch appmenu
bindsym $mod+p exec sxmo_appmenu.sh
bindsym $mod+Shift+p exec sxmo_appmenu.sh sys
# Wm menu switcher
bindsym $mod+i exec sxmo_wmmenu.sh windowswitcher
# Kill focused window
bindsym $mod+Shift+q kill
# Start your launcher
bindsym $mod+d exec $menu
# 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
# 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 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
# Move the focused workspace to output
bindsym $mod+Shift+Ctrl+$left move workspace output left
bindsym $mod+Shift+Ctrl+$down move workspace output down
bindsym $mod+Shift+Ctrl+$up move workspace output up
bindsym $mod+Shift+Ctrl+$right move workspace output right
#
# Workspaces:
#
# 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.
#
# 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
# Switch the current container between different layout styles
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# Move focus to the parent container
bindsym $mod+a focus parent
# Manual locker
bindsym $mod+g exec sxmo_hook_locker.sh
# Shutdown
bindsym $mod+t exec sxmo_appmenu.sh power
#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
# Move the currently focused window to the scratchpad
bindsym $mod+Shift+minus move scratchpad
# 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" {
# 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 30px
bindsym $down resize grow height 30px
bindsym $up resize shrink height 30px
bindsym $right resize grow width 30px
# Ditto, with arrow keys
bindsym Left resize shrink width 30px
bindsym Down resize grow height 30px
bindsym Up resize shrink height 30px
bindsym Right resize grow width 30px
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
position top
# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
status_command sxmo_status_watch.sh -o pango
swaybar_command @waybar@
pango_markup enabled
colors {
statusline #ffffff
background #323232
inactive_workspace #32323200 #32323200 #5c5c5c
font "Sxmo 10"
}
}
for_window [app_id="pinentry-.*"] floating true
for_window [app_id="foot" title=".*sxmo/modem/.*/draft.txt.*"] resize set height 25
for_window [title="megapixels"] inhibit_idle open
# Need playerctl installed and running
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioStop exec playerctl stop
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86MonBrightnessUp exec sxmo_brightness.sh up
bindsym XF86MonBrightnessDown exec sxmo_brightness.sh down
bindsym Print exec sxmo_screenshot.sh
bindsym button2 kill
bindswitch lid:on exec sxmo_wm.sh dpms on
bindswitch lid:off exec sxmo_wm.sh dpms off
include /etc/sway/config.d/*
exec 'printf %s "$SWAYSOCK" > "$XDG_RUNTIME_DIR"/sxmo.swaysock'
exec_always @sxmo_init@