diff --git a/AUTHORS b/AUTHORS index a9af2916..ed8b650b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -24,7 +24,7 @@ affinity akash battery_percent and battery_bar -Asbjørn Zweidorff Kjær +Asbj�rn Zweidorff Kj�r support for EVE-Online skill monitoring Aseem Mohanty @@ -122,7 +122,7 @@ Gwenhael LE MOINE Hannu Saransaari Main code -Henri Häkkinen +Henri H�kkinen MOC support hinokind @@ -170,7 +170,7 @@ Jonas Koelker Joshua Gerrish mpd password patch -Jørgen P. Tjernø +J�rgen P. Tjern� Restores default settings before loading new config file in SIGHUP Some cleaning and commenting apparently :) SIGHUP config file reload @@ -205,7 +205,7 @@ Lassi Selander Lauri Hakkarainen Some translating, web and other stuff -Leszek Krupiñski +Leszek Krupi�ski Battery number for ACPI battery Load average bug fix @@ -278,6 +278,9 @@ Phil Psychon a bunch of code cleanups +Rogier Reerink + Intel backlight support + roiban adi hex colour patch @@ -314,7 +317,7 @@ Szymon Boniecki Thomas Cort CPU frequency patch for alpha -Toke Høiland-Jørgensen +Toke H�iland-J�rgensen systemd journal support Toni @@ -358,5 +361,5 @@ zimba-tm zotrix FreeBSD patch for <10 procs -Daniel Beßler +Daniel Be�ler argb visual patch diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 53b84608..54334a59 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -259,6 +259,9 @@ option(BUILD_JOURNAL "Enable support for reading from the systemd journal" option(BUILD_PULSEAUDIO "Enable support for Pulseaudio's default sink and source" false) +option(BUILD_INTEL_BACKLIGHT + "Enable support for Intel backlight" false) + option(BUILD_HSV_GRADIENT "Enable gradient in HSV colour space" true) message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) diff --git a/cmake/config.h.in b/cmake/config.h.in index c53ff82d..f2411517 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -107,6 +107,8 @@ #cmakedefine BUILD_PULSEAUDIO 1 +#cmakedefine BUILD_INTEL_BACKLIGHT 0 + #cmakedefine BUILD_IPV6 1 #cmakedefine BUILD_HTTP 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7162b749..059d6522 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -282,6 +282,11 @@ if(BUILD_PULSEAUDIO) set(optional_sources ${optional_sources} ${pulseaudio}) endif(BUILD_PULSEAUDIO) +if(BUILD_INTEL_BACKLIGHT) + set(intel_backlight intel_backlight.cc intel_backlight.h) + set(optional_sources ${optional_sources} ${intel_backlight}) +endif(BUILD_INTEL_BACKLIGHT) + if(BUILD_HSV_GRADIENT) set(hsv_gradient hsv_gradient.cc hsv_gradient.h) set(optional_sources ${optional_sources} ${hsv_gradient}) diff --git a/src/core.cc b/src/core.cc index ae044d0a..92c56248 100644 --- a/src/core.cc +++ b/src/core.cc @@ -107,6 +107,9 @@ #ifdef BUILD_PULSEAUDIO #include "pulseaudio.h" #endif /* BUILD_PULSEAUDIO */ +#ifdef BUILD_INTEL_BACKLIGHT +#include "intel_backlight.h" +#endif /* BUILD_INTEL_BACKLIGHT */ /* check for OS and include appropriate headers */ #if defined(__linux__) @@ -1974,6 +1977,11 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, obj->callbacks.free = &free_pulseaudio; init_pulseaudio(obj); #endif /* BUILD_PULSEAUDIO */ +#ifdef BUILD_INTEL_BACKLIGHT + END OBJ(intel_backlight, 0) obj->callbacks.print = &print_intel_backlight; + obj->callbacks.free = &free_intel_backlight; + init_intel_backlight(obj); +#endif /* BUILD_INTEL_BACKLIGHT */ END { auto *buf = static_cast(malloc(text_buffer_size.get(*state))); diff --git a/src/intel_backlight.cc b/src/intel_backlight.cc new file mode 100644 index 00000000..92852cf7 --- /dev/null +++ b/src/intel_backlight.cc @@ -0,0 +1,107 @@ +/* + * + * Conky, a system monitor, based on torsmo. + * + * Any original torsmo code is licensed under the BSD license. + * All code written since the fork of torsmo is licensed under the GPL. + * Please see COPYING for details. + * + * Copyright (c) 2021 Rogier Reerink + * (See AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "intel_backlight.h" +#include "logging.h" + +#define FS_BRIGHTNESS_MAX "/sys/class/backlight/intel_backlight/max_brightness" +#define FS_BRIGHTNESS_CURRENT "/sys/class/backlight/intel_backlight/brightness" + +struct backlight { + FILE *fp_max; + unsigned max; + FILE *fp_current; + unsigned current; +}; + +void open_backlight(struct backlight *bl) { + bl->fp_max = fopen(FS_BRIGHTNESS_MAX, "r"); + if (bl->fp_max == NULL) { + NORM_ERR("Failed to open file: '" FS_BRIGHTNESS_MAX "'."); + } + bl->fp_current = fopen(FS_BRIGHTNESS_CURRENT, "r"); + if (bl->fp_current == NULL) { + NORM_ERR("Failed to open file: '" FS_BRIGHTNESS_CURRENT "'."); + } +} + +void read_backlight(struct backlight *bl) { + FILE *fp_max, *fp_current; + fp_max = bl->fp_max; + if (fp_max != NULL) { + rewind(fp_max); + fflush(fp_max); + if (fscanf(fp_max, "%u", &(bl->max)) < 0) { + NORM_ERR("Failed to read maximum brightness."); + } + } else { + bl->max = 0; + } + fp_current = bl->fp_current; + if (fp_current != NULL) { + rewind(fp_current); + fflush(fp_current); + if (fscanf(fp_current, "%u", &(bl->current)) < 0) { + NORM_ERR("Failed to read current brightness."); + } + } else { + bl->current = 0; + } +} + +unsigned get_backlight_percent(struct backlight *bl) { + read_backlight(bl); + if (bl->max == 0) { + return 0; + } else { + return bl->current * 100.0 / bl->max + 0.5; + } +} + +void close_backlight(struct backlight *bl) { + if (bl->fp_max != NULL) { fclose(bl->fp_max); } + if (bl->fp_current != NULL) { fclose(bl->fp_current); } +} + +void init_intel_backlight(struct text_object *obj) { + struct backlight *bl = (struct backlight *)malloc(sizeof(struct backlight)); + open_backlight(bl); + obj->data.opaque = bl; +} + +void free_intel_backlight(struct text_object *obj) { + struct backlight *bl = (struct backlight *)obj->data.opaque; + close_backlight(bl); + free(bl); +} + +void print_intel_backlight(struct text_object *obj, char *p, + unsigned int p_max_size) { + struct backlight *bl = (struct backlight *)obj->data.opaque; + unsigned percent = get_backlight_percent(bl); + snprintf(p, p_max_size, "%d", percent); +} \ No newline at end of file diff --git a/src/intel_backlight.h b/src/intel_backlight.h new file mode 100644 index 00000000..6c223823 --- /dev/null +++ b/src/intel_backlight.h @@ -0,0 +1,39 @@ +/* + * + * Conky, a system monitor, based on torsmo. + * + * Any original torsmo code is licensed under the BSD license. + * All code written since the fork of torsmo is licensed under the GPL. + * Please see COPYING for details. + * + * Copyright (c) 2021 Rogier Reerink + * (See AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef _INTEL_BACKLIGHT_H +#define _INTEL_BACKLIGHT_H + +#include "conky.h" +#include "text_object.h" + +void init_intel_backlight(struct text_object *obj); +void free_intel_backlight(struct text_object *obj); +void print_intel_backlight(struct text_object *obj, char *p, + unsigned int p_max_size); + +#endif /* _INTEL_BACKLIGHT_H */ \ No newline at end of file