From e837390dc1524ba83415374fc078d8e4e02c118d Mon Sep 17 00:00:00 2001 From: dcarrillo Date: Fri, 3 Jul 2020 20:08:19 +0200 Subject: [PATCH] [polybar] Add task menu to open/close tasks --- .config/polybar/launch.sh | 1 + .config/polybar/modules.ini | 2 +- .config/polybar/scripts/nmcli_manager | 2 +- .config/polybar/scripts/task_manager | 47 ++++++++++++++++++++++++--- .config/rofi/orange.rasi | 5 +++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index 8b878da..faf3ca6 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -5,6 +5,7 @@ export TERMINAL_CMD=${TERMINAL_CMD:-"tilix --profile orange --new-process -e"} export WM_CONTROL=${WM_CONTROL:-"~/.config/polybar/scripts/switch_window_state"} export TASKMANAGER_MAX_TASKS=${TASKMANAGER_MAX_TASKS:-20} +export ROFI_THEME=${ROFI_THEME:-orange} function wait_for_polybar { diff --git a/.config/polybar/modules.ini b/.config/polybar/modules.ini index 2e20d52..00c0184 100644 --- a/.config/polybar/modules.ini +++ b/.config/polybar/modules.ini @@ -1,7 +1,7 @@ [module/windows] type = custom/text content ="  " -click-left = rofi -modi window -show window -theme orange -show-icons -location 1 -yoffset +45 -xoffset +20 +click-left = rofi -modi window -show window -theme $ROFI_THEME -show-icons -location 1 -yoffset +45 -xoffset +20 [module/mpd] type = internal/mpd diff --git a/.config/polybar/scripts/nmcli_manager b/.config/polybar/scripts/nmcli_manager index 005a4ec..000f7f1 100755 --- a/.config/polybar/scripts/nmcli_manager +++ b/.config/polybar/scripts/nmcli_manager @@ -10,7 +10,7 @@ ROFI="rofi -dmenu -sep # -i -p Network: - -theme orange + -theme $ROFI_THEME -location 3 -yoffset +45 -xoffset -80 diff --git a/.config/polybar/scripts/task_manager b/.config/polybar/scripts/task_manager index 396bc71..55faf0c 100755 --- a/.config/polybar/scripts/task_manager +++ b/.config/polybar/scripts/task_manager @@ -4,6 +4,7 @@ STATUS_FILE=/dev/shm/polybar_task_manager BAR_CONFIG_FILE=~/.config/polybar/bar.ini MODULES_LEFT_FILE=~/.config/polybar/modules-left.ini REFRESH=1 +TASK_MENU=" Open a new one # Close" update_bar_config() { @@ -19,8 +20,10 @@ hook-0 = echo "" hook-1 = ~/.config/polybar/scripts/task_manager --set-task $task hook-2 = ~/.config/polybar/scripts/task_manager --show-or-minimize-window $task hook-3 = ~/.config/polybar/scripts/task_manager --close-window $task +hook-4 = ~/.config/polybar/scripts/task_manager --show-menu $task click-left = polybar-msg -p %pid% hook taskbar$task 3 click-middle = polybar-msg -p %pid% hook taskbar$task 4 +click-right = polybar-msg -p %pid% hook taskbar$task 5 MODULE_TEMPLATE @@ -37,7 +40,7 @@ cat < -1) print $3,$1}' \ - | sed -r 's/([0-9])\.([0-9])/\1\2/g' \ - | awk -F'.' '{ print $NF }' \ - | tail -"$max_tasks" | sort > $STATUS_FILE.current + wmctrl -lxp | awk '{if ($2 > -1) print $4,$1,$3}' \ + | sed -r 's/([0-9])\.([0-9])/\1\2/g' \ + | awk -F'.' '{ print $NF }' \ + | tail -"$max_tasks" | sort > $STATUS_FILE.current diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1 if [ $? -ne 1 ]; then @@ -123,6 +126,32 @@ print_task_name() echo '%{T6}'"$icon"'%{T-}' } +show_task_menu() +{ + pid=$(get_task_pid "$1") + cmd=$(ps --no-headers -o cmd "$pid" \ + | sed 's/--gapplication-service//g' \ + | tr -d '\n') + offset=$(( ($1 * 65) )) + ROFI="rofi -dmenu -sep # -theme $ROFI_THEME + -location 1 -width 8 + -yoffset +45 -xoffset +${offset}" + choice=$(echo "$TASK_MENU" | $ROFI -theme-str 'inputbar { children: [];}' \ + | sed 's/^[[:space:]]*//' | cut -f 1 -d " ") + + case "$choice" in + Open) + $cmd &>/dev/null & + ;; + Close) + id=$(get_task_id "$1") + wmctrl -ic "$id" + ;; + esac + + print_task_name "$1" +} + get_active_window() { echo 0x0"$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2 | cut -f 2 -d 'x')" @@ -133,6 +162,11 @@ get_task_id() sed "${1}q;d" $STATUS_FILE | cut -f 2 -d " " } +get_task_pid() +{ + sed "${1}q;d" $STATUS_FILE | cut -f 3 -d " " +} + daemon() { while true; do @@ -153,6 +187,9 @@ case "$1" in --set-task) print_task_name "$2" ;; + --show-menu) + show_task_menu "$2" + ;; --show-or-minimize-window) id=$(get_task_id "$2") diff --git a/.config/rofi/orange.rasi b/.config/rofi/orange.rasi index 96ed8e4..ecdb4d5 100644 --- a/.config/rofi/orange.rasi +++ b/.config/rofi/orange.rasi @@ -6,6 +6,11 @@ * Slight modification by dcarrillo */ +configuration { + me-select-entry: "MouseSecondary"; + me-accept-entry: "MousePrimary"; +} + /* global settings and color variables */ * { maincolor: #ed8712;