forked from onokatio/wayland-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwshot.sh
executable file
·186 lines (167 loc) · 4.52 KB
/
wshot.sh
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
if
[ ! "$XDG_SESSION_TYPE" = "wayland" ];
then
zenity \
--title=Wshot \
--width=150 \
--warning \
--timeout 5 \
--text="Wshot works only on wayland"
exit 0
fi
if pgrep -x -u $USER "kwin_wayland" > /dev/null
then
zenity \
--title=Wshot \
--width=150 \
--warning \
--timeout 5 \
--text="kwin_wayland is not supported"
exit 0
fi
_() {
gettext wshot "$1"
}
WshotApp() {
local FILEDIR=/tmp
local OPTION=()
# Translation strings
local _textOptions=$(_ "Options")
local _grabMode=$(_ "Mode")
local _fullScreen=$(_ "Full screen")
local _selectedArea=$(_ "Selected area")
local _selectedWindow=$(_ "Selected window")
local _withCursor=$(_ "Include cursor")
## both below not used under qarma:
local _nope=$(_ "no")
local _yep=$(_ "yes")
local _delay=$(_ "Delay")
local _destination=$(_ "Destination")
local _saveFile=$(_ "Save file")
local _clipboard=$(_ "Clipboard")
local _customFilename=$(_ "Custom filename:")
local _fileType=$(_ "File type")
local _openSaved=$(_ "Open saved result")
local _shotToClip=$(_ "Screenshot copied to clipboard")
local _savedAs=$(_ "Screenshot saved as")
local _winDetectionError=$(_ "Compositor does not support automatic window detection.")
if command -v qarma &>/dev/null; then
# using qarma
local values=$(zenity \
--window-icon=/usr/share/pixmaps/wshot.png \
--title=Wshot \
--text="$_textOptions" \
--forms \
--add-combo="$_grabMode" \
--combo-values="$_fullScreen|$_selectedArea|$_selectedWindow" \
--add-combo="$_delay" \
--combo-values="0|2|4|6|8|10|15|20" \
--add-combo="$_destination" \
--combo-values="$_saveFile|$_clipboard" \
--add-entry="$_customFilename" \
--add-combo="$_fileType" \
--combo-values="png|jpeg" \
--add-checkbox="$_withCursor" \
--add-checkbox="$_openSaved" \
)
OK="true"
else
# using zenity
local values=$(zenity \
--icon=/usr/share/pixmaps/wshot.png \
--title=Wshot \
--text="$_textOptions" \
--forms \
--add-combo="$_grabMode" \
--combo-values="$_fullScreen|$_selectedArea|$_selectedWindow" \
--add-combo="$_delay" \
--combo-values="0|2|4|6|8|10|15|20" \
--add-combo="$_destination" \
--combo-values="$_saveFile|$_clipboard" \
--add-entry="$_customFilename" \
--add-combo="$_fileType" \
--combo-values="png|jpeg" \
--add-combo="$_withCursor" \
--combo-values="$_nope|$_yep" \
--add-combo="$_openSaved" \
--combo-values="$_nope|$_yep" \
)
fi
if [ -z "$values" ]; then
echo "Goodbye!"
exit 0
fi
if [ -z "$values" ]; then
echo "Goodbye!"
exit 0
fi
local result=$?
local mode=$(echo $values | cut -d '|' -f 1)
local wait=$(echo $values | cut -d '|' -f 2)
local destination=$(echo $values | cut -d '|' -f 3)
local filename=$(echo $values | cut -d '|' -f 4|tr -cd '[:alnum:]')
local filetype=$(echo $values | cut -d '|' -f 5)
local cursor=$(echo $values | cut -d '|' -f 6)
local open=$(echo $values | cut -d '|' -f 7)
if [ "$cursor" = "$_nope" ]; then
unset cursor
fi
if [ "$open" = "$_yep" ]; then
open="true"
fi
if [ "$result" -eq 1 ];then # selected cancel
echo "Goodbye!"
exit
fi
if [ ! -z "$cursor" ];then
OPTION+="-c"
fi
if [ ! -z "$wait" ];then
sleep $wait
fi
if [ "$mode" == "$_fullScreen" ];then
true
elif [ "$mode" == "$_selectedWindow" ];then
if pgrep -x sway > /dev/null; then
GEO="$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)"
elif pgrep -x wayfire > /dev/null; then
GEO=$(wf-info |grep Geometry |cut -c 10-)
elif pgrep -x Hyprland > /dev/null; then
GEO="$(hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | slurp)"
else
zenity \
--title=Wshot \
--width=150 \
--warning \
--timeout 3 \
--text="$_winDetectionError"
GEO="$(slurp)"
fi
elif [ "$mode" == "$_selectedArea" ];then
GEO="$(slurp)"
fi
if [ -z "$filename" ];then
filename=screenshot_$(date +%F_%H.%M.%S)
fi
if [ -z "$destination" ] || [ "$destination" == "$_clipboard" ];then
if [ -z "$GEO" ]; then
grim $OPTION -t $filetype - | wl-copy;
else
grim $OPTION -t $filetype -g "$GEO" - | wl-copy;
fi
notify-send -t 3000 -a Wshot -i /usr/share/pixmaps/wshot.png "$_shotToClip"
else
if [ -z "$GEO" ]; then
grim $OPTION -t $filetype $FILEDIR/$filename.$filetype
else
grim $OPTION -t $filetype -g "$GEO" $FILEDIR/$filename.$filetype
fi
if [ "$open" == "true" ]; then
xdg-open $FILEDIR/$filename.$filetype
else
notify-send -t 3000 -a Wshot -i /usr/share/pixmaps/wshot.png "$_savedAs $FILEDIR/$filename.$filetype"
fi
fi
}
WshotApp