How to make windows appear first on primary monitor (no. 2) on dual-monitor configuration?

Hello, LinuxConfig Forum.

Thanks for this wonderful Linux forum site!

I have a functional dual-monitor desktop on Ubuntu 18.04 GNOME 3.

I have display no. 1 on my left, set as secondary monitor, using the VGA output of my only-one video card.
I have display no. 2 on my right, set as primary monitor, using the HDMI output of my video card.

GNOME Activities appear on primary monitor, as expected.

But whenever I open a new application, it shows first on monitor no. 1 the SECONDARY, so I have to drag it to my primary monitor.

I want new apps to appear first on primary monitor no. 2. Is this possible?

Is this happening with all applications or just only on some? My guess is that this is a random, per application case.

The trick here is to force application window to open at a specific X,Y coordinates/location. There are few tools which might help like devilspie or compiz however depending on your case they might be overhead with no guaranteed success results.

Perhaps the easiest and universal way on how to approach this is to customize application launcher on per application basis. For example first install wmctrl tool:

$ sudo apt install wmctrl

Next, create a custom script for eg. Firefox application called firefox.sh:

#!/bin/bash
firefox &
sleep 1 # allow some time for the application to start and to become active window
wmctrl -r :ACTIVE: -e 0,400,0,1024,640 # move the window into preset position

Make the script executable:

$ chmod +x firefox.sh

When you run the above script the Firefox will start, and then will be moved X,Y position 400:0 and resized to 1024:640. Fiddle with the setting to suit your needs and then replace your current Firefox launcher with this script.

Hint: use xdotool to get a window geometry. For example:

$ sudo apt install xdotool

Run the below command and make the window active ( you have 2 seconds to do so ) by clicking on window you wish to get a geometry information about:

$ sleep 2 && xdotool getactivewindow
117440517
$ xdotool getwindowgeometry 117440517
Window 117440517
  Position: 538,292 (screen: 0)
  Geometry: 840x420

Use this information for your custom application launcher script.

Yes, I agree this is somewhat lengthy solution but it give you a full control. I do not use GNOME as I’m KDE user so it would be good to get some GNOME expert’s opinion on this. I do not want to go into comparison between KDE and GNOME but in this case KDE has you covered in few clicks. Example:

Hope this helps
Lubos

Hi, Lubos. Thanks for answering.

I quickly tried your fix, but whenever I run run the script, the window of Firefox (for example) goes immediately to the monitor to the left (num. 1 and secondary)! And the terminal window moves to the left of primary monitor.

So, I need to double check everything but wanted to let you know that I already read and tried the solution. I will test it more thoroughly.

In one thing you are absolutely correct: not every application suffers from this; some windows/apps, like Firefox does.

And I will no use KDE, sorry! :relaxed: It is not my style :smile: I’m stuck to GNOME:heart_eyes:

Hi,

Move the window you are trying to manage to location where you eventually want it to appear. Using xdotool get the correct XY location. Use this location to configure the script.

PS: I’m not trying to convince you to switch to KDE. Its just that something is missing here as to why to set this up in GNOME seems to be so obscure.

Lubos

Blockquote
PS: I’m not trying to convince you to switch to KDE. Its just that something is missing here as to why to set this up in GNOME seems to be so obscure.

Of course not, Lubos. I tried to joke, but with wiriting, face expressions are lost and extra meaning is gone, too.

I appreciate your comments. Thanks!
I’ll update with more news about my desktop windows.