added xbacklight argument compatability option
This commit is contained in:
parent
078b9bf1e3
commit
f475f18ce8
@ -2,7 +2,7 @@ include(CMakeDependentOption)
|
|||||||
cmake_minimum_required(VERSION 3.0.2)
|
cmake_minimum_required(VERSION 3.0.2)
|
||||||
project(rexbacklight)
|
project(rexbacklight)
|
||||||
set(rexbacklight_VERSION_MAJOR 1)
|
set(rexbacklight_VERSION_MAJOR 1)
|
||||||
set(rexbacklight_VERSION_MINOR 0)
|
set(rexbacklight_VERSION_MINOR 1)
|
||||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||||
configure_file(
|
configure_file(
|
||||||
"${INCLUDE_PATH}/config.h.in"
|
"${INCLUDE_PATH}/config.h.in"
|
||||||
@ -12,6 +12,7 @@ include_directories("${INCLUDE_PATH}")
|
|||||||
|
|
||||||
option(BUILD_REXLEDCTL "Build led control program" ON)
|
option(BUILD_REXLEDCTL "Build led control program" ON)
|
||||||
option(BUILD_REXBACKLIGHT "Build backlight 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
|
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)
|
"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
|
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")
|
set(UDEV_DIR "/etc/udev/rules.d" CACHE STRING "Set the output directory for udev rules")
|
||||||
mark_as_advanced(UDEV_DIR)
|
mark_as_advanced(UDEV_DIR)
|
||||||
|
|
||||||
|
if(XBACKLIGHT_COMPAT)
|
||||||
|
add_definitions(-DXBACKLIGHT_COMPAT_OPTIONS)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILD_REXLEDCTL)
|
if(BUILD_REXLEDCTL)
|
||||||
add_executable (rexledctl src/rexbacklight.c src/cmd.c src/common.c)
|
add_executable (rexledctl src/rexbacklight.c src/cmd.c src/common.c)
|
||||||
target_compile_definitions(rexledctl PRIVATE REXLEDCTL)
|
target_compile_definitions(rexledctl PRIVATE REXLEDCTL)
|
||||||
|
|||||||
2
TODO
2
TODO
@ -1,7 +1,7 @@
|
|||||||
#Individual device control
|
#Individual device control
|
||||||
#List devices
|
#List devices
|
||||||
#Query backlight percentage (get)
|
#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
|
#allow fade in and fade out
|
||||||
a lot of cleanup
|
a lot of cleanup
|
||||||
#rename "backlight" things to "device" things because led/backlight ambiguity
|
#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 HELP_SHORT_OPT "-h"
|
||||||
#define VERSION_LONG_OPT "--version"
|
#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_SHORT_OPTION(opt, arg) (!strcmp(opt##_SHORT_OPT, arg))
|
||||||
#define CHECK_LONG_OPTION(opt, arg) (!strcmp(opt##_LONG_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))
|
#define CHECK_OPTION(opt, arg) (!strcmp(opt##_LONG_OPT, arg) || !strcmp(opt##_SHORT_OPT, arg))
|
||||||
|
|
||||||
struct cmd_arg rexbacklight_args[] = {
|
struct cmd_arg rexbacklight_args[] = {
|
||||||
{DEVICE_LONG_OPT, DEVICE_SHORT_OPT, "select which device to control"},
|
{DEVICE_LONG_OPT, DEVICE_SHORT_OPT, DEVICE_DESC},
|
||||||
{FADE_LONG_OPT, FADE_SHORT_OPT, "change brightness over time interval"},
|
{FADE_LONG_OPT, FADE_SHORT_OPT, FADE_DESC},
|
||||||
{STEPS_LONG_OPT, STEPS_SHORT_OPT, "number of steps over which to fade"},
|
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_DESC},
|
||||||
{GET_LONG_OPT, GET_SHORT_OPT, "print current brightness level to stdout"},
|
{GET_LONG_OPT, GET_SHORT_OPT, GET_DESC},
|
||||||
{LIST_LONG_OPT, LIST_SHORT_OPT, "print device names to stdout and exit"},
|
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_DESC},
|
||||||
{HELP_LONG_OPT, HELP_SHORT_OPT, "print this help message and exit"},
|
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_DESC},
|
||||||
{VERSION_LONG_OPT, NO_OPT, "print program version and exit"}
|
{VERSION_LONG_OPT, NO_OPT, VERSION_DESC}
|
||||||
};
|
};
|
||||||
|
#endif //XBACKLIGHT_COMPAT_OPTIONS
|
||||||
|
|
||||||
|
|
||||||
int rexbacklight_args_length = sizeof(rexbacklight_args) / sizeof(rexbacklight_args[0]);
|
int rexbacklight_args_length = sizeof(rexbacklight_args) / sizeof(rexbacklight_args[0]);
|
||||||
|
|
||||||
//Clean up a cmd_arg struct
|
//Clean up a cmd_arg struct
|
||||||
@ -124,12 +166,7 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
|||||||
curr->device = argv[++i];
|
curr->device = argv[++i];
|
||||||
continue;
|
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])){
|
else if(CHECK_OPTION(HELP, argv[i])){
|
||||||
free_cmd_args(&ret);
|
free_cmd_args(&ret);
|
||||||
return (struct arg_values){.operation = OP_USAGE};
|
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};
|
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")){
|
else if(!strcmp(argv[i], "max")){
|
||||||
curr->operation = OP_SET;
|
curr->operation = OP_SET;
|
||||||
curr->delta = 100;
|
curr->delta = 100;
|
||||||
@ -151,6 +195,25 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
|||||||
curr->operation = OP_SET;
|
curr->operation = OP_SET;
|
||||||
curr->delta = 0;
|
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] == '='){
|
else if(argv[i][0] == '='){
|
||||||
curr->operation = OP_SET;
|
curr->operation = OP_SET;
|
||||||
|
|||||||
@ -57,9 +57,11 @@ _Noreturn void usage(int exit_val){
|
|||||||
printf(" =<percentage>\n");
|
printf(" =<percentage>\n");
|
||||||
printf(" -<percentage>\n");
|
printf(" -<percentage>\n");
|
||||||
printf(" +<percentage>\n");
|
printf(" +<percentage>\n");
|
||||||
|
#ifndef XBACKLIGHT_COMPAT_OPTIONS
|
||||||
printf(" off\n");
|
printf(" off\n");
|
||||||
printf(" max\n");
|
printf(" max\n");
|
||||||
printf(" min\n");
|
printf(" min\n");
|
||||||
|
#endif //XBACKLIGHT_COMPAT_OPTIONS
|
||||||
|
|
||||||
printf("\n%s Copyright (C) 2018 rexy712\n", executable_name);
|
printf("\n%s Copyright (C) 2018 rexy712\n", executable_name);
|
||||||
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
|
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user