8

I am running Linux Mint 17 Cinnamon 2.4.8.

I really like xdotool, but it conflicts with Cinnamon's awesome snapping/tiling feature.

If I run the following command, it does NOT work if the current window is snapped to a corner/side/fullscreen.

xdotool getactivewindow windowsize 500 1080 windowmove 1420 0

I would like to keep it snapped, but with a custom width. If it is NOT snapped, it works.

Main goal: Snap a window to the right side, with 500 width (via a command)

However, it's probably impossible with xdotool.

I would prefer not to install anything else, and do it all with cinnamon, but if anyone thinks I can achieve my goal with wmctrl, then I'll give it a shot.

Desired output vs. current output

http://s115.photobucket.com/user/ericrazy2000/media/snapped.png.html

http://s115.photobucket.com/user/ericrazy2000/media/NOTsnapped.png.html

TuxForLife
  • 2,909

3 Answers3

3

Does this command work for you (uses wmctrl):

dist500fromright=$((`xrandr | grep \* | awk '{print $1}' | sed 's/x.*$//'`-500));y=`xrandr | grep \* | awk '{print $1}' | sed 's/^.*x//'`;wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$dist500fromright,0,500,$y

Breakdown

xrandr outputs a list of geometries and the * shows the current mode. For example:

$ xrandr | grep \*
   1920x1200      60.0*+

We use awk to capture the first column of output, and sed to grab the dimensions delimited by the x character.

$ xrandr | grep \* | awk '{print $1}' 
1920x1200

$ xrandr | grep \* | awk '{print $1}' | sed 's/x.*$//'
1920

Bash allows us to do math on command output by wrapping it in $((...)):

$ echo 5+2
5+2

$ echo $((5+2))
7

So above, we wrap the command in $((...)) and subtract 500 to get the x-coordinate position 500 pixels from the right edge of the screen:

$ echo  $((`xrandr | grep \* | awk '{print $1}' | sed 's/x.*$//'`-500))
1420

Note, in order to subtract 500 from 1920, we had to put the command that produces 1920 in backticks first.

We set the output above to the variable dist500fromright, and do something similar to store the y-dimensions of the screen in the y variable:

$ dist500fromright=$((`xrandr | grep \* | awk '{print $1}' | sed 's/x.*$//'`-500))

$ y=`xrandr | grep \* | awk '{print $1}' | sed 's/^.*x//'`;

We are now ready to run the wmctrl command

$ wmctrl -r :ACTIVE: -b add,maximized_vert

$ wmctrl -r :ACTIVE: -e 0,$dist500fromright,0,500,$y

where the latter command resizes and moves the active window while the former allows the resize/move on snapped windows.

