diff --git a/meson.build b/meson.build index f9dec35..8081bd0 100644 --- a/meson.build +++ b/meson.build @@ -3,13 +3,15 @@ project('network.cycles.wdisplays', 'c', license: 'GPL-3.0-or-later', - version: '1.1.3' + version: '1.1.3', + meson_version:'>=1.1' ) conf = configuration_data({ 'app_id': meson.project_name(), 'version': meson.project_version(), 'resource_prefix': '/' / '/'.join(meson.project_name().split('.')), + 'WITH_KANSHI': get_option('kanshi').allowed(), }) subdir('protocol') diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..de78db1 --- /dev/null +++ b/meson.options @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: NONE +option('kanshi', type:'feature', description: 'Build support for saving config for the kanshi daemon') diff --git a/src/config.h.in b/src/config.h.in index 47a8834..f62aeab 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -8,4 +8,7 @@ #define WDISPLAYS_VERSION "@version@" #define WDISPLAYS_RESOURCE_PREFIX "@resource_prefix@" +// Features +#mesondefine WITH_KANSHI + #endif diff --git a/src/outputs.c b/src/outputs.c index f4ac15c..b294451 100644 --- a/src/outputs.c +++ b/src/outputs.c @@ -54,11 +54,13 @@ static void config_handle_succeeded(void *data, struct wd_pending_config *pending = data; zwlr_output_configuration_v1_destroy(config); wd_ui_apply_done(pending->state, pending->outputs); - if (store_config(pending->outputs) == 0) +#ifdef WITH_KANSHI + if (wd_store_config(pending->outputs) == 0) { wd_ui_show_error(pending->state, "Change was applied successfully and config was saved."); } +#endif destroy_pending(pending); } diff --git a/src/store.c b/src/store.c index 5d07272..728b049 100644 --- a/src/store.c +++ b/src/store.c @@ -5,17 +5,12 @@ #include "wdisplays.h" #include #include -#include -#include #include #include -#include #include #define MAX_NAME_LENGTH 256 -struct wd_head_config; - struct profile_line { int start; int end; @@ -23,7 +18,7 @@ struct profile_line { typedef enum { Looking_for_profile, Looking_for_outputs, Found } parser_states; -char *wd_get_config_file_path() { +char *wd_get_kanshi_config_file_path() { char kanshiConfigPath[PATH_MAX]; char wdisplaysPath[PATH_MAX]; char defaultConfigDir[PATH_MAX]; @@ -75,8 +70,10 @@ char *wd_get_config_file_path() { } // reached end of file fclose(wdisplaysFile); } else { // can't open config file + #ifdef VERBOSE dprintf(2, "%s:%i:%s(): Can't open %s : ", __FILE__, __LINE__, __func__, wdisplaysPath); perror(NULL); + #endif } // look for WDISPLAYS_KANSHI_CONFIG @@ -107,7 +104,9 @@ struct profile_line match(char **descriptions, int num, const char *filename) { } // buffer to store each line char buffer[LINE_MAX]; +#ifdef VERBOSE char *profileName; +#endif int profileStartLine = 0; // mark the start line of matched profile int profileEndLine = 0; // mark the end line of matched profile @@ -123,12 +122,14 @@ struct profile_line match(char **descriptions, int num, const char *filename) { // check if "profile" keyword is in the line and remember its position char *pstart = strstr(buffer, "profile "); if (pstart != NULL) { + #ifdef VERBOSE pstart += 7; char *pend = strchr(pstart, '{'); // find the end of the profile name while (isspace(*pend)) pend--; size_t pnsize = pend - pstart; // use strndup to extract it without being size constrained profileName = strndup(pstart, pnsize); + #endif // record the start line of the profile profileStartLine = lineCount; ps = Looking_for_outputs; @@ -162,8 +163,11 @@ struct profile_line match(char **descriptions, int num, const char *filename) { } fclose(configFile); if (ps == Found) { + + #ifdef VERBOSE printf("Matched profile:%s\n", profileName); printf("Start line:%d\nEnd line:%d\n", profileStartLine, profileEndLine); + #endif matched_profile.start = profileStartLine; matched_profile.end = profileEndLine; } else dprintf(2, "%s:%i:%s(): Cannot find existing profile to match\n", __FILE__, __LINE__, __func__); @@ -171,7 +175,7 @@ struct profile_line match(char **descriptions, int num, const char *filename) { } int wd_store_config(struct wl_list *outputs) { - const char *file_name = wd_get_kanshi_config(); + const char *file_name = wd_get_kanshi_config_file_path(); char tmp_file_name[PATH_MAX]; sprintf(tmp_file_name, "%s.tmp", file_name); @@ -252,7 +256,7 @@ int wd_store_config(struct wl_list *outputs) { while (fgets(_buffer, sizeof(_buffer), file) != NULL) { if (_line >= matched_profile.start && _line < matched_profile.end - 1) { if (_i_output >= num_of_monitors) { - perror("Null pointer"); + dprintf(2, "%s:%i:%s(): too many outputs : %i", __FILE__, __LINE__, __func__, _i_output); fclose(tmp); fclose(file); return 1; diff --git a/src/wdisplays.h b/src/wdisplays.h index e20a609..9e2b76d 100644 --- a/src/wdisplays.h +++ b/src/wdisplays.h @@ -344,19 +344,16 @@ void wd_destroy_overlay(struct wd_output *output); // SPDX-SnippetBegin // SPDX-License-Identifier: MIT // SPDX-SnippetCopyrightText: 2024-2025 Jason André Charles Gantner +#ifdef WITH_KANSHI /* * Locate kanshi config */ -char *wd_get_config_file_path(); - -/* - * Returns kanshi config path - */ -char *wd_get_kanshi_config(); +char *wd_get_kanshi_config_file_path(); /* * Updates kanshi config */ int wd_store_config(struct wl_list *outputs); +#endif // SPDX-SnippetEnd #endif