Skip to content

Instantly share code, notes, and snippets.

@Misko-2083
Last active August 25, 2018 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Misko-2083/9d802269db03e118dc756598d0c33fce to your computer and use it in GitHub Desktop.
Save Misko-2083/9d802269db03e118dc756598d0c33fce to your computer and use it in GitHub Desktop.
Brisk-menu workaround when it's not unmapping by hot-key in Ubuntu Mate
#!/bin/bash
### Brisk-menu workaround when it's not unmapping by hot-key in Ubuntu Mate
### Install xdotool
### Save this script and make it executable
###############################################################################
# Launching this script with the Super_L keyboard key
# Install ksuperkey https://github.com/hanschen/ksuperkey
# Set brisk menu hot-key to none '' or some other key combo like '<Ctrl>F10'
# gsettings set com.solus-project.brisk-menu hot-key '<Ctrl>F10'
# Set next command to run on startup (ksuperkey required):
# ksuperkey -e 'Super_L=Control_L|Shift_L|Escape'
# Set the keyboard shortcut to run this script with Ctrl+Shift+Escape
###############################################################################
# Get brisk-menu PID
brisk_pid="$(ps -eo pid,cmd | grep "/usr/libexec/brisk-menu" | grep -v grep | awk '{print $1}')"
OIFS="$IFS"
IFS=$'\n'
RC=0
# Map or unmap the window with Xwindow property _NET_WM_NAME = Brisk Menu Launcher
for BRISK_WIN_ID in $(xdotool search --pid $brisk_pid); do
BRISK_WIN_ID_HEX="$(printf "0x%08x\n" $BRISK_WIN_ID)"
NET_WM_NAME="$(xprop -id ${BRISK_WIN_ID_HEX} _NET_WM_NAME)"
if [[ "${NET_WM_NAME##*'='}" =~ "Brisk Menu Launcher" ]] ; then
if ! xwininfo -id ${BRISK_WIN_ID_HEX} -stats | grep -q "IsViewable"
then
xdotool windowmap ${BRISK_WIN_ID_HEX}
else
xdotool windowunmap ${BRISK_WIN_ID_HEX}
fi
RC=1
break
fi
done
IFS="$OIFS"
# On startup there is no Brisk Menu Launcher window id
# If there is no window with Xwindow property _NET_WM_NAME = Brisk Menu Launcher
# Click in the middle of the brisk-menu button
# Not fancy but that will launch the brisk menu
if [[ "${RC}" -eq "0" ]]; then
# finds the visible window
BRISK_WIN_ID=$(xdotool search --onlyvisible --pid $brisk_pid)
# Extracts the window's absolute-left x,y and width and height
XWININFO=$(xwininfo -id $BRISK_WIN_ID)
ARRAY=(${XWININFO#* X: })
AX=${ARRAY[0]}
AY=${ARRAY[4]}
RX=${ARRAY[8]}
RY=${ARRAY[12]}
W=${ARRAY[14]}
H=${ARRAY[16]}
X=$((AX-RX))
Y=$((AY-RY))
POS_X=$((X+W/2)) # Approximately X in the middle of the toggle button
POS_Y=$((Y+H/2)) # Approximately Y in the middle of the toggle button
# Moves the mouse pointer to coordinates $POS_X $POS_Y and clicks
xdotool mousemove --clearmodifiers $POS_X $POS_Y click 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment