From e98c632fb002de0975666c74d9b62c9498e2d6d2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 4 Dec 2017 19:41:16 +0100 Subject: [PATCH] Click handlers --- bar/bar1.conf | 18 +++++++++++------- bar/src/date.php | 6 +++++- bar/src/ip.php | 6 +++++- bar/src/ip_wan.php | 2 +- bar/src/mount_point_space.php | 14 ++++++++++---- bar/src/spotify.php | 11 +++++++---- bar/src/time.php | 6 +++++- 7 files changed, 44 insertions(+), 19 deletions(-) diff --git a/bar/bar1.conf b/bar/bar1.conf index a05a047..bd3f377 100644 --- a/bar/bar1.conf +++ b/bar/bar1.conf @@ -21,40 +21,43 @@ command=/home/simon/.i3/bar/src/ip.php eth0 format=json interval=10 -[inet_eth0] +[ip_eth0_inet] command=/home/simon/.i3/bar/src/ip.php eth0 format=json interval=10 -[inet_eth1] +[ip_eth1_inet] command=/home/simon/.i3/bar/src/ip.php eth1 format=json interval=10 -[inet_wlan0] +[ip_wlan0_inet] command=/home/simon/.i3/bar/src/ip.php wlan0 format=json interval=10 +min_width=button=1 -[inet_easytether0] +[ip_easytether0_inet] command=/home/simon/.i3/bar/src/ip.php easytether0 format=json interval=100 -[inet_wan] +[ip_wan] command=/home/simon/.i3/bar/src/ip_wan.php format=json interval=100 [mount_point_space_root] -command=/home/simon/.i3/bar/src/mount_point_space.php / +command=/home/simon/.i3/bar/src/mount_point_space.php root / format=json interval=5 +min_width=button=1 [mount_point_space_home] -command=/home/simon/.i3/bar/src/mount_point_space.php /home 90 95 +command=/home/simon/.i3/bar/src/mount_point_space.php home /home 90 95 format=json interval=5 +min_width=button=1 [memory] command=memory @@ -63,6 +66,7 @@ command=memory command=/home/simon/.i3/bar/src/spotify.php format=json interval=1 +min_width=button=1 [volume] command=/home/simon/.i3/bar/src/volume.php diff --git a/bar/src/date.php b/bar/src/date.php index af56ac2..df1c3b3 100755 --- a/bar/src/date.php +++ b/bar/src/date.php @@ -7,8 +7,12 @@ $format = $argv[1] ?? 'd/m/Y'; $fullText = date($format); +if (getenv('BLOCK_BUTTON') === '1') { + shell_exec('i3-msg \'workspace "3. MAIL"\''); +} + echo block( - 'date_'.$format, + 'date', [ 'full_text' => $fullText, 'color' => color('date'), diff --git a/bar/src/ip.php b/bar/src/ip.php index ce18e43..30ab5e2 100755 --- a/bar/src/ip.php +++ b/bar/src/ip.php @@ -21,8 +21,12 @@ if (empty($ip)) { $fullText = sprintf('[%s] %s', $iface, $ip); $shortText = sprintf('%s: %s', $iface, $ip); +if (getenv('BLOCK_BUTTON') === '1') { + shell_exec('echo "'.escapeshellarg($ip).'" | xclip'); +} + echo block( - 'ip_'.$iface.'_'.$inet, + 'ip_'.$iface.'_'.trim($inet), [ 'full_text' => $fullText, 'short_text' => $shortText, diff --git a/bar/src/ip_wan.php b/bar/src/ip_wan.php index 648a08d..8f2e41e 100755 --- a/bar/src/ip_wan.php +++ b/bar/src/ip_wan.php @@ -21,7 +21,7 @@ $fullText = sprintf('[%s] %s', $iface, $ip); $shortText = sprintf('%s: %s', $iface, $ip); echo block( - 'ip_'.$iface, + 'ip_wan', [ 'full_text' => $fullText, 'short_text' => $shortText, diff --git a/bar/src/mount_point_space.php b/bar/src/mount_point_space.php index 98d9f95..46bcfa4 100755 --- a/bar/src/mount_point_space.php +++ b/bar/src/mount_point_space.php @@ -3,9 +3,10 @@ require __DIR__.'/base/block.php'; -$mountPoint = $argv[1] ?? '/'; -$range1 = $argv[2] ?? 70; -$range2 = $argv[3] ?? 90; +$name = $argv[1] ?? 'root'; +$mountPoint = $argv[2] ?? '/'; +$range1 = $argv[3] ?? 70; +$range2 = $argv[4] ?? 90; $command = sprintf( 'df -h %s | tail -n 1', @@ -33,8 +34,13 @@ if ($percent < $range1) { $fullText = sprintf('[%s] %s%%', $mountPoint, $percent); $shortText = sprintf('%s: %s%%', $mountPoint, $percent); +if (getenv('BLOCK_BUTTON') === '1') { + $command = 'export DISPLAY=:0; pcmanfm '.escapeshellarg('file://'.$mountPoint).'&'; + pclose(popen($command, 'r')); +} + echo block( - 'mount_point_space_'.$mountPoint, + 'mount_point_space_'.$name, [ 'full_text' => $fullText, 'short_text' => $shortText, diff --git a/bar/src/spotify.php b/bar/src/spotify.php index 244465d..4fdbf95 100755 --- a/bar/src/spotify.php +++ b/bar/src/spotify.php @@ -9,12 +9,12 @@ if (!in_array($status, ['Playing'])) { die; } -function cleanUp($d) +function cleanUp($d, $max = 30) { $string = trim(str_replace(['"', "'"], ' ', $d)); - if (mb_strlen($string) > 15) { - $string = substr($string, 0, 15).'…'; + if (mb_strlen($string) > $max) { + $string = substr($string, 0, $max).'…'; } return $string; @@ -24,9 +24,12 @@ $title = cleanUp(shell_exec('playerctl -p spotify metadata xesam:title')); $artist = cleanUp(shell_exec('playerctl -p spotify metadata xesam:artist')); $label = sprintf('%s – %s', $title, $artist); - $fullText = sprintf('%s – %s', $title, $artist); +if (getenv('BLOCK_BUTTON') === '1') { + shell_exec('i3-msg \'workspace "6. MEDIA"\''); +} + echo block( 'spotify', [ diff --git a/bar/src/time.php b/bar/src/time.php index b0d22c1..4782ba2 100755 --- a/bar/src/time.php +++ b/bar/src/time.php @@ -7,8 +7,12 @@ $format = $argv[1] ?? 'H:i:s'; $fullText = date($format); +if (getenv('BLOCK_BUTTON') === '1') { + shell_exec('i3-msg \'workspace "3. MAIL"\''); +} + echo block( - 'time_'.$format, + 'time', [ 'full_text' => $fullText, 'color' => color('date'),