Typical situation is that I type something (worst case is my password) in some application, when some other application pops up a window and steals the focus, so my typing (password) goes to something else. I would like to prevent this, at least when I actively type something in an edit box. I always really hated this on Windows, but I never found a way to prevent this. I started using Ubuntu a while ago, and so far I was able to do everything I wanted, so I thought maybe this is also possible. Thanks in advance!
4 Answers
Install CompizConfig Settings Manager
- either from Ubuntu Software Center
or via terminal:
sudo apt-get install compizconfig-settings-manager
Open CompizConfig Settings Manager and go to General -> General options -> Focus and raise behaviour
Change the 'Focus prevention level' from 'Low' to 'Normal'.
-
1Not applicable to Ubuntu 18.04 with GNOME 3, it doesn't even have Compiz.– pomskyMay 3, 2020 at 16:18
-
@pomsky I just today did the above steps on my Ubuntu 18.04 and they worked. I don't remember having added Compiz individually, other than the mentioned package. How could it be working? May 3, 2020 at 18:58
-
-
No, it was installed as 18.04.1 and has been upgraded just up to 18.04.4 and I can verify that my window manager is Gnome 3, so I haven't changed it. Have you tried the above steps on your Ubuntu 18.04 and didn't work? I wonder if adding
CompizConfig Settings Manager
also adds any prerequisite that make this requested feature working. In any case I only did the above and I am no longer experiencing the issue. May 3, 2020 at 19:06 -
2On Ubuntu 20.04 I used this solution and it required one more step for it to work. I had to Alt+F2 and run the "r" command to restart the x server. I assume the settings get reloaded after that and THEN, new windows stopped stealing current window focus.– EffectiXAug 31, 2021 at 13:27
gsettings set org.gnome.desktop.wm.preferences focus-new-windows 'smart'
(I tried the first comment which set the setting to 'strict' but found this didn't work. I also found a tutorial when I searched this setting, that was trying to make windows steal focus like WindowsOS does(opposite of OP), and he set it to 'strict' to accomplish this, and said 'smart' caused things to NOT steal focus. I tried 'smart' and it worked. I can now type freely into a terminal while programs open and they don't steal focus. Ubuntu 18.04) https://major.io/2015/07/06/allow-new-windows-to-steal-focus-in-gnome-3/#:~:text=Open%20dconf%2Deditor%20and%20navigate,and%20you%20can%20select%20strict.
-
Doesn't work for me unfortunately. I keep typing in a terminal window, meanwhile start spotify for example. As soon as the spotify window appears my typing stops working. Ubuntu 21.10, GNOME 40.4.0 Feb 25 at 18:50
The best recommendation I have for this issue is using "Always On Top" or "Always Below Other Windows" options for the window you need to remain (un)focused. Just right-click your title bar and check the option. I can promise, that window anyhow, will and/or will not lose focus for anything popping up.
You can also force certain windows to stay on a particular workspace. You could also divert the applications that have frequent notifications to workspace 1 and then operate from workspace 2.
Edit: To address comments, this is a workaround idea that "could" solve the potential problems, and very much affects focus. And comments that follow, the question is not just referring to "general" problems with focus being stolen, it's not even Microsoft Windows they are asking about. 😉
-
5
-
Especially, even with always on top and always on visible workspace enabled, Skype still steals focus when you switch to another workspace– axolotlOct 5, 2020 at 2:50
-
1Also, it doesn't work for MS Teams, which doesn't support the normal window options - there's no way to tell it to stay on any workspace.– Rick-777Mar 29, 2021 at 9:48
-
Sorry it does not pop up but it steals the active window, so the typing goes to a window in the background which is even worse. May 19, 2021 at 12:34
gsettings set org.gnome.desktop.wm.preferences focus-new-windows 'strict'
. Let us know if that works in your case. To reset to default, give the commandgsettings reset org.gnome.desktop.wm.preferences focus-new-windows
bash
andxdotool
, but a lot of things look simple before you try to implement them. This would have to know what windows it was looking for in advance, so it's not a generic solution to your issue.gedit &[enter]ls"
, "ls" ends up in gedit, not on the shell.