mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 21:14:10 +01:00
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;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -147,11 +137,10 @@ char *workspace_next_name(const char *output_name) {
|
||||
strcmp(_target, "prev_on_output") == 0 ||
|
||||
strcmp(_target, "number") == 0 ||
|
||||
strcmp(_target, "back_and_forth") == 0 ||
|
||||
strcmp(_target, "current") == 0)
|
||||
{
|
||||
strcmp(_target, "current") == 0) {
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
free(_target);
|
||||
free(dup);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,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
|
||||
@ -184,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);
|
||||
@ -198,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…
Reference in New Issue
Block a user