home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / xlibloop.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  3.4 KB  |  147 lines

  1. #include <signal.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <sys/time.h>
  5.  
  6. #include "Xv9t9.h"
  7.  
  8. #include "v9t9_common.h"
  9. #include "system.h"
  10. #include "timer.h"
  11. #include "v9t9.h"
  12.  
  13. #include "command_rl.h"
  14. #include "moduleconfig.h"
  15. #include "v9t9_module.h"
  16.  
  17. #include "unixmain.h"
  18.  
  19. #if defined(X_WIN_VIDEO) && defined(X_WIN_KEYBOARD)
  20.  
  21. #define _L     LOG_INTERNAL | LOG_INFO
  22.  
  23. #include "xlibrsrc.h"
  24.  
  25. #define SIZEOF_OPS    4
  26. XrmOptionDescRec xlib_opTable[SIZEOF_OPS] = {
  27.      {"-geometry",     ".geometry",     XrmoptionSepArg, (XPointer) NULL},
  28.      {"-xrm",         NULL,             XrmoptionResArg, (XPointer) NULL},
  29.      {"-display",     ".display",     XrmoptionSepArg, (XPointer) NULL},
  30.      {"-iconic",     "*iconStartup", XrmoptionNoArg,  (XPointer) NULL},
  31. };
  32.  
  33. XrmDatabase xlib_rDB;
  34.  
  35. extern Display *x11_dpy;
  36. extern Window vwin;
  37. extern int  x11_screen;
  38.  
  39. void xlib_get_resources(const char *appname, XrmDatabase cmdlineDB)
  40. {
  41.     XrmDatabase homeDB, serverDB, appDB;
  42.     char filenamebuf[1024];
  43.     char *str;
  44.  
  45.     /*    Get merged resource database  */
  46.  
  47.     /*    Read app-defaults... */
  48.     strcpy(filenamebuf, "/usr/lib/X11/app-defaults/");
  49.     strcat(filenamebuf, appname);
  50.     appDB = XrmGetFileDatabase(filenamebuf);
  51.     if (appDB) XrmMergeDatabases(appDB, &xlib_rDB);
  52.  
  53.     /*    Read server defaults... */
  54.     if ((str = XResourceManagerString(x11_dpy)) != NULL) {
  55.         serverDB = XrmGetStringDatabase(str);
  56.     } else {
  57.         /* Open .Xdefaults file */
  58.         strcpy(filenamebuf, (str = getenv("HOME")) ? str : ".");
  59.         strcat(filenamebuf, "/.Xdefaults");
  60.         serverDB = XrmGetFileDatabase(filenamebuf);
  61.     }
  62.     if (serverDB) XrmMergeDatabases(serverDB, &xlib_rDB);
  63.  
  64.     /*    Get local defaults for server */
  65.     if ((str = getenv("XENVIRONMENT")) == NULL) {
  66.         int len;
  67.         strcpy(filenamebuf, (str = getenv("HOME")) ? str : ".");
  68.         strcat(filenamebuf, "/.Xdefaults-");
  69.         len = strlen(filenamebuf);
  70.         gethostname(filenamebuf+len, sizeof(filenamebuf)-len);
  71.         str = filenamebuf;
  72.     }
  73.     homeDB = XrmGetFileDatabase(str);
  74.     if (homeDB) XrmMergeDatabases(homeDB, &xlib_rDB);
  75.  
  76.     /*    Command line is priority */
  77.     if (cmdlineDB) XrmMergeDatabases(cmdlineDB, &xlib_rDB);
  78. }
  79.  
  80. /*
  81.  *    Initialize what we can and return 1 if we are to use
  82.  *    the xlib loop.
  83.  */    
  84. int
  85. xlib_system_init(void)
  86. {
  87.     XrmDatabase cmdlineDB = 0;
  88.     XrmValue    value;
  89.     char         *display;
  90.     char        *str_type[20];
  91.  
  92.     /*  Read command-line args */
  93.     XrmParseCommand(&cmdlineDB, xlib_opTable, SIZEOF_OPS, 
  94.                     OS_GetFileNamePtr(v9t9_argv[0]), 
  95.                     &v9t9_argc, v9t9_argv);
  96.  
  97.     /* Initialize X context */
  98.     if (XrmGetResource(cmdlineDB, "v9t9.display", "V9t9.Display",
  99.                         str_type, &value)) {
  100.         display = (char *)value.addr;
  101.     } else {
  102.         display = NULL;
  103.     }
  104.  
  105.     if ((x11_dpy = XOpenDisplay(display)) == NULL) {
  106.         logger(_L | LOG_USER, "Cannot connect to X server '%s'\n",
  107.             XDisplayName(display));
  108.         return 0;
  109.     }
  110.  
  111.     xlib_get_resources(OS_GetFileNamePtr(v9t9_argv[0]), cmdlineDB);
  112.  
  113.     x11_screen = DefaultScreen(x11_dpy);
  114.  
  115.     return 1;
  116. }
  117.  
  118. int
  119. xlib_system_loop(void)
  120. {
  121.     XEvent      Event;
  122.     int            ret;
  123.  
  124.     while (1) {
  125.         while (TM_Ticked) {
  126.             TM_TickHandler(0);
  127. //            TM_Ticked--;
  128.             TM_Ticked = 0;
  129.         }
  130.         while (XCheckWindowEvent(x11_dpy, vwin, ~0, &Event)) {
  131.             logger(_L | L_2, "Event = %d\n\n\n", Event.type);
  132.             x_handle_kbd_event(&Event);
  133.             x_handle_video_event(&Event);
  134.         }
  135. //        XSync(x11_dpy, False);
  136.  
  137.         ret = v9t9_execute();
  138.         if (ret == em_TooFast)
  139.             unix_system_pause();
  140.         else if (ret == em_Quitting || ret == em_Dying)
  141.             break;
  142.     }
  143.     return ret == em_Dying;
  144. }
  145.  
  146. #endif    // defined(X_WIN_VIDEO) && defined(X_WIN_KEYBOARD)
  147.