#! /bin/bash

# This script installs commands for tiling to the end of the keys file
# it was created by user PPC and released in January 2020 under GPLv3 
# "Control 9" was added by MX Linux Devs September 2020

TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN="mxfb-tiles"

MESSAGE1=$"This script will back up your current keys file, then install commands for tiling to the end of the file</b>"
HINT1=$"Control 1-4 for 1/2 screen tiling"
HINT2=$"Control 5-8 for 1/4 screen tiling"
HINT3=$"Control 9 for 1/3 tiling"
HINT4=$"Control 0 to maximize"
TITLE=$"OK to proceed?"

##begin message box
yad --text="


<b>$MESSAGE1\n
<b>--$HINT1
--$HINT2
--$HINT3
--$HINT4</b>" --title=$"$TITLE" --window-icon=/usr/share/icons/mxflux.png --geometry=400x40 --text-align=center 


##end message box

if [ ! "$?" = "0" ]; then
    exit 0
fi

cp ~/.fluxbox/keys ~/.fluxbox/keys_BAK

echo "## BASIC WINDOW TILING ##
# Make active window 1/2 of the screen 
Control 1 :MacroCmd {ResizeTo 50% 100%} {MoveTo 00 00 Left} 
Control 2 :MacroCmd {ResizeTo 50% 100%} {MoveTo 00 00 Right} 
Control 3 :MacroCmd {ResizeTo 100% 50%} {MoveTo 00 00 Up} 
Control 4 :MacroCmd {ResizeTo 100% 50%} {MoveTo 00 00 Bottom} 
# Make active window 1/4 of the screen on the upper left 
Control 5 :MacroCmd {ResizeTo 50% 50%} {MoveTo 00 00 Up} 
Control 6 :MacroCmd {ResizeTo 50% 50%} {MoveTo 00 00 TopRight} 
Control 7 :MacroCmd {ResizeTo 50% 50%} {MoveTo 00 00 BottomLeft} 
Control 8 :MacroCmd {ResizeTo 50% 50%} {MoveTo 00 00 BottomRight} 
# Make active window 1/3 of the screen on the right
Control 9 :MacroCmd {ResizeTo 33% 100%} {MoveTo 00 00 Left}
# toggle active window: Maximized/ last size 
Control 0 :ToggleCmd {Maximize} {Restore}" >> ~/.fluxbox/keys 
fluxbox-remote restart
