int main(int argc, char *argv[]) { Display *dpy; Bool ret; int screen, retval, setval = -1; int display_devices, mask; NVCTRLAttributeValidValuesRec valid_values; /* * If there is a commandline argument, interpret it as the value * to use to set DVC. */ if (argc == 2) { setval = atoi(argv[1]); } /* * Open a display connection, and make sure the NV-CONTROL X * extension is present on the screen we want to use. */ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Cannot open display '%s'.\n", XDisplayName(NULL)); return 1; } screen = GetNvXScreen(dpy); /* * Get the bitmask of enabled display devices */ ret = XNVCTRLQueryAttribute(dpy, screen, 0, NV_CTRL_ENABLED_DISPLAYS, &display_devices); if (!ret) { fprintf(stderr, "Unable to determine enabled display devices for " "screen %d of '%s'\n", screen, XDisplayName(NULL)); return 1; } /* * loop over each enabled display device */ for (mask = 1; mask < (1<<24); mask <<= 1) { if (!(mask & display_devices)) continue; /* * Query the valid values for NV_CTRL_DIGITAL_VIBRANCE */ ret = XNVCTRLQueryValidAttributeValues(dpy, screen, mask, NV_CTRL_DIGITAL_VIBRANCE, &valid_values); if (!ret) { fprintf(stderr, "Unable to query the valid values for " "NV_CTRL_DIGITAL_VIBRANCE on display device %s of " "screen %d of '%s'.\n", display_device_name(mask), screen, XDisplayName(NULL)); return 1; } /* we assume that NV_CTRL_DIGITAL_VIBRANCE is a range type */ if (valid_values.type != ATTRIBUTE_TYPE_RANGE) { fprintf(stderr, "NV_CTRL_DIGITAL_VIBRANCE is not of " "type RANGE.\n"); return 1; } /* print the range of valid values */ printf("Valid values for NV_CTRL_DIGITAL_VIBRANCE: " "(%" PRId64 " - %" PRId64 ").\n", valid_values.u.range.min, valid_values.u.range.max); /* * if a value was specified on the commandline, set it; * otherwise, query the current value */ if (setval != -1) { XNVCTRLSetAttribute(dpy, screen, mask, NV_CTRL_DIGITAL_VIBRANCE, setval); XFlush(dpy); printf("Set NV_CTRL_DIGITAL_VIBRANCE to %d on display device " "%s of screen %d of '%s'.\n", setval, display_device_name(mask), screen, XDisplayName(NULL)); } else { ret = XNVCTRLQueryAttribute(dpy, screen, mask, NV_CTRL_DIGITAL_VIBRANCE, &retval); printf("The current value of NV_CTRL_DIGITAL_VIBRANCE " "is %d on display device %s of screen %d of '%s'.\n", retval, display_device_name(mask), screen, XDisplayName(NULL)); } } return 0; }
int main(int argc, char *argv[]) { Display *dpy; Bool ret; int screen, display_devices, mask, major, minor; char *str; int nDisplayDevice; /* * Open a display connection, and make sure the NV-CONTROL X * extension is present on the screen we want to use. */ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Cannot open display '%s'.\n\n", XDisplayName(NULL)); return 1; } screen = GetNvXScreen(dpy); ret = XNVCTRLQueryVersion(dpy, &major, &minor); if (ret != True) { fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n\n", XDisplayName(NULL)); return 1; } /* * query the connected display devices on this X screen and print * basic information about each X screen */ ret = XNVCTRLQueryAttribute(dpy, screen, 0, NV_CTRL_CONNECTED_DISPLAYS, &display_devices); if (!ret) { fprintf(stderr, "Failed to query the enabled Display Devices.\n\n"); return 1; } int pci_bus; int pci_device; int pci_func; ret = XNVCTRLQueryTargetAttribute(dpy, NV_CTRL_TARGET_TYPE_GPU, 0 /* Just query first GPU */, 0, NV_CTRL_PCI_BUS, &pci_bus); ret = XNVCTRLQueryTargetAttribute(dpy, NV_CTRL_TARGET_TYPE_GPU, 0 /* Just query first GPU */, 0, NV_CTRL_PCI_DEVICE, &pci_device); ret = XNVCTRLQueryTargetAttribute(dpy, NV_CTRL_TARGET_TYPE_GPU, 0 /* Just query first GPU */, 0, NV_CTRL_PCI_FUNCTION, &pci_func); dbset("system.hardware.nvidia.busid=%i:%i:%i", pci_bus, pci_device, pci_func); nDisplayDevice = 0; for (mask = 1; mask < (1 << 24); mask <<= 1) { if (display_devices & mask) { XNVCTRLQueryStringAttribute(dpy, screen, mask, NV_CTRL_STRING_DISPLAY_DEVICE_NAME, &str); dbset("system.x11.display.%i.device=%s" , nDisplayDevice, display_device_name(mask)); dbset("system.x11.display.%i.mode.0=nvidia-auto-select", nDisplayDevice); dbset("system.x11.display.%i.default=nvidia-auto-select", nDisplayDevice); printf("%i:%s:0x%08x:%s\n", nDisplayDevice, display_device_name(mask), mask, str); nDisplayDevice++; } } if (nDisplayDevice > 1) { // more than one screen found dbset("system.x11.dualhead.enabled=1"); } else { dbset("system.x11.dualhead.enabled=0"); } char *dummy; for (; nDisplayDevice <= 3; nDisplayDevice++) { if (asprintf(&dummy, "system.x11.display.%i", nDisplayDevice) >= 0) { dbremove(dummy); free(dummy); } } return 0; }