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 2 - Events and errors



Setting the WM_NAME property.

Until now our little program hasn't displayed anything in it's titlebar. The windowmanager will look for the WM_NAME property for our top level window and use this as the title. Setting properties is usually a pretty complicated business but luckily this is such a common action that a convenience function has been made. More information about properties and atoms will follow in the third tutorial.

    char *title = "Hello!";
    XTextProperty windowProp;
    if( XStringListToTextProperty( &title, 1, &windowProp ) == 0 )
    {
        printf( "XStringListToTextProperty ran out of memory" );
        exit( 1 );
    }
    XSetWMName( dpy, win, &windowProp );
    XFree( windowProp.value );

To set the WM_NAME property we choose to use the XSetWMName function on our main window. Unfortunately we can't just give XSetWMName a pointer to the string we want to use as title. It expects an XTextProperty structure.

We start out by defining the title we want and the XTextProperty structure we want to use. We then call the XStringListToTextProperty function which fills out the XTextProperty structure for us. Note that XStringListToTextProperty expects an array as the first argument and that we cheat by giving it the pointer the title pointer specifying that this is an array of length 1. In case we're out of memory we check the return value of XStringListToTextProperty and show the user and error before we quit.
The title has successfully been transferred to our XTextProperty structure and we call XSetWMName to set this property on the X server. Finally we clean up after ourselves by calling XFree on the value variable of our XTextProperty which XStringListToTextProperty allocated for us.

Final words

The latest version of this tutorial is part of the frekko project and can always be found here.

Hopefully this little tutorial has given you a feeling about how events work. Next time we will be back with a tutorial about atoms, the inner building blocks of X ;)

Attached files:


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

Comment List


Topic: Author:
Time:
Xlib ButtonHandler Sant Kumar 16.11.2004 06:04

Hi
Everybody
I want to handle the mouse button to be clear
i am writing a Gui for which i have to handle the mouse i.e when ever the mouse comes to a particular rectangle it has to change its cursor and draw a line and this line should move with the mouse i.e this line has to repainted every time
is anyone to help me
Thanking u
Santhosh


salaf osman altayeb 12.02.2004 11:29

i want to learn c++.


C++ make errors Anthony Bargnesi 05.12.2003 17:18

I had troubles with

#include <stack> in painter.hpp

I noticed it wasn't including a header file, so i searched for stack.h...

I replaced #include <stack> with:

#include </c++/3.2.2/backward/stack.h>
where the stack.h header file was...

Now it works and compiles, and runs correctly.

Hope that helps somebody else, If not im the only one..haha..

Great Tutorials..COME OUT WITH MORE!




Forgot your password?

Register a new user

Results

Polls