-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmxfb-quickshot
More file actions
executable file
·282 lines (228 loc) · 7.3 KB
/
mxfb-quickshot
File metadata and controls
executable file
·282 lines (228 loc) · 7.3 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
## this app is based on one by tenner that can be downloaded at http://tenr.de/snippets/scripts/shot.sh
## it has been modified and expanded for use with MX-Fluxbox
## released under GPLv3
# mxfb-quickshot version
VERSION="2504-02"
## the following parameters are set in ${HOME}/.config/MX-Linux/mxfb-quickshot.conf
#OPTION="-s -q 100"
#DESTDIR="$(xdg-user-dir PICTURES)"
#NAME="$(date +'%y%m%d_%H%M%S')"
#SUF="png"
#PRE="quickshot_"
# check yad version and set buttons
yad_version_check=$(yad --version 2>/dev/null | sed "s/[^0-9].*//")
if [[ $yad_version_check -gt 0 ]]; then
yad_btn_ok='yad-ok'
yad_btn_cancel='yad-cancel'
else
yad_btn_ok='gtk-ok'
yad_btn_cancel='gtk-cancel'
fi
BASE_NAME=$(basename "$0")
DATE=$(date '+%Y%m%d')
CONFIG_DIR="$HOME/.config/MX-Linux"
BACKUP_DIR="$HOME/.restore/MX-Linux"
CONFIG_NAME="mxfb-quickshot.conf"
BACKUP_NAME="${CONFIG_NAME}_${VERSION}_${DATE}"
FLUXBOXKEYS="$HOME/.fluxbox/keys"
USER_CONFIG="${CONFIG_DIR}/${CONFIG_NAME}"
DISMISS_CHK="${CONFIG_DIR}/mxfb-quickshot-dismiss.chk"
BACKUP_CONF="${BACKUP_DIR}/${BACKUP_NAME}"
SYSTEM_CONF="/usr/share/mxfb-quickshot/$CONFIG_NAME"
ICONPATH="/usr/share/icons/Papirus/24x24/devices/camera.svg"
# take icon from theme if needed
[ -e "$ICONPATH" ] || ICONPATH=camera-photo
WM_CLASS=mxfb-quickshot
# messages shown
USAGE="Usage: $BASE_NAME [-r|r|-u|u] [-png|png|-jpg|jpg]"
#set up translation
export TEXTDOMAIN=mxfb-accessories
export TEXTDOMAINDIR=/usr/share/locale
source gettext.sh
#Note: Comment lines above gettext lines are visible to translators.
# The capture of a screenshot was aborted.
NONE_SELECTED=$(gettext 'exiting, no image selected')
# The capture of a screenshot was cancelled.
CANCELLED=$(gettext 'Cancelled!')
# The capture of a screenshot was successful.
SUCCESS=$(gettext 'Success!')
# Do you want to allow a new config file to be installed?
OK_TO_PROCEED=$(gettext 'OK to proceed?')
# Do you want to display the Help message again?
DISMISS=$(gettext 'Dismiss')
DISMISS_HELP=$(gettext "Don't display the Help message again!")
# A new config file will be installed.
UPGRADE_MESSAGE=$(gettext 'This will install a new config file')
# The existing config file will be copied into a backup directory.
BACKUP_MESSAGE=$(gettext 'The existing file will be backed up in:')
MESSAGE="$UPGRADE_MESSAGE\n\n$BACKUP_MESSAGE\n\n<b>$BACKUP_DIR/</b>"
HELP_TITLE=$(gettext 'HELP: how to take a screenshot')
# How to take a screenshot...
HELP0=$(gettext 'Press "Print" (or "PrtSc") and use the mouse:')
# Press the Print-Screen-key to capture a window.
# WINDOW: press Print, then click anywhere inside
HELP1=$(gettext 'WINDOW: click anywhere inside')
# Press the Print-Screen-key to capture a wallpaper.
# DESKTOP: press Print, then click the background
HELP2=$(gettext 'DESKTOP: click the background')
# Press the Print-Screen-key to capture a screen selection.
# SELECTION: press Print, then draw a rectangle
HELP3=$(gettext 'SELECTION: draw a rectangle')
HELP_MESSAGE="
$HELP0
--$HELP1
--$HELP2
--$HELP3
"
# Hints for creating a screenshot
# The help message will not be displayed again, if user clicks on "Dismiss" button.
# The capture of a screenshot will start after closing this window.
HELP_HINTS=$(eval_gettext '
Hints
--Click "Dismiss" to hide Help in the future!
--Capture Help by clicking it after agreeing to proceed
--More: search "Quickshot" in the MX Wiki')
display_help() {
printf "%s\n" "$USAGE"
}
if [ ! -f "$DISMISS_CHK" ]; then
HELP=(
/usr/bin/notify-send
-i "$ICONPATH"
-t 30000
"$HELP_TITLE"
"$HELP_MESSAGE"
)
"${HELP[@]}"
sleep 3
YAD=(yad
--title="Quickshot"
--class="$WM_CLASS"
--window-icon="$ICONPATH"
--borders=20
--center
--fixed
--height=300
--width=300
--text-align=left
--text="\n\n<b>$HELP_HINTS</b>\n\n"
--button="$DISMISS"'!!'"$DISMISS_HELP":3
--button="$yad_btn_ok"
)
"${YAD[@]}"
if [ $? = 3 ]; then
[ -d "$CONFIG_DIR" ] || mkdir -p "$CONFIG_DIR"
echo "VERSION=$VERSION" > "$DISMISS_CHK"
fi
fi
if [ -r "$SYSTEM_CONF" ] && [ ! -r "$USER_CONFIG" ]; then
[ -d "$CONFIG_DIR" ] || mkdir -p "$CONFIG_DIR"
cp "$SYSTEM_CONF" "$USER_CONFIG"
[ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"
cp "$USER_CONFIG" "$BACKUP_CONF"
fi
if ! ls "${BACKUP_DIR}/${CONFIG_NAME}_${VERSION}"* >/dev/null 2>&1 &&
[ -r "$USER_CONFIG" ] && [ -r "$SYSTEM_CONF" ] &&
! cmp -s "$SYSTEM_CONF" "$USER_CONFIG" ; then
YAD=(yad
--title="Quickshot"
--class="$WM_CLASS"
--window-icon="$ICONPATH"
--width=350
--height=200
--borders=20
--center
--text-align=center
--text="\n\n$MESSAGE\n\n"
--button="$yad_btn_cancel":7
--button="$OK_TO_PROCEED":6
)
"${YAD[@]}"
[ $? = 6 ] || exit 0
[ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"
cp "$USER_CONFIG" "$BACKUP_CONF"
cp "$SYSTEM_CONF" "$USER_CONFIG"
fi
# using "safe-source" instead of source "$USER_CONFIG"
# safe-source - will read only allowed config parameter lines from user config
# as defined in system config. Other paramter and lines are ignored.
#
ALLOWED_CONF_PARAMETER=( $(sed -r '/^\s*[a-zA-Z_]+=/!d; s/=.*//' $SYSTEM_CONF 2>/dev/null) )
if [ ${#ALLOWED_CONF_PARAMETER[@]} != 0 ]; then
CONF_PARAMETER_PATTERN="${ALLOWED_CONF_PARAMETER[*]}"
CONF_PARAMETER_PATTERN="${CONF_PARAMETER_PATTERN// /|}"
USER_CONF_PARAMETER=$(sed -r "/^\s*(${CONF_PARAMETER_PATTERN})=/!d" "$USER_CONFIG" 2>/dev/null )
eval "$USER_CONF_PARAMETER"
fi
# user config sanity check
# set to reasonable vaules with := assignment only if not set already
: ${OPTION:="-s -q 100"}
: ${DESTDIR:=$(xdg-user-dir PICTURES)}
: ${NAME:=$(date +%y%m%d_%H%M%S)}
: ${PRE:=quickshot_}
: ${SUF:=png}
: ${TIMEOUT:=5}
: ${ICONPATH:=/usr/share/icons/Papirus/24x24/devices/camera.svg}
# take icon from theme if needed - in case user change in conf was allowed
[ -e "$ICONPATH" ] || ICONPATH=camera-photo
# use home directory if destdir is not defined
: ${DESTDIR:=$HOME}
take_shot() {
local ret
local filename="${PRE}${NAME}.${SUF}"
local exec_option='mv $f '"$DESTDIR"
[ -w "$PWD" ] || cd "$HOME" # to make shure current directory is writable
if [ "$(readlink -e "$DESTDIR")" = "$(readlink -e "$PWD")" ]; then
scrot ${OPTION} "${PRE}${NAME}.${SUF}"
ret=$?
else
scrot ${OPTION} "${PRE}${NAME}.${SUF}" -e "$exec_option"
ret=$?
fi
if [ $ret = 1 ]; then
/usr/bin/notify-send -i "$ICONPATH" -t 3000 "$CANCELLED"
exit 0
fi
if [ $ret = 2 ] ; then
echo "$NONE_SELECTED"
exit 1
fi
return $ret
}
if [ $# -eq 0 ]; then
take_shot && /usr/bin/notify-send -i "$ICONPATH" -t 3000 " $SUCCESS"
exit 0
fi
if [ $# -gt 2 ]; then
display_help
exit 1
fi
ARG1=${1#-} # remove '-' from start of arg
case "${ARG1,,}" in # lower case
r|root)
OPTION=""
;;
u|focused)
OPTION="-u"
;;
*)
display_help
exit 1
;;
esac
ARG2=${2#-} # remove '-' from start of arg
case "${ARG2,,}" in # lower case
jpg)
SUF="jpg"
;;
png)
SUF="png"
;;
*)
display_help
exit 1
;;
esac
take_shot
exit $?