New scripts: sxmo_{youtube,weather,rss,camera}.sh; Implement screenlock

Various minor script bugfixes
master
Miles Alan 5 years ago
parent 9beef511af
commit ed09f2b8b3
  1. 9
      Makefile
  2. 32
      configs/sxmo_sfeedrc
  3. 33146
      configs/zipcodes_for_weather.csv
  4. 148
      programs/sxmo_screenlock.c
  5. 49
      scripts/sxmo_appmenu.sh
  6. 3
      scripts/sxmo_camera.sh
  7. 33
      scripts/sxmo_command.sh
  8. 6
      scripts/sxmo_dimscreentoggle.sh
  9. 4
      scripts/sxmo_dmenu_with_kb.sh
  10. 30
      scripts/sxmo_keyboard.sh
  11. 18
      scripts/sxmo_lowpowermode.sh
  12. 25
      scripts/sxmo_pastecomplete.sh
  13. 53
      scripts/sxmo_rss.sh
  14. 7
      scripts/sxmo_surf_linkselect.sh
  15. 4
      scripts/sxmo_timermenu.sh
  16. 35
      scripts/sxmo_urlhandler.sh
  17. 7
      scripts/sxmo_vol.sh
  18. 23
      scripts/sxmo_weather.sh
  19. 1
      scripts/sxmo_xinit.sh
  20. 23
      scripts/sxmo_youtube.sh

@ -6,7 +6,10 @@ programs/sxmo_setpineled:
programs/sxmo_setpinebacklight:
gcc -o programs/sxmo_setpinebacklight programs/sxmo_setpinebacklight.c
install: programs/sxmo_setpineled programs/sxmo_setpinebacklight
programs/sxmo_screenlock:
gcc -o programs/sxmo_screenlock programs/sxmo_screenlock.c -lX11
install: programs/sxmo_setpineled programs/sxmo_setpinebacklight programs/sxmo_screenlock
mkdir -p $(PREFIX)/usr/share/sxmo
cp configs/* $(PREFIX)/usr/share/sxmo
@ -23,3 +26,7 @@ install: programs/sxmo_setpineled programs/sxmo_setpinebacklight
chown root programs/sxmo_setpinebacklight
chmod u+s programs/sxmo_setpinebacklight
cp programs/sxmo_setpinebacklight $(PREFIX)/usr/bin
chown root programs/sxmo_screenlock
chmod u+s programs/sxmo_screenlock
cp programs/sxmo_screenlock $(PREFIX)/usr/bin

@ -0,0 +1,32 @@
#sfeedpath="$HOME/.sfeed/feeds"
USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
#[ -z "$https_proxy" ] && echo "Please set https_proxy" 2>&1 && exit 1
#[ -z "$http_proxy" ] && echo "Please set http_proxy" 2>&1 && exit 1
# fetch a feed via HTTP/HTTPS etc.
# fetch(name, url, feedfile)
fetch() {
# fail on redirects, hide User-Agent, timeout is 15 seconds.
curl -L --max-redirs 2 -H "User-Agent: $USERAGENT" -f -s -m 15 \
"$2" 2>/dev/null
}
# list of feeds to fetch:
feeds() {
# feed <name> <feedurl> [basesiteurl] [encoding]
feed 'Tech/HN' 'https://news.ycombinator.com/rss'
feed 'Tech/Lobsters' 'https://lobste.rs/rss'
feed 'Tech/Pine64' 'https://www.pine64.org/blog/'
feed 'Tech/Slashdot' 'http://feeds.feedburner.com/SlashdotSitenews'
feed 'Tech/Suckless' 'http://git.suckless.org/sites/atom.xml'
feed 'Yt/Distrotube' 'https://www.youtube.com/feeds/videos.xml?channel_id=UCVls1GmFKf6WlTraIb_IaJg'
feed 'Yt/Budlabs' 'https://www.youtube.com/feeds/videos.xml?channel_id=UCi8XrDg1bK_MJ0goOnbpTMQ'
feed 'Yt/LukeSmith' 'https://www.youtube.com/feeds/videos.xml?channel_id=UC2eYFnH61tmytImy1mTYvhA'
feed 'Yt/Rossman' 'https://www.youtube.com/feeds/videos.xml?channel_id=UCl2mFZoRqjw_ELax4Yisf6w'
feed 'MSM/CNN' 'http://rss.cnn.com/rss/cnn_topstories.rss'
feed 'MSM/Fox' 'http://feeds.foxnews.com/foxnews/latest'
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,148 @@
#include <X11/XF86keysym.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
static int running = 1;
static int lastkeysym = NULL;
static int lastkeyn = 0;
static int oldbrightness = 10;
static int screenon = 1;
static char screentogglecommand[100];
void
updatescreen() {
sprintf(
screentogglecommand,
"sh -c 'echo %d > /sys/devices/platform/backlight/backlight/backlight/brightness'",
screenon ? oldbrightness : 0
);
if (screenon) {
system("sh -c 'echo 1 > /sys/devices/platform/leds/leds/pinephone:blue:user/brightness'");
system("sh -c 'echo 0 > /sys/devices/platform/leds/leds/pinephone:red:user/brightness'");
} else {
system("sh -c 'echo 0 > /sys/devices/platform/leds/leds/pinephone:blue:user/brightness'");
system("sh -c 'echo 1 > /sys/devices/platform/leds/leds/pinephone:red:user/brightness'");
}
system(screentogglecommand);
}
void
cleanupscreen() {
screenon = 1;
updatescreen();
system("sh -c 'echo 0 > /sys/devices/platform/leds/leds/pinephone:red:user/brightness'");
system("sh -c 'echo 0 > /sys/devices/platform/leds/leds/pinephone:blue:user/brightness'");
}
static void die(const char *err, ...) {
fprintf(stderr, "Error: %s", err);
cleanupscreen();
exit(1);
}
static void usage(void) {
die("usage: slock [-v] [cmd [arg ...]]\n");
}
// Loosely derived from suckless' slock's lockscreen binding logic but
// alot more coarse, intentionally so can be triggered while grab_key
// for dwm multikey path already holding..
void lockscreen(Display *dpy, int screen) {
int i, ptgrab, kbgrab;
//XSetWindowAttributes wa;
Window root;
//win,
root = RootWindow(dpy, screen);
//wa.override_redirect = 1;
//win = XCreateWindow(dpy, root, 0, 0,
// DisplayWidth(dpy, screen),
// DisplayHeight(dpy, screen),
// 0, DefaultDepth(dpy, screen),
// CopyFromParent,
// DefaultVisual(dpy, screen),
// CWOverrideRedirect | CWBackPixel, &wa);
for (i = 0, ptgrab = kbgrab = -1; i < 9999999; i++) {
if (ptgrab != GrabSuccess) {
ptgrab = XGrabPointer(dpy, root, False,
ButtonPressMask | ButtonReleaseMask |
PointerMotionMask, GrabModeAsync,
GrabModeAsync, None, None, CurrentTime);
}
if (kbgrab != GrabSuccess) {
kbgrab = XGrabKeyboard(dpy, root, True,
GrabModeAsync, GrabModeAsync, CurrentTime);
}
if (ptgrab == GrabSuccess && kbgrab == GrabSuccess) {
XSelectInput(dpy, root, SubstructureNotifyMask);
return;
}
usleep(100000);
}
return;
}
void
readinputloop(Display *dpy, int screen) {
KeySym keysym;
XEvent ev;
char buf[32];
while (running && !XNextEvent(dpy, &ev)) {
if (ev.type == KeyPress) {
XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, 0);
if (lastkeysym == keysym) {
lastkeyn++;
} else {
lastkeysym = keysym;
lastkeyn = 1;
}
if (lastkeyn < 3)
continue;
lastkeyn = 0;
lastkeysym = NULL;
switch (keysym) {
case XF86XK_AudioRaiseVolume:
screenon = !screenon;
updatescreen();
break;
case XF86XK_AudioLowerVolume:
screenon = !screenon;
updatescreen();
break;
case XF86XK_PowerOff:
cleanupscreen();
running = 0;
break;
}
}
}
}
int
main(int argc, char **argv) {
Display *dpy;
Screen *screen;
if (setuid(0))
die("setuid(0) failed\n");
if (!(dpy = XOpenDisplay(NULL)))
die("Cannot open display\n");
updatescreen();
screen = XDefaultScreen(dpy);
XSync(dpy, 0);
lockscreen(dpy, screen);
XSync(dpy, 0);
readinputloop(dpy, screen);
return 0;
}

@ -6,33 +6,61 @@ programchoicesinit() {
# Default
CHOICES="$(echo "
Push window tag → ^ 0 ^ sxmo_lowpowermode.sh
Tag focus → ^ 0 ^ sxmo_lowpowermode.sh
Applications ^ 0 ^ sxmo_appmenu.sh applications
Scripts ^ 0 ^ sxmo_appmenu.sh scripts
Apps ^ 0 ^ sxmo_appmenu.sh applications
Volume ↑ ^ 1 ^ sxmo_vol.sh up
Volume ↓ ^ 1 ^ sxmo_vol.sh down
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up
Brightness ↓ ^ 1 ^ sxmo_brightness.sh down
Camera ^ 0 ^ sxmo_camera.sh
Wifi ^ 0 ^ st -e "nmtui"
Rotate ^ 1 ^ rotate
Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh
System Config ^ 0 ^ sxmo_appmenu.sh control
Logout ^ 0 ^ pkill -9 dwm
Close Menu ^ 0 ^ quit
")" && WINNAME=sys
")" && WINNAME=Sys
echo $WMCLASS | grep -i "applications" && CHOICES="$(echo "
Surf ^ 0 ^ surf
NetSurf ^ 0 ^ netsurf
Sacc ^ 0 ^ st -e sacc i-logout.cz/1/bongusta
W3M ^ 0 ^ st -e w3m duck.com
St ^ 0 ^ st
Firefox ^ 0 ^ firefox
Foxtrotgps ^ 0 ^ foxtrotgps
Timer ^ 0 ^ sxmo_timermenu.sh
Close Menu ^ 0 ^ quit
")" && WINNAME=Apps
echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo "
Timer ^ 0 ^ sxmo_timermenu.sh
Youtube ^ 0 ^ sxmo_youtube.sh
Youtube (Audio) ^ 0 ^ sxmo_youtube.sh
Weather ^ 0 ^ sxmo_weather.sh
RSS ^ 0 ^ sxmo_rss.sh
Close Menu ^ 0 ^ quit
")" && WINNAME=Scripts
echo $WMCLASS | grep -i "control" && CHOICES="$(echo "
Volume ↑ ^ 1 ^ sxmo_vol.sh up
Volume ↓ ^ 1 ^ sxmo_vol.sh down
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up
Brightness ↓ ^ 1 ^ sxmo_brightness.sh down
Rotate ^ 1 ^ rotate
Wifi ^ 0 ^ st -e "nmtui"
Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh
Close Menu ^ 0 ^ quit
")" && WINNAME=Control
echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo "
Pause ^ 0 ^ key space
Pause ^ 0 ^ key space
Seek ← ^ 1 ^ key Left
Seek → ^ 1 ^ key Right
App Volume ↑ ^ 1 ^ key 0
App Volume ↓ ^ 1 ^ key 9
Speed ↑ ^ 1 ^ key bracketright
Speed ↓ ^ 1 ^ key bracketleft
Screenshot ^ 1 ^ key s
Loopmark ^ 1 ^ key l
Info ^ 1 ^ key i
Seek Info ^ 1 ^ key o
Close Menu ^ 0 ^ quit
")" && WINNAME=Mpv
# St
@ -44,6 +72,7 @@ programchoicesinit() {
Zoom - ^ 1 ^ key Ctrl+Shift+Next
Scroll ↑ ^ 1 ^ key Shift+Prior
Scroll ↓ ^ 1 ^ key Shift+Next
Invert ^ 1 ^ key Ctrl+Shift+x
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
Close Menu ^ 0 ^ quit
")" && WINNAME=st

@ -0,0 +1,3 @@
#!/usr/bin/env sh
media-ctl -d /dev/media1 --set-v4l2 '"ov5640 3-004c":0[fmt:UYVY8_2X8/1280x720]'
mpv --video-rotate=90 av://v4l2:/dev/video1

@ -1,33 +0,0 @@
#!/usr/bin/env sh
power_1() {
pgrep -f sxmo_appmenu.sh || sxmo_keyboard.sh
}
power_2() {
st
}
power_3() {
surf
}
voldown_1() {
pgrep -f sxmo_appmenu.sh && xdotool key Control+n || xdotool key Alt+Ctrl+period
}
voldown_2() {
xdotool key Alt+Shift+c
}
voldown_3() {
xdotool key Alt+Return
}
volup_1() {
pgrep -f sxmo_appmenu.sh && xdotool key Control+p || sxmo_appmenu.sh
}
volup_2() {
echo nop
}
volup_3() {
echo nop
}
$@

@ -0,0 +1,6 @@
#!/usr/bin/env sh
OLDB=$(cat /tmp/oldscreenb || echo 10)
DIMB=2
CURB=$(cat /sys/devices/platform/backlight/backlight/backlight/brightness)
[[ $CURB == $DIMB ]] && sxmo_setpinebacklight $OLDB || sxmo_setpinebacklight $DIMB

@ -1,6 +1,6 @@
#!/usr/bin/env sh
sxmo_keyboard.sh on &
pidof svkbd-sxmo || svkbd-sxmo &
OUTPUT="$(cat | dmenu -t $@)"
sxmo_keyboard.sh off
pkill svkbd-sxmo
echo "$OUTPUT"

@ -1,30 +0,0 @@
#!/usr/bin/env sh
P=/tmp/KEYTOG
keyoff() {
kill -9 $(cat $P)
pgrep -f sxmo_keyboard.sh | grep -Ev "^${$}$" | xargs kill -9
pkill -9 svkbd-en
pkill -9 svkbd-symbols
rm $P
}
keyon() {
echo $$ >> $P
while :
do
svkbd-en -d
svkbd-symbols -d
done
}
if [ "$1" == "on" ]; then
[ -f $P ] && keyoff
keyon
elif [ "$1" == "off" ]; then
[ -f $P ] && keyoff
else
# Default toggle
[ -f $P ] && keyoff || keyon
fi

@ -1,18 +0,0 @@
#!/usr/bin/env sh
TOUCHSCREENID=$(
xinput |
grep -i touchscreen |
grep pointer |
grep -oE 'id=[0-9]+' |
cut -d= -f2
)
xinput disable $TOUCHSCREENID
sxmo_setpineled blue 1
OLDB="$(cat /sys/class/backlight/backlight/brightness)"
sxmo_setpinebacklight 0
echo "Dragons?" | dmenu
sxmo_setpinebacklight $OLDB
sxmo_setpineled blue 0
xinput enable $TOUCHSCREENID

@ -1,16 +1,23 @@
#!/usr/bin/env sh
sxmo_keyboard.sh on &
INPUT="$(cat)"
cat |\
grep -Eo '\\S+' |\
tr -d '[:blank:]' |\
sort |\
uniq |\
dmenu -p Type -l 10 -i -c -fn Terminus-20
pidof svkbd-sxmo || svkbd-sxmo &
sxmo_keyboard.sh off
RESULT="$(
echo "$(
echo "Close Menu" &&
echo "$INPUT" |\
grep -Eo '\S+' |\
tr -d '[:blank:]' |\
sort |\
uniq
)" | dmenu -p Type -l 10 -i -c -fn Terminus-20
)"
pkill svkbd-sxmo
if [[ "$RESULT" = "Close Menu" ]]; then
exit 0
else
xargs -I CC xdotool type "$RESULT"
xdotool type "$RESULT"
fi

@ -0,0 +1,53 @@
#!/usr/bin/env sh
SFEEDCONF=/usr/share/sxmo/sxmo_sfeedrc
tflt() {
# Date with feature like "1 day ago" etc main reason
# coreutils is a dep...
TIME=$(eval date -d \""$TIMESPAN"\" +%s)
cat | gawk "\$1 > $TIME"
}
prep_temp_folder_with_items() {
mkdir -p $FOLDER
rm -rf $FOLDER/*
cd ~/.sfeed/feeds/
for f in $(ls)
do
cat $f | tflt $@ > $FOLDER/$f
[ -s $FOLDER/$f ] || rm $FOLDER/$f
done
}
list_items() {
cd $FOLDER
gawk -F'\t' '{print $1 " " FILENAME " | " $2 ": " $3}' * |\
grep -E '^[0-9]{5}' |\
sort -nk1 |\
sort -r |\
gawk -F' ' '{printf strftime("%y/%m/%d %H:%M",$1); $1=""; print $0}'
}
# Update Sfeed
st -e sh -c "echo Syncing Feeds && sfeed_update $SFEEDCONF"
# Dmenu prompt for timespan
TIMESPAN=$(
echo "1 hour ago
3 hours ago
12 hours ago
1 day ago
2 day ago
1970-01-01" | dmenu -p "RSS Timespan" -c -l 10 -fn Terminus-20
)
# Make folder like /tmp/sfeed_1_day_ago
FOLDER="/tmp/sfeed_$(echo "$TIMESPAN" | sed 's/ /_/g')"
prep_temp_folder_with_items
# Show list of items
PICKED=$(echo "$(list_items)" | dmenu -p "RSS" -c -l 20 -fn Terminus-15)
# Handle picked item
URL="$(echo "$PICKED" | gawk -F " " '{print $NF}')"
sxmo_urlhandler.sh "$URL"

@ -73,4 +73,9 @@ function link_select() {
link_normalize $(xprop -id $SURF_WINDOW _SURF_URI | cut -d '"' -f 2)
}
link_select
xset r off
pidof svkbd-sxmo || svkbd-sxmo &
VAL="$(link_select)"
pkill svkbd-sxmo
xset r on
echo "$VAL"

@ -1,5 +1,5 @@
#!/usr/bin/env sh
sxmo_keyboard.sh on &
pidof svkbd-sxmo || svkbd-sxmo &
TIMEINPUT=$(
echo "1h
10m
@ -15,7 +15,7 @@ echo "1h
30s
Close Menu" | dmenu -p Timer -c -fn "Terminus-30" -l 20
)
sxmo_keyboard.sh off &
pkill svkbd-sxmo
[ "Close Menu" = $TIMEINPUT ] && exit 0
st -f Monospace-50 -e sxmo_timer.sh $TIMEINPUT

@ -1,23 +1,26 @@
#!/usr/bin/env sh
# URL test passed from $1
URL=${1:-$URL}
# Surf
WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
SURFURL=`xprop -id $WINDOW | grep URI | awk '{print $3}' | sed 's/\"//g'`
if [[ ! -z "$SURFURL" ]]
if [[ ! -z "$1" ]]
then
URL="$SURFURL"
fi
# E.g. passed liked: sxmo_urlhandler.sh http://foo.com
URL=$1
else
# Surf
WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
SURFURL=`xprop -id $WINDOW | grep URI | awk '{print $3}' | sed 's/\"//g'`
if [[ ! -z "$SURFURL" ]]
then
URL="$SURFURL"
fi
# Is normal browser? (FF or Netsurf) - use Ctrl-L Ctrl-C to copy URL
ISNORMBROWS=`xprop -id $(xdotool getactivewindow) | grep -E 'WM_CLASS.*(Netsurf|Firefox)'`
if [[ ! -z "$ISNORMBROWS" ]]
then
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2
URL="$(xclip -o)"
# Is normal browser? (FF or Netsurf) - use Ctrl-L Ctrl-C to copy URL
ISNORMBROWS=`xprop -id $(xdotool getactivewindow) | grep -E 'WM_CLASS.*(Netsurf|Firefox)'`
if [[ ! -z "$ISNORMBROWS" ]]
then
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2
URL="$(xclip -o)"
fi
fi
COMMAND=$(

@ -10,3 +10,10 @@ decvol() {
echo $1 | grep up && echo 1 > /tmp/sxmo_bar && incvol
echo $1 | grep down && echo 1 > /tmp/sxmo_bar && decvol
sxmo_notify.sh 200 "Volume $(
amixer sget Headphone |
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
)"

@ -0,0 +1,23 @@
#!/usr/bin/env sh
pidof svkbd-sxmo || svkbd-sxmo &
ZIP=$(
echo -e "
10025 - NYC
60007 - Chicago
94016 - San Francisco
97035 - Portland, OR
" |
awk 'NF' |
awk '{$1=$1};1' |
dmenu -fn Terminus-20 -i -c -l 10 -p "US Zipcode" |
awk -F " " '{print $1}'
)
pkill svkbd-sxmo
LATLON=$(cat /usr/share/sxmo/zipcodes_for_weather.csv | grep "^$ZIP")
LAT=$(echo $LATLON | cut -d, -f2 | tr -d ' ')
LON=$(echo $LATLON | cut -d, -f3 | tr -d ' ')
URL="https://forecast.weather.gov/MapClick.php?lat=${LAT}&lon=${LON}&unit=0&lg=english&FcstType=text&TextType=1"
st -f Monospace-20 -e w3m "$URL"

@ -7,6 +7,7 @@ xsetroot -mod 3 2 -fg '#000000' -bg '#888888'
conky -c /usr/share/sxmo/conky.conf -d
sxmo_statusbar.sh &
xset s off -dpms
xset r off
alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore
exec dbus-run-session dwm 2> ~/.dwm.log

@ -0,0 +1,23 @@
#!/usr/bin/env sh
pidof svkbd-sxmo || svkbd-sxmo &
SEARCHTERMS="$(
echo "Search term" |
dmenu -p "Yt Search" -c -l 10 -fn Terminus-20
)"
pkill svkbd-sxmo
IDIOTRESULTS="$(idiotbox-cli $SEARCHTERMS)"
RESULT="$(
echo "$IDIOTRESULTS" |
grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' |
sed -E 's/^(URL|Duration):\s+/\t/g' |
tr -d '\n' |
sed 's/===/\n/g' |
gawk -F'\t' '{ print $3 " " $1 " " $2}' |
dmenu -c -l 10 -fn Terminus-20
)"
[[ "CLOSE_MENU" == "$RESULT" ]] && exit 0
URL=$(echo "$RESULT" | awk -F " " '{print $NF}')
st -e mpv --ytdl-format='[height<420]' "$URL"
Loading…
Cancel
Save