mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-06-04 03:02:37 -04:00
Improve consistency of tag types; streamline CLAMP macro
This commit is contained in:
parent
923c7add5b
commit
686bd7f6ec
5 changed files with 36 additions and 31 deletions
31
mmsg/mmsg.c
31
mmsg/mmsg.c
|
|
@ -46,7 +46,7 @@ static int32_t Aflag;
|
||||||
static uint32_t occ, seltags, total_clients, urg;
|
static uint32_t occ, seltags, total_clients, urg;
|
||||||
|
|
||||||
static char *output_name;
|
static char *output_name;
|
||||||
static int32_t tagcount;
|
static uint32_t tag_count;
|
||||||
static char *tagset;
|
static char *tagset;
|
||||||
static char *layout_name;
|
static char *layout_name;
|
||||||
static int32_t layoutcount, layout_idx;
|
static int32_t layoutcount, layout_idx;
|
||||||
|
|
@ -85,10 +85,11 @@ static void noop_scale(void *data, struct wl_output *wl_output,
|
||||||
static void noop_description(void *data, struct wl_output *wl_output,
|
static void noop_description(void *data, struct wl_output *wl_output,
|
||||||
const char *description) {}
|
const char *description) {}
|
||||||
|
|
||||||
// Convert n to an N-bit binary string, store result in buf (minimum length bits+1)
|
// Convert num to an N-bit binary string, store result in buf (minimum length
|
||||||
void bin_str_nbits(char *buf, uint32_t n, int32_t bits) {
|
// nbits+1)
|
||||||
for (int32_t i = bits - 1; i >= 0; i--) {
|
void bin_str_nbits(char *buf, uint32_t num, uint32_t nbits) {
|
||||||
*buf++ = ((n >> i) & 1) ? '1' : '0';
|
for (int32_t i = nbits - 1; i >= 0; i--) {
|
||||||
|
*buf++ = ((num >> i) & 1) ? '1' : '0';
|
||||||
}
|
}
|
||||||
*buf = '\0'; // 字符串结尾
|
*buf = '\0'; // 字符串结尾
|
||||||
}
|
}
|
||||||
|
|
@ -96,9 +97,9 @@ void bin_str_nbits(char *buf, uint32_t n, int32_t bits) {
|
||||||
static void dwl_ipc_tags(void *data,
|
static void dwl_ipc_tags(void *data,
|
||||||
struct zdwl_ipc_manager_v2 *dwl_ipc_manager,
|
struct zdwl_ipc_manager_v2 *dwl_ipc_manager,
|
||||||
uint32_t count) {
|
uint32_t count) {
|
||||||
tagcount = count;
|
tag_count = count;
|
||||||
if (Tflag && mode & GET)
|
if (Tflag && mode & GET)
|
||||||
printf("%d\n", tagcount);
|
printf("%u\n", tag_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dwl_ipc_layout(void *data,
|
static void dwl_ipc_layout(void *data,
|
||||||
|
|
@ -324,7 +325,7 @@ static void dwl_ipc_output_frame(void *data,
|
||||||
if (tflag) {
|
if (tflag) {
|
||||||
uint32_t mask = seltags;
|
uint32_t mask = seltags;
|
||||||
char *t = tagset;
|
char *t = tagset;
|
||||||
int32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
||||||
for (; *t && *t >= '0' && *t <= '9'; t++)
|
for (; *t && *t >= '0' && *t <= '9'; t++)
|
||||||
i = *t - '0' + i * 10;
|
i = *t - '0' + i * 10;
|
||||||
|
|
@ -346,7 +347,7 @@ static void dwl_ipc_output_frame(void *data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((i - 1) > tagcount)
|
if ((i - 1) > tag_count)
|
||||||
die("bad tagset %s", tagset);
|
die("bad tagset %s", tagset);
|
||||||
|
|
||||||
zdwl_ipc_output_v2_set_tags(dwl_ipc_output, mask, 0);
|
zdwl_ipc_output_v2_set_tags(dwl_ipc_output, mask, 0);
|
||||||
|
|
@ -354,7 +355,7 @@ static void dwl_ipc_output_frame(void *data,
|
||||||
if (cflag) {
|
if (cflag) {
|
||||||
uint32_t and = ~0, xor = 0;
|
uint32_t and = ~0, xor = 0;
|
||||||
char *t = client_tags;
|
char *t = client_tags;
|
||||||
int32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
||||||
for (; *t && *t >= '0' && *t <= '9'; t++)
|
for (; *t && *t >= '0' && *t <= '9'; t++)
|
||||||
i = *t - '0' + i * 10;
|
i = *t - '0' + i * 10;
|
||||||
|
|
@ -376,7 +377,7 @@ static void dwl_ipc_output_frame(void *data,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i - 1) > tagcount)
|
if ((i - 1) > tag_count)
|
||||||
die("bad client tagset %s", client_tags);
|
die("bad client tagset %s", client_tags);
|
||||||
|
|
||||||
zdwl_ipc_output_v2_set_client_tags(dwl_ipc_output, and, xor);
|
zdwl_ipc_output_v2_set_client_tags(dwl_ipc_output, and, xor);
|
||||||
|
|
@ -395,11 +396,11 @@ static void dwl_ipc_output_frame(void *data,
|
||||||
|
|
||||||
printf("%s clients %u\n", output_name, total_clients);
|
printf("%s clients %u\n", output_name, total_clients);
|
||||||
|
|
||||||
char occ_str[tagcount + 1], seltags_str[tagcount + 1], urg_str[tagcount + 1];
|
char occ_str[tag_count + 1], seltags_str[tag_count + 1], urg_str[tag_count + 1];
|
||||||
|
|
||||||
bin_str_nbits(occ_str, occ, tagcount);
|
bin_str_nbits(occ_str, occ, tag_count);
|
||||||
bin_str_nbits(seltags_str, seltags, tagcount);
|
bin_str_nbits(seltags_str, seltags, tag_count);
|
||||||
bin_str_nbits(urg_str, urg, tagcount);
|
bin_str_nbits(urg_str, urg, tag_count);
|
||||||
printf("%s tags %u %u %u\n", output_name, occ, seltags, urg);
|
printf("%s tags %u %u %u\n", output_name, occ, seltags, urg);
|
||||||
printf("%s tags %s %s %s\n", output_name, occ_str, seltags_str,
|
printf("%s tags %s %s %s\n", output_name, occ_str, seltags_str,
|
||||||
urg_str);
|
urg_str);
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,19 @@
|
||||||
#define SYSCONFDIR "/etc"
|
#define SYSCONFDIR "/etc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Clamps value in range while preserving numeric type
|
||||||
|
#define CLAMP(x, min, max) \
|
||||||
|
((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
|
||||||
|
|
||||||
// 整数版本 - 截断小数部分
|
// 整数版本 - 截断小数部分
|
||||||
|
// Deprecated: use CLAMP or CLAMP with explicit casts instead
|
||||||
#define CLAMP_INT(x, min, max) \
|
#define CLAMP_INT(x, min, max) \
|
||||||
((int32_t)(x) < (int32_t)(min) \
|
CLAMP((int32_t)(x), (int32_t)(min), (int32_t)(max))
|
||||||
? (int32_t)(min) \
|
|
||||||
: ((int32_t)(x) > (int32_t)(max) ? (int32_t)(max) : (int32_t)(x)))
|
|
||||||
|
|
||||||
// 浮点数版本 - 保留小数部分
|
// 浮点数版本 - 保留小数部分
|
||||||
|
// Deprecated: use CLAMP instead
|
||||||
#define CLAMP_FLOAT(x, min, max) \
|
#define CLAMP_FLOAT(x, min, max) \
|
||||||
((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
|
CLAMP(x, min, max)
|
||||||
|
|
||||||
enum { NUM_TYPE_MINUS, NUM_TYPE_PLUS, NUM_TYPE_DEFAULT };
|
enum { NUM_TYPE_MINUS, NUM_TYPE_PLUS, NUM_TYPE_DEFAULT };
|
||||||
|
|
||||||
|
|
@ -159,7 +163,7 @@ typedef struct {
|
||||||
} GestureBinding;
|
} GestureBinding;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t id;
|
uint32_t id;
|
||||||
char *layout_name;
|
char *layout_name;
|
||||||
char *monitor_name;
|
char *monitor_name;
|
||||||
char *monitor_make;
|
char *monitor_make;
|
||||||
|
|
@ -314,7 +318,7 @@ typedef struct {
|
||||||
|
|
||||||
char autostart[3][256];
|
char autostart[3][256];
|
||||||
|
|
||||||
int32_t tag_count;
|
uint32_t tag_count;
|
||||||
ConfigTagRule *tag_rules; // 动态数组
|
ConfigTagRule *tag_rules; // 动态数组
|
||||||
int32_t tag_rules_count; // 数量
|
int32_t tag_rules_count; // 数量
|
||||||
|
|
||||||
|
|
@ -1586,7 +1590,7 @@ bool parse_option(Config *config, char *key, char *value) {
|
||||||
} else if (strcmp(key, "default_nmaster") == 0) {
|
} else if (strcmp(key, "default_nmaster") == 0) {
|
||||||
config->default_nmaster = atoi(value);
|
config->default_nmaster = atoi(value);
|
||||||
} else if (strcmp(key, "tag_count") == 0) {
|
} else if (strcmp(key, "tag_count") == 0) {
|
||||||
config->tag_count = CLAMP_INT(atoi(value), 1, 32);
|
config->tag_count = CLAMP(atoi(value), 1, 32);
|
||||||
tag_count = config->tag_count;
|
tag_count = config->tag_count;
|
||||||
} else if (strcmp(key, "center_master_overspread") == 0) {
|
} else if (strcmp(key, "center_master_overspread") == 0) {
|
||||||
config->center_master_overspread = atoi(value);
|
config->center_master_overspread = atoi(value);
|
||||||
|
|
@ -3707,7 +3711,7 @@ void reapply_pointer(void) {
|
||||||
|
|
||||||
void reapply_master(void) {
|
void reapply_master(void) {
|
||||||
|
|
||||||
int32_t i;
|
uint32_t i;
|
||||||
Monitor *m = NULL;
|
Monitor *m = NULL;
|
||||||
for (i = 0; i <= tag_count; i++) {
|
for (i = 0; i <= tag_count; i++) {
|
||||||
wl_list_for_each(m, &mons, link) {
|
wl_list_for_each(m, &mons, link) {
|
||||||
|
|
@ -3725,7 +3729,7 @@ void reapply_master(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_tagrule(Monitor *m) {
|
void parse_tagrule(Monitor *m) {
|
||||||
int32_t i, jk;
|
uint32_t i, jk;
|
||||||
ConfigTagRule tr;
|
ConfigTagRule tr;
|
||||||
Client *c = NULL;
|
Client *c = NULL;
|
||||||
bool match_rule = false;
|
bool match_rule = false;
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
|
||||||
/* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */
|
/* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */
|
||||||
#define MODKEY WLR_MODIFIER_ALT
|
#define MODKEY WLR_MODIFIER_ALT
|
||||||
|
|
||||||
int32_t tag_count = 9;
|
uint32_t tag_count = 9;
|
||||||
|
|
||||||
float focused_opacity = 1.0;
|
float focused_opacity = 1.0;
|
||||||
float unfocused_opacity = 1.0;
|
float unfocused_opacity = 1.0;
|
||||||
|
|
|
||||||
|
|
@ -112,15 +112,15 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
|
||||||
Client *c = NULL, *focused = NULL;
|
Client *c = NULL, *focused = NULL;
|
||||||
struct wlr_keyboard *keyboard;
|
struct wlr_keyboard *keyboard;
|
||||||
xkb_layout_index_t current;
|
xkb_layout_index_t current;
|
||||||
int32_t tagmask, state, numclients, focused_client, tag;
|
uint32_t tagmask, state, numclients, focused_client, tag_idx;
|
||||||
const char *title, *appid, *symbol;
|
const char *title, *appid, *symbol;
|
||||||
char kb_layout[32];
|
char kb_layout[32];
|
||||||
focused = focustop(monitor);
|
focused = focustop(monitor);
|
||||||
zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
|
zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon);
|
||||||
|
|
||||||
for (tag = 0; tag < tag_count; tag++) {
|
for (tag_idx = 0; tag_idx < tag_count; tag_idx++) {
|
||||||
numclients = state = focused_client = 0;
|
numclients = state = focused_client = 0;
|
||||||
tagmask = 1 << tag;
|
tagmask = 1 << tag_idx;
|
||||||
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
|
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
|
||||||
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
|
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
|
||||||
wl_list_for_each(c, &clients, link) {
|
wl_list_for_each(c, &clients, link) {
|
||||||
|
|
@ -134,7 +134,7 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
|
||||||
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
|
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
|
||||||
numclients++;
|
numclients++;
|
||||||
}
|
}
|
||||||
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
|
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag_idx, state,
|
||||||
numclients, focused_client);
|
numclients, focused_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ static void handle_ext_workspace_deactivate(struct wl_listener *listener,
|
||||||
|
|
||||||
static void get_name_from_tag_number(char *dst_buf, size_t dst_len,
|
static void get_name_from_tag_number(char *dst_buf, size_t dst_len,
|
||||||
uint32_t tag_number) {
|
uint32_t tag_number) {
|
||||||
assert(tag_number <= (uint32_t)tag_count);
|
assert(tag_number <= tag_count);
|
||||||
if (tag_number == 0)
|
if (tag_number == 0)
|
||||||
snprintf(dst_buf, dst_len, "overview");
|
snprintf(dst_buf, dst_len, "overview");
|
||||||
else
|
else
|
||||||
|
|
@ -169,7 +169,7 @@ void dwl_ext_workspace_printstatus(Monitor *m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh_monitors_workspaces_status(Monitor *m) {
|
void refresh_monitors_workspaces_status(Monitor *m) {
|
||||||
int32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (m->isoverview) {
|
if (m->isoverview) {
|
||||||
for (i = 1; i <= tag_count; i++) {
|
for (i = 1; i <= tag_count; i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue