diff options
author | Ismo Toijala | 2015-06-26 10:41:19 +0200 |
---|---|---|
committer | Ismo Toijala | 2015-06-26 10:41:19 +0200 |
commit | c2f724140459fbaa86edf6c76b6a1efca5e72dcc (patch) | |
tree | 38061fbb7fb7fc53e2b13e58cfad62307cf2f9ad | |
download | aur-c2f724140459fbaa86edf6c76b6a1efca5e72dcc.tar.gz |
initial upload
-rw-r--r-- | .SRCINFO | 18 | ||||
-rw-r--r-- | PKGBUILD | 22 | ||||
-rw-r--r-- | i3-wsbar | 107 |
3 files changed, 147 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..01f064f68931 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,18 @@ +# Generated by makepkg 4.2.1 +# Fri Jun 26 08:36:24 UTC 2015 +pkgbase = i3-wsbar + pkgdesc = i3 workspace output for dzen2 + pkgver = 1 + pkgrel = 2 + url = https://i3wm.org/ + arch = any + license = BSD + depends = dzen2 + depends = perl-ipc-run + depends = perl-json-xs + depends = perl-anyevent-i3 + source = i3-wsbar + md5sums = 1af3160aa252542abdaf4b21eb942242 + +pkgname = i3-wsbar + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..1a76bb6d7902 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,22 @@ +# Maintainer: Ismo Toijala <ismo.toijala@gmail.com> + +pkgname=i3-wsbar +pkgver=1 +pkgrel=2 +pkgdesc='i3 workspace output for dzen2' +url='https://i3wm.org/' +arch=('any') +license=('BSD') +depends=( + 'dzen2' + 'perl-ipc-run' + 'perl-json-xs' + 'perl-anyevent-i3' +) +source=('i3-wsbar') + +package() { + install -Dm755 i3-wsbar "${pkgdir}/usr/bin/i3-wsbar" +} + +md5sums=('1af3160aa252542abdaf4b21eb942242') diff --git a/i3-wsbar b/i3-wsbar new file mode 100644 index 000000000000..19cb79320bdd --- /dev/null +++ b/i3-wsbar @@ -0,0 +1,107 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Pod::Usage; +use IPC::Run qw(start pump); +use AnyEvent::I3; +use AnyEvent; +use v5.10; + +my $dmplex = ""; +if ($#ARGV >= 0) { + $dmplex = $ARGV[0] . " "; +} + +my $i3 = i3; +my $workspaces = []; + +# Disable buffering +$| = 1; + +# Wait a short amount of time and try to connect to i3 again +sub reconnect { + my $timer; + my $c = sub { + $timer = AnyEvent->timer( + after => 0.01, + cb => sub { $i3->connect->cb(\&connected) } + ); + }; + $c->(); +} + +# Connection attempt succeeded or failed +sub connected { + my ($cv) = @_; + + if (!$cv->recv) { + reconnect(); + return; + } + + $i3->subscribe({ + workspace => \&ws_change, + _error => sub { reconnect() } + }); + ws_change(); +} + +# Called when a ws changes +sub ws_change { + # Request the current workspaces and update the output afterwards + $i3->get_workspaces->cb( + sub { + my ($cv) = @_; + $workspaces = $cv->recv; + update_output(); + } + ); +} + +sub update_output { + my $dzen_bg = "#000000"; + my $out; + my $width = "1366"; + + $out = qq|$dmplex|; + $out .= qq|^pa(;0)|; + for my $ws (@{$workspaces}) + { + my ($bg, $fg) = qw(333333 888888); + ($bg, $fg) = qw(4c7899 ffffff) if $ws->{visible}; + ($bg, $fg) = qw(900000 ffffff) if $ws->{urgent}; + + my $cmd = q|i3-msg "workspace | . $ws->{num} . q|"|; + my $name = $ws->{name}; + + # Begin the clickable area + $out .= qq|^ca(1,$cmd)|; + + # Draw the rest of the bar in the background color, but + # don’t move the "cursor" + $out .= qq|^p(_LOCK_X)^fg(#$bg)^r(${width}x20)^p(_UNLOCK_X)|; + # Draw the name of the workspace without overwriting the + # background color + $out .= qq|^p(+4;+1)^fg(#$fg)^ib(1)$name^ib(0)^p(+5;-1)|; + # Draw the rest of the bar in the normal background color + # without moving the "cursor" + $out .= qq|^p(_LOCK_X)^fg($dzen_bg)^r(${width}x17)^p(_UNLOCK_X)|; + + # End the clickable area + $out .= qq|^ca()|; + + # Move to the next rect, reset Y coordinate + $out .= qq|^p(2)^pa(;0)|; + } + + $out .= qq|^p(+5)|; + $out .= "\n"; + + print $out; +} + +$i3->connect->cb(\&connected); + +# let AnyEvent do the rest ("endless loop") +AnyEvent->condvar->recv |