user1717828
  • 3,542
  • Your command works pretty much exactly as my xdotool example above.

    It also deals with the same problems with the xdotool method:

    1. It does not move the window if it is tiled/snapped.
    2. It does not leave the window tiled/snapped in the end
    – TuxForLife May 17 '15 at 23:56
  • 1
    @TuxForLife, I updated it for Cinnamon snapping. Please let me know if it works. – user1717828 May 18 '15 at 00:18
  • You are very close! However, I would like the final window to be snapped to the right. It is almost, there, it just needs to be snapped to the edge of my screen – TuxForLife May 18 '15 at 00:22
  • @TuxForLife, Does this command not align the window to the right edge of the screen? Could you describe (or post a screenshot) of what it is doing? Here is what I get. – user1717828 May 18 '15 at 00:36
  • The snapped one, I snapped it manually, then I adjusted the size by dragging the edge of the window. http://s115.photobucket.com/user/ericrazy2000/media/snapped.png.html
    http://s115.photobucket.com/user/ericrazy2000/media/NOTsnapped.png.html
    
    – TuxForLife May 18 '15 at 00:46
  • So by "snapped" you mean a curved border, or is there something else? – user1717828 May 18 '15 at 00:59
  • When it is snapped, there should not be a curved border. I put 2 links if it was hard to tell. There you can compare between snapped and not snapped – TuxForLife May 18 '15 at 01:04
  • @TuxForLife, I don't know how to restyle the border without corners. Good luck! – user1717828 May 18 '15 at 14:04
  • It's not just restyling the border without corners. Doing it with our current methods leaves a slight gap still from the window to the edge of the screen. I think it is beyond the control of xdotool and wmctrl, and should be done with Cinnamon. Thanks for the help regardless! – TuxForLife May 18 '15 at 14:08
  • @TuxForLife, I wish I could see your exact setup (mine doesn't have that gap), but you could always try changing -500)) to -500+2)) or -500+4)) or whatever until it looks right for you. – user1717828 May 18 '15 at 14:13
  • Using your method, it positions it really well, but the only problem is that it isn't officially "snapped"

    Is there any way I can do a command with Cinnamon?

    – TuxForLife May 18 '15 at 14:34
  • I recommend getting the geometries with xdotool instead. Your method assumes I have only 1 monitor. width=$(xdotool getdisplaygeometry | cut -d' ' -f1) ; height=$(xdotool getdisplaygeometry | cut -d' ' -f2) – TuxForLife May 18 '15 at 14:58
  • I am running out of time for the bounty. I would rather give the bounty points to someone rather than waste them. Unless someone provides the answer I anticipated for, I can give the bounty points to whoever gives me the best answer to the following question first. How can I unsnap/unfullscreen a window using just xdotool? – TuxForLife May 22 '15 at 01:02
  • @TuxForLife, let me know if it works for you. – user1717828 May 22 '15 at 18:44
  • Hello, that just puts Firefox in "Full screen" mode. It doesn't affect the window size. I would like it to be any window, not just Firefox – TuxForLife May 22 '15 at 19:21
3

You might need to remove some maximization flags first:

wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz;\
xdotool getactivewindow windowsize 500 1080 windowmove 1420 0;\
wmctrl -r :ACTIVE: -b add,maximized_vert
Petr Skocik
  • 28,816
  • This did indeed help a bit. If the window is tiled at the top or bottom, the command works and resizes/relocates the window. However, if the window is tiled to the left or right, the command does not relocate/resize. Also, I would really like to have the final state of the window to be tiled to the edge of the screen – TuxForLife May 18 '15 at 00:13
  • How about now ? – Petr Skocik May 18 '15 at 00:28
  • Hmmm. While it is working very nicely, it does not put it in snapped mode. I can tell it is not in snapped mode since a shadow is visible, and the top corners are rounded. If the window is snapped, then this does not occur – TuxForLife May 18 '15 at 00:33
  • I am running out of time for the bounty. I would rather give the bounty points to someone rather than waste them. Unless someone provides the answer I anticipated for, I can give the bounty points to whoever gives me the best answer to the following question first. How can I unsnap/unfullscreen a window using just xdotool? – TuxForLife May 22 '15 at 01:02
  • You probably won't be able to tile the window using either wmctrl or xdotool. The reason is, muffin (the cinamon window manager) uses a nonstandard state for that (_NET_WM_STATE_TILED) as you can learn from xprop output. I don't think you can get at that reasonably efficiently from a currently existing higher level tool. You'd need to hack at muffin's C code. – Petr Skocik May 22 '15 at 01:14
  • Yeah, I thought of a very funky solution dragging the mouse with xdotool. It actually works much better than I expected. If you can provide me with a way to "remove some maximization flags" with xdotool by itself, I will reward you the bounty points – TuxForLife May 22 '15 at 01:22
0

You can use wmctrl for this,

as example from the old linux mint mate forum, I think you also can use it in cinnamon:

wmctrl -r :ACTIVE: -e 0,0,0,width,height

This should work.

If your screen is fullscreen you should use:

wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized_vert
wmctrl -r :ACTIVE: -e 0,0,0,width,height

source:

http://forums.linuxmint.com/viewtopic.php?f=90&t=109020

or use ctrl + numpad to get the desired location

source:

http://www.reddit.com/r/linux/comments/tbqky/window_snapping_pseudotiling_wm/

  • Please take a look at the previous discussions I had with the other answers. I am aware I can manually snap it, but I am trying to do it with a command. – TuxForLife May 19 '15 at 15:03