master
Daniel Napora 2021-05-21 23:06:41 +02:00
parent 543fe65065
commit 90f4e264e8
4 changed files with 50 additions and 36 deletions

View File

@ -4,7 +4,9 @@
# (C) Daniel Napora <napcok@gmail.com>, 2021
# https://maboxlinux.org
#
CONFIG_DIR="$HOME/.config/deskgrid"
CONFIG_DIR=~/.config/deskgrid
CONFIG_FILE="$CONFIG_DIR/deskgrid.conf"
mkdir -p $CONFIG_DIR
if [ ! -f $CONFIG_FILE ]; then
@ -18,7 +20,7 @@ grid_y=12
#
titlebar_height=18
#Notifications true or false
enable_notifications=true
notifications=true
# Outer gap (disable if you use WM margins)
show_outer_gap=true
# Only for clicksnap action
@ -58,8 +60,8 @@ 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."
if [ $notifications = true ]; then
notify-send.sh -t 15000 --replace-file=/tmp/deskgrid --icon=mbcc "Welcome to DeskGrid (experimental)" "\nDraw rectangle 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
@ -91,7 +93,7 @@ xdotool windowmove $WINDOW $POSITION
xdotool windowmap $WINDOW
if [ $enable_notifications = true ]; then
if [ $notifications = true ]; then
notify-send.sh -t 15000 --replace-file=/tmp/deskgrid --icon=mbcc "Info" "You can disable those notifications or edit config file using buttons below.\n\n" -o "Disable notifications:mb-setvar enable_notifications=false ~/.config/deskgrid/deskgrid.conf" -o "Edit DeskGrid config file:geany ~/.config/deskgrid/deskgrid.conf"
#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\nPosition: <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

View File

@ -4,7 +4,7 @@
#: With windows positions and state (decorated or not)
#: Usage:
#: -s|save - save session from current desktop
#: -r|restore sesionfile desktop_nr - restore session from sessionfile on desktop
#: -r|restore sesionfile desktop_ID - restore session from sessionfile on desktop
#:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -24,6 +24,8 @@ mkdir -p $SESSIONDIR
savesession() {
curdesk=$(wmctrl -d | grep "*" | awk '{print $1}')
if [ $(wmctrl -l -p -G | awk -v c=$curdesk '$2 == c {print $2}' | wc -l) == "0" ];then notify-send -i dialog-warning "Nothing to save" "\nStart some programs and try again.\n";exit 1;fi
filename=$(yad --center --title "Save session as:" --entry --entry-label="Session name" --entry-text="Session name") || exit 1
windows=()
wmctrl -l -p -G | {
@ -44,27 +46,31 @@ savesession() {
fi
fi
done
printf "%s\n" "${windows[@]}" > "$SESSIONDIR/${filename// /_}.desk"
# Serch replace
if command -v sd 1>/dev/null; then
sd -s "/usr/lib/chromium/chromium" "chromium --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "/usr/lib/firefox/firefox" "firefox --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "/usr/bin/python3 /usr/bin/terminator" "terminator" "$SESSIONDIR/${filename// /_}.desk"
sd -s "geany" "geany -i" "$SESSIONDIR/${filename// /_}.desk"
sd -s "cherrytree" "cherrytree --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "pcmanfm -d" "pcmanfm -n" "$SESSIONDIR/${filename// /_}.desk"
sd -s "Thunar --daemon" "thunar" "$SESSIONDIR/${filename// /_}.desk"
if [ ${#windows[@]} -eq 0 ]; then
notify-send -i dialog-warning "Nothing to save" "Opps, looks like there are no windows to save on current desktop.\n Run some programs and try again ;)"
else
sed -i '/usr/lib/chromium/chromium,chromium --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i '/usr/lib/firefox/firefox,firefox --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i '/usr/bin/python3 /usr/bin/terminator,terminator,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'geany,geany -i,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'cherrytree,cherrytree --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'pcmanfm -d,pcmanfm -n,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'Thunar --daemon,thunar,' "$SESSIONDIR/${filename// /_}.desk"
fi
if command -v geany 1>/dev/null; then
geany "$SESSIONDIR/${filename// /_}.desk"
printf "%s\n" "${windows[@]}" > "$SESSIONDIR/${filename// /_}.desk"
# Serch replace
if command -v sd 1>/dev/null; then
sd -s "/usr/lib/chromium/chromium" "chromium --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "/usr/lib/firefox/firefox" "firefox --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "/usr/bin/python3 /usr/bin/terminator" "terminator" "$SESSIONDIR/${filename// /_}.desk"
sd -s "geany" "geany -i" "$SESSIONDIR/${filename// /_}.desk"
sd -s "cherrytree" "cherrytree --new-window" "$SESSIONDIR/${filename// /_}.desk"
sd -s "pcmanfm -d" "pcmanfm -n" "$SESSIONDIR/${filename// /_}.desk"
sd -s "Thunar --daemon" "thunar" "$SESSIONDIR/${filename// /_}.desk"
else
sed -i '/usr/lib/chromium/chromium,chromium --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i '/usr/lib/firefox/firefox,firefox --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i '/usr/bin/python3 /usr/bin/terminator,terminator,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'geany,geany -i,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'cherrytree,cherrytree --new-window,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'pcmanfm -d,pcmanfm -n,' "$SESSIONDIR/${filename// /_}.desk"
sed -i 'Thunar --daemon,thunar,' "$SESSIONDIR/${filename// /_}.desk"
fi
if command -v geany 1>/dev/null; then
geany "$SESSIONDIR/${filename// /_}.desk"
fi
fi
}
}
@ -100,7 +106,8 @@ usage() {
case "$1" in
-s|save) savesession "$2";;
-r|restore) restoresession "$2" "$3";;
-r|restore) restoresession "$2" "$3";;
-o|overwrite) overwrite "$2" ;;
-l|list) listsessions ;;
-h|--help) usage;;
*) usage;;

