Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f475f18ce8 | ||
|
|
078b9bf1e3 |
@@ -2,7 +2,7 @@ include(CMakeDependentOption)
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(rexbacklight)
|
||||
set(rexbacklight_VERSION_MAJOR 1)
|
||||
set(rexbacklight_VERSION_MINOR 0)
|
||||
set(rexbacklight_VERSION_MINOR 1)
|
||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||
configure_file(
|
||||
"${INCLUDE_PATH}/config.h.in"
|
||||
@@ -12,6 +12,7 @@ include_directories("${INCLUDE_PATH}")
|
||||
|
||||
option(BUILD_REXLEDCTL "Build led control program" ON)
|
||||
option(BUILD_REXBACKLIGHT "Build backlight control program" ON)
|
||||
option(XBACKLIGHT_COMPAT "Use xbacklight style options (eg -get -inc -dec)" OFF)
|
||||
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_LED_RULE "Install the udev rule to allow users of video group to control led devices" ON
|
||||
"BUILD_REXLEDCTL" OFF)
|
||||
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_BACKLIGHT_RULE "Install the udev rule to allow users of video group to control backlight devices" ON
|
||||
@@ -19,6 +20,10 @@ CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_BACKLIGHT_RULE "Install the udev rule to all
|
||||
set(UDEV_DIR "/etc/udev/rules.d" CACHE STRING "Set the output directory for udev rules")
|
||||
mark_as_advanced(UDEV_DIR)
|
||||
|
||||
if(XBACKLIGHT_COMPAT)
|
||||
add_definitions(-DXBACKLIGHT_COMPAT_OPTIONS)
|
||||
endif()
|
||||
|
||||
if(BUILD_REXLEDCTL)
|
||||
add_executable (rexledctl src/rexbacklight.c src/cmd.c src/common.c)
|
||||
target_compile_definitions(rexledctl PRIVATE REXLEDCTL)
|
||||
|
||||
72
README.md
Normal file
72
README.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# README
|
||||
|
||||
## About
|
||||
rexbacklight is a program designed to operate similarly to xbacklight, though it's not a drop in replacement (possibly adding drop in replacement configure option at some point). Unlike xbacklight, this program does not use X11 to control the backlight devices. rexbacklight directly interacts with sysfs to change backlight levels, read their current status, and find their max output level. This has the advantage of allowing rexbacklight to run without the X server running and will work even if X doesn't recognize your backlight device, which was my original inspiration to make this project.
|
||||
|
||||
I've also since added a program to control LED devices, rexledctl (best name I could think of). This one was inspired by the fact that my laptop's keyboard backlight wasn't controllable by any program I had and the hardware button didn't work either. So now I have my own program which can control it. It was so similar in function to rexbacklight that I decided to just add some compile time `#define`'s and make a few things more modular in the code and have the same source files make 2 different programs.
|
||||
|
||||
Either program can be built alone or both together. This is configured using some cmake magic.
|
||||
|
||||
Current version is 1.0 as of writing this, so if the version is much newer, remind me to update this readme.
|
||||
|
||||
```
|
||||
Usage: rexbacklight [argument] [options] [argument]
|
||||
|
||||
Options:
|
||||
--device|-d
|
||||
select which device to control
|
||||
--fade|-f
|
||||
change brightness over time interval
|
||||
--steps|-s
|
||||
number of steps over which to fade
|
||||
--get|-g
|
||||
print current brightness level to stdout
|
||||
--list|-l
|
||||
print device names to stdout and exit
|
||||
--help|-h
|
||||
print this help message and exit
|
||||
--version
|
||||
print program version and exit
|
||||
|
||||
Arguments:
|
||||
=<percentage>
|
||||
-<percentage>
|
||||
+<percentage>
|
||||
off
|
||||
max
|
||||
min
|
||||
|
||||
rexbacklight Copyright (C) 2018 rexy712
|
||||
This program comes with ABSOLUTELY NO WARRANTY.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; see the GNU GPLv3 for details.
|
||||
A copy of the GPLv3 is available with the source in the file 'LICENSE'
|
||||
```
|
||||
|
||||
|
||||
## Building
|
||||
##### Run the following commands
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
ccmake ..
|
||||
#or just 'cmake ..' and specify options on command line
|
||||
make
|
||||
```
|
||||
|
||||
## Installing
|
||||
##### Run the following commands from the build directory after building
|
||||
```
|
||||
sudo make install
|
||||
```
|
||||
##### Reload the udev rules for them to take effect, otherwise just reboot
|
||||
```
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
```
|
||||
|
||||
## Uninstalling
|
||||
##### Run the following commands from the build directory
|
||||
```
|
||||
sudo make uninstall
|
||||
```
|
||||
2
TODO
2
TODO
@@ -1,7 +1,7 @@
|
||||
#Individual device control
|
||||
#List devices
|
||||
#Query backlight percentage (get)
|
||||
xbacklight compat option (-get/-set/-inc/-dec/-help/-time/-steps)
|
||||
#xbacklight compat option (-get/-set/-inc/-dec/-help/-time/-steps)
|
||||
#allow fade in and fade out
|
||||
a lot of cleanup
|
||||
#rename "backlight" things to "device" things because led/backlight ambiguity
|
||||
|
||||
@@ -1,2 +1,26 @@
|
||||
#define REXBACKLIGHT_VERSION_MAJOR 1
|
||||
#define REXBACKLIGHT_VERSION_MINOR 0
|
||||
/**
|
||||
rexbacklight
|
||||
Copyright (C) 2018 rexy712
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define REXBACKLIGHT_VERSION_MAJOR @rexbacklight_VERSION_MAJOR@
|
||||
#define REXBACKLIGHT_VERSION_MINOR @rexbacklight_VERSION_MINOR@
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
89
src/cmd.c
89
src/cmd.c
@@ -40,19 +40,61 @@
|
||||
#define HELP_SHORT_OPT "-h"
|
||||
#define VERSION_LONG_OPT "--version"
|
||||
|
||||
#define DEVICE_XBACK_OPT "-display"
|
||||
#define HELP_XBACK_OPT "-help"
|
||||
#define VERSION_XBACK_OPT "-version"
|
||||
#define SET_XBACK_OPT "-set"
|
||||
#define INC_XBACK_OPT "-inc"
|
||||
#define DEC_XBACK_OPT "-dec"
|
||||
#define GET_XBACK_OPT "-get"
|
||||
#define FADE_XBACK_OPT "-time"
|
||||
#define STEPS_XBACK_OPT "-steps"
|
||||
|
||||
#define DEVICE_DESC "select which device to control"
|
||||
#define FADE_DESC "change brightness over time interval"
|
||||
#define STEPS_DESC "number of steps over which to fade"
|
||||
#define GET_DESC "print current brightness level to stdout"
|
||||
#define LIST_DESC "print device names to stdout and exit"
|
||||
#define HELP_DESC "print this help message and exit"
|
||||
#define VERSION_DESC "print program version and exit"
|
||||
#define SET_DESC "set backlight device to specified value"
|
||||
#define INC_DESC "increase backlight device by specified value"
|
||||
#define DEC_DESC "decrease backlight device by specified value"
|
||||
|
||||
#ifdef XBACKLIGHT_COMPAT_OPTIONS
|
||||
#define CHECK_SHORT_OPTION(opt, arg) assert(0)
|
||||
#define CHECK_LONG_OPTION(opt, arg) (!strcmp(opt##_XBACK_OPT, arg))
|
||||
#define CHECK_OPTION(opt, arg) (!strcmp(opt##_XBACK_OPT, arg))
|
||||
|
||||
struct cmd_arg rexbacklight_args[] = {
|
||||
{DEVICE_XBACK_OPT, NO_OPT, DEVICE_DESC},
|
||||
{SET_XBACK_OPT, NO_OPT, SET_DESC},
|
||||
{INC_XBACK_OPT, NO_OPT, INC_DESC},
|
||||
{DEC_XBACK_OPT, NO_OPT, DEC_DESC},
|
||||
{FADE_XBACK_OPT, NO_OPT, FADE_DESC},
|
||||
{STEPS_XBACK_OPT, NO_OPT, STEPS_DESC},
|
||||
{GET_XBACK_OPT, NO_OPT, GET_DESC},
|
||||
{HELP_XBACK_OPT, NO_OPT, HELP_DESC},
|
||||
{VERSION_XBACK_OPT, NO_OPT, VERSION_DESC}
|
||||
};
|
||||
|
||||
#else //XBACKLIGHT_COMPAT_OPTIONS
|
||||
#define CHECK_SHORT_OPTION(opt, arg) (!strcmp(opt##_SHORT_OPT, arg))
|
||||
#define CHECK_LONG_OPTION(opt, arg) (!strcmp(opt##_LONG_OPT, arg))
|
||||
#define CHECK_OPTION(opt, arg) (!strcmp(opt##_LONG_OPT, arg) || !strcmp(opt##_SHORT_OPT, arg))
|
||||
|
||||
struct cmd_arg rexbacklight_args[] = {
|
||||
{DEVICE_LONG_OPT, DEVICE_SHORT_OPT, "select which device to control"},
|
||||
{FADE_LONG_OPT, FADE_SHORT_OPT, "change brightness over time interval"},
|
||||
{STEPS_LONG_OPT, STEPS_SHORT_OPT, "number of steps over which to fade"},
|
||||
{GET_LONG_OPT, GET_SHORT_OPT, "print current brightness level to stdout"},
|
||||
{LIST_LONG_OPT, LIST_SHORT_OPT, "print device names to stdout and exit"},
|
||||
{HELP_LONG_OPT, HELP_SHORT_OPT, "print this help message and exit"},
|
||||
{VERSION_LONG_OPT, NO_OPT, "print program version and exit"}
|
||||
{DEVICE_LONG_OPT, DEVICE_SHORT_OPT, DEVICE_DESC},
|
||||
{FADE_LONG_OPT, FADE_SHORT_OPT, FADE_DESC},
|
||||
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_DESC},
|
||||
{GET_LONG_OPT, GET_SHORT_OPT, GET_DESC},
|
||||
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_DESC},
|
||||
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_DESC},
|
||||
{VERSION_LONG_OPT, NO_OPT, VERSION_DESC}
|
||||
};
|
||||
#endif //XBACKLIGHT_COMPAT_OPTIONS
|
||||
|
||||
|
||||
int rexbacklight_args_length = sizeof(rexbacklight_args) / sizeof(rexbacklight_args[0]);
|
||||
|
||||
//Clean up a cmd_arg struct
|
||||
@@ -124,12 +166,7 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
||||
curr->device = argv[++i];
|
||||
continue;
|
||||
}
|
||||
else if(CHECK_OPTION(LIST, argv[i])){
|
||||
free_cmd_args(&ret);
|
||||
ret.operation = OP_LIST;
|
||||
ret.next = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
else if(CHECK_OPTION(HELP, argv[i])){
|
||||
free_cmd_args(&ret);
|
||||
return (struct arg_values){.operation = OP_USAGE};
|
||||
@@ -139,6 +176,13 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
||||
return (struct arg_values){.operation = OP_VERSION};
|
||||
}
|
||||
|
||||
#ifndef XBACKLIGHT_COMPAT_OPTIONS
|
||||
else if(CHECK_OPTION(LIST, argv[i])){
|
||||
free_cmd_args(&ret);
|
||||
ret.operation = OP_LIST;
|
||||
ret.next = NULL;
|
||||
return ret;
|
||||
}
|
||||
else if(!strcmp(argv[i], "max")){
|
||||
curr->operation = OP_SET;
|
||||
curr->delta = 100;
|
||||
@@ -151,6 +195,25 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
||||
curr->operation = OP_SET;
|
||||
curr->delta = 0;
|
||||
}
|
||||
#else //XBACKLIGHT_COMPAT_OPTIONS
|
||||
else if(CHECK_OPTION(SET, argv[i])){
|
||||
CHECK_NEXT_ARG();
|
||||
curr->operation = OP_SET;
|
||||
curr->delta = atof(argv[++i]);
|
||||
}
|
||||
|
||||
else if(CHECK_OPTION(INC, argv[i])){
|
||||
CHECK_NEXT_ARG();
|
||||
curr->operation = OP_INC;
|
||||
curr->delta = atof(argv[++i]);
|
||||
}
|
||||
|
||||
else if(CHECK_OPTION(DEC, argv[i])){
|
||||
CHECK_NEXT_ARG();
|
||||
curr->operation = OP_DEC;
|
||||
curr->delta = atof(argv[++i]);
|
||||
}
|
||||
#endif //XBACKLIGHT_COMPAT_OPTIONS
|
||||
|
||||
else if(argv[i][0] == '='){
|
||||
curr->operation = OP_SET;
|
||||
|
||||
10
src/common.c
10
src/common.c
@@ -43,7 +43,13 @@ _Noreturn void usage(int exit_val){
|
||||
|
||||
printf("Options:\n");
|
||||
for(i = 0;i < rexbacklight_args_length;++i){
|
||||
printf(" %s|%s\n", rexbacklight_args[i].lopt, rexbacklight_args[i].sopt);
|
||||
if(!rexbacklight_args[i].lopt){
|
||||
printf(" %s\n", rexbacklight_args[i].sopt);
|
||||
}else if(!rexbacklight_args[i].sopt){
|
||||
printf(" %s\n", rexbacklight_args[i].lopt);
|
||||
}else{
|
||||
printf(" %s|%s\n", rexbacklight_args[i].lopt, rexbacklight_args[i].sopt);
|
||||
}
|
||||
printf(" %s\n", rexbacklight_args[i].desc);
|
||||
}
|
||||
printf("\n");
|
||||
@@ -51,9 +57,11 @@ _Noreturn void usage(int exit_val){
|
||||
printf(" =<percentage>\n");
|
||||
printf(" -<percentage>\n");
|
||||
printf(" +<percentage>\n");
|
||||
#ifndef XBACKLIGHT_COMPAT_OPTIONS
|
||||
printf(" off\n");
|
||||
printf(" max\n");
|
||||
printf(" min\n");
|
||||
#endif //XBACKLIGHT_COMPAT_OPTIONS
|
||||
|
||||
printf("\n%s Copyright (C) 2018 rexy712\n", executable_name);
|
||||
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
|
||||
|
||||
Reference in New Issue
Block a user