From 3342374657bd712f14cd772378b23d2bca3382cb Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Thu, 13 Jun 2024 14:01:00 -0400 Subject: [PATCH] i3 improvements --- brc2 | 4 +++ ffs | 41 ++++++++++++++--------- filesystem/usr/local/bin/abrowser | 31 ++++------------- filesystem/usr/local/bin/irc | 2 +- i3-abrowser | 55 +++++++++++++++++++++++++++++++ i3-emacs | 41 +++++++++++++++++++++++ i3-konsole | 45 +++++++++++++++++++++++++ i3-pull | 1 - i3-split-maybe | 4 +-- i3-sway/common.conf | 15 +++++---- 10 files changed, 189 insertions(+), 50 deletions(-) create mode 100755 i3-abrowser create mode 100755 i3-emacs create mode 100755 i3-konsole diff --git a/brc2 b/brc2 index bb33b7d..ff0d7a8 100644 --- a/brc2 +++ b/brc2 @@ -2012,6 +2012,10 @@ apache-apply-repo() { apache-apply() { for file; do + if [[ ! -e $file ]]; then + echo '#!/bin/bash' >$file + chmod +x $file + fi if head -n1 "$file"| grep -E '^#!/' &>/dev/null; then { head -n1 "$file" diff --git a/ffs b/ffs index d6dc01f..4ffb0a0 100755 --- a/ffs +++ b/ffs @@ -41,8 +41,10 @@ Usage: ${0##*/} [OPTIONS] [sysops|tech|staff] 3 mountpoints: fsf-sysops (default, public), fsf (all staff), fsf-tech (tech team) -d debug. --f Stream full screen even high resolution. --t Stream tall half screen +-r RESOLUTION_TYPE + full: full screen even high resolution. + tall (default): half screen. + quarter: self evident -u Undelayed. Removes 5 second video delay, and about 4 second audio delay. -w do not launch watch of stream @@ -69,8 +71,8 @@ delay=true loglevel=fatal watch=true fullscreen=false -tall=false -temp=$(getopt -l help hdftuw "$@") || usage 1 +tall=true +temp=$(getopt -l help hdr:uw "$@") || usage 1 eval set -- "$temp" while true; do case $1 in @@ -80,13 +82,22 @@ while true; do loglevel=info ffp_args+=(-d) ;; - -f) - fullscreen=true - tall=false - ;; - -t) - fullscreen=false - tall=true + -r) + case $2 in + tall) + fullscreen=false + tall=true + ;; + quarter) + fullscreen=false + tall=false + ;; + full) + fullscreen=true + tall=false + ;; + esac + shift ;; -w) watch=false @@ -224,9 +235,6 @@ opts=( [vol0][vol1] amerge=inputs=2; [2]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''${delay_arg}[out]" -# [vol0][vol1] amerge=inputs=2,adelay=6000:all=1; - - # An online source says to match a 5 second vid delay, we can do an # audio delay filter: "adelay=5000|5000". However, we already get # a stream delay of about 2 seconds, and having the audio be about @@ -264,8 +272,9 @@ opts=( rm -f /tmp/iank-ffmpeg-interlude-toggle -# start muted -pactl set-source-mute @DEFAULT_SOURCE@ true +# system mute. disabled, just using application level mute atm. +# +# pactl set-source-mute @DEFAULT_SOURCE@ true if pkill -f ^ffmpeg.\*icecast://source.\*/fsf; then sleep 1 diff --git a/filesystem/usr/local/bin/abrowser b/filesystem/usr/local/bin/abrowser index d3ce643..b67ec81 100755 --- a/filesystem/usr/local/bin/abrowser +++ b/filesystem/usr/local/bin/abrowser @@ -21,6 +21,12 @@ # limitations under the License. +if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi +shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR + + # https://stackoverflow.com/a/2108540 tmp=:$PATH: del=/usr/local/bin @@ -38,8 +44,6 @@ PATH=$tmp # new tab -tmpf=$(mktemp) -i3-msg -t get_tree | jq -e '.nodes[].nodes[].nodes[].nodes | [.[]] + ( [.[].nodes[]]) | .[] | select(.window_properties.class=="abrowser") | .id' | sort >$tmpf # prefer abrowser if type -P abrowser &>/dev/null; then @@ -48,25 +52,4 @@ else b=firefox fi -$b "$@" & - -# on a fast computer, .5 is too fast, 1 is ok. on x200, 1 is too fast, 2 is ok. -sleep 2 -# debug -#printf "%s\n" "$*" >> /tmp/a -if (( $# == 0 )) && ! i3-msg -t get_tree | jq --stream -r 'select(.[1]|scalars!=null) | "\(.[0]|join(".")): \(.[1]|tojson)"' | grep 'marks.0: "abrowser"$' &>/dev/null; then - # explaining this jq nonsense. when the abrowser window starts, it - # might be in a vertical split container, and then it is nested down - # another level. the best way I could find to look in both levels was - # to get both, then combine them with + (and you have to turn them - # into a single array instead of a list of arrays with [.[]], or else - # it will add the arrays a bunch of times and give several results. - # comm gives us just the new id. - id=$(i3-msg -t get_tree | jq -e '.nodes[].nodes[].nodes[].nodes | [.[]] + ( [.[].nodes[]]) + ( [.[].nodes[].nodes[]]) + ( [.[].nodes[].nodes[].nodes[]]) | .[] | select(.window_properties.class=="'$b'") | .id' | comm -23 - $tmpf | head -n1) - rm -f $tmpf - if [[ $id ]]; then - i3-msg "[con_id=$id] mark abrowser" - fi -fi - -wait +$b "$@" diff --git a/filesystem/usr/local/bin/irc b/filesystem/usr/local/bin/irc index 0b2703e..5a76bd1 100755 --- a/filesystem/usr/local/bin/irc +++ b/filesystem/usr/local/bin/irc @@ -20,4 +20,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -exec emacs -f znc-all "$@" +exec emacs -f my-znc-all "$@" diff --git a/i3-abrowser b/i3-abrowser new file mode 100755 index 0000000..eb2d47c --- /dev/null +++ b/i3-abrowser @@ -0,0 +1,55 @@ +#!/bin/bash +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to change +# to a recommended GPL license. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi +shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR + + +# prefer abrowser +if type -P abrowser &>/dev/null; then + b=abrowser +else + b=firefox +fi + +# mark if we dont have a mark already +if i3-msg -t get_tree | jq --stream -r 'select(.[1]|scalars!=null) | "\(.[0]|join(".")): \(.[1]|tojson)"' | grep 'marks.0: "abrowser"$' &>/dev/null; then + h=$(i3-msg -t get_tree | jq -r ".. | select(.focused? == true) | .rect.height") + cur_workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused? == true) | .name') + + # h tests if we have a current focus, but that is just a random guess. + if [[ $cur_workspace == 2 && $h ]]; then + i3-msg "swap container with mark abrowser; [con_mark=\"abrowser\"] focus" + else + i3-msg '[con_mark="abrowser"] move workspace current' + fi + +else + i3-split-maybe + abrowser & + # on a fast computer, .5 is too fast, 1 is ok. on x200, 1 is too fast, 2 is ok. + sleep 2 + i3-msg "[workspace=__focused__ class=\"$b\"] mark abrowser" + wait +fi diff --git a/i3-emacs b/i3-emacs new file mode 100755 index 0000000..f3eb116 --- /dev/null +++ b/i3-emacs @@ -0,0 +1,41 @@ +#!/bin/bash +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to change +# to a recommended GPL license. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +id=$(i3-msg -t get_tree | jq -e '.. | select(.name?) | select(.name | test("^e-iak")).id ') + +if [[ $id ]]; then + h=$(i3-msg -t get_tree | jq -r ".. | select(.focused? == true) | .rect.height") + + cur_workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused? == true) | .name') + + # h tests if we have a current focus, but that is just a random guess. + if [[ $cur_workspace == 2 && $h ]]; then + i3-msg "swap container with con_id $id; [con_id=\"$id\"] focus" + else + i3-msg '[con_id="'$id'"] move workspace current' + fi +else + + i3-split-maybe + emacsclient -c +fi diff --git a/i3-konsole b/i3-konsole new file mode 100755 index 0000000..c4b5182 --- /dev/null +++ b/i3-konsole @@ -0,0 +1,45 @@ +#!/bin/bash +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to change +# to a recommended GPL license. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi +shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR + + +if i3-msg -t get_tree | jq --stream -r 'select(.[1]|scalars!=null) | "\(.[0]|join(".")): \(.[1]|tojson)"' | grep 'marks.0: "term"$' &>/dev/null; then + h=$(i3-msg -t get_tree | jq -r ".. | select(.focused? == true) | .rect.height") + + cur_workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused? == true) | .name') + + # h tests if we have a current focus, but that is just a random guess. + if [[ $cur_workspace == 2 && $h ]]; then + i3-msg "swap container with mark term; [con_mark=\"term\"] focus" + else + i3-msg '[con_mark="term"] move workspace current' + fi +else + i3-split-maybe + konsole + sleep 1 + i3-msg "[workspace=__focused__ class=\"konsole\"] mark term" +fi diff --git a/i3-pull b/i3-pull index 9d391d5..5ed9181 100755 --- a/i3-pull +++ b/i3-pull @@ -31,7 +31,6 @@ h=$(i3-msg -t get_tree | jq -r ".. | select(.focused? == true) | .rect.height") cur_workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused? == true) | .name') - # 1080 = half the 4k height #if [[ $cur_workspace == 1 && $h ]] && (( h <= 1080 )); then if [[ $cur_workspace == 1 && $h ]]; then diff --git a/i3-split-maybe b/i3-split-maybe index bb425ef..0e05259 100755 --- a/i3-split-maybe +++ b/i3-split-maybe @@ -108,7 +108,7 @@ def set_layout(i3): print('d2: len(parent.nodes):', len(parent.nodes),' > 1', 'and ( ph:',ph,' > h + 10:',h + 10,' or pw:',pw,' > w:',w,' )', 'and (screen_w:',screen_w,' < screen_h:',screen_h,' or w <= half_w:',half_w,')', - 'and h <= half_h:',half_h,'))') + 'and h <= half_h:',half_h,')') # h + 10 because a tabbed window loses high compared to its parent. # Note, it is redundant since we check above if the parent is tabbed, @@ -121,7 +121,7 @@ def set_layout(i3): if (len(parent.nodes) > 1 and ( ph > h + 10 or pw > w ) and ( screen_w < screen_h or w <= half_w ) - and h <= half_h )): + and h <= half_h ): i3.command('split vertical, layout tabbed') # print('d1: tabbed') diff --git a/i3-sway/common.conf b/i3-sway/common.conf index 79f26bb..d0ce973 100644 --- a/i3-sway/common.conf +++ b/i3-sway/common.conf @@ -23,7 +23,8 @@ set $ex exec --no-startup-id bindsym $mod+2 $ex "i3-split-maybe"; exec "pavucontrol" # calling without -no-remote makes this to be the instance that links # will open in from other applications. -bindsym $mod+3 $ex "i3-split-maybe"; exec "abrowser" +# unused. todo: consider binding this to some key on the right side of keyboard. +#bindsym $mod+3 $ex "i3-split-maybe"; exec "abrowser" # calling just abrowser mysteriously stopped working, # so I figured out this is how to get output, but then # it suddenly started working again. @@ -54,11 +55,12 @@ bindsym $mod+equal $ex "i3-set-layout splith" # get class with xprop, example output # WM_CLASS(STRING) = "irssi", "URxvt" # xprop |& grep WM_CLASS -bindsym $mod+w $ex i3-pull abrowser +bindsym $mod+w $ex "/a/exe/i3-abrowser" bindsym $mod+shift+w fullscreen toggle -bindsym $mod+e $ex i3-pull emacs -bindsym $mod+shift+e unmark emacs; mark emacs +bindsym $mod+e $ex "/a/exe/i3-emacs" +# unused +#bindsym $mod+shift+e bindsym $mod+r $ex "/a/bin/ds/xl" bindsym $mod+t $ex "i3-set-layout splitv" @@ -127,8 +129,10 @@ bindcode 171 $ex "toggle-mute unmute" #bindsym $mod+shift+5 $ex "/a/a.sh" -bindsym $mod+b $ex i3-pull term +bindsym $mod+b $ex "/a/exe/i3-konsole" bindsym $mod+shift+b unmark term; mark term + + # for use to cleanup extra emacs windows # https://faq.i3wm.org/question/7662/reverse-perl-matches-in-criteria-in-i3-config.1.html # I found their regex slightly wrong. This is a hacky way to @@ -140,7 +144,6 @@ bindsym $mod+shift+6 [class="Emacs" title="^(?!#[a-zA-Z][a-zA-Z-]*$)"] move work bindsym $mod+c kill - bindsym $mod+Home split horizontal bindsym $mod+Shift+End move container to workspace 7 bindsym $mod+End workspace 7 -- 2.30.2