massive improvements lol

This commit is contained in:
Clay Gomera 2023-10-03 15:16:54 -04:00
parent 8ea5a726bf
commit 0d4bdcb5bb
6 changed files with 229 additions and 93 deletions

View file

@ -165,7 +165,7 @@ config.set('content.javascript.enabled', True, 'qute://*/*')
# Directory to save downloads to. If unset, a sensible OS-specific # Directory to save downloads to. If unset, a sensible OS-specific
# default is used. # default is used.
# Type: Directory # Type: Directory
c.downloads.location.directory = '~/Temporal/Downloads' c.downloads.location.directory = '~/var/downloads'
# When to show the tab bar. # When to show the tab bar.
# Type: String # Type: String

View file

@ -4,17 +4,18 @@
# - Description: A simple screenshot/screencast dmenu script # - Description: A simple screenshot/screencast dmenu script
# - Dependencies: maim, splop, ffmpeg, dmenu, libnotify # - Dependencies: maim, splop, ffmpeg, dmenu, libnotify
########################### #######################################
## Screenshots Directory ## ## Screenshot & Screencast Directory ##
########################### #######################################
SHOTDIR="$XDG_PICTURES_DIR/screenshots" SHOTDIR="$XDG_PICTURES_DIR/screenshots"
mkdir -p "$SHOTDIR"
###########################
## Screencasts Directory ##
###########################
CASTDIR="$XDG_VIDEOS_DIR/screencasts" CASTDIR="$XDG_VIDEOS_DIR/screencasts"
mkdir -p "$CASTDIR" [ ! -d "$SHOTDIR" ] && [ ! -d "$CASTDIR" ] && mkdir -p "$SHOTDIR" "$CASTDIR" || echo
######################
## Format Variables ##
######################
image_formats="jpg\npng"
video_formats="mp4\nmkv"
####################### #######################
## Main menu choices ## ## Main menu choices ##
@ -25,22 +26,22 @@ mcho3="󰙧 Stop recording"
mcho4="󱎘 Exit" mcho4="󱎘 Exit"
mchos="$mcho1\n$mcho2\n$mcho3\n$mcho4" mchos="$mcho1\n$mcho2\n$mcho3\n$mcho4"
############################# ##########################
## Screenshot menu choices ## ## Main submenu choices ##
############################# ##########################
scho1="󱣴 Entire screen" mscho1="󱣴 Capture the entire screen"
scho2="󱎫 Entire screen with delay" mscho2="󱎫 Capture the entire screen (With delay)"
scho3="󱕻 Select area" mscho3="󱕻 Capture area"
scho4="󰖯 Active window" mscho4="󰖯 Capture active window"
scho5="󱎘 Exit" mscho5="󱎘 Exit"
schos="$scho1\n$scho2\n$scho3\n$scho4\n$scho5" mschos="$mscho1\n$mscho2\n$mscho3\n$mscho4\n$mscho5"
######################## ###############################
## Screenshot submenu ## ## Save/clip submenu choices ##
######################## ###############################
sscho1="󰆏 Copy to clipboard" svcho1="󰆏 Copy to clipboard"
sscho2="󰠘 Save to $SHOTDIR" svcho2="󰠘 Save to $SHOTDIR"
sschos="$sscho1\n$sscho2" svchos="$svcho1\n$svcho2"
################################# #################################
## Screenshot delay subsubmenu ## ## Screenshot delay subsubmenu ##
@ -51,11 +52,24 @@ del3="󱑇 10 sec delay"
dels="$del1\n$del2\n$del3" dels="$del1\n$del2\n$del3"
##### #####
## This function uses the sschos variable to ask the user what to do with the ## This function will check for dependencies
#####
check_dependencies() {
local dependencies=("maim" "ffmpeg" "dmenu" "notify-send" "xclip" "xdotool")
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &>/dev/null; then
echo "$dep is required but not installed. Please install it and try again."
exit 1
fi
done
}
#####
## This function uses the svchos variable to ask the user what to do with the
## screenshot ## screenshot
##### #####
fsschos() { fsvchos() {
sschoice=$(echo -e "$sschos" | dmenu -i -l 2 -p " What do you want to do with this screenshot?") svchoice=$(echo -e "$svchos" | dmenu -i -l 2 -p " What do you want to do with this screenshot?")
} }
##### #####
@ -66,17 +80,32 @@ fdel() {
del=$(echo -e "$dels" | dmenu -i -p " Select Delay") del=$(echo -e "$dels" | dmenu -i -p " Select Delay")
} }
#####
## This function allows the user to choose the screenshot format
#####
fimage_format() {
image_format=$(echo -e "$image_formats" | dmenu -i -p " Choose screenshot format")
}
#####
## This function allows the user to choose the recording format
#####
fvideo_format() {
video_format=$(echo -e "$video_formats" | dmenu -i -p " Choose video format")
}
##### #####
## This function does a full screen screenshot without delay, depending on what ## This function does a full screen screenshot without delay, depending on what
## the user chooses on the fsschos function, the screenshot will be saved to the ## the user chooses on the fsvchos function, the screenshot will be saved to the
## clipboard or to $SHOTDIR ## clipboard or to $SHOTDIR
##### #####
shot_screen() { shot_screen() {
fsschos fimage_format
if [ "$sschoice" = "$sscho1" ]; then fsvchos
maim | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard" if [ "$svchoice" = "$svcho1" ]; then
elif [ "$sschoice" = "$sscho2" ]; then maim | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard"
maim -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved" elif [ "$svchoice" = "$svcho2" ]; then
maim -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved"
else else
exit 0 exit 0
fi fi
@ -84,36 +113,42 @@ shot_screen() {
##### #####
## This function does a full screen screenshot with delay, depending on what the ## This function does a full screen screenshot with delay, depending on what the
## user chooses on the fsschos function, the screenshot will be saved to the ## user chooses on the fsvchos function, the screenshot will be saved to the
## clipboard or to $SHOTDIR. And depending on what the user chooses on the fdel ## clipboard or to $SHOTDIR. And depending on what the user chooses on the fdel
## function, the delay will be between 3 and 10 seconds ## function, the delay will be between 3 and 10 seconds
##### #####
shot_screen_delay() { shot_screen_delay() {
fsschos; fimage_format
if [ "$sschoice" = "$sscho1" ]; then fsvchos
fdel; fdel
case $del in case $del in
"$del1") "$del1")
sleep 3 && maim | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard"; for i in 3 2 1
;; do
"$del2") notify-send -d 1 "Capturing in $i.."
sleep 5 && maim | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard"; sleep 0.1
;; done
"$del3") ;;
sleep 10 && maim | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard"; "$del2")
esac for i in 5 4 3 2 1
elif [ "$sschoice" = "$sscho2" ]; then do
fdel; notify-send -d 1 "Capturing in $i.."
case $del in sleep 0.1
"$del1") done
sleep 3 && maim -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved to $SHOTDIR"; ;;
;; "$del3")
"$del2") for i in 10 9 8 7 6 5 4 3 2 1
sleep 5 && maim -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved to $SHOTDIR"; do
;; notify-send -d 1 "Capturing in $i.."
"$del3") sleep 0.1
sleep 10 && maim -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved to $SHOTDIR"; done
esac ;;
esac
if [ "$svchoice" = "$svcho1" ]; then
maim | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
elif [ "$svchoice" = "$svcho2" ]; then
maim -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
else else
exit 0 exit 0
fi fi
@ -121,15 +156,16 @@ shot_screen_delay() {
##### #####
## This function allows the user to select the area on the screen to screenshot ## This function allows the user to select the area on the screen to screenshot
## depending on what the user chooses on the fsschos function, the screenshot will ## depending on what the user chooses on the fsvchos function, the screenshot will
## be saved to the clipboard or to $SHOTDIR ## be saved to the clipboard or to $SHOTDIR
##### #####
shot_area() { shot_area() {
fsschos; fimage_format
if [ "$sschoice" = "$sscho1" ]; then fsvchos
maim -s | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard"; if [ "$svchoice" = "$svcho1" ]; then
elif [ "$sschoice" = "$sscho2" ]; then maim -s | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
maim -s -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved to $SHOTDIR"; elif [ "$svchoice" = "$svcho2" ]; then
maim -s -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
else else
exit 0 exit 0
fi fi
@ -137,15 +173,16 @@ shot_area() {
##### #####
## This function does a screenshot of the currently active window, depending ## This function does a screenshot of the currently active window, depending
## on what the user chooses on the fsschos function, the screenshot will be ## on what the user chooses on the fsvchos function, the screenshot will be
## saved to the clipboard or to $SHOTDIR ## saved to the clipboard or to $SHOTDIR
##### #####
shot_window() { shot_window() {
fsschos; fimage_format
if [ "$sschoice" = "$sscho1" ]; then fsvchos
maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png && notify-send "Screenshot saved to clipboard"; if [ "$svchoice" = "$svcho1" ]; then
elif [ "$sschoice" = "$sscho2" ]; then maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
maim -i "$(xdotool getactivewindow)" -f jpg "$SHOTDIR/$(date +%s).jpg" && notify-send "Screenshot saved to $SHOTDIR"; elif [ "$svchoice" = "$svcho2" ]; then
maim -i "$(xdotool getactivewindow)" -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
else else
exit 0 exit 0
fi fi
@ -157,17 +194,58 @@ shot_window() {
## another ffmpeg instance, if it's not running, it will grab the screen ## another ffmpeg instance, if it's not running, it will grab the screen
## resolution with xdpyinfo and use it to record the screen with ffmpeg. ## resolution with xdpyinfo and use it to record the screen with ffmpeg.
##### #####
start_recording() { rec_screen() {
fvideo_format
if pgrep -x "ffmpeg" > /dev/null; then if pgrep -x "ffmpeg" > /dev/null; then
notify-send "A screen recording is already in progress." notify-send "A screen recording is already in progress."
else else
filename="$CASTDIR/$(date +%s).mp4" filename="$CASTDIR/$(date +%s).$video_format"
resolution="$(xdpyinfo | grep dimensions | awk '{print $2}')" resolution="$(xdpyinfo | grep dimensions | awk '{print $2}')"
ffmpeg -f x11grab -s "$resolution" -i :0.0 -c:v libx264 -preset ultrafast -qp 0 "$filename" & ffmpeg -f x11grab -s "$resolution" -i :0.0 -c:v libx264 -preset ultrafast -qp 0 "$filename" &
notify-send "Screen recording started." notify-send "Screen recording started."
fi fi
} }
#####
## This function will record the screen with a given delay
#####
rec_screen_delay() {
fvideo_format
fdel
case $del in
"$del1")
for i in 3 2 1
do
notify-send -d 1 "Starting in $i.."
sleep 0.1
done
;;
"$del2")
for i in 5 4 3 2 1
do
notify-send -d 1 "Starting in $i.."
sleep 0.1
done
;;
"$del3")
for i in 10 9 8 7 6 5 4 3 2 1
do
notify-send -d 1 "Starting in $i.."
sleep 0.1
done
;;
esac
if pgrep -x "ffmpeg" > /dev/null; then
notify-send "A screen recording is already in progress."
else
filename="$CASTDIR/$(date +%s).$video_format"
resolution="$(xdpyinfo | grep dimensions | awk '{print $2}')"
ffmpeg -f x11grab -s "$resolution" -i :0.0 -c:v libx264 -preset ultrafast -qp 0 "$filename" &
notify-send "Screen recording started"
fi
}
##### #####
## This function stops screen recording, it first checks if ffmpeg is already ## This function stops screen recording, it first checks if ffmpeg is already
## running (already recording), to only stop a recording if there's an ffmpeg ## running (already recording), to only stop a recording if there's an ffmpeg
@ -185,29 +263,48 @@ stop_recording() {
########## ##########
## main ## ## main ##
########## ##########
check_dependencies;
mchoice=$(echo -e "$mchos" | dmenu -i -l 4 -p " Screen Capture Menu") # main menu prompt mchoice=$(echo -e "$mchos" | dmenu -i -l 4 -p " Screen Capture Menu") # main menu prompt
case $mchoice in case $mchoice in
"$mcho1") "$mcho1")
schoice=$(echo -e "$schos" | dmenu -i -l 9 -p " Screenshot Menu") # screenshot menu prompt mschoice=$(echo -e "$mschos" | dmenu -i -l 9 -p " Screenshot Menu") # screenshot menu prompt
case $schoice in case $mschoice in
"$scho1") "$mscho1")
shot_screen; shot_screen;
;; ;;
"$scho2") "$mscho2")
shot_screen_delay; shot_screen_delay;
;; ;;
"$scho3") "$mscho3")
shot_area; shot_area;
;; ;;
"$scho4") "$mscho4")
shot_window; shot_window;
;; ;;
"$scho5") "$mscho5")
exit 0 exit 0
esac esac
;; ;;
"$mcho2") "$mcho2")
start_recording; mschoice=$(echo -e "$mschos" | dmenu -i -l 9 -p " Screencast Menu") # screenshot menu prompt
case $mschoice in
"$mscho1")
rec_screen;
;;
"$mscho2")
rec_screen_delay;
;;
"$mscho3")
#rec_area;
notify-send "not implemented yet"
;;
"$mscho4")
#rec_window;
notify-send "not implemented yet"
;;
"$mscho5")
exit 0
esac
;; ;;
"$mcho3") "$mcho3")
stop_recording; stop_recording;

View file

@ -5,7 +5,7 @@ libxft
libxinerama libxinerama
# extra dependencies # extra dependencies
xbacklight # brightness control brightnessctl # brightness control
pamixer # volume control pamixer # volume control
arandr # display config arandr # display config
st # terminal st # terminal
@ -13,10 +13,10 @@ dmenu # run launcher
dwmblocks # status bar scripts dwmblocks # status bar scripts
slock # lockscreen slock # lockscreen
herbe # notifications herbe # notifications
emacs # text editor lunarvim # text editor
# scratchpads # scratchpads
musikcube # music player cmus # music player
ani-cli # watch anime ani-cli # watch anime
flix-cli # watch movies flix-cli # watch movies
ytfzf # watch/listen to youtube ytfzf # watch/listen to youtube
@ -24,3 +24,4 @@ vifm # file manager
btop # process viewer btop # process viewer
pulsemixer # audio mixer 1 pulsemixer # audio mixer 1
alsamixer # audio mixer 2 alsamixer # audio mixer 2
tut # mastodon client

View file

@ -13,7 +13,7 @@ static const unsigned int pos_y = 60;
enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
enum corners corner = TOP_RIGHT; enum corners corner = TOP_RIGHT;
static const unsigned int duration = 5; /* in seconds */ static unsigned int duration = 5; /* in seconds */
#define DISMISS_BUTTON Button1 #define DISMISS_BUTTON Button1
#define ACTION_BUTTON Button3 #define ACTION_BUTTON Button3

