Xlib Classes for D
Yesternite, I got around to start encapsulating Xlib C functionality into D Classes.
Still working from the simple line drawing example, I was able to pick out the necessary layers for a basic Xlib application, and have translated these to classes. So far, I had to create there to work:
- This seems to be the basis of what you end up seeing. I’m still reading up on what it really is, but I think it’s the basic abstraction of what the XServer actually controls.
- For my program to run, I needed to get the current BlackPixel, WhitePixel values from the DefaultScreen of the Display. So my display class allows me access to the Screens (encapsulated as the Screen class)
- Now, those little boxen you see on you monitor. The ones with the close buttons, etc, are actually the windows. Actually I got to find out that even buttons, scrollbars, etc, are all windows under Xlib.
- To create me a window I need a parent, and the display has a DefaultRootWindow, which I use as the parent for the top level window of my little line drawing app. Display class has a property, DefaultRoowWindow (encapsulated as a Window class)
- Also windows are not visible or usable until after successfully Mapped by X.
- This one confused me initially, as I first thought it was another surface encapsulation. Reading the Xlib programming manual in the wee hours of this morning, cleared this up for me.
- A GC (Graphic Context), is an encapsulated resource that holds information about drawing primitives, for example, line width, line style, foreground color, etc.
- To draw a line, I create a simple GC from the Window, and call its DrawLine method.
Yesternite, I was a bit lazy about encapsulating the Events immidietly, actually I felt that my initial understanding of the Events wasn’t very good, and I may not do a good job encapsulating, so I left them raw as they are. I’ll read more on them tonite, and do some more work. Once I have the Events also encapsulated, I’ll proceed to write the various unittests for the small functionality present in these classes, and I think I’ll do a File refactoring, it seems those classes are gonna get really big, I don’t want them all in the same single file.
Once I’m done with the UnitTests tho, I’ll move on to the second example program, and add features to the classes to get it to run.
Btw, I didn’t get to touch the EFL to D port last nite… I have some design decisions to make on EET, and I’m thinking I’ll take the very raw and straightforward way forward for now… when I’m more used to the class, I’ll come back and refactor.