Как автоматически изменить местоположение my-weather-indicator настольных виджетов для внешнего монитора

My-Weather-Indicator является, вероятно, лучшим погодным виджетом для рабочего стола Ubuntu.

Однако нужно вручную изменить местоположение настольных виджетов (например, выровненный верхний правый) каждый раз, когда внешний монитор подключен к ноутбуку.

Как насчет сценария запуска, который автоматически изменит местоположение my-weather-indicator's (например, 2 "суперчасов") настольные виджеты для внешнего монитора? Или кто-либо другой (возможно, лучше) решение?

0
задан 3 February 2016 в 01:36

1 ответ

Вот демонстрационный сценарий запуска

в это можно ввести Exec= строка ~/.config/autostart/my-weather-indicator.desktop файл вместо команды /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator:

#!/bin/bash

while true
do
    MONITORS="$(xrandr | grep -v "eDP1 " | grep -c " connected ")"
    if [[ "$MONITORS" -eq 0 ]]                              # no external monitor, LCD panel only
    then
        MONINTX="$(xrandr | grep "eDP1 connected " | sed -e 's/^eDP1 connected primary //g' -e 's/x.*$//g')"
        MONINTV="$(expr $MONINTX - 316)"
        MONINT1="$(grep -c "\"wp1-x\": $MONINTV" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf")"
        if  [[ "$MONINT1" -eq 0 ]]                          # widget1 not configured for LCD panel
        then
            sed -i "s/\"wp1\-x\"\: [0-9]*/\"wp1\-x\"\: $MONINTV/" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf"
            echo "REFRESH" > "/tmp/my-weather-indicator_mon-int"
        fi
        MONINT2="$(grep -c "\"wp2-x\": $MONINTV" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf")"
        if  [[ "$MONINT2" -eq 0 ]]                          # widget2 not configured for LCD panel
        then
            sed -i "s/\"wp2\-x\"\: [0-9]*/\"wp2\-x\"\: $MONINTV/" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf"
            echo "REFRESH" > "/tmp/my-weather-indicator_mon-int"
        fi
        if [ -f "/tmp/my-weather-indicator_mon-int" ]       # marker file
        then
            if [ -s "/tmp/my-weather-indicator_mon-int" ]   # content
            then
                PID="$(ps -e -o pid,cmd | grep "/usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" | egrep -v grep | awk '{print$1}')"
                if [[ "$PID" -eq 0 ]]                       # not running, start
                then
                    rm "/tmp/my-weather-indicator_mon-int"
                    "/opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" &
                else
                    kill -9 "$PID"                          # running, re-start
                    rm "/tmp/my-weather-indicator_mon-int"
                    "/opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" &
                fi
            fi
        fi
    else                                                    # external monitor connected
        MONEXTX="$(xrandr | grep " connected " | grep -v "eDP1" | sed -e 's/^e*[A-Z]*[A-Z][A-Z][0-9] connected primary //g' -e 's/x.*$//g')"
        MONEXTV="$(expr $MONEXTX - 316)"
        MONEXT1="$(grep -c "\"wp1-x\": $MONEXTV" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf")"
        if  [[ "$MONEXT1" -eq 0 ]]                          # widget1 not configured for external monitor
        then
            sed -i "s/\"wp1\-x\"\: [0-9]*/\"wp1\-x\"\: $MONEXTV/" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf"
            echo "REFRESH" > "/tmp/my-weather-indicator_mon-ext"
        fi
        MONEXT2="$(grep -c "\"wp2-x\": $MONEXTV" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf")"
        if  [[ "$MONEXT2" -eq 0 ]]                          # widget2 not configured for external monitor
        then
            sed -i "s/\"wp2\-x\"\: [0-9]*/\"wp2\-x\"\: $MONEXTV/" "/home/$USER/.config/my-weather-indicator/my-weather-indicator.conf"
            echo "REFRESH" > "/tmp/my-weather-indicator_mon-ext"
        fi
        if [ -f "/tmp/my-weather-indicator_mon-ext" ]       # marker file
        then
            if [ -s "/tmp/my-weather-indicator_mon-ext" ]   # content
            then
                PID="$(ps -e -o pid,cmd | grep "/usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" | egrep -v grep | awk '{print$1}')"
                if [[ "$PID" -eq 0 ]]                       # not running, start
                then
                    rm "/tmp/my-weather-indicator_mon-ext"
                    "/opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" &
                else
                    kill -9 "$PID"                          # running, re-start
                    rm "/tmp/my-weather-indicator_mon-ext"
                    "/opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" &
                fi
            fi
        fi
    fi
    PID="$(ps -e -o pid,cmd | grep "/usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" | egrep -v grep | awk '{print$1}')"
    if [[ "$PID" -eq 0 ]]                                   # not running, start
    then
        "/opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator" &
    fi
    sleep 12
done

Внимание: Этот сценарий был только протестирован на ноутбуке Dell Latitude с 2 настольными виджетами с помощью темы суперчасов и мог бы потребовать некоторой дальнейшей подстройки, и это могла бы быть хорошая идея проверить, будут ли переменные, используемые здесь, также работать в других системах путем проверки терминального вывода команды xrandr

enter image description here

0
ответ дан 29 September 2019 в 12:59

Другие вопросы по тегам:

Похожие вопросы: