Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Xlib tutorial 1 - painting colors, graphics contexts and fonts




The root window


Concept Window: Windows are the building blocks of X applications. A window can be painted upon and it can have subwindows. When something happens inside a window e.g a mouseclick or keypress an Event will be generated and sent to the client that created this window. Do not confuse a Window with an application window decorated by a window manager. An application will generally contain lots of Windows e.g buttons, scrollbars, menuitems. A window is represented by an integer ID.
Concept Root Window: The root window is the toplevel window that covers a whole screen. Your toplevel application window will use the Root Window as its parent.

 int screen = DefaultScreen( dpy );
    Window root = RootWindow( dpy, screen );

Before we can get the root window we need to know what screen we are using. This is done with the DefaultScreen macro which returns the screen given in the optional screen element of the DISPLAY environment variable. (See Opening a display). With the second macro RootWindow we fetch the ID of the root Window.

Creating our application window


Concept Colormap: A colormap holds the translation for a given color into the data sent to the monitor. In theory each window can have it's own colormap, however this is almost never applicable or desirable. Ofcourse a system with multiple screens will have one colormap for each screen.
Concept mapping: A window that is visible on the screen is known to be mapped. A non-visible window is unmapped.

    Colormap colmap = DefaultColormap( dpy, screen );
    
    XColor dummy, black, red;
    XAllocNamedColor( dpy, colmap, "black", &black, &dummy );
    XAllocNamedColor( dpy, colmap, "red", &red, &dummy );
    
    // create a window that we can draw on.
    Window win = XCreateSimpleWindow( dpy, root, 100, 100, 200, 200, 0, black.pixel, black.pixel );
    // map the window (that is, show it)
    XMapWindow( dpy, win );


We start off getting the Colormap for our screen using another macro. Then we ask for the colors red and black using the XAllocNamedColor function. XAllocNamedColor allocates a read only entry in the colormap with the closest RGB value to the value we specified. A copy of the entry is returned to us.
It's time to create our toplevel application window. There are two functions we can use for this, XCreateWindow and XCreateSimpleWindow. To keep things simple we will use XCreateSimpleWindow which creates a window that copies most of its properties from the parent. We create a window that uses root as it's parent, position it at coordinates 100,100 with size 200,200 where 0,0 is the topleft corner of the root window.
Finally it's time to tell X to show the window. This is done by sending a XMapWindow request to the server.

Attached files:


<< Previous page | 1 | < 2 > | 3 | 4 | Next page >> | Printer-friendly page |

Comment List


There are no comments.


Forgot your password?

Register a new user

Results

Polls