View File

@ -24,8 +24,8 @@ rectangles=""
rectangles+="rectangle $((tile*TILE_WIDTH)),$((row*TILE_HEIGHT)) $((tile*TILE_WIDTH+TILE_WIDTH)),$((row*TILE_HEIGHT+TILE_HEIGHT)) ";
done
done
name="text 4,66 DeskGrid"
text="text 16,96 \"Hello I'm here to help you get familiar with DeskGrid ;)\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: middle click on taskbar or click here, then hit q key\""
name="text 24,96 DeskGrid"
text="text 30,120 \"Hello I'm here to help you get familiar with DeskGrid ;)\nGrid: $GRID_X columns, $GRID_Y rows\nSingle tile size: $TILE_WIDTH x $TILE_HEIGHT\n\nUse mousewheel on taskbar to show/hide me\nTo close: middle click on taskbar or click here, then hit q key\""
magick -size $AVAILSIZE xc:LavenderBlush3 -stroke LavenderBlush2 -strokewidth 1 \
-fill LavenderBlush3 \
-draw "$rectangles" \

View File

@ -34,7 +34,7 @@ grid_y=12
#
titlebar_height=18
#Notifications true or false
enable_notifications=true
notifications=true
# Outer gap (disable if you use WM margins)
show_outer_gap=true
# Only for clicksnap action
@ -107,7 +107,7 @@ clicksnap() {
Mouse_y="$Y"
HEX_ID=$(printf '0x%x\n' $WINDOW)
wmctrl -i -r $HEX_ID -b remove,maximized_vert,maximized_horz
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
@ -121,13 +121,18 @@ clicksnap() {
Win_y="$Y"
Win_width="$WIDTH"
Win_height="$HEIGHT"
Rel_x="$((Mouse_x-Win_x))"
Rel_y="$((Mouse_y-Win_y))"
pos_x="$(((Mouse_x-Win_x)/(Win_width/3)))"
if [[ $Mouse_x -gt $Win_x && $Mouse_x -lt $((Win_x+WIDTH)) && $Mouse_y -gt $Win_y && $Mouse_y -lt $((Win_y+HEIGHT)) ]];then
pos_x="$(((Mouse_x-Win_x)/(Win_width/3)))"
pos_y="$(((Mouse_y-Win_y)/(Win_height/3)))"
POS_CODE="$pos_x$pos_y"
else
pos_x="$((Mouse_x*3/AVAIL_X))"
pos_y="$((Mouse_y*3/AVAIL_Y))"
POS_CODE="$pos_x$pos_y"
fi
#xdotool windowminimize $WINDOW
_movewin
}