From cd7f6cbc7c4620afad542f41b4c8845484a8e6e9 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 9 Mar 2021 15:03:52 +0100 Subject: [PATCH] add bar2, wireguard block, workspace_apps block, i3_switch_window script --- bar/bar1.conf | 98 ++++++++++++++++------- bar/bar2.conf | 144 ++++++++++++++++++++++++++++++++++ bar/src/base/block.php | 4 - bar/src/ip_wan.php | 13 ++- bar/src/wireguard.php | 39 +++++++++ bar/src/workspace_apps.php | 139 ++++++++++++++++++++++++++++++++ config | 28 ++++++- i3_switch_focus_container.php | 2 +- i3_switch_window.php | 86 ++++++++++++++++++++ i3_switch_workspace.php | 2 +- 10 files changed, 518 insertions(+), 37 deletions(-) create mode 100644 bar/bar2.conf create mode 100755 bar/src/wireguard.php create mode 100755 bar/src/workspace_apps.php create mode 100755 i3_switch_window.php diff --git a/bar/bar1.conf b/bar/bar1.conf index e84265c..05975bf 100644 --- a/bar/bar1.conf +++ b/bar/bar1.conf @@ -1,26 +1,50 @@ -[bandwidth_eth0] -command=/home/simon/.i3/bar/src/bandwidth.php eth0 inet eth -format=json -markup=pango -interval=5 +#[bandwidth_eth0] +#command=/home/simon/.i3/bar/src/bandwidth.php eth0 inet eth +#format=json +#markup=pango +#interval=5 +# +#[bandwidth_wg0] +#command=/home/simon/.i3/bar/src/bandwidth.php wg0 wg0 +#format=json +#markup=pango +#interval=5 +# +#[bandwidth_wg1] +#command=/home/simon/.i3/bar/src/bandwidth.php wg1 wg1 +#format=json +#markup=pango +#interval=5 +# +#[bandwidth_enx00e04cf69b06] +#command=/home/simon/.i3/bar/src/bandwidth.php enx00e04cf69b06 inet eth +#format=json +#markup=pango +#interval=5 +# +#[bandwidth_enx00e04c68022c] +#command=/home/simon/.i3/bar/src/bandwidth.php enx00e04c68022c inet eth +#format=json +#markup=pango +#interval=5 +# +#[bandwidth_wlp59s0] +#command=/home/simon/.i3/bar/src/bandwidth.php wlp59s0 inet wifi +#format=json +#markup=pango +#interval=1 -[bandwidth_enx00e04cf69b06] -command=/home/simon/.i3/bar/src/bandwidth.php enx00e04cf69b06 inet eth +[ip_wg0_inet] +command=/home/simon/.i3/bar/src/ip.php wg0 inet wg0 format=json markup=pango -interval=5 +interval=10 -[bandwidth_enx00e04c68022c] -command=/home/simon/.i3/bar/src/bandwidth.php enx00e04c68022c inet eth +[ip_wg1_inet] +command=/home/simon/.i3/bar/src/ip.php wg1 inet wg1 format=json markup=pango -interval=5 - -[bandwidth_wlp59s0] -command=/home/simon/.i3/bar/src/bandwidth.php wlp59s0 inet wifi -format=json -markup=pango -interval=1 +interval=10 [ip_eth0_inet] command=/home/simon/.i3/bar/src/ip.php eth0 inet eth @@ -52,6 +76,18 @@ format=json markup=pango interval=100 +[wireguard_wg0] +command=/home/simon/.i3/bar/src/wireguard.php wg0 wg0 +format=json +markup=pango +interval=1 + +[wireguard_wg1] +command=/home/simon/.i3/bar/src/wireguard.php wg1 wg1 +format=json +markup=pango +interval=1 + [mount_point_space_root] command=/home/simon/.i3/bar/src/mount_point_space.php root / format=json @@ -112,6 +148,18 @@ format=json markup=pango interval=1000 +[app_flameshot] +command=/home/simon/.i3/bar/src/app.php app_flameshot "F" "/usr/bin/flameshot gui --delay 500" '#bf007e' '#fff' +format=json +markup=pango +interval=1000 + +[app_ksnip] +command=/home/simon/.i3/bar/src/app.php app_ksnip "K" "/usr/bin/ksnip" '#a460ef' '#fff' +format=json +markup=pango +interval=1000 + [app_cloud] command=/home/simon/.i3/bar/src/app.php app_cloud C "xdg-open https://deblan.cloud/" '#3c4e74' '#fff' format=json @@ -124,17 +172,11 @@ format=json markup=pango interval=1000 -[app_netflix] -command=/home/simon/.i3/bar/src/app.php app_netflix N "xdg-open https://www.netflix.com/browse" '#363636' '#e50914' -format=json -markup=pango -interval=1000 - -[time] -command=/home/simon/.i3/bar/src/time.php "H:i:s d/m" -format=json -markup=pango -interval=1 +#[app_netflix] +#command=/home/simon/.i3/bar/src/app.php app_netflix N "xdg-open https://www.netflix.com/browse" '#363636' '#e50914' +#format=json +#markup=pango +#interval=1000 [rss_tts] command=/home/simon/.i3/bar/src/rss.php "rss_tts" "https://tiny.deblan.org/public.php?op=rss&id=-3&key=17c659af1ad27f30941a724fcf48421d1e83081a" "https://tiny.deblan.org/" diff --git a/bar/bar2.conf b/bar/bar2.conf new file mode 100644 index 0000000..b410826 --- /dev/null +++ b/bar/bar2.conf @@ -0,0 +1,144 @@ +[bandwidth_eth0] +command=/home/simon/.i3/bar/src/bandwidth.php eth0 inet eth +format=json +markup=pango +interval=5 + +[bandwidth_wg0] +command=/home/simon/.i3/bar/src/bandwidth.php wg0 +format=json +markup=pango +interval=5 + +[bandwidth_wg1] +command=/home/simon/.i3/bar/src/bandwidth.php wg1 +format=json +markup=pango +interval=5 + +[bandwidth_enx00e04cf69b06] +command=/home/simon/.i3/bar/src/bandwidth.php enx00e04cf69b06 inet eth +format=json +markup=pango +interval=5 + +[bandwidth_enx00e04c68022c] +command=/home/simon/.i3/bar/src/bandwidth.php enx00e04c68022c inet eth +format=json +markup=pango +interval=5 + +[bandwidth_wlp59s0] +command=/home/simon/.i3/bar/src/bandwidth.php wlp59s0 inet wifi +format=json +markup=pango +interval=1 + +[workspace_apps_0] +command=/home/simon/.i3/bar/src/workspace_apps.php 0 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_1] +command=/home/simon/.i3/bar/src/workspace_apps.php 1 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_2] +command=/home/simon/.i3/bar/src/workspace_apps.php 2 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_3] +command=/home/simon/.i3/bar/src/workspace_apps.php 3 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_4] +command=/home/simon/.i3/bar/src/workspace_apps.php 4 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_5] +command=/home/simon/.i3/bar/src/workspace_apps.php 5 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_6] +command=/home/simon/.i3/bar/src/workspace_apps.php 6 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_7] +command=/home/simon/.i3/bar/src/workspace_apps.php 7 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_8] +command=/home/simon/.i3/bar/src/workspace_apps.php 8 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_9] +command=/home/simon/.i3/bar/src/workspace_apps.php 9 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_10] +command=/home/simon/.i3/bar/src/workspace_apps.php 10 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_11] +command=/home/simon/.i3/bar/src/workspace_apps.php 11 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +[workspace_apps_12] +command=/home/simon/.i3/bar/src/workspace_apps.php 12 $BLOCK_BUTTON +format=json +markup=pango +interval=1 +align=left + +#[meteo] +#command=/home/simon/.i3/bar/src/meteo.php +#format=json +#markup=pango +#interval=3600 + +[time] +command=/home/simon/.i3/bar/src/time.php "H:i:s d/m/Y" +format=json +markup=pango +interval=1 + +[app_system] +command=/home/simon/.i3/bar/src/app.php app_system "Système" /home/simon/bin/poweroption '#000' '#fff' +format=json +markup=pango +interval=1000 diff --git a/bar/src/base/block.php b/bar/src/base/block.php index 552c952..02ec9d2 100644 --- a/bar/src/base/block.php +++ b/bar/src/base/block.php @@ -83,7 +83,6 @@ function lpspan($text, $foreground = null, $background = null) return span(sprintf(' %s', $text), $foreground, $background); } - /** * Creates span. * @@ -106,9 +105,6 @@ function span($text, $foreground = null, $background = null) /** * Returns a json of a block. * - * @param string $name - * @param array $options - * * @return string */ function block(string $name, array $options = []) diff --git a/bar/src/ip_wan.php b/bar/src/ip_wan.php index f68f1b3..ac76d86 100755 --- a/bar/src/ip_wan.php +++ b/bar/src/ip_wan.php @@ -8,7 +8,7 @@ $ipv6 = !empty($argv[1]); $iface = 'wan'; $command = sprintf( - 'dig +short %s myip.opendns.com @resolver1.opendns.com', + 'dig +short %s myip.opendns.com @resolver1.opendns.com 2>/dev/null | grep -v could', $ipv6 ? '-6' : null ); @@ -16,7 +16,7 @@ $ip = trim(shell_exec($command)); if (empty($ip)) { $command = sprintf( - 'dig +short %s TXT o-o.myaddr.l.google.com @ns1.google.com', + 'dig +short %s TXT o-o.myaddr.l.google.com @ns1.google.com 2>/dev/null | grep -v could', $ipv6 ? '-6' : '-4' ); @@ -24,6 +24,15 @@ if (empty($ip)) { $ip = trim($ip, '"'); } +if (empty($ip)) { + $command = sprintf( + 'curl %s ifconfig.co 2>/dev/null', + $ipv6 ? '-6' : '-4' + ); + + $ip = trim(shell_exec($command)); +} + if (empty($ip)) { die; } diff --git a/bar/src/wireguard.php b/bar/src/wireguard.php new file mode 100755 index 0000000..5c185be --- /dev/null +++ b/bar/src/wireguard.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +/dev/null'; +$output = trim(shell_exec($command)); + +if (empty($output)) { + echo block( + 'wireguard_'.$iface, + [ + 'full_text' => pspan($name, color('warning'), '#000'), + 'color' => color('warning'), + ] + ); + + if (getenv('BLOCK_BUTTON') === '1') { + $command = 'sudo wg-quick up '.escapeshellarg($iface); + shell_exec($command); + } +} else { + echo block( + 'wireguard_'.$iface, + [ + 'full_text' => pspan($name, color('normal'), '#000'), + 'color' => color('normal'), + ] + ); + + if (getenv('BLOCK_BUTTON') === '1') { + $command = 'sudo wg-quick down '.escapeshellarg($iface); + shell_exec($command); + } +} + diff --git a/bar/src/workspace_apps.php b/bar/src/workspace_apps.php new file mode 100755 index 0000000..f9b5f4e --- /dev/null +++ b/bar/src/workspace_apps.php @@ -0,0 +1,139 @@ +#!/usr/bin/env php + $n) { + if (!isset($n['window'])) { + unset($nodes[$k]); + + foreach ($n['nodes'] as $node) { + $nodes[] = $node; + } + + foreach ($n['floating_nodes'] as $node) { + $nodes[] = $node; + } + + } + } + + return $nodes; +} + +$node = getVisibleWorkspacesNodes(getTree(), getVisibleWorkspaces())[$windowKey] ?? null; + +if (!$node) { + die(0); +} + +$title = $node['window_properties']['title']; +$instance = $node['window_properties']['instance']; +$window = $node['window']; +$focused = $node['focused']; +$urgent = $node['urgent']; +$scratchpad = $node['output'] === '__i3'; + +if (mb_strlen($title) > 25) { + $title = mb_substr($title, 0, 22).'…'; +} + +$foreground = '#9cb7d1'; +$background = '#222222'; + +if ($focused) { + $foreground = '#07c0d4'; + $background = '#333333'; +} elseif ($scratchpad) { + $foreground = '#bababa'; + $background = '#222222'; +} + +if ($urgent) { + if (date('s') % 2) { + $foreground = '#ffffff'; + $background = '#87af15'; + } else { + $foreground = '#ffffff'; + $background = '#07c0d4'; + } +} + +$fullText = pspan(mb_strtoupper($title), $foreground, $background).' '; + +if ($blockButton) { + shell_exec(sprintf('i3-msg "[id=%s] focus"', $window)); +} + +echo block( + 'workspace_apps_'.$windowKey, + [ + 'full_text' => $fullText, + 'color' => color('normal'), + 'separator' => false, + 'separator_block_width' => 0, + 'min_width' => 1, + 'align' => 'left', + ] +); diff --git a/config b/config index d650cde..53e9a3c 100644 --- a/config +++ b/config @@ -12,6 +12,7 @@ set $left Left set $up Up set $right Right set $down Down +set $tab Tab set $mouseleft button1 set $mousemiddle button2 @@ -197,6 +198,7 @@ bindsym $altleft+$shift+k exec ~/bin/i3_move_mouse.sh right bindsym $altleft+$shift+u exec ~/bin/i3_move_mouse.sh up bindsym $altleft+$shift+j exec ~/bin/i3_move_mouse.sh down bindsym $window+$shift+y exec ~/bin/i3_mouse_click.sh +bindsym $altleft+$tab exec ~/.i3/i3_switch_window.php bindsym $ctrl+$shift+f exec ~/bin/search bindsym $ctrl+$altleft+$shift+e exec sudo shutdown -h now bindsym $ctrl+$altleft+$shift+r exec sudo shutdown -r now @@ -264,6 +266,30 @@ bar { } } +bar { + status_command i3blocks -c ~/.i3/bar/bar2.conf + workspace_buttons no + position bottom + tray_output none + + output DP1 + output HDMI1 + output eDP-1 + output eDP1 + + colors { + background #000000 + statusline #ffffff + #border bg text + # focused_workspace #a74068 #bd4875 #ffffff + # focused_workspace #05abba #07c0d4 #01282c + focused_workspace #333333 #333333 #07c0d4 + active_workspace #5f676a #5f676a #ffffff + inactive_workspace #222222 #222222 #bababa + urgent_workspace #5aaad8 #6ac6ff #ffffff + } +} + #bar { # status_command ~/.i3/processList.sh # workspace_buttons no @@ -294,7 +320,7 @@ bar { # exec pulseaudio -D && start-pulseaudio-x11 # exec start-pulseaudio-x11 exec ~/bin/pulseaudio-start -exec tint2 +# exec tint2 exec rofi -key-run 'SuperL+Alt+d' -Key-ssh 'SuperL+Alt+s' -key-window 'SuperL+Alt+w' exec feh --bg-fill ~/wallpaper.jpg exec setxkbmap fr oss diff --git a/i3_switch_focus_container.php b/i3_switch_focus_container.php index 14b4914..72d7f98 100755 --- a/i3_switch_focus_container.php +++ b/i3_switch_focus_container.php @@ -1,4 +1,4 @@ -#!/usr/bin/php5 +#!/usr/bin/php $n) { + if (!isset($n['window'])) { + unset($nodes[$k]); + + foreach ($n['nodes'] as $node) { + $nodes[] = $node; + } + + foreach ($n['floating_nodes'] as $node) { + $nodes[] = $node; + } + + } + } + + return $nodes; +} + +$nodes = getVisibleWorkspacesNodes(getTree(), getVisibleWorkspaces()); + +foreach ($nodes as $key => $node) { + if ($node['focused']) { + shell_exec(sprintf('i3-msg "[id=%s] focus"', $nodes[(++$key) % count($nodes)]['window'])); + } +} diff --git a/i3_switch_workspace.php b/i3_switch_workspace.php index 5822512..57f5ce3 100755 --- a/i3_switch_workspace.php +++ b/i3_switch_workspace.php @@ -1,4 +1,4 @@ -#!/usr/bin/php5 +#!/usr/bin/php