Did you know LQ has a Linux Hardware Compatibility List?
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 08-29-2005, 01:46 PM   #1
LQ Newbie
Registered: Aug 2005
Posts: 3

Rep: Reputation: 0
Capturing the window close event in X

I need to capture the event generated when my X app is closed. I can capture all events except when the 'x' is clicked and the window disappears. Whenever I click the 'x' I get a message like this:

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

How can I capture when the user exits the app so I can do some clean up within my program?



P.S. - I don't want to use GTK or Motif to do so either. I just need to capture the close event and do some stuff before exiting the app.

Last edited by phanna; 08-29-2005 at 02:23 PM.
Old 09-01-2005, 09:04 AM   #2
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
although not straight X , its Xt

gcc -o 1 1.c -L/usr/X11R6/lib -lXaw -lXmu -lXt -lXext -lX11
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/Box.h>

XtAppContext appcontext;

void Quit( Widget w,XtPointer client_data,XtPointer call_data )
printf("try capturing close event ...\n"); 
//exit( 0 ); // uncomment this to avoid the error message

int main( int argc, char *argv[] )
  Widget topwidget, container, quitButton, changeButton;
  //static String fallbackResources[] = {".xsample.*font: lucidasans-bold-12",NULL };
  topwidget = XtVaAppInitialize(&appcontext,"XSample",NULL, 0,&argc, argv,NULL,NULL );
  container = XtVaCreateManagedWidget("container",boxWidgetClass,topwidget,NULL );
  quitButton = XtVaCreateManagedWidget("quitButton",commandWidgetClass,container,XtNwidth, 180,NULL );
  XtAddCallback( quitButton, XtNcallback, Quit, NULL );
  XtRealizeWidget( topwidget );
  XtAppMainLoop( appcontext );
hope it helps you a one way or another ...

source ::

also have a look at xcalc.c , also using Xt


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
Event Capturing rem1986 Linux - General 2 12-13-2005 01:11 PM
Capturing another application's window koxin Programming 3 05-18-2005 09:11 PM
Javascript - what to use rather than window.close() then davee Programming 2 04-11-2005 09:28 AM
close window causes reboot aarean Linux - Software 4 03-22-2004 09:10 PM
lid close generates no acpi event mannyzen76 Linux - Laptop and Netbook 0 02-22-2004 12:37 AM

All times are GMT -5. The time now is 11:24 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