Ubuntu Linux 17.10 螢幕鎖定失效 [論壇 - Ubuntu 與 GNOME]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



Ubuntu Linux 17.10 螢幕鎖定失效
會員一級
註冊日期:
2011/8/30 13:53
所屬群組:
已註冊使用者
等級: 3
HP : 0 / 55
MP : 6 / 1892
EXP: 20
離線
小弟今日進行了一些軟體的安裝、移除與升級後,發現鎖定螢幕的按鍵消失,快捷鍵也無法鎖定螢幕,連鎖定螢幕的設定選項也無法更動。
自己還是初學者,不過今日剛開機都還正常,猜想是今日誤動了些套件,造成這個問題。

爬了一些文章,也沒找到類似情況的解法,還請各位先進幫幫忙除錯!非常感謝!

附件:



png  2017-11-04 00-18-13 的螢幕擷圖.png (18.76 KB)
26880_59fc98c1660c4.png 493X510 px

png  2017-11-04 00-21-24 的螢幕擷圖.png (91.69 KB)
26880_59fc98cfd8d98.png 1022X716 px

2017/11/4 0:27
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

吹風 寫到:
小弟今日進行了一些軟體的安裝、移除與升級後,發現鎖定螢幕的按鍵消失,快捷鍵也無法鎖定螢幕,連鎖定螢幕的設定選項也無法更動。
自己還是初學者,不過今日剛開機都還正常,猜想是今日誤動了些套件,造成這個問題。

爬了一些文章,也沒找到類似情況的解法,還請各位先進幫幫忙除錯!非常感謝!



我的環境目前測試正常,目前沒遇到您說的情況,
另外我還沒研究透徹,
所以我也不曉得在您的環境,發生這個狀況,是那個關鍵因素導致的,
因此也只能先給您一些探索的起點。

我在「#22 回覆: Ubuntu 17.10 推出」有建立索引,裡面的一些文章,您可以參考。

================================================================================


關於右上角,也就是您提供的第一張圖,您可以參考「關於「gnome-shell-extension」」那幾篇。

然後可以探索「gnome-shell」的「Source Package: gnome-shell」。

執行下面指令


$ apt-get source gnome-shell




然後您可以從「gnome-shell-3.26.1/js/ui/panel.js」研究起,


