Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-09-2007, 09:55 PM   #1
Registered: Sep 2005
Posts: 47

Rep: Reputation: 15
Prevent XLIB application from closing when close button pressed

Anybody know how I can prevent the close button (the top right X in the title bar) from closing my application. I want to ask the user if they wish to save their changes before closing (and perhaps even to cancel the close operation).

If it makes a difference in the answer ... I want the close button to change a variable from 0 to 1, call a particular function, and then for the application to return to normal operation as though nothing had ever happened. The application would perform an elegant shutdown from there if it is still needed.

My application is running in a plain Xlib window with an OpenGL render (no GTK, or other libraries are linked in).

Thanks for any help you can provide
Old 11-11-2007, 01:47 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Here are a couple of links from people who've asked similar (the same?) questions:

See also FAQ #188:
<= Good explanation of what's going on...

The basic issue is that the little "X" (close window) icon isn't really an Xlib thing; it's actually more of a Windows manager thing.

Here is one possible solution:

  Atom              wm_protocols;
  Atom              wm_delete_window;
  wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
  wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  XSetWMProtocols(dpy, win, &wm_delete_window, 1);
  for (;;) {
    XEvent event;

    XNextEvent(dpy, &event);
    switch (event.type) {
      case ClientMessage:
        if (event.xclient.message_type == wm_protocols &&
  [0] == wm_delete_window)  {
          XDestroyWindow(dpy, win);
'Hope that helps .. PSM

Last edited by paulsm4; 11-11-2007 at 01:49 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dell Latitude c610 mouse only works if another button is pressed tallmtt Linux - Laptop and Netbook 3 07-10-2007 11:04 AM
Connect Gtk's key event with button pressed? Chowroc Programming 6 12-20-2004 01:52 PM
Close window error when not closing firehawk573 Programming 0 03-22-2004 03:05 PM
Automatic shutdown when power button pressed.. mr_smidge Linux - General 9 09-08-2003 02:16 AM
Closing applications using Xlib stoney79 Programming 7 08-01-2003 06:20 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration