Take the 2-minute tour ×

I'm looking into delving into a bit of custom OS work (and yes I understand that doing any development at the DE level or lower on an OS is extremely complex and not a light thing to undertake, curiosity is driving this though), I'm in the research phase right now, digging around and learning by example from the source code for projects like GNOME, KDE and XFCE.

I can't seem to find a really good resource, or resources that describes how a "desktop environment" is initialized, instantiated and drawn to the screen of the user (i.e. it's lifecycle). I know that Xorg/X11 sits in there somewhere, acting as server and the users screen is the client, and your desktop sits on top of this client. A lot of resources just start talking about rearranging combinations of already developed window managers, apps and such in order to customize your desktop experience, but what I'm thinking is what If I wanted a stripped down OS that only consisted of a screen with three buttons that performed some actions and that was it? I don't need window management, applications, or other GUI items, just the ability to draw a desktop and three buttons... (hypothetical)

My problem is at the distro level, how does a DE get registered as an available desktop environment, how is it strapped into the distros boot up, what happens after the login, what's run, what is the topography of a DE? By example, in Ubuntu you can have KDE, XFCE and GNOME installed on one distro and switch between them by logging out, changing the active DE and logging back in so how does the DE make the OS aware of its existence in the first place?

I only really need high level here really, I want to do something fairly simple in that I want to make a DE available in a distro like Ubuntu Desktop (not openly, I mean just for myself) and initialize to an empty desktop (no taskbar, apps, window manager, etc...; just the most base state possible) in order to understand what's required to get a DE running.

I don't need code specific answers (where's the challenge in that right?) but pointers to good resources on how this process works. I'll take a well formed textual answer over a chunk of code as I'm looking to understand how it all works, the path taken to get to a DE and not implementation specifics.

The outcome of this will not technically be published (code-wise) but I'm looking at doing some blog posts that describe the process of learning all of this and writing the DE layer in order to get a "Raw" desktop up and running in a pre-existing/established OS like Ubuntu, Mint, Gentoo or another distro.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Well, I never actually did what you want to do, but I have some ideas you may consider.

If I were to try what you are doing I would look for a very basic, ultra-minimalistic DE, so that there is little noise and maybe I can build on it.

See an extensive list here: http://xwinman.org/others.php

About how things are starting up. Well, you explained it in big. I would add the following details, general stuff - not Ubuntu specific.

On my Linux, I use Sabayon, but probably on other distros too, there should be a service responsible to initializing X.org and maybe offering the graphical login screen. Look for things like /etc/init.d/xdm , or kdm, gdm, etc. Where "dm" is usually stands for "Display Manager".

After login, "/etc/X11/xinit/xinitrc" is involved in the action. I'm not sure why. In this, or in the user's "~/.xinitrc" a line will specify the DE you want to use. Here are some examples from my .xinitrc file:

#exec /usr/bin/enlightenment_start
exec /usr/bin/startkde

The first line would start E17 DE, de second one, currently active, starts KDE.

Additionally, as @sepp2k pointed out, "X has the concept of a root window that you can draw to like to any other X11 window. This window exists automatically and doesn't have to be created (the X11 API (as well as higher-level APIs like GDK) has a method to get a reference to the root window). That's how you can draw stuff on the desktop."

Finally, X.org provides a "handle to the DisplayContext" and you can add a "window on top of the display and draws some lines to it." as @jduren discovered later.

share|improve this answer
Many DMs actually ask you, which DE you want to use. To make your DE appear in that list, you should create an entry in /usr/share/xsessions (might be a different path on different distros - I seem to remember it being /etc/X11/sessions on Ubuntu, but that information may be outdated). That's preferable to using .xinitrc as it allows you to select between different DEs without having to edit the file each time. –  sepp2k Dec 28 '12 at 19:27
This is some great concise info from you and sepp2k, so I gather this is what is roughly happening: 1. You create your DE and register it to X11's sessions config ("/usr/share/xsessions" possibly, depending on distro) 2. ON boot, linux starts X (and shows the login screen) showing the DE options. 3. On successful login, the OS and X11 start your DE's main entry point, i.e. "/usr/bin/startkde" which should do... After #3 the DE should do what to create a desktop? Seen a couple resources where they describe the desktop as a root window itself, basically in full screen mode, credible? –  jduren Dec 28 '12 at 19:37
I also heard about the "desktop as a window" concept. But this is beyond my expertise here. I don't know what is happening after your #3. –  Patkos Csaba Dec 28 '12 at 19:43
@jduren Yes, X has the concept of a root window that you can draw to like to any other X11 window. This window exists automatically and doesn't have to be created (the X11 API (as well as higher-level APIs like GDK) has a method to get a reference to the root window). That's how you can draw stuff on the desktop. –  sepp2k Dec 28 '12 at 19:59
So I've got a small, really basic start to a DE that interfaces with X11, gets a handle to the DisplayContext, adds a new window on top of the display and draws some lines to it. Very cool and not as hard as I had thought it would be to get the basics going through X11. So, @sepp2k or Patkos do either of you want to write up an answer based on what's here in our comments and Patkos's (I guess Patkos would have to edit his current answer) answer to form a more complete answer helpful to anyone coming along here later. I can write one if you are busy, but I'd rather award it to one of you. –  jduren Dec 28 '12 at 21:53
show 2 more comments

X Window overview:

  • a display is one or several screens, a keyboard, a pointer device (often a mouse) (1)

  • the display server is the program which act a mediator between the display and the program who want to use it (the clients). The server do very little as a matter of ui policy (but it handles the access right one).

  • clients are drawing on windows, rectangular area on the screens.

  • there are special windows which cover each a whole screen, the root windows of those screens.

  • X is a network protocol, so the clients may run on another machine than the server. Part of the protocol allows some communication between clients.

  • drawing window borders, changing the focus, minimizing, ... and such kind of ui policy is handled by a client called the window manager. There is very little special about the window manager excepted that it answer to events which are ignored by other clients and for which there can be only one recipient. In some situations, you may end up without a window manager active.

  • there are more or less standardized conventions for communicating between clients and the window manager.

  • desktop environment isn't a well defined term. What it usually covers is a window manager and a set of applications designed to provide a coherent use model and some more conventions so applications can interact with them and between them. Part of those conventions are also more or less standardized.

  • when you start an X server after having logged in in text mode, or when you use a graphical display manager to log in, there is a session script which is executed. That session script may launch just an xterm on the display, launch several programs and a window manager or starts the initialization of a whole desktop environment. Display managers tend to allow to choose one of several session scripts.

  • Linux distributions do their packaging in such a way that when you install a desktop environment, it registers a session scripts for each of the display manager installed.

(1) well there may be several keyboards and mouses, but you are unable to make a difference between them

share|improve this answer
add comment

Your Answer


