From 3bde1292fcb4d49254a4f37017440a4ada55cefc Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 2 Jan 2023 13:13:07 -0500 Subject: [PATCH] Move i3 modi scripts into this repo --- .config/rofi/config.rasi | 2 +- .config/rofi/i3_monitor_layout.sh | 101 +++++++++++++++++++++++++++ .config/rofi/i3_move_to_workspace.py | 12 ++++ .config/rofi/i3_switch_workspace.py | 12 ++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100755 .config/rofi/i3_monitor_layout.sh create mode 100755 .config/rofi/i3_move_to_workspace.py create mode 100755 .config/rofi/i3_switch_workspace.py diff --git a/.config/rofi/config.rasi b/.config/rofi/config.rasi index 29edcb7..2acecab 100644 --- a/.config/rofi/config.rasi +++ b/.config/rofi/config.rasi @@ -1,5 +1,5 @@ configuration { - modi: "drun,run,sworkspace:~/.config/i3/switch_workspace.py,mworkspace:~/.config/i3/move_to_workspace.py,window,monitor:~/.config/i3/monitor_layout.sh"; + modi: "drun,run,sworkspace:~/.config/rofi/i3_switch_workspace.py,mworkspace:~/.config/rofi/i3_move_to_workspace.py,window,monitor:~/.config/rofi/i3_monitor_layout.sh"; show-icons: true; sidebar-mode: true; } diff --git a/.config/rofi/i3_monitor_layout.sh b/.config/rofi/i3_monitor_layout.sh new file mode 100755 index 0000000..7b7da0e --- /dev/null +++ b/.config/rofi/i3_monitor_layout.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +XRANDR=$(which xrandr) + +MONITORS=( $( ${XRANDR} | awk '( $2 == "connected" ){ print $1 }' ) ) + + +NUM_MONITORS=${#MONITORS[@]} + +TITLES=() +COMMANDS=() + + +function gen_xrandr_only() +{ + selected=$1 + + cmd="xrandr --output ${MONITORS[$selected]} --auto " + + for entry in $(seq 0 $((${NUM_MONITORS}-1))) + do + if [ $selected != $entry ] + then + cmd="$cmd --output ${MONITORS[$entry]} --off" + fi + done + + echo $cmd +} + + + +declare -i index=0 +TILES[$index]="Cancel" +COMMANDS[$index]="true" +index+=1 + + +for entry in $(seq 0 $((${NUM_MONITORS}-1))) +do + TILES[$index]="Only ${MONITORS[$entry]}" + COMMANDS[$index]=$(gen_xrandr_only $entry) + index+=1 +done + +## +# Dual screen options +## +for entry_a in $(seq 0 $((${NUM_MONITORS}-1))) +do + for entry_b in $(seq 0 $((${NUM_MONITORS}-1))) + do + if [ $entry_a != $entry_b ] + then + TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" + COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ + --output ${MONITORS[$entry_b]} --auto --left-of ${MONITORS[$entry_a]}" + + index+=1 + fi + done +done + + +## +# Clone monitors +## +for entry_a in $(seq 0 $((${NUM_MONITORS}-1))) +do + for entry_b in $(seq 0 $((${NUM_MONITORS}-1))) + do + if [ $entry_a != $entry_b ] + then + TILES[$index]="Clone Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" + COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ + --output ${MONITORS[$entry_b]} --auto --same-as ${MONITORS[$entry_a]}" + + index+=1 + fi + done +done + + +## +# Generate entries, where first is key. +## +function gen_entries() +{ + for a in $(seq 0 $(( ${#TILES[@]} -1 ))) + do + echo $a ${TILES[a]} + done +} + +if [ -z "$@" ] +then + # Call menu + gen_entries +else + $( ${COMMANDS[$(awk '{print $1}' <<< "$@")]} ) +fi diff --git a/.config/rofi/i3_move_to_workspace.py b/.config/rofi/i3_move_to_workspace.py new file mode 100755 index 0000000..e455ec6 --- /dev/null +++ b/.config/rofi/i3_move_to_workspace.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +import i3ipc + +i3 = i3ipc.Connection() + +if len(sys.argv) == 1: + print("\n".join([ws.name for ws in i3.get_workspaces()])) +else: + i3.command("move to workspace {sys.argv[1]}") diff --git a/.config/rofi/i3_switch_workspace.py b/.config/rofi/i3_switch_workspace.py new file mode 100755 index 0000000..ad06a17 --- /dev/null +++ b/.config/rofi/i3_switch_workspace.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +import i3ipc + +i3 = i3ipc.Connection() + +if len(sys.argv) == 1: + print("\n".join([ws.name for ws in i3.get_workspaces()])) +else: + i3.command("workspace {sys.argv[1]}")