mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2025-12-17 15:45:12 +02:00
Store sfdo-basedir ctx in state
This commit is contained in:
12
src/config.c
12
src/config.c
@@ -1,7 +1,6 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sfdo-basedir.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -86,8 +85,8 @@ static void load_key(const char *value, int line_idx, xkb_keysym_t *out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dp_config_load(struct dp_config *config, const char *user_path) {
|
void dp_config_load(struct dp_state *state, const char *user_path) {
|
||||||
FILE *fp = NULL;
|
struct dp_config *config = &state->config;
|
||||||
|
|
||||||
*config = (struct dp_config){
|
*config = (struct dp_config){
|
||||||
.quit_key = XKB_KEY_Escape,
|
.quit_key = XKB_KEY_Escape,
|
||||||
@@ -100,16 +99,15 @@ void dp_config_load(struct dp_config *config, const char *user_path) {
|
|||||||
bytes_to_color((uint8_t[]){0x00, 0x00, 0x00, 0x00}, config->selected_color);
|
bytes_to_color((uint8_t[]){0x00, 0x00, 0x00, 0x00}, config->selected_color);
|
||||||
bytes_to_color((uint8_t[]){0xff, 0xff, 0xff, 0xff}, config->border_color);
|
bytes_to_color((uint8_t[]){0xff, 0xff, 0xff, 0xff}, config->border_color);
|
||||||
|
|
||||||
|
FILE *fp = NULL;
|
||||||
if (user_path != NULL) {
|
if (user_path != NULL) {
|
||||||
fp = fopen(user_path, "r");
|
fp = fopen(user_path, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
dp_log_fatal("Failed to open %s: %s", user_path, strerror(errno));
|
dp_log_fatal("Failed to open %s: %s", user_path, strerror(errno));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct sfdo_basedir_ctx *basedir_ctx = sfdo_basedir_ctx_create();
|
|
||||||
|
|
||||||
size_t n_dirs;
|
size_t n_dirs;
|
||||||
const struct sfdo_string *dirs = sfdo_basedir_get_config_dirs(basedir_ctx, &n_dirs);
|
const struct sfdo_string *dirs = sfdo_basedir_get_config_dirs(state->basedir_ctx, &n_dirs);
|
||||||
for (size_t i = 0; i < n_dirs && fp == NULL; i++) {
|
for (size_t i = 0; i < n_dirs && fp == NULL; i++) {
|
||||||
const struct sfdo_string *dir = &dirs[i];
|
const struct sfdo_string *dir = &dirs[i];
|
||||||
size_t size = dir->len + sizeof(CONFIG_SUBPATH);
|
size_t size = dir->len + sizeof(CONFIG_SUBPATH);
|
||||||
@@ -124,8 +122,6 @@ void dp_config_load(struct dp_config *config, const char *user_path) {
|
|||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
sfdo_basedir_ctx_destroy(basedir_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define DULCEPAN_H
|
#define DULCEPAN_H
|
||||||
|
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
#include <sfdo-basedir.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
@@ -157,6 +158,8 @@ struct dp_state {
|
|||||||
|
|
||||||
struct xkb_context *xkb_context;
|
struct xkb_context *xkb_context;
|
||||||
|
|
||||||
|
struct sfdo_basedir_ctx *basedir_ctx;
|
||||||
|
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
struct wl_list seats;
|
struct wl_list seats;
|
||||||
|
|
||||||
@@ -169,7 +172,7 @@ struct dp_state {
|
|||||||
bool show_cursors;
|
bool show_cursors;
|
||||||
};
|
};
|
||||||
|
|
||||||
void dp_config_load(struct dp_config *config, const char *user_path);
|
void dp_config_load(struct dp_state *state, const char *user_path);
|
||||||
|
|
||||||
// When done, data must be unmapped
|
// When done, data must be unmapped
|
||||||
struct wl_buffer *dp_buffer_create(struct dp_state *state, int32_t width, int32_t height,
|
struct wl_buffer *dp_buffer_create(struct dp_state *state, int32_t width, int32_t height,
|
||||||
|
|||||||
@@ -198,7 +198,9 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dp_config_load(&state.config, config_path);
|
state.basedir_ctx = sfdo_basedir_ctx_create();
|
||||||
|
|
||||||
|
dp_config_load(&state, config_path);
|
||||||
|
|
||||||
if (state.output_format == DP_FILE_UNKNOWN) {
|
if (state.output_format == DP_FILE_UNKNOWN) {
|
||||||
if (state.output_path != NULL) {
|
if (state.output_path != NULL) {
|
||||||
@@ -229,6 +231,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
wl_display_disconnect(state.display);
|
wl_display_disconnect(state.display);
|
||||||
|
|
||||||
|
sfdo_basedir_ctx_destroy(state.basedir_ctx);
|
||||||
|
|
||||||
if (state.status == DP_STATUS_QUIT) {
|
if (state.status == DP_STATUS_QUIT) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user