
我正在使用 Manjaro 17 和 i3wm(如果有相關的話)。
我想在啟動時運行一個命令來修復我的觸控板點擊設定。我編寫了啟用該選項/usr/bin/
並將其模式更改為可執行的腳本。
/usr/bin/touchpad-enable-tap-click:
#!/bin/bash
exec xinput set-prop 11 290 1
該腳本可以在終端機中順利執行,不會造成任何問題。
根據我的研究,我準備了一個簡單的服務文件/etc/systemd/system/
。
/etc/systemd/system/touchpad-enable-tap-click.service:
[Unit]
Description=Allow touchpad tap click
[Service]
Type=oneshot
ExecStart=/usr/bin/touchpad-enable-tap-click
[Install]
WantedBy=multi-user.target
比在重新啟動之前執行以下命令:
[sercan@compaq ~]$ sudo systemctl enable touchpad-enable-tap-click.service
Created symlink /etc/systemd/system/multi-user.target.wants/touchpad-enable-tap-click.service → /etc/systemd/system/touchpad-enable-tap-click.service.
我也嘗試過完整路徑。
該服務無法正常運作,結果是:
系統控制狀態
[sercan@compaq ~]$ systemctl status touchpad-enable-tap-click.service
● touchpad-enable-tap-click.service - Allow touchpad tap click
Loaded: loaded (/etc/systemd/system/touchpad-enable-tap-click.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2017-04-22 01:51:17 +03; 14min ago
Main PID: 32429 (code=exited, status=1/FAILURE)
Nis 22 01:51:17 compaq systemd[1]: Starting Allow touchpad tap click...
Nis 22 01:51:17 compaq bash[32429]: Unable to connect to X server
Nis 22 01:51:17 compaq systemd[1]: touchpad-enable-tap-click.service: Main process exited, code=exited, status=1/FAILURE
Nis 22 01:51:17 compaq systemd[1]: Failed to start Allow touchpad tap click.
Nis 22 01:51:17 compaq systemd[1]: touchpad-enable-tap-click.service: Unit entered failed state.
Nis 22 01:51:17 compaq systemd[1]: touchpad-enable-tap-click.service: Failed with result 'exit-code'.
日誌-xe嘗試重新啟動服務後:
Nis 22 02:09:52 compaq sudo[21550]: sercan : TTY=pts/0 ; PWD=/home/sercan ; USER=root ; COMMAND=/usr/bin/systemctl restart touchpad-enable-tap-click.service
Nis 22 02:09:52 compaq sudo[21550]: pam_unix(sudo:session): session opened for user root by (uid=0)
Nis 22 02:09:52 compaq systemd[1]: Starting Allow touchpad tap click...
-- Subject: Unit touchpad-enable-tap-click.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit touchpad-enable-tap-click.service has begun starting up.
Nis 22 02:09:52 compaq bash[21553]: Unable to connect to X server
Nis 22 02:09:52 compaq systemd[1]: touchpad-enable-tap-click.service: Main process exited, code=exited, status=1/FAILURE
Nis 22 02:09:52 compaq systemd[1]: Failed to start Allow touchpad tap click.
-- Subject: Unit touchpad-enable-tap-click.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit touchpad-enable-tap-click.service has failed.
--
-- The result is failed.
Nis 22 02:09:52 compaq systemd[1]: touchpad-enable-tap-click.service: Unit entered failed state.
Nis 22 02:09:52 compaq systemd[1]: touchpad-enable-tap-click.service: Failed with result 'exit-code'.
Nis 22 02:09:52 compaq sudo[21550]: pam_unix(sudo:session): session closed for user root
我希望你能幫助我,我很感激。
答案1
GUI 是作業系統的獨特部分,一台機器可以有多個 GUI 環境。您對 systemd 的嘗試不起作用,因為服務是在 GUI 上下文之外執行的。事實上,它們是在 GUI 啟動之前執行的。要運行xinput
,您需要有一個 GUI,它由X伺服器。
應用程式透過環境變數知道GUI上下文是什麼(即與哪個X伺服器通訊)DISPLAY
。這是一種檢查 GUI 是否可用的方法:如果未設定該變量,則您位於 GUI 上下文之外。 (設定變數不會建立 GUI 上下文。它可以讓您從外部連接到現有的 GUI 上下文,但這與這裡無關。)
如果您的登入提示是圖形模式,那麼您正在使用顯示管理器。您可以將顯示管理器設定為運行xinput
,然後在顯示登入提示時立即套用設定。如何執行此操作取決於您使用的顯示管理器;看如何運行在登入畫面之前啟動的腳本?更多細節。
無論您如何登錄,您都可以將這些設定作為登入腳本的一部分套用。如果您正在使用.xinitrc
或.xsession
來啟動 GUI 會話,請在此處新增命令。如果您使用的桌面環境具有啟動應用程式的概念,請將命令xinput
或執行它的腳本新增至啟動應用程式。如果您直接使用視窗管理器,請檢查其文件以了解如何在啟動時執行命令(幾乎所有視窗管理器都可以執行此操作)。
由於您使用的是 i3,因此您可以在 GUI 登入時執行命令,方法是輸入exec
命令在你的~/.i3/config
:
exec xinput set-prop 11 290 1
儘管 systemd 將顯示管理器作為服務啟動,但我認為它沒有提供在生成的 GUI 上下文中運行命令的方法。但是,它可能提供一種在您登入時運行命令的方法;看到拱門維基舉些例子。
答案2
發生這種情況是因為您嘗試在 X 載入之前執行修改 X 系統(GUI)行為的命令。因此,可以理解的是,它抱怨無法連接到 X 伺服器。提示是您正在執行的命令的名稱:X輸入 。
現在,我不能保證 systemd 在不久的將來不會開發與尚未啟動的伺服器互動的功能,但就目前而言,這不是完成這項工作的正確工具。
首先要嘗試的是將(沒有不必要的exec
)命令添加到您的~/.profile
(或者,如果您使用bash
並且它存在,添加到您的~/.bash_profile
):
xinput set-prop 11 290 1
但請注意,如果您以非圖形方式登錄,這會讓它抱怨。如果這不起作用(請參閱這裡有關詳細資訊),找到一種方法將其新增至桌面環境的啟動程式。大多數流行的桌面環境(例如 Gnome、Cinnamon、KDE、Unity 等)都有 GUI 工具,可讓您在登入時載入程式。看這裡了解如何在 openbox 中執行此操作以及這裡對於 LXDE。或者,請參閱這裡使用更全局的解決方案~/config/autostart
。