-
Notifications
You must be signed in to change notification settings - Fork 0
/
ligma.pl
executable file
·103 lines (82 loc) · 2.2 KB
/
ligma.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
use v5.36;
use AnyEvent;
use Fcntl ':flock';
use FindBin;
use POSIX;
use lib "$FindBin::Bin/Modules/";
use BatteryModule;
use KeyboardModule;
use MusicModule;
use VolumeModule;
use WifiModule;
open(my $lock_fh, '>', "/tmp/ligma.lock") or die "Could not create lock file: $!";
flock($lock_fh, LOCK_EX | LOCK_NB) or die "Another instance of this script is already running.";
# Kill any pactl left behind if killed.
`pkill pactl`;
`pkill cmus-remote`;
# Change process name to make tracking easy.
$0="Ligma";
my $cv = AnyEvent->condvar;
sub print_spectrwm_bar($message) {
print("$message\n");
}
my %modules = (
start => [],
);
sub update_module($position, $index, $content) {
$modules{$position}->[$index] = $content;
}
sub print_bar {
my @start = map { defined($_) ? " $_ " : " <default_value> " } @{$modules{start}};
print_spectrwm_bar(
"@start"
);
}
# Subroutine for bar refresh.
sub update_bar {
print_bar();
}
########Modules#################################################################
#===== Bar printer =====
# This module re-prints the bar every few seconds (timer) to ensure a constant
# output to prevent bugs if lemonbar were to experience a bad formatter.
my $barprinter = AnyEvent->timer(
after => 0,
interval => 2,
cb => \&update_bar
);
#===== CMUS Bar =====
my $music_values = MusicModule::listen_cmus(sub {
my $music = shift;
update_module('start', 0, "$music");
update_bar();
});
#===== Keyboard Distribution =====
my $keyboard_handle = KeyboardModule::listen_keyboard(sub {
my $layout = shift;
update_module('start', 1, "$layout");
update_bar();
});
#===== Wifi Connection =====
my $wifi_handle = WifiModule::listen_wifi(sub {
my $wifi = shift;
update_module('start', 2, "$wifi");
update_bar();
});
# ===== Battery =====
# (Args: BATTERY_ID to monitor. e.g: "BAT0" or "BAT1")
# =====
my $battery_handle = BatteryModule::listen_battery("BAT0", sub {
my $info = shift;
update_module('start', 3, "$info");
print_bar();
});
# ===== Volume =====
my $volume_handle = VolumeModule::listen_volume(sub {
my $volume = shift;
update_module('start', 4, "$volume");
print_bar();
});
AnyEvent->condvar->recv;
1;