例如,您可以先用關鍵字「GenericContainer」來找尋,
稍微向上找,就可以找到「var Panel = new Lang.Class({」。

可以從這裡開始探索。


例如,

您可以鍵盤按下「Alt+F2」,會跳出「Run Command」對話框,然後輸入「lg」,喚起「Looking Glass」,
然後在「Looking Glass / Evaluator」

可以輸入「Main.panel.」,然後按下「Tab」鍵,就會看到一些訊息。

或是可以輸入「imports.ui.main.panel.」,然後按下「Tab」鍵,就會看到一些訊息,跟「Main.panel.」是一樣的。


您可以測試「Main.panel.toggleCalendar()」或是「imports.ui.main.panel.toggleCalendar()」,
就會跳出日曆,這跟您按下「TopBar」中間那個按鈕是同樣的效果。



$ grep 'toggleCalendar' gnome-shell-3.26.1/js/ui/panel.js -n



顯示


985:    toggleCalendar: function() {




所以您就可以嘗試從「gnome-shell-3.26.1/js/ui/panel.js」,然後找右上角的那段機制。
不過我還沒研究,所以只能給您初步探索的方向。

================================================================================

接下來您的第二張圖,

只要執行


$ gnome-control-center privacy



就會出現「privacy」那個「panel」


您可以參考「如何找到「gnome-control-center」的「panel」指令」那篇提到的概念。


然後可以探索「gnome-control-center」的「Source Package: gnome-control-center」。

執行下面指令


$ apt-get source gnome-control-center




然後從「gnome-control-center-3.26.1/panels/privacy/cc-privacy-panel.c」開始探索起。

關鍵字「screen_lock_dialog」或是「lock」找尋

一樣,我這部份也尚未深究,所以也只能提供您初步探索的方向。

================================================================================

至於如何下載「Source Package」,請參考
執行「apt-get source some_package」的前置作業 (下載「Source Package」的前置作業)』這篇。

================================================================================

以上提供參考

報告完畢



================================================================================

[回到索引]

2017/11/4 4:27
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

# 如何透過「gsettings」設定顯示或隱藏「螢幕鎖定按鈕」

================================================================================


剛剛看「gnome-control-center」的原始碼,
在「gnome-control-center-3.26.1/panels/privacy/cc-privacy-panel.c」,
有找到一個關鍵字「org.gnome.desktop.lockdown」,


然後執行


$ gsettings list-recursively | grep org.gnome.desktop.lockdown



顯示


org.gnome.desktop.lockdown disable-command-line false
org.gnome.desktop.lockdown disable-application-handlers false
org.gnome.desktop.lockdown disable-user-switching false
org.gnome.desktop.lockdown user-administration-disabled false
org.gnome.desktop.lockdown disable-printing false
org.gnome.desktop.lockdown disable-log-out false
org.gnome.desktop.lockdown disable-lock-screen false
org.gnome.desktop.lockdown disable-print-setup false
org.gnome.desktop.lockdown disable-save-to-disk false



執行


$ gsettings list-keys org.gnome.desktop.lockdown



顯示


disable-command-line
disable-application-handlers
disable-user-switching
user-administration-disabled
disable-printing
disable-log-out
disable-lock-screen
disable-print-setup
disable-save-to-disk




然後我測試「org.gnome.desktop.lockdown disable-lock-screen」發現它是有作用的。

================================================================================

## get

執行


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



================================================================================

## set

執行


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



你提到的第一張圖,原本應該有三個按鈕,中間有一個按鈕消失了,
設定為「true」,就會變成您提供的第一張圖顯示的兩個按鈕。

================================================================================

## reset

執行


$ gsettings reset org.gnome.desktop.lockdown disable-lock-screen



執行上面指令,還原成預設值

然後執行下面指令,觀看目前的值


gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



================================================================================

或是您也可以直接執行下面的指令,直接設定為「false」



$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



這樣第一張圖,中間的按鈕就會跑出來了


================================================================================

以上提供參考,我還不是很了解整個機制,
也不曉得,您遇到這狀況,導致的關鍵因素是啥?
所以您需要在您的環境,再測試看看,看看剛剛提到的解法,是否在您的環境,能生效。


報告完畢



================================================================================

[回到索引]

2017/11/4 14:16
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員一級
註冊日期:
2011/8/30 13:53
所屬群組:
已註冊使用者
等級: 3
HP : 0 / 55
MP : 6 / 1892
EXP: 20
離線
根據以上方式,已經將問題排除。

我回想了一下,我認為比較可能是移除Phoronix Test Suite v7.4.0時引發的。移除此軟體時有錯誤出現,提示執行「dpkg --configue -a」來除錯,疑似是相依性有問題。

只是我也不確定這是否為關鍵因素,我再找時間使用虛擬機來試驗一次看看是否是這個動作引起的。

2017/11/4 21:14
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員一級
註冊日期:
2011/8/30 13:53
所屬群組:
已註冊使用者
等級: 3
HP : 0 / 55
MP : 6 / 1892
EXP: 20
離線
經過再次試驗,發現問題是由Phoronix Test Suite 7.4該軟體所引起,大概是安裝或執行時,某個環節去改動到螢幕鎖定的設定檔案。

只於是哪個細項去引發問題,小弟能力不足,不懂如何分析。

2017/11/4 22:43
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
吹風 寫到:
根據以上方式,已經將問題排除。

我回想了一下,我認為比較可能是移除Phoronix Test Suite v7.4.0時引發的。移除此軟體時有錯誤出現,提示執行「dpkg --configue -a」來除錯,疑似是相依性有問題。

只是我也不確定這是否為關鍵因素,我再找時間使用虛擬機來試驗一次看看是否是這個動作引起的。


收到。

別太在意,因為原本我怕在您的環境,有未知的因素,導致上面的方法,無法生效。

感謝您的回報,讓我了解上面的方法,在您的環境是有效的。

既然如此,未來若您遇到相同的狀況,您就知道怎麼去修復了。


吹風 寫到:
經過再次試驗,發現問題是由Phoronix Test Suite 7.4該軟體所引起,大概是安裝或執行時,某個環節去改動到螢幕鎖定的設定檔案。

只於是哪個細項去引發問題,小弟能力不足,不懂如何分析。


我目前想到的有兩個方向可以去找。

* 第一種是「MaintainerScripts」。
* 第二種是「glib schema override

================================================================================

若是第一種,

假設在「MaintainerScripts」,有可以能執行類似如下的指令,


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



舉例,那就可以使用「disable-lock-screen」當關鍵字,在「/var/lib/dpkg/info/」這個資料夾找尋。


$ grep disable-lock-screen /var/lib/dpkg/info/* -R -n



================================================================================

另外您提到的,您推測是「Phoronix Test Suite 7.4」這個套件引起的。

我有做了點測試,在我環境並沒有辦法重現您遇到的狀況。

以下是我的測試步驟。

================================================================================

執行


$ apt-cache search 'Phoronix Test Suite'



顯示


phoronix-test-suite - comprehensive testing and benchmarking platform



我是在新安裝的「Ubuntu 17.10」在「VirtualBox」上測試的。

================================================================================

一開始測試,我並沒有安裝這個套件。

我先執行下面指令,下載「phoronix-test-suite」這個套件。


$ apt-get download phoronix-test-suite



會下載一個檔案「phoronix-test-suite_5.2.1-1ubuntu2_all.deb」。

然後執行下面指令,解開「Control File」和「MaintainerScripts」。


$ dpkg -e phoronix-test-suite_5.2.1-1ubuntu2_all.deb



會解開到「DEBIAN」這個資料夾,

執行下面指令,觀看「DEBIAN」這個資料夾結構。


$ tree DEBIAN



顯示


DEBIAN/
├── conffiles
├── control
└── md5sums

0 directories, 3 files




只有看到「DEBIAN/control」,並沒有看到「MaintainerScripts」。

================================================================================

接著我執行下面指令,找尋那些套件,是需要「phoronix-test-suite」這個套件。


$ apt-cache rdepends phoronix-test-suite



顯示


phoronix-test-suite
Reverse Depends:
  ubuntu-benchmark-tools




所以我照剛剛的方式,來探索。

我先執行下面指令,下載「ubuntu-benchmark-tools」這個套件。


$ apt-get download ubuntu-benchmark-tools



會下載一個檔案「ubuntu-benchmark-tools_0.2_all.deb」。

然後執行下面指令,解開「Control File」和「MaintainerScripts」。


$ dpkg -e ubuntu-benchmark-tools_0.2_all.deb



會解開到「DEBIAN」這個資料夾,

執行下面指令,觀看「DEBIAN」這個資料夾結構。


$ tree DEBIAN



顯示


DEBIAN/
├── control
└── md5sums

0 directories, 2 files




只有看到「DEBIAN/control」,並沒有看到「MaintainerScripts」。

================================================================================

後來我有嘗試著去安裝「phoronix-test-suite」和「ubuntu-benchmark-tools」這兩個套件,


$ sudo apt-get install phoronix-test-suite ubuntu-benchmark-tools



然後再移除。


$ sudo apt-get purge phoronix-test-suite ubuntu-benchmark-tools



在我的環境,測試的過程並沒有什麼異狀,也無法重現您說的狀況「螢幕鎖定」按鈕消失。

可能我還少了什麼步驟,呵!只能隨緣了。

所以就沒再探究下去了。

================================================================================

接著下一篇,來討論第二個方向。

2017/11/6 19:04
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

# 關於「gsettings schema」

================================================================================

在說明「glib schema override」之前。

我先來補充,我所了解到的一些關於「gsettings」的機制

剛好用您的案例來舉例。

================================================================================

執行


$ grep 'disable-lock-screen' /usr/share/glib-2.0/schemas/* -R



顯示


Binary file /usr/share/glib-2.0/schemas/gschemas.compiled matches
/usr/share/glib-2.0/schemas/org.gnome.desktop.lockdown.gschema.xml: <key name="disable-lock-screen" type="b">



================================================================================

執行


$ grep 'disable-lock-screen' /usr/share/glib-2.0/schemas/org.gnome.desktop.lockdown.gschema.xml -A 6



顯示


<key name="disable-lock-screen" type="b">
  <default>false</default>
  <summary>Disable lock screen</summary>
  <description>
	Prevent the user to lock his screen.
  </description>
</key>




================================================================================

然後關於「/usr/share/glib-2.0/schemas/gschemas.compiled」這個檔案

是透過「glib-compile-schemas」這個指令指令產生的。

先執行


$ stat /usr/share/glib-2.0/schemas/gschemas.compiled



顯示


File: /usr/share/glib-2.0/schemas/gschemas.compiled
Size: 227030    	Blocks: 448        IO Block: 4096   regular file
Device: 803h/2051d	Inode: 4982468     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-05 15:09:18.725119070 +0800
Modify: 2017-11-05 15:08:41.130911832 +0800
Change: 2017-11-05 15:08:41.174909677 +0800
Birth: -




執行下面的指令


$ sudo glib-compile-schemas /usr/share/glib-2.0/schemas/



接著再執行一次下面的指令


$ stat /usr/share/glib-2.0/schemas/gschemas.compiled



顯示


File: /usr/share/glib-2.0/schemas/gschemas.compiled
Size: 227030    	Blocks: 448        IO Block: 4096   regular file
Device: 803h/2051d	Inode: 4982467     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-05 16:46:08.669166025 +0800
Modify: 2017-11-05 16:46:08.669166025 +0800
Change: 2017-11-05 16:46:08.705163197 +0800
Birth: -




可以看到時間戳記變了。

================================================================================

以下是我作實驗後,所得到的歸納

* 「gsettings」獲得「預設值」的地方,是來自於「/usr/share/glib-2.0/schemas/gschemas.compiled」這個檔案。
* 「gsettings」的「設定值」,則是會紀錄在「dconf」,也就是來自於「~/.config/dconf/user」這個檔案。
* 「gsettings」若執行「reset」這個動作,則是會把「dconf」這邊的紀錄刪除。

一些概念,之前有紀錄在「另一篇」。

================================================================================

以下是實驗的參考步驟

================================================================================

## 執行「reset」,先還原成「預設值」

執行


$ gsettings reset org.gnome.desktop.lockdown disable-lock-screen



執行上面指令,將目前的「設定值」還原成「預設值」。

然後執行下面指令,觀看目前的「設定值」。


gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



顯示「org.gnome.desktop.lockdown disable-lock-screen」目前的「設定值」是「false」,
因為我們先作「reset」的動作,所以表示「預設值」是「false」。

================================================================================

## 設定值

執行


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



執行上面指令,將「設定值」設為「true」。

然後執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


true



顯示「org.gnome.desktop.lockdown disable-lock-screen」」目前的「設定值」是「true」。

================================================================================

執行


$ grep 'disable-lock-screen' /usr/share/glib-2.0/schemas/org.gnome.desktop.lockdown.gschema.xml -A 6



顯示



<key name="disable-lock-screen" type="b">
  <default>false</default>
  <summary>Disable lock screen</summary>
  <description>
	Prevent the user to lock his screen.
  </description>
</key>




還是看到「<default>false</default>」。
推測「/usr/share/glib-2.0/schemas/org.gnome.desktop.lockdown.gschema.xml」這個檔案並不會被修改。

================================================================================

接下來觀看「dconf」那邊的紀錄。

## 先找到「path」

執行


$ grep path /usr/share/glib-2.0/schemas/org.gnome.desktop.lockdown.gschema.xml -n



顯示


2:  <schema id="org.gnome.desktop.lockdown" path="/org/gnome/desktop/lockdown/">




可以找到「path="/org/gnome/desktop/lockdown/"」,
也就是找到「/org/gnome/desktop/lockdown/」。

================================================================================

將剛剛找到的「/org/gnome/desktop/lockdown/」加上「disable-lock-screen」,
就變成「/org/gnome/desktop/lockdown/disable-lock-screen」。

執行


$ dconf read /org/gnome/desktop/lockdown/disable-lock-screen



顯示


true



表示「disable-lock-screen」有紀錄在「dconf」這邊。

================================================================================

執行


$ grep 'disable-lock-screen' ~/.config/dconf/user





Binary file /home/user/.config/dconf/user matches



表示「disable-lock-screen」有紀錄在「~/.config/dconf/user」這個檔案。

註: 「dconf」的紀錄,是來自「~/.config/dconf/user」這個檔案。

================================================================================

## 設定跟「預設值」相同

執行


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



執行上面指令,將「設定值」設為「false」。

然後執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



顯示「org.gnome.desktop.lockdown disable-lock-screen」」目前的「設定值」是「false」。
與原本的「預設值」「false」相同。

================================================================================

接著執行

執行


$ dconf read /org/gnome/desktop/lockdown/disable-lock-screen



顯示


false



表示「disable-lock-screen」還是有紀錄在「dconf」這邊。

================================================================================

執行


$ grep 'disable-lock-screen' ~/.config/dconf/user



顯示


Binary file /home/user/.config/dconf/user matches



表示「disable-lock-screen」還是有紀錄在「~/.config/dconf/user」這個檔案。

註: 「dconf」的紀錄,是來自「~/.config/dconf/user」這個檔案。

================================================================================

## 執行「reset」,再次還原成「預設值」

執行


$ gsettings reset org.gnome.desktop.lockdown disable-lock-screen



執行上面指令,還原成「預設值」。

然後執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



顯示「org.gnome.desktop.lockdown disable-lock-screen」」目前的「設定值」是「false」。
因為我們先作「reset」的動作,所以表示「預設值」是「false」。

================================================================================

接著執行

執行


$ dconf read /org/gnome/desktop/lockdown/disable-lock-screen



沒有顯示任何結果,直接出現下一個提示字元。

表示「disable-lock-screen」在「dconf」這邊的紀錄被刪除了。

================================================================================

執行


$ grep 'disable-lock-screen' ~/.config/dconf/user



沒有顯示任何結果,直接出現下一個提示字元。

表示「disable-lock-screen」沒有紀錄在「~/.config/dconf/user」這個檔案。

註: 「dconf」的紀錄,是來自「~/.config/dconf/user」這個檔案。

================================================================================

關於這些,在以前的一篇討論回覆「#8 回覆: 如何移除碰觸邊界視窗自動放大功能」,我有列一些參考連結。
關於「gsettings」和「dconf」的一些討論案例,我則是紀錄在「[索引] 泛Ubuntu 安裝調校」。

================================================================================

接下來介紹「schema override」的功能。

================================================================================

[回到索引]

2017/11/6 19:13
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

# 關於「gsettings schema override」

================================================================================

剛剛介紹完了「schema」,接下來介紹「override」。

================================================================================

* https://developer.gnome.org/gio/stable/glib-compile-schemas.html
* $ man glib-compile-schemas

================================================================================

先來做個小實驗

================================================================================

## 執行「reset」,先還原成「預設值」

執行


$ gsettings reset org.gnome.desktop.lockdown disable-lock-screen



執行上面指令,將目前的「設定值」還原成「預設值」。

然後執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



顯示「org.gnome.desktop.lockdown disable-lock-screen」目前的「設定值」是「false」,
因為我們先作「reset」的動作,所以表示「預設值」是「false」。

================================================================================

執行下面指令,產生「/usr/share/glib-2.0/schemas/90_test.gschema.override」這個檔案



cat > 90_test.gschema.override <<EOF
[org.gnome.desktop.lockdown]
disable-lock-screen=true

EOF

sudo cp 90_test.gschema.override /usr/share/glib-2.0/schemas/90_test.gschema.override




執行下面指令,觀看「/usr/share/glib-2.0/schemas/90_test.gschema.override」這個檔案的內容


$ cat /usr/share/glib-2.0/schemas/90_test.gschema.override



顯示「/usr/share/glib-2.0/schemas/90_test.gschema.override」這個檔案的內容


[org.gnome.desktop.lockdown]
disable-lock-screen=true




還記得上一篇,有提到一個指令「gsettings set org.gnome.desktop.lockdown disable-lock-screen true」
將「org.gnome.desktop.lockdown」變成「[org.gnome.desktop.lockdown]」。
將「disable-lock-screen true」變成「disable-lock-screen=true」。
就會變成上面那個檔案的內容。

================================================================================

然後執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


false



顯示「org.gnome.desktop.lockdown disable-lock-screen」目前的「設定值」一樣是「false」。

================================================================================

接著執行下面的指令,重新產生「/usr/share/glib-2.0/schemas/gschemas.compiled」這個檔案。


$ sudo glib-compile-schemas /usr/share/glib-2.0/schemas



這時候再次執行下面指令,觀看目前的「設定值」。


$ gsettings get org.gnome.desktop.lockdown disable-lock-screen



顯示


true



顯示「org.gnome.desktop.lockdown disable-lock-screen」目前的「設定值」一樣是「true」。

雖然目前的設定值是「true」。

不過「螢幕鎖定」的那個按鈕並沒有跟著消失。

這時候只要「重新登出」再「登入系統」,這樣就會「螢幕鎖定」的那個按鈕就會消失了。

================================================================================

重新登入後,

一樣可以透過下面的指令,將消失的「螢幕鎖定」的那個按鈕,再次顯示出來(無須登出登入)


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



一樣可以透過下面的指令,將「螢幕鎖定」的那個按鈕,再次隱藏(無須登出登入)


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



================================================================================

以上功能介紹完畢。

================================================================================

額外一提的,在「Ubuntu」的「Live系統」,就是透過「override」這樣的設定,
也就是在「Ubuntu」的「Live系統」,預設並沒有顯示「螢幕鎖定」的那個按鈕。

您可以在「Ubuntu」的「Live系統」,開啟「Terminal」,執行下面的指令


$ grep lock /usr/share/glib-2.0/schemas/*.override



顯示


/usr/share/glib-2.0/schemas/casper.gschema.override:[org.gnome.desktop.lockdown]
/usr/share/glib-2.0/schemas/casper.gschema.override:disable-lock-screen=true
/usr/share/glib-2.0/schemas/casper.gschema.override:lock-enabled=false



執行下面指令,觀看「/usr/share/glib-2.0/schemas/casper.gschema.override」這個檔案的內容。


$ cat /usr/share/glib-2.0/schemas/casper.gschema.override




[org.gnome.desktop.lockdown]
disable-lock-screen=true
[org.gnome.desktop.screensaver]
lock-enabled=false




================================================================================

下面則是在我原本安裝在硬碟裡的系統,做的額外探索。

================================================================================

執行


$ ls /usr/share/glib-2.0/schemas/*.override -1



顯示


/usr/share/glib-2.0/schemas/10_gnome-software.gschema.override
/usr/share/glib-2.0/schemas/10_gsettings-desktop-schemas.gschema.override
/usr/share/glib-2.0/schemas/10_ibus.gschema.override
/usr/share/glib-2.0/schemas/10_ubuntu-dock.gschema.override
/usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override
/usr/share/glib-2.0/schemas/90_test.gschema.override



以「/usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override」這個檔案為例

執行下面指令,就可以了解「/usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override」這個檔案,是來自哪個套件。


$ dpkg -S /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override



顯示


ubuntu-settings: /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override



表示「/usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override」這個檔案,是來自「ubuntu-settings」這個套件。

而「dpkg -S 」這個指令,也可以對某個資料夾下,例如「dpkg -S /usr/share/glib-2.0/schemas/」,就會找到很多套件名稱。
也可以找尋關鍵字,不需要特定的檔案或是特定的資料夾。

所以也可以如此的下


$ dpkg -S $(ls /usr/share/glib-2.0/schemas/*.override -1)



顯示


gnome-software: /usr/share/glib-2.0/schemas/10_gnome-software.gschema.override
gsettings-desktop-schemas: /usr/share/glib-2.0/schemas/10_gsettings-desktop-schemas.gschema.override
ibus: /usr/share/glib-2.0/schemas/10_ibus.gschema.override
gnome-shell-extension-ubuntu-dock: /usr/share/glib-2.0/schemas/10_ubuntu-dock.gschema.override
ubuntu-settings: /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override
dpkg-query: no path found matching pattern /usr/share/glib-2.0/schemas/90_test.gschema.override



從剛剛找到的「ubuntu-settings」,執行下面指令


$ dpkg -L ubuntu-settings



就可以了解到「ubuntu-settings」這個套件,安裝哪些檔案在系統上。

更多套件探索的技巧,請參考「[索引] 套件操作實務」,那裡我有紀錄討論案例和參考連結。

================================================================================

或是也可以執行,找到尚未安裝在系統上的套件。


$ apt-file search gschema.override



顯示


budgie-appmenu-applet: /usr/share/glib-2.0/schemas/10_budgie_appmenu_applet.gschema.override
budgie-desktop: /usr/share/glib-2.0/schemas/15_budgie-desktop.gschema.override
budgie-desktop-common: /usr/share/glib-2.0/schemas/15_budgie-desktop-common.gschema.override
budgie-desktop-environment: /usr/share/glib-2.0/schemas/15_budgie-desktop-environment.gschema.override
budgie-lightdm-theme: /usr/share/glib-2.0/schemas/10_budgie-lightdm-theme.gschema.override
cinnamon: /usr/share/glib-2.0/schemas/10_cinnamon.gschema.override
cinnamon-core: /usr/share/glib-2.0/schemas/10_cinnamon-core.gschema.override
cinnamon-settings-daemon: /usr/share/glib-2.0/schemas/10_cinnamon-settings-daemon.gschema.override
compiz-gnome: /usr/share/glib-2.0/schemas/10_compiz-gnome.gschema.override
desktop-base: /usr/share/glib-2.0/schemas/10_desktop-base.gschema.override
edubuntu-artwork: /usr/share/glib-2.0/schemas/95_edubuntu-artwork.gschema.override
evolution-common: /usr/share/glib-2.0/schemas/10_evolution-common.gschema.override
gnome-flashback-common: /usr/share/glib-2.0/schemas/10_gnome-flashback-common.gschema.override
gnome-games-app: /usr/share/glib-2.0/schemas/10_gnome-games-app.gschema.override
gnome-shell-extension-ubuntu-dock: /usr/share/glib-2.0/schemas/10_ubuntu-dock.gschema.override
gnome-software: /usr/share/glib-2.0/schemas/10_gnome-software.gschema.override
gnome-system-log: /usr/share/glib-2.0/schemas/10_gnome-system-log.gschema.override
gsettings-desktop-schemas: /usr/share/glib-2.0/schemas/10_gsettings-desktop-schemas.gschema.override
ibus: /usr/share/glib-2.0/schemas/10_ibus.gschema.override
libcinnamon-desktop4: /usr/share/glib-2.0/schemas/10_libcinnamon-desktop4.gschema.override
libgtk-4-common: /usr/share/glib-2.0/schemas/10_libgtk-4-common.gschema.override
mate-applet-appmenu: /usr/share/glib-2.0/schemas/10_mate_applet_appmenu.gschema.override
mate-desktop-environment-core: /usr/share/glib-2.0/schemas/mate-ubuntu.gschema.override
onboard-common: /usr/share/doc/onboard/onboard-default-settings.gschema.override.example
ubuntu-business-defaults: /usr/share/glib-2.0/schemas/ubuntu-business-defaults.gschema.override
ubuntu-defaults-nl-nl: /usr/share/glib-2.0/schemas/ubuntu-defaults-nl-nl.gschema.override
ubuntu-defaults-zh-cn: /usr/share/glib-2.0/schemas/ubuntu-defaults-zh-cn.gschema.override
ubuntu-mate-default-settings: /usr/share/glib-2.0/schemas/ubuntu-mate.gschema.override
ubuntu-mate-live-settings: /usr/share/glib-2.0/schemas/zubuntu-mate-live.gschema.override
ubuntu-settings: /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override
ubuntu-touch-settings: /usr/share/glib-2.0/schemas/10_ubuntu-touch-settings.gschema.override
ubuntukylin-default-settings: /usr/share/glib-2.0/schemas/20_ubuntukylin-default-settings.gschema.override
ubuntukylin-theme: /usr/share/glib-2.0/schemas/25_ubuntukylin-theme.gschema.override
ubuntukylin-wallpapers: /usr/share/glib-2.0/schemas/30_ubuntukylin-wallpapers.gschema.override
ubuntustudio-default-settings: /usr/share/glib-2.0/schemas/20_ubuntustudio-default-settings.gschema.override
ukui-desktop-environment-core: /usr/share/glib-2.0/schemas/ukui-ubuntu.gschema.override
unity-scope-diodon: /usr/share/glib-2.0/schemas/10_unity-scope-diodon.gschema.override
vanilla-gnome-default-settings: /usr/share/glib-2.0/schemas/20_vanilla-gnome-default-settings.gschema.override
virt-manager: /usr/share/glib-2.0/schemas/10_virt-manager.gschema.override
xchat-gnome: /usr/share/glib-2.0/schemas/10_xchat-gnome.gschema.override
xubuntu-default-settings: /usr/share/glib-2.0/schemas/20_xubuntu-default-settings.gschema.override



================================================================================

接下來,介紹安裝這些套件的過程中,關於「/usr/share/glib-2.0/schemas/gschemas.compiled」這個檔案,自動重新產生的機制。

================================================================================

[回到索引]

2017/11/6 19:18
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

# 關於「compile schemas triggger」

================================================================================

延續上一篇最後面提到的,

要來了解,安裝這些套件的過程中,關於「/usr/share/glib-2.0/schemas/gschemas.compiled」這個檔案,自動重新產生的機制。

以下是簡易的探索紀錄。

================================================================================

## 探索開始

使用「/usr/share/glib-2.0/schemas」和「triggers」當關鍵字來找尋「/var/lib/dpkg/info/」這個資料夾,執行下面指令


$ grep '/usr/share/glib-2.0/schemas' /var/lib/dpkg/info/* | grep triggers



顯示


/var/lib/dpkg/info/libglib2.0-0:amd64.triggers:interest /usr/share/glib-2.0/schemas




================================================================================

執行下面指令,觀看「/var/lib/dpkg/info/libglib2.0-0:amd64.triggers」的內容


$ cat /var/lib/dpkg/info/libglib2.0-0:amd64.triggers



顯示


interest /usr/lib/x86_64-linux-gnu/gio/modules
interest /usr/lib/gio/modules
interest /usr/share/glib-2.0/schemas
# Triggers added by dh_makeshlibs/10.7.2ubuntu2
activate-noawait ldconfig




================================================================================

## libglib2.0-0


$ dpkg-query --control-path libglib2.0-0



顯示


/var/lib/dpkg/info/libglib2.0-0:amd64.symbols
/var/lib/dpkg/info/libglib2.0-0:amd64.postrm
/var/lib/dpkg/info/libglib2.0-0:amd64.shlibs
/var/lib/dpkg/info/libglib2.0-0:amd64.postinst
/var/lib/dpkg/info/libglib2.0-0:amd64.triggers
/var/lib/dpkg/info/libglib2.0-0:amd64.md5sums



================================================================================

可以執行下面指令,觀看「/var/lib/dpkg/info/libglib2.0-0:amd64.postinst」這個檔案內容


$ cat /var/lib/dpkg/info/libglib2.0-0:amd64.postinst




使用「'glib-compile-schemas'」當關鍵字,查詢「/var/lib/dpkg/info/libglib2.0-0:amd64.postinst」這個檔案


$ grep 'glib-compile-schemas' /var/lib/dpkg/info/libglib2.0-0:amd64.postinst -n



顯示


13:            /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas /usr/share/glib-2.0/schemas || true
39:    /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas /usr/share/glib-2.0/schemas || true




================================================================================

可以執行下面指令,觀看「/var/lib/dpkg/info/libglib2.0-0:amd64.postrm」這個檔案內容


$ cat /var/lib/dpkg/info/libglib2.0-0:amd64.postrm



================================================================================

主要要研究的是下面三個檔案

* /var/lib/dpkg/info/libglib2.0-0:amd64.triggers
* /var/lib/dpkg/info/libglib2.0-0:amd64.postinst
* /var/lib/dpkg/info/libglib2.0-0:amd64.postrm


關於這部份的機制,我有做了兩個簡易專案,放在「GitHub」上,可以用來產生「deb檔」,來測試這樣的流程。

可以參考其中一個專案「ex-demo-schema」這裡面的說明,裡面就有提到「實驗的步驟」和「相關的概念」。

* $ man deb-triggers
* $ less /usr/share/doc/dpkg-dev/triggers.txt.gz
* $ man dpkg-trigger
* https://wiki.debian.org/DpkgTriggers
* https://wiki.debian.org/MaintainerScripts
* https://www.debian.org/doc/manuals/maint-guide/dother.en.html#maintscripts

================================================================================

一開始探索的時候,也可以使用「/usr/share/glib-2.0/schemas/gschemas.compiled」當關鍵字來找尋「/var/lib/dpkg/info/」這個資料夾,可以找到初步的線索


$ grep '/usr/share/glib-2.0/schemas/gschemas.compiled' /var/lib/dpkg/info/* -R



顯示


/var/lib/dpkg/info/libglib2.0-0:amd64.postrm: rm -f /usr/share/glib-2.0/schemas/gschemas.compiled



================================================================================

也可以使用「glib-compile-schemas」當關鍵字來找尋「/var/lib/dpkg/info/」這個資料夾,也可以找到初步的線索


$ grep 'glib-compile-schemas' /var/lib/dpkg/info/* -R



顯示


/var/lib/dpkg/info/libglib2.0-0:amd64.list:/usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas
/var/lib/dpkg/info/libglib2.0-0:amd64.md5sums:d9a0ecdc65f5327e00bfac10e7b601b7 usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas
/var/lib/dpkg/info/libglib2.0-0:amd64.postinst: /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas /usr/share/glib-2.0/schemas || true
/var/lib/dpkg/info/libglib2.0-0:amd64.postinst: /usr/lib/x86_64-linux-gnu/glib-2.0/glib-compile-schemas /usr/share/glib-2.0/schemas || true
/var/lib/dpkg/info/libglib2.0-bin.list:/usr/share/man/man1/glib-compile-schemas.1.gz
/var/lib/dpkg/info/libglib2.0-bin.list:/usr/bin/glib-compile-schemas
/var/lib/dpkg/info/libglib2.0-bin.md5sums:ac7a0d4f3e82b47166813d4b659efbf6 usr/share/man/man1/glib-compile-schemas.1.gz
/var/lib/dpkg/info/libglib2.0-doc.list:/usr/share/doc/libglib2.0-doc/gio/glib-compile-schemas.html
/var/lib/dpkg/info/libglib2.0-doc.md5sums:9003f7b8a3582e8d92eb5c2147e4c2fc usr/share/doc/libglib2.0-doc/gio/glib-compile-schemas.html



================================================================================

以上補充說明

報告完畢



================================================================================

[回到索引]

2017/11/6 19:25
應用擴展 工具箱
回覆: Ubuntu Linux 17.10 螢幕鎖定失效
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 901
MP : 671 / 29288
EXP: 6
離線
[回到索引]

================================================================================

# 探索「螢幕鎖定按鈕」顯示或隱藏的實作原始碼

================================================================================

今天研究了「gnome-shell」的原始碼,了解了「螢幕鎖定」那個按鈕,「顯示與隱藏」的那段機制,

以下簡易紀錄,提供對這方面想深入探究的人,可以有個探索的起點。

================================================================================

先執行下面指令,下載「gnome-shell」的「Source Package: gnome-shell」。


$ apt-get source gnome-shell



要執行上面指令的前置作業,請參考之前寫的一篇「#24 回覆: Ubuntu 17.10 推出

================================================================================

執行下面指令,使用「disable-lock-screen」當關鍵字,在「gnome-shell-3.26.1」這個資料夾找尋。


$ grep 'disable-lock-screen' gnome-shell-3.26.1/* -R -n



顯示


gnome-shell-3.26.1/debian/patches/ubuntu_lock_on_suspend.patch:19: const DISABLE_LOCK_KEY = 'disable-lock-screen';
gnome-shell-3.26.1/js/misc/systemActions.js:17:const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
gnome-shell-3.26.1/js/ui/screenShield.js:38:const DISABLE_LOCK_KEY = 'disable-lock-screen';




可以從「gnome-shell-3.26.1/js/misc/systemActions.js」這個檔案開始研究起。


================================================================================

執行下面指令,使用「DISABLE_LOCK_SCREEN_KEY」當關鍵字,在「gnome-shell-3.26.1/js/misc/systemActions.js」這個檔案找尋。


$ grep 'DISABLE_LOCK_SCREEN_KEY' gnome-shell-3.26.1/js/misc/systemActions.js -R -n



顯示


17:const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
166:        this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
330:        let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);





================================================================================

執行下面指令,使用「imports.misc.systemActions」當關鍵字,在「gnome-shell-3.26.1」這個資料夾找尋。


$ grep 'imports.misc.systemActions' gnome-shell-3.26.1/* -R -n



顯示


gnome-shell-3.26.1/js/ui/status/system.js:13:const SystemActions = imports.misc.systemActions;
gnome-shell-3.26.1/js/ui/appDisplay.js:31:const SystemActions = imports.misc.systemActions;




就可以找到「gnome-shell-3.26.1/js/ui/status/system.js」這個檔案。

================================================================================

以下主要是研究這兩個檔案的心得。

* gnome-shell-3.26.1/js/misc/systemActions.js
* gnome-shell-3.26.1/js/ui/status/system.js

一些基本的概念,請參考「#22 回覆: Ubuntu 17.10 推出」,裡面『## 關於「gnome-shell-extension』列的那幾篇,尤其「#31」和「#32」。

================================================================================

## SystemActions Singleton


$ grep 'SystemActions' gnome-shell-3.26.1/* -R -n



顯示


gnome-shell-3.26.1/debian/patches/ubuntu-lightdm-user-switching.patch:17:@@ -218,6 +218,21 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/ubuntu-lightdm-user-switching.patch:39:@@ -313,7 +328,7 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/ubuntu-lightdm-user-switching.patch:48:@@ -400,20 +415,24 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/optional-libgdm.patch:36:@@ -137,7 +141,8 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/optional-libgdm.patch:46:@@ -345,7 +350,7 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/optional-libgdm.patch:55:@@ -363,7 +368,7 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/optional-libgdm.patch:64:@@ -393,7 +398,7 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/debian/patches/optional-libgdm.patch:73:@@ -428,7 +433,8 @@ const SystemActions = new Lang.Class({
gnome-shell-3.26.1/js/misc/systemActions.js:44:        _singleton = new SystemActions();
gnome-shell-3.26.1/js/misc/systemActions.js:49:const SystemActions = new Lang.Class({
gnome-shell-3.26.1/js/misc/systemActions.js:50:    Name: 'SystemActions',
gnome-shell-3.26.1/js/ui/status/system.js:13:const SystemActions = imports.misc.systemActions;
gnome-shell-3.26.1/js/ui/status/system.js:124:        this._systemActions = new SystemActions.getDefault();
gnome-shell-3.26.1/js/ui/appDisplay.js:31:const SystemActions = imports.misc.systemActions;
gnome-shell-3.26.1/js/ui/appDisplay.js:1092:        this._systemActions = new SystemActions.getDefault();
gnome-shell-3.26.1/js/ui/appDisplay.js:2016:        SystemActions.getDefault().activateAction(this.metaInfo['id']);




在「gnome-shell-3.26.1/js/misc/systemActions.js」有實做一個「singleton」。


執行


$ grep '_singleton = new SystemActions();' gnome-shell-3.26.1/js/misc/systemActions.js -A 4 -B 3



顯示


function getDefault() {
    if (_singleton == null)
        _singleton = new SystemActions();

    return _singleton;
}




================================================================================

## Play on LookingGlass

所以我們就可以在「Looking Glass / Evaluator」,來作點測試了。


## 測試一

輸入「imports.misc.systemActions.」,然後連續按兩下「Tab」,就會出現一些訊息,其中就有「getDefault」。


## 測試二

先輸入「imports.misc.systemActions.getDefault()」,

會顯示「r(0) = [object instance proxy Gtype:Gjs_SystemActions jsobj@0x7f3f8bdBe780 native@0x56408d71a600]」。

可以按下「[object instance proxy Gtype:Gjs_SystemActions jsobj@0x7f3f8bdBe780 native@0x56408d71a600]」,就會跳出另一個對話框。


## 測試三

輸入「imports.misc.systemActions.getDefault().」,然後連續按兩下「Tab」,就會出現一些訊息。


## 測試四

輸入「imports.misc.systemActions.getDefault().activate」,然後連續按兩下「Tab」,就會出現一些訊息。

會顯示「activateAction, activateLockOrientation, activateLockScreen, activateLogout, activatePowerOff, activateSuspend, activateSwitchUser」


## 測試五

所以就可以輸入下面幾個指令來測試

* 「imports.misc.systemActions.getDefault().activateAction('lock-screen')」
* 「imports.misc.systemActions.getDefault().activateLockOrientation()」
* 「imports.misc.systemActions.getDefault().activateLockScreen()」
* 「imports.misc.systemActions.getDefault().activateLogout()」
* 「imports.misc.systemActions.getDefault().activatePowerOff()」
* 「imports.misc.systemActions.getDefault().activateSuspend()」
* 「imports.misc.systemActions.getDefault().activateSwitchUser()」

不過我只有測過下面兩個

* 「imports.misc.systemActions.getDefault().activateAction('lock-screen')」
* 「imports.misc.systemActions.getDefault().activateLockScreen()」

測試這兩個指令前,記得先在「Terminal」執行下面指令,確保「功能是打開的」。


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false




## 測試六

輸入「imports.misc.systemActions.getDefault().can_」,然後連續按兩下「Tab」,就會出現一些訊息。

會顯示「can_lock_orientation, can_lock_screen, can_logout, can_power_off, can_suspend, can_switch_user」。

所以就可以輸入「imports.misc.systemActions.getDefault().can_lock_screen」會顯示「r(6) = true」。

其他的以此類推

* 「imports.misc.systemActions.getDefault().can_lock_orientation」
* 「imports.misc.systemActions.getDefault().can_lock_screen」
* 「imports.misc.systemActions.getDefault().can_logout」
* 「imports.misc.systemActions.getDefault().can_power_off」
* 「imports.misc.systemActions.getDefault().can_suspend」
* 「imports.misc.systemActions.getDefault().can_switch_user」


## 測試七

先在「Terminal」執行下面指令


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



然後再到「Looking Glass / Evaluator」輸入


imports.misc.systemActions.getDefault().can_lock_screen



這時候顯示的就會變成「「r(7) = false」」


## 測試八

先在「Terminal」執行下面指令


$ grep 'const POWER_OFF_ACTION_ID' gnome-shell-3.26.1/js/misc/systemActions.js -A 6 -B 1



顯示



const POWER_OFF_ACTION_ID        = 'power-off';
const LOCK_SCREEN_ACTION_ID      = 'lock-screen';
const LOGOUT_ACTION_ID           = 'logout';
const SUSPEND_ACTION_ID          = 'suspend';
const SWITCH_USER_ACTION_ID      = 'switch-user';
const LOCK_ORIENTATION_ACTION_ID = 'lock-orientation';





然後再到「Looking Glass / Evaluator」輸入下面指令

* 「imports.misc.systemActions.getDefault().getIconName('power-off')」
* 「imports.misc.systemActions.getDefault().getIconName('lock-screen')」
* 「imports.misc.systemActions.getDefault().getIconName('logout')」
* 「imports.misc.systemActions.getDefault().getIconName('suspend')」
* 「imports.misc.systemActions.getDefault().getIconName('switch-user')」
* 「imports.misc.systemActions.getDefault().getIconName('lock-orientation')」

分別會得到

* 「r(11) = system-shutdown-symbolic」
* 「r(12) = system-lock-screen-symbolic」
* 「r(13) = application-exit-symbolic」
* 「r(14) = media-playback-pause-symbolic」
* 「r(15) = system-switch-user-symbolic」
* 「r(16) = rotation-allowed-symbolic」

另外還有「getName」也是同樣模式,可以輸入下面指令

* 「imports.misc.systemActions.getDefault().getName('power-off')」
* 「imports.misc.systemActions.getDefault().getName('lock-screen')」
* 「imports.misc.systemActions.getDefault().getName('logout')」
* 「imports.misc.systemActions.getDefault().getName('suspend')」
* 「imports.misc.systemActions.getDefault().getName('switch-user')」
* 「imports.misc.systemActions.getDefault().getName('lock-orientation')」

分別會得到

* 「r(21) = Power off」
* 「r(22) = Lock screen」
* 「r(23) = Log out」
* 「r(24) = Suspend」
* 「r(25) = Switch user」
* 「r(26) = Lock orientation」

================================================================================

接下來我寫了兩個範例程式,

也許可以幫助理解「gnome-shell-3.26.1/js/misc/systemActions.js」這個檔案的實作機制。

還有我們一直在探討的「螢幕鎖定」那個按鈕,如何切換「顯示」和「隱藏」實作的機制。

================================================================================

## gsettings monitor

在提第一個範例之前,先來做個小實驗

先在「Terminal A」,執行下面指令,


$ gsettings monitor org.gnome.desktop.lockdown disable-lock-screen



然後另外開啟一個「Terminal B」,執行下面指令,


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



可以看到「Terminal A」,會出現下面的訊息。


disable-lock-screen: true



然後在「Terminal B」,執行下面指令,


$ gsettings reset org.gnome.desktop.lockdown disable-lock-screen



可以看到「Terminal A」,會出現下面的訊息。


disable-lock-screen: false




================================================================================


## 範例一

先產生一個檔案,檔案名稱是「on_change.js」,然後填入下面的內容。


#!/usr/bin/env gjs

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;

//http://rocksaying.tw/archives/15700221.html
const Mainloop = imports.mainloop;


const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';


var app = {
    available: false,

    _init: function() {
        this._lockdownSettings = new Gio.Settings({schema_id: LOCKDOWN_SCHEMA});

        this._lockdownSettings.connect(
            'changed::' + DISABLE_LOCK_SCREEN_KEY,
            () => { this._updateLockScreen(); }
        );
    },

    _updateLockScreen: function() {
        let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
        this.available = allowLockScreen;
        print('Button available: ' , this.available);
    },


    run: function() {
        this._init();
    }

}

app.run();
Mainloop.run(null);




接著執行下面指令,將「on_change.js」設為可執行。


$ chmod u+x on_change.js



然後執行下面指令


$ ./on_change.js



接著開起另一個「Terminal」,姑且稱它「Terminal B」,剛剛的則是「Terminal A」。


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



然後在「Terminal A」,就會多出一個訊息如下


Button available: false



接著在「Terminal A」,執行下面的指令


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



然後在「Terminal A」,就會多出一個訊息如下


Button available: true




================================================================================

## 範例二

先產生一個檔案,檔案名稱是「demo_button.js」,然後填入下面的內容。


#!/usr/bin/env gjs

const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;

const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';

const LOCK_SCREEN_ACTION_ID = 'lock-screen';

const SystemActions = new Lang.Class({
	Name: 'SystemActions',
	Extends: GObject.Object,
	Properties: {
		'can-lock-screen': GObject.ParamSpec.boolean(
			'can-lock-screen',
			'can-lock-screen',
			'can-lock-screen',
			GObject.ParamFlags.READABLE,
			false
		)
	},

	_init: function() {
		this.parent();

		this._actions = new Map();
		this._actions.set(
			LOCK_SCREEN_ACTION_ID,
			{
				name: 'Lock screen',
				iconName: 'system-lock-screen-symbolic',
				keywords: 'lock screen',
				available: false
			}
		);

		this._lockdownSettings = new Gio.Settings({schema_id: LOCKDOWN_SCHEMA});

		this._lockdownSettings.connect(
			'changed::' + DISABLE_LOCK_SCREEN_KEY,
			() => { this._updateLockScreen(); }
		);

	},

	get can_lock_screen() {
		return this._actions.get(LOCK_SCREEN_ACTION_ID).available;
	},

	update: function() {
		this._updateLockScreen();
	},

	_updateLockScreen: function() {
		let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
		this._actions.get(LOCK_SCREEN_ACTION_ID).available = allowLockScreen;
		this.notify('can-lock-screen');
	},

	activateAction: function(id) {
		switch (id) {
			case LOCK_SCREEN_ACTION_ID:
				this.activateLockScreen();
				break;
		}
	},

	activateLockScreen: function() {
		print('activateLockScreen');
		this._doLockScreen();
	},

	_doLockScreen: function() {
		//https://wiki.archlinux.org/index.php/Desktop_notifications
		const Notify = imports.gi.Notify;
		Notify.init('LockScreen');
		var tips = new Notify.Notification ({
		summary: 'Do LockScreen!',
			body: 'Just kidding!',
			'icon-name': 'dialog-information'
		});
		tips.show();
	}

});


var Win = new Lang.Class({
	Name: 'Win',
	_init: function(args) {
		this.win = new Gtk.Window({
			title: 'Demo bind_property',
			default_width: 100,
			default_height: 100,
			type: Gtk.WindowType.TOPLEVEL
		});

		this.win.connect('delete-event', Gtk.main_quit);


		//http://devdocs.baznga.org/gtk30~3.22.12/gtk.button
		//https://people.gnome.org/~gcampagna/docs/Gtk-3.0/Gtk.Button.html
		//this.btnLockScreen = new Gtk.Button({label: 'LockScreen'});
		//this.btnLockScreen = Gtk.Button.new_with_label('LockScreen');
		//this.btnLockScreen = Gtk.Button.new_from_icon_name('changes-prevent-symbolic', Gtk.ICON_SIZE_BUTTON);
		this.btnLockScreen = Gtk.Button.new_from_icon_name('video', null);
		this.btnLockScreen.connect('clicked', (e) => {
			print('click');
			//print(e);
			//print(this);
			this.systemActions.activateLockScreen();
		});
		this.win.add(this.btnLockScreen);

		let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
		this.systemActions = new SystemActions;
		this.systemActions.bind_property(
			'can-lock-screen',
			this.btnLockScreen,
			'visible',
			bindFlags
		);


	},

	run: function() {
		this.win.show_all();
		this.systemActions.update();
	}
});

Gtk.init(null);
var win = new Win();
win.run();
Gtk.main();




接著執行下面指令,將「demo_button.js」設為可執行。


$ chmod u+x demo_button.js



然後執行下面指令


$ ./demo_button.js



就會跳出一個視窗,然後整個畫面只有一個按鈕,中間有一個「影片」的圖示。

可以按下按鈕,系統上方就會出現標題為「Do LockScreen!」的對話框。

接著開起另一個「Terminal」,姑且稱它「Terminal B」,剛剛的則是「Terminal A」。


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen true



然後剛剛視窗裡的按鈕,就會消失。


接著在「Terminal A」,執行下面的指令


$ gsettings set org.gnome.desktop.lockdown disable-lock-screen false



然後剛剛視窗裡的按鈕,就會顯示。


================================================================================

從範例二,您可以再去對照觀看下面這兩檔案


* gnome-shell-3.26.1/js/misc/systemActions.js
* gnome-shell-3.26.1/js/ui/status/system.js

可以輔助您理解相關的實作,因為不太好說明,所以就先給範例當作參考。



* gnome-shell-3.26.1/js/misc/systemActions.js

可以先理解「範例一」的那段機制。



* gnome-shell-3.26.1/js/ui/status/system.js

有一個關鍵字「bind_property

兩個地方可以查「API」文件。

* https://people.gnome.org/~gcampagna/docs/
* http://devdocs.baznga.org/

我在「#32 回覆: Ubuntu 17.10 推出」最下方有列更多跟gjs相關的參考連結。

================================================================================

以上提供參考

報告完畢



================================================================================

[回到索引]

2017/11/7 20:43
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.