static int process_config_file_attributes(const char *file, ParsedAttributeWrapper *w, const char *display_name) { int i, j, ret, found, n = 0; CtrlHandles **h = NULL; /* * make sure that all ParsedAttributes have displays (this will do * nothing if we already have a display name */ for (i = 0; w[i].line != -1; i++) { nv_assign_default_display(&w[i].a, display_name); } /* build the list of CtrlHandles */ for (i = 0; w[i].line != -1; i++) { found = NV_FALSE; for (j = 0; j < n; j++) { if (nv_strcasecmp(h[j]->display, w[i].a.display)) { w[i].h = h[j]; found = NV_TRUE; break; } } /* * no handle found for this display, need to create a new * handle. * * XXX we should really just build a list of what ctrl_handles * we need, and what attributes on which ctrl_handles, so that * we don't have to pass NV_CTRL_ATTRIBUTES_ALL_SUBSYSTEMS to * NvCtrlAttributeInit (done in nv_alloc_ctrl_handles()) * unless we really need it. */ if (!found) { h = realloc(h, sizeof(CtrlHandles *) * (n + 1)); h[n] = nv_alloc_ctrl_handles(w[i].a.display); w[i].h = h[n]; n++; } } /* now process each attribute, passing in the correct CtrlHandles */ for (i = 0; w[i].line != -1; i++) { ret = nv_process_parsed_attribute(&w[i].a, w[i].h, NV_TRUE, NV_FALSE, "on line %d of configuration file " "'%s'", w[i].line, file); /* * We do not fail if processing the attribute failed. If the * GPU or the X config changed (for example stereo is * disabled), some attributes written in the config file may * not be advertised by the the NVCTRL extension (for example * the control to force stereo) */ } /* free all the CtrlHandles we allocated */ for (i = 0; i < n; i++) { nv_free_ctrl_handles(h[i]); } if (h) free(h); return NV_TRUE; } /* process_config_file_attributes() */
int main(int argc, char **argv) { ConfigProperties conf; ParsedAttribute *p; CtrlHandles *h; Options *op; int ret; char *dpy = NULL; int gui = 0; /* * initialize the ui * * XXX it would be nice if we didn't do this up front, since we * may not even use the gui, but we want the toolkit to have a * chance to parse the commandline before we do... * * gui flag used to decide if ctk should be used or not, as * the user might just use control the display from a remote console * but for some reason cannot initialize the gtk gui. - TY 2005-05-27 */ if (ctk_init_check(&argc, &argv)) { dpy = ctk_get_display(); gui = 1; } /* parse the commandline */ op = parse_command_line(argc, argv, dpy); /* quit here if we don't have a ctrl_display - TY 2005-05-27 */ if (op->ctrl_display == NULL) { nv_error_msg("The control display is undefined; please run " "`%s --help` for usage information.\n", argv[0]); return 1; } /* process any query or assignment commandline options */ if (op->num_assignments || op->num_queries) { ret = nv_process_assignments_and_queries(op); return ret ? 0 : 1; } /* initialize the parsed attribute list */ p = nv_parsed_attribute_init(); /* initialize the ConfigProperties */ init_config_properties(&conf); /* * Rewrite the X server settings to configuration file * and exit, without starting a Graphical User Interface. */ if (op->rewrite) { nv_parsed_attribute_clean(p); h = nv_alloc_ctrl_handles(op->ctrl_display); if(!h || !h->dpy) return 1; ret = nv_write_config_file(op->config, h, p, &conf); nv_free_ctrl_handles(h); nv_parsed_attribute_free(p); free(op); op = NULL; return ret ? 0 : 1; } /* upload the data from the config file */ if (!op->no_load) { ret = nv_read_config_file(op->config, op->ctrl_display, p, &conf); } else { ret = 1; } /* * if the user requested that we only load the config file, then * exit now */ if (op->only_load) { return ret ? 0 : 1; } /* * past this point, we need to be able to create a gui; fail if * the gui isn't available; TY 2005-05-27 */ if (gui == 0) { nv_error_msg("Unable to create nvidia-settings GUI; please run " "`%s --help` for usage information.\n", argv[0]); return 1; } /* allocate the CtrlHandles for this X screen */ h = nv_alloc_ctrl_handles(op->ctrl_display); if (!h || !h->dpy) { return 1; } /* pass control to the gui */ ctk_main(p, &conf, h, op->page); /* write the configuration file */ nv_write_config_file(op->config, h, p, &conf); /* cleanup */ nv_free_ctrl_handles(h); nv_parsed_attribute_free(p); return 0; } /* main() */
void print_glxinfo(const char *display_name) { int screen; CtrlHandles *h; CtrlHandleTarget *t; ReturnStatus status = NvCtrlSuccess; char *direct_rendering = NULL; char *glx_extensions = NULL; char *server_vendor = NULL; char *server_version = NULL; char *server_extensions = NULL; char *client_vendor = NULL; char *client_version = NULL; char *client_extensions = NULL; char *opengl_vendor = NULL; char *opengl_renderer = NULL; char *opengl_version = NULL; char *opengl_extensions = NULL; GLXFBConfigAttr *fbconfig_attribs = NULL; char *formated_ext_str = NULL; h = nv_alloc_ctrl_handles(display_name); if ( h == NULL ) { return; } /* Print information for each screen */ for (screen = 0; screen < h->targets[X_SCREEN_TARGET].n; screen++) { t = &h->targets[X_SCREEN_TARGET].t[screen]; /* No screen, move on */ if ( !t->h ) continue; nv_msg(NULL, "GLX Information for %s:", t->name); /* Get GLX information */ status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_DIRECT_RENDERING, &direct_rendering); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_GLX_EXTENSIONS, &glx_extensions); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } if ( glx_extensions != NULL ) { formated_ext_str = format_extension_list(glx_extensions); if ( formated_ext_str != NULL ) { free(glx_extensions); glx_extensions = formated_ext_str; } } /* Get server GLX information */ status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_SERVER_VENDOR, &server_vendor); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_SERVER_VERSION, &server_version); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_SERVER_EXTENSIONS, &server_extensions); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } if ( server_extensions != NULL ) { formated_ext_str = format_extension_list(server_extensions); if ( formated_ext_str != NULL ) { free(server_extensions); server_extensions = formated_ext_str; } } /* Get client GLX information */ status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_CLIENT_VENDOR, &client_vendor); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_CLIENT_VERSION, &client_version); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_CLIENT_EXTENSIONS, &client_extensions); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } if ( client_extensions != NULL ) { formated_ext_str = format_extension_list(client_extensions); if ( formated_ext_str != NULL ) { free(client_extensions); client_extensions = formated_ext_str; } } /* Get OpenGL information */ status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_OPENGL_VENDOR, &opengl_vendor); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_OPENGL_RENDERER, &opengl_renderer); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_OPENGL_VERSION, &opengl_version); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } status = NvCtrlGetStringAttribute(t->h, NV_CTRL_STRING_GLX_OPENGL_EXTENSIONS, &opengl_extensions); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } if ( opengl_extensions != NULL ) { formated_ext_str = format_extension_list(opengl_extensions); if ( formated_ext_str != NULL ) { free(opengl_extensions); opengl_extensions = formated_ext_str; } } /* Get FBConfig information */ status = NvCtrlGetVoidAttribute(t->h, NV_CTRL_ATTR_GLX_FBCONFIG_ATTRIBS, (void *)(&fbconfig_attribs)); if ( status != NvCtrlSuccess && status != NvCtrlNoAttribute ) { goto finish; } /* Print results */ nv_msg(TAB, "direct rendering: %s", NULL_TO_EMPTY(direct_rendering)); nv_msg(TAB, "GLX extensions:"); nv_msg(" ", NULL_TO_EMPTY(glx_extensions)); nv_msg(" ", "\n"); nv_msg(TAB, "server glx vendor string: %s", NULL_TO_EMPTY(server_vendor)); nv_msg(TAB, "server glx version string: %s", NULL_TO_EMPTY(server_version)); nv_msg(TAB, "server glx extensions:"); nv_msg(" ", NULL_TO_EMPTY(server_extensions)); nv_msg(" ", "\n"); nv_msg(TAB, "client glx vendor string: %s", NULL_TO_EMPTY(client_vendor)); nv_msg(TAB, "client glx version string: %s", NULL_TO_EMPTY(client_version)); nv_msg(TAB, "client glx extensions:"); nv_msg(" ", NULL_TO_EMPTY(client_extensions)); nv_msg(" ", "\n"); nv_msg(TAB, "OpenGL vendor string: %s", NULL_TO_EMPTY(opengl_vendor)); nv_msg(TAB, "OpenGL renderer string: %s", NULL_TO_EMPTY(opengl_renderer)); nv_msg(TAB, "OpenGL version string: %s", NULL_TO_EMPTY(opengl_version)); nv_msg(TAB, "OpenGL extensions:"); nv_msg(" ", NULL_TO_EMPTY(opengl_extensions)); #ifdef GLX_VERSION_1_3 if ( fbconfig_attribs != NULL ) { nv_msg(" ", "\n"); print_fbconfig_attribs(fbconfig_attribs); } #endif fflush(stdout); /* Free memory used */ SAFE_FREE(server_vendor); SAFE_FREE(server_version); SAFE_FREE(server_extensions); SAFE_FREE(client_vendor); SAFE_FREE(client_version); SAFE_FREE(client_extensions); SAFE_FREE(direct_rendering); SAFE_FREE(glx_extensions); SAFE_FREE(opengl_vendor); SAFE_FREE(opengl_renderer); SAFE_FREE(opengl_version); SAFE_FREE(opengl_extensions); SAFE_FREE(fbconfig_attribs); } /* Done looking at all screens */ /* Fall through */ finish: if ( status == NvCtrlError ) { nv_error_msg("Error fetching GLX Information: %s", NvCtrlAttributesStrError(status) ); } /* Free any leftover memory used */ SAFE_FREE(server_vendor); SAFE_FREE(server_version); SAFE_FREE(server_extensions); SAFE_FREE(client_vendor); SAFE_FREE(client_version); SAFE_FREE(client_extensions); SAFE_FREE(direct_rendering); SAFE_FREE(glx_extensions); SAFE_FREE(opengl_vendor); SAFE_FREE(opengl_renderer); SAFE_FREE(opengl_version); SAFE_FREE(opengl_extensions); SAFE_FREE(fbconfig_attribs); nv_free_ctrl_handles(h); } /* print_glxinfo() */