5

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

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

It's Shift + Windows + arrow on default.

  • 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 '17 at 13:53
  • I think this was asked when Cinnamon was unable to do this natively. Is this any better? – tsusanka Nov 27 '17 at 13:57
  • Ah, OK. In that case, thanks for clarifying. – Darren Nov 27 '17 at 13:58
1

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.

  • 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. – I say Reinstate Monica Nov 26 '14 at 19:09
  • 1
    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. – LAFK says Reinstate Monica Dec 1 '14 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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