From 5f048c4c4ead0be9bbfbdfdfb03ac54c81e16b4f Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 22 Apr 2025 11:02:12 +0800 Subject: [PATCH] feat:windowrule allowed to further match the title on the premise of matching the id --- config.conf | 3 +-- src/maomao.c | 42 ++++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/config.conf b/config.conf index 22d354a..c2354e7 100644 --- a/config.conf +++ b/config.conf @@ -121,8 +121,7 @@ tags=id:9,layout_name:tile # example # windowrule=isfloating:1,appid:yesplaymusic -# windowrule=width:1500,appid:yesplaymusic -# windowrule=height:900,appid:yesplaymusic +# windowrule=width:1000,height:900,appid:yesplaymusic,title:Demons # windowrule=isfloating:1,title:qxdrag # windowrule=isfloating:1,appid:Rofi # windowrule=isfloating:1,appid:wofi diff --git a/src/maomao.c b/src/maomao.c index e4cba0f..866c81b 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -1572,8 +1572,9 @@ applyrulesgeom(Client *c) { if (config.window_rules_count < 1) break; r = &config.window_rules[ji]; - if ((r->title && strstr(title, r->title)) || - (r->id && strstr(appid, r->id))) { + if ((r->title && strstr(title, r->title) && !r->id) || + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.height = r->height > 0 ? r->height : c->geom.height; // 重新计算居中的坐标 @@ -1608,8 +1609,9 @@ applyrules(Client *c) { break; r = &config.window_rules[ji]; - if ((r->title && strstr(title, r->title)) || - (r->id && strstr(appid, r->id))) { + if ((r->title && strstr(title, r->title) && !r->id) || + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { c->isterm = r->isterm > 0 ? r->isterm : c->isterm; c->noswallow = r->noswallow > 0 ? r->noswallow : c->noswallow; c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating; @@ -3707,7 +3709,7 @@ bool keypressglobal(struct wlr_surface *last_surface, int reset = false; const char *appid = NULL; const char *title = NULL; - int appid_len, title_len, ji; + int ji; const ConfigWinRule *r; for (ji = 0; ji < config.window_rules_count; ji++) { @@ -3725,28 +3727,16 @@ bool keypressglobal(struct wlr_surface *last_surface, if (c && c != lastc) { appid = client_get_appid(c); title = client_get_title(c); - if (appid && r->id) { - appid_len = strlen(appid); - if (strncmp(appid, r->id, appid_len) == 0) { - reset = true; - wlr_seat_keyboard_enter(seat, client_surface(c), keycodes, 0, - &keyboard->modifiers); - wlr_seat_keyboard_send_key(seat, event->time_msec, event->keycode, - event->state); - goto done; - } - } - if (title && r->title) { - title_len = strlen(title); - if (strncmp(title, r->title, title_len) == 0) { - reset = true; - wlr_seat_keyboard_enter(seat, client_surface(c), keycodes, 0, - &keyboard->modifiers); - wlr_seat_keyboard_send_key(seat, event->time_msec, event->keycode, - event->state); - goto done; - } + if ((r->title && strstr(title, r->title) && !r->id) || + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { + reset = true; + wlr_seat_keyboard_enter(seat, client_surface(c), keycodes, 0, + &keyboard->modifiers); + wlr_seat_keyboard_send_key(seat, event->time_msec, event->keycode, + event->state); + goto done; } } }