diff --git a/dot_config/i3/executable_common_var.sh b/dot_config/i3/executable_common_var.sh new file mode 100644 index 0000000..e5ae079 --- /dev/null +++ b/dot_config/i3/executable_common_var.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +MONITOR_CONF=~/.screenlayout/monitor.sh +GENERATED_MONITOR_CONF=~/.screenlayout/generated_monitor.sh diff --git a/dot_config/i3/executable_configure_monitors.sh b/dot_config/i3/executable_configure_monitors.sh new file mode 100644 index 0000000..86547e9 --- /dev/null +++ b/dot_config/i3/executable_configure_monitors.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +source ~/.config/i3/common_var.sh + +function set_configuration () { + # Display message and wait press any key with -n 1 + read -n 1 -r -s -p $"Save configuration in $MONITOR_CONF.\nPress any key to continue" + + # Ask set monitor configuration + arandr + + $MONITOR_CONF # Apply configuration +} + +# set_configuration + +# SCREENS => HashMap | Key => Output name | Value => Position X +# SCREENS EX: +# SCREENS[DP-1]=1920 +# SCREENS[DP-2]=0 +declare -A SCREENS +CURRENT_SCREEN="na" +for line in $(xrandr --listmonitors); do + # Return all line with: + # OUTPUT NAME: +DP-3 + # DETAILS: 1920/510x1080/290+0+0 + if [[ $line == *"+"* ]]; then + INFO=$(echo $line | cut -d '+' -f 2) + if [[ $CURRENT_SCREEN == "na" ]]; then + CURRENT_SCREEN=$INFO + echo "SET CURRENT_SCREEN : $CURRENT_SCREEN" + else + SCREENS["$CURRENT_SCREEN"]=$INFO + echo "ADD SCREEN : $CURRENT_SCREEN -> $INFO" + CURRENT_SCREEN="na" + fi + fi +done + +# SCREENS ORDER BY POSITION +# FINAL RESULT SCREENS=(DP-2 DP-1) +ORDERED_SCREENS=($(for x in ${!SCREENS[@]}; do echo $x; done | sort -r | sed 's/\n/ /g')) + +EXPORT_SCREENS="SCREENS=(" +for screen in ${!ORDERED_SCREENS[@]}; do + EXPORT_SCREENS+="\"${ORDERED_SCREENS[$screen]}\" " +done +EXPORT_SCREENS="${EXPORT_SCREENS:0:-1})" # Remove last space + +echo "#!/bin/bash" > $GENERATED_MONITOR_CONF +echo $EXPORT_SCREENS >> $GENERATED_MONITOR_CONF diff --git a/dot_config/i3/executable_relative_workspace.sh b/dot_config/i3/executable_relative_workspace.sh new file mode 100644 index 0000000..d2a8be5 --- /dev/null +++ b/dot_config/i3/executable_relative_workspace.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Required jq to be installed with +# pacman -S jq arandr + +# Move to layout.sh exported with arandr +SCREENS=("DP-3" "DP-1" "DP-5") +SCREEN_NUMBER=${#SCREENS[@]} + +# Set command from current WM +MSG_COMMAND=i3-msg +if [[ $DESKTOP_SESSION =~ ^sway$ ]]; then + MSG_COMMAND=swaymsg +fi + +# Get current workspace output (Screen) +CURRENT_WORKSPACE=$($MSG_COMMAND -t get_workspaces \ + | jq '.[] | select(.visible == true and .focused == true) | .output' \ + | sed "s/\"\|'//g") + + +# Get screen index from screens list and current workspace +SCREEN_INDEX=-1 +for val in ${!SCREENS[@]} +do + if [[ "${SCREENS[val]}" == "$CURRENT_WORKSPACE" ]]; then + SCREEN_INDEX=$val; + break; + fi +done + +DESIRED_WORKSPACE=$(($SCREEN_INDEX * 10 + $1)) + +# To run in DRY RUN uncomment line in below +# MSG_COMMAND=echo +if [[ "$2" == "move" ]]; then + $MSG_COMMAND move container to workspace number $DESIRED_WORKSPACE +else + $MSG_COMMAND workspace number $DESIRED_WORKSPACE +fi diff --git a/run_once_prepare_arch.sh.tmpl b/run_once_prepare_arch.sh.tmpl index ad7481d..131ac98 100644 --- a/run_once_prepare_arch.sh.tmpl +++ b/run_once_prepare_arch.sh.tmpl @@ -1,7 +1,7 @@ {{ if eq .chezmoi.osRelease.idLike "arch" }} #!/bin/bash # All requirements for i3 -sudo pacman -S curl picom i3-gaps polybar dunst dmenu i3lock bluez-tools blueberry pavucontrol tmux feh dex yay xss-lock network-manager-applet playerctl alacritty git gnome-keyring --noconfirm +sudo pacman -S curl picom i3-gaps polybar dunst dmenu i3lock bluez-tools blueberry pavucontrol tmux feh dex yay xss-lock network-manager-applet playerctl alacritty git gnome-keyring jq arandr --noconfirm yay -S nerd-fonts-complete spotify spicetify-cli --noconfirm