diff --git a/mmsg/mmsg.c b/mmsg/mmsg.c index 08932cf5..017f3d2a 100644 --- a/mmsg/mmsg.c +++ b/mmsg/mmsg.c @@ -88,10 +88,14 @@ static void noop_description(void *data, struct wl_output *wl_output, // Convert num to an N-bit binary string, store result in buf (minimum length // nbits+1) void bin_str_nbits(char *buf, uint32_t num, uint32_t nbits) { + if (nbits == 0) { + *buf = '\0'; + return; + } for (int32_t i = nbits - 1; i >= 0; i--) { *buf++ = ((num >> i) & 1) ? '1' : '0'; } - *buf = '\0'; // 字符串结尾 + *buf = '\0'; } static void dwl_ipc_tags(void *data, diff --git a/src/config/parse_config.h b/src/config/parse_config.h index dada63c0..4ecf9c82 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -8,9 +8,16 @@ #define SYSCONFDIR "/etc" #endif +static bool config_initialized = false; + // Clamps value in range while preserving numeric type #define CLAMP(x, min, max) \ - ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x))) + ({ \ + __typeof__(x) _x = (x); \ + __typeof__(min) _min = (min); \ + __typeof__(max) _max = (max); \ + _x < _min ? _min : (_x > _max ? _max : _x); \ + }) // 整数版本 - 截断小数部分 // Deprecated: use CLAMP or CLAMP with explicit casts instead @@ -1590,8 +1597,16 @@ bool parse_option(Config *config, char *key, char *value) { } else if (strcmp(key, "default_nmaster") == 0) { config->default_nmaster = atoi(value); } else if (strcmp(key, "tag_count") == 0) { - config->tag_count = CLAMP(atoi(value), 1, 32); - tag_count = config->tag_count; + uint32_t requested = CLAMP(atoi(value), 1, 32); + config->tag_count = requested; + if (!config_initialized) { + tag_count = requested; + } else if (tag_count != requested) { + wlr_log(WLR_INFO, + "tag_count change requires restart (current: %u, " + "requested: %u)", + tag_count, requested); + } } else if (strcmp(key, "center_master_overspread") == 0) { config->center_master_overspread = atoi(value); } else if (strcmp(key, "center_when_single_stack") == 0) { @@ -3555,6 +3570,7 @@ bool parse_config(void) { parse_correct = parse_config_file(&config, filename, true); set_default_key_bindings(&config); override_config(); + config_initialized = true; return parse_correct; } diff --git a/src/ext-protocol/ext-workspace.h b/src/ext-protocol/ext-workspace.h index 648690ef..3bb9e946 100644 --- a/src/ext-protocol/ext-workspace.h +++ b/src/ext-protocol/ext-workspace.h @@ -1,5 +1,4 @@ #include "wlr_ext_workspace_v1.h" -#include #define WORKSPACE_NAME_MAX_SIZE 12 @@ -74,7 +73,8 @@ static void handle_ext_workspace_deactivate(struct wl_listener *listener, static void get_name_from_tag_number(char *dst_buf, size_t dst_len, uint32_t tag_number) { - assert(tag_number <= tag_count); + if (tag_number > tag_count) + die("tag_number %u exceeds tag_count %u", tag_number, tag_count); if (tag_number == 0) snprintf(dst_buf, dst_len, "overview"); else diff --git a/src/mango.c b/src/mango.c index b544863b..d1ca6973 100644 --- a/src/mango.c +++ b/src/mango.c @@ -3032,6 +3032,8 @@ void createmon(struct wl_listener *listener, void *data) { wl_list_insert(&mons, &m->link); m->pertag = calloc(1, sizeof(Pertag)); + if (!m->pertag) + die("pertag calloc failed"); m->pertag->nmasters = calloc(tag_count + 1, sizeof(int32_t)); m->pertag->mfacts = calloc(tag_count + 1, sizeof(float)); m->pertag->no_hide = calloc(tag_count + 1, sizeof(bool)); @@ -3039,7 +3041,7 @@ void createmon(struct wl_listener *listener, void *data) { m->pertag->ltidxs = calloc(tag_count + 1, sizeof(const Layout *)); if (!m->pertag->nmasters || !m->pertag->mfacts || !m->pertag->no_hide || !m->pertag->no_render_border || !m->pertag->ltidxs) - die("pertag calloc failed"); + die("pertag member calloc failed"); if (chvt_backup_tag && regex_match(chvt_backup_selmon, m->wlr_output->name)) { m->tagset[0] = m->tagset[1] = (1 << (chvt_backup_tag - 1)) & TAGMASK;