mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2025-11-10 13:29:55 -05:00
feat: support set monitor resolution and refresh rate in monitor rule
This commit is contained in:
parent
8889ebd604
commit
f42b3080b4
2 changed files with 33 additions and 17 deletions
|
|
@ -70,15 +70,14 @@ typedef struct {
|
||||||
} ConfigWinRule;
|
} ConfigWinRule;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name; // 显示器名称
|
const char *name; // 显示器名称
|
||||||
float mfact; // 主区域比例
|
float mfact; // 主区域比例
|
||||||
int nmaster; // 主区域窗口数量
|
int nmaster; // 主区域窗口数量
|
||||||
const char *layout; // 布局名称(字符串)
|
const char *layout; // 布局名称(字符串)
|
||||||
int rr; // 旋转和翻转(假设为整数)
|
int rr; // 旋转和翻转(假设为整数)
|
||||||
float scale; // 显示器缩放比例
|
float scale; // 显示器缩放比例
|
||||||
int x, y; // 显示器位置
|
int x, y; // 显示器位置
|
||||||
int isterm;
|
int width, height, refresh; // 显示器分辨率和刷新率
|
||||||
int noswallow;
|
|
||||||
} ConfigMonitorRule;
|
} ConfigMonitorRule;
|
||||||
|
|
||||||
// 修改后的宏定义
|
// 修改后的宏定义
|
||||||
|
|
@ -1470,16 +1469,18 @@ void parse_config_line(Config *config, const char *line) {
|
||||||
// 临时存储每个字段的原始字符串
|
// 临时存储每个字段的原始字符串
|
||||||
char raw_name[256], raw_layout[256];
|
char raw_name[256], raw_layout[256];
|
||||||
char raw_mfact[256], raw_nmaster[256], raw_rr[256];
|
char raw_mfact[256], raw_nmaster[256], raw_rr[256];
|
||||||
char raw_scale[256], raw_x[256], raw_y[256];
|
char raw_scale[256], raw_x[256], raw_y[256], raw_width[256],
|
||||||
|
raw_height[256], raw_refresh[256];
|
||||||
|
|
||||||
// 先读取所有字段为字符串
|
// 先读取所有字段为字符串
|
||||||
int parsed = sscanf(value,
|
int parsed =
|
||||||
"%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255["
|
sscanf(value,
|
||||||
"^,],%255[^,],%255s",
|
"%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255["
|
||||||
raw_name, raw_mfact, raw_nmaster, raw_layout,
|
"^,],%255[^,],%255[^,],%255[^,],%255[^,],%255s",
|
||||||
raw_rr, raw_scale, raw_x, raw_y);
|
raw_name, raw_mfact, raw_nmaster, raw_layout, raw_rr,
|
||||||
|
raw_scale, raw_x, raw_y, raw_width, raw_height, raw_refresh);
|
||||||
|
|
||||||
if (parsed == 8) {
|
if (parsed == 11) {
|
||||||
// 修剪每个字段的空格
|
// 修剪每个字段的空格
|
||||||
trim_whitespace(raw_name);
|
trim_whitespace(raw_name);
|
||||||
trim_whitespace(raw_mfact);
|
trim_whitespace(raw_mfact);
|
||||||
|
|
@ -1489,6 +1490,9 @@ void parse_config_line(Config *config, const char *line) {
|
||||||
trim_whitespace(raw_scale);
|
trim_whitespace(raw_scale);
|
||||||
trim_whitespace(raw_x);
|
trim_whitespace(raw_x);
|
||||||
trim_whitespace(raw_y);
|
trim_whitespace(raw_y);
|
||||||
|
trim_whitespace(raw_width);
|
||||||
|
trim_whitespace(raw_height);
|
||||||
|
trim_whitespace(raw_refresh);
|
||||||
|
|
||||||
// 转换修剪后的字符串为特定类型
|
// 转换修剪后的字符串为特定类型
|
||||||
rule->name = strdup(raw_name);
|
rule->name = strdup(raw_name);
|
||||||
|
|
@ -1499,6 +1503,9 @@ void parse_config_line(Config *config, const char *line) {
|
||||||
rule->scale = atof(raw_scale);
|
rule->scale = atof(raw_scale);
|
||||||
rule->x = atoi(raw_x);
|
rule->x = atoi(raw_x);
|
||||||
rule->y = atoi(raw_y);
|
rule->y = atoi(raw_y);
|
||||||
|
rule->width = atoi(raw_width);
|
||||||
|
rule->height = atoi(raw_height);
|
||||||
|
rule->refresh = atoi(raw_refresh);
|
||||||
|
|
||||||
if (!rule->name || !rule->layout) {
|
if (!rule->name || !rule->layout) {
|
||||||
if (rule->name)
|
if (rule->name)
|
||||||
|
|
|
||||||
11
src/maomao.c
11
src/maomao.c
|
|
@ -2343,6 +2343,7 @@ void createmon(struct wl_listener *listener, void *data) {
|
||||||
int ji, jk;
|
int ji, jk;
|
||||||
struct wlr_output_state state;
|
struct wlr_output_state state;
|
||||||
Monitor *m;
|
Monitor *m;
|
||||||
|
bool custom_monitor_mode = false;
|
||||||
|
|
||||||
if (!wlr_output_init_render(wlr_output, alloc, drw))
|
if (!wlr_output_init_render(wlr_output, alloc, drw))
|
||||||
return;
|
return;
|
||||||
|
|
@ -2392,6 +2393,12 @@ void createmon(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
scale = r->scale;
|
scale = r->scale;
|
||||||
rr = r->rr;
|
rr = r->rr;
|
||||||
|
|
||||||
|
if (r->width > 0 && r->height > 0 && r->refresh > 0) {
|
||||||
|
custom_monitor_mode = true;
|
||||||
|
wlr_output_state_set_custom_mode(&state, r->width, r->height,
|
||||||
|
r->refresh * 1000);
|
||||||
|
}
|
||||||
wlr_output_state_set_scale(&state, r->scale);
|
wlr_output_state_set_scale(&state, r->scale);
|
||||||
wlr_output_state_set_transform(&state, r->rr);
|
wlr_output_state_set_transform(&state, r->rr);
|
||||||
break;
|
break;
|
||||||
|
|
@ -2402,7 +2409,9 @@ void createmon(struct wl_listener *listener, void *data) {
|
||||||
* monitor supports only a specific set of modes. We just pick the
|
* monitor supports only a specific set of modes. We just pick the
|
||||||
* monitor's preferred mode; a more sophisticated compositor would let
|
* monitor's preferred mode; a more sophisticated compositor would let
|
||||||
* the user configure it. */
|
* the user configure it. */
|
||||||
wlr_output_state_set_mode(&state, wlr_output_preferred_mode(wlr_output));
|
if (!custom_monitor_mode)
|
||||||
|
wlr_output_state_set_mode(&state,
|
||||||
|
wlr_output_preferred_mode(wlr_output));
|
||||||
|
|
||||||
/* Set up event listeners */
|
/* Set up event listeners */
|
||||||
LISTEN(&wlr_output->events.frame, &m->frame, rendermon);
|
LISTEN(&wlr_output->events.frame, &m->frame, rendermon);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue