From 078e1c69b836ab2c4c671488764da78750c3c02f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 1 Aug 2020 00:28:48 -0400 Subject: add scripts to switch a workspace between a virtual screen this keeps it rendering even while offscreen so obs works correctly --- bin/hush/i3-switch-workspace | 31 ++++++++++++++++++++++++------- bin/hush/vscreen | 17 +++++++++++++++++ config/i3/config | 1 + 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 bin/hush/vscreen diff --git a/bin/hush/i3-switch-workspace b/bin/hush/i3-switch-workspace index acae465..b54afa1 100755 --- a/bin/hush/i3-switch-workspace +++ b/bin/hush/i3-switch-workspace @@ -8,6 +8,8 @@ use JSON::PP; my $json = JSON::PP->new; +my $virtual_workspace = 'virtual'; + my %message_types = ( command => 0, get_workspaces => 1, @@ -32,11 +34,17 @@ my $tree_data = $json->decode(i3_msg('get_tree')); my $first = 99999; my $last = -99999; my $cur; +my $cur_name; +my $virtual_output; for my $i (0..$#$workspace_data) { my $num = $workspace_data->[$i]{num}; if ($workspace_data->[$i]{focused}) { $cur = $num; + $cur_name = $workspace_data->[$i]{name}; + if ($cur_name eq $virtual_workspace) { + $virtual_output = $workspace_data->[$i]{output}; + } } my $workspace_tree = find_workspace($tree_data, $num); @@ -48,25 +56,34 @@ for my $i (0..$#$workspace_data) { $last = $num if $num > $last; } -my $to; if ($dir eq 'prev') { if ($cur >= $first) { - $to = $cur - 1; + i3_msg('command', "workspace ${\($cur - 1)}"); } } elsif ($dir eq 'next') { if ($cur <= $last) { - $to = $cur + 1; + i3_msg('command', "workspace ${\($cur + 1)}"); + } +} +elsif ($dir eq $virtual_workspace) { + if (!defined $virtual_output || $virtual_output eq 'VIRTUAL1') { + i3_msg( + 'command', + "workspace $virtual_workspace; move workspace to output eDP1", + ); + } + else { + i3_msg( + 'command', + "workspace $virtual_workspace; move workspace to output VIRTUAL1", + ); } } else { die "unknown subcommand $dir"; } -if (defined $to) { - i3_msg('command', "workspace $to"); -} - sub find_workspace { my ($tree, $num) = @_; if (exists $tree->{num} && $tree->{num} == $num) { diff --git a/bin/hush/vscreen b/bin/hush/vscreen new file mode 100755 index 0000000..d39b389 --- /dev/null +++ b/bin/hush/vscreen @@ -0,0 +1,17 @@ +#!/bin/sh + + +case "$1" in + goto) + xrandr --addmode VIRTUAL1 1920x1080 + xrandr --output VIRTUAL1 --auto --output eDP1 --auto --left-of VIRTUAL1 + i3-switch-workspace virtual + ;; + off) + xrandr --output VIRTUAL1 --off + ;; + *) + echo "bad subcommand $1" >&2 + exit 1 + ;; +esac diff --git a/config/i3/config b/config/i3/config index 510adeb..7ff71f9 100644 --- a/config/i3/config +++ b/config/i3/config @@ -42,6 +42,7 @@ bindsym $mod+space focus mode_toggle bindsym $mod+bracketleft exec i3-switch-workspace prev bindsym $mod+bracketright exec i3-switch-workspace next +bindsym $mod+v exec vscreen goto bindsym $mod+1 workspace 1 bindsym $mod+2 workspace 2 -- cgit v1.2.3-54-g00ecf