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 ++++++++++++++++++++++++++++++ dot_gitconfig | 2 + dot_zshrc | 6 +- 4 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 dot_config/i3/scripts/executable_monitor 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 diff --git a/dot_gitconfig b/dot_gitconfig index 0a3fad2..eaa62bf 100644 --- a/dot_gitconfig +++ b/dot_gitconfig @@ -4,3 +4,5 @@ signingkey = DD3B254076A2E156! [init] defaultBranch = master +[core] + autocrlf = input diff --git a/dot_zshrc b/dot_zshrc index 2bb3f10..dd47aaa 100644 --- a/dot_zshrc +++ b/dot_zshrc @@ -125,6 +125,9 @@ function addPATHBefore { addPATH $HOME/.local/bin addPATH $GOPATH/bin +source $HOME/.zshrc-local + +alias tf="terraform" alias emacs="emacs -nw" alias open="xdg-open" alias sl="ls" @@ -132,8 +135,5 @@ alias ssh="ssh -o ServerAliveInterval=60" alias dl="yt-dlp" alias m="make -j`nproc --all`" alias t="xfce4-terminal" -alias nas="sudo mount -t cifs -o user=clarkzjw //192.168.1.201/pool1 /mnt/truenas" alias chez="/usr/bin/chezmoi" alias xc="xclip -selection clip" -alias ws="/home/clarkzjw/Documents/application/wondershaper/wondershaper" -alias log="/home/clarkzjw/Documents/sync/UVic/PanLab/Code/picoquic/picoquic/picolog_t -f qlog" -- cgit v1.2.3