#!/usr/bin/env php connect('127.0.0.1', 6379); $value = (array) json_decode($redis->get('i3_get_workspaces'), true); return $value; } function getVisibleWorkspaces(): array { $workspaces = []; foreach (getWorkspaces() as $wp) { if (true === $wp['visible']) { $workspaces[] = $wp; } } return $workspaces; } function getTree(): array { $output = shell_exec('i3-msg -t get_tree'); return json_decode($output, true); } function getVisibleWorkspacesNodes(array $tree, array $workspaces): array { $nodes = []; $num = $tree['num'] ?? null; $output = $tree['output'] ?? null; foreach ($workspaces as $workspace) { if ($num === $workspace['num']) { $nodes = array_merge( $nodes, $tree['nodes'] ); $nodes = array_merge( $nodes, $tree['floating_nodes'] ); } elseif ($output === '__i3' && isset($tree['window'])) { $nodes[] = $tree; } } foreach ($tree as $node) { if (is_array($node)) { $nodes = array_merge( $nodes, getVisibleWorkspacesNodes($node, $workspaces) ); } } foreach ($nodes as $k => $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', ] );