Also extract first workspace name from bindcodes
This commit is contained in:
parent
71774ecd36
commit
ab0efebc3e
|
@ -107,18 +107,8 @@ static bool workspace_valid_on_output(const char *output_name,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *workspace_next_name(const char *output_name) {
|
static void workspace_name_from_binding(const struct sway_binding * binding,
|
||||||
wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
|
const char* output_name, int *min_order, char **earliest_name) {
|
||||||
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];
|
|
||||||
char *cmdlist = strdup(binding->command);
|
char *cmdlist = strdup(binding->command);
|
||||||
char *dup = cmdlist;
|
char *dup = cmdlist;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
@ -147,11 +137,10 @@ char *workspace_next_name(const char *output_name) {
|
||||||
strcmp(_target, "prev_on_output") == 0 ||
|
strcmp(_target, "prev_on_output") == 0 ||
|
||||||
strcmp(_target, "number") == 0 ||
|
strcmp(_target, "number") == 0 ||
|
||||||
strcmp(_target, "back_and_forth") == 0 ||
|
strcmp(_target, "back_and_forth") == 0 ||
|
||||||
strcmp(_target, "current") == 0)
|
strcmp(_target, "current") == 0) {
|
||||||
{
|
|
||||||
free(_target);
|
free(_target);
|
||||||
free(dup);
|
free(dup);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the command is workspace number <name>, isolate the name
|
// If the command is workspace number <name>, isolate the name
|
||||||
|
@ -168,7 +157,7 @@ char *workspace_next_name(const char *output_name) {
|
||||||
if (workspace_by_number(_target)) {
|
if (workspace_by_number(_target)) {
|
||||||
free(_target);
|
free(_target);
|
||||||
free(dup);
|
free(dup);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +165,7 @@ char *workspace_next_name(const char *output_name) {
|
||||||
if (workspace_by_name(_target)) {
|
if (workspace_by_name(_target)) {
|
||||||
free(_target);
|
free(_target);
|
||||||
free(dup);
|
free(dup);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that the workspace can appear on the given
|
// make sure that the workspace can appear on the given
|
||||||
|
@ -184,19 +173,37 @@ char *workspace_next_name(const char *output_name) {
|
||||||
if (!workspace_valid_on_output(output_name, _target)) {
|
if (!workspace_valid_on_output(output_name, _target)) {
|
||||||
free(_target);
|
free(_target);
|
||||||
free(dup);
|
free(dup);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding->order < order) {
|
if (binding->order < *min_order) {
|
||||||
order = binding->order;
|
*min_order = binding->order;
|
||||||
free(target);
|
free(*earliest_name);
|
||||||
target = _target;
|
*earliest_name = _target;
|
||||||
wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
|
wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
|
||||||
} else {
|
} else {
|
||||||
free(_target);
|
free(_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(dup);
|
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) {
|
if (target != NULL) {
|
||||||
return target;
|
return target;
|
||||||
|
|
Loading…
Reference in a new issue