예제 #1
0
static ALLEGRO_DISPLAY_INTERFACE *xglx_get_display_driver(void)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();

   /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
    * to do it, but the config file is not available until after the system driver
    * is initialised.
    */
   if (!system->toggle_mouse_grab_keycode) {
      const char *binding = al_get_config_value(al_get_system_config(),
         "keyboard", "toggle_mouse_grab_key");
      if (binding) {
         system->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
            &system->toggle_mouse_grab_modifiers);
         if (system->toggle_mouse_grab_keycode) {
            ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
         }
         else {
            ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
         }
      }
   }

   return _al_display_xglx_driver();
}
예제 #2
0
static ALLEGRO_DISPLAY_INTERFACE *win_get_display_driver(void)
{
    const int flags = al_get_new_display_flags();
    ALLEGRO_SYSTEM *sys = al_get_system_driver();
    ALLEGRO_CONFIG *sys_cfg = al_get_system_config();
    ALLEGRO_SYSTEM_WIN *syswin = (ALLEGRO_SYSTEM_WIN *)sys;
    const char *s;

    /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
     * to do it, but the config file is not available in win_initialize,
     * and this is neutral between the D3D and OpenGL display drivers.
     */
    if (!syswin->toggle_mouse_grab_keycode) {
        const char *binding = al_get_config_value(sys_cfg, "keyboard",
                              "toggle_mouse_grab_key");
        if (binding) {
            syswin->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
                                                &syswin->toggle_mouse_grab_modifiers);
            if (syswin->toggle_mouse_grab_keycode) {
                ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
            }
            else {
                ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
            }
        }
    }

    /* Programmatic selection. */
#ifdef ALLEGRO_CFG_D3D
    if (flags & ALLEGRO_DIRECT3D_INTERNAL) {
        ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
        if (iface == NULL)
            ALLEGRO_WARN("Direct3D graphics driver not available.\n");
        return iface;
    }
#endif
#ifdef ALLEGRO_CFG_OPENGL
    if (flags & ALLEGRO_OPENGL) {
        return _al_display_wgl_driver();
    }
#endif

    /* Selection by configuration file.  The configuration value is non-binding.
     * The user may unknowingly set a value which was configured out at compile
     * time.  The value should have no effect instead of causing a failure.
     */
    s = al_get_config_value(sys_cfg, "graphics", "driver");
    if (s) {
        ALLEGRO_DEBUG("Configuration value graphics.driver = %s\n", s);
        if (0 == _al_stricmp(s, "DIRECT3D") || 0 == _al_stricmp(s, "D3D")) {
#ifdef ALLEGRO_CFG_D3D
            ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
            if (iface != NULL) {
                al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
                return iface;
            }
#endif
        }
        else if (0 == _al_stricmp(s, "OPENGL")) {
#ifdef ALLEGRO_CFG_OPENGL
            al_set_new_display_flags(flags | ALLEGRO_OPENGL);
            return _al_display_wgl_driver();
#endif
        }
        else if (0 != _al_stricmp(s, "DEFAULT")) {
            ALLEGRO_WARN("Graphics driver selection unrecognised: %s\n", s);
        }
    }

    /* Automatic graphics driver selection. */
    /* XXX is implicitly setting new_display_flags the desired behaviour? */
#ifdef ALLEGRO_CFG_D3D
    {
        ALLEGRO_DISPLAY_INTERFACE* iface = _al_display_d3d_driver();
        if (iface != NULL) {
            al_set_new_display_flags(flags | ALLEGRO_DIRECT3D_INTERNAL);
            return iface;
        }
    }
#endif
#ifdef ALLEGRO_CFG_OPENGL
    {
        al_set_new_display_flags(flags | ALLEGRO_OPENGL);
        return _al_display_wgl_driver();
    }
#endif
    ALLEGRO_WARN("No graphics driver available.\n");
    return NULL;
}
예제 #3
0
파일: xsystem.c 프로젝트: allefant/allegro
static ALLEGRO_SYSTEM *xglx_initialize(int flags)
{
   Display *x11display;
   Display *gfxdisplay;
   ALLEGRO_SYSTEM_XGLX *s;

   (void)flags;

#ifdef DEBUG_X11
   _Xdebug = 1;
#endif

   XInitThreads();

   /* Get an X11 display handle. */
   x11display = XOpenDisplay(0);
   if (x11display) {
      /* Never ask. */
      gfxdisplay = XOpenDisplay(0);
      if (!gfxdisplay) {
         ALLEGRO_ERROR("XOpenDisplay failed second time.\n");
         XCloseDisplay(x11display);
         return NULL;
      }
   }
   else {
      ALLEGRO_INFO("XOpenDisplay failed; assuming headless mode.\n");
      gfxdisplay = NULL;
   }
   
   _al_unix_init_time();

   s = al_calloc(1, sizeof *s);

   _al_mutex_init_recursive(&s->lock);
   _al_cond_init(&s->resized);
   s->inhibit_screensaver = false;

   _al_vector_init(&s->system.displays, sizeof (ALLEGRO_DISPLAY_XGLX *));

   s->system.vt = xglx_vt;

   s->gfxdisplay = gfxdisplay;
   s->x11display = x11display;

   if (s->x11display) {
      ALLEGRO_INFO("XGLX driver connected to X11 (%s %d).\n",
         ServerVendor(s->x11display), VendorRelease(s->x11display));
      ALLEGRO_INFO("X11 protocol version %d.%d.\n",
         ProtocolVersion(s->x11display), ProtocolRevision(s->x11display));

      /* We need to put *some* atom into the ClientMessage we send for
       * faking mouse movements with al_set_mouse_xy - so let's ask X11
       * for one here.
       */
      s->AllegroAtom = XInternAtom(x11display, "AllegroAtom", False);

      /* Message type for XEmbed protocol. */
      s->XEmbedAtom = XInternAtom(x11display, "_XEMBED", False);

      _al_thread_create(&s->xevents_thread, _al_xwin_background_thread, s);
      s->have_xevents_thread = true;
      ALLEGRO_INFO("events thread spawned.\n");
   }

   const char *binding = al_get_config_value(al_get_system_config(),
         "keyboard", "toggle_mouse_grab_key");
   if (binding) {
      s->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
         &s->toggle_mouse_grab_modifiers);
      if (s->toggle_mouse_grab_keycode) {
         ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
      }
      else {
         ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
      }
   }

#ifdef ALLEGRO_XWINDOWS_WITH_XPM
   x11_xpm = icon_xpm;
#endif

   return &s->system;
}