6

I'm currently setting up a new Cinnamon environment, and all my shortcuts are working properly. I managed to find this script online which I've bound to allow me to move windows between monitors:

#!/bin/bash

#get the window geometry
widthHeight=( $(wmctrl -l  -G | grep -v ' \-1 ' | awk 'END{print $5,$6}' ))

#toggle if $1 is set and set to left - move window to left
if [[ ! -z $1 ]]; then
        if [[ $1 == "left" ]]; then
        #this window is in another screen
            wmctrl -r ":ACTIVE:" -e 0,0,0,${widthHeight[0]},${widthHeight[1]}
    else
            wmctrl -r ":ACTIVE:" -e 0,1920,0,${widthHeight[0]},${widthHeight[1]}
        fi  
fi

However, it doesn't work if the window is either maximized or snapped to either side of the monitor. Does anyone know how to modify this script so that it will ALWAYS move the window to the next monitor?

2 Answers 2

4

Cinnamon can do this natively now, you don't need a script to do that.

It's Shift + Windows + arrow on default.

3
  • I don't think this answers the question. The question is how to modify the script in the OP. This combination of keys might do something (it's not clear what from the context) but you need to explain how that fits into the script.
    – Darren
    Nov 27, 2017 at 13:53
  • I think this was asked when Cinnamon was unable to do this natively. Is this any better?
    – tsusanka
    Nov 27, 2017 at 13:57
  • It works only for moving windows from my laptop screen to the external one, but not the other way around. Probably because the external screen is bigger, the window grows and does not have enough space to get back? Mar 31, 2023 at 17:33
2

Some time ago I asked the Internet the very same question and found a somewhat better answer in Github repository of ntowbinj:

https://github.com/ntowbinj/switch-monitor

Script works with maximized windows and with those in full-screen mode too. You may need to install xdotools and wmctrl (I had), the latter is required to undo/reapply maximization and full-screen mode.

I chose NOT to copy/paste code here despite knowing about link-only answers. Reason: 161 additional lines won't make this a clearer/better answer and eventual updates to make this time-resistant will happen most likely on GitHub, not here, nor on PasteBin (where other SE sites I've been to encourage to put such lengthy pastes). To make up for it though, I've roughly outlined how the script will work.

2
  • Welcome to SuperUser! Please edit your answer to include the information from your linked source so that it will remain useful to other users even if the link becomes inaccessible in the future. Nov 26, 2014 at 19:09
  • 2
    I find the verdict / downvote slightly hasty. To comply I'd have to copy-paste 161 lines of Bash code (+ formatting). Such large pastes usually warrant links to PasteBin (per other SE sites I'm on) and linking to PasteBin to stale version of the script is actually WORSE than linking to GitHub. So: I gave it some thought prior to answering and chose to add info on reqs / how it works rather than paste the code. I won't impose on rules if general consensus prefers it without answer, so be it. I'm however unconvinced that lengthy code will make it clearer/better. Do tell where I'm wrong though. Dec 1, 2014 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .