summaryrefslogtreecommitdiffstats
path: root/src/x.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/x.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/src/x.c b/src/x.c
index dde874e..68b27e4 100644
--- a/src/x.c
+++ b/src/x.c
@@ -25,50 +25,51 @@
#include <pthread.h>
-static Display* restrict display;
+static Display *restrict display;
-static double get_brightness(int screen)
+static double
+get_brightness(int screen)
{
- auto Window root = XRootWindow(display, screen);
- auto long width = (long)XDisplayWidth(display, screen);
- auto long height = (long)XDisplayHeight(display, screen);
- auto XImage* restrict image = XGetImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap);
- register double sum = 0;
- register unsigned char* restrict pixels;
- register unsigned char* restrict end;
-
- if (image == NULL)
- return -1;
-
- pixels = (unsigned char*)(image->data);
- end = pixels + width * height * 4;
-
- while (pixels != end)
- {
- sum += LINEAR_MAP[*pixels++];
- sum += LINEAR_MAP[*pixels++];
- sum += LINEAR_MAP[*pixels++];
- pixels++;
- }
-
- XDestroyImage(image);
- return sum / (double)(height * width * 3);
+ auto Window root = XRootWindow(display, screen);
+ auto long width = (long)XDisplayWidth(display, screen);
+ auto long height = (long)XDisplayHeight(display, screen);
+ auto XImage *restrict image = XGetImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap);
+ register double sum = 0;
+ register unsigned char *restrict pixels;
+ register unsigned char *restrict end;
+
+ if (!image)
+ return -1;
+
+ pixels = (unsigned char *)(image->data);
+ end = pixels + width * height * 4;
+
+ while (pixels != end) {
+ sum += LINEAR_MAP[*pixels++];
+ sum += LINEAR_MAP[*pixels++];
+ sum += LINEAR_MAP[*pixels++];
+ pixels++;
+ }
+
+ XDestroyImage(image);
+ return sum / (double)(height * width * 3);
}
-int main(void)
+int
+main(void)
{
- int screen, screens;
-
- if (display = XOpenDisplay(NULL), display == NULL)
- return 1;
-
- screens = (size_t)ScreenCount(display);
- for (screen = 0; screen < screens; screen++)
- fprintf(stderr, "%lf\n", get_brightness(screen));
-
- XCloseDisplay(display);
- return 0;
-}
+ int screen, screens;
+
+ display = XOpenDisplay(NULL)
+ if (!display)
+ return 1;
+ screens = (size_t)ScreenCount(display);
+ for (screen = 0; screen < screens; screen++)
+ fprintf(stderr, "%lf\n", get_brightness(screen));
+
+ XCloseDisplay(display);
+ return 0;
+}