调整有多个 class 相同的 client 时 raise_or_run 的行为
This commit is contained in:
76
src/main.c
76
src/main.c
@@ -73,6 +73,7 @@ static monitor_t *get_monitor_by_direction(bool forward);
|
|||||||
static void send_client_to_monitor(client_t *client, monitor_t *monitor);
|
static void send_client_to_monitor(client_t *client, monitor_t *monitor);
|
||||||
static void set_client_tag_prop(client_t *client);
|
static void set_client_tag_prop(client_t *client);
|
||||||
static bool restore_client_tag(client_t *client);
|
static bool restore_client_tag(client_t *client);
|
||||||
|
static client_t *get_next_client_with_class(const char *class);
|
||||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||||
gpointer userdata);
|
gpointer userdata);
|
||||||
static void cleanup(bool will_restart);
|
static void cleanup(bool will_restart);
|
||||||
@@ -170,25 +171,25 @@ void focus_monitor(const user_action_arg_t *arg) {
|
|||||||
|
|
||||||
void raise_or_run(const user_action_arg_t *arg) {
|
void raise_or_run(const user_action_arg_t *arg) {
|
||||||
const char *class = ((const char **)arg->ptr)[0];
|
const char *class = ((const char **)arg->ptr)[0];
|
||||||
const char *command = ((const char **)arg->ptr)[1];
|
client_t *client = get_next_client_with_class(class);
|
||||||
|
if (client && client == current_monitor->selected_client) return;
|
||||||
|
|
||||||
user_action_arg_t argument;
|
user_action_arg_t argument;
|
||||||
for (monitor_t *m = monitors; m; m = m->next) {
|
if (client) {
|
||||||
for (client_t *c = m->clients; c; c = c->next) {
|
logger("==== raise client: %s, window: 0x%x\n", client->name,
|
||||||
window_class_instance_t class_instance;
|
client->window);
|
||||||
get_window_class_instance(c->window, &class_instance);
|
current_monitor = client->monitor;
|
||||||
if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) {
|
argument.ui = client->tags;
|
||||||
current_monitor = m;
|
select_tag(&argument);
|
||||||
argument.ui = c->tags;
|
focus(client);
|
||||||
select_tag(&argument);
|
raise_window(client->window);
|
||||||
focus(c);
|
return;
|
||||||
raise_window(c->window);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *command = ((const char **)arg->ptr)[1];
|
||||||
argument.ptr = command;
|
argument.ptr = command;
|
||||||
spawn(&argument);
|
spawn(&argument);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggle_mute(const user_action_arg_t *arg) { toggle_pulse_mute(); }
|
void toggle_mute(const user_action_arg_t *arg) { toggle_pulse_mute(); }
|
||||||
@@ -1202,6 +1203,53 @@ bool restore_client_tag(client_t *client) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client_t *get_next_client_with_class(const char *class) {
|
||||||
|
monitor_t *m = NULL;
|
||||||
|
client_t *c = NULL;
|
||||||
|
window_class_instance_t class_instance;
|
||||||
|
|
||||||
|
for (m = current_monitor; m; m = m->next) {
|
||||||
|
if (m == current_monitor && m->selected_client) {
|
||||||
|
c = m->selected_client->next;
|
||||||
|
} else {
|
||||||
|
c = m->clients;
|
||||||
|
}
|
||||||
|
for (; c; c = c->next) {
|
||||||
|
get_window_class_instance(c->window, &class_instance);
|
||||||
|
if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (m = monitors; m && m != current_monitor; m = m->next) {
|
||||||
|
for (c = m->clients; c; c = c->next) {
|
||||||
|
get_window_class_instance(c->window, &class_instance);
|
||||||
|
if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m = current_monitor;
|
||||||
|
for (c = m->clients; c && m->selected_client && c != m->selected_client;
|
||||||
|
c = c->next) {
|
||||||
|
get_window_class_instance(c->window, &class_instance);
|
||||||
|
if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_monitor->selected_client) {
|
||||||
|
get_window_class_instance(c->window, &class_instance);
|
||||||
|
if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||||
gpointer userdata) {
|
gpointer userdata) {
|
||||||
if (condition & (G_IO_HUP | G_IO_ERR)) {
|
if (condition & (G_IO_HUP | G_IO_ERR)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user