summaryrefslogtreecommitdiff
path: root/perl5
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-01-03 23:25:43 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-01-04 11:11:55 -0700
commit35b66310cc54a6e06e060a9b471fbfc43ff0341e (patch)
tree1d0be75041229c9a5595a8663b5f26655cd57d11 /perl5
parentab924009cb7e84fcdc95935d9d5bda66ee113789 (diff)
downloaddotfiles-35b66310cc54a6e06e060a9b471fbfc43ff0341e.tar.gz
move fresh-workspace into lib so sway-ftp-master need not shell out
Diffstat (limited to 'perl5')
-rw-r--r--perl5/Local/Desktop.pm43
1 files changed, 42 insertions, 1 deletions
diff --git a/perl5/Local/Desktop.pm b/perl5/Local/Desktop.pm
index 3ca93b90..189f3689 100644
--- a/perl5/Local/Desktop.pm
+++ b/perl5/Local/Desktop.pm
@@ -2,7 +2,7 @@ package Local::Desktop;
# graphical desktop management functions
#
-# Copyright (C) 2020 Sean Whitton
+# Copyright (C) 2020-2022 Sean Whitton
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,20 +22,61 @@ use strict;
use warnings;
use Carp;
+use JSON;
use File::Find;
use File::LibMagic;
use File::Spec::Functions "rel2abs";
use Exporter "import";
use File::Copy;
+use List::Util "first";
our @EXPORT = qw(
+ fresh_workspace
select_wallpaper_files
ensure_resize_for_current_outputs
resize_for_current_outputs
pick_random_wallpapers );
+`sh -c "command -v i3-msg"`;
+my $wmipc = $? == 0 ? "i3-msg" : "swaymsg";
+
my $output_re = qr/ ([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+) /;
+=head fresh_workspace($send)
+
+Switch to the next free workspace, if any. Return the name of that workspace,
+or undef if no workspace was available. If $send, send the current window to
+the fresh workspace instead of switching focus there.
+
+=cut
+
+sub fresh_workspace {
+ my %current_names = map +($_->{name}, undef),
+ @{ decode_json `$wmipc -t get_workspaces` };
+ my $next_free_workspace = first { not exists $current_names{$_} }
+ "1", "2", "3", "4", "5", "6", "7", "8",
+ "9", "10", "11:F1", "12:F2", "13:F3", "14:F4", "15:F5",
+ "16:F6", "17:F7", "18:F8", "19:F9", "20:F10", "21:F11", "22:F12";
+
+ if ($next_free_workspace) {
+ if ($_[0]) {
+ # Send it there but don't change focus. User can use 'move
+ # container to workspace back_and_forth' binding to move any other
+ # wanted containers over there, before finally switching the view
+ # with 'workspace back_and_forth'
+ system
+ "$wmipc -q move container to workspace $next_free_workspace"
+ # Only the first of the three commands within this call to
+ # i3-msg should be necessary, but we need the others to work
+ # around https://github.com/swaywm/sway/issues/6081
+ . ", workspace $next_free_workspace, workspace back_and_forth";
+ } else {
+ system "$wmipc -q workspace $next_free_workspace";
+ }
+ }
+ $next_free_workspace
+ }
+
=head select_wallpaper_files(@files)
Select the first entry of @files as the wallpaper for the first output, the