Solved

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

Posted on 2000-05-11
1
3,704 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

630 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