update for dynamic workspace and polybar switching

This commit is contained in:
Tyler Starr 2022-12-10 23:04:30 -08:00
parent 3488a3b4b3
commit d6af01cec9
9 changed files with 61 additions and 25 deletions

View File

@ -3,4 +3,4 @@ readme.md
.git
provision
additional-setup.md
vars
.gen

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python3
import subprocess
import json
import pathlib
# save needed information in a dictionary
i3_dict = {}
def pri_sec_monitor():
# save output of xrandr
output = str(subprocess.check_output("xrandr", shell=True))
primary = []
secondary = []
# Get name of primary and secondary monitor
for row in output.split('\\n'):
if " connected" in row and "primary" in row:
primary.append(row.split(" ")[0])
if " connected" in row and "primary" not in row:
secondary.append(row.split(" ")[0])
# If we only have on monitor set primary and secondary
# to the one monitor
if len(primary) == 1 and len(secondary) == 0:
secondary = primary
elif len(primary) == 0 and len(secondary) == 1:
primary = secondary
elif len(primary) != 1 or len(secondary) != 1:
print("Error: i3_gen/pri_sec_monitor")
return "ERROR", "ERROR"
return primary[0], secondary[0]
# pri_sec_monitor
monitors = pri_sec_monitor()
i3_dict["disp_pri"] = monitors[0]
i3_dict["disp_sec"] = monitors[1]
# write result to json
p = pathlib.Path('{{ .chezmoi.sourceDir }}/.gen/i3.json')
p.parent.mkdir(parents=True, exist_ok=True)
with open(p, 'w') as f:
json.dump(i3_dict, f, indent=4, sort_keys=True)

3
.gitignore vendored
View File

@ -1,2 +1 @@
vars/*
!vars/.keep
.gen

View File

@ -28,5 +28,5 @@ alias n="nnn -d -e -H -r"
# Chezmoi
alias cmc="chezmoi cd"
alias cmd="chezmoi apply --verbose --dry-run"
alias cma="chezmoi apply --verbose"
alias cma="chezmoi apply"

View File

@ -1,3 +1,5 @@
{{- $i3:= include ".gen/i3.json" | mustFromJson -}}
# i3 config file (v4)
# TODO: add scratchpads (terminal, password manager, discord, task)
@ -5,19 +7,13 @@
#----- VARIABLES
#-------------------------------------------------------------------------------
set $HOME /home/tstarr
set $HOME {{ .chezmoi.homeDir }}
#set $DISP_PRI DP-4
#set $DISP_SEC HDMI-0
set $DISP_PRI {{ $i3.disp_pri }}
set $DISP_SEC {{ $i3.disp_sec }}
set $DISP_PRI HDMI-0
set $DISP_SEC DP-4
#set $DISP_PRI HDMI-0
#set $DISP_SEC HDMI-0
set $BOR_WIDTH 2
set $GAP_INNER 2
set $BOR_WIDTH 4
set $GAP_INNER 4
set $mod Mod4
@ -111,7 +107,7 @@ for_window [class="Steam"] move container to workspace "1:game"
#-------------------------------------------------------------------------------
# i3 utility commands
bindsym $mod+Ctrl+r restart
bindsym $mod+Ctrl+r exec chezmoi apply && i3-msg restart
bindsym $mod+Ctrl+q exit
bindsym $mod+Ctrl+h resize shrink width 50
bindsym $mod+Ctrl+j resize shrink height 50
@ -190,6 +186,8 @@ bindsym $mod+b exec --no-startup-id $HOME/.config/i3/scripts/scratch.sh \
#----- AUTOSTART WITH I3
#-------------------------------------------------------------------------------
exec --no-startup-id $HOME/.config/i3/scripts/xrandr.sh
exec_always --no-startup-id $HOME/.config/i3/scripts/polybar.sh
exec --no-startup-id "$HOME/.config/i3/scripts/xrandr.sh && \
chezmoi apply && \
i3-msg restart && \
$HOME/.config/i3/scripts/polybar.sh"
exec_always --no-startup-id nitrogen --restore

View File

@ -7,4 +7,4 @@ killall -q polybar
while pgrep -x polybar >/dev/null; do sleep 1; done
# Launch polybar
polybar -c ~/.config/polybar/dracula &
polybar -c {{ .chezmoi.homeDir }}/.config/polybar/dracula &

View File

@ -1,5 +1,7 @@
{{- $i3:= include ".gen/i3.json" | mustFromJson -}}
[bar/fullbar]
monitor = HDMI-0
monitor = {{ $i3.disp_sec }}
include-file = ~/.config/polybar/common
background = #bb282a36

View File

@ -1,3 +0,0 @@
#!/bin/bash
#
echo "Hello World!"

View File

@ -1 +0,0 @@
keep