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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#!/usr/bin/env perl
use strict;
use warnings;
use File::HomeDir qw(home);
use constant {
SAVE_PATH => 'pics/scrot/',
SCREENSHOT_PATH => 'scrot',
IMGVIEW_PATH => 'nsxiv',
XCLIP_PATH => 'xclip',
NOTIFY_PATH => 'notify-send'
};
use constant LIST => [
'select region',
'window',
'fullscreen',
'monitor 1',
'monitor 2'
];
sub show_img
{
my ($file) = @_;
my $pid;
$pid = fork();
if (not $pid) {
exec(IMGVIEW_PATH, '-b', $file);
}
return;
}
sub notify_img
{
my ($file) = @_;
system(
NOTIFY_PATH,
'-u', 'low',
'-t', '2000',
'scrot',
' screenshot captured to ' . "\n" .
'<b>' . $file . '</b>'
);
return;
}
sub clip_img
{
my ($file) = @_;
chomp $file;
system('echo -n ' . $file . ' | ' . XCLIP_PATH);
system('copyq write image/png - < ' . $file);
system('copyq', 'select', '0');
return;
}
sub file_name
{
my $file_name;
$file_name = home() . '/' . SAVE_PATH . 'screen_';
$file_name .= `date +%s`;
chomp $file_name;
$file_name .= '.png';
return ($file_name);
}
sub action
{
my ($var) = @_;
my $pid;
my $file_name;
chomp $var;
$file_name = file_name();
if ($var eq ${+LIST}[0]) {
system(
SCREENSHOT_PATH,
$file_name,
'-q', '100',
'-s',
'-l', 'mode=edge,width=2,color=#990000'
);
}
elsif ($var eq ${+LIST}[1]) {
system(
SCREENSHOT_PATH,
$file_name,
'-q', '100',
'-u'
);
}
elsif ($var eq ${+LIST}[2]) {
system(
SCREENSHOT_PATH,
$file_name,
'-q', '100'
);
}
elsif ($var eq ${+LIST}[3]) {
system(
SCREENSHOT_PATH,
$file_name,
'-q', '100',
'-a', '0,0,1920,1080'
);
}
elsif ($var eq ${+LIST}[4]) {
sleep(1);
system(
SCREENSHOT_PATH,
$file_name,
'-q', '100',
'-a', '1920,0,2560,1440'
);
}
else {
return;
}
show_img($file_name);
notify_img($file_name);
clip_img($file_name);
return;
}
sub main
{
my $list;
my $choice;
my $color;
$color = '#cc241d';
if (@ARGV == 1) {
$color = $ARGV[0];
}
for (@{+LIST}) {
$list .= $_ . "\n";
}
$choice = `printf "%s" "$list" | dmenu -i -sb '$color' -shb '$color'`;
action($choice);
return (0);
}
main();
__END__
|