|  | @@ -44,6 +44,24 @@ LBOOL readint(const char* f, unsigned int *i){
 | 
	
		
			
			| 44 | 44 |  	}
 | 
	
		
			
			| 45 | 45 |  }
 | 
	
		
			
			| 46 | 46 |  
 | 
	
		
			
			|  | 47 | +LBOOL readchar(const char* f, char *c){
 | 
	
		
			
			|  | 48 | +	
 | 
	
		
			
			|  | 49 | +	FILE* ff = fopen(f, "r");
 | 
	
		
			
			|  | 50 | +
 | 
	
		
			
			|  | 51 | +	/*c = malloc(sz+1);*/
 | 
	
		
			
			|  | 52 | +	if(ff){
 | 
	
		
			
			|  | 53 | +		unsigned int sz;
 | 
	
		
			
			|  | 54 | +		fseek(ff, 0L, SEEK_END);
 | 
	
		
			
			|  | 55 | +		sz = ftell(ff);
 | 
	
		
			
			|  | 56 | +		fseek(ff, 0L, SEEK_SET);
 | 
	
		
			
			|  | 57 | +		fgets(c,sz,ff);
 | 
	
		
			
			|  | 58 | +		fclose(ff);
 | 
	
		
			
			|  | 59 | +		return TRUE;
 | 
	
		
			
			|  | 60 | +	}else{
 | 
	
		
			
			|  | 61 | +		return FALSE;
 | 
	
		
			
			|  | 62 | +	}
 | 
	
		
			
			|  | 63 | +}
 | 
	
		
			
			|  | 64 | +
 | 
	
		
			
			| 47 | 65 |  LBOOL writeint(const char* f, unsigned int i){
 | 
	
		
			
			| 48 | 66 |  	FILE* ff = fopen(f, "w");
 | 
	
		
			
			| 49 | 67 |  	if(ff){
 | 
	
	
		
			
			|  | @@ -77,14 +95,15 @@ LBOOL is_writable(const char* f){
 | 
	
		
			
			| 77 | 95 |  }
 | 
	
		
			
			| 78 | 96 |  
 | 
	
		
			
			| 79 | 97 |  typedef struct {
 | 
	
		
			
			| 80 |  | -	char*		name;
 | 
	
		
			
			|  | 98 | +	char		name[256];
 | 
	
		
			
			| 81 | 99 |  	unsigned int	current_brightness;
 | 
	
		
			
			| 82 | 100 |  	unsigned int	max_brightness;
 | 
	
		
			
			| 83 |  | -	char*		c_path; /* Controller-path */
 | 
	
		
			
			| 84 |  | -	char*		cb_path; /* Current brightness-path */
 | 
	
		
			
			| 85 |  | -	char*		mb_path; /* Max brightness-path */
 | 
	
		
			
			| 86 |  | -	char*		b_path; /* Brightness-path */
 | 
	
		
			
			| 87 |  | -	enum LBOOL		is_ok;
 | 
	
		
			
			|  | 101 | +	char		c_path[256]; /* Controller-path */
 | 
	
		
			
			|  | 102 | +	char		cb_path[256]; /* Current brightness-path */
 | 
	
		
			
			|  | 103 | +	char		mb_path[256]; /* Max brightness-path */
 | 
	
		
			
			|  | 104 | +	char		b_path[256]; /* Brightness-path */
 | 
	
		
			
			|  | 105 | +	enum LBOOL	is_ok;
 | 
	
		
			
			|  | 106 | +	unsigned int	guide_id;
 | 
	
		
			
			| 88 | 107 |  } controller;
 | 
	
		
			
			| 89 | 108 |  
 | 
	
		
			
			| 90 | 109 |  typedef struct {
 | 
	
	
		
			
			|  | @@ -111,20 +130,23 @@ fetch_result fetch_controllers(const char* ctrldir){
 | 
	
		
			
			| 111 | 130 |  			char* currctrldir_max = "";
 | 
	
		
			
			| 112 | 131 |  			char* currctrldir_f = "";
 | 
	
		
			
			| 113 | 132 |  			if( ep->d_name[0] != '.'){
 | 
	
		
			
			| 114 |  | -				returner.controllers[returner.num_controllers].name = ep->d_name;
 | 
	
		
			
			|  | 133 | +				strncpy(returner.controllers[returner.num_controllers].name, ep->d_name, sizeof(returner.controllers[returner.num_controllers].name));
 | 
	
		
			
			| 115 | 134 |  				
 | 
	
		
			
			| 116 | 135 |  				/* Set some default values, in case something fails we dont just get null */
 | 
	
		
			
			| 117 | 136 |  				returner.controllers[returner.num_controllers].current_brightness = 0;
 | 
	
		
			
			| 118 | 137 |  				returner.controllers[returner.num_controllers].max_brightness = 0;
 | 
	
		
			
			| 119 | 138 |  				returner.controllers[returner.num_controllers].is_ok = TRUE;
 | 
	
		
			
			|  | 139 | +				/*
 | 
	
		
			
			| 120 | 140 |  				returner.controllers[returner.num_controllers].c_path = NULL;
 | 
	
		
			
			| 121 | 141 |  				returner.controllers[returner.num_controllers].cb_path = NULL;
 | 
	
		
			
			| 122 | 142 |  				returner.controllers[returner.num_controllers].b_path = NULL;
 | 
	
		
			
			| 123 | 143 |  				returner.controllers[returner.num_controllers].mb_path = NULL;
 | 
	
		
			
			| 124 |  | -				
 | 
	
		
			
			|  | 144 | +				*/
 | 
	
		
			
			| 125 | 145 |  				/* Get path to the current controller dir */
 | 
	
		
			
			| 126 | 146 |  				asprintf(&currctrldir, "%s/%s", ctrldir, ep->d_name);
 | 
	
		
			
			| 127 |  | -				returner.controllers[returner.num_controllers].c_path = currctrldir;
 | 
	
		
			
			|  | 147 | +				
 | 
	
		
			
			|  | 148 | +				strncpy(returner.controllers[returner.num_controllers].c_path, currctrldir, sizeof(returner.controllers[returner.num_controllers].c_path));
 | 
	
		
			
			|  | 149 | +				
 | 
	
		
			
			| 128 | 150 |  				if(is_dir(currctrldir) == FALSE){
 | 
	
		
			
			| 129 | 151 |  					if(q == FALSE)
 | 
	
		
			
			| 130 | 152 |  						printf("Warning: '%s' is not a directory, check your system.\n", currctrldir);
 | 
	
	
		
			
			|  | @@ -133,7 +155,7 @@ fetch_result fetch_controllers(const char* ctrldir){
 | 
	
		
			
			| 133 | 155 |  				
 | 
	
		
			
			| 134 | 156 |  				/* Get path to current actual_brightness-file */
 | 
	
		
			
			| 135 | 157 |  				asprintf(&currctrldir_curr, "%s/%s", currctrldir, "actual_brightness");
 | 
	
		
			
			| 136 |  | -				returner.controllers[returner.num_controllers].cb_path = currctrldir_curr;
 | 
	
		
			
			|  | 158 | +				strncpy(returner.controllers[returner.num_controllers].cb_path, currctrldir_curr, sizeof(returner.controllers[returner.num_controllers].cb_path));
 | 
	
		
			
			| 137 | 159 |  				if( readint(currctrldir_curr, &returner.controllers[returner.num_controllers].current_brightness) == FALSE ){
 | 
	
		
			
			| 138 | 160 |  					if(q == FALSE)
 | 
	
		
			
			| 139 | 161 |  						printf("Warning: Can't read actual_brightness-file of '%s'. Will ignore this controller.\n", ep->d_name);
 | 
	
	
		
			
			|  | @@ -142,7 +164,8 @@ fetch_result fetch_controllers(const char* ctrldir){
 | 
	
		
			
			| 142 | 164 |  				
 | 
	
		
			
			| 143 | 165 |  				/* Get path to current max_brightness-file*/
 | 
	
		
			
			| 144 | 166 |  				asprintf(&currctrldir_max, "%s/%s", currctrldir, "max_brightness");
 | 
	
		
			
			| 145 |  | -				returner.controllers[returner.num_controllers].mb_path = currctrldir_max;
 | 
	
		
			
			|  | 167 | +				strncpy(returner.controllers[returner.num_controllers].mb_path, currctrldir_max, sizeof(returner.controllers[returner.num_controllers].mb_path));
 | 
	
		
			
			|  | 168 | +				
 | 
	
		
			
			| 146 | 169 |  				if( readint(currctrldir_max, &returner.controllers[returner.num_controllers].max_brightness) == FALSE ){
 | 
	
		
			
			| 147 | 170 |  					if(q == FALSE)
 | 
	
		
			
			| 148 | 171 |  						printf("Warning: Can't read max_brightness-file of '%s'. Will ignore this controller.\n", ep->d_name);
 | 
	
	
		
			
			|  | @@ -151,7 +174,7 @@ fetch_result fetch_controllers(const char* ctrldir){
 | 
	
		
			
			| 151 | 174 |  				
 | 
	
		
			
			| 152 | 175 |  				/* Get path to current brightness-file */
 | 
	
		
			
			| 153 | 176 |  				asprintf(&currctrldir_f, "%s/%s", currctrldir, "brightness");
 | 
	
		
			
			| 154 |  | -				returner.controllers[returner.num_controllers].b_path = currctrldir_f;
 | 
	
		
			
			|  | 177 | +				strncpy(returner.controllers[returner.num_controllers].b_path, currctrldir_f, sizeof(returner.controllers[returner.num_controllers].b_path));
 | 
	
		
			
			| 155 | 178 |  				if( is_writable(currctrldir_f) == FALSE){
 | 
	
		
			
			| 156 | 179 |  					if(q == FALSE)
 | 
	
		
			
			| 157 | 180 |  						printf("Warning: Controllerfile of '%s' is not writable. Will ignore this controller.\n", ep->d_name);
 | 
	
	
		
			
			|  | @@ -197,8 +220,27 @@ controller* get_best_controller(fetch_result* res){
 | 
	
		
			
			| 197 | 220 |  	return returner;
 | 
	
		
			
			| 198 | 221 |  }
 | 
	
		
			
			| 199 | 222 |  
 | 
	
		
			
			|  | 223 | +controller* get_controller_by_name(fetch_result* res, const char* name){
 | 
	
		
			
			|  | 224 | +	unsigned int it;
 | 
	
		
			
			|  | 225 | +	controller* returner;
 | 
	
		
			
			|  | 226 | +	
 | 
	
		
			
			|  | 227 | +	it = 0;
 | 
	
		
			
			|  | 228 | +	returner = NULL;
 | 
	
		
			
			|  | 229 | +	
 | 
	
		
			
			|  | 230 | +	while(it < res->num_controllers){
 | 
	
		
			
			|  | 231 | +		if(strcmp(res->controllers[it].name, name) == 0){
 | 
	
		
			
			|  | 232 | +			returner = &res->controllers[it];
 | 
	
		
			
			|  | 233 | +		}
 | 
	
		
			
			|  | 234 | +		it++;
 | 
	
		
			
			|  | 235 | +	}
 | 
	
		
			
			|  | 236 | +	
 | 
	
		
			
			|  | 237 | +	return returner;
 | 
	
		
			
			|  | 238 | +		
 | 
	
		
			
			|  | 239 | +}
 | 
	
		
			
			|  | 240 | +
 | 
	
		
			
			| 200 | 241 |  void usage(){
 | 
	
		
			
			| 201 |  | -	printf("Usage: light [-qcaspm] <value>\n\n\t-q:\t Run quiet, supresses output.\n\t-c:\t Prints the current brightness in percent and exits.(Not precise)\n\t-p:\t Prints the current brightness directly from controller and exits. (Precise)\n\t-m:\t Prints the max brightness directly from controller and exits. \n\t-a:\t Add the value instead of setting it.\n\t-s:\t Subtract the value instead of setting it.\n\n\t<value>\t Brightness wanted in percent.\n\n");
 | 
	
		
			
			|  | 242 | +	printf("Usage: light [-qcaspmfh] [--options] <value>\n\n\tFlags:\n\t-q:\t Run quiet, supresses output.\n\t-c:\t Prints the current brightness in percent and exits.(Not precise)\n\t-p:\t Prints the current brightness directly from controller and exits. (Precise)\n\t-m:\t Prints the max brightness directly from controller and exits. \n\t-a:\t Add the value instead of setting it.\n\t-s:\t Subtract the value instead of setting it.\n\t-h:\t Shows this help and exits.\n");
 | 
	
		
			
			|  | 243 | +	printf("\n\tOptions:\n\t--help:\t Shows this help and exits.\n\n\t<value>\t Brightness wanted in percent.\n\n");
 | 
	
		
			
			| 202 | 244 |  }
 | 
	
		
			
			| 203 | 245 |  
 | 
	
		
			
			| 204 | 246 |  int main(int argc, char **argv) {
 | 
	
	
		
			
			|  | @@ -214,11 +256,15 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 214 | 256 |  	unsigned int	minlight_nonp;
 | 
	
		
			
			| 215 | 257 |  	unsigned int	curr_bright;
 | 
	
		
			
			| 216 | 258 |  	unsigned int	curr_brightp;
 | 
	
		
			
			| 217 |  | -	
 | 
	
		
			
			|  | 259 | +	LBOOL		useforce;
 | 
	
		
			
			|  | 260 | +	char*		useforce_name;
 | 
	
		
			
			| 218 | 261 |  	
 | 
	
		
			
			| 219 | 262 |  	/* Get UID */
 | 
	
		
			
			| 220 | 263 |  	uid = getuid();
 | 
	
		
			
			| 221 | 264 |  	
 | 
	
		
			
			|  | 265 | +	useforce = FALSE;
 | 
	
		
			
			|  | 266 | +	useforce_name = malloc(256*sizeof(char));
 | 
	
		
			
			|  | 267 | +	
 | 
	
		
			
			| 222 | 268 |  	/* Parse arguments */
 | 
	
		
			
			| 223 | 269 |  	q=FALSE;
 | 
	
		
			
			| 224 | 270 |  	c=FALSE;
 | 
	
	
		
			
			|  | @@ -231,31 +277,58 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 231 | 277 |  	while(argsit < argc){
 | 
	
		
			
			| 232 | 278 |  		char* carg = argv[argsit];
 | 
	
		
			
			| 233 | 279 |  		if(carg[0] == '-'){
 | 
	
		
			
			| 234 |  | -			unsigned int cargit = 1;
 | 
	
		
			
			| 235 |  | -			while(cargit < strlen(carg)){
 | 
	
		
			
			| 236 |  | -				switch(carg[cargit]){
 | 
	
		
			
			| 237 |  | -					case 'q':
 | 
	
		
			
			| 238 |  | -						q = TRUE;
 | 
	
		
			
			| 239 |  | -					break;
 | 
	
		
			
			| 240 |  | -					case 'a':
 | 
	
		
			
			| 241 |  | -						ot = ADD;
 | 
	
		
			
			| 242 |  | -					break;
 | 
	
		
			
			| 243 |  | -					case 's':
 | 
	
		
			
			| 244 |  | -						ot = SUB;
 | 
	
		
			
			| 245 |  | -					break;
 | 
	
		
			
			| 246 |  | -					case 'c':
 | 
	
		
			
			| 247 |  | -						c = TRUE;
 | 
	
		
			
			| 248 |  | -					break;
 | 
	
		
			
			| 249 |  | -					case 'p':
 | 
	
		
			
			| 250 |  | -						p = TRUE;
 | 
	
		
			
			| 251 |  | -					break;
 | 
	
		
			
			| 252 |  | -					case 'm':
 | 
	
		
			
			| 253 |  | -						m = TRUE;
 | 
	
		
			
			| 254 |  | -					break;
 | 
	
		
			
			| 255 |  | -					default:
 | 
	
		
			
			| 256 |  | -					break;
 | 
	
		
			
			|  | 280 | +			LBOOL argdone;
 | 
	
		
			
			|  | 281 | +			argdone = FALSE;
 | 
	
		
			
			|  | 282 | +			if(strlen(carg) > 2){
 | 
	
		
			
			|  | 283 | +				if(carg[1] == '-'){
 | 
	
		
			
			|  | 284 | +					int longargs = strlen(carg) -2;
 | 
	
		
			
			|  | 285 | +					char *longarg = (char*) malloc(longargs);
 | 
	
		
			
			|  | 286 | +					strncpy(longarg, carg+2, longargs);
 | 
	
		
			
			|  | 287 | +					
 | 
	
		
			
			|  | 288 | +					if(strcmp(longarg, "help") == 0){
 | 
	
		
			
			|  | 289 | +						usage();
 | 
	
		
			
			|  | 290 | +						return 0;
 | 
	
		
			
			|  | 291 | +					}else{
 | 
	
		
			
			|  | 292 | +						printf("Unknown option: \"%s\".\n", longarg);
 | 
	
		
			
			|  | 293 | +						return 0;
 | 
	
		
			
			|  | 294 | +					}
 | 
	
		
			
			|  | 295 | +					argdone = TRUE;
 | 
	
		
			
			|  | 296 | +				}
 | 
	
		
			
			|  | 297 | +			}
 | 
	
		
			
			|  | 298 | +			
 | 
	
		
			
			|  | 299 | +			if(argdone == FALSE){
 | 
	
		
			
			|  | 300 | +				unsigned int cargit = 1;
 | 
	
		
			
			|  | 301 | +				while(cargit < strlen(carg)){
 | 
	
		
			
			|  | 302 | +					switch(carg[cargit]){
 | 
	
		
			
			|  | 303 | +						case 'q':
 | 
	
		
			
			|  | 304 | +							q = TRUE;
 | 
	
		
			
			|  | 305 | +						break;
 | 
	
		
			
			|  | 306 | +						case 'a':
 | 
	
		
			
			|  | 307 | +							ot = ADD;
 | 
	
		
			
			|  | 308 | +						break;
 | 
	
		
			
			|  | 309 | +						case 's':
 | 
	
		
			
			|  | 310 | +							ot = SUB;
 | 
	
		
			
			|  | 311 | +						break;
 | 
	
		
			
			|  | 312 | +						case 'c':
 | 
	
		
			
			|  | 313 | +							c = TRUE;
 | 
	
		
			
			|  | 314 | +						break;
 | 
	
		
			
			|  | 315 | +						case 'p':
 | 
	
		
			
			|  | 316 | +							p = TRUE;
 | 
	
		
			
			|  | 317 | +						break;
 | 
	
		
			
			|  | 318 | +						case 'm':
 | 
	
		
			
			|  | 319 | +							m = TRUE;
 | 
	
		
			
			|  | 320 | +						break;
 | 
	
		
			
			|  | 321 | +						case 'h':
 | 
	
		
			
			|  | 322 | +							usage();
 | 
	
		
			
			|  | 323 | +							return 0;
 | 
	
		
			
			|  | 324 | +						break;
 | 
	
		
			
			|  | 325 | +						default:
 | 
	
		
			
			|  | 326 | +							printf("Unknown flag: %c\n", carg[cargit]);
 | 
	
		
			
			|  | 327 | +							return 1;
 | 
	
		
			
			|  | 328 | +						break;
 | 
	
		
			
			|  | 329 | +					}
 | 
	
		
			
			|  | 330 | +					cargit++;
 | 
	
		
			
			| 257 | 331 |  				}
 | 
	
		
			
			| 258 |  | -				cargit++;
 | 
	
		
			
			| 259 | 332 |  			}
 | 
	
		
			
			| 260 | 333 |  		}else{
 | 
	
		
			
			| 261 | 334 |  			wbright = atoi(carg);
 | 
	
	
		
			
			|  | @@ -265,6 +338,7 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 265 | 338 |  		argsit++;
 | 
	
		
			
			| 266 | 339 |  	}
 | 
	
		
			
			| 267 | 340 |  	
 | 
	
		
			
			|  | 341 | +	
 | 
	
		
			
			| 268 | 342 |  	if(c == TRUE || m == TRUE || p == TRUE){
 | 
	
		
			
			| 269 | 343 |  		q = TRUE;
 | 
	
		
			
			| 270 | 344 |  	}
 | 
	
	
		
			
			|  | @@ -274,7 +348,7 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 274 | 348 |  		return 0;
 | 
	
		
			
			| 275 | 349 |  	}
 | 
	
		
			
			| 276 | 350 |  	if(q == FALSE)
 | 
	
		
			
			| 277 |  | -		printf("Light 0.4 - Fredrik Haikarainen\n");
 | 
	
		
			
			|  | 351 | +		printf("Light 0.7 - Fredrik Haikarainen\n");
 | 
	
		
			
			| 278 | 352 |  	
 | 
	
		
			
			| 279 | 353 |  	/* Get and check minlight */
 | 
	
		
			
			| 280 | 354 |  	
 | 
	
	
		
			
			|  | @@ -289,7 +363,6 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 289 | 363 |  		printf("Fetching controllers..\n");
 | 
	
		
			
			| 290 | 364 |  	
 | 
	
		
			
			| 291 | 365 |  	res = fetch_controllers("/sys/class/backlight");
 | 
	
		
			
			| 292 |  | -	
 | 
	
		
			
			| 293 | 366 |  	citr = 0;
 | 
	
		
			
			| 294 | 367 |  	while(citr < res.num_controllers){
 | 
	
		
			
			| 295 | 368 |  		controller* currc = &res.controllers[citr];
 | 
	
	
		
			
			|  | @@ -305,19 +378,32 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 305 | 378 |  
 | 
	
		
			
			| 306 | 379 |  	if(q == FALSE)
 | 
	
		
			
			| 307 | 380 |  		printf("\n");
 | 
	
		
			
			| 308 |  | -	
 | 
	
		
			
			| 309 |  | -	/* Get the best controller */
 | 
	
		
			
			| 310 |  | -	best_ctrl = get_best_controller(&res);
 | 
	
		
			
			| 311 |  | -	
 | 
	
		
			
			| 312 |  | -	if(best_ctrl == NULL){
 | 
	
		
			
			| 313 |  | -		if(uid == 0){
 | 
	
		
			
			| 314 |  | -			if(q == FALSE)
 | 
	
		
			
			| 315 |  | -				printf("No okay controller found, even though you are root! Check your system.\n");
 | 
	
		
			
			| 316 |  | -		}else{
 | 
	
		
			
			|  | 381 | +	/* Read override-file if exists*/
 | 
	
		
			
			|  | 382 | +	if(readchar("/etc/light/override",useforce_name) == TRUE){
 | 
	
		
			
			|  | 383 | +		printf("Overriding controller '%s' !\n", useforce_name);
 | 
	
		
			
			|  | 384 | +		useforce=TRUE;
 | 
	
		
			
			|  | 385 | +	}
 | 
	
		
			
			|  | 386 | +	if(useforce == TRUE){
 | 
	
		
			
			|  | 387 | +		best_ctrl = get_controller_by_name(&res, useforce_name);
 | 
	
		
			
			|  | 388 | +		if(best_ctrl == NULL){
 | 
	
		
			
			| 317 | 389 |  			if(q == FALSE)
 | 
	
		
			
			| 318 |  | -				printf("No okay controller found, check your permissions or try to run as root.\n");
 | 
	
		
			
			|  | 390 | +				printf("Can't override, no such controller. Check/remove your override-file!\n");
 | 
	
		
			
			|  | 391 | +			return 1;	
 | 
	
		
			
			|  | 392 | +		}
 | 
	
		
			
			|  | 393 | +	}else{
 | 
	
		
			
			|  | 394 | +		/* Get the best controller */
 | 
	
		
			
			|  | 395 | +		best_ctrl = get_best_controller(&res);
 | 
	
		
			
			|  | 396 | +		
 | 
	
		
			
			|  | 397 | +		if(best_ctrl == NULL){
 | 
	
		
			
			|  | 398 | +			if(uid == 0){
 | 
	
		
			
			|  | 399 | +				if(q == FALSE)
 | 
	
		
			
			|  | 400 | +					printf("No okay controller found, even though you are root! Check your system.\n");
 | 
	
		
			
			|  | 401 | +			}else{
 | 
	
		
			
			|  | 402 | +				if(q == FALSE)
 | 
	
		
			
			|  | 403 | +					printf("No okay controller found, check your permissions or try to run as root.\n");
 | 
	
		
			
			|  | 404 | +			}
 | 
	
		
			
			|  | 405 | +			return 1;
 | 
	
		
			
			| 319 | 406 |  		}
 | 
	
		
			
			| 320 |  | -		return 1;
 | 
	
		
			
			| 321 | 407 |  	}
 | 
	
		
			
			| 322 | 408 |  	
 | 
	
		
			
			| 323 | 409 |  	if(p == TRUE){
 | 
	
	
		
			
			|  | @@ -345,6 +431,8 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 345 | 431 |  		return 0;
 | 
	
		
			
			| 346 | 432 |  	}
 | 
	
		
			
			| 347 | 433 |  	
 | 
	
		
			
			|  | 434 | +	minlight_nonp = best_ctrl->max_brightness * ( (float)minlight / 100) + 1;
 | 
	
		
			
			|  | 435 | +	
 | 
	
		
			
			| 348 | 436 |  	switch(ot){
 | 
	
		
			
			| 349 | 437 |  		case SET:
 | 
	
		
			
			| 350 | 438 |  			real_wbright = best_ctrl->max_brightness * ( (float)wbright / 100 );
 | 
	
	
		
			
			|  | @@ -353,20 +441,24 @@ int main(int argc, char **argv) {
 | 
	
		
			
			| 353 | 441 |  			real_wbright = ( best_ctrl->max_brightness * ( (float)( curr_brightp + wbright +1) / 100 ));
 | 
	
		
			
			| 354 | 442 |  		break;
 | 
	
		
			
			| 355 | 443 |  		case SUB:
 | 
	
		
			
			| 356 |  | -			real_wbright = ( best_ctrl->max_brightness * ( (float)( curr_brightp - wbright + 1) / 100 ));
 | 
	
		
			
			|  | 444 | +			if(curr_brightp <= wbright){
 | 
	
		
			
			|  | 445 | +				real_wbright = minlight_nonp;
 | 
	
		
			
			|  | 446 | +			}else{
 | 
	
		
			
			|  | 447 | +				real_wbright = ( best_ctrl->max_brightness * ( (float)( curr_brightp - wbright + 1) / 100 ));
 | 
	
		
			
			|  | 448 | +			}
 | 
	
		
			
			| 357 | 449 |  		break;
 | 
	
		
			
			| 358 | 450 |  		default:
 | 
	
		
			
			| 359 | 451 |  		break;
 | 
	
		
			
			| 360 | 452 |  	}
 | 
	
		
			
			| 361 | 453 |  	
 | 
	
		
			
			| 362 |  | -	minlight_nonp = best_ctrl->max_brightness * ( (float)minlight / 100);
 | 
	
		
			
			| 363 | 454 |  
 | 
	
		
			
			| 364 |  | -	/* FIXME 
 | 
	
		
			
			|  | 455 | +
 | 
	
		
			
			|  | 456 | +	/* FIXME<- SHOULD BE FIXED NOW, LETS STAY HERE ANYWAY JUST IN CASE 
 | 
	
		
			
			| 365 | 457 |  		Line below makes sure the value never wraps around and gets higher. Puts a (high) limit on max brightness.
 | 
	
		
			
			| 366 | 458 |  		Not sure if safe for portabilities sake.
 | 
	
		
			
			| 367 |  | -	 */
 | 
	
		
			
			|  | 459 | +	 
 | 
	
		
			
			| 368 | 460 |  	if(real_wbright > ((UINT_MAX/2) - best_ctrl->max_brightness)){ real_wbright = minlight_nonp; } 
 | 
	
		
			
			| 369 |  | -	
 | 
	
		
			
			|  | 461 | +	*/
 | 
	
		
			
			| 370 | 462 |  	
 | 
	
		
			
			| 371 | 463 |  	
 | 
	
		
			
			| 372 | 464 |  	if(real_wbright > best_ctrl->max_brightness){real_wbright = best_ctrl->max_brightness;}
 |