mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-27 21:58:16 +01:00
Allow output ids and wildcard for workspace output
This allows for output identifiers and to be used in the `workspace <workspace> output <outputs...>` command. Previously, only output names would be allowed. If an output identifier was given, it would never match an output. This also allows for the wildcard character (`*`) to be specified, which can be used to generate a list of workspace names that should be used when generating new workspaces
This commit is contained in:
parent
eb527ac01a
commit
5f25541022
1 changed files with 29 additions and 4 deletions
|
@ -113,7 +113,10 @@ struct sway_workspace *workspace_create(struct sway_output *output,
|
|||
|
||||
// Add output priorities
|
||||
for (int i = 0; i < wsc->outputs->length; ++i) {
|
||||
list_add(ws->output_priority, strdup(wsc->outputs->items[i]));
|
||||
char *name = wsc->outputs->items[i];
|
||||
if (strcmp(name, "*") != 0) {
|
||||
list_add(ws->output_priority, strdup(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +186,10 @@ static bool workspace_valid_on_output(const char *output_name,
|
|||
struct workspace_config *wsc = workspace_find_config(ws_name);
|
||||
char identifier[128];
|
||||
struct sway_output *output = output_by_name(output_name);
|
||||
if (!output) {
|
||||
output = output_by_identifier(output_name);
|
||||
output_name = output->wlr_output->name;
|
||||
}
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
if (!wsc) {
|
||||
|
@ -190,7 +197,8 @@ static bool workspace_valid_on_output(const char *output_name,
|
|||
}
|
||||
|
||||
for (int i = 0; i < wsc->outputs->length; i++) {
|
||||
if (strcmp(wsc->outputs->items[i], output_name) == 0 ||
|
||||
if (strcmp(wsc->outputs->items[i], "*") == 0 ||
|
||||
strcmp(wsc->outputs->items[i], output_name) == 0 ||
|
||||
strcmp(wsc->outputs->items[i], identifier) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -286,6 +294,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(output_name);
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
int order = INT_MAX;
|
||||
char *target = NULL;
|
||||
for (int i = 0; i < mode->keysym_bindings->length; ++i) {
|
||||
|
@ -304,7 +316,9 @@ 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], output_name) == 0) {
|
||||
if (strcmp(wsc->outputs->items[j], "*") == 0 ||
|
||||
strcmp(wsc->outputs->items[j], output_name) == 0 ||
|
||||
strcmp(wsc->outputs->items[j], identifier) == 0) {
|
||||
found = true;
|
||||
free(target);
|
||||
target = strdup(wsc->workspace);
|
||||
|
@ -525,9 +539,15 @@ 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 && strcasecmp(name, exclude->wlr_output->name) == 0) {
|
||||
if (exclude && (strcmp(name, exclude->wlr_output->name) == 0
|
||||
|| strcmp(name, exclude_id) == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -535,6 +555,11 @@ struct sway_output *workspace_output_get_highest_available(
|
|||
if (output) {
|
||||
return output;
|
||||
}
|
||||
|
||||
output = output_by_identifier(name);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue