在Linux中使用C,是否可以改变观看屏幕的亮度? 除了在我的Ubuntu和Fedora安装上运行外,这不会是可移植的。 我在问如何与os进行交互来改变亮度。
我会从下面的Ubuntu pacakges列表中选择,这个工具可以让你管理你的屏幕的亮度(提示:这取决于品牌)
nvidia-settings - Tool of configuring the NVIDIA graphics driver smartdimmer - Change LCD brightness on Geforce cards armada-backlight - adjust backlight of Compaq Armada laptops (E300, M500, M700) ddccontrol - a program to control monitor parameters eeepc-acpi-scripts - Scripts to support suspend and hotkeys on the Asus Eee PC laptop fnfxd - ACPI and hotkey daemon for Toshiba laptops gddccontrol - a program to control monitor parameters spicctrl - Sony Vaio controller program to set LCD backlight brightness tpb - program to use the IBM ThinkPad(tm) special keys xfce4-power-manager - power manager for Xfce desktop xfce4-power-manager-plugins - power manager plugins for Xfce panel xvattr - Utility to change Xv attributes
一旦你选择了它,
sudo apt-get build-dep <pkgname> apt-get source --compile <pkgname>
应该让你走上正轨
戳/sys/class/backlight/*/brightness
。 是的,即使在C
是的,但不能移植 – 你需要一个平台特定的功能,C标准库中没有任何东西。
查看xbacklight源代码 。 例如,以下代码将屏幕亮度设置为50%。
// brightness.c // gcc -o brightness brightness.c -lXrandr -lX11 #include <X11/Xatom.h> #include <X11/Xlib.h> #include <X11/extensions/Xrandr.h> #define BRIGHTNESS 0.5 // Target brightness between 0.0 and 1.0 int main(int argc, char *argv[]) { Display *dpy; static Atom backlight; int screen = 0, o = 0; Window root; XRRScreenResources *resources; RROutput output; XRRPropertyInfo *info; double min, max; long value; dpy = XOpenDisplay(NULL); backlight = XInternAtom (dpy, "Backlight", True); root = RootWindow(dpy, screen); resources = XRRGetScreenResources(dpy, root); output = resources->outputs[o]; info = XRRQueryOutputProperty(dpy, output, backlight); min = info->values[0]; max = info->values[1]; XFree(info); // Don't need this anymore XRRFreeScreenResources(resources); // or this value = BRIGHTNESS * (max - min) + min; XRRChangeOutputProperty(dpy, output, backlight, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &value, 1); XFlush(dpy); XSync(dpy, False); return 0; }