我刚刚在 Ubuntu 17.10 下从 XOrg 切换到 Wayland。
假设我在 Nautilus 中单击一个文本文件。以前我会自动切换到 gedit(每次我单击一个文件时,即使 gedit 已经打开)。
在 Wayland 上,这种情况发生在我第一次单击文件时(第一次打开 gedit 时),但之后,它不再切换。gedit 只是在后台打开文本文件,甚至没有弹出通知说“blablabla.txt 在 gedit 中已准备就绪”。
在 XOrg gnome-shell 下,我曾经能够安装一个名为夺走我的注意力(也可以找到 3.26 的更新版本 这里)。这两个扩展似乎都不再起作用了。
还有一个 gsetting 可以做与这些扩展相同的事情:
gsettings set org.gnome.desktop.wm.preferences focus-new-windows 'strict'
而且这似乎也不再起作用了。
由于这是在我转换到 Wayland 之后发生的,所以我猜测这与 Wayland 有关。
有人成功禁用 Wayland 下的焦点窃取保护吗?如果没有,有人有什么想法或建议吗?
答案1
好吧,不确定这个错误是否只发生在我的机器上,或者它是否更广泛。我可能错了,但我猜这可能是由于某些 Wayland 安全限制导致应用程序无法聚焦已打开的窗口(据我所知,现在应该由窗口管理器来处理这些事情,而不是像 X 中的显示服务器)。我假设这是一个过渡问题,gnome 最终将使 gedit 能够聚焦新选项卡。
在等待修复的过程中,我想到了一个部分修复方法,即在 gedit 中打开新选项卡时发送通知。这并不能解决自动对焦问题,但至少可以给你一些提示,这样你就不必在那里坐 2 或 3 秒,想知道为什么你的窗口还没有打开。
在非 root 终端中输入:
gedit admin:///usr/bin/gedit-notify
在gedit-notify,粘贴以下脚本:
#!/bin/bash
# purpose of this script: gedit under gnome Wayland has pretty messed up focusing and activation problems. First document/tab opened will focus normally but all the following ones open in the background without the traditional notification: "Your window is now read, click to focus". Its very distracting behavior because for the first 2 seconds you're wondering if your click was registered or not, if the app opened or not, etc. This script sends a notification every time you open a text file in the background.
skip_list=true # you get notified but your notification list doesn't get spammed.
gedit_inst=$(ps ax|grep " gedit "|wc -l) #total number gedit windows + 1
gedit_inst=$(expr $gedit_inst - 1) #remove one from the count to account for the grep " gedit " process
gedit_s=$(ps ax|grep " gedit -s"|wc -l) # -s switch represents signle / independent instance for gedit.
# gedit_s represents the number of gedit windows running as
# independent instances + 1
gedit_s=$(expr $gedit_s - 1) # same logic as before
gedit_inst=$(expr $gedit_inst - $gedit_s) #substracts the # of windows running in independent instances
#from total cound - because they don't affect the focus behavior.
if [ "$skip_list" = true ]; then
n_arg0="--hint";n_arg1="int:transient:1"
else
n_arg0="-u";n_arg1="low"
fi
if [ "$gedit_inst" = 0 ]; then notify=false;fi
n=0
while true; do
n=$(expr $n + 1)
file=$(eval echo \$$n)
if ! [ -z "$file" ]; then
gedit "$file" &
if [ -z "$err" -o "$err" = 0 ]; then
err="$?"
fi
else
count=$(expr $n - 1)
if [ $count = 0 ]; then
if [ "$notify" != false ]; then notify-send $n_arg0 $n_arg1 "TEXT EDITOR is ready. Activate it manually.";fi
gedit
fi
break;
fi
done
if [ "$err" = 0 -a "$notify" != false ]; then
if [ $count -gt 1 ]; then
notify-send $n_arg0 $n_arg1 "TEXT EDITOR is ready. Activate it manually." "$count files were opened."
elif [ $count = 1 ]; then
notify-send $n_arg0 $n_arg1 "TEXT EDITOR is ready. Activate it manually." "file: \"$1\""
fi
elif [ "$err" != 0 ]; then
notify-send -i error "TEXT EDITOR: I ran into some error(s) while opening your file(s)."
fi
节省gedit-notify,然后输入:
cd /usr/bin
sudo chmod +x gedit-notify; sudo touch gedit-notify
gedit admin:///usr/share/applications/gedit-notify.desktop
在gedit-notify.desktop,粘贴以下代码:
[Desktop Entry]
Name=Text Editor (Notify)
Comment=Edit text files
Exec=gedit-notify %U
Terminal=false
Type=Application
StartupNotify=true
Icon=gedit
Categories=GNOME;GTK;Utility;TextEditor;
X-GNOME-DocPath=gedit/gedit.xml
X-GNOME-FullName=Text Editor
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gedit
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.22.1
X-GNOME-Bugzilla-ExtraInfoScript=/usr/share/gedit/gedit-bugreport.sh
Actions=new-window;new-document;
Keywords=Text;Editor;Plaintext;Write;
X-Ubuntu-Gettext-Domain=gedit
X-AppStream-Ignore=true
[Desktop Action new-window]
Name=New Window
Exec=gedit --new-window
[Desktop Action new-document]
Name=New Document
Exec=gedit --new-document
这将创建一个桌面快捷方式,它将在您的仪表板和打开方式菜单中显示为文本编辑器(通知)。在 nautilus 中,浏览,找到一个文本文件,右键单击它,选择属性,单击打开方式选项卡,选择“文本编辑器(通知)”,设置为默认值。将有 4 或 5 种不同类型的文本文件需要重复此过程。重复此操作。