From 0ea7a9251f388a1e1225f787ed128a65041a4f64 Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Wed, 18 Sep 2024 18:44:47 -0700 Subject: [PATCH] Restructured DWL startup files --- dwl.entourage | 62 +++-------- dwl.service | 7 +- dwl.session | 2 + dwl_entourage/dwl.bar_setup | 9 ++ dwl_entourage/dwl.idle_setup | 3 + dwl_entourage/dwl.mpd_support_setup | 2 + dwl_entourage/dwl.notification_setup | 7 ++ dwl_entourage/dwl.randr_setup | 3 + dwl_entourage/dwl.wallpaper_setup | 3 + get_randr.pl | 152 +++++++++++++++++++++++++++ 10 files changed, 199 insertions(+), 51 deletions(-) create mode 100644 dwl_entourage/dwl.bar_setup create mode 100644 dwl_entourage/dwl.idle_setup create mode 100644 dwl_entourage/dwl.mpd_support_setup create mode 100644 dwl_entourage/dwl.notification_setup create mode 100644 dwl_entourage/dwl.randr_setup create mode 100644 dwl_entourage/dwl.wallpaper_setup create mode 100755 get_randr.pl diff --git a/dwl.entourage b/dwl.entourage index 32b39fb..7d98ff3 100755 --- a/dwl.entourage +++ b/dwl.entourage @@ -5,35 +5,7 @@ function log_this() { echo "$TSTMP : " $1 >> $DWL_LOG_FILE } -log_this "Entourage: $XDG_RUNTIME_DIR - $DWL_TAGS_FILE" - -NUM_DISPS=$(wlr-randr | grep -E "^\w+" | wc -l) -log_this "Entourage: Configuring ${NUM_DISPS} displays" - -if [[ $NUM_DISPS > 1 ]]; then - # Dual screen - # wlr-randr --output HDMI-A-1 --on --pos 0,0 --output eDP-1 --on --pos 0,1050 - # wlr-randr --output HDMI-A-1 --on --pos 0,0 --output eDP-1 --on --pos 2560,0 - - # With Dell 1920x1200 display - vertical arrangement - # - # .--------------------------------. - # | | - # | DELL 24" 1920x1200 | - # | (HDMI-A-1) | - # | | - # `--------------------------------' - # | | - # | LAPTOP 13" 1366x768 | - # | (eDP-1) | - # | | - # `-------------------------' - # - wlr-randr --output HDMI-A-1 --on --pos 0,0 --output eDP-1 --on --pos 300,1200 -else - # Single laptop screen - wlr-randr --output HDMI-A-1 --off --output eDP-1 --on --pos 0,0 -fi +log_this "Entourage: $XDG_RUNTIME_DIR" # ---------------------------------------------------------- # Let DWL start @@ -44,32 +16,24 @@ do sleep 1 done log_this "DWL ready!" -log_this "Entourage: $DWL_TAGS_FILE" # ---------------------------------------------------------- -# Background +# Background and support tasks # ---------------------------------------------------------- # TODO: Consuimng too much CPU - keeps fan spinning -# swaybg --mode fill --image ~/.config/wallpaper.jpg & +# source ~/bin/dwl.wallpaper_setup -# ---------------------------------------------------------- -# Lock when idle -# ---------------------------------------------------------- log_this "Entourage: Starting screen locker with 10min idle time" -swayidle -w timeout 600 swaylock & +source ~/bin/dwl.idle_setup -# ---------------------------------------------------------- -# Redirect STDIN to STDOUT and pass along to tags script -# ---------------------------------------------------------- -DWL_BAR=$DWL_BAR_PATH/somebar +log_this "Entourage: Configuring $(wlr-randr | grep -E "^\w+" | wc -l) displays" +source ~/bin/dwl.randr_setup + +log_this "Entourage: Setting up notification" +source ~/bin/dwl.notification_setup + +log_this "Entourage: Setting up MPD support" +source ~/bin/dwl.mpd_support_setup -export SOMEBAR_FIFO=$XDG_RUNTIME_DIR/somebar.fifo -mkfifo $SOMEBAR_FIFO -m666 log_this "Entourage: Starting somebar using $SOMEBAR_FIFO" -conky -c ~/.conkyrc > $SOMEBAR_FIFO & - -(while read line -do - echo $line -done) | ($DWL_BAR -s $SOMEBAR_FIFO > $XDG_RUNTIME_DIR/somebar.log 2>&1) - +source ~/bin/dwl.bar_setup diff --git a/dwl.service b/dwl.service index 690e1c3..eb807ff 100644 --- a/dwl.service +++ b/dwl.service @@ -1,9 +1,12 @@ # Systemd service to start DWL # ---------------------------------------------------------- # -# Put this file in following directory: +# Symlink this file in following directory as follows: # -# ~/.config/systemd/user +# $ cd ~/.config/systemd/user +# $ ln -s /dwl.service dwl@.service +# +# Be sure to link it as a named service with (@.service) # # Start this service with something like this: # diff --git a/dwl.session b/dwl.session index 947da12..e02a597 100755 --- a/dwl.session +++ b/dwl.session @@ -7,6 +7,8 @@ export DWL_PATH=/usr/local/bin # export DWL_PATH=/home/mahesh/git/furnish/heshapps_dwl export DWL_BAR_PATH=/usr/local/bin # export DWL_BAR_PATH=/home/mahesh/git/somebar_20240217/build +export DWL_BAR=$DWL_BAR_PATH/somebar +export SOMEBAR_FIFO=$XDG_RUNTIME_DIR/somebar.fifo # export DWLTAGS_SHOW_MON=1 export PATH=~/bin:$PATH diff --git a/dwl_entourage/dwl.bar_setup b/dwl_entourage/dwl.bar_setup new file mode 100644 index 0000000..4318dce --- /dev/null +++ b/dwl_entourage/dwl.bar_setup @@ -0,0 +1,9 @@ + +killall conky +killall somebar + +mkfifo $SOMEBAR_FIFO -m666 +conky -c ~/.conkyrc > $SOMEBAR_FIFO & + +$DWL_BAR -s $SOMEBAR_FIFO > $XDG_RUNTIME_DIR/somebar.log 2>&1 + diff --git a/dwl_entourage/dwl.idle_setup b/dwl_entourage/dwl.idle_setup new file mode 100644 index 0000000..b77b689 --- /dev/null +++ b/dwl_entourage/dwl.idle_setup @@ -0,0 +1,3 @@ + +swayidle -w \ + timeout 600 'systemctl hybrid-sleep' & diff --git a/dwl_entourage/dwl.mpd_support_setup b/dwl_entourage/dwl.mpd_support_setup new file mode 100644 index 0000000..f4d5300 --- /dev/null +++ b/dwl_entourage/dwl.mpd_support_setup @@ -0,0 +1,2 @@ + +musnify-mpd -h localhost -p 6600 & diff --git a/dwl_entourage/dwl.notification_setup b/dwl_entourage/dwl.notification_setup new file mode 100644 index 0000000..cbf2d8f --- /dev/null +++ b/dwl_entourage/dwl.notification_setup @@ -0,0 +1,7 @@ + +mako --font "Iosevka Term" \ + --background-color "#777777AA" \ + --text-color "#EEEEEE" \ + --border-color "#777777AA" \ + --border-radius 5 \ + --default-timeout 5000 & diff --git a/dwl_entourage/dwl.randr_setup b/dwl_entourage/dwl.randr_setup new file mode 100644 index 0000000..7aeadac --- /dev/null +++ b/dwl_entourage/dwl.randr_setup @@ -0,0 +1,3 @@ + +cmd=$(get_randr.pl) +$cmd diff --git a/dwl_entourage/dwl.wallpaper_setup b/dwl_entourage/dwl.wallpaper_setup new file mode 100644 index 0000000..e5a607f --- /dev/null +++ b/dwl_entourage/dwl.wallpaper_setup @@ -0,0 +1,3 @@ + +swaybg --mode fill --image ~/.config/wallpaper.jpg & + diff --git a/get_randr.pl b/get_randr.pl new file mode 100755 index 0000000..ee2568b --- /dev/null +++ b/get_randr.pl @@ -0,0 +1,152 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Data::Dumper; + +unless (exists $ENV{'WAYLAND_DISPLAY'}) { + die "Not running in WAYLAND"; +} + +my $app = {}; +$app->{'displays'} = {}; + +get_display_info($app); +show_debug(Data::Dumper->Dump([$app])); +my $wlr_line = get_wlr_line($app); + +print "${wlr_line}\n"; + +# ----------- +# Subroutines +# ----------- +sub get_display_info { + my ($app) = @_; + + open (my $RANDRH, "wlr-randr |") or die "Couldn't run wlr-randr"; + my @lines = map { chomp(); $_ } <$RANDRH>; + close ($RANDRH); + + my $state = "IDLE"; + my $curr_disp = "UNDEF"; + my $disp_info = {}; + + foreach my $ln (@lines) { + if (my ($dn, $dd) = $ln =~ /^(\S+)\s+"([^"]+)"$/) { + $state = "IN_DISP"; + + unless (exists $disp_info->{$dn}) { + $disp_info->{$dn} = {}; + $disp_info->{$dn}->{'name'} = $dn; + $curr_disp = $dn; + + $disp_info->{$dn}->{'desc'} = $dd; + + } + } + if (($state eq "IN_DISP") || ($state eq "IN_MODES")) { + if (my ($k,$v) = $ln =~ /\s+(\w+)\s*:\s*(.*)?$/) { + if ($k eq "Modes") { + $state = "IN_MODES"; + $disp_info->{$curr_disp}->{'modes'} = []; + } else { + $disp_info->{$curr_disp}->{$k} = $v; + $state = "IN_DISP" + } + } + } + if ($state eq "IN_MODES") { + if (my ($mode_string) = $ln =~ /\s+(.+)$/) { + # 1920x1080 px, 60.000999 Hz (preferred, current) + my ($h, $v, $f, $a) = $mode_string =~ /(\d+)x(\d+)\s*px,\s*(\S+)\s*Hz\s*\((.*)\)$/; + my $mode_info = {}; + $mode_info->{'horizontal'} = $h; + $mode_info->{'vertical'} = $v; + $mode_info->{'refresh_freq'} = $f; + if (defined $a) { + $mode_info->{'attributes'} = [split (/\s*,\s*/, $a)]; + if ($a =~ /current/) { + $disp_info->{$curr_disp}->{'current_mode'} = $mode_info; + } + if ($a =~ /preferred/) { + $disp_info->{$curr_disp}->{'preferred_mode'} = $mode_info; + } + } + + push(@{$disp_info->{$curr_disp}->{'modes'}}, $mode_info); + + } + } + # show_debug("$state: $ln"); + } + + $app->{'displays'} = $disp_info; +} + +# ----------- +sub get_wlr_line { + my ($app) = @_; + + my $wlr_line = "UNKNOWN"; + + my $num_disps = scalar(keys(%{$app->{'displays'}})); + if ($num_disps == 1) { + show_debug("Single display configuration"); + $wlr_line = "wlr-randr --output HDMI-A-1 --off --output eDP-1 --on --pos 0,0" + } elsif ($num_disps > 1) { + # Determine setup (Custom) + # + # - Den room (DELL 27" monitor on the left of laptop display) + my $matching_disps = has_display_with_name($app, "DELL U27"); + if (scalar (@{$matching_disps}) == 1) { + my ($h, $v) = get_display_current_dimensions($app, $matching_disps->[0]); + my $disp_name = $matching_disps->[0]->{'name'}; + show_debug("Multiple display configuration: Den room"); + + $wlr_line = "wlr-randr --output ${disp_name} --on --pos 0,0 --output eDP-1 --on --pos ${h},0"; + } + + # + # - Media room (DELL 24" monitor above laptop display) + $matching_disps = has_display_with_name($app, "DELL U24"); + if (scalar (@{$matching_disps}) == 1) { + my ($h, $v) = get_display_current_dimensions($app, $matching_disps->[0]); + my $disp_name = $matching_disps->[0]->{'name'}; + show_debug("Multiple display configuration: Media room"); + + $wlr_line = "wlr-randr --output ${disp_name} --on --pos 0,0 --output eDP-1 --on --pos 0,${v}"; + } + } else { + show_debug("No displays?!"); + } + + return $wlr_line; +} + +# ----------- +sub has_display_with_name { + my ($app, $name) = @_; + my $found = []; + + foreach my $k (keys %{$app->{'displays'}}) { + if ($app->{'displays'}->{$k}->{'desc'} =~ /$name/) { + push(@{$found}, $app->{'displays'}->{$k}); + } + } + + return $found; +} + +# ----------- +sub get_display_current_dimensions { + my ($app, $disp) = @_; + + return ($disp->{'current_mode'}->{'horizontal'}, $disp->{'current_mode'}->{'vertical'}); +} + +# ----------- +sub show_debug { + my ($str) = @_; + # UNCOMMENT TO DEBUG # print "[DEBUG] $str\n"; +}