Compare commits

..

No commits in common. "master" and "v1.5" have entirely different histories.
master ... v1.5

12 changed files with 41 additions and 71 deletions

View File

@ -1,7 +1,6 @@
project(rexbacklight)
cmake_minimum_required(VERSION 3.1)
include(CMakeDependentOption)
include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.1)
project(rexbacklight)
set(SCRIPT_DIR ${CMAKE_SOURCE_DIR}/scripts)
@ -24,7 +23,7 @@ if(PYTHONINTERP_FOUND)
add_custom_command(
OUTPUT ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "//File generated by CMake. Do not edit!" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.3\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GIT_VERSION_TMP_FILE} ${GIT_VERSION_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GIT_VERSION_TMP_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@ -35,7 +34,7 @@ elseif(UNIX)
add_custom_command(
OUTPUT ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "//File generated by CMake. Do not edit!" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.3\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GIT_VERSION_TMP_FILE} ${GIT_VERSION_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GIT_VERSION_TMP_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@ -62,8 +61,8 @@ endif()
#locate rjp library requirements
if(ENABLE_RESTORE_FILE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(RJP REQUIRED rjp)
find_library(RJP_LIB rjp)
find_path(RJP_HEADER_DIR rjp.h)
#temporary library (no actual library generated)
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
add_definitions("-DENABLE_RESTORE_FILE")
@ -81,9 +80,8 @@ if(BUILD_REXLEDCTL)
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
target_link_libraries(rexledctl PRIVATE $<TARGET_OBJECTS:common_srcs>) #link with the common_srcs "library"
if(ENABLE_RESTORE_FILE)
target_link_libraries(rexledctl PRIVATE "${RJP_LIBRARIES}") #link with rjp
target_include_directories(rexledctl PUBLIC "${RJP_INCLUDE_DIRS}") #include rjp.h directory
target_compile_options(rexledctl PUBLIC ${RJP_CFLAGS_OTHER})
target_link_libraries(rexledctl PRIVATE "${RJP_LIB}") #link with rjp
target_include_directories(rexledctl PUBLIC "${RJP_HEADER_DIR}") #include rjp.h directory
endif()
install(TARGETS rexledctl RUNTIME DESTINATION bin)
if(INSTALL_UDEV_LED_RULE)
@ -97,9 +95,8 @@ if(BUILD_REXBACKLIGHT)
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
target_link_libraries(rexbacklight PRIVATE $<TARGET_OBJECTS:common_srcs>)
if(ENABLE_RESTORE_FILE)
target_link_libraries(rexbacklight PRIVATE "${RJP_LIBRARIES}")
target_include_directories(rexbacklight PUBLIC "${RJP_INCLUDE_DIRS}")
target_compile_options(rexbacklight PUBLIC ${RJP_CFLAGS_OTHER})
target_link_libraries(rexbacklight PRIVATE "${RJP_LIB}")
target_include_directories(rexbacklight PUBLIC "${RJP_HEADER_DIR}")
endif()
install(TARGETS rexbacklight RUNTIME DESTINATION bin)
if(INSTALL_UDEV_BACKLIGHT_RULE)

View File

@ -7,11 +7,9 @@ I've also since added a program to control LED devices, rexledctl (best name I c
Either program can be built alone or both together. This is configured using some cmake magic.
Current version is 1.5.2 as of writing this, so if the version is much newer, remind me to update this readme.
Current version is 1.3.1 as of writing this, so if the version is much newer, remind me to update this readme.
```
rexbacklight version v1.5.2
Usage: rexbacklight [argument] [options] [argument]
Options:
@ -27,8 +25,6 @@ Options:
print device names to stdout and exit
--restore|-R
reassign previously saved device values
--no-save|-N
do not write any data to the restore file
--help|-h
print this help message and exit
--version
@ -42,7 +38,7 @@ Arguments:
max
min
rexbacklight Copyright (C) 2018-2021 rexy712
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.

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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
@ -94,7 +94,7 @@ _Noreturn void usage(int exit_val){
printf(" max\n");
printf(" min\n");
printf("\n%s Copyright (C) 2018-2021 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 is free software, and you are welcome to redistribute it\n");
printf("under certain conditions; see the GNU GPLv3 for details.\n");

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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
@ -77,7 +77,7 @@ RJP_value* read_restore_file(const char* file){
i = fread(file_contents, filesize, 1, fp);
fclose(fp);
file_contents[filesize] = 0;
RJP_value* root = rjp_parse(file_contents, RJP_PARSE_ALLOW_COMMENTS, NULL);
RJP_value* root = rjp_parse(file_contents);
free(file_contents);
return root;
}
@ -93,10 +93,8 @@ static RJP_value* restore_file_handle(void){
}
RJP_value* find_matching_json_device(const char* name, RJP_value* root){
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
for(RJP_value* curr = rjp_object_iterator_current(&it);curr;curr = rjp_object_iterator_next(&it)){
if(!strcmp(rjp_member_key(curr)->value, name)){
for(RJP_value* curr = rjp_get_member(root);curr;curr = rjp_next_member(curr)){
if(!strcmp(rjp_member_name(curr), name)){
return curr;
}
}
@ -116,7 +114,7 @@ int restore_to_delta(struct arg_values* curr){
return 0;
}
curr->operation = OP_SET;
curr->delta = rjp_get_float(match);
curr->delta = rjp_value_dfloat(match);
return 1;
}
void prep_restore(struct arg_values* a){
@ -126,12 +124,10 @@ void prep_restore(struct arg_values* a){
}
void save_restore_file(struct string_array* devices, struct arg_values* args){
RJP_object_iterator it;
RJP_value* rf = restore_file_handle();
if(!rf)
rf = rjp_new_object();
rjp_init_object_iterator(&it, rf);
for(RJP_value* mem = rjp_object_iterator_current(&it);mem;mem = rjp_object_iterator_next(&it)){
rf = rjp_init_json();
for(RJP_value* mem = rjp_get_member(rf);mem;mem = rjp_next_member(mem)){
for(struct arg_values* curr = args->next, *prev = args;curr;prev = curr, curr = curr->next){
if(curr->operation != OP_SET || curr->flags & ARG_FLAG_NO_SAVE){
prev->next = curr->next;
@ -139,8 +135,8 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
curr = prev;
continue;
}
if(!strcmp(rjp_member_key(mem)->value, curr->device)){
rjp_set_float(mem, curr->delta);
if(!strcmp(rjp_member_name(mem), curr->device)){
rjp_set_value(mem, rjp_dfloat(curr->delta));
prev->next = curr->next;
free(curr);
break;
@ -148,14 +144,12 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
}
}
for(struct arg_values* curr = args->next;curr;curr = curr->next){
if(curr->operation == OP_SET){
RJP_value* newmem = rjp_new_member(rf, curr->device, 0);
rjp_set_float(newmem, curr->delta);
}
if(curr->operation == OP_SET)
rjp_add_member(rf, curr->device, 0, rjp_dfloat(curr->delta));
}
free_cmd_args(args);
char* tmp = rjp_to_json(rf, RJP_FORMAT_NONE);
char* tmp = rjp_to_json(rf);
char* rfil = restore_file();
FILE* restf = fopen(rfil, "w");
if(!restf){

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018-2021 rexy712
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
@ -63,15 +63,6 @@ const char* max_brightness_file(void){return "max_brightness";}
/////////////////////////////////////////////////////////////////////////////////////////////
//create a copy of a string and append a '/' character to the end
char* add_slash_to(const char* name, size_t namelen){
char* newname = malloc(namelen + 2);
memcpy(newname, name, namelen);
newname[namelen++] = '/';
newname[namelen] = 0;
return newname;
}
//Get a list of led/backlight devices in sysfs
struct string_array get_device_sources(void){
DIR* fd;
@ -171,12 +162,6 @@ void sleep_for(double time){
nanosleep(&ts, NULL);
}
void return_to_root_dir(void){
if(chdir(device_dir())){
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
return_value = RETVAL_INVALID_DIR;
}
}
//update brightness incrementally over requested millisecond time interval
void fade_out(struct arg_values* arg){
FILE* fd;
@ -192,11 +177,8 @@ void fade_out(struct arg_values* arg){
start = get_time();
fd = fopen(brightness_file(), "w+");
if(!fd){
char* devname = add_slash_to(arg->device, strlen(arg->device));
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
return_value = RETVAL_INVALID_FILE;
free(devname);
return_to_root_dir();
return;
}
fprintf(fd, "%d", (int)value);
@ -219,17 +201,18 @@ void fade_out(struct arg_values* arg){
}
fd = fopen(brightness_file(), "w+");
if(!fd){
char* devname = add_slash_to(arg->device, strlen(arg->device));
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
return_value = RETVAL_INVALID_FILE;
free(devname);
return_to_root_dir();
return;
}
fprintf(fd, "%d", arg->act_delta);
fclose(fd);
return_to_root_dir();
if(chdir(device_dir())){
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
return_value = RETVAL_INVALID_DIR;
return;
}
}
int prep_offset(struct arg_values* args){