My name is Sjaak van den Berg and I'm a freelance devops engineer from the Netherlands. I work with digital infrastructure.
Tiling in XFCE
Published on Last updated on
Xfce is a lightweight desktop environment for UNIX-like operating systems. It aims to be fast and low on system resources, while still being visually appealing and user friendly.
XFCE is awesome, and it has thousands of themes to allow you to make it look just the way you want it to. It’s not as heavy on resources as Gnome 3, and not as nimble as Openbox, but for me it strikes the perfect balance between aesthetics and performance.
XFCE is a stacking window manager, that treats windows like pieces of paper that can be stacked, like in Microsoft Windows or Apple Mac OS. There are also tiling window managers that are much lower on resources but usually don’t offer the aesthetics of a stacking WM. ArchWiki has an extensive list.
Custom Tiling in a Stacking WM
While Gnome does offer tiling extensions, I don’t want that high of a resource burden. I like XFCE just fine, but the tiling features that it offers are a little lacking. XFCE 4.12 did introduce quarter screen corner tiling in addition to half screen tiling, but I’d like to define my own grid. On my laptop, I’d like to have my editor take up as much space as it needs for me to have a 100 character line length, and the rest is for my terminal. And I want to be able to tile or un-tile my windows to my grid using hotkeys. And I have no need for window decorations once a window is tiled, but want them back sometimes when it isn’t.
Python to the Rescue
I’ve written a Python script that does exactly that. Here is the grid I’ve defined in the XFCE Settings Editor under xfce4-keyboard-shortcuts.
TITLE_BAR = 22# Put the height of your title bar here
# Parse the command line arguments
parser = argparse.ArgumentParser(description="Simple tiling for GTK") parser.add_argument("w", type=int, help="Frame width (in percentage of screen width)") parser.add_argument("h", type=int, help="Frame height (in percentage of screen height)") parser.add_argument("x", type=int, help="Frame x coordinate (in percentage of screen width)") parser.add_argument("y", type=int, help="Frame y coordinate (in percentage of screen height)") parser.add_argument("-d", type=int, choices=[0, 1], default=1, help="1 for window decorations, 0 for none") args = parser.parse_args()
win = window_foreign_new((get_default_root_window() .property_get('_NET_ACTIVE_WINDOW')[2][0])) state = win.property_get('_NET_WM_STATE')[2]
# Calculate the frame dimensions and location in pixels
w = int(round(args.w / 100.0 * screen_width)) h = int(round(args.h / 100.0 * screen_height)) x = int(round(args.x / 100.0 * screen_width)) y = int(round(args.y / 100.0 * screen_height))
# Check whether decorations are desired
if args.d == 1: win.set_decorations(DECOR_TITLE) # or DECOR_ALL for all decorations win.move_resize(x, y, w, (h - TITLE_BAR)) if args.d == 0: win.set_decorations(0) win.move_resize(x, y, w, h)
# Apply changes to window
window_process_all_updates() flush()
To download, just copy/paste the thing, save the repo as a zip or run git clone https://github.com/sjaakvandenberg/gtk-tiling.git. You’ll also need python2, and pygtk.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ ./tiling.py -h usage: tiling.py [-h] [-d {0,1}] w h x y
Simple tiling for GTK
positional arguments: w Frame width (in percentage of screen width) h Frame height (in percentage of screen height) x Frame x coordinate (in percentage of screen width) y Frame y coordinate (in percentage of screen height)
optional arguments: -h, --help show this help message and exit -d {0,1} 1 for window decorations, 0 for none
Make sure to give the script executable permissions with chmod +x tiling.py. To see it in use, here’s a video walkthrough.
Comments