LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-29-2005, 12:46 PM   #1
phanna
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?

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.

Last edited by phanna; 08-29-2005 at 01:23 PM.
 
Old 09-01-2005, 08:04 AM   #2
alred
Member
 
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
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
 
  


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


All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration