home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / motifpg2.zip / ch14 / xtwoapp.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  110 lines

  1. /*
  2.  * Copyright 1989, 1992 O'Reilly and Associates, Inc.
  3.  * See ../Copyright for complete rights and liability information.
  4.  */
  5.  
  6. /*
  7.  * xtwoapp.c - an application with two app contexts and two displays
  8.  */
  9.  
  10. /*
  11.  * Include files required for all Toolkit programs
  12.  */
  13. #include <Xm/Xm.h>    /* Intrinsics Definitions */
  14.  
  15. /*
  16.  * Public include file for widgets we actually use in this file.
  17.  */
  18. #include <Xm/PushB.h>        /* Motif Label Widget */
  19.  
  20.  
  21. /* 
  22.  * This kind of works, but is not elegant, since it ruins Xlib's
  23.  * network optimizations.
  24.  */
  25. void OurMainLoop(app1, app2, dis1, dis2)
  26.     XtAppContext app1, app2;
  27.     Display *dis1, *dis2;
  28. {
  29.     XEvent event;
  30.  
  31.     for (;;) {
  32.         if (XtAppPeekEvent(app1, &event) == TRUE) {
  33.         XtAppNextEvent(app1, &event);
  34.         XtDispatchEvent(&event);
  35.         if (XtAppPeekEvent(app2, &event) == TRUE) {
  36.             XtAppNextEvent(app2, &event);
  37.         XtDispatchEvent(&event);
  38.           }
  39.         else XFlush(dis2);
  40.       }
  41.     else {
  42.         XFlush(dis1);
  43.         if (XtAppPeekEvent(app2, &event) == TRUE) {
  44.             XtAppNextEvent(app2, &event);
  45.         XtDispatchEvent(&event);
  46.           }
  47.         else XFlush(dis2);
  48.       }
  49.       }
  50.   }
  51.  
  52. main(argc, argv)
  53. int argc;
  54. char **argv;
  55. {
  56.     XtAppContext app_con1, app_con2;
  57.     Widget topLevel1, topLevel2, hello, goodbye;
  58.     Display *display1, *display2;
  59.     
  60.     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  61.     
  62.     XtToolkitInitialize();
  63.     
  64.     app_con1 = XtCreateApplicationContext();
  65.     app_con2 = XtCreateApplicationContext();
  66.     
  67.     display1 = XtOpenDisplay(app_con1, "obsidian:0", argv[0], "XHello", 
  68.                  NULL, 0, &argc, argv);
  69.  
  70.     display2 = XtOpenDisplay(app_con2, "harry:0", argv[0], "XGoodbye", 
  71.                  NULL, 0, &argc, argv);
  72.  
  73.     topLevel1 = XtAppCreateShell("name1", "XHello", 
  74.                  applicationShellWidgetClass, display1, 
  75.                  NULL, 0);
  76.  
  77.     topLevel2 = XtAppCreateShell("name2", "XGoodbye", 
  78.                  applicationShellWidgetClass, display2, 
  79.                  NULL, 0);
  80.  
  81.     hello = XtCreateManagedWidget(
  82.         "hello",        /* arbitrary widget name */
  83.         xmPushButtonWidgetClass,/* widget class from PushB.h */
  84.         topLevel1,        /* parent widget*/
  85.         NULL,            /* argument list */
  86.         0            /* arg list size */
  87.         );
  88.  
  89.     goodbye = XtCreateManagedWidget(
  90.         "goodbye",        /* arbitrary widget name */
  91.         xmPushButtonWidgetClass,/* widget class from PushB.h */
  92.         topLevel2,        /* parent widget*/
  93.         NULL,            /* argument list */
  94.         0            /* arg list size */
  95.         );
  96.     /*
  97.      *  Create windows for widgets and map them.
  98.      */
  99.     XtRealizeWidget(topLevel1);
  100.     XtRealizeWidget(topLevel2);
  101.     
  102.     /*
  103.      *  Loop for events.
  104.      *  Notice that since XtAppMainLoop only handles on
  105.      *  app context, we have to write our own juggling loop.
  106.      *  This is not easy (just an attempt made here).
  107.      */
  108.     OurMainLoop(app_con1, app_con2, display1, display2);
  109. }
  110.