Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Statment to match two tables in c# 6 78
C: GetDiskFreeSpaceEx() for default drive 14 107
How to organize data in excel ? 2 114
Computer slow / BSOD 10 59
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…
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…
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 and use conditional statements in the C programming language.

770 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