river icon indicating copy to clipboard operation
river copied to clipboard

[Feature Request] Move Focus To Window With App-Id

Open ZachIndigo opened this issue 2 years ago • 6 comments

After an amount of finagling and hackering, I've got dwm style scratchpads mostly working perfectly, except for one issue. When I spawn the window and assign it to a scratchpad tag, the newly spawned window has focus (which is good). Then when I hide the scratchpad tag, the window goes away (which is good). When I bring that tag back, the window comes back (good) but is not focused (bad). I would like a riverctl command to focus a window with a specific app-id, if that's possible.

Here are the dotfiles I'm using.

At a high level, the command river_sp will toggle tag $(( 1 << ($ARG + 9) )) (where ARG is the scratchpad number), set the tag-mask to the same $(( 1 << ($ARG + 9) )), then spawn the correct scratchpad program based off of whatever number ARG is, and then reset the tagmask to $(( (1 << 9) - 1)).

river_sp:

#!/bin/sh

#{{{ binpath
BINPATH="${XDG_CONFIG_HOME:-$HOME/.config}/river/sp"
#}}}

#{{{ spawnwindow
spawnwindow () {
  case "$1" in
    1) pgrep -x sp_z ||  ${BINPATH}/sp_z ;;
    2) pgrep -x sp_x ||  ${BINPATH}/sp_x ;;
    3) pgrep -x sp_c ||  ${BINPATH}/sp_c ;;
    4) pgrep -x sp_v ||  ${BINPATH}/sp_v ;;
    5) pgrep -x sp_b ||  ${BINPATH}/sp_b ;;
    6) pgrep -x sp_a ||  ${BINPATH}/sp_a ;;
    7) pgrep -x sp_s ||  ${BINPATH}/sp_s ;;
    8) pgrep -x sp_d ||  ${BINPATH}/sp_d ;;
    9) pgrep -x sp_f ||  ${BINPATH}/sp_f ;;
    10) pgrep -x sp_g || ${BINPATH}/sp_g ;;
    11) pgrep -x sp_q || ${BINPATH}/sp_q ;;
    *) printf "Unknown scratchpad $1!\n" ; exit 1 ;;
  esac
}
#}}}

#{{{ getopts
for i in "$@"; do
  case "$i" in
    z) ARG=1  ;;
    x) ARG=2  ;;
    c) ARG=3  ;;
    v) ARG=4  ;;
    b) ARG=5  ;;
    a) ARG=6  ;;
    s) ARG=7  ;;
    d) ARG=8  ;;
    f) ARG=9  ;;
    g) ARG=10 ;;
    q) ARG=11 ;;
    *) printf "Unknown scratchpad $i!\n" ; exit 1 ;;
  esac
  if pgrep -x "sp_$i"; then
    riverctl toggle-focused-tags $((1 << ($ARG + 9)))
  else
    riverctl toggle-focused-tags $(( 1 << ($ARG + 9)))
    riverctl spawn-tagmask $(( 1 << ($ARG + 9)))
    spawnwindow "$ARG"
    riverctl spawn-tagmask $(( (1 << 9) - 1))
  fi
done
#}}}

ZachIndigo avatar Feb 24 '23 17:02 ZachIndigo