Adventures in C and Improving UX

Ben Reaves
3 min readJan 30, 2020

--

I wasn’t really sure what to expect going into writing a C program for Kinto, my Linux based solution for porting over a mac keyboard experience. And bear with me, the UX part of this article is literally in the last paragraph.

I was never 100% satisfied with using xprop in Kinto, and knowing the future was Wayland at the time of creating Kinto I did not know if I really wanted to spend the time to write a custom C or C++ program just detect the focus window under x11 or Xlib considering I do not write much C/C++ and certainly have never dealt with x11 on any serious level.

It went smoother than I expected and as a javascript developer there was a lot of similarity in syntax and operators that I was happy about, although I was still constantly checking and making sure that I found examples of what I wanted to do beforehand any ways.

Needing to be aware of the required switch parameters/arguments was also a minor nuisance, but not totally unexpected. I have compiled linux kernels before, particularly for Android phones and other open sourced projects.

# The arguments to provide if you are compiling for Xlib and Xmu libraries
-lX11 -lXmu
# Also the compiler you will use under linux for c is
gcc
# While c++ is
g++
# macOS used to use gcc, but modern versions use the following
clang
# Be aware that some library names and arguments for compiling may be slightly different btwn linux and macOShttps://github.com/rbreaves/kinto/blob/dev/kintox11/src/kintox11.c

I am pretty happy with how this turned out, although I have to admit much of the code this is based off of what was written by kui. Initially I was basing my work off of advice given in stackoverflow with some examples on how to interact with Xlib, but I quickly learned from compiling those examples that they were extremely unstable to be basing my work off of and it was going to take more time to debug it than rewriting from scratch… At least until I came across the gist by kui.

https://github.com/kuihttps://gist.github.com/kui/2622504

I wish his blog post about it was still available as I would love to read about why he wrote it, but the possibilities are nearly endless.

The utility of triggering actions depending on the application you are using could be useful not just for remapping a keyboard, but by changing how a person can interact with their computer, particularly disabled people. Unfortunately the flexibility of solutions like these will have to adapt in the Linux sphere as security of the underlying windowing system, x11, shifts to Wayland. Although for all the kicking and screaming that is happening and claims of security, I think we’re really just shifting the burden of security to the DE, such as gnome, kde, xfce, etc. Already there are pretty easy methods for extracting the active window from Gnome via dbus, and possibly under kde as well, if not by dbus then by kwin or whatever scripting engine is in use for plasmoids.

--

--

No responses yet