mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-27 07:58:53 -04:00
feat: monitor arg support multi spec match in disptach
This commit is contained in:
parent
72898a165c
commit
8b30eb8e61
3 changed files with 76 additions and 6 deletions
|
|
@ -211,7 +211,7 @@ int32_t focusmon(const Arg *arg) {
|
||||||
if (!m->wlr_output->enabled) {
|
if (!m->wlr_output->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (regex_match(arg->v, m->wlr_output->name)) {
|
if (match_monitor_spec(arg->v, m)) {
|
||||||
tm = m;
|
tm = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1103,7 +1103,7 @@ int32_t tagmon(const Arg *arg) {
|
||||||
if (!cm->wlr_output->enabled) {
|
if (!cm->wlr_output->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (regex_match(arg->v, cm->wlr_output->name)) {
|
if (match_monitor_spec(arg->v, cm)) {
|
||||||
m = cm;
|
m = cm;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1544,7 +1544,7 @@ int32_t tagcrossmon(const Arg *arg) {
|
||||||
if (!selmon || !selmon->sel)
|
if (!selmon || !selmon->sel)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (regex_match(selmon->wlr_output->name, arg->v)) {
|
if (match_monitor_spec(arg->v, selmon)) {
|
||||||
tag_client(arg, selmon->sel);
|
tag_client(arg, selmon->sel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1702,7 +1702,7 @@ int32_t disable_monitor(const Arg *arg) {
|
||||||
Monitor *m = NULL;
|
Monitor *m = NULL;
|
||||||
struct wlr_output_state state = {0};
|
struct wlr_output_state state = {0};
|
||||||
wl_list_for_each(m, &mons, link) {
|
wl_list_for_each(m, &mons, link) {
|
||||||
if (regex_match(arg->v, m->wlr_output->name)) {
|
if (match_monitor_spec(arg->v, m)) {
|
||||||
wlr_output_state_set_enabled(&state, false);
|
wlr_output_state_set_enabled(&state, false);
|
||||||
wlr_output_commit_state(m->wlr_output, &state);
|
wlr_output_commit_state(m->wlr_output, &state);
|
||||||
m->asleep = 1;
|
m->asleep = 1;
|
||||||
|
|
@ -1717,7 +1717,7 @@ int32_t enable_monitor(const Arg *arg) {
|
||||||
Monitor *m = NULL;
|
Monitor *m = NULL;
|
||||||
struct wlr_output_state state = {0};
|
struct wlr_output_state state = {0};
|
||||||
wl_list_for_each(m, &mons, link) {
|
wl_list_for_each(m, &mons, link) {
|
||||||
if (regex_match(arg->v, m->wlr_output->name)) {
|
if (match_monitor_spec(arg->v, m)) {
|
||||||
wlr_output_state_set_enabled(&state, true);
|
wlr_output_state_set_enabled(&state, true);
|
||||||
wlr_output_commit_state(m->wlr_output, &state);
|
wlr_output_commit_state(m->wlr_output, &state);
|
||||||
m->asleep = 0;
|
m->asleep = 0;
|
||||||
|
|
@ -1732,7 +1732,7 @@ int32_t toggle_monitor(const Arg *arg) {
|
||||||
Monitor *m = NULL;
|
Monitor *m = NULL;
|
||||||
struct wlr_output_state state = {0};
|
struct wlr_output_state state = {0};
|
||||||
wl_list_for_each(m, &mons, link) {
|
wl_list_for_each(m, &mons, link) {
|
||||||
if (regex_match(arg->v, m->wlr_output->name)) {
|
if (match_monitor_spec(arg->v, m)) {
|
||||||
wlr_output_state_set_enabled(&state, !m->wlr_output->enabled);
|
wlr_output_state_set_enabled(&state, !m->wlr_output->enabled);
|
||||||
wlr_output_commit_state(m->wlr_output, &state);
|
wlr_output_commit_state(m->wlr_output, &state);
|
||||||
m->asleep = !m->wlr_output->enabled;
|
m->asleep = !m->wlr_output->enabled;
|
||||||
|
|
|
||||||
|
|
@ -105,3 +105,72 @@ Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly) {
|
||||||
return output_from_wlr_output(
|
return output_from_wlr_output(
|
||||||
wlr_output_layout_output_at(output_layout, closest_x, closest_y));
|
wlr_output_layout_output_at(output_layout, closest_x, closest_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool match_monitor_spec(char *spec, Monitor *m) {
|
||||||
|
if (!spec || !m)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// if the spec does not contain a colon, treat it as a match on the monitor
|
||||||
|
// name
|
||||||
|
if (strchr(spec, ':') == NULL) {
|
||||||
|
return regex_match(spec, m->wlr_output->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *spec_copy = strdup(spec);
|
||||||
|
if (!spec_copy)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char *name_rule = NULL;
|
||||||
|
char *make_rule = NULL;
|
||||||
|
char *model_rule = NULL;
|
||||||
|
char *serial_rule = NULL;
|
||||||
|
|
||||||
|
char *token = strtok(spec_copy, "&&");
|
||||||
|
while (token) {
|
||||||
|
char *colon = strchr(token, ':');
|
||||||
|
if (colon) {
|
||||||
|
*colon = '\0';
|
||||||
|
char *key = token;
|
||||||
|
char *value = colon + 1;
|
||||||
|
|
||||||
|
if (strcmp(key, "name") == 0)
|
||||||
|
name_rule = strdup(value);
|
||||||
|
else if (strcmp(key, "make") == 0)
|
||||||
|
make_rule = strdup(value);
|
||||||
|
else if (strcmp(key, "model") == 0)
|
||||||
|
model_rule = strdup(value);
|
||||||
|
else if (strcmp(key, "serial") == 0)
|
||||||
|
serial_rule = strdup(value);
|
||||||
|
}
|
||||||
|
token = strtok(NULL, "&&");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool match = true;
|
||||||
|
|
||||||
|
if (name_rule) {
|
||||||
|
if (!regex_match(name_rule, m->wlr_output->name))
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
if (make_rule) {
|
||||||
|
if (!m->wlr_output->make || strcmp(make_rule, m->wlr_output->make) != 0)
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
if (model_rule) {
|
||||||
|
if (!m->wlr_output->model ||
|
||||||
|
strcmp(model_rule, m->wlr_output->model) != 0)
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
if (serial_rule) {
|
||||||
|
if (!m->wlr_output->serial ||
|
||||||
|
strcmp(serial_rule, m->wlr_output->serial) != 0)
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(spec_copy);
|
||||||
|
free(name_rule);
|
||||||
|
free(make_rule);
|
||||||
|
free(model_rule);
|
||||||
|
free(serial_rule);
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
@ -813,6 +813,7 @@ static int monitor_skip_frame_timeout_callback(void *data);
|
||||||
static void handle_iamge_copy_capture_new_session(struct wl_listener *listener,
|
static void handle_iamge_copy_capture_new_session(struct wl_listener *listener,
|
||||||
void *data);
|
void *data);
|
||||||
static Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly);
|
static Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly);
|
||||||
|
static bool match_monitor_spec(char *spec, Monitor *m);
|
||||||
|
|
||||||
#include "data/static_keymap.h"
|
#include "data/static_keymap.h"
|
||||||
#include "dispatch/bind_declare.h"
|
#include "dispatch/bind_declare.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue