Recently I started learning what makes Linux work, meaning the core of the whole system. One of the most complex things to understand was the X Window System, or X11 (because the current version is Version 11). In case you don't know, X11 is the part of Linux that actually makes everything graphical and runs windowed programs, and not run programs through a command line interface.s
You might think that this would be a very simple part of the system, but believe me, it's not. The kernel and X11 might just be the most complicated structures.
A Linux system does not require having X11 installed, but if you're going to use graphical programs, like web browsers and word processors, then you're probably going to want to.
Before I go further, I just want to explain that in order to display applications in windows, the Linux system must have X11 installed, and if the user wants to have toolbars, shortcuts, a desktop, and more, then there also must be a window manager present. A window manager is a program built on top of X11 that places designs around windows (like help buttons, minimize buttons, and exit buttons) and can place toolbars on the screen.
There are so many different window managers, that I could not possibly list them all without missing at least fifty, but some of the major ones are GNOME, KDE, and Xfce. There are also several others small ones, called minimalists, like Blackbox, but the best way to learn about something is to actually create it, and when it came to creating my own minimalist window manager, I had very little information on how to. Finally, after hours of research, I now share my findings with you.
First of all, you're going to need to know C or C++. There's no doubt about that. You're also going to want to have experience with a widget toolkit for Linux, like GTK+ or Motif, at least if you're going to place buttons around a window, or create toolbars at the bottom of the screen.
Then you need to buy the book XLIB Programming Manual. Try Amazon Zshops, they're really cheap there. It is also available online for free, but believe me, it's better to have a book.
Xlib is an X11 protocol client library for C or C++, and is the lowest level of interacting with X11. It basically does everything, from raising and resizing a window, to manage the keyboard and mouse focus. Xlib will become your best friend, because all window managers are written in some, if not 100%, Xlib.
I read the book from cover to cover, but if you don't feel like it, you might just read the first few chapters, the ones about keyboard and mouse focus, and the one on window management.
You might also want to download another window manager as a reference. I suggest a small one, like Blackbox or aewm. These can be helpful when you are trying to find out how to perform a certain task.
Once you've downloaded another window manager and read the book, you can start programming your window manager. There's a few things to remember when doing this. Remember that not all programs start in the size that they appear. For example, say I start up Konqueror (a Linux web browser). The program will be created as a window that is 100 by 100 pixels wide, but will then jump to 100 by 50 pixels wide. The reason you must remember this is because you will need to change the size of your toolbars around the windows (if you have any) when this happens!
The aggravating thing about testing out a window manager you've written is that it is more time efficient to not have X11 running when programming, but just use the command line interface, and a text editor like Vi. This is because you constantly have to change and recompile your code, and start up X to test your changes!
Also, remember that ?startx? starts a new X11 session, and you have to edit your user's ?.xinitrc? script to run your new window manager. Also, if you're ever stuck in an X11 session with no way out, press Ctrl-Alt-Backspace to exit.
I hope I've helped if you are going to create your own window manager. I've successfully created the core of mine, but there are still some bugs I have to fix. Good luck!
Would you like to be a Community Voices blogger? If so, please send a letter of interest and a sample blog entry (what you would post here if you were already a blogger for us) to forums@pcworld.com. We'd love to hear your perspective.