View file

@ -115,8 +115,28 @@ int main(int argc, char *argv[])
sigaction(SIGUSR1, &act_ignore, 0); sigaction(SIGUSR1, &act_ignore, 0);
sigaction(SIGUSR2, &act_ignore, 0); sigaction(SIGUSR2, &act_ignore, 0);
int opt;
while ((opt = getopt(argc, argv, "d:")) != -1)
{
switch (opt)
{
case 'd':
duration = atoi(optarg); // Parse the duration from the command line
break;
default:
die("Usage: %s [-d duration] body", argv[0]);
}
}
if (optind >= argc)
{
die("Usage: %s [-d duration] body", argv[0]);
}
if (!(display = XOpenDisplay(0))) if (!(display = XOpenDisplay(0)))
die("Cannot open display"); {
die("Cannot open display");
}
int screen = DefaultScreen(display); int screen = DefaultScreen(display);
Visual *visual = DefaultVisual(display, screen); Visual *visual = DefaultVisual(display, screen);
@ -142,7 +162,7 @@ int main(int argc, char *argv[])
XftFont *font = XftFontOpenName(display, screen, font_pattern); XftFont *font = XftFontOpenName(display, screen, font_pattern);
for (int i = 1; i < argc; i++) for (int i = optind; i < argc; i++)
{ {
for (unsigned int eol = get_max_len(argv[i], font, max_text_width); eol; argv[i] += eol, num_of_lines++, eol = get_max_len(argv[i], font, max_text_width)) for (unsigned int eol = get_max_len(argv[i], font, max_text_width); eol; argv[i] += eol, num_of_lines++, eol = get_max_len(argv[i], font, max_text_width))
{ {
@ -191,8 +211,10 @@ int main(int argc, char *argv[])
sigaction(SIGUSR1, &act_expire, 0); sigaction(SIGUSR1, &act_expire, 0);
sigaction(SIGUSR2, &act_expire, 0); sigaction(SIGUSR2, &act_expire, 0);
if (duration != 0) if (duration > 0)
alarm(duration); {
alarm(duration);
}
for (;;) for (;;)
{ {

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# Shell script to redirect notify-send calls to herbe. The purpose is to ignore # Shell script to redirect notify-send calls to herbe. The purpose is to ignore
# options passed to notify-send. # options passed to notify-send and wait for herbe to finish.
# #
# Option parser generated by getoptions # Option parser generated by getoptions
# URL: https://github.com/ko1nksm/getoptions # URL: https://github.com/ko1nksm/getoptions
@ -10,11 +10,18 @@ usage() {
printf '%s\n' "${0##*/}: notify-send replacement for herbe" "accepts but ignores all notify-send options." printf '%s\n' "${0##*/}: notify-send replacement for herbe" "accepts but ignores all notify-send options."
} }
REST='' # Default duration value
duration=""
parse() { parse() {
OPTIND=$(($#+1)) OPTIND=$(($#+1))
while [ $# -gt 0 ] && OPTARG=; do while [ $# -gt 0 ] && OPTARG=; do
case $1 in case $1 in
-d) # Parse the duration option and its value
[ $# -le 1 ] && set -- "$1" required && break
duration=$2
_=$duration
shift 2 ;; # Shift both the option and its value
--?*=*) OPTARG=$1; shift --?*=*) OPTARG=$1; shift
eval 'set -- "${OPTARG%%\=*}" "${OPTARG#*\=}"' ${1+'"$@"'} eval 'set -- "${OPTARG%%\=*}" "${OPTARG#*\=}"' ${1+'"$@"'}
;; ;;
@ -78,4 +85,13 @@ parse() {
parse "$@" parse "$@"
eval set -- "$REST" eval set -- "$REST"
herbe "$@" &
# Pass the duration option to herbe if it's specified
if [ -n "$duration" ]; then
herbe -d "$duration" "$@" &
else
herbe "$@" &
fi
# Wait for the herbe process to finish
wait