DWL launching with systemd and setup changes

This commit is contained in:
2021-05-25 22:23:50 -07:00
parent d2386bca8d
commit b794ef8737
4 changed files with 103 additions and 34 deletions

View File

@@ -5,8 +5,14 @@ use warnings;
use Data::Dumper;
use Term::ANSIColor;
use FileHandle;
use Getopt::Long;
my $info = {};
my $tags_file = $ENV{'DWLTAGS_FILE'};
my $log_file = $ENV{'XDG_RUNTIME_DIR'} . "/dwl.log";
GetOptions("file=s" => \$tags_file)
or die("Command line usage error");
# Color scheme is only used in ANSI mode
# <class>_f/_g: class is used in JSON mode to be used in style.css for styling
@@ -33,34 +39,38 @@ my $colorscheme = {
# 'title_b' => 'black'
};
print_log("DWLTAGS: $tags_file");
print_tags({
'selmon' => '1',
'tags' => '1 1',
'title' => '',
'layout' => '[]='
});
}, $tags_file);
while (<>) {
my $line = $_;
chomp $line;
# print_log("DWLTAGS [VV] : $line");
if (my ($mon, $key, $val) = $line =~ /^(\S+)\s+(\S+)\s(.*)$/) {
$info->{$key} = $val;
if ($key eq "layout") {
# Commit a status
# Assumption: layout is the last piece of information dumped by DWL
$info->{'mon'} = $mon;
print_tags($info);
print_tags($info, $tags_file);
$info = {};
}
} else {
print "DWL: Printed out of format\n";
print_log("DWL: Printed out of format - $line");
}
}
sub print_tags {
my ($info) = @_;
my ($info, $tags_file) = @_;
my $numtags = 10;
return if ($info->{'selmon'} ne "1");
@@ -85,13 +95,13 @@ sub print_tags {
$tags .= getformatted("lay", " $info->{'layout'} ");
$tags .= getformatted("title", " $info->{'title'} ");
my $fh = FileHandle->new("> " . $ENV{'DWLTAGS_FILE'});
my $fh = FileHandle->new("> " . $tags_file);
if (defined $fh) {
print $fh $tags . "\n";
$fh->close;
}
} else {
print "DWL: Printed out of format - tags\n";
print_log("DWL: Printed out of format - tags");
}
}
@@ -120,3 +130,12 @@ sub dzen_colored {
# return colored([$colorscheme->{$c . '_f'} . " on_" . $colorscheme->{$c . '_b'}], $txt);
return "^fg(" . $fc . ")^bg(" . $bc . ")" . $txt . "^fg()^bg()";
}
sub print_log {
my ($line) = @_;
my $fh = FileHandle->new(">> " . $ENV{'XDG_RUNTIME_DIR'} . "/dwl.log");
if (defined $fh) {
print $fh $line . "\n";
$fh->close;
}
}