Touch controls on dwm

go back / p4p1


Created on Fri. 05 Jan 2024



Happy New Year! For XMass I got myself a pinephone. Honestly coolest investments I made for myself. I am loving porting all of my tools over to arm. Interacting with the different OS's is so fun for me I love looking at what the community has made.

Like mentioned in other blog posts the one that stood out the most to me was the sxmo based distros. Like arch-linux arm has a sxmo image. For those that do not know sxmo is a tiling windows manager fork of dwm that works on pinephone. I always wanted a linux phone and with a tilling window manager is even more of a fever dream to me.

Reversing Existing Projects

Now this post is in the same vein as the one on the svkbd keyboard one. Using the sxmo dwm port I quickly realised that on sxmo switching between desktops felt unintuitive since all of the gestures where handled by some kind of external software. Now I don't like that approach since it is quite slow on my pinephone. Sadly I didn't get the pro but the normal one with only 2Gigs of ram since I'll focus on development with it and nothing else for now.

The more I looked at that project the more I got a headache and I thought if I could inside of dwm just map gestures it would make things so much simpler. I was going to modify dwm a loads so that it works like intended on my pinephone so I thought the earlier I dove in the better it would be since now I'm trying to learn window re-parenting do draw close buttons on windows as a training for baking in menus to dwm.

The Patch

Going through the dwm source code I had a bit of a fan nerd moment. When I was in college I was using arrays of function pointers to simplify the logic of some section of my parsers and discovered that it was also done inside of dwm :)

Seeing this also reminded me of my contributions to the flipper zero where it is basically what I added to the flipper zero bad usb parser!

Now in the dwm scenario there is a main difference every time the X window manager receives an event a function is called. The events are predefined where for example ButtonRelease is when you release a click from the mouse. Which in gestures this is quite important. Inside of the pinephone the button presses and releases are treated like the left click of a mouse so in theory if these are treated the same I could code in everything to work with a mouse and then just port it to the phone.

Pointer tracking

So obviously to get all of this working inside of the gestures we will need to code in logic to do some pointer tracking. The main concept is I want to know the position on a pointer click and on a release where I can then write some logic that will check from the positions what gesture I am trying to do. So obviously for pointer tracking we need to hook ourselves on the ButtonRelease and ButtonPress.

Now after finding where we need to be we need to track a few things the objective is to do swiping motions so we need to track when the click is held. To do that we can just use a boolean that is set to True when you call ButtonPress and set to false when you do a ButtonRelease. After that for the algorithms we need to save the position during a press and the position during a release.

Swipe Algorithm

From tracking the pointers position we can then check the position of the pointer with the current position to see if the gesture was initiated. To do that I compare the start positions and end positions to figure out which direction I am going in:

Now inside of dwm there is a cool function called motion notify that gets called during movement of the mouse so we can wrap out logic inside of an if that checks if we are in swiping mode then from there check the orientation of the swipe and then call the appropriate function.

In Action

To showcase this all in action here is a quick video of me swiping on the phone pay attention to the top left where the desktop counter is located you will see it change when I switch from desktop 1 -> 2 etc...

What's so cool about this patch is that it also works amazingly on my laptop and I also have ideas that in the future I might get one of the pine64 tablets since it would be funny to just do every hardware with my distro at this point :)


Well thank you for reading you will realise that there is a great little new widget on the pages of the blog for support you can if you want donate through github since I don't want something to fancy it's just there for those that really want and nothing more. You can also follow me on twitter so that you can get updates and notifications on new blog posts and new havoc-extensions...

p3ng0s
arch linux iso

A linux distribution with my entire config pre-installed. Great for learning linux and pentesting with a steep learning curve.

wiki | repo
Similar content
Questions / Feedback
For any questions or feedback you can contact me on LinkedIn or twitter / X. I also use twitter as a platform to update on new posts!
Donate
sponsor me image

If you like the content of my website you can help me out by donating through my github sponsors page.