Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

X connection to :0.0 broken (explicit kill or server shutdown)

Posted on 2000-05-11
1
Medium Priority
?
3,720 Views
Last Modified: 2010-10-05
I obtain the error message 'X connection to :0.0 broken (explicit kill or server shutdown)' when I close an X graphical window using the window manager close button.

The graphical application is written in C and uses X11 library.

Applications written using MOTIF library doesn't do so, they seem to close cleanly.

How can I get rid of this?
What event have I to manage?
0
Comment
Question by:mliberi
1 Comment
 

Accepted Solution

by:
zou3 earned 400 total points
ID: 2803839
Hi,
You have to gracefully handle WM_DELETE_WINDOW protocol
message from a window manager.
For this purpose, you can use XSetWMProtocols() and check ClientMessage event.

Please refer to the following sample program.
(There's no XSelectInput() in this sample since ClientMessage
event is not maskable. You may need to call it usually, though)

Xtoolkit used by Motif handles these stuff implicitly.

Compiling/linking is as simple as;
cc -I<X11 inc path> -L<X11lib path> -o prog prog.c  -lX11

------------------ >8 ---------------------
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>

main(void)
{
    Display *d;
    Window w;
    XEvent event;
    Atom    WM_DELETE_WINDOW;

    d = XOpenDisplay(0);
    w = XCreateSimpleWindow(d, RootWindow(d, 0), 0, 0, 100, 100, 2, 0, 1);

    WM_DELETE_WINDOW = XInternAtom(d, "WM_DELETE_WINDOW", True);
    (void)XSetWMProtocols(d, w, &WM_DELETE_WINDOW, 1);

    XMapWindow(d, w);

    while (True) {
        if (XPending(d)) {
            XNextEvent(d, &event);
            switch (event.type) {
            case ClientMessage:
                if (event.xclient.data.l[0] == WM_DELETE_WINDOW) {
                    fprintf(stderr, "ClientMessage with WM_DELETE_WINDOW\n");
                    exit(0);
                }
                break;
            default:
                break;
            }
        }
    }
}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question