mirror of
https://github.com/swaywm/sway.git
synced 2026-04-21 06:46:22 -04:00
Merge b343a55e68 into dadf3e9b78
This commit is contained in:
commit
765dfb5142
6 changed files with 52 additions and 54 deletions
|
|
@ -96,6 +96,9 @@ void output_damage_box(struct sway_output *output, struct wlr_box *box);
|
|||
void output_damage_whole_container(struct sway_output *output,
|
||||
struct sway_container *con);
|
||||
|
||||
bool output_match_name_or_id(struct sway_output *output,
|
||||
const char *name_or_id);
|
||||
|
||||
// this ONLY includes the enabled outputs
|
||||
struct sway_output *output_by_name_or_id(const char *name_or_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -153,29 +153,23 @@ static void merge_wildcard_on_all(struct output_config *wildcard) {
|
|||
}
|
||||
|
||||
static void merge_id_on_name(struct output_config *oc) {
|
||||
char *id_on_name = NULL;
|
||||
char id[128];
|
||||
char *name = NULL;
|
||||
struct sway_output *output;
|
||||
wl_list_for_each(output, &root->all_outputs, link) {
|
||||
name = output->wlr_output->name;
|
||||
output_get_identifier(id, sizeof(id), output);
|
||||
if (strcmp(name, oc->name) == 0 || strcmp(id, oc->name) == 0) {
|
||||
size_t length = snprintf(NULL, 0, "%s on %s", id, name) + 1;
|
||||
id_on_name = malloc(length);
|
||||
if (!id_on_name) {
|
||||
sway_log(SWAY_ERROR, "Failed to allocate id on name string");
|
||||
return;
|
||||
}
|
||||
snprintf(id_on_name, length, "%s on %s", id, name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!id_on_name) {
|
||||
struct sway_output *output = all_output_by_name_or_id(oc->name);
|
||||
if (output == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *name = output->wlr_output->name;
|
||||
char id[128];
|
||||
output_get_identifier(id, sizeof(id), output);
|
||||
|
||||
size_t size = snprintf(NULL, 0, "%s on %s", id, name) + 1;
|
||||
char *id_on_name = malloc(size);
|
||||
if (!id_on_name) {
|
||||
sway_log(SWAY_ERROR, "Failed to allocate id on name string");
|
||||
return;
|
||||
}
|
||||
snprintf(id_on_name, size, "%s on %s", id, name);
|
||||
|
||||
int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
|
||||
if (i >= 0) {
|
||||
sway_log(SWAY_DEBUG, "Merging on top of existing id on name config");
|
||||
|
|
@ -728,12 +722,11 @@ void apply_output_config_to_outputs(struct output_config *oc) {
|
|||
// this is during startup then there will be no container and config
|
||||
// will be applied during normal "new output" event from wlroots.
|
||||
bool wildcard = strcmp(oc->name, "*") == 0;
|
||||
char id[128];
|
||||
struct sway_output *sway_output, *tmp;
|
||||
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
|
||||
char *name = sway_output->wlr_output->name;
|
||||
output_get_identifier(id, sizeof(id), sway_output);
|
||||
if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
|
||||
if (output_match_name_or_id(sway_output, oc->name)) {
|
||||
char id[128];
|
||||
output_get_identifier(id, sizeof(id), sway_output);
|
||||
struct output_config *current = get_output_config(id, sway_output);
|
||||
if (!current) {
|
||||
// No stored output config matched, apply oc directly
|
||||
|
|
|
|||
|
|
@ -36,13 +36,29 @@
|
|||
#include <wlr/types/wlr_drm_lease_v1.h>
|
||||
#endif
|
||||
|
||||
bool output_match_name_or_id(struct sway_output *output,
|
||||
const char *name_or_id) {
|
||||
if (strcmp(name_or_id, "*") == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char port_prefix[] = "port:";
|
||||
if (strncmp(name_or_id, port_prefix, strlen(port_prefix)) == 0) {
|
||||
const char *port = &name_or_id[strlen(port_prefix)];
|
||||
return output->wlr_output->port != NULL &&
|
||||
strcmp(output->wlr_output->port, port) == 0;
|
||||
}
|
||||
|
||||
char identifier[128];
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
return strcasecmp(identifier, name_or_id) == 0
|
||||
|| strcasecmp(output->wlr_output->name, name_or_id) == 0;
|
||||
}
|
||||
|
||||
struct sway_output *output_by_name_or_id(const char *name_or_id) {
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
char identifier[128];
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
if (strcasecmp(identifier, name_or_id) == 0
|
||||
|| strcasecmp(output->wlr_output->name, name_or_id) == 0) {
|
||||
if (output_match_name_or_id(output, name_or_id)) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
@ -52,10 +68,7 @@ struct sway_output *output_by_name_or_id(const char *name_or_id) {
|
|||
struct sway_output *all_output_by_name_or_id(const char *name_or_id) {
|
||||
struct sway_output *output;
|
||||
wl_list_for_each(output, &root->all_outputs, link) {
|
||||
char identifier[128];
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
if (strcasecmp(identifier, name_or_id) == 0
|
||||
|| strcasecmp(output->wlr_output->name, name_or_id) == 0) {
|
||||
if (output_match_name_or_id(output, name_or_id)) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,6 +300,7 @@ static void ipc_json_describe_wlr_output(struct wlr_output *wlr_output, json_obj
|
|||
json_object_new_string(wlr_output->model ? wlr_output->model : "Unknown"));
|
||||
json_object_object_add(object, "serial",
|
||||
json_object_new_string(wlr_output->serial ? wlr_output->serial : "Unknown"));
|
||||
json_object_object_add(object, "port", json_object_new_string(wlr_output->port));
|
||||
|
||||
json_object *modes_array = json_object_new_array();
|
||||
struct wlr_output_mode *mode;
|
||||
|
|
|
|||
|
|
@ -176,22 +176,16 @@ void workspace_consider_destroy(struct sway_workspace *ws) {
|
|||
static bool workspace_valid_on_output(const char *output_name,
|
||||
const char *ws_name) {
|
||||
struct workspace_config *wsc = workspace_find_config(ws_name);
|
||||
char identifier[128];
|
||||
struct sway_output *output = output_by_name_or_id(output_name);
|
||||
if (!output) {
|
||||
return false;
|
||||
}
|
||||
output_name = output->wlr_output->name;
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
if (!wsc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < wsc->outputs->length; i++) {
|
||||
if (strcmp(wsc->outputs->items[i], "*") == 0 ||
|
||||
strcmp(wsc->outputs->items[i], output_name) == 0 ||
|
||||
strcmp(wsc->outputs->items[i], identifier) == 0) {
|
||||
if (output_match_name_or_id(output, wsc->outputs->items[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -286,13 +280,10 @@ char *workspace_next_name(const char *output_name) {
|
|||
// assignments primarily, falling back to bindings and numbers.
|
||||
struct sway_mode *mode = config->current_mode;
|
||||
|
||||
char identifier[128];
|
||||
struct sway_output *output = output_by_name_or_id(output_name);
|
||||
if (!output) {
|
||||
return NULL;
|
||||
}
|
||||
output_name = output->wlr_output->name;
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
int order = INT_MAX;
|
||||
char *target = NULL;
|
||||
|
|
@ -312,9 +303,7 @@ char *workspace_next_name(const char *output_name) {
|
|||
}
|
||||
bool found = false;
|
||||
for (int j = 0; j < wsc->outputs->length; ++j) {
|
||||
if (strcmp(wsc->outputs->items[j], "*") == 0 ||
|
||||
strcmp(wsc->outputs->items[j], output_name) == 0 ||
|
||||
strcmp(wsc->outputs->items[j], identifier) == 0) {
|
||||
if (output_match_name_or_id(output, wsc->outputs->items[j])) {
|
||||
found = true;
|
||||
free(target);
|
||||
target = strdup(wsc->workspace);
|
||||
|
|
@ -654,15 +643,9 @@ void workspace_output_add_priority(struct sway_workspace *workspace,
|
|||
|
||||
struct sway_output *workspace_output_get_highest_available(
|
||||
struct sway_workspace *ws, struct sway_output *exclude) {
|
||||
char exclude_id[128] = {'\0'};
|
||||
if (exclude) {
|
||||
output_get_identifier(exclude_id, sizeof(exclude_id), exclude);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ws->output_priority->length; i++) {
|
||||
char *name = ws->output_priority->items[i];
|
||||
if (exclude && (strcmp(name, exclude->wlr_output->name) == 0
|
||||
|| strcmp(name, exclude_id) == 0)) {
|
||||
const char *name = ws->output_priority->items[i];
|
||||
if (exclude && output_match_name_or_id(exclude, name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,11 +193,12 @@ static void pretty_print_output(json_object *o) {
|
|||
json_object_object_get_ex(o, "power", &power);
|
||||
json_object_object_get_ex(o, "current_workspace", &ws);
|
||||
json_object_object_get_ex(o, "non_desktop", &non_desktop);
|
||||
json_object *make, *model, *serial, *scale, *scale_filter, *subpixel,
|
||||
json_object *make, *model, *serial, *port, *scale, *scale_filter, *subpixel,
|
||||
*transform, *max_render_time, *adaptive_sync_status;
|
||||
json_object_object_get_ex(o, "make", &make);
|
||||
json_object_object_get_ex(o, "model", &model);
|
||||
json_object_object_get_ex(o, "serial", &serial);
|
||||
json_object_object_get_ex(o, "port", &port);
|
||||
json_object_object_get_ex(o, "scale", &scale);
|
||||
json_object_object_get_ex(o, "scale_filter", &scale_filter);
|
||||
json_object_object_get_ex(o, "subpixel_hinting", &subpixel);
|
||||
|
|
@ -267,6 +268,10 @@ static void pretty_print_output(json_object *o) {
|
|||
);
|
||||
}
|
||||
|
||||
if (port != NULL) {
|
||||
printf(" Port: %s\n", json_object_get_string(port));
|
||||
}
|
||||
|
||||
size_t modes_len = json_object_is_type(modes, json_type_array)
|
||||
? json_object_array_length(modes) : 0;
|
||||
if (modes_len > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue