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.
I recently bought a 49" monitor with 5K resolution, which I intend to use mostly for productivity work. My previous monitor was a 27" with 1080p resolution. So it’s quite a generous upgrade on the screen real estate department.
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:
- 4 columns
- 3 columns with twice more space for the 2nd columns
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.
Obviously, the first thing that I look for was whether my OS already has support for such layout requirements. I use Elementary OS as my daily driver. Although it has a tiling window functionality, the option is very limited. You can only tile to the left and the right, effectively splitting the screen by two. So this approach is ruled out and I moved on to the next approach.
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.
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
When browsing about this problem on Reddit, somebody commented about xdotool. I then quickly looked it up. xdotool is a command-line X11 automation tool. It lets you manually simulate input and mouse activity, move and resize windows, etc. So I thought, well, I can bind this command to a keyboard shortcut and have the windows tiled to the layout that I want. That sounds like a plan.
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:
border-radius: 4px 4px 0 0;
There’s a problem, though. The alert dialog now looks broken.
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.
With this setup, I can easily tile windows according to the layout that I want.
In this post, I’ve demonstrated the use of xdotool as a tiling window solution. This resolves the problem that I had. I hope this resolves yours too and probably me in the future.
Thanks for reading.