#!/usr/bin/env perl use strict; use warnings; use POSIX qw(setsid); use constant PIDFILE => '/tmp/halfcab.pid'; my @keys = ( 'warm', 'sex', 'purp', 'blues', 'burn', 'white', 'off', 'scr', ); my @values = ( 'hc 214 90 10', 'hc 255 0 0', 'hc 255 0 255', 'hc 150 150 255', 'hc 214 50 0', 'hc 255 200 150', 'hc 0 0 0', '', ); my %list; @list{@keys} = @values; sub dmhc { my $choice; my $url; my $pid; my $prefix; my $list; my $color; my $read_pid; $color = '#cc241d'; if (@ARGV == 1) { $color = $ARGV[0]; } $list = join("\n", @keys); $choice = `printf "$list" | dmenu -i -sb '$color' -shb '$color'`; chomp($choice); return unless exists $list{$choice}; if (-e PIDFILE) { open(my $fh, '<', PIDFILE); $read_pid = <$fh>; chomp($read_pid); close($fh); kill('TERM', $read_pid); while (kill(0, $read_pid) != 0) { sleep(0.05); } unlink(PIDFILE); } $pid = fork(); if ($pid > 0 && $choice eq 'scr') { open(my $fh, '>', PIDFILE) or die $!; print $fh $pid; close($fh); } elsif (not $pid) { exec($list{$choice}) if $choice ne 'scr'; setsid(); my $grep = system( 'xrandr | command grep -E "DP-4.+\+1920" >/dev/null 2>&1' ); exec('hc 1920') if not $grep; exec('hc'); } return; } dmhc(); __END__