-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlswmenu
More file actions
executable file
·122 lines (89 loc) · 2.36 KB
/
Copy pathlswmenu
File metadata and controls
executable file
·122 lines (89 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env perl
# lswmenu - list windows, select and jump to the specified one
# See LICENSE file for copyright and license details.
use strict;
use warnings;
#use diagnostics;
use IPC::Open2;
my $VERBOSE = 0;
my $WINJMP = 'wmctrl';
my %WNDs = ();
sub lswin {
my @args = @_;
print "Open pipe into 'lsw @args'\n" if $VERBOSE;
open(my $lsw_fh, '-|', "lsw @args")
or die "$0: couldn't open a pipe into lsw: $!\n";
while (my $line = <$lsw_fh>) {
chomp $line;
my ($wid, $text) = ($1, $2)
if $line =~ /^(0x[0-9a-h]{7}) (.*)$/;
print "Window $wid: $text\n" if $VERBOSE;
$WNDs{ $wid } = length($text) ? $text : "(null)";
}
close $lsw_fh;
return keys %WNDs;
}
sub dmenu_sel_win {
my @args = @_;
my $selwin;
print "Open pipe into 'dmenu @args'\n" if $VERBOSE;
open2(my $chld_out, my $chld_in, 'dmenu', @args)
or die "$0: open2() failed: $!\n";
print $chld_in "$WNDs{ $_ }\n" for sort keys %WNDs;
close $chld_in;
while (<$chld_out>) {
chomp;
$selwin .= $_;
}
close $chld_out;
print "Selected '$selwin'.\n" if $VERBOSE;
return $selwin;
}
sub goto_sel_win {
my $wid = shift;
if ($WINJMP eq 'xdotool') {
print "Execute 'xdotool windowactivate $wid'\n"
if $VERBOSE;
system("xdotool windowactivate '$wid'");
} elsif ($WINJMP eq 'wmctrl') {
print "Execute 'wmctrl -i -a $wid'\n" if $VERBOSE;
system("wmctrl -i -a '$wid'");
} elsif ($WINJMP eq 'xdo') {
print "Execute 'xdo activate $wid'\n" if $VERBOSE;
system("xdo activate '$wid'");
} else {
die "$0: unknown window jumper: $WINJMP\n";
}
}
sub main {
my @lswargs;
my @dmenuargs;
for (@ARGV) {
if (/\bverbose\b/) { $VERBOSE++ }
elsif (/\bxdotool\b/) { $WINJMP = 'xdotool' }
elsif (/\bxdo\b/) { $WINJMP = 'xdo' }
elsif (/\b(0x[0-9a-h]{7})\b/) { push @lswargs, $_ }
else { push @dmenuargs, $_ }
}
print <<EOF if $VERBOSE > 1;
--------------------------------
Verbosity level: $VERBOSE
Window jumper: $WINJMP
lsw(1) optargs: @lswargs
dmenu(1) optargs: @dmenuargs
--------------------------------
EOF
lswin(@lswargs)
or die "$0: no windows available\n";
my $sel = dmenu_sel_win(@dmenuargs)
or die "$0: cannot select window\n";
for my $wid (keys %WNDs) {
if ($WNDs{ $wid } eq $sel) {
goto_sel_win($wid) and last;
}
}
}
main() if not caller;
1;
# vim: cc=72 tw=70
# End of file.