Commit e2a3df6207b354f9b92aeaa686a59d484680a019 Parent: fb891291b73beb6716cbf20a4b1b7948735bd02e Author: mcol <mcol@posteo.net> Date: 2020-11-06 01:43:28 +0000 Committer: mcol <mcol@posteo.net> Committed: 2020-11-06 01:43:28 +0000 add basic config parser, and opt to set background colour
src/types.h Modified
@@ -30,6 +30,7 @@ struct wlr_xdg_shell *shell; struct wl_listener new_xdg_surface_listener; struct wl_list views; + float background[4]; struct wlr_cursor *cursor; struct wlr_xcursor_manager *cursor_manager;
src/output.c Modified
@@ -60,8 +60,7 @@ wlr_output_effective_resolution(output->wlr_output, &width, &height); wlr_renderer_begin(renderer, width, height); - float color[4] = {0.3, 0.05, 0.7, 1.0}; // background - wlr_renderer_clear(renderer, color); + wlr_renderer_clear(renderer, output->server->background); struct view *view; wl_list_for_each_reverse(view, &output->server->views, link) {
src/deskwm.c Modified
@@ -7,6 +7,7 @@ #include <wlr/types/wlr_xdg_shell.h> #include <wlr/util/log.h> +#include "config.h" #include "deskwm.h" #include "input.h" #include "output.h" @@ -40,6 +41,9 @@ // create struct server server = create_server(); + // read config + load_config(&server); + // configure set_up_outputs(&server); set_up_shell(&server);
src/config.h Added
@@ -0,0 +1,6 @@ +#pragma once + +#include "types.h" + + +void load_config(struct server *server);
src/config.c Added
@@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "types.h" + + +void assign_colour(char *hex, float dest[4]) { + switch (strlen(hex)) { + case 6: + case 8: + break; + case 7: + case 9: + hex++; + break; + default: + return; + } + + char c[2]; + for (int i = 0; i < 3; i++) { + strncpy(c, &hex[i * 2], 2); + dest[i] = (float)strtol(c, NULL, 16) / 255; + } + dest[4] = 1; +} + + +void set_defaults(struct server *server) { + assign_colour("#5D479D", &server->background); +} + + +void load_config(struct server *server) { + set_defaults(server); + + char config[1024] = ""; + strcpy(config, getenv("HOME")); + strcat(config, "/.config/deskwm.conf"); + + if(access(config, R_OK) == -1) { + return; + } + FILE *fd = fopen(config, "r"); + + char *s; + char linebuf[1024]; + while (fgets(linebuf, sizeof(linebuf), fd)) { + if (!(s = strtok(linebuf, " \t\n\r")) || s[0] == '#') { + continue; + } + if (!strcasecmp(s, "background")) { + if ((s = strtok(NULL, " \t\n\r"))) { + assign_colour(s, &server->background); + } + } else if (!strcasecmp(s, "modifier")) { + } + } + fclose(fd); +}