Using xdotool as a Tiling Window Solution

In this post, I’d like to explain how I use xdotool to easily tile windows to my preferred layout on my 49" 5K monitor.

The Problem

There’s one issue, though, with the new monitor: The screen is simply too large for one program. Even worse, since most programs start from the top left, I need to turn my head left. This is not nice for my neck and posture. I had expected about this problem, but I thought I could just split the screen by two: left and right side. Turned out splitting by two is also not ideal for me.

After a few minutes of dragging around windows and experimenting with some layouts, I found that I just need 2 types of layout:

  1. 4 columns
  2. 3 columns with twice more space for the 2nd columns
4 columns layout. All 4 windows are laid out evenly. Taking notes while reading is great on this layout.
3 columns layout. More screen space for the center window. Great for programming.

I also need windows to move easily to this layout. So, dragging windows around is not sufficient. I want to have some keyboard keys combination to achieve such a layout.

Failed Approaches

The next approach that I looked into was about Tiling Window Manager. Tiling Window Manager is an alternative to Desktop Environment, e.g. GNOME. The main feature of Tiling Window Manager is exactly this: tiling the windows nicely so that they efficiently use the screen space. Some software for Tiling Windows Manager is i3wm, awesomewm, and xmonad.

While it solves my problem, it brings another problem: I’ll be missing out on a lot of the functionalities of the Desktop Environment that I’m using. Things such as the system trays, the application finders, etc. Well, yes, I can get those back but I need to spend some time and effort to get to the same state as I have right now. Because of the upfront cost of setting this up, I ruled out this approach.

The next approach that I looked into was using quicktile, a software for tiling windows on an X11-based Desktop Environment.

quicktile usage animation taken from quicktile docs

Looks very user friendly, isn’t it? I went ahead and install it on my system. While modifying the config, I realized that this also won’t work for my needs. The main issue is that there’s no way to tile the second window for my 4 columns layout. This tool works well for 3 columns, but beyond that, it’s unusable. Sadly, this approach is ruled out as well.

The Successful Approach

So I went ahead and install it.

$ sudo apt install xdotool

Then I looked into the man page to find the command for moving and resizing windows. The command to resize a window to WIDTH and HEIGHT and to move a window to X and Y is as follows:

$ xdotool getactivewindow windowsize WIDTH HEIGHT windowmove X Y

While testing the tool, I noticed something strange: when I move the window to the position (0, 0), it doesn’t move to the top left. When I resize the window to (100%, 100%), it also doesn’t fully occupy the screen space. Fortunately, I found a hint to solve this problem in quicktile’s FAQ section. The issue is the shadow. The shadow is still considered part of the window.

After experimenting with the /usr/share/themes/elementary/gtk-3.0/gtk-widgets.css I finally settled with this modification:

decoration {
box-shadow: none;
border-radius: 4px 4px 0 0;
margin: 1px;
}
decoration:backdrop {
box-shadow: none;
}

There’s a problem, though. The alert dialog now looks broken.

Broken alert dialog

However, by pressing the command key, the alert dialog fixes itself. Not ideal, but definitely not a blocker.

Finally, I create shortcuts for tiling a window from the Keyboard Shortcuts Manager in Elementary OS.

Keyboard shortcuts setup

With this setup, I can easily tile windows according to the layout that I want.

Tiling window with xdotool

Conclusion

Thanks for reading.

--

--

I write stories that make you a more effective programmer — https://www.linkedin.com/in/eckyputrady/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store