Domanda

Utilizzando C in Linux, sarebbe possibile modificare la luminosità dello schermo di visualizzazione? Questo non dovrebbe essere portatile altro che correre sulle mie installazioni di Ubuntu e Fedora. Sto chiedendo a come avrei interfacciarsi con il sistema operativo per modificare la luminosità.

È stato utile?

Soluzione

Mi piacerebbe iniziare con la selezione dal seguente elenco di ubuntu Pacakges, lo strumento che consente di gestire la luminosità dello schermo (suggerimento: dipende dalla marca)

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

Dopo aver selezionato che,

sudo apt-get build-dep <pkgname>
apt-get source --compile <pkgname> 

dovrebbe farti sulla strada giusta

Altri suggerimenti

/sys/class/backlight/*/brightness

Poke. Sì, anche in C.

Sì, ma non portabile -. È necessaria una funzione di piattaforma specifica, non v'è nulla nella libreria standard C

Controlla la xbacklight fonte . Ad esempio, il codice seguente imposta la luminosità dello schermo al 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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top