Compare commits
No commits in common. "c2cb64efea3dd41db6a60bc6ec110a124e5588ab" and "0abcd17f2239eeba44b93af5c94f080ed41fb1d2" have entirely different histories.
c2cb64efea
...
0abcd17f22
|
@ -2,128 +2,79 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use feature ( 'signatures' );
|
|
||||||
use JSON::MaybeXS;
|
|
||||||
my $json = JSON::MaybeXS->new();
|
|
||||||
|
|
||||||
our ($workspace, $term_id, $term_ws, $ww, $wh, $tw, $th, $tc);
|
|
||||||
# Desired terminal dimensions (px or %) and corner (top-right, top-left, bottom-right, bottom-left)
|
|
||||||
$tw = '100%';
|
|
||||||
$th = '30%';
|
|
||||||
$tc = 'bottom-right';
|
|
||||||
|
|
||||||
# Workspace to push the terminal to when dismissed
|
# Workspace to push the terminal to when dismissed
|
||||||
my $hidden = 'grave';
|
my $hidden = 'grave';
|
||||||
# Terminal executable used for pop-up
|
# Terminal application used for pop-up (swaymsg 'name')
|
||||||
my $term = 'alacritty';
|
my $term = 'alacritty';
|
||||||
# App ID
|
# App ID
|
||||||
my $app_id = 'Alacritty-grave';
|
my $class = 'Alacritty-grave';
|
||||||
|
|
||||||
sub search($nodes, $o=undef, $w=undef, $depth=0) {
|
use JSON::XS;
|
||||||
my $debug = 0;
|
my $json = JSON::XS->new();
|
||||||
my $term_id;
|
|
||||||
$depth++;
|
|
||||||
my $prefix = " "x($depth*4);
|
|
||||||
foreach my $n (@{$nodes}) {
|
|
||||||
print("${prefix}Checking node $n->{id}".(defined($n->{name}) ? " ($n->{name})" : "")."\n") if ($debug);
|
|
||||||
print("${prefix}Considering $n->{app_id}...\n") if ($debug && defined($n->{app_id}));
|
|
||||||
if ($n->{type} eq "output") {
|
|
||||||
$o = $n->{name};
|
|
||||||
print("${prefix}Searching output $o\n") if ($debug);
|
|
||||||
} elsif ($n->{type} eq "workspace") {
|
|
||||||
$w = $n->{name};
|
|
||||||
print("${prefix}Searching workspace $w\n") if ($debug);
|
|
||||||
} else {
|
|
||||||
print("${prefix}Currently on display $o, workspace $w\n") if ($debug);
|
|
||||||
if (defined($n->{app_id}) && $n->{app_id} eq $app_id) {
|
|
||||||
$term_id = $n->{id};
|
|
||||||
$term_ws = $w;
|
|
||||||
print("${prefix}Found $app_id with id $term_id on workspace $w\n") if ($debug);
|
|
||||||
return $term_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$term_id = search($n->{floating_nodes}, $o, $w, $depth);
|
|
||||||
$term_id = search($n->{nodes}, $o, $w, $depth) if ($term_id == 0);
|
|
||||||
print("${prefix}Found $term_id on $w\n") if ($debug && $term_id);
|
|
||||||
return $term_id if ($term_id);
|
|
||||||
}
|
|
||||||
print("${prefix}Not found, moving up a node\n") if ($debug);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub resize() {
|
|
||||||
my ($d, $r, $h, $w) = (0, 0);
|
|
||||||
if (my ($hit) = $tw =~ m/^(100|\d\d?)\%$/) {
|
|
||||||
$w = int(($ww * $hit) / 100);
|
|
||||||
$r = $ww - $w if ($tc =~ m/right$/);
|
|
||||||
} elsif (($tw =~ m/^\d+$/) && (1 < $tw <= $ww)) {
|
|
||||||
$d = $wh - $th if ($tc =~ m/^bottom/);
|
|
||||||
}
|
|
||||||
if (my ($hit) = $th =~ m/^(100|\d\d?)\%$/) {
|
|
||||||
$h = int(($wh * $hit) / 100);
|
|
||||||
$d = $wh - $h if ($tc =~ m/^bottom/);
|
|
||||||
} elsif (($tw =~ m/^\d+$/) && (1 < $tw <= $ww)) {
|
|
||||||
$r = $ww - $tw if ($tc =~ m/right$/);
|
|
||||||
}
|
|
||||||
`swaymsg "[con_id=$term_id]" resize set width ${w}px height ${h}px, move position ${r}px ${d}px`;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $raw = join("\n",`swaymsg -t get_tree`);
|
my $raw = join("\n",`swaymsg -t get_tree`);
|
||||||
|
|
||||||
my $root = $json->decode($raw);
|
my $root = $json->decode($raw);
|
||||||
$term_id = search($root->{nodes}) || undef;
|
|
||||||
|
|
||||||
my $focused = $root->{focus}->[0];
|
# Get focused
|
||||||
|
my $display = $root->{focus}->[0];
|
||||||
|
my ($workspace, $term_id, $term_ws);
|
||||||
foreach my $d (@{$root->{nodes}}) {
|
foreach my $d (@{$root->{nodes}}) {
|
||||||
last if (defined($workspace));
|
# If both the current workspace and terminal have been found
|
||||||
if ($d->{id} eq $focused) {
|
# nothing else to look for
|
||||||
|
if (defined($workspace) && defined($term_id)) {
|
||||||
|
last;
|
||||||
|
# If the display from this iteration of the loop is in focus
|
||||||
|
# look for the active workspace
|
||||||
|
} elsif ($d->{id} eq $display) {
|
||||||
foreach my $w (@{$d->{nodes}}) {
|
foreach my $w (@{$d->{nodes}}) {
|
||||||
if ($w->{id} eq $d->{focus}->[0]) {
|
# Again, if both found, skip
|
||||||
$workspace = $w->{name};
|
if (defined($workspace) && defined($term_id)) {
|
||||||
$ww = $w->{rect}->{width};
|
|
||||||
$wh = $w->{rect}->{height};
|
|
||||||
last;
|
last;
|
||||||
|
# Otherwise if the current workspace is active, mark it
|
||||||
|
} elsif ($w->{id} eq $d->{focus}->[0]) {
|
||||||
|
$workspace = $w->{name};
|
||||||
|
}
|
||||||
|
# In any case, look for the terminal app
|
||||||
|
foreach my $n (@{$w->{floating_nodes}}) {
|
||||||
|
if ($n->{name} eq $term) {
|
||||||
|
$term_id = $n->{id};
|
||||||
|
$term_ws = $w->{name};
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# All other displays only need to be quickly searched for the term_id
|
||||||
|
} else {
|
||||||
|
foreach my $w (@{$d->{nodes}}) {
|
||||||
|
if (defined($term_id)) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
foreach my $n (@{$w->{floating_nodes}}) {
|
||||||
|
if ($n->{name} eq $term) {
|
||||||
|
$term_id = $n->{id};
|
||||||
|
$term_ws = $w->{name};
|
||||||
|
last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print("Current workspace is $workspace ($ww x $wh)\n");
|
|
||||||
#print("Found terminal at node $term_id\n") if (defined($term_id));
|
|
||||||
#print("Found terminal on workspace $term_ws\n") if (defined($term_ws));
|
|
||||||
|
|
||||||
# If there is no terminal found, spawn one
|
# If there is no terminal found, spawn one
|
||||||
my $resize = 0;
|
|
||||||
if (!defined($term_id)) {
|
if (!defined($term_id)) {
|
||||||
my $pid = fork();
|
print "No term running, starting one\n";
|
||||||
if ($pid) {
|
`$term --config-file $ENV{HOME}/.dotfiles/alacritty/grave.yml --class $class`;
|
||||||
print "No term running, starting one with PID $pid\n";
|
|
||||||
sleep 1;
|
|
||||||
$raw = join("\n",`swaymsg -t get_tree`);
|
|
||||||
$root = $json->decode($raw);
|
|
||||||
$term_id = search($root->{nodes}) || undef;
|
|
||||||
die("Term not found after starting") unless (defined($term_id));
|
|
||||||
} else {
|
|
||||||
print("Starting in fork...\n");
|
|
||||||
`$term --config-file $ENV{HOME}/.dotfiles/alacritty/grave.toml --class $app_id & disown`;
|
|
||||||
print("Exitting\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
resize();
|
|
||||||
}
|
|
||||||
|
|
||||||
# If the current workspace is known and terminal isn't on it, bring and focus
|
# If the current workspace is known and terminal isn't on it, bring and focus
|
||||||
if (defined($term_ws) && $workspace ne $term_ws) {
|
} elsif ($workspace != $term_ws) {
|
||||||
print "Term not on current workspace, bringing it\n";
|
print "Term not on current workspace, bringing it\n";
|
||||||
`swaymsg "[con_id=$term_id]" floating enable`;
|
|
||||||
resize();
|
|
||||||
`swaymsg "[con_id=$term_id]" sticky enable`;
|
|
||||||
`swaymsg "[con_id=$term_id]" move workspace $workspace`;
|
`swaymsg "[con_id=$term_id]" move workspace $workspace`;
|
||||||
`swaymsg "[con_id=$term_id]" focus`;
|
`swaymsg "[con_id=$term_id]" focus`;
|
||||||
|
`swaymsg "[con_id=$term_id]" sticky enable`;
|
||||||
# Otherwise hide it from whereever it is
|
# Otherwise hide it from whereever it is
|
||||||
} else {
|
} else {
|
||||||
print "Term is on current workspace or lost, moving to $hidden\n";
|
print "Term is on current workspace or lost, moving to $hidden\n";
|
||||||
`swaymsg "[con_id=$term_id]" sticky disable`;
|
`swaymsg "[con_id=$term_id]" sticky disable`;
|
||||||
`swaymsg "[con_id=$term_id]" move workspace $hidden`;
|
`swaymsg "[con_id=$term_id]" move workspace $hidden`;
|
||||||
`swaymsg "[con_id=$term_id]" floating disable`;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
OLDPWD=$OLDPWD
|
|
||||||
PWD=$PWD
|
|
||||||
cd $HOME/scripts/sway/
|
|
||||||
source ~/.dotfiles/bash/plenv-path.sh
|
|
||||||
perl -Ilocal/lib/perl5/5.38.2 displays.pl
|
|
||||||
cd $OLDPWD
|
|
||||||
cd $PWD
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
OLDPWD=$OLDPWD
|
|
||||||
PWD=$PWD
|
|
||||||
cd $HOME/scripts/sway/
|
|
||||||
source ~/.dotfiles/bash/plenv-path.sh
|
|
||||||
perl -Ilocal/lib/perl5/5.38.2 popup-term.pl
|
|
||||||
cd $OLDPWD
|
|
||||||
cd $PWD
|
|
|
@ -207,7 +207,7 @@ sub choose_image($self)
|
||||||
sub crop($self, $image, $ow, $oh)
|
sub crop($self, $image, $ow, $oh)
|
||||||
{
|
{
|
||||||
my $cropped = $image;
|
my $cropped = $image;
|
||||||
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}/$1-cropped.$2#;
|
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#;
|
||||||
|
|
||||||
use Image::Magick;
|
use Image::Magick;
|
||||||
my $im = Image::Magick->new();
|
my $im = Image::Magick->new();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ -z ${SWAYSOCK+x} ]; then
|
if [ -z ${SWAYSOCK+x} ]; then
|
||||||
i3 exit
|
i3lock -c 000000
|
||||||
else
|
else
|
||||||
sway exit
|
swaylock -c 000000
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,5 +3,7 @@ if [ -z ${SWAYSOCK+x} ]; then
|
||||||
i3 reload
|
i3 reload
|
||||||
else
|
else
|
||||||
swaymsg reload
|
swaymsg reload
|
||||||
${HOME}/scripts/sway/restore_display.sh
|
source ${HOME}/.dotfile/bash/bashrc
|
||||||
|
cd ${HOME}/scripts/sway
|
||||||
|
perl -Ilocal/lib/perl5/5.38.2 display.pl
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue