[idea] Pyradio quake like . .

Hi @napcok,

What do you think about the following.

To give Pyradio Guake behavior. [W+r]

Why …

It is quieter and quick way to use the radio.
It prevents opening a new Pyradio instance every [W+r].

gif
pyradio-quake-WR

I got it to work, ugly for now . . . .

What happend

  • I am not getting out of the position management, as you set it up.

  • In my .config/mabox, i can’t see a file created for dimensions. (.quake-pyradio in my case).

  • Using the ${HEIGHT}x etc lines, gives me only the terminal. No pyradio.


As you can see, that’s why I put down the position fixed, for now.

mb-pyradio.sh (mabox-terminal)

#!/bin/bash

# Author: Daniel Napora <napcok@gmail.com>
# "Show-Hide" terminal wrapper for terminator for use with keybind eg. super + enter.
# Depenging on actual state it will start, show or hide terminal window.

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
NAME="pyradio"

__run() {
ID=$(wmctrl -x -l | grep ${NAME} | awk '{print $1}' | head -n 1)
if [ -z "${ID}" ]; then
    if [ -f "$GEOMETRY_FILE" ]; then
    POS=$(head -n 1 $GEOMETRY_FILE)
    terminator -T ${NAME} -b --geometry "$POS" -e 'pyradio -lt'
    else
	#TOP=$(wmctrl -d|grep "*"|awk '{print $8}'|cut -d',' -f2)
	#LEFT=$[$(wmctrl -d|grep "*"|awk '{print $4}'|cut -d'x' -f1)/8]
	#HEIGHT=$[$(wmctrl -d|grep "*"|awk '{print $4}'|cut -d'x' -f2)/2]
	#WIDTH=$[${LEFT}*6]
	#terminator -T ${NAME} -b --geometry ${WEIDTH}x${HEIGTH}+${LEFT}+${TOP} -e "pyradio -lt"
	
        terminator -T ${NAME} -b --geometry "900x400+150+48" -e 'pyradio -lt'
        
    fi
else
	ID_DEC=$((${ID}))
	ACTIVE_WIN_DEC=$(xdotool getactivewindow)
	if [ "${ACTIVE_WIN_DEC}" == "${ID_DEC}" ]; then
		xdotool windowminimize ${ID_DEC}
	else
		xdotool windowactivate ${ID_DEC}
	fi
fi
}

__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool getactivewindow))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE

}
__reset() {
    rm -f $GEOMETRY_FILE
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac

Curious what you think of the idea - Pyradio quake like -

:bird:

2 Likes

Hi @muzqs
I modified script a little, now saving position should work.

I also added --icon and removed -b (borderless - no window decoration option)

#!/bin/bash

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
NAME="quakeradio"

__run() {
ID=$(wmctrl -x -l | grep ${NAME} | awk '{print $1}' | head -n 1)
if [ -z "${ID}" ]; then
    if [ -f "$GEOMETRY_FILE" ]; then
    POS=$(head -n 1 $GEOMETRY_FILE)
    terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "$POS" -e 'pyradio -lt'
    else
       terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "900x400+150+48" -e 'pyradio -lt'
    fi
else
	ID_DEC=$((${ID}))
	ACTIVE_WIN_DEC=$(xdotool getactivewindow)
	if [ "${ACTIVE_WIN_DEC}" == "${ID_DEC}" ]; then
		xdotool windowminimize ${ID_DEC}
	else
		xdotool windowactivate ${ID_DEC}
	fi
fi
}

__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool search --name ${NAME}))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE
}
__reset() {
    rm -f $GEOMETRY_FILE
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac
2 Likes

Hi @napcok,

Thanks for taking the time looking at the script.

:ok_hand:


A check thingy.

Is it True|False that .quakeradio is needed to be created manually.

Once I manually create the file .quakeradio with a line like this, 900x400+150+48, then
the positioning works. $POS

If .qaukeradio [$GEOMETRY_FILE] does not exist, it is also not created during the process.

Actually i never saw .quake-term or .quakeradio file automatic generated.

__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool search --name ${NAME}))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE
}

Without .quakeradio the dimensions are top, left, not using the else.

else
    terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "900x400+150+48" -e 'pyradio -lt'
    fi


:face_with_spiral_eyes: I guess I don’t understand how the $GEOMETRY_FILE part works. :face_with_spiral_eyes:

Once I have manually edit .quakeradio, it works very nicely.

Very happy with W+r now.:bird:

It is not automatically generated.
You need to run command:

your_scriptname save

to generate it.

1 Like

Same script with some minor improvements, hope you don’t mind :wink:

#!/bin/bash

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
PYRADIO_ICON_FILE="/usr/share/icons/pyradio.png"
NAME="quakeradio"

__run() {
ID=$(wmctrl -xl | awk -v P="${NAME}" '$0 ~ P {print $1;exit}')
if [ -z "${ID}" ]; then
   if [ -f "$GEOMETRY_FILE" ] && [ -s "$GEOMETRY_FILE" ]; then
      POS="$(head -n 1 "$GEOMETRY_FILE")"
   else
      POS="900x400+150+48"
   fi
   terminator -T ${NAME} --icon="${PYRADIO_ICON_FILE}" --geometry "$POS" -e 'pyradio -lt'
else
   ID_DEC="$((${ID}))"
   ACTIVE_WIN_DEC="$(xdotool getactivewindow)"
   if [ "${ACTIVE_WIN_DEC}" == "${ID_DEC}" ]; then
      xdotool windowminimize ${ID_DEC}
   else
      xdotool windowactivate ${ID_DEC}
   fi
fi
}

__save() {
  eval "$(xdotool getwindowgeometry --shell "$(xdotool search --name ${NAME})")"
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > "$GEOMETRY_FILE"
}
__reset() {
    rm -f "$GEOMETRY_FILE"
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac

2 Likes

Notes:

  • Files in variables; clear and easier to customize later on.
  • Simplified method for getting the ID.
  • Avoid a possible race condition where the Geometry File may exists but it is empty.
  • I was trying to get rid of the number format converting line but, surprisingly, none of the commands has a native way to do so. :face_with_spiral_eyes:
2 Likes