<commit_before>#include <stdlib.h>
#include <stdbool.h>
#include <wlc/wlc.h>
#include "workspace.h"
#include "layout.h"
#include "list.h"
#include "log.h"
#include "container.h"

swayc_t *active_workspace = NULL;

int ws_num = 1;

char *workspace_next_name(void) {
	int l = 1;
	if (ws_num >= 10) {
		l = 2;
	} else if (ws_num >= 100) {
		l = 3;
	}
	char *name = malloc(l + 1);
	sprintf(name, "%d", ws_num++);
	return name;
}

swayc_t *workspace_create(const char* name) {
	swayc_t *parent = get_focused_container(&root_container);
	while(parent->type != C_OUTPUT) {
		parent = parent->parent;<commit_msg>Changed workspace name generation to try and use bindsyms when possible<commit_after>#include <stdlib.h>
#include <stdbool.h>
#include <wlc/wlc.h>
#include "workspace.h"
#include "layout.h"
#include "list.h"
#include "log.h"
#include "container.h"

swayc_t *active_workspace = NULL;

int ws_num = 1;

char *workspace_next_name(void) {
	int i;
    // 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;

	for (i = 0; i < mode->bindings->length; ++i) {
		const char* command = *binding = mode->bindings->items[i]->command;
	    list_t *args = split_string(command, " ");

        if (strcmp("workspace", args->items[0]) == 0 && args->length > 2) {
            const char* target = args->items[1];

            while (*target == ' ' || *target == '\t')
                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, "next_on_output") == 0 ||
                strcmp(target, "prev_on_output") == 0 ||
                strcmp(target, "number") == 0 ||
                strcmp(target, "back_and_forth") == 0 ||
                strcmp(target, "current") == 0)
                continue;
           
            //Make sure that the workspace doesn't already exist 
            if (workspace_find_by_name(args->items[2]))
               continue; 

            return args->items[2];        
        }
    }
    // As a fall back, get the current number of active workspaces
    // and return that + 1 for the next workspace's name
	int ws_num = root_container.children->length;
	if (ws_num >= 10) {
		l = 2;
	} else if (ws_num >= 100) {
		l = 3;
	}
	char *name = malloc(l + 1);
	sprintf(name, "%d", ws_num++);
	return name;
}

swayc_t *workspace_create(const char* name) {
	swayc_t *parent = get_focused_container(&root_container);
	while(parent->type != C_OUTPUT) {
		parent = parent->parent;
{'fraction_non_alphanumeric': 0.1443791329904482, 'fraction_numerical': 0.012490815576781777, 'mean_word_length': 2.7148703956343794, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '868527', 'n_tokens_mistral': 979, 'n_tokens_neox': 909, 'n_words': 250}