From 17f7c9056df2a3a10d65ea1417986e35158699d8 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Mon, 19 Dec 2022 12:02:50 -0800 Subject: monitor: exec restore wallpaper after switching monitors --- dot_config/i3/scripts/executable_battery2 | 1 + dot_config/i3/scripts/executable_monitor | 125 ++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 dot_config/i3/scripts/executable_monitor (limited to 'dot_config/i3') diff --git a/dot_config/i3/scripts/executable_battery2 b/dot_config/i3/scripts/executable_battery2 index 2d55dab..d4b69db 100644 --- a/dot_config/i3/scripts/executable_battery2 +++ b/dot_config/i3/scripts/executable_battery2 @@ -70,6 +70,7 @@ else: elif state == "Full": fulltext = FA_PLUG + " " timeleft = "" + elif state == "Unknown": fulltext = FA_QUESTION + " " + FA_BATTERY + " " timeleft = "" diff --git a/dot_config/i3/scripts/executable_monitor b/dot_config/i3/scripts/executable_monitor new file mode 100644 index 0000000..9ec2f39 --- /dev/null +++ b/dot_config/i3/scripts/executable_monitor @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +# +# Use rofi to switch between different screen layouts. +# +# Note: this currently relies on associative array support in the shell. +# +# Inspired from i3pystatus wiki: +# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu +# +# Copyright 2022 Jinwei Zhao +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# modified to work with latest rofi update by joekamprad + +####################################################################### +# BEGIN CONFIG # +####################################################################### + +# Colors: FG (foreground), BG (background), HL (highlighted) +FG_COLOR="#bbbbbb" +BG_COLOR="#111111" +HLFG_COLOR="#111111" +HLBG_COLOR="#bbbbbb" +BORDER_COLOR="#222222" + +# Options not related to colors (most rofi options do not work anymore) +ROFI_OPTIONS=(-theme ~/.config/rofi/monitor.rasi) + +####################################################################### +# END CONFIG # +####################################################################### + +# Preferred launcher if both are available +preferred_launcher="rofi" + +# Check whether the user-defined launcher is valid +launcher_list=(rofi) +function check_launcher() { + if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then + echo "Supported launchers: ${launcher_list[*]}" + exit 1 + else + # Get array with unique elements and preferred launcher first + # Note: uniq expects a sorted list, so we cannot use it + i=1 + launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ + | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) + fi +} + +# Parse CLI arguments +while getopts "hcp:" option; do + case "${option}" in + p) preferred_launcher="${OPTARG}" + check_launcher "${preferred_launcher}" + ;; + *) exit 1 + ;; + esac +done + +# Check whether a command exists +function command_exists() { + command -v "$1" &> /dev/null 2>&1 +} + +# menu defined as an associative array +typeset -A menu + +menu=( + [Home]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x1080 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --mode 1920x1080 --pos 0x0 --rotate normal --output DP-4 --off && nitrogen --restore" + [Lab]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x1200 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --mode 1920x1200 --pos 0x0 --rotate normal && nitrogen --restore" + [Builtin]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x0 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --off && nitrogen --restore" +) + +menu_nrows=${#menu[@]} + +launcher_exe="" +launcher_options="" +rofi_colors="" + +function prepare_launcher() { + if [[ "$1" == "rofi" ]]; then + rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ + -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") + launcher_exe="rofi" + launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ + "${rofi_colors}" "${ROFI_OPTIONS[@]}") + elif [[ "$1" == "zenity" ]]; then + launcher_exe="zenity" + launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ + "${ZENITY_OPTIONS[@]}") + fi +} + +for l in "${launcher_list[@]}"; do + if command_exists "${l}" ; then + prepare_launcher "${l}" + break + fi +done + +# No launcher available +if [[ -z "${launcher_exe}" ]]; then + exit 1 +fi + +launcher=(${launcher_exe} "${launcher_options[@]}") +selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" + +if [[ $? -eq 0 && ! -z ${selection} ]]; then + i3-msg -q "exec --no-startup-id ${menu[${selection}]}" +fi -- cgit v1.2.3