Merge branch 'workspace-startup-order'

This commit is contained in:
Michael Stapelberg 2011-08-03 03:33:34 +02:00
commit 4760f721e6
2 changed files with 95 additions and 18 deletions

View File

@ -365,36 +365,48 @@ void init_ws_for_output(Output *output, Con *content) {
DLOG("Now adding a workspace\n");
/* add a workspace to this output */
Con *out, *current;
bool exists = true;
Con *ws = con_new(NULL, NULL);
ws->type = CT_WORKSPACE;
/* try the configured workspace bindings first to find a free name */
Binding *bind;
TAILQ_FOREACH(bind, bindings, bindings) {
DLOG("binding with command %s\n", bind->command);
if (strlen(bind->command) < strlen("workspace ") ||
strncasecmp(bind->command, "workspace", strlen("workspace")) != 0)
continue;
DLOG("relevant command = %s\n", bind->command);
char *target = bind->command + strlen("workspace ");
if (*target == '"')
target++;
FREE(ws->name);
ws->name = strdup(target);
if (ws->name[strlen(ws->name)-1] == '"')
ws->name[strlen(ws->name)-1] = '\0';
DLOG("trying name *%s*\n", ws->name);
TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name));
exists = (current != NULL);
if (!exists)
break;
}
/* get the next unused workspace number */
DLOG("Getting next unused workspace\n");
int c = 0;
bool exists = true;
while (exists) {
Con *out, *current, *child;
c++;
FREE(ws->name);
asprintf(&(ws->name), "%d", c);
exists = false;
TAILQ_FOREACH(out, &(croot->nodes_head), nodes) {
TAILQ_FOREACH(current, &(out->nodes_head), nodes) {
if (current->type != CT_CON)
continue;
TAILQ_FOREACH(child, &(current->nodes_head), nodes) {
if (strcasecmp(child->name, ws->name) != 0)
continue;
exists = true;
break;
}
}
}
TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name));
exists = (current != NULL);
DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists);
}

View File

@ -0,0 +1,65 @@
#!perl
# vim:ts=4:sw=4:expandtab
# !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
#
# checks if i3 starts up on workspace '1' or the first configured named workspace
#
use X11::XCB qw(:all);
use X11::XCB::Connection;
use i3test;
my $x = X11::XCB::Connection->new;
##############################################################
# 1: i3 should start with workspace '1'
##############################################################
my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
EOT
my $process = launch_with_config($config);
my @names = @{get_workspace_names()};
cmp_deeply(\@names, [ '1' ], 'i3 starts on workspace 1 without any configuration');
exit_gracefully($process->pid);
##############################################################
# 2: with named workspaces, i3 should start on the first named one
##############################################################
$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
bindsym Mod1+1 workspace foobar
EOT
$process = launch_with_config($config);
my @names = @{get_workspace_names()};
cmp_deeply(\@names, [ 'foobar' ], 'i3 starts on named workspace foobar');
exit_gracefully($process->pid);
##############################################################
# 3: the same test as 2, but with a quoted workspace name
##############################################################
$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
bindsym Mod1+1 workspace "foobar"
EOT
$process = launch_with_config($config);
my @names = @{get_workspace_names()};
cmp_deeply(\@names, [ 'foobar' ], 'i3 starts on named workspace foobar');
exit_gracefully($process->pid);
done_testing;