Solved

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

Posted on 2000-05-11
1
3,699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
zou3 earned 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

734 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