3

I would like a drop down terminal which drops down when I move the mouse to the top (or bottom, left, right), similar to how the panel can be configured to auto-hide and only drop down or pop up if the mouse hovers to the border where it is.

Currently I only found a method using shortcuts e.g. F12 to bind to e.g. xfce4-terminal --drop-down.

I'm using XFCE 4.12, but I'm not particularly fixed to XFCE or xfce4-terminal, so if some other desktop or terminal supports this, it would also help.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
mxmlnkn
  • 526
  • 4
  • 11

2 Answers2

3

You can do something like this with xdotool. For example,

xdotool behave_screen_edge top search --name mywindowname windowactivate

will continuously monitor mouse movement and when at the top of the screen it will search for a window named mywindowname and cause it to be visible, depending on your window manager.

meuh
  • 49,672
  • 2
  • 52
  • 114
3

Building on top of @meuh's answer I came up with the attached script. Here are the features:

  • Spawns five terminals two each left and right and one on the top
  • Terminals are initially minimized and set active if cursor hits border inside the terminal height / width, disappears if window is active and border hit again

Notes:

  • I found the behavior of behave_screen_edge weird at times. It seems to ignore many cases. This is quite unsatisfactory.
  • Also there is no fancy drop/slide in animation. I tried windowmove in a loop, but a bash loop is too slow, to look good.

The script:

#!/bin/bash
# spawn drop in terminals
getLastWid() {
    sleep 0.4s
    wid=$(wmctrl -lp | 'grep' " Terminal " | awk '{print strtonum($1),$0;}' |
          'sort' -n | 'tail' -1 | 'sed' -nE 's|^([0-9a-f]+) .*|\1|p')
}
getBorderWidth() {
    # https://github.com/jordansissel/xdotool/issues/115
    local X Y X0 Y0
    eval $(xdotool getwindowgeometry --shell $1 | command grep '[XY]=')
    X0=$X
    Y0=$Y
    xdotool windowmove --relative $1 0 0
    eval $(xdotool getwindowgeometry --shell $1)
    bw=$((X-X0))
    bh=$((Y-Y0))
    xdotool windowmove $1 $((X0-bw)) $((Y0-bh))
}

script=$(mktemp)
cat > "$script" <<"EOF"
#!/bin/bash

sw=1920 # screen width
sh=1080 # screen height
ph=35   # panel height (assumed it is at the bottom)
script=$0; pos=$1; wid=$2; bw=$3; bh=$4; firstUse=$5

# test if window is still open, if not close xdotool
if ! wmctrl -lp | 'grep' -q -i "$(echo "obase=16;$wid" | bc)"; then
    pkill -i -f "xdotool behave_screen_edge.*$wid"
    exit 1
fi

# choose target coordinates, where to move window and also to manually evalute clicks
eval $(xdotool getwindowgeometry --shell $wid)  # sets HEIGHT, WIDTH
ww=$((WIDTH+bw/2))       # window width
wh=$((HEIGHT+bh/2+bw/2)) # window height
case $pos in
    left1)  x=0; y=$((sh-ph-wh-1-wh))          ; ;;
    left2)  x=0; y=$((sh-ph-wh-1))             ; ;;
    top)    x=$((sw/2-ww/2)); y=0              ; ;;
    right1) x=$((sw-ww)); y=$((sh-ph-wh-1-wh)) ; ;;
    right2) x=$((sw-ww)); y=$((sh-ph-wh-1))    ; ;;
esac

# on first use only move windows to their correct positions and hide them
if [ ! -z "$firstUse" ] && [ $firstUse == 1 ]; then
    xdotool behave_screen_edge ${pos%*[0-9]} exec "$script" $pos $wid $bw $bh &
    xdotool windowminimize $wid windowmove $wid $x $y
    exit 0
fi

# evaluate mouse location now and exit if not correct
eval $(xdotool getmouselocation --shell | command grep '[XY]=')
case $pos in
    left1|left2)   if [ $Y -lt $y ] || [ $Y -ge $((y+HEIGHT)) ]; then exit; fi; ;;
    right1|right2) if [ $Y -lt $y ] || [ $Y -ge $((y+HEIGHT)) ]; then exit; fi; ;;
    top)           if [ $X -lt $x ] || [ $X -ge $((x+WIDTH )) ]; then exit; fi; ;;
esac

#actually move and activate window and hide it, if it already is active
if [ $wid == $(xdotool getactivewindow) ]; then
    xdotool windowminimize $wid
else
    xdotool windowmove $wid $x $y windowactivate $wid
fi
EOF
chmod u+x "$script"

xfce4-terminal --working-directory="$HOME" & getLastWid && getBorderWidth $wid  && "$script" left1  $wid $bw $bh 1
xfce4-terminal --working-directory="$HOME" & getLastWid && "$script" left2  $wid $bw $bh 1
xfce4-terminal --working-directory="$HOME" & getLastWid && "$script" right1 $wid $bw $bh 1
xfce4-terminal --working-directory="$HOME" & getLastWid && "$script" right2 $wid $bw $bh 1
xfce4-terminal --working-directory="$HOME" & getLastWid && "$script" top    $wid $bw $bh 1
mxmlnkn
  • 526
  • 4
  • 11