Restructured DWL startup files

This commit is contained in:
Mahesh Asolkar 2024-09-18 18:44:47 -07:00
parent d9cca35b59
commit 0ea7a9251f
10 changed files with 199 additions and 51 deletions

View File

@ -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

View File

@ -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 <snips>/dwl.service dwl@.service
#
# Be sure to link it as a named service with (@.service)
#
# Start this service with something like this:
#

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
swayidle -w \
timeout 600 'systemctl hybrid-sleep' &

View File

@ -0,0 +1,2 @@
musnify-mpd -h localhost -p 6600 &

View File

@ -0,0 +1,7 @@
mako --font "Iosevka Term" \
--background-color "#777777AA" \
--text-color "#EEEEEE" \
--border-color "#777777AA" \
--border-radius 5 \
--default-timeout 5000 &

View File

@ -0,0 +1,3 @@
cmd=$(get_randr.pl)
$cmd

View File

@ -0,0 +1,3 @@
swaybg --mode fill --image ~/.config/wallpaper.jpg &

152
get_randr.pl Executable file
View File

@ -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";
}