Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

With multiple monitors, I have so far been dragging windows manually around. Is there a way to make a window open on a specific screen in a dual-head setup? (Not to be confused with multiple X server displays.)

Something like: SCREEN=2 firefox or open-in-screen 2 firefox.

If it matters, my environment is KDE using the KWin window manager. KWin window rules can only match some properties like title, but I could not find an environment variable as filter.

The secondary display extends the primary screen:

$ xrandr -q
Screen 0: minimum 320 x 200, current 3520 x 1080, maximum 32767 x 32767
LVDS1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 382mm x 214mm
   1600x900       60.1*+
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 connected 1920x1080+1600+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080      60.0*    50.0     59.9  
   1920x1080i     60.1     50.0     60.0  
   1680x1050      59.9  
   1280x1024      75.0     60.0  
   1440x900       59.9  
   1280x960       60.0  
   1280x720       60.0     50.0     59.9  
   1024x768       75.1     70.1     60.0  
   832x624        74.6  
   800x600        72.2     75.0     60.3     56.2  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        75.0     72.8     66.7     60.0     59.9  
   720x400        70.1  
DP1 disconnected (normal left inverted right x axis y axis)
share|improve this question
1  
Usually, I'd suggest to use kstart for this, but it seems kstart only supports defining a specific desktop, but not a screen on which the application should be started. Probably worth a WISHLIST bugreport on bugs.kde.org. –  Elias Probst Dec 27 '13 at 21:32
    
Great tip about kstart, I also wanted to know that. The command is: kstart --desktop $N firefox where $N is a number between 1 and the total number of virtual desktops. –  Lekensteyn Dec 28 '13 at 9:38
    
Regarding kstart, there's also a bugreport on bugs.kde.org asking for this feature. –  Elias Probst Jan 18 at 14:10
    
How odd, I saw a post about wmctrl earlier today but haven't had a chance to test it. Why was it deleted? –  Lekensteyn Jan 18 at 21:18
    
No idea about the wmctrl post, didn't see it. –  Elias Probst Jan 19 at 14:55

5 Answers 5

This depends on how your dual-monitors are setup.

If you are using XINERAMA to make both displays look like one to X, then you would use the -geometry option to ask applications to appear at a specific location. If you have the displays setup as different screens then you will use the DISPLAY to achieve this.

Give these a try:

$ DISPLAY=0.0 xterm &
$ DISPLAY=0.1 xterm &

If your monitors are screen 0 and 1, this should spawn an xterm on each monitor.

share|improve this answer
2  
I've tried this already, but this configuration does not apply to me, one screen is positioned left from another. I'll update my question. –  Lekensteyn Dec 27 '13 at 20:42
1  
Have you tried using the geometry option to apps that support it? Giving an x coordinate > 1600 should position the app in the second monitors space. You might also try that outside of kwin (just to see if it works) as in my experience kwin and -geometry doesn't always work properly. –  casey Dec 27 '13 at 20:49
    
Casey, the application that I am trying to position does not support such an option (android emulator, based on QEMU). The program opens where my mouse cursor is located. –  Lekensteyn Dec 27 '13 at 20:59

No, you can't do that directly. In the X architecture, the two physical monitors you see are not discernible by applications. You can only work your way around this abstraction, by determining which areas of the visible workspace correspond to which monitor and then place windows at the correct offset.

Sensible toolkits support a -geometry option, which allows your application to request being placed at a specific position. If you don't have this option available, you can use wmctrl if you have an EWMH/NetWM compatible X Window Manager to move and resize already existing windows (see wmctrl (1), you need options -r and -e). I use devilspie to force placement of some windows and of course your window manager of choice may have its own facility to force window placement.

devilspie allows to apply certain actions on X windows and can use X window properties to discern different windows and applications. The key rule for you would be geometry "<width>x<height>+<xoffset>+<yoffset>".

Yet, you always need to do the calculations of when and where another physical monitor begins yourself. But this is not too hard and xrandr does tell you how and where it uses monitors in the form of "<width>x<height>+<xoffset>+<yoffset> on each line staring with an output name.

There is not the foolproof-it-will-just-work way, because implementations may (and do!) vary. wmctrl usually works on the window title to identify the target. devilspie can also refer to its class, yet, I am not aware of any toolkit that lets you specify a X windows class but not its geometry.

Of course you could always start two xephyr instances and make one fill your left screen and the other your right screen and then address screens via the DISPLAY environment variable, but this solution has other downsides.

