home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / fj / maillis / xwindow / 18998 < prev    next >
Encoding:
Text File  |  1992-12-30  |  5.7 KB  |  188 lines

  1. Path: sparky!uunet!wupost!darwin.sura.net!sgiblab!nec-gw!nec-tyo!wnoc-tyo-news!scslwide!wsgw!wsservra!onoe
  2. From: raja@roma.berkeley.edu (Raja R. Kadiyala)
  3. Newsgroups: fj.mail-lists.x-window
  4. Subject: Re: Catching window manager's kill (Solutions)
  5. Message-ID: <1992Dec31.011146.28385@sm.sony.co.jp>
  6. Date: 31 Dec 92 01:11:46 GMT
  7. Sender: onoe@sm.sony.co.jp (Atsushi Onoe)
  8. Distribution: fj
  9. Organization: U.C. Berkeley -- ERL
  10. Lines: 175
  11. Approved: michael@sm.sony.co.jp
  12.  
  13. Date: 30 Dec 92 18:32:42 GMT
  14. Message-Id: <1992Dec30.183242.24141@pasteur.Berkeley.EDU>
  15. Newsgroups: comp.windows.x.motif,comp.windows.x
  16. References: <1992Dec29.224940.23390@pasteur.Berkeley.EDU>
  17. Sender: xpert-request@expo.lcs.mit.edu
  18.  
  19.  
  20.  
  21. My question:
  22. >    How do I catch/stop the window mngr. from quiting my application (i.e.
  23. >if I am running olwm the user may go up to the the title bar click to
  24. >get the 'window' menu and select 'quit' and my app is outa there.  Likewise
  25. >with mwm except it is 'close').
  26.  
  27. >    I want to prompt the user if he/she REALLY wants to quit.
  28.  
  29. Thanks for all the responses.  I got one to work (which is all I needed ...)
  30. raja
  31.  
  32.  
  33. Solutions:
  34.  
  35. John L. Cwikla <cwikla@wri.com>:
  36.     Look at handling WM_SAVE_YOURSELF and WM_DELETE_WINDOW
  37.     for regular Xt with XSetWMProtocols and
  38.     XmInternAtom and XmAddWMProtocolCallback for Motif.
  39.  
  40. Balwalli Krishnanan <SLLKZ@CC.USU.EDU>:
  41.     Your wm is using resources from .mwmrc (for mwm) etc. Simply 
  42.     edit that file to suit your requirements specifically as follows..
  43.     For .mwmrc (since i use it, i would do ..)
  44.     ...
  45.     Menu DefaultWindowMenu
  46.     {
  47.     ....
  48.     "Close"    _C  Alt<Key>F4     f.exec"yourprog"
  49.     }
  50.  
  51.   
  52. Scott Grosch <garath@engin.umich.edu>:
  53. Curtis Generous <generous@Sti.NASA.GOV>:
  54.     Here is example code taken from Dan Heller's book to handle MWM
  55.     protocols.  Hope it helps.
  56.     Here's an mwm specific example:
  57.  
  58. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  59.  * This program is freely distributable without licensing fees and
  60.  * is provided without guarantee or warrantee expressed or implied.
  61.  * This program is -not- in the public domain.
  62.  */
  63.  
  64. /* wm_delete.c -- demonstrate how to bind the Close button in the
  65.  * window manager's system menu to the "cancel" button in a dialog.
  66.  */
  67. #include <Xm/MessageB.h>
  68. #include <Xm/PushB.h>
  69. #include <Xm/Protocols.h>
  70.  
  71. #define YES 1
  72. #define NO  0
  73. int answer;
  74.  
  75. /* main() --create a pushbutton whose callback pops up a dialog box */
  76. main(argc, argv)
  77. char *argv[];
  78. {
  79.     Widget toplevel, button;
  80.     XtAppContext app;
  81.     void activate();
  82.  
  83.     toplevel = XtVaAppInitialize(&app, "Demos",
  84.         NULL, 0, &argc, argv, NULL, NULL);
  85.  
  86.     button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
  87.         toplevel, NULL, 0);
  88.     XtAddCallback(button, XmNactivateCallback, activate, NULL);
  89.  
  90.     XtRealizeWidget(toplevel);
  91.     XtAppMainLoop(app);
  92. }
  93.  
  94. /* Create and popup an ErrorDialog indicating that the user may have
  95.  * done something wrong.  The dialog contains an Ok and Cancel button,
  96.  * but he can still choose the Close button in the titlebar.
  97.  */
  98. void
  99. activate(w)
  100. Widget w;
  101. {
  102.     Widget dialog, shell;
  103.     void handle_close(), response();
  104.     XmString t = XmStringCreateSimple("Warning: Delete All Files?");
  105.     Atom WM_DELETE_WINDOW;
  106.     Arg args[2];
  107.  
  108.     /* Make sure the VendorShell associated with the dialog does not
  109.      * react to the user's selection of the Close system menu item.
  110.      */
  111.     XtSetArg(args[0], XmNmessageString, t);
  112.     XtSetArg(args[1], XmNdeleteResponse, XmDO_NOTHING);
  113.     dialog = XmCreateWarningDialog(w, "notice", args, 2);
  114.     XmStringFree(t);
  115.  
  116.     /* add callback routines for ok and cancel -- desensitize help */
  117.     XtAddCallback(dialog, XmNokCallback, response, NULL);
  118.     XtAddCallback(dialog, XmNcancelCallback, response, NULL);
  119.     XtSetSensitive(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
  120.  
  121.     XtManageChild(dialog);
  122.  
  123.     /* Add a callback for the WM_DELETE_WINDOW protocol */
  124.     shell = XtParent(dialog);
  125.     WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False);
  126.     XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, response, dialog);
  127. }
  128.  
  129. /* callback for the Ok and Cancel buttons in the dialog -- may also be
  130.  * called from the WM_DELETE_WINDOW protocol message sent by the wm.
  131.  */
  132. void
  133. response(widget, client_data, cbs)
  134. Widget widget;
  135. XtPointer client_data;
  136. XmAnyCallbackStruct *cbs;
  137. {
  138.     Widget dialog;
  139.  
  140.     if (cbs->reason == XmCR_OK) {
  141.         answer = YES;
  142.         puts("Yes.");
  143.     } else {
  144.         answer = NO;
  145.         puts("No.");
  146.     }
  147.     /* test that "reason" is not the cancel button and not the ok button.
  148.      * It's value is XmCR_PROTOCOLS (6666), but we can't check for that
  149.      * because OSF didn't make that value public.
  150.      */
  151.     if (cbs->reason != XmCR_CANCEL && cbs->reason != XmCR_OK)
  152.         /* we passed the dialog as client data for the protocol callback */
  153.         dialog = (Widget)client_data;
  154.     else
  155.         dialog = widget;
  156.  
  157.     XtDestroyWidget(dialog);
  158. }
  159.  
  160.  
  161. Doug Clinton <dec@alex.com>:
  162.     You need to tell the window manager that you are interested in the
  163.     WM_PROTOCOL message WM_DELETE_WINDOW. You can do this in Motif using
  164.     the XmAddProtocolCallback function and related functions. See also the
  165.     VendorShell widget.
  166.  
  167.  
  168. Michael E. Dupree <zmed0b@trc.amoco.com>:
  169.     Atom wm_delete_window;
  170.     ...
  171.     ...
  172.     ...
  173.     
  174.     wm_delete_window=XmInternAtom(XtDisplay(toplevel),
  175.                         "WM_DELETE_WINDOW",False);
  176.     XmAddWMProtocols(toplevel,&wm_delete_window,1);
  177.     XmAddWMProtocolCallback(toplevel,wm_delete_window,
  178.                     exit_dialog, (XtPointer) app_context);
  179.  
  180.     This will trap for the Delete Window signal and call the exit_dialog
  181.     callback when this signal is received.
  182.  
  183. --
  184. Raja R. Kadiyala            UC Berkeley Robotics Lab
  185. Mail is forwarded to:            raja@robotics.berkeley.edu
  186. Office  333-5D Cory Hall        Phone: (510) 643-5798
  187. Lab     330    Cory Hall        Phone: (510) 642-3248 or 2-7824
  188.