mirror of
https://github.com/swaywm/sway.git
synced 2026-05-02 06:46:23 -04:00
Also extract first workspace name from bindcodes
This commit is contained in:
parent
110d698807
commit
7d18112a7e
1 changed files with 88 additions and 80 deletions
|
|
@ -106,18 +106,8 @@ static bool workspace_valid_on_output(const char *output_name,
|
|||
return true;
|
||||
}
|
||||
|
||||
char *workspace_next_name(const char *output_name) {
|
||||
wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
|
||||
output_name);
|
||||
// Scan all workspace bindings to find the next available workspace name,
|
||||
// if none are found/available then default to a number
|
||||
struct sway_mode *mode = config->current_mode;
|
||||
|
||||
// TODO: iterate over keycode bindings too
|
||||
int order = INT_MAX;
|
||||
char *target = NULL;
|
||||
for (int i = 0; i < mode->keysym_bindings->length; ++i) {
|
||||
struct sway_binding *binding = mode->keysym_bindings->items[i];
|
||||
static void workspace_name_from_binding(const struct sway_binding * binding,
|
||||
const char* output_name, int *min_order, char **earliest_name) {
|
||||
char *cmdlist = strdup(binding->command);
|
||||
char *dup = cmdlist;
|
||||
char *name = NULL;
|
||||
|
|
@ -150,7 +140,7 @@ char *workspace_next_name(const char *output_name) {
|
|||
{
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// If the command is workspace number <name>, isolate the name
|
||||
|
|
@ -167,7 +157,7 @@ char *workspace_next_name(const char *output_name) {
|
|||
if (workspace_by_number(_target)) {
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +165,7 @@ char *workspace_next_name(const char *output_name) {
|
|||
if (workspace_by_name(_target)) {
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure that the workspace can appear on the given
|
||||
|
|
@ -183,13 +173,13 @@ char *workspace_next_name(const char *output_name) {
|
|||
if (!workspace_valid_on_output(output_name, _target)) {
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
if (binding->order < order) {
|
||||
order = binding->order;
|
||||
free(target);
|
||||
target = _target;
|
||||
if (binding->order < *min_order) {
|
||||
*min_order = binding->order;
|
||||
free(*earliest_name);
|
||||
*earliest_name = _target;
|
||||
wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
|
||||
} else {
|
||||
free(_target);
|
||||
|
|
@ -197,6 +187,24 @@ char *workspace_next_name(const char *output_name) {
|
|||
}
|
||||
free(dup);
|
||||
}
|
||||
|
||||
char *workspace_next_name(const char *output_name) {
|
||||
wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
|
||||
output_name);
|
||||
// Scan all workspace bindings to find the next available workspace name,
|
||||
// if none are found/available then default to a number
|
||||
struct sway_mode *mode = config->current_mode;
|
||||
|
||||
int order = INT_MAX;
|
||||
char *target = NULL;
|
||||
for (int i = 0; i < mode->keysym_bindings->length; ++i) {
|
||||
workspace_name_from_binding(mode->keysym_bindings->items[i],
|
||||
output_name, &order, &target);
|
||||
}
|
||||
for (int i = 0; i < mode->keycode_bindings->length; ++i) {
|
||||
workspace_name_from_binding(mode->keycode_bindings->items[i],
|
||||
output_name, &order, &target);
|
||||
}
|
||||
if (target != NULL) {
|
||||
return target;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue