imported: DeskGrid, drawgrid and chwp

master
Daniel Napora 2021-05-14 19:35:19 +02:00
parent 09cd079155
commit 6843f14174
3 changed files with 191 additions and 0 deletions

50
bin/chwp 100755
View File

@ -0,0 +1,50 @@
#!/bin/bash
CONFIG_DIR="$HOME/.config/chwp"
CONFIG_FILE="$CONFIG_DIR/chwp.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"
# Make config directory if not exist
mkdir -p $CONFIG_DIR
# If config file not exist create one with defaults
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=10
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
EOF
fi
# read config variables from file
source <(grep = $CONFIG_FILE)
# decide which setter and command use to set wallpaper
case "$setter" in
nitrogen) command="nitrogen --set-zoom-fill";;
feh) command="feh --bg-fill" ;;
*) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;;
esac
while true
do
# If list does not exist or is empty
if [[ ! -f $WALLPAPERS_LIST || $(wc -l <$WALLPAPERS_LIST) -lt 1 ]]; then
# Prepare list with wallpapers (only PNG and JPG)
ls -1 "$wallpaper_dir"/*{.jpg,.png} > "$WALLPAPERS_LIST"
fi
# if wallpapers list have more than 0 lines
while [ $(wc -l <$WALLPAPERS_LIST) -gt 0 ]
do
# get random line
line=$(shuf -n 1 $WALLPAPERS_LIST)
#delete it from list
grep -v "$line" "$WALLPAPERS_LIST" > "$CONFIG_DIR/tmpfile"; mv "$CONFIG_DIR/tmpfile" "$WALLPAPERS_LIST"
#run command to set wallpaper
${command} ${line}
sleep ${interval}
done
done

90
bin/deskgrid 100755
View File

@ -0,0 +1,90 @@
#!/bin/bash
### deskgrid - click on the window and select area to place it on the grid
# Works with active and inactive windows
# (C) Daniel Napora <napcok@gmail.com>, 2021
# https://maboxlinux.org
#
CONFIG_DIR="$HOME/.config/deskgrid"
CONFIG_FILE="$CONFIG_DIR/deskgrid.conf"
mkdir -p $CONFIG_DIR
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
# Gap between windows in pixels
gap=16
# Grid columns
grid_x=16
# Grid rows
grid_y=12
#
titlebar_height=18
#Notifications true or false
enable_notifications=true
EOF
fi
source <(grep = $CONFIG_FILE)
GAP=${gap:-16}
GRID_X=${grid_x:-12}
GRID_Y=${grid_y:-6}
TITLEBAR_HEIGHT=${titlebar_height:-18}
eval $(xdotool getmouselocation --shell)
# we have window id now as $WINDOW
HEX_ID=$(printf '0x%x\n' $WINDOW)
CHILD_ID=$(xwininfo -id $HEX_ID -children|grep "\"" | awk '{print $1}')
if xwininfo -id $CHILD_ID -wm |grep Dock ; then exit 0 ;fi # Ignore Dock eg. tint2
if xwininfo -id $CHILD_ID -wm |grep Undecorated ; then # Undecorated
T="0"
else # Decorated
T="$TITLEBAR_HEIGHT"
fi
xdotool windowminimize --sync $WINDOW
# Screen dimensions, margins and available size
SCREENSIZE=$(wmctrl -d |grep "*" | awk -F' ' '{print $4}')
MARGINS=$(wmctrl -d |grep "*" | awk -F' ' '{print $8}')
AVAILSIZE=$(wmctrl -d |grep "*" | awk -F' ' '{print $9}')
SCREEN_X="${SCREENSIZE%x*}"
SCREEN_Y="${SCREENSIZE#*x}"
AVAIL_X="${AVAILSIZE%x*}"
AVAIL_Y="${AVAILSIZE#*x}"
MARGIN_X="${MARGINS%,*}"
MARGIN_Y="${MARGINS#*,}"
#Show notify
if [ $enable_notifications = true ]; then
notify-send.sh -t 15000 --replace-file=/tmp/deskgrid --icon=mbcc "Welcome to DeskGrid (experimental)" "\nDraw selection by mouse to set new window positon and size.\nWhile drawing you may hold Space key to move selection.\nNew window will be bigger than selection."
fi
# Take selection
slop=$(slop --highlight -b 4 --tolerance=0 --color=0.3,0.4,0.6,0.4 -f "%x %y %w %h") || exit 1
read -r X Y W H < <(echo $slop)
start_x="$(((X-MARGIN_X)/(AVAIL_X/GRID_X)))"
start_y="$(((Y-MARGIN_Y)/(AVAIL_Y/GRID_Y)))"
end_x="$(((X-MARGIN_X+W)/(AVAIL_X/GRID_X)))"
end_y="$(((Y-MARGIN_Y+H)/(AVAIL_Y/GRID_Y)))"
### SIZE and POS calculation
if [[ $start_x = "0" ]]; then GAP_X="$GAP" ; else GAP_X=$((GAP/2)) ; fi
if [[ $start_y = "0" ]]; then GAP_Y="$GAP" ; else GAP_Y=$((GAP/2)) ; fi
if [[ $end_x = $((GRID_X-1)) ]]; then GAP_X_END="$GAP" ; else GAP_X_END=$((GAP/2)) ; fi
if [[ $end_y = $((GRID_Y-1)) ]]; then GAP_Y_END="$GAP" ; else GAP_Y_END=$((GAP/2)) ; fi
SIZE="$(((end_x-start_x+1)*(AVAIL_X/GRID_X)-GAP_X-GAP_X_END)) $(((end_y-start_y+1)*(AVAIL_Y/GRID_Y)-GAP_Y-GAP_Y_END-T))"
POSITION="$((start_x*AVAIL_X/GRID_X+GAP_X+MARGIN_X)) $((start_y*AVAIL_Y/GRID_Y+GAP_Y+MARGIN_Y))"
xdotool windowsize $WINDOW $SIZE
xdotool windowmove $WINDOW $POSITION
xdotool windowmap $WINDOW
if [ $enable_notifications = true ]; then
notify-send.sh -t 15000 --replace-file=/tmp/deskgrid --icon=mbcc "Success notification" "You can disable those notifications by editing config file. Button below.\nScreensize: $SCREENSIZE\nMargins: $MARGINS\nAvailable size: $AVAILSIZE\nGrid: $((AVAIL_X/GRID_X)) x $((AVAIL_Y/GRID_Y)) Selection: $slop\n\
Position: <b>$POSITION</b>\n($start_x*$AVAIL_X/$GRID_X+$GAP_X+$MARGIN_X)\n($start_y*$AVAIL_Y/$GRID_Y+$GAP_Y+$MARGIN_Y) \nSize: $SIZE" -o "Disable notifications:mb-setvar enable_notifications=false ~/.config/deskgrid/deskgrid.conf" -o "Edit config file:geany ~/.config/deskgrid/deskgrid.conf"
fi

51
bin/drawgrid 100755
View File

@ -0,0 +1,51 @@
#!/bin/bash
CONFIG_DIR="$HOME/.config/deskgrid"
CONFIG_FILE="$CONFIG_DIR/deskgrid.conf"
source <(grep = $CONFIG_FILE)
GAP=${gap:-16}
GRID_X=${grid_x:-12}
GRID_Y=${grid_y:-6}
AVAILSIZE=$(wmctrl -d |grep "*"|awk -F' ' '{print $9}')
AVAIL_X="${AVAILSIZE%x*}"
AVAIL_Y="${AVAILSIZE#*x}"
# DRAWAREA = AVAILSIZE - OUTER_GAP
if [[ "$show_outer_gap" == "true" ]]; then
DRAW_X="$((AVAIL_X-GAP))" DRAW_Y="$((AVAIL_Y-GAP))"
else
DRAW_X="$AVAIL_X" DRAW_Y="$AVAIL_Y"
GAP_COMP="0"
fi
TILE_WIDTH="$((DRAW_X/GRID_X))"
TILE_HEIGHT="$((DRAW_Y/GRID_Y))"
rectangles=""
row="0"
for row in $(seq 0 $((GRID_Y-1)));
do
for tile in $(seq 0 $((GRID_X-1)));
do
rectangles+="rectangle $((tile*TILE_WIDTH)),$((row*TILE_HEIGHT)) $((tile*TILE_WIDTH+TILE_WIDTH)),$((row*TILE_HEIGHT+TILE_HEIGHT)) ";
done
done
text="text $((4)),$((26)) \"Hello I'm here to help you get familiar with this crazy tool ;)\nGrid: $GRID_X rows, $GRID_Y columns\nSingle tile size: $TILE_WIDTH x $TILE_HEIGHT\n\nUse mousewheel on taskbar to show/hide me\nTo close me: middle click on taskbar or click here, then hit q key\""
magick -size $AVAILSIZE xc:LavenderBlush3 -stroke LavenderBlush2 -strokewidth 1 \
-fill LavenderBlush3 \
-draw "$rectangles" \
-style Normal +stroke -pointsize 14 -fill gray16 -draw "$text" \
/tmp/grid.png
feh -N -x --title "DrawGrid helper" /tmp/grid.png > /dev/null 2>&1 &
sleep .2
dupa=$(wmctrl -l -p |grep "DrawGrid helper")
#echo "$dupa"
read -r A B C D< <(echo $dupa)
#echo "$A $C"
wmctrl -i -r "$A" -b add,below
#Kolory dawne: fill LavenderBlush3 stroke LavenderBlush1