LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-09-2007, 09:55 PM   #1
fcdev
Member
 
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
paulsm4
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:

http://www.linuxquestions.org/questi...43#post2747343

http://www.linuxquestions.org/questi...95#post2188995

See also comp.windows.x FAQ #188:
http://www.faqs.org/faqs/x-faq/part7/section-40.html
<= 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:
http://groups.google.com/group/comp....44530709ea65aa

Code:
...
  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 &&
            event.xclient.data.l[0] == wm_delete_window)  {
          XDestroyWindow(dpy, win);
          XCloseDisplay(dpy);
          exit(0);
        }
        break;
      ...
      default:
        break;
    }
  }
'Hope that helps .. PSM

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


Reply


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


All times are GMT -5. The time now is 10:47 PM.

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