From: <tj...@us...> - 2010-07-25 04:04:33
|
Revision: 13511 http://alleg.svn.sourceforge.net/alleg/?rev=13511&view=rev Author: tjaden Date: 2010-07-25 04:04:26 +0000 (Sun, 25 Jul 2010) Log Message: ----------- Allow the X11 port to initialise without an X server connection. This allows headless programs to run on Unix systems without an X server, without having to add a null system driver. However other ports would need similar changes for for consistent behaviour across ports. Modified Paths: -------------- allegro/branches/4.9/include/allegro5/internal/aintern_xglx.h allegro/branches/4.9/src/x/xdisplay.c allegro/branches/4.9/src/x/xfullscreen.c allegro/branches/4.9/src/x/xkeyboard.c allegro/branches/4.9/src/x/xmousenu.c allegro/branches/4.9/src/x/xsystem.c Modified: allegro/branches/4.9/include/allegro5/internal/aintern_xglx.h =================================================================== --- allegro/branches/4.9/include/allegro5/internal/aintern_xglx.h 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/include/allegro5/internal/aintern_xglx.h 2010-07-25 04:04:26 UTC (rev 13511) @@ -44,11 +44,15 @@ * way to enforce locking for them. * The only solution seems to be two X11 display connections. One to do our * input handling, and one for OpenGL graphics. + * + * Note: these may be NULL if we are not connected to an X server, for + * headless command-line tools. We don't have a separate "null" system + * driver. */ Display *x11display; /* The X11 display. You *MUST* only access this from one * thread at a time, use the mutex lock below to ensure it. */ - Display *gfxdisplay; /* Annother X11 display we use for graphics. You *MUST* + Display *gfxdisplay; /* Another X11 display we use for graphics. You *MUST* * only use this in the main thread. */ Modified: allegro/branches/4.9/src/x/xdisplay.c =================================================================== --- allegro/branches/4.9/src/x/xdisplay.c 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/src/x/xdisplay.c 2010-07-25 04:04:26 UTC (rev 13511) @@ -225,6 +225,11 @@ ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver(); int adapter = al_get_new_display_adapter(); + if (system->x11display == NULL) { + ALLEGRO_WARN("Not connected to X server.\n"); + return NULL; + } + _al_mutex_lock(&system->lock); if (adapter >= ScreenCount(system->x11display)) { Modified: allegro/branches/4.9/src/x/xfullscreen.c =================================================================== --- allegro/branches/4.9/src/x/xfullscreen.c 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/src/x/xfullscreen.c 2010-07-25 04:04:26 UTC (rev 13511) @@ -790,10 +790,15 @@ * */ -static void init_mmon_interface(ALLEGRO_SYSTEM_XGLX *s) +static bool init_mmon_interface(ALLEGRO_SYSTEM_XGLX *s) { + if (s->x11display == NULL) { + ALLEGRO_WARN("Not connected to X server.\n"); + return false; + } + if (s->mmon_interface_inited) - return; + return true; /* Shouldn't we avoid initing any more of these than we need? */ @@ -813,6 +818,8 @@ mmon_interface.store_mode(s); s->mmon_interface_inited = true; + + return true; } void _al_xsys_mmon_exit(ALLEGRO_SYSTEM_XGLX *s) @@ -837,7 +844,8 @@ int _al_xglx_get_num_display_modes(ALLEGRO_SYSTEM_XGLX *s, int adapter) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return 0; if (!mmon_interface.get_num_display_modes) { if (adapter != 0) @@ -852,7 +860,8 @@ ALLEGRO_DISPLAY_MODE *_al_xglx_get_display_mode(ALLEGRO_SYSTEM_XGLX *s, int adapter, int index, ALLEGRO_DISPLAY_MODE *mode) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return NULL; if (!mmon_interface.get_display_mode) { mode->width = DisplayWidth(s->x11display, DefaultScreen(s->x11display)); @@ -873,7 +882,8 @@ int i; int n; - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return -1; n = _al_xglx_get_num_display_modes(s, adapter); if (!n) @@ -917,7 +927,8 @@ bool _al_xglx_fullscreen_set_mode(ALLEGRO_SYSTEM_XGLX *s, ALLEGRO_DISPLAY_XGLX *d, int w, int h, int format, int refresh_rate) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return false; if (!mmon_interface.set_mode) return false; @@ -941,7 +952,8 @@ void _al_xglx_store_video_mode(ALLEGRO_SYSTEM_XGLX *s) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return; if (!mmon_interface.store_mode) return; @@ -951,7 +963,8 @@ void _al_xglx_restore_video_mode(ALLEGRO_SYSTEM_XGLX *s, int adapter) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return; if (!mmon_interface.restore_mode) return; @@ -961,7 +974,8 @@ void _al_xglx_get_display_offset(ALLEGRO_SYSTEM_XGLX *s, int adapter, int *x, int *y) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return; if (!mmon_interface.get_display_offset) return; @@ -971,7 +985,8 @@ void _al_xglx_get_monitor_info(ALLEGRO_SYSTEM_XGLX *s, int adapter, ALLEGRO_MONITOR_INFO *info) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return; if (!mmon_interface.get_monitor_info) { _al_mutex_lock(&s->lock); @@ -988,7 +1003,8 @@ int _al_xglx_get_num_video_adapters(ALLEGRO_SYSTEM_XGLX *s) { - init_mmon_interface(s); + if (!init_mmon_interface(s)) + return 0; if (!mmon_interface.get_num_adapters) return 1; Modified: allegro/branches/4.9/src/x/xkeyboard.c =================================================================== --- allegro/branches/4.9/src/x/xkeyboard.c 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/src/x/xkeyboard.c 2010-07-25 04:04:26 UTC (rev 13511) @@ -695,6 +695,9 @@ if (xkeyboard_installed) return 0; + if (s->x11display == NULL) + return 0; + main_pid = getpid(); memcpy(key_names, _al_keyboard_common_names, sizeof key_names); Modified: allegro/branches/4.9/src/x/xmousenu.c =================================================================== --- allegro/branches/4.9/src/x/xmousenu.c 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/src/x/xmousenu.c 2010-07-25 04:04:26 UTC (rev 13511) @@ -98,9 +98,11 @@ */ static bool xmouse_init(void) { - //FIXME - //_al_xwin_enable_hardware_cursor(true); + ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver(); + if (system->x11display == NULL) + return false; + memset(&the_mouse, 0, sizeof the_mouse); _al_event_source_init(&the_mouse.parent.es); Modified: allegro/branches/4.9/src/x/xsystem.c =================================================================== --- allegro/branches/4.9/src/x/xsystem.c 2010-07-24 18:41:25 UTC (rev 13510) +++ allegro/branches/4.9/src/x/xsystem.c 2010-07-25 04:04:26 UTC (rev 13511) @@ -182,17 +182,18 @@ /* Get an X11 display handle. */ x11display = XOpenDisplay(0); - if (!x11display) { - ALLEGRO_ERROR("XOpenDisplay failed.\n"); - return NULL; + if (x11display) { + /* Never ask. */ + gfxdisplay = XOpenDisplay(0); + if (!gfxdisplay) { + ALLEGRO_ERROR("XOpenDisplay failed second time.\n"); + XCloseDisplay(x11display); + return NULL; + } } - - /* Never ask. */ - gfxdisplay = XOpenDisplay(0); - if (!gfxdisplay) { - ALLEGRO_ERROR("XOpenDisplay failed.\n"); - XCloseDisplay(x11display); - return NULL; + else { + ALLEGRO_INFO("XOpenDisplay failed; assuming headless mode.\n"); + gfxdisplay = NULL; } _al_unix_init_time(); @@ -200,12 +201,6 @@ s = al_malloc(sizeof *s); memset(s, 0, sizeof *s); - /* We need to put *some* atom into the ClientMessage we send for - * faking mouse movements with al_set_mouse_xy - so lets ask X11 - * for one here. - */ - s->AllegroAtom = XInternAtom(x11display, "AllegroAtom", False); - _al_mutex_init_recursive(&s->lock); _al_cond_init(&s->resized); s->inhibit_screensaver = false; @@ -217,28 +212,38 @@ s->system.vt = xglx_vt; - 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)); + 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)); - _al_thread_create(&s->thread, xglx_background_thread, s); + /* 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); - ALLEGRO_INFO("events thread spawned.\n"); + _al_thread_create(&s->thread, xglx_background_thread, s); + ALLEGRO_INFO("events thread spawned.\n"); + } return &s->system; } static void xglx_shutdown_system(void) { - /* Close all open displays. */ ALLEGRO_SYSTEM *s = al_get_system_driver(); ALLEGRO_SYSTEM_XGLX *sx = (void *)s; ALLEGRO_INFO("shutting down.\n"); - _al_thread_join(&sx->thread); + if (sx->x11display) { + /* Events thread only runs if we are connected to an X server. */ + _al_thread_join(&sx->thread); + } + /* Close all open displays. */ while (_al_vector_size(&s->displays) > 0) { ALLEGRO_DISPLAY **dptr = _al_vector_ref(&s->displays, 0); ALLEGRO_DISPLAY *d = *dptr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |