|
|
@ -107,96 +107,103 @@ 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);
|
|
|
|
char *cmdlist = strdup(binding->command);
|
|
|
|
// Scan all workspace bindings to find the next available workspace name,
|
|
|
|
char *dup = cmdlist;
|
|
|
|
// if none are found/available then default to a number
|
|
|
|
char *name = NULL;
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
|
|
|
|
|
|
|
|
|
// workspace n
|
|
|
|
// TODO: iterate over keycode bindings too
|
|
|
|
char *cmd = argsep(&cmdlist, " ");
|
|
|
|
int order = INT_MAX;
|
|
|
|
if (cmdlist) {
|
|
|
|
char *target = NULL;
|
|
|
|
name = argsep(&cmdlist, ",;");
|
|
|
|
for (int i = 0; i < mode->keysym_bindings->length; ++i) {
|
|
|
|
}
|
|
|
|
struct sway_binding *binding = mode->keysym_bindings->items[i];
|
|
|
|
|
|
|
|
char *cmdlist = strdup(binding->command);
|
|
|
|
if (strcmp("workspace", cmd) == 0 && name) {
|
|
|
|
char *dup = cmdlist;
|
|
|
|
char *_target = strdup(name);
|
|
|
|
char *name = NULL;
|
|
|
|
_target = do_var_replacement(_target);
|
|
|
|
|
|
|
|
strip_quotes(_target);
|
|
|
|
// workspace n
|
|
|
|
while (isspace(*_target)) {
|
|
|
|
char *cmd = argsep(&cmdlist, " ");
|
|
|
|
memmove(_target, _target+1, strlen(_target+1));
|
|
|
|
if (cmdlist) {
|
|
|
|
|
|
|
|
name = argsep(&cmdlist, ",;");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'",
|
|
|
|
|
|
|
|
_target);
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp("workspace", cmd) == 0 && name) {
|
|
|
|
// Make sure that the command references an actual workspace
|
|
|
|
char *_target = strdup(name);
|
|
|
|
// not a command about workspaces
|
|
|
|
_target = do_var_replacement(_target);
|
|
|
|
if (strcmp(_target, "next") == 0 ||
|
|
|
|
strip_quotes(_target);
|
|
|
|
|
|
|
|
while (isspace(*_target)) {
|
|
|
|
|
|
|
|
memmove(_target, _target+1, strlen(_target+1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'",
|
|
|
|
|
|
|
|
_target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that the command references an actual workspace
|
|
|
|
|
|
|
|
// not a command about workspaces
|
|
|
|
|
|
|
|
if (strcmp(_target, "next") == 0 ||
|
|
|
|
|
|
|
|
strcmp(_target, "prev") == 0 ||
|
|
|
|
strcmp(_target, "prev") == 0 ||
|
|
|
|
strcmp(_target, "next_on_output") == 0 ||
|
|
|
|
strcmp(_target, "next_on_output") == 0 ||
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the command is workspace number <name>, isolate the name
|
|
|
|
|
|
|
|
if (strncmp(_target, "number ", strlen("number ")) == 0) {
|
|
|
|
|
|
|
|
size_t length = strlen(_target) - strlen("number ") + 1;
|
|
|
|
|
|
|
|
char *temp = malloc(length);
|
|
|
|
|
|
|
|
strncpy(temp, _target + strlen("number "), length - 1);
|
|
|
|
|
|
|
|
temp[length - 1] = '\0';
|
|
|
|
|
|
|
|
free(_target);
|
|
|
|
|
|
|
|
_target = temp;
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure the workspace number doesn't already exist
|
|
|
|
|
|
|
|
if (workspace_by_number(_target)) {
|
|
|
|
|
|
|
|
free(_target);
|
|
|
|
|
|
|
|
free(dup);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that the workspace doesn't already exist
|
|
|
|
// If the command is workspace number <name>, isolate the name
|
|
|
|
if (workspace_by_name(_target)) {
|
|
|
|
if (strncmp(_target, "number ", strlen("number ")) == 0) {
|
|
|
|
|
|
|
|
size_t length = strlen(_target) - strlen("number ") + 1;
|
|
|
|
|
|
|
|
char *temp = malloc(length);
|
|
|
|
|
|
|
|
strncpy(temp, _target + strlen("number "), length - 1);
|
|
|
|
|
|
|
|
temp[length - 1] = '\0';
|
|
|
|
|
|
|
|
free(_target);
|
|
|
|
|
|
|
|
_target = temp;
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure the workspace number doesn't already exist
|
|
|
|
|
|
|
|
if (workspace_by_number(_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 doesn't already exist
|
|
|
|
// output
|
|
|
|
if (workspace_by_name(_target)) {
|
|
|
|
if (!workspace_valid_on_output(output_name, _target)) {
|
|
|
|
free(_target);
|
|
|
|
free(_target);
|
|
|
|
free(dup);
|
|
|
|
free(dup);
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (binding->order < order) {
|
|
|
|
// make sure that the workspace can appear on the given
|
|
|
|
order = binding->order;
|
|
|
|
// output
|
|
|
|
free(target);
|
|
|
|
if (!workspace_valid_on_output(output_name, _target)) {
|
|
|
|
target = _target;
|
|
|
|
free(_target);
|
|
|
|
wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
|
|
|
|
free(dup);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
free(_target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(dup);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|