Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Move Active Window to Different Screen (dual head)

  1. #1
    Join Date
    Oct 2008
    Beans
    6

    Move Active Window to Different Screen (dual head)

    I was looking for a built-in method of moving the active window between screens in a dual-head Gnome environment using keyboard shortcuts. Instead of the solution, I found many others looking for the same. Here's the solution I came up with.

    It's limited in that I can only specify to move the window to a specific X-coordinate on the screen -- in my case, I chose to move the active window to the left-most portion of whichever screen I choose, maintaining the Y-coordinate, width, and height of the screen. This solution uses wmctrl.

    http://www.sweb.cz/tripie/utils/wmctrl/

    Also, I run Ubuntu 8.10 with Gnome (or Blackbox), but that should be irrelevant as this solution should even work in Fluxbox, Enlightenment, or any other EWMH/NetWM compatible X Window Manager.

    1. Install wmctrl.

      Code:
      sudo apt-get install wmctrl
    2. Go to the custom commands in the Compiz settings manager. (System > Preferences > CompizConfig Settings Manager > General Options > Commands tab > Commands section)
    3. Add the following commands to move the window to the left screen:
      Code:
      wmctrl -r :ACTIVE: -e 0,0,-1,-1,-1
      wmctrl -r :ACTIVE: -e 0,1440,-1,-1,-1
      NOTE: Replace 1440 with whatever the horizontal screen resolution is of the left monitor.
      -r <WIN> -e <G>,<X>,<Y>,<W>,<H> resize/move the window using gravity, x, y, width, height
      (gravity of 0 uses window's default gravity and values of -1 specify window's properties for other values.)
      The first command above will move the active window to the left most edge of the viewing space.
      The second command will move the active window to the 1440 pixels from the left most edge. In my case, the resolution of my left monitor is 1440x900. Change 1440 to reflect the horizontal resolution of your setup.
    4. Finally, open the Key Bindings section and create keyboard shortcuts associated with the above commands. I use <Alt><Super>Left and <Alt><Super>Right, respectively. These coordinate well with the keyboard shortcuts I use to move screens to other viewports: <Alt><Super>Tab and <Alt><Super><Shift>Tab.
    5. That's all. Close the Compiz Settings Manager and try it out.


    Please let me know if I made any mistakes transcribing these steps. Also, I would love some feedback on how to maintain the relative x-coordinate of the screen while moving. I'm sure there's a better utility than the minimal wmctrl.

    Hope this helps.

    Yours in linux,
    Andrew

  2. #2
    Join Date
    Jun 2006
    Location
    Tallinn, E-stonia
    Beans
    16
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Move Active Window to Different Screen (dual head)

    Tnx a lot for this solution. Worked well on 9.04

    Since my second monitor is below and I didn't want the windows to be sticked to the edges my conf was as follows:

    Code:
    wmctrl -r :ACTIVE: -e 0,50,50,-1,-1
    wmctrl -r :ACTIVE: -e 0,100,950,-1,-1
    I also suggest using Grid plugin on Dual Head.

  3. #3
    Join Date
    Oct 2008
    Beans
    6

    Re: Move Active Window to Different Screen (dual head)

    Thanks, I'm glad someone found use for this post.

    The Grid plugin is great. Thanks!

    Here's a link to a post that explains how to install it for anyone else:
    http://wiki.compiz.org/Plugins/Grid

    It also mentions at the bottom that the following command should install Grid, but that it did not work for the author (I already had it installed by the time I read that):
    Code:
    sudo apt-get build-dep compiz-fusion-plugins-main
    Cheers,
    Andrew
    Last edited by enthooz; July 23rd, 2009 at 07:35 PM.

  4. #4
    Join Date
    May 2008
    Beans
    14
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Move Active Window to Different Screen (dual head)

    I got excited because I presumed this would shift the window between x-screens, but on my setup it only switches the window between workspaces. What graphics adaptor and drivers are you using?

  5. #5
    Join Date
    Oct 2008
    Beans
    6

    Re: Move Active Window to Different Screen (dual head)

    Quote Originally Posted by kitrule View Post
    I got excited because I presumed this would shift the window between x-screens, but on my setup it only switches the window between workspaces. What graphics adaptor and drivers are you using?
    @kitrule: I'm using an NVidia GeForce 8800 GT adaptor and the 'nvidia' driver.

    This basic functionality of this tip is to change the x position of a window. If your desktop spans two monitors, changing the x-position of a window equal to or greater than the resolution of the left monitor will effectively position the window on right monitor. I realize after reading your post that the title should be "Move Active Window to Different Monitor Using TwinView".

    It sounds like you're using Xinerama which, as I understand, creates two separate x sessions and displays them on each monitor separately. Is there a reason you're not using TwinView to have your screen span across both monitors?

  6. #6
    Join Date
    May 2008
    Beans
    14
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Move Active Window to Different Screen (dual head)

    Hi, it's not Xinerama but the native support for separate x screens in the nvidia-settings panel that I'm using. This is for a few reasons:

    . VNC-ing in to my desktop when twin-view is configured is unbearably irritating to work with.
    . One of the DVIs is connected to my tv so if I'm watching a video on that whilst using VNC from my laptop the video ends up getting piped through the VNC connection and hogging the bandwidth.
    . A lot of fullscreen 3d games (e.g. nexuiz) often try to pan across my monitors, thinking that I just have one exceptionally wide screen. I haven't tried it yet, but I'm sure it'll be nice to play a game through the TV whilst watching IRC or torrents download on the monitor when i'm respawning.

    I was using VLC to output videos fullscreen only to my tv using ":0.1" but I've upgraded to karmic and that's broken (across x-sessions and within twinview -i think) so I was hoping I'd find another way of transferring the fullscreen video to the tv. At the moment I have to start VLC on my tv and then manage the playlist and options there. The TVs not really up to displaying text well so it would be beneficial to transfer windows between x screens on the fly. I suppose thinking of them as separate x sessions rather than just screen makes it easier to understand why it's not such a simple task and hasn't been developed yet.

    Thanks for your quick reply though.

  7. #7
    Join Date
    Oct 2008
    Beans
    6

    Re: Move Active Window to Different Screen (dual head)

    Quote Originally Posted by kitrule View Post
    Thanks for your quick reply though.
    No worries. Sounds like you have quite a setup there. That's the best thing about linux -- just being able to hack away at it and tweak it just to your liking. Here at work, I just got another monitor -- three total. We just had this other monitor hangin' around and it's a touch-screen (we develop touch screen kiosks). Unfortunately, I haven't been able to get it calibrated properly in linux so the y-axis is inverted and it uses the touch area to represent the entire viewable area. Maybe I'll get it figured out later on.

    Here's to our solving out both our issues!

    Cheers,
    Andrew

  8. #8
    Join Date
    Sep 2009
    Beans
    4

    Re: Move Active Window to Different Screen (dual head)

    You can also use the 'put' plugin with the 'put to next output' setting from compiz to move windows around.
    http://wiki.compiz.org/Plugins/Put

    Thx for the hint with the Grid plugin.

    Regards,
    1Proton

  9. #9
    Join Date
    Nov 2010
    Beans
    8

    Re: Move Active Window to Different Screen (dual head)

    I don't know about you guys, but on 10.10 I simply can't get the suggestion working. Neither the put or any other suggestion works to send the active window to another X Screen.

    My setup is 3 monitors and 2 cards, 2 monitors on a 8800 GT and one on 210. Xinerama works (but disables compiz) so in an attempt to keep compiz I am trying to work with the screens by sending active window to relevant x-screen.

    It's been a while since last post here but I'm hoping someone would know how to handle this in Ubuntu. I have everything setup but this is the last frontier I can't get over.

  10. #10
    Join Date
    Nov 2007
    Beans
    1

    Re: Move Active Window to Different Screen (dual head)

    I'm using 10.10 with Gnome and the script below works for me. I only have two screens (Lenovo T410 laptop and a second display).

    Kudos to these guys for doing most of the actual thinking:
    http://averagepenguin.com/?p=266

    The script uses xdotool, so grab it if you don't have it installed.

    Code:
    sudo apt-get install xdotool
    Script:

    Code:
    #!/bin/bash
    #++++++++++++++++
    # Monitor Switch
    #
    # Moves currently focused window from one monitor to the other.
    # Designed for a system with two monitors.
    # Script should be triggered using a keyboard shortcut.
    # If the window is maximized it should remain maximized after being moved.
    # If the window is not maximized it should retain its current size, unless
    # height is too large for the destination monitor, when it will be trimmed.
    #++++++++++++++++
    
    # resolution of left monitor
    w_l_monitor=1440
    h_l_monitor=900
    # resolution of right monitor
    w_r_monitor=1280
    h_r_monitor=1024
    
    # window title bar height (default title bar height in Gnome)
    h_tbar=29
    
    # focus on active window
    window=`xdotool getactivewindow`
    
    # get active window size and position
    x=`xwininfo -id $window | grep "Absolute upper-left X" | awk '{print $4}'`
    y=`xwininfo -id $window | grep "Absolute upper-left Y" | awk '{print $4}'`
    w=`xwininfo -id $window | grep "Width" | awk '{print $2}'`
    h=`xwininfo -id $window | grep "Height" | awk '{print $2}'`
    
    # window on left monitor
    if [ "$x" -lt "$w_l_monitor" ]; then
    	new_x=$(($x+$w_l_monitor))
    	new_y=$(($y-$h_tbar))
    	xdotool windowmove $window $new_x $new_y
    	# retain maximization
    	if [ "$w" -eq "$w_l_monitor" ]; then
    		xdotool windowsize $window 100% 100%
    	# adjust height
    	elif [ "$h" -gt $(($h_r_monitor-$h_tbar)) ]; then
    		xdotool windowsize $window $w $(($h_r_monitor-$h_tbar))
    	fi
    
    # window on right monitor
    else
    	new_x=$(($x-$w_l_monitor))
    	new_y=$(($y-$h_tbar))
    	xdotool windowmove $window $new_x $new_y
    	# retain maximization
    	if [ "$w" -eq "$w_r_monitor" ]; then
    	  	xdotool windowsize $window 100% 100%
    	# adjust height
    	elif [ "$h" -gt $(($h_l_monitor-$h_tbar)) ]; then
    		xdotool windowsize $window $w $(($h_l_monitor-$h_tbar))
    	fi
    fi

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •