2023-10-22 Trying to use Sway as my window manager

I'm hoping to get a MNT Pocket Reform at some point and I heard that it comes with Sway as the default window manager. No problem, I can get into that. Years ago I was a fan of ratpoison and i3. Today, I'm trying to use sway. I think my biggest problem right now is that the pipe/backslash key works like a < and > key. How weird is that. Maybe some weird key binding that is coming back to haunt me.

In order to get started, I copied `/etc/sway/config` to `~/.config/sway/config` and started making some changes.

Scrolling with the touch pad was weird. Somehow inverted! The answer was to have `natural_scroll enabled` for the touchpad input. This didn't always work. And the scroll wheel was different than the touchpad. So right now I'm using the following:

input * {
    dwt enabled
    tap enabled
    middle_emulation disabled
    xkb_layout us
    xkb_variant altgr-intl
    xkb_options compose:caps
}

input type:touchpad {
    natural_scroll enabled
}

This also makes Caps Lock the Compose Key again.

Getting the less key instead of the backslash key remained a problem. There are so many variants in `/usr/share/X11/xkb/symbols/us`. After a while I realised that I needed a variant with LSGT (less/greater) being mapped to `backslash` and `bar`, like this:

key <LSGT> {	[ backslash,         bar	]	};

The options I had seemed to be: `euro`, `ibm2381`, `intl`, and so on. But also anything that contained dead keys was no good:

    key <TLDE> { [dead_grave, dead_tilde,         grave,       asciitilde ] };

In these variants, I have to type every back-quote, single-quote, double-quote and circumflex twice. @bkhl@social.sdfeu.org pointed me to `altgr-intl`. Thanks!

Now I'm wondering about suspending the laptop. With Gnome, I'd hit the GUI key and type "suspend", Enter, done. But there is no "suspend" command. I ended up installing `wlogout` which gives me huge buttons to lock, logout, suspend, hibernate, shutdown and reboot. But, surprisingly, when it suspends, and it comes back, no password is required. That's weird!

I installed `cryptsetup-suspend` which adds something the old setup did not have: returning from a suspend now asks for the disk decryption password but still does not ask for the account password. Well, on a single user system like mine, one of the two is good enough, I guess. But still. And then the other time I tried it (by running wlogout and choosing "suspend") the system would go to sleep and I couldn't find a way to get it back. And when I reset it, it wiped my keyboard's config?? I don't quite understand but I hate all of it. I uninstalled it again.

​#Administration ​#Sway ​#Window Manager

Time has passed and today I added keybindings for lowering and raising the volume.

bindsym XF86AudioLowerVolume exec amixer set Master '10%-'
bindsym XF86AudioRaiseVolume exec amixer set Master '10%+'

So proud of myself. 😁

As for playback from the command-line, right now I'm using `mpv`:

mpv "https://somafm.com/secretagent.pls"

Status bar

OK, time for fiddling with stuff. Every minute, the script called to produce the status bar.

bar {
    position top
    status_command while ~/.config/sway/status.fish; do sleep 60; done
    colors {
        statusline #ffffff
        background #323232
        inactive_workspace #32323200 #32323200 #5c5c5c
    }
}

The script prints something like this:

Bandu 65% 🟑 100% πŸ”Š fully-chargedπŸ”‹ 2023-10-31 15:40

This is the code. As you can see it calls `awk`, `perl` and tons of other stuff. Yikes!

#!/usr/bin/fish
# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.

set date (date +'%Y-%m-%d %R')