In theory, the authority to govern window placement is the window manager. Consequently, if you want stuff your window manager can't to, it will be hacky and it's also the reason why there is no generic way to accomplish this.

Yet, if your concrete use case is your android emulator ... which is very different from asking for the option to specify SCREEN=n fooapp on the shell, then devilspie may be what you are looking for. Hint: I found it's best to identify applications by their window class.

share|improve this answer
    
Thanks for explaining why this is not an easy feature. KWin also has window rules that force placement on a different screen (which is what I use now). While there is no default feature for SCREEN=x app, is it possible to add a window property in this way so that it can be filtered by KWin? –  Lekensteyn Jan 20 at 11:32
    
In theory yes, but I am not aware of any existing solution for this. I think you can't add properties but you can change existing properties, so you simply could add some string to the window class that kwin could detect. –  Bananguin Jan 20 at 15:33
    
I awarded the bounty to you because SE would otherwise grant it to the top-voted answer while your answer better describes the issues. The current answers are still not satisfatory though. –  Lekensteyn Jan 23 at 22:36

I did come across this method which makes use of xdotool, xprop, & wmctrl.

Here’s what the below script will do:

  1. Find the active window
  2. Get its maximized state and remember it
  3. Remove maximization
  4. Get its geometry
  5. Calculate the new position
  6. Move it
  7. Maximize based on the previous state
  8. Raise it
  9. Here’s a script that does that:

script

This will move the active window to the other monitor. It can only handle a side by side, aka. horizontal, configuration of monitors.

wid=`xdotool getactivewindow`
max_state=`xprop -id $wid _NET_WM_STATE`

wmctrl -ir $wid -b remove,maximized_vert,maximized_horz
eval `xdotool getwindowgeometry --shell $wid`

new_x=1600
if [[ "$X" -ge "$new_x" ]]; then
  new_x=0
fi

xdotool windowmove $wid $new_x $Y
if [ -z "${max_state/*_NET_WM_STATE_MAXIMIZED_*/}" ]; then
  wmctrl -ir $wid -b add,maximized_vert,maximized_horz
fi

xdotool windowraise $wid

Source: Xubuntu – moving windows between monitors

share|improve this answer
    
This only works after an application has been opened, not really what I am looking for (a keybinding could probably be added for this though). If I am not mistaken, this always positions a window to the left side of a monitor? –  Lekensteyn Jan 22 at 9:46
    
@Lekensteyn - Yes the intent of this solution is you launch appX and then run this cmd to move it. I do not have dual monitors 8-( so I have no way to test this, I simply found it and provided the details here for you to evaluate. It is an option and could likely be adapted but it's a "raw" solution in its current form. –  slm Jan 22 at 13:08
    
@Lekensteyn - this solution is not that much different than your SCREEN=2 appX concept, except it's appX; sleep 1; moveWindow.sh. –  slm Jan 22 at 13:12
    
@Lekensteyn - also I've used devilspie, xdotool, etc. to do exactly the same things (within a single window), this A compliments the other one, in that it shows the specifics, where the other only explains the possible approaches but doesn't show actual implementation details. –  slm Jan 22 at 13:20
    
It will be more like app & sleep 1; moveWindow.sh as the programs do not detach. I do not consider this an improvement over using KWin window rules though. +1 for your efforts. –  Lekensteyn Jan 22 at 14:14

This is a window manager specific solution. This is how to do it with kwin which is KDE's default window manager.

If you right click on the application Title Bar and select more settings -> special application settings.

Go to Window matching tab. Click on Detect Window Properties button. Then with mouse cursor click on application main window. It will select window class etc and also get window positioning info etc.

Then click on Size and Position tab. Click the Box Position and box Size and drop down box to right of both and set to remember.

Then click ok.

Next time you run the app it should be the same size and on same monitor.

I use this in KDE to open my uRxvt terminal on my left monitor on a 3-monitor setup and it works every time.

Good luck.

share|improve this answer
    
This is how I do it right now, I was hoping there is a more straightforward way using envvars. –  Lekensteyn Jan 22 at 9:42

Had a similar problem. Found the following:

  1. Right click on the window titlebar and select "More Actions" -> "Window Manager Settings".
  2. There choose "Focus" in the column to the left.
  3. Toggle option "Active screen follows mouse".

If no other defaults are specified, windows appear on the currently active screen. With the procedure described above, mouse position defines this active screen.

share|improve this answer
    
Right, but this does not work if I want to keep the cursor in the current screen. I think this is even the default option, but not all programs respect it. –  Lekensteyn Apr 25 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.