Ubuntu: Is it possible to Enable Focus Stealing under Wayland? (Gnome Shell 3.26, Ubuntu 17.10)


I've just switched over to Wayland from XOrg under Ubuntu 17.10.

Say I'm in Nautilus and I click on a text-file. It used to be for me that I was automatically switched over to gedit (every time I click on a file, even if gedit was already opened).

On Wayland, this happens on the first time I click on file (when gedit is opened the first time) but afterwards, it no longer switches. gedit simply opens text files in the background without even a notification popup saying "blablabla.txt is ready in gedit".

Under XOrg gnome-shell, I used to be able to install a extension called Steal My Focus (there's also an updated version for 3.26 that could be found here). Neither of these extensions seem to work anymore.

There was also a gsetting that did the same thing as these extensions:

gsettings set org.gnome.desktop.wm.preferences focus-new-windows 'strict'  

And that doesn't seem to work anymore either.

Since this is happening right after I switched over to Wayland, I'm guessing that this is Wayland related.

Anyone succeeded in disabling focus stealing protection under Wayland. If not, anyone have any ideas? suggestions?


Well, not sure if this bug is only taking place in my machine or if it's more widespread. I could be wrong but I'm guessing this is probably due to some wayland security restriction that prevents apps from focusing already open windows (as far as I know the window manager is supposed to handle these things now and not the display server like in X). I'm assuming this is a transitional issue and that gnome will eventually give gedit the ability to focus new tabs.

While waiting for this fix, I came up with a partial fix that will send a notification when a new tab is opened in gedit. This doesn't fix the autofocus issue but at least it gives you some kind of cue so that you don't have sit there for 2 or 3 seconds wondering why your window hasn't opened yet.

In a non-root terminal, enter:

gedit admin:///usr/bin/gedit-notify  

In gedit-notify, paste the following script:

#!/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  

save gedit-notify, and enter:

cd /usr/bin  sudo chmod +x gedit-notify; sudo touch gedit-notify  gedit admin:///usr/share/applications/gedit-notify.desktop  

in gedit-notify.desktop, paste the following code:

[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  

This will create a desktop shortcut that will show up as Text Editor (notify) in your dashboard and Open With menu. In nautilus, browse around, find a text file, right-click on it, select Properties, click on the Open With tab, select "Text Editor (Notify)", set as default. There will be 4 or 5 different types of text files that needs to have this process repeated. Rinse and repeat.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »