2

With screens getting larger and/or wider (some with aspect ratios over 21:9 nowadays), the typical way to snap windows to half the screen on the left or right becomes pretty useless. That is, none really wants to have a text editor window that is half the screen on a 34" wide monitor with 3440 x 1440 resolution! (That would be a text window that is 1720 x 1440 or almost 40cm wide!)

To make better use of the screen real state, I have created a few scripts to make windows full height but only a portion of the whole screen (say, one third or one quarter). I then assign each of those scripts to a specific key combination.

I am using xdotool to do all this so before you try you may want to install is using: sudo apt-get install xdotool. Help for xdotool can be found here.

Here is one of the scripts. This one is for the first window on the left taking only 25% of the screen width and 100% of the height:

#~/.resize_window_location_1
#!/bin/bash

xdotool getactivewindow windowsize 25% 100% # width and height
xdotool getactivewindow windowmove 0 0      # Moves to 100,y

Then, for the second one, I use is:

#~/.resize_window_location_2
#!/bin/bash

xdotool getactivewindow windowsize 25% 100% # width and height
xdotool getactivewindow windowmove 320 0      # Moves to 100,y

And so on and so forth with the last line changing based on the position (as an example these could be 0, 320, 640, and 960). Note that in this case I had to manually add the position as 320 as I was unable to use percentage of the screen size. I am not sure what units the 320 refers to (maybe characters) as it is does not seem to be pixels.

Then I go to: All settings > Keyboard menu and on the Shortcuts tab I create new custom shortcuts. I use Shift+Ctrl+Super+Fn, that run one of the command: ~/.resize_window_location_n (for n=1,2,3, and 4).

All this works quite well except for one small annoyance: the first window which, in spite of me specifying its position as 0 0, it is always put a few characters to the right of the launcher. I have tried setting the position as negative without any luck, instead, it is always placed a few characters to the right of the launcher.

Do any of you know a more elegant way of doing this AND/OR a command-line to move the window all the way to the left, just next to the launcher.

Juan Antonio
  • 1,572
  • Instead of specifying 0 0, try doing something like 34 0 , where 34 is your launcher width, maybe even 34+2 ( moving off by 2 pixels is not exactly noticable, especially on big screens ). The 0 0 area, I'd assume, is reserved by the launcher. As for elegant ways . . . xdotool is already quite simple and usable. One could write a script for resizing windows, but . . . there's no special need for that. I could, however, try to write a script that automates finding the launcher width and subtracting it, if you wish – Sergiy Kolodyazhnyy Sep 06 '16 at 21:23
  • I tried changing the 0 0 as you suggest but that does not work. I tried negative number and that did not work either. I noticed that below a certain number for the x-position the window always appears on the same spot. – Juan Antonio Sep 06 '16 at 21:28
  • Yes, negative numbers are impossible to set, they're not recognized. Well, I'll see what can be done – Sergiy Kolodyazhnyy Sep 06 '16 at 21:37
  • Serg: Any success?

    I find that when dragging the window to the right, it snaps right to the edge of the menu. So, if it 'reserved' space, there must be a way around this.

    – Juan Antonio Sep 11 '16 at 15:35
  • @DK Bose: no, I am using Ubuntu in this case [work computer and laptop on Ubuntu, home computer lubuntu]. I have edited my question based on your comment (i.e., replaced "menu bar" with "launcher" as this is the proper term. – Juan Antonio Oct 07 '16 at 17:54
  • 1
    Hi Juan, this is a bug, noticed it a long time ago already. Both xdotool and wmctrl will always keep a distonce from both the launcher and the panel (the latter seems fixed in the latest versions), unless you uese maximize (wmctrl) or 100% (xdotool). That's simply how it is. See also this, rather old answer for example: http://askubuntu.com/a/565087/72216 "The window to be moved/re-sized needs to be at least a few px from both the Unity launcher and the top panel.". I ran into it many, many times. – Jacob Vlijm Oct 07 '16 at 18:29

0 Answers0