diff --git a/distrobox/debian12/wallpaper.pl b/distrobox/debian12/wallpaper.pl new file mode 100755 index 0000000..1f8024e --- /dev/null +++ b/distrobox/debian12/wallpaper.pl @@ -0,0 +1,24 @@ +#!/bin/sh +# distrobox_binary +# name: debian12 +if [ ! -f /run/.containerenv ] && [ ! -f /.dockerenv ]; then + command="/usr/bin/distrobox-enter -n debian12 -- /var/home/jpm/scripts/sway/wallpaper.pl --path=/var/home/jpm/wallpapers -d HDMI-A-1 " + + for arg in "$@"; do + if echo "${arg}" | grep -Eq "'|\""; then + command="${command} \ + $(echo "${arg}" | sed 's|\\|\\\\|g' | + sed 's| |\\ |g' | + sed 's|\$|\\\$|g' | + sed "s|'|\\\'|g" | + sed 's|"|\\\"|g')" + elif echo "${arg}" | grep -q "'"; then + command="${command} \"${arg}\"" + else + command="${command} '${arg}'" + fi + done + eval ${command} +else + /var/home/jpm/scripts/sway/wallpaper.pl /var/home/jpm/scripts/sway/wallpaper.pl --path=/var/home/jpm/wallpapers -d HDMI-A-1 "$@" +fi diff --git a/sway/arrange.pl b/sway/arrange.pl new file mode 100755 index 0000000..5d03ebf --- /dev/null +++ b/sway/arrange.pl @@ -0,0 +1,82 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use AnyEvent::Sway; +our $s = AnyEvent::Sway->new(); + +sub switch +{ + my $workspace = shift; + return defined($s->message(0,"workspace $workspace")->recv->[0]->{'success'}); +} + +sub move +{ + my $output = shift; + return defined($s->message(0,"move workspace to output $output")->recv->[0]->{'success'}); +} + +sub assign +{ + my $workspace = shift; + my $output = shift || die('No output argument given'); + + return 0 unless (switch($workspace)); + return 0 unless (move($output)); + return 1; +} + +my $workspaces = { + '0' => [ 'DP-1', 'eDP-1' ], # HUD + '1' => [ 'DP-1', 'eDP-1' ], # Chat (mattermost, rocket.chat) + '2' => [ 'DP-1', 'eDP-1' ], # Mail (thunderbird) + '3' => [ 'DP-1', 'eDP-1' ], # Secondary browser (ungoogled chromium) + '4' => [ 'DP-1', 'eDP-1' ], # Git (gittyup) + '5' => [ 'HDMI-A-1', 'eDP-1' ], # TBD + '6' => [ 'HDMI-A-1', 'eDP-1' ], # Terminals (gnome-terminal) - not auto-assigned since they are used everywhere + '7' => [ 'HDMI-A-1', 'eDP-1' ], # Browser (firefox) + '8' => [ 'HDMI-A-1', 'eDP-1' ], # IDE (neovide, vscode) + '9' => [ 'HDMI-A-1', 'eDP-1' ], # Music (WIP) + # Miscellaneous Extras + 'c0' => [ 'DP-1', 'eDP-1' ], + 'c1' => [ 'DP-1', 'eDP-1' ], + 'c2' => [ 'DP-1', 'eDP-1' ], + 'c3' => [ 'DP-1', 'eDP-1' ], + 'c4' => [ 'DP-1', 'eDP-1' ], + 'c5' => [ 'HDMI-A-1', 'eDP-1' ], + 'c6' => [ 'HDMI-A-1', 'eDP-1' ], + 'c7' => [ 'HDMI-A-1', 'eDP-1' ], + 'c8' => [ 'HDMI-A-1', 'eDP-1' ], + 'c9' => [ 'HDMI-A-1', 'eDP-1' ], +}; + +my $outputs = ($s->get_outputs->recv())[0]; +my $focused; +my %attached; +foreach my $o (@{$outputs}) { + $focused = $o->{'current_workspace'} if ($o->{'focused'}); + if ($o->{'active'}) { + $attached{$o->{'name'}} = $o->{'current_workspace'}; + } +} + +foreach my $w (keys(%{$workspaces})) { + foreach my $o (@{$workspaces->{$w}}) { + if (defined($attached{$o})) { + last() if assign($w, $o); + print STDERR ("Failed to assign $w to $o\n") + } + } +} + +# Favour for which workspace should be focused at the end should follow this logic: +# - Focused window should return to being focused, regardless of the display. +# - Any workspaces which were currently visible at the start should be made current again (multiple could be on the same output, pick random) +# - Any output which is has neither of the above should just be left with the last switch +# Laziest just to switch to those in reverse order, even if it means a few extra switches +foreach (keys(%attached)) { + switch($attached{$_}); +} +switch($focused); diff --git a/sway/displays.pl b/sway/displays.pl index 42c4d16..398726f 100755 --- a/sway/displays.pl +++ b/sway/displays.pl @@ -76,7 +76,7 @@ my %configs = ( 'rotate' => 90, 'scale' => 2, 'waybar' => 'top', - 'fallback' => '#fefefe', + 'fallback' => '#010101', }, 'TV' => { 'on' => 1, diff --git a/sway/sway-alt-tab.sh b/sway/sway-alt-tab.sh new file mode 100644 index 0000000..9ca4685 --- /dev/null +++ b/sway/sway-alt-tab.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +swaymsg -t get_tree | + jq -r '.nodes[].nodes[] | if .nodes then [recurse(.nodes[])] else [] end + .floating_nodes | .[] | select(.nodes==[]) | ((.id | tostring) + " " + .name)' | + wofi --show dmenu -c .dotfiles/wofi/sidebar | { + read -r id name + swaymsg "[con_id=$id]" focus + } diff --git a/sway/sway-transparency.service b/sway/sway-transparency.service new file mode 100644 index 0000000..d0e2e8f --- /dev/null +++ b/sway/sway-transparency.service @@ -0,0 +1,15 @@ +[Unit] +Description=Sway window transparency daemon +PartOf=graphical-session.target +After=sway.service + +[Service] +Type=simple +ExecStart=/var/home/jpm/scripts/distrobox/debian12/sway-transparency.sh +Restart=unless-stopped +Requires=dbus.service +After=dbus.service +TimeoutSec=5 + +[Install] +WantedBy=default.target diff --git a/sway/wallpapers.service b/sway/wallpapers.service index d430f51..82ff2bd 100644 --- a/sway/wallpapers.service +++ b/sway/wallpapers.service @@ -5,9 +5,9 @@ Description=Rotate through cropped wallpapers for %u Type=forking #PIDFile=/var/home/%u/.spool/wallpaper.pid WorkingDirectory=/var/home/%u/.spool -ExecStart=/usr/bin/distrobox enter debian12 -- "$HOME/scripts/sway/wallpaper.pl -d --path=/home/jpm/wallpapers `cat $HOME/.spool/wallpaper_outputs`" -#ExecStart=/var/home/%u/scripts/sway/wallpaper.pl -d --path=/home/jpm/wallpapers +ExecStart=/var/home/%u/scripts/distrobox/debian12/wallpaper.pl Restart=always +TimeoutSec=5 [Install] WantedBy=graphical.target