set battery (upower --show-info (upower --enumerate | grep 'BAT') | perl -e '
use utf8;
binmode(STDOUT,":utf8");
while (<>) {
  if (/state:\s*(.*)/) {
    print $1;
  } elsif (/percentage:\s*([0-9]+)/) {
    print $1 > 20 ? "πŸ”‹" : "πŸͺ«";
  }
}')
# "amixer -M" gets the mapped volume for evaluating the percentage
# which is more natural to the human ear according to "man amixer".
# The current volume percentage comes in brackets, e.g., "[36%]"
# followed by "[off]" or "[on]" depending on whether sound is muted or
# not. "tr -d []" removes brackets around the volume. I'm looking at
# "Front Left:" because of how amixer reports volumes on my laptop.
set audio_volume (amixer -M get Master |\
awk '/Front Left:/ {print $6=="[off]" ?\
$5" πŸ”‡": \
$5=="[100%]" ? \
$5" πŸ”Š": \
$5" πŸ”‰"}' |\
tr -d [])

set wlan (nmcli --get-values name,device,type connection show --active \
              | grep wireless \
              | string split ':')

# $bar = join("", " β–β–‚β–ƒβ–„β–…β–†β–‡β–ˆ", int(9*$1/$2), 1); \

set ssid $wlan[1]
set device $wlan[2]
set q (/sbin/iwconfig $device | perl -e '
use utf8;
binmode(STDOUT,":utf8");
while (<>) {
  if (/([0-9]+)\/([0-9]+)/) {
    print int(100*$1/$2) . "% " . substr("πŸ”΄πŸŸ πŸŸ‘πŸŸ’πŸŸ’", int(4*$1/$2), 1);
  }
}')
set lan (nmcli --get-values type connection show --active|awk '/ethernet/ { print "πŸ–§" }')

echo $lan $ssid $q $audio_volume $battery $date

I'm learning quite a bit about controlling my system from the command line. I hadn't known about `nmcli`.

In order for the computer to lock when when idle, install `swayidle` (a separate Debian package). Then the following will have the expected effect:

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'

Console

With no more X11, I noticed that `dmenu` no longer worked and I replaced it with `wofi`. The following lets me use GUI+d to start desktop applications and GUI+Shift+d to start binaries on my `$PATH`.

set $desktop-menu wofi --show=drun
set $run-menu wofi --show=run --term=foot

# Start your launcher
bindsym $gui+d exec $desktop-menu
bindsym $gui+Shift+d exec $run-menu

I also had to rebuild Emacs using `./configure --with-pgtk` to get a graphical Emacs without X11.

rebuild Emacs

This is going to be interesting.

bindsym $gui+s         exec fuzzel
bindsym $gui+c         exec $term --window-size-chars=80x25 orpie
bindsym $gui+d         exec evince
bindsym $gui+Period    exec /home/alex/.local/bin/bemoji -t
bindsym $gui+e         exec emacsclient --create-frame --alternate-editor=

The config file sets the terminal and gets rid of transparency:

terminal=foot

[colors]
background=fdf6e3ff
text=657b83ff
match=cb4b16ff
selection=eee8d5ff
selection-text=657b83ff
border=002b36ff

Removing x11proto-dev is also impossible. So many other dev packages seem to depend on it, I suspect Emacs would no longer work.

Removing x11-utils removes Chromium, the backup browser! Now it really starts to hurt.

I guess X11 is here to stay.

exec swaync
bindsym $gui+n         exec swaync-client -t -sw

Oh. And Gimp needs X11? "Cannot open display:" … that's bad.

I tried to use another file manager. Something leaner. Like midnight commander? I also looked at `nnn`. I think it uses `xdg-open` to open files.

Here's what's weird. The default application for PDF files is Gimp instead of Evince. I want to change that, but it appears to have no effect.

alex@melanobombus ~> xdg-mime query default application/pdf
gimp.desktop
alex@melanobombus ~> xdg-mime default Evince.desktop application/pdf
alex@melanobombus ~> cat .config/mimeapps.list

[Default Applications]
application/pdf=Evince.desktop
alex@melanobombus ~> xdg-mime query default application/pdf
gimp.desktop

In desperation, I uninstalled Gimp. The default was set to Libre Office Draw. I uninstalled that, too. Now the default was correct: `org.gnome.Evince.desktop`. What a headache. I'm sure it can be specified somewhere, but I don't know how.

OK, reinstalled Gimp, same problem. But now:

alex@melanobombus ~> xdg-mime default org.gnome.Evince.desktop application/pdf
alex@melanobombus ~> xdg-mime query default application/pdf
org.gnome.Evince.desktop

Oh, and installing xwayland, of course, so that I can run Gimp again.

[Settings]
gtk-application-prefer-dark-theme=1

Sadly, the above only changes my Firefox theme and doesn't seem to affect this site's CSS. The following has no effect:

@media (prefers-color-scheme: dark) {
  …
}

At the console, the following still returns `false`, disappointingly:

window.matchMedia('(prefers-color-scheme: dark)').matches 

It works with Chromium. My Firefox is 115.9.1esr (64-bit). This is unrelated to Sway: The situation is unchanged when I switch to Gnome. I feel like this has worked before?

this has worked before

MNT Pocket Reform

input * {
    dwt enabled
    tap enabled
    middle_emulation disabled
    xkb_layout eu
    # xkb_layout us
    # xkb_variant altgr-intl
    xkb_options compose:caps
}

The tricky parts:

Strangely, on Windows, more combos are possible but Caps Lock is no Compose Key.