Hi! this will be a short post to help future window manager hackers. I’m currently developing a window manager and was having trouble debugging it from a TTY (yes, from TTY). After a bit of searching, I find the Xephyr.
Xephyr - A Nested X Server
Xephyr is the best way to test and run a window manager. It basically runs an X server inside a window.
Installation (Arch Linux, Void Linux)
$ sudo pacman -S xorg-server-xephyr
$ sudo xbps-install xorg-server-xephyr
Usage
$ Xephyr -screen 1280x720 :1
Create a nested X server window with size 1280x720 and display name “:1”.
Launching applications
$ DISPLAY=:1 dwm
Launch the
dwmin display “:1”.
To launch an application, specify the display followed by the application command.
Grabbing and un-grabbing user input
Pressing Ctrl+Shift should lock/unlock your mouse pointer and your keystrokes inside Xephyr window exclusively if possible.
Reference
https://wiki.archlinux.org/title/Xephyr
Logging system based on C macros
I could end this post here, but I want to share a useful way for logging in your application using C macros:
#include <stdio.h>
#define LOG(str)\
printf("[%s:%i] %s\n", __FILE__, __LINE__, str);
int main() {
int err = 1;
#ifdef LOG
if (err)
LOG("error...");
#endif
return 0;
}
__FILE__: A macro that expands to the name of current input file. __LINE__: A macro that expands to the current input line number. https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
This system uses the #ifdef and #endif macros to create a conditional compilation based on the #define LOG macro. You can enable or disable the logging system simply by commenting or uncommenting the #define LOG line. Of course, you can also apply this strategy using a library like log.c.