diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2009-07-01 13:46:56 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2009-07-01 13:46:56 -0700 |
commit | 2fcdb1ef11a4ddf9258dd41edb7af7bb994afc98 (patch) | |
tree | 433ea7470e8a7346eb38e1e0097992a2e0b02549 | |
parent | 3970e33d4d84a539025ea09eea35dcc6c572fd81 (diff) |
173.14.19173.14.38173.14.37173.14.36173.14.35173.14.34173.14.31173.14.30173.14.28173.14.27173.14.25173.14.22173.14.20173.14.19173.14
-rw-r--r-- | XF86Config-parser/Generate.c | 261 | ||||
-rw-r--r-- | XF86Config-parser/Screen.c | 62 | ||||
-rw-r--r-- | XF86Config-parser/xf86Parser.h | 8 | ||||
-rw-r--r-- | nvidia-xconfig.c | 200 | ||||
-rw-r--r-- | nvidia-xconfig.h | 2 | ||||
-rw-r--r-- | options.c | 2 |
6 files changed, 370 insertions, 165 deletions
diff --git a/XF86Config-parser/Generate.c b/XF86Config-parser/Generate.c index 22ce212..0897fe3 100644 --- a/XF86Config-parser/Generate.c +++ b/XF86Config-parser/Generate.c @@ -141,9 +141,10 @@ XConfigScreenPtr xconfigGenerateAddScreen(XConfigPtr config, /* - * assign_screen_adjacencies() - setup all the adjacency information - * for the X screens in the given layout. Nothing fancy here: just - * position all the screens horizontally, moving from left to right. + * xconfigGenerateAssignScreenAdjacencies() - setup all the adjacency + * information for the X screens in the given layout. Nothing fancy + * here: just position all the screens horizontally, moving from left + * to right. */ void xconfigGenerateAssignScreenAdjacencies(XConfigLayoutPtr layout) @@ -375,6 +376,15 @@ static void add_modules(GenerateOptions *gop, XConfigPtr config) { XConfigLoadPtr l = NULL; + /* + * if the X server will automatically autoload GLX, then don't + * bother adding a modules section; it is difficult for + * nvidia-xconfig to know if modules like "type1" are present, + * anyway. + */ + + if (gop->autoloads_glx) return; + config->modules = xconfigAlloc(sizeof(XConfigModuleRec)); l = xconfigAddNewLoadDirective(l, xconfigStrdup("dbe"), @@ -1297,3 +1307,248 @@ int xconfigAddKeyboard(GenerateOptions *gop, XConfigPtr config) return TRUE; } /* xconfigAddKeyboard() */ + + + +/* + * xconfigGetDefaultProjectRoot() - scan some common directories for the X + * project root. + * + * Users of this information should be careful to account for the + * modular layout. + */ + +static char *xconfigGetDefaultProjectRoot(void) +{ + char *paths[] = { "/usr/X11R6", "/usr/X11", NULL }; + struct stat stat_buf; + int i; + + for (i = 0; paths[i]; i++) { + + if (stat(paths[i], &stat_buf) == -1) { + continue; + } + + if (S_ISDIR(stat_buf.st_mode)) { + return paths[i]; + } + } + + /* default to "/usr/X11R6", I guess */ + + return paths[0]; + +} /* xconfigGetDefaultProjectRoot() */ + + + + +/* + * get_xserver_information() - parse the versionString (from `X + * -version`) and assign relevant information that we infer from the X + * server version. + * + * Note: this implementation should be shared with nvidia-installer + */ + +static int get_xserver_information(const char *versionString, + int *isXorg, + int *isModular, + int *autoloadsGLX, + int *supportsExtensionSection) +{ +#define XSERVER_VERSION_FORMAT_1 "X Window System Version" +#define XSERVER_VERSION_FORMAT_2 "X.Org X Server" + + int major, minor, found; + const char *ptr; + + /* check if this is an XFree86 X server */ + + if (strstr(versionString, "XFree86 Version")) { + *isXorg = FALSE; + *isModular = FALSE; + *autoloadsGLX = FALSE; + *supportsExtensionSection = FALSE; + return TRUE; + } + + /* this must be an X.Org X server */ + + *isXorg = TRUE; + + /* attempt to parse the major.minor version out of the string */ + + found = FALSE; + + if (((ptr = strstr(versionString, XSERVER_VERSION_FORMAT_1)) != NULL) && + (sscanf(ptr, XSERVER_VERSION_FORMAT_1 " %d.%d", &major, &minor) == 2)) { + found = TRUE; + } + + if (!found && + ((ptr = strstr(versionString, XSERVER_VERSION_FORMAT_2)) != NULL) && + (sscanf(ptr, XSERVER_VERSION_FORMAT_2 " %d.%d", &major, &minor) == 2)) { + found = TRUE; + } + + /* if we can't parse the version, give up */ + + if (!found) return FALSE; + + /* + * isModular: X.Org X11R6.x X servers are monolithic, all others + * are modular + */ + + if (major == 6) { + *isModular = FALSE; + } else { + *isModular = TRUE; + } + + /* + * supportsExtensionSection: support for the "Extension" xorg.conf + * section was added between X.Org 6.7 and 6.8. To account for + * the X server version wrap, it is easier to check for X servers + * that do not support the Extension section: 6.x (x < 8) X + * servers. + */ + + if ((major == 6) && (minor < 8)) { + *supportsExtensionSection = FALSE; + } else { + *supportsExtensionSection = TRUE; + } + + /* + * support for autoloading GLX was added in X.Org 1.5. To account + * for the X server version wrap, it is easier to check for X + * servers that do not support GLX autoloading: 6.x, 7.x, or < 1.5 + * X servers. + */ + + if ((major == 6) || (major == 7) || ((major == 1) && (minor < 5))) { + *autoloadsGLX = FALSE; + } else { + *autoloadsGLX = TRUE; + } + + return TRUE; + +} /* get_xserver_information() */ + + + +/* + * xconfigGetXServerInUse() - try to determine which X server is in use + * (XFree86, Xorg); also determine if the X server supports the + * Extension section of the X config file; support for the "Extension" + * section was added between X.Org 6.7 and 6.8. + * + * Some of the parsing here mimics what is done in the + * check_for_modular_xorg() function in nvidia-installer + */ + +#define NV_LINE_LEN 1024 +#define EXTRA_PATH "/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/usr/bin/X11" +#if defined(NV_SUNOS) +#define XSERVER_BIN_NAME "Xorg" +#else +#define XSERVER_BIN_NAME "X" +#endif + + +void xconfigGetXServerInUse(GenerateOptions *gop) +{ + FILE *stream = NULL; + int xserver = -1; + int isXorg; + int dummy, len, found; + char *cmd, *ptr, *ret; + + gop->supports_extension_section = FALSE; + gop->autoloads_glx = FALSE; + + /* run `X -version` with a PATH that hopefully includes the X binary */ + + cmd = xconfigStrcat("PATH=", gop->x_project_root, ":", + EXTRA_PATH, ":$PATH ", XSERVER_BIN_NAME, + " -version 2>&1", NULL); + + if ((stream = popen(cmd, "r"))) { + char buf[NV_LINE_LEN]; + + /* read in as much of the input as we can fit into the buffer */ + + ptr = buf; + + do { + len = NV_LINE_LEN - (ptr - buf) - 1; + ret = fgets(ptr, len, stream); + ptr = strchr(ptr, '\0'); + } while ((ret != NULL) && (len > 1)); + + /* + * process the `X -version` output to infer relevant + * information from this X server + */ + + found = get_xserver_information(buf, + &isXorg, + &dummy, /* isModular */ + &gop->autoloads_glx, + &gop->supports_extension_section); + + if (found) { + if (isXorg) { + xserver = X_IS_XORG; + } else { + xserver = X_IS_XF86; + } + } else { + xconfigErrorMsg(WarnMsg, "Unable to parse X.Org version string."); + } + } + /* Close the popen()'ed stream. */ + pclose(stream); + free(cmd); + + if (xserver == -1) { + char *xorgpath; + + xorgpath = xconfigStrcat(gop->x_project_root, "/bin/Xorg", NULL); + if (access(xorgpath, F_OK)==0) { + xserver = X_IS_XORG; + } else { + xserver = X_IS_XF86; + } + free(xorgpath); + } + + gop->xserver=xserver; + +} /* xconfigGetXServerInUse() */ + + + +/* + * xconfigGenerateLoadDefaultOptions - initialize a GenerateOptions + * structure with default values by peeking at the file system. + */ + +void xconfigGenerateLoadDefaultOptions(GenerateOptions *gop) +{ + memset(gop, 0, sizeof(GenerateOptions)); + + gop->x_project_root = xconfigGetDefaultProjectRoot(); + + /* XXX What to default the following to? + gop->xserver + gop->keyboard + gop->mouse + gop->keyboard_driver + */ + +} /* xconfigGenerateLoadDefaultOptions() */ diff --git a/XF86Config-parser/Screen.c b/XF86Config-parser/Screen.c index f58d76b..2adcb79 100644 --- a/XF86Config-parser/Screen.c +++ b/XF86Config-parser/Screen.c @@ -79,6 +79,8 @@ static XConfigSymTabRec DisplayTab[] = #define CLEANUP xconfigFreeDisplayList +static int addImpliedScreen(XConfigPtr config); + XConfigDisplayPtr xconfigParseDisplaySubSection (void) { @@ -490,12 +492,12 @@ xconfigValidateScreen (XConfigPtr p) XConfigDevicePtr device; XConfigAdaptorLinkPtr adaptor; - if (!screen) - { - xconfigErrorMsg(ValidationErrorMsg, "At least one Screen section " - "is required."); - return (FALSE); - } + /* + * if we do not have a screen, just return TRUE; we'll add a + * screen later during the Sanitize step + */ + + if (!screen) return TRUE; while (screen) { @@ -559,6 +561,10 @@ int xconfigSanitizeScreen(XConfigPtr p) { XConfigScreenPtr screen = p->screens; XConfigMonitorPtr monitor; + + if (!addImpliedScreen(p)) { + return FALSE; + } while (screen) { @@ -600,8 +606,9 @@ int xconfigSanitizeScreen(XConfigPtr p) screen->monitor_name = xconfigStrdup(monitor->identifier); - if (!xconfigValidateMonitor(p, screen)) - return (FALSE); + if (!xconfigValidateMonitor(p, screen)) { + return FALSE; + } } } @@ -676,4 +683,43 @@ xconfigRemoveMode(XConfigModePtr head, const char *name) } +static int addImpliedScreen(XConfigPtr config) +{ + XConfigScreenPtr screen; + XConfigDevicePtr device; + XConfigMonitorPtr monitor; + if (config->screens) return TRUE; + + xconfigErrorMsg(WarnMsg, "No Screen specified, constructing implicit " + "screen section.\n"); + + /* allocate the new screen section */ + + screen = calloc(1, sizeof(XConfigScreenRec)); + if (!screen) return FALSE; + + screen->identifier = xconfigStrdup("Default Screen"); + + /* + * Use the first device section if there is one. + */ + if (config->devices) { + device = config->devices; + screen->device_name = xconfigStrdup(device->identifier); + screen->device = device; + } + + /* + * Use the first monitor section if there is one. + */ + if (config->monitors) { + monitor = config->monitors; + screen->monitor_name = xconfigStrdup(monitor->identifier); + screen->monitor = monitor; + } + + config->screens = screen; + + return TRUE; +} diff --git a/XF86Config-parser/xf86Parser.h b/XF86Config-parser/xf86Parser.h index 6598d5e..a68962a 100644 --- a/XF86Config-parser/xf86Parser.h +++ b/XF86Config-parser/xf86Parser.h @@ -591,6 +591,10 @@ typedef struct { char *keyboard; char *mouse; char *keyboard_driver; + + int supports_extension_section; + int autoloads_glx; + } GenerateOptions; @@ -724,6 +728,10 @@ void xconfigGenerateAssignScreenAdjacencies(XConfigLayoutPtr layout); void xconfigGeneratePrintPossibleMice(void); void xconfigGeneratePrintPossibleKeyboards(void); +void xconfigGenerateLoadDefaultOptions(GenerateOptions *gop); + +void xconfigGetXServerInUse(GenerateOptions *gop); + /* * check (and update, if necessary) the inputs in the specified layout diff --git a/nvidia-xconfig.c b/nvidia-xconfig.c index ed9cbf5..ae90c16 100644 --- a/nvidia-xconfig.c +++ b/nvidia-xconfig.c @@ -193,59 +193,17 @@ static void print_help(int advanced) /* - * get_default_project_root() - scan some common directories for the X - * project root - * - * Users of this information should be careful to account for the - * modular layout. - */ - -char *get_default_project_root(void) -{ - char *paths[] = { "/usr/X11R6", "/usr/X11", NULL }; - struct stat stat_buf; - int i; - - for (i = 0; paths[i]; i++) { - - if (stat(paths[i], &stat_buf) == -1) { - continue; - } - - if (S_ISDIR(stat_buf.st_mode)) { - return paths[i]; - } - } - - /* default to "/usr/X11R6", I guess */ - - return paths[0]; - -} /* get_default_project_root() */ - - - -/* * parse_commandline() - malloc an Options structure, initialize it, * and fill in any pertinent data from the commandline arguments */ -Options *parse_commandline(int argc, char *argv[]) +void parse_commandline(Options *op, int argc, char *argv[]) { - Options *op; int c, boolval; char *strval; int intval, disable; double doubleval; - op = (Options *) nvalloc(sizeof(Options)); - - op->gop.x_project_root = get_default_project_root(); - op->nvagp = -1; - op->transparent_index = -1; - op->stereo = -1; - op->cool_bits = -1; - op->tv_over_scan = -1.0; while (1) { @@ -748,7 +706,42 @@ Options *parse_commandline(int argc, char *argv[]) op->xconfig = tilde_expansion(op->xconfig); op->output_xconfig = tilde_expansion(op->output_xconfig); + + return; + fail: + + fprintf(stderr, "\n"); + fprintf(stderr, "Invalid commandline, please run `%s --help` " + "for usage information.\n", argv[0]); + fprintf(stderr, "\n"); + exit(1); + +} /* parse_commandline() */ + + + +/* + * load_default_options - malloc an Options structure + * and initialize it with default values. + * + */ + +Options *load_default_options(void) +{ + Options *op; + + op = (Options *) nvalloc(sizeof(Options)); + if (!op) return NULL; + + op->nvagp = -1; + op->transparent_index = -1; + op->stereo = -1; + op->cool_bits = -1; + op->tv_over_scan = -1.0; + + xconfigGenerateLoadDefaultOptions(&op->gop); + /* * XXX save the option structure so that printing routines can * access it (and so that we don't have to carry the op everywhere @@ -760,20 +753,9 @@ Options *parse_commandline(int argc, char *argv[]) __op = op; } - return (op); - - fail: - - fprintf(stderr, "\n"); - fprintf(stderr, "Invalid commandline, please run `%s --help` " - "for usage information.\n", argv[0]); - fprintf(stderr, "\n"); - exit(1); - - return NULL; - -} /* parse_commandline() */ + return op; +} /* load_default_options() */ @@ -1096,99 +1078,6 @@ int update_xconfig(Options *op, XConfigPtr config) /* - * get_xserver_in_use() - try to determine which X server is in use - * (XFree86, Xorg); also determine if the X server supports the - * Extension section of the X config file; support for the "Extension" - * section was added between X.Org 6.7 and 6.8. - * - * Some of the parsing here mimics what is done in the - * check_for_modular_xorg() function in nvidia-installer - */ - -#define NV_LINE_LEN 1024 -#define EXTRA_PATH "/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/usr/bin/X11" -#define VERSION_FORMAT "X Protocol Version %d, Revision %d, Release %d.%d" - -static void get_xserver_in_use(Options *op) -{ -#if defined(NV_SUNOS) - - /* - * Solaris x86/x64 always uses X.Org 6.8 or higher, atleast as far - * as the NVIDIA X driver is concerned - */ - - op->gop.xserver = X_IS_XORG; - op->supports_extension_section = TRUE; - -#else - - FILE *stream = NULL; - int xserver = -1; - int dummy, len, release_major, release_minor; - char *cmd, *ptr, *ret; - - op->supports_extension_section = FALSE; - - /* run `X -version` with a PATH that hopefully includes the X binary */ - - cmd = xconfigStrcat("PATH=", op->gop.x_project_root, ":", - EXTRA_PATH, ":$PATH X -version 2>&1", NULL); - - if ((stream = popen(cmd, "r"))) { - char buf[NV_LINE_LEN]; - - /* read in as much of the input as we can fit into the buffer */ - - ptr = buf; - - do { - len = NV_LINE_LEN - (ptr - buf) - 1; - ret = fgets(ptr, len, stream); - ptr = strchr(ptr, '\0'); - } while ((ret != NULL) && (len > 1)); - - /* Check if this is an XFree86 release */ - - if (strstr(buf, "XFree86 Version") != NULL) { - xserver = X_IS_XF86; - op->supports_extension_section = FALSE; - } else { - xserver = X_IS_XORG; - if ((ptr = strstr(buf, "X Protocol Version")) != NULL && - sscanf(ptr, VERSION_FORMAT, &dummy, &dummy, - &release_major, &release_minor) == 4) { - - if ((release_major > 6) || - ((release_major == 6) && (release_minor >= 8))) { - op->supports_extension_section = TRUE; - } - } - } - } - /* Close the popen()'ed stream. */ - pclose(stream); - free(cmd); - - if (xserver == -1) { - char *xorgpath; - - xorgpath = xconfigStrcat(op->gop.x_project_root, "/bin/Xorg", NULL); - if (access(xorgpath, F_OK)==0) { - xserver = X_IS_XORG; - } else { - xserver = X_IS_XF86; - } - free(xorgpath); - } - - op->gop.xserver=xserver; -#endif -} /* get_xserver_in_use */ - - - -/* * main program entry point * * The intended behavior is that, by default, nvidia-xconfig make the @@ -1205,9 +1094,18 @@ int main(int argc, char *argv[]) int ret; XConfigPtr config = NULL; + + /* Load defaults */ + + op = load_default_options(); + if (!op) { + fprintf(stderr, "\nOut of memory error.\n\n"); + return 1; + } + /* parse the commandline */ - op = parse_commandline(argc, argv); + parse_commandline(op, argc, argv); /* * first, check for any of special options that cause us to exit @@ -1259,7 +1157,7 @@ int main(int argc, char *argv[]) /* * Get which X server is in use: Xorg or XFree86 */ - get_xserver_in_use(op); + xconfigGetXServerInUse(&op->gop); /* * if we failed to find the system's config file, generate a new diff --git a/nvidia-xconfig.h b/nvidia-xconfig.h index d15c399..a0d4dc6 100644 --- a/nvidia-xconfig.h +++ b/nvidia-xconfig.h @@ -178,8 +178,6 @@ typedef struct __options { TextRows add_modes_list; TextRows remove_modes; - int supports_extension_section; - GenerateOptions gop; } Options; @@ -222,7 +222,7 @@ void validate_composite(Options *op, XConfigPtr config) */ if (disable_composite && - (op->supports_extension_section || + (op->gop.supports_extension_section || config->extensions || GET_BOOL_OPTION(op->boolean_options, COMPOSITE_BOOL_OPTION))) { |