LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Capturing the window close event in X (https://www.linuxquestions.org/questions/programming-9/capturing-the-window-close-event-in-x-358162/)

phanna 08-29-2005 12:46 PM

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?

Thanks,

Patrick

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.

alred 09-01-2005 08:04 AM

although not straight X , its Xt

gcc -o 1 1.c -L/usr/X11R6/lib -lXaw -lXmu -lXt -lXext -lX11
Code:

#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 :: http://www.stllinux.org/meeting_note...619/xprog.html

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


All times are GMT -5. The time now is 07:20 AM.