dwm keyboard patch

go back / p4p1


Created on Mon. 19 Dec 2023



Hello World! I got a new tool that I started to work on lately which is my amazing Pinephone! Which obviously mean a lot of linux phone tooling. I want to port p3ng0s in a way so that it can fully work on ARM aka pinephone so that I can have a on the go pentest experience I don't need everything to work perfectly but in the future I would like everything to be seamless.

I did start moving a lot of my architecture online for example bloodhound on p3ng0s is now "cloud" based. I will keep the control on the user side you just will have to pay for your own VPS to use some features of p3ng0s. They can be reconfigured to be hosted locally as well. For now keyboards in this case on screen keyboards ^^.

A PinePhone Foreword

I was going to sprint this blog post like 1h ago but then I SSH'd into my pinephone and started setting up autologin and dwm to automatically load. I think with this first sentence it will show how much this project is sick, having the power of linux on my phone was always a fantasy and seeing it now IRL is freaking me out. For those that do not know pine phone is made by the Pine64 project and is a open source phone that is ARM based. Image a raspberry pi but it has a tactile screen and a phone casing this is basically what this is. It has multiple OS from kali nethunter to android ungoogled ROMS. I tried out kali nethunter but I honestly preferred a lot more the Arch linux ARM base since I just want to have the most empty phone to load my own custom things ^^

Now on most phones there are virtual keyboards and I would need one to get DWM working on my phone so I first went through existing pinephone OS with DWM, currently sxmo is supposed to be the main on inside of the source code I found SVKBD, which surprisingly is maintained by suckless. So I obviously got a copy of it inside of a fork and started working on a DWM patch to get this all functional with a keyboard. By reversing sxmo I realised it was a little before opening the keyboard on my pinephone and I realised they where using shell scripts to get those things seamless I wanted it baked into DWM so that is what I did ^^.

DWM patching

When you are inside of DWM you have a spawn function that will handle opening windows that you have defined in your shortcuts like for example the terminal, your menu system etc.. The possibilities of those shortcuts are endless. But since inside of dwm the spawn function only just runs the command inside of a fork I would need a way to catch when the keyboard is ran and then from there resize the windows to fit the keyboard.

Thinking of that implementation more I thought why would I do that? I could just rewrite a clone of spawn but only for the keyboard and it can manage all of the windows for me!

Now look I love how in my DWM I got little gaps around the windows and how my tiling is. Basically what I am looking for is that when the keyboard is not there I have the normal tiling but if I open the keyboard the tiling does not change but just shifts up a bit to allow me to not have the kb above everything.

Now to get this I first determined how do I open and close the keyboard seamlessly basically some quick fork and kill logic worked great. On a fork I save the pid(1) of what handles the execve of the keyboard(2) and if that pid is set(3) on running the function again I kill(4) the pid and revert all of the variables.

From there I just have to save the predetermined size of the height of the keyboard and add it as big gap on the height of each windows since most windows are managed from the top left it is simple to then add a big gap at the bottom.

Now saving the gap and doing the algorithm is the pain in the ass bit I need to save the gap to then resize later in code to avoid doing a hardcoded global variable of some kind I used on of the builtin structures that handles the windows. From there I am able to patch the code up and remove in all of the algorithms the height of the keyboard:

From there the patch works. If you want to patch this into your DWM instance hereis a link to the .diff file to allow you to patch it inside of the latest version of DWM. It's quite small since I did an effort on the code for once ^^.

SVKBD customisation

Now the cute part basically I customized two main things. The first one is obviously the theme I wanted the keyboard to integrate well with the OS:

Now what was needed the most is a way to get the DWM shortcuts I use in a simple way on the phone. Now I compared to sxmo before basically inside of that you get a giant dmenu script that handles most of the apps / menus for you. Now I already have screenshots for the things I use the most. I would not need a big convoluted menu system. The system settings I like I hard code them and never touch them no need for a menu and what is needed is in shortcuts.

So the way I got these working on the keyboard was through the layouts. The SVKBD program has different layouts you can configure with different key presses now I have the normal qwerty layout setup with all of the special characters by scalping through the english layout provided which is great but by going through the code I found a way to parse in modifier keys through those presses so I basically added an extra layout with all of the shortcuts:


Thank you so much for reading I realised that my first blog post was about dwm in this type of format and it's kinda cool that I am doing that kind of post after 3 years. Follow me on twitter to see the next post once I release it and also on github you can see the cool projects I am coding on.

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.