Solved

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

Posted on 2000-05-11
1
3,654 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 100 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now