some changes, still needs polish
This commit is contained in:
parent
34c0c6988d
commit
cacfd2e244
26
c/colors.c
26
c/colors.c
|
@ -116,7 +116,7 @@ void adjust_colors(struct color *colors) {
|
||||||
int check_colors(struct color *colors) {
|
int check_colors(struct color *colors) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
if(colors[i].r == colors[i].g == colors[i].b) j++;
|
if(colors[i].r + colors[i].g + colors[i].b == 0) j++;
|
||||||
}
|
}
|
||||||
if(j > 0) return 0;
|
if(j > 0) return 0;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -138,7 +138,6 @@ struct color *get_colors(char *filename) {
|
||||||
/* generalized function ,
|
/* generalized function ,
|
||||||
* used by get_conf_file and get_wal_dir */
|
* used by get_conf_file and get_wal_dir */
|
||||||
char *get_file_gen(char *initvar, char *backvar, char *postfix, char *file) {
|
char *get_file_gen(char *initvar, char *backvar, char *postfix, char *file) {
|
||||||
printf("%s %s %s %s\n", initvar, backvar, postfix, file);
|
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
int extension = 0;
|
int extension = 0;
|
||||||
char *path = getenv(initvar);
|
char *path = getenv(initvar);
|
||||||
|
@ -166,8 +165,7 @@ char *get_wal_dir(char *file) {
|
||||||
return get_file_gen("XDG_DATA_HOME", "HOME", "/.local/share/wallpapers", file);
|
return get_file_gen("XDG_DATA_HOME", "HOME", "/.local/share/wallpapers", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *select_random(void) {
|
char *select_random_rel(void) {
|
||||||
printf("%s\n", get_wal_dir(NULL));
|
|
||||||
DIR *dir = opendir(get_wal_dir(NULL));
|
DIR *dir = opendir(get_wal_dir(NULL));
|
||||||
struct dirent *file;
|
struct dirent *file;
|
||||||
/* probably should move hardcoded constants somewhere that makes sense */
|
/* probably should move hardcoded constants somewhere that makes sense */
|
||||||
|
@ -195,7 +193,7 @@ void print_color(struct color *color) {
|
||||||
|
|
||||||
void run_handler(struct color *colors, char *wal) {
|
void run_handler(struct color *colors, char *wal) {
|
||||||
char chars[16][8];
|
char chars[16][8];
|
||||||
char *argv[18];
|
char *argv[19];
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
snprintf(&chars[i], 8, "#%02x%02x%02x", colors[i].r, colors[i].g, colors[i].b);
|
snprintf(&chars[i], 8, "#%02x%02x%02x", colors[i].r, colors[i].g, colors[i].b);
|
||||||
|
@ -203,9 +201,9 @@ void run_handler(struct color *colors, char *wal) {
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
argv[i + 1] = &chars[i];
|
argv[i + 1] = &chars[i];
|
||||||
}
|
}
|
||||||
argv[17] = NULL;
|
argv[17] = wal;
|
||||||
|
argv[18] = NULL;
|
||||||
|
|
||||||
printf("envp[0] = %s\n", argv[1]);
|
|
||||||
char *conf = get_conf_file("handler");
|
char *conf = get_conf_file("handler");
|
||||||
argv[0] = "handler";
|
argv[0] = "handler";
|
||||||
|
|
||||||
|
@ -225,11 +223,17 @@ struct settings {
|
||||||
.r = 1,
|
.r = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(void) {
|
char *select_random_file(void) {
|
||||||
char *file = select_random();
|
char *file = select_random_rel();
|
||||||
printf("%s\n", file);
|
static char ret[256];
|
||||||
file = get_wal_dir(file);
|
file = get_wal_dir(file);
|
||||||
printf("%s\n", file);
|
memcpy(&ret, file, 256);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char *file = select_random_file();
|
||||||
struct color *colors = get_colors(file);
|
struct color *colors = get_colors(file);
|
||||||
printf("%i\n", check_colors(colors));
|
printf("%i\n", check_colors(colors));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue