Posted by Bums wmiircpl on Fri 16th Mar 19:39 (modification of post by view diff)
download | new post
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use threads;
- use 5.010;
- use File::Basename; # fileparse
- use IO::Socket::UNIX;
- $SIG{CHLD} = 'IGNORE';
- pipe EVENT_READ, EVENT_WRITE;
- my $CLIENT;
- sub ycreate {
- my ($file, $data) = @_;
- xcreate($CLIENT, $file, $data);
- }
- sub yremove {
- my ($file) = @_;
- xremove($CLIENT, $file);
- }
- sub ylist {
- my ($dir) = @_;
- }
- sub yread {
- my ($file) = @_;
- xread($CLIENT, $file, -1);
- }
- sub ywrite {
- my ($file, $data) = @_;
- xwrite($CLIENT, $file, $data);
- }
- sub launch_external {
- die 'Couldn\'t fork';
- } elsif (not $pid) {
- exit;
- }
- }
- sub gen_proglist {
- my ($proglist_fh, $proglist_file) = tempfile();
- my @progs = ();
- for my $p (@path) {
- }
- return $proglist_file;
- }
- sub all_tags {
- }
- sub tagmenu {
- return `echo -e $tags | wimenu`;
- }
- sub float {
- ywrite('/tag/sel/ctl', 'select ~');
- }
- }
- sub cur_tag_info {
- my $ctl = yread('/tag/sel/ctl');
- }
- sub cur_tag {
- }
- sub extract_colors {
- }
- sub shift_tag {
- my @tags = all_tags();
- my $cur = cur_tag();
- $tags[((first {$tags[$_] eq $cur} 0..$#tags) + $dir) % @tags];
- }
- my @tag_stack;
- sub update_tag_stack {
- my ($tag) = @_;
- @tag_stack = @temp_stack;
- }
- my $VLC_SOCK = '/tmp/vlc.sock';
- sub vlc_cmd {
- my ($cmd) = @_;
- }
- ### Change current directory
- ### Set some values
- my $USER = $ENV{USER};
- $CLIENT = "unix!/tmp/ns.$USER.$DISPLAY/wmii";
- my $proglist_file = gen_proglist();
- ### General configuration
- my $term='urxvt';
- my $normal_fg = '#ffffff';
- my $normal_bg = '#000000';
- my $normal_brd = '#444444';
- my $focus_brd = '#ffffff';
- my $urgent_bg = '#ff6600';
- my $offline_bg = '#444444';
- my $normal_colors = "$normal_fg $normal_bg $normal_brd";
- my $focus_colors = "$normal_fg $normal_bg $focus_brd";
- my $urgent_colors = "$normal_fg $urgent_bg $normal_brd";
- my $offline_colors = "$normal_fg $offline_bg $normal_brd";
- my $battery_path = '/sys/class/power_supply/BAT1';
- my %key = (
- mod => 'Mod4',
- mod_alt => 'Mod1',
- left => 'h',
- down => 'j',
- up => 'k',
- right => 'l',
- toggle => 'space',
- );
- my $loadavg_alert = 4;
- my $loadavg_warn = 2;
- ### Init wmii
- ywrite('/event', 'Start wmiirc');
- ywrite('/ctl', "normcolors $normal_colors");
- ywrite('/ctl', "focuscolors $focus_colors");
- ywrite('/ctl', "grabmod $key{mod}");
- ### Set up keys
- my %keys = (
- "$key{mod}-Return" => sub {
- launch_external($term);
- },
- "$key{mod}-Shift-c" => sub {
- ywrite('/client/sel/ctl', 'kill');
- },
- "$key{mod}-d" => sub {
- ywrite('/tag/sel/ctl', 'colmode sel default-max');
- },
- "$key{mod}-s" => sub {
- ywrite('/tag/sel/ctl', 'colmode sel stack-max');
- },
- "$key{mod}-m" => sub {
- ywrite('/tag/sel/ctl', 'colmode sel stack+max');
- },
- "$key{mod}-f" => sub {
- ywrite('/client/sel/ctl', 'Fullscreen toggle');
- },
- "$key{mod}-t" => sub {
- my $result = tagmenu();
- ywrite('/ctl', "view $result");
- },
- "$key{mod}-Shift-t" => sub {
- my $result = tagmenu();
- ywrite('/client/sel/tags', $result);
- },
- "$key{mod}-a" => sub {
- my @tags = ylist('/lbar');
- for my $tag (@tags) {
- my $colors = extract_colors(yread("/lbar/$tag"));
- if ($colors eq $urgent_colors) {
- ywrite('/ctl', "view $tag");
- last;
- }
- }
- },
- "$key{mod}-Left" => sub {
- my $new_tag = shift_tag(-1);
- ywrite('/ctl', "view $new_tag");
- },
- "$key{mod}-Right" => sub {
- my $new_tag = shift_tag(+1);
- ywrite('/ctl', "view $new_tag");
- },
- "$key{mod}-Tab" => sub {
- my $prev_tag = $tag_stack[-2];
- ywrite('/ctl', "view $prev_tag");
- },
- "$key{mod}-p" => sub {
- launch_external("\$(wimenu <$proglist_file)");
- },
- "$key{mod_alt}-space" => sub {
- float();
- launch_external("$term -e alsamixer");
- },
- "$key{mod}-w" => sub {
- float();
- launch_external('~/uw-weather/fetch.pl | xmessage -default okay -center -file -');
- },
- 'XF86AudioMute' => sub {
- launch_external('amixer set Master toggle');
- },
- 'XF86MonBrightnessDown' => sub {
- launch_external('setlap \'b!d\' q');
- },
- 'XF86MonBrightnessUp' => sub {
- launch_external('setlap \'b!u\' q');
- },
- 'Control-Shift-Up' => sub {
- launch_external('setxkbmap -layout us');
- },
- 'Control-Shift-Down' => sub {
- launch_external('setxkbmap -layout ru');
- },
- 'Print' => sub {
- launch_external('import /tmp/foo.png');
- },
- 'XF86AudioPlay' => sub {
- vlc_cmd('pause');
- },
- 'Shift-XF86AudioPlay' => sub {
- vlc_cmd('play');
- },
- 'XF86AudioStop' => sub {
- vlc_cmd('stop');
- },
- 'XF86AudioNext' => sub {
- vlc_cmd('next');
- },
- 'XF86AudioPrev' => sub {
- vlc_cmd('prev');
- },
- 'Shift-XF86AudioNext' => sub {
- vlc_cmd('key key-jump+short');
- },
- 'Shift-XF86AudioPrev' => sub {
- vlc_cmd('key key-jump-short');
- },
- );
- $keys{Caps_Lock} = $keys{"$key{mod}-t"};
- for my $dir ('left', 'down', 'up', 'right', 'toggle') {
- $keys{"$key{mod}-$key{$dir}"} = sub {
- ywrite('/tag/sel/ctl', "select $dir");
- };
- $keys{"$key{mod}-shift-$key{$dir}"} = sub {
- ywrite('/tag/sel/ctl', "send sel $dir");
- };
- }
- for my $tag (0..9) {
- $keys{"$key{mod}-$tag"} = sub {
- ywrite('/ctl', "view $tag");
- };
- $keys{"$key{mod}-Shift-$tag"} = sub {
- ywrite('/client/sel/tags', $tag);
- };
- }
- ### Set up statuses
- my @statuses = (
- sub { # spacer
- },
- sub { # speakers
- my $bar = "/rbar/$_[0]";
- for (;;) {
- my ($volume, $on);
- while (<MIXER>) {
- if (/front left:.*?\[(-?[\d.]+)dB\].*?\[(o[fn]+)\]/i) {
- ($volume, $on) = ($1, $2 ne 'off');
- last;
- }
- }
- my $colors;
- if ($on) {
- } else {
- $colors = $offline_colors;
- }
- ywrite($bar, "$colors ${volume} dB");
- usleep(2_000_000);
- }
- },
- sub { # load average
- my $bar = "/rbar/$_[0]";
- for (;;) {
- my $colors;
- if ($la > $loadavg_alert) {
- $colors = "$normal_fg #ff0000 #ff0000";
- } elsif ($la > $loadavg_warn) {
- } else {
- $colors = $normal_colors;
- }
- ywrite($bar, "$colors $la");
- usleep(5_000_000);
- }
- },
- sub { # backlight
- my $bar = "/rbar/$_[0]";
- for (;;) {
- my $brightness = <BACKLIGHT>;
- ywrite($bar, "b$brightness");
- usleep(1_000_000);
- }
- },
- sub { # cpu temp
- my $bar = "/rbar/$_[0]";
- for (;;) {
- my $temp = <CPU_TEMP> / 1000;
- my $colors;
- if ($temp > 75) {
- $colors = "$normal_fg #ff0000 #ff0000";
- } elsif ($temp >= 55) {
- } else {
- $colors = $normal_colors;
- }
- ywrite($bar, "$colors $temp C");
- usleep(1_000_000);
- }
- },
- sub { # battery
- my $bar = "/rbar/$_[0]";
- for (;;) {
- if (-e $battery_path) {
- my $status = <BATTERY>;
- my $now = <BATTERY>;
- my $full = <BATTERY>;
- my $ratio = $now / $full;
- my $border;
- given ($status) {
- when (/^charging/i) { $border = '#00ff00' };
- when (/^full/i) { $border = $normal_brd };
- default { $border = '#ff0000' };
- }
- } else {
- ywrite($bar, "$offline_colors ???%");
- }
- usleep(5_000_000);
- }
- },
- sub { # time
- my $bar = "/rbar/$_[0]";
- for (;;) {
- usleep(500_000);
- }
- },
- );
- ### Set up lbar for existing tags
- yremove("/lbar/$_") for ylist('/lbar');
- my $cur_tag = cur_tag();
- for my $tag (all_tags()) {
- if ($tag eq $cur_tag) {
- ycreate("/lbar/$tag", "$focus_colors $tag");
- } else {
- ycreate("/lbar/$tag", "$normal_colors $tag");
- }
- }
- ### And get the statuses going
- yremove("/rbar/$_") for ylist('/rbar');
- for my $status (0..$#statuses) {
- ycreate("/rbar/$status", '');
- my $thr = threads->create($statuses[$status], $status);
- $thr->detach();
- }
- ### Event loop!
- die 'Couldn\'t fork';
- } elsif (not $event_child) {
- # Since /event doesn't get EOF until wmii exits, this hangs forever.
- exit; # But just in case.
- }
- END {
- # Kill the child that has the xread call for /event
- }
- while (<EVENT_READ>) {
- if (/^Start wmiirc$/) {
- last;
- } elsif (/^Key (.*)$/) {
- $keys{$1}();
- }
- } elsif (/^CreateTag (.*)/) {
- ycreate("/lbar/$1", "$normal_colors $1");
- } elsif (/^DestroyTag (.*)/) {
- yremove("/lbar/$1");
- } elsif (/^FocusTag (.*)/) {
- update_tag_stack($1);
- ywrite("/lbar/$1", "$focus_colors $1");
- } elsif (/^UnfocusTag (.*)/) {
- ywrite("/lbar/$1", "$normal_colors $1");
- } elsif (/^UrgentTag [^ ]+ (.*)/) {
- if (cur_tag() ne $1) {
- ywrite("/lbar/$1", "$urgent_colors $1");
- }
- } elsif (/^NotUrgentTag [^ ]+ (.*)/) {
- if (cur_tag() ne $1) {
- ywrite("/lbar/$1", "$normal_colors $1");
- }
- } elsif (/^LeftBarMouseDown \d+ (.*)/) {
- ywrite('/ctl', "view $1");
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.