透過邊緣綁定顯示啟動器

透過邊緣綁定顯示啟動器

我使用 2 個顯示器(其中右側顯示器的像素和物理指標小於左側顯示器),並且經常想在自動隱藏的啟動器上的右側顯示器上開啟某些內容。 (顯示設定中的黏性邊緣已關閉,因此在螢幕之間移動遊標感覺更自然。)這需要我將遊標緩慢移動到右顯示器的左邊緣,因為如果我像平常一樣快速移動遊標,遊標就會移動到左側顯示器。

如果我可以將遊標移到底部邊緣以淡入啟動器,我希望它。但是,我找不到這樣做的推薦。

如果有淡入啟動器的命令或其他方式來執行此操作,請告訴我。

答案1

當滑鼠進入「觸發」區域時顯示啟動器

當滑鼠指標進入特定區域時,下面的腳本會啟動(自動隱藏)啟動器(啟動區在圖像中)。

因為畫圖不太方便完全是直線朝向目標啟動器圖標,啟動器啟動後,我在(右)螢幕左側創建了一個 200px 的區域,您可以在其中自由移動而無需再次隱藏啟動器(移動區域)。

在此輸入影像描述

如何使用

  1. 此腳本用於xdotool獲取滑鼠位置:

    sudo apt-get install xdotool
    
  2. 將腳本複製到一個空文件中,另存為trigger_launcher.py

  3. 在腳本的頭部部分,我設定了適合您的螢幕組合且頂部對齊的值。但是,如果您要將腳本與其他螢幕(尺寸)一起使用,或者您想更改(觸發)邊距,則可以在腳本的頭部進行更改:

    # the script assumes the two screens are top-alligned (!)
    
    #-- set the area to trigger the launcher (from left bottom of second screen) below:
    vert_marge = 50
    hor_marge = 200
    #-- set the width of the left screen below:
    width_screen1 = 1680
    #-- set the height of the right screen below:
    height_screen2 = 900
    #---
    
  4. 使用以下命令測試驅動腳本:

    python3 /path/to/trigger_launcher.py
    
  5. 如果一切正常,請將其新增至您的啟動應用程式:Dash > 啟動應用程式 > 新增。新增指令:

    /bin/bash -c "sleep 15&&python3 /path/to/trigger_launcher.py"
    

劇本

#!/usr/bin/env python3
import subprocess
import time

# the script assumes the two screens are top-alligned (!)

#-- set the area to trigger the launcher (from left bottom of second screen) below:
vert_marge = 50
hor_marge = 200
#-- set the with of the left screen below:
width_screen1 = 1680
#-- set the height of the right screen below:
height_screen2 = 900
#--


vert_line = height_screen2-vert_marge
hor_line2 = width_screen1+hor_marge
k = [" org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ ",
    "gsettings set ", "launcher-hide-mode 1", "launcher-hide-mode 0"]

hide = k[1]+k[0]+k[2]; show = k[1]+k[0]+k[3]

def set_launcher(command):
    subprocess.Popen(["/bin/bash", "-c", command])

def get_mousepos():
    curr = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8")
    return [int(it.split(":")[1]) for it in curr.split()[:2]]

current1 = get_mousepos()
while True:
    time.sleep(0.3)
    current2 = get_mousepos()
    if not current1 == current2:
        test1 = [int(current1[1]) > vert_line, width_screen1 < int(current1[0]) < hor_line2]
        test2 = [int(current2[1]) > vert_line, width_screen1 < int(current2[0]) < hor_line2]
        test3 = any([int(current2[0]) > hor_line2, int(current2[0]) < width_screen1])
        if (all(test1), all(test2)) == (False, True):
            set_launcher(show)
        elif test3 == True:
            set_launcher(hide)
    current1 = current2

編輯

正如您在評論中提到的,下面的版本有 3 秒的時間間隔,而不是「移動區域」。

#!/usr/bin/env python3
import subprocess
import time

# the script assumes the two screens are top-alligned (!)

#-- set the area to trigger the launcher (from left bottom of second screen) below:
vert_marge = 50
hor_marge = 200
#-- set the with of the left screen below:
width_screen1 = 1680
#-- set the height of the right screen below:
height_screen2 = 900
#--

vert_line = height_screen2-vert_marge
hor_line2 = width_screen1+hor_marge
k = [" org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ ",
    "gsettings set ", "launcher-hide-mode 1", "launcher-hide-mode 0"]

hide = k[1]+k[0]+k[2]; show = k[1]+k[0]+k[3]

def set_launcher(command):
    subprocess.Popen(["/bin/bash", "-c", command])

def get_mousepos():
    curr = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8")
    return [int(it.split(":")[1]) for it in curr.split()[:2]]

current1 = get_mousepos()
while True:
    time.sleep(0.3)
    current2 = get_mousepos()
    if not current1 == current2:
        test1 = [int(current1[1]) > vert_line, width_screen1 < int(current1[0]) < hor_line2]
        test2 = [int(current2[1]) > vert_line, width_screen1 < int(current2[0]) < hor_line2]
        if (all(test1), all(test2)) == (False, True):
            set_launcher(show)
            time.sleep(3)
            set_launcher(hide)
    current1 = current2

相關內容