從掛起恢復後如何重新啟動 Unity?

從掛起恢復後如何重新啟動 Unity?

這聽起來可能是一個愚蠢的想法,但我喜歡有一個透明的頂部面板,可以在Compiz 配置設定管理器中進行配置,但是當我從掛起狀態恢復時,它不再透明,並且在調用破折號時會出現圖形故障。如果我透過執行命令「unity」重新啟動 Unity,這種情況就會消失。所以我想知道是否有可能實現這一目標?我嘗試/etc/pm/sleep.d/按照中所述設定腳本如何從掛起恢復後執行命令?但它不起作用,我想它是在我再次登入並且 Unity 恢復之前運行的。

有什麼辦法可以實現我想要的還是我應該放棄?

答案1

系統設定 > 鍵盤 > 快速鍵 > 自訂快速鍵

並創建一個新的:

在此輸入影像描述

然後設定一個簡單的鍵盤快速鍵(如Alt+)R,以便在暫停後輕鬆執行 Unity 快速重新啟動。

我不會遭受你的錯誤,但我需要在每個新會話上執行此命令,因為統一不記得新會話上的邊緣綁定。

答案2

直接來自systemd-suspend.service 手冊:

Immediately before entering system suspend and/or hibernation systemd-suspend.service (and the other mentioned units, respectively) will run all executables in /usr/lib/systemd/system-sleep/ and pass two arguments to them. The first argument will be "pre", the second either "suspend", "hibernate", or "hybrid-sleep" depending on the chosen action. Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now "post". All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.

我做了一些測試,發現如果你將一個腳本(被所有人標記為可執行文件,可以透過 實作chmod a+x)放在/lib/systemd/system-sleep,沒有 /usr,它將按所述執行。

然而,有一個缺點讓你認為它不起作用:環境不同。圖形命令不工作。可能有辦法解決這個問題,但預設情況下,unity --replace 將失敗因為它無法連接到 X 伺服器(因此,如果您按 CTRL-ALT-F1 並進入實際控制台而不進行篡改,則所有不起作用的命令都不會起作用)。

好吧,我只是暫停打字去做一些研究:在查看了基本 chroot 維基(因為我在chroots中也遇到過同樣的問題),我發現如果你手動調用xhost + 暫停,圖形命令(在我的例子中zenity --info --text "1:$1 2:$1")正常工作。但是,您無法xhost +從腳本中呼叫。你什麼要做的是將一個程式添加到“啟動應用程式”中,以便xhost +在您登入時自動調用(將其添加到那裡而不是.bashrc因為如果添加到.bashrc它,每次打開終端模擬器時都會運行)。在 Unity 上可能有所不同,但在 Ubuntu MATE 上我可以轉到System → Preferences → Personal → Startup Applications並點擊「新增」來執行此操作。

/lib/systemd/system-sleep/restart-unity然後,建立一個包含以下內容的文件:

#!/bin/bash
export DISPLAY=:0
if [[ "$1" == "post" && "$2" == "suspend" ]]
then
    sleep 5
    unity --replace
fi

並運行sudo chmod a+x /lib/systemd/system-sleep/restart-unity(確保該文件歸 root 所有並且只能由 root 寫入)。

請注意,它必須使用bash。這是因為“if”語句。當我在 中手動嘗試該語句時,我從該部分sh收到了各種錯誤。&&

之所以sleep存在,是因為沒有它,unity --replace將無法連接到 X 伺服器(或看起來是這樣)。

根據我自己在 Zesty 上的測試,這應該可行。

我花了 15 分鐘試圖弄清楚為什麼它不起作用,卻發現我忘了這條export DISPLAY=:0線。

答案3

這些看起來很有用:

這是你看到的故障嗎?

bad_transparency_after_sleep.png

相關內容