Use output_match_name_or_id() in workspace functions

This commit is contained in:
Simon Ser 2023-02-28 12:58:52 +01:00
parent 64858795a8
commit 2ace2fea95

View file

@ -176,22 +176,16 @@ void workspace_consider_destroy(struct sway_workspace *ws) {
static bool workspace_valid_on_output(const char *output_name, static bool workspace_valid_on_output(const char *output_name,
const char *ws_name) { const char *ws_name) {
struct workspace_config *wsc = workspace_find_config(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); struct sway_output *output = output_by_name_or_id(output_name);
if (!output) { if (!output) {
return false; return false;
} }
output_name = output->wlr_output->name;
output_get_identifier(identifier, sizeof(identifier), output);
if (!wsc) { if (!wsc) {
return true; return true;
} }
for (int i = 0; i < wsc->outputs->length; i++) { for (int i = 0; i < wsc->outputs->length; i++) {
if (strcmp(wsc->outputs->items[i], "*") == 0 || if (output_match_name_or_id(output, wsc->outputs->items[i])) {
strcmp(wsc->outputs->items[i], output_name) == 0 ||
strcmp(wsc->outputs->items[i], identifier) == 0) {
return true; return true;
} }
} }
@ -286,13 +280,10 @@ char *workspace_next_name(const char *output_name) {
// assignments primarily, falling back to bindings and numbers. // assignments primarily, falling back to bindings and numbers.
struct sway_mode *mode = config->current_mode; struct sway_mode *mode = config->current_mode;
char identifier[128];
struct sway_output *output = output_by_name_or_id(output_name); struct sway_output *output = output_by_name_or_id(output_name);
if (!output) { if (!output) {
return NULL; return NULL;
} }
output_name = output->wlr_output->name;
output_get_identifier(identifier, sizeof(identifier), output);
int order = INT_MAX; int order = INT_MAX;
char *target = NULL; char *target = NULL;
@ -312,9 +303,7 @@ char *workspace_next_name(const char *output_name) {
} }
bool found = false; bool found = false;
for (int j = 0; j < wsc->outputs->length; ++j) { for (int j = 0; j < wsc->outputs->length; ++j) {
if (strcmp(wsc->outputs->items[j], "*") == 0 || if (output_match_name_or_id(output, wsc->outputs->items[j])) {
strcmp(wsc->outputs->items[j], output_name) == 0 ||
strcmp(wsc->outputs->items[j], identifier) == 0) {
found = true; found = true;
free(target); free(target);
target = strdup(wsc->workspace); 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_output *workspace_output_get_highest_available(
struct sway_workspace *ws, struct sway_output *exclude) { 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++) { for (int i = 0; i < ws->output_priority->length; i++) {
char *name = ws->output_priority->items[i]; const char *name = ws->output_priority->items[i];
if (exclude && (strcmp(name, exclude->wlr_output->name) == 0 if (exclude && output_match_name_or_id(exclude, name)) {
|| strcmp(name, exclude_id) == 0)) {
continue; continue;
} }