static void print_table_entry(NVCTRLAttributePermissionsRec *perms, const int index, const char *name) { /* * Don't print the attribute if *both* the permissions are empty * and the attribute table was missing an entry for the attribute. * Either condition by itself is acceptable: * * - Event-only attributes (e.g., NV_CTRL_GVO_CSC_CHANGED_EVENT) * don't have any permissions. * * - A missing table entry could just mean the table is stale * relative to NVCtrl.h. */ if ((perms->permissions == 0) && (name == NULL)) { return; } printf(" (%3d) [Perms: ", index); print_perms(perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms->type)); printf("] - %s\n", name ? name : "Unknown"); }
int main(void) { Display *dpy; Bool ret; int event_base, error_base, major, minor, screens, i; char *str; /* * open a connection to the X server indicated by the DISPLAY * environment variable */ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Cannot open display '%s'.\n", XDisplayName(NULL)); return 1; } /* * check if the NV-CONTROL X extension is present on this X server */ ret = XNVCTRLQueryExtension(dpy, &event_base, &error_base); if (ret != True) { fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", XDisplayName(NULL)); return 1; } /* * query the major and minor extension version */ ret = XNVCTRLQueryVersion(dpy, &major, &minor); if (ret != True) { fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", XDisplayName(NULL)); return 1; } /* * print statistics thus far */ printf("NV-CONTROL X extension present\n"); printf(" version : %d.%d\n", major, minor); printf(" event base : %d\n", event_base); printf(" error base : %d\n", error_base); /* * loop over each screen, and determine if each screen is * controlled by the NVIDIA X driver (and thus supports the * NV-CONTROL X extension); then, query the string attributes on * the screen. */ screens = ScreenCount(dpy); for (i = 0; i < screens; i++) { if (XNVCTRLIsNvScreen(dpy, i)) { printf("Screen %d supports the NV-CONTROL X extension\n", i); ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_PRODUCT_NAME, &str); if (ret) { printf(" GPU : %s\n", str); XFree(str); } ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_VBIOS_VERSION, &str); if (ret) { printf(" VideoBIOS : %s\n", str); XFree(str); } ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, &str); if (ret) { printf(" Driver version : %s\n", str); XFree(str); } } } /* * print attribute permission and type information. */ printf("Attributes (Integers):\n"); for (i = 0; i < NV_CTRL_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_int_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (Strings):\n"); for (i = 0; i < NV_CTRL_STRING_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_str_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryStringAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (Binary Data):\n"); for (i = 0; i < NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_bin_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryBinaryDataAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (String Operations):\n"); for (i = 0; i < NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_strop_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryStringOperationAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } /* * close the display connection */ XCloseDisplay(dpy); return 0; }