|
|
@ -1,5 +1,7 @@
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <wlc/wlc.h>
|
|
|
|
#include <wlc/wlc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <strings.h>
|
|
|
@ -31,6 +33,8 @@ char *workspace_next_name(void) {
|
|
|
|
// if none are found/available then default to a number
|
|
|
|
// if none are found/available then default to a number
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int order = INT_MAX;
|
|
|
|
|
|
|
|
char *target = NULL;
|
|
|
|
for (i = 0; i < mode->bindings->length; ++i) {
|
|
|
|
for (i = 0; i < mode->bindings->length; ++i) {
|
|
|
|
struct sway_binding *binding = mode->bindings->items[i];
|
|
|
|
struct sway_binding *binding = mode->bindings->items[i];
|
|
|
|
char *cmdlist = strdup(binding->command);
|
|
|
|
char *cmdlist = strdup(binding->command);
|
|
|
@ -45,35 +49,40 @@ char *workspace_next_name(void) {
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp("workspace", cmd) == 0 && name) {
|
|
|
|
if (strcmp("workspace", cmd) == 0 && name) {
|
|
|
|
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name);
|
|
|
|
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name);
|
|
|
|
char* target = strdup(name);
|
|
|
|
char *_target = strdup(name);
|
|
|
|
while (*target == ' ' || *target == '\t')
|
|
|
|
while (isspace(*_target))
|
|
|
|
target++;
|
|
|
|
_target++;
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that the command references an actual workspace
|
|
|
|
// Make sure that the command references an actual workspace
|
|
|
|
// not a command about workspaces
|
|
|
|
// not a command about workspaces
|
|
|
|
if (strcmp(target, "next") == 0 ||
|
|
|
|
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);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure that the workspace doesn't already exist
|
|
|
|
// Make sure that the workspace doesn't already exist
|
|
|
|
if (workspace_by_name(target)) {
|
|
|
|
if (workspace_by_name(_target)) {
|
|
|
|
free(target);
|
|
|
|
free(_target);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(dup);
|
|
|
|
if (binding->order < order) {
|
|
|
|
sway_log(L_DEBUG, "Workspace: Found free name %s", target);
|
|
|
|
order = binding->order;
|
|
|
|
return target;
|
|
|
|
target = _target;
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Workspace: Found free name %s", _target);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(dup);
|
|
|
|
free(dup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target != NULL) {
|
|
|
|
|
|
|
|
return target;
|
|
|
|
|
|
|
|
}
|
|
|
|
// As a fall back, get the current number of active workspaces
|
|
|
|
// As a fall back, get the current number of active workspaces
|
|
|
|
// and return that + 1 for the next workspace's name
|
|
|
|
// and return that + 1 for the next workspace's name
|
|
|
|
int ws_num = root_container.children->length;
|
|
|
|
int ws_num = root_container.children->length;
|
|
|
|