Merge branch 'fix-wsnum' into next
This commit is contained in:
commit
0a42a16429
|
@ -447,10 +447,12 @@ void init_ws_for_output(Output *output, Con *content) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
/* Set ->num to the number of the workspace, if the name actually
|
/* Set ->num to the number of the workspace, if the name actually
|
||||||
* is a number or starts with a number */
|
* is a number or starts with a number */
|
||||||
long parsed_num = strtol(ws->name, NULL, 10);
|
char *endptr = NULL;
|
||||||
|
long parsed_num = strtol(ws->name, &endptr, 10);
|
||||||
if (parsed_num == LONG_MIN ||
|
if (parsed_num == LONG_MIN ||
|
||||||
parsed_num == LONG_MAX ||
|
parsed_num == LONG_MAX ||
|
||||||
parsed_num <= 0)
|
parsed_num < 0 ||
|
||||||
|
endptr == ws->name)
|
||||||
ws->num = -1;
|
ws->num = -1;
|
||||||
else ws->num = parsed_num;
|
else ws->num = parsed_num;
|
||||||
LOG("Used number %d for workspace with name %s\n", ws->num, ws->name);
|
LOG("Used number %d for workspace with name %s\n", ws->num, ws->name);
|
||||||
|
|
|
@ -49,11 +49,12 @@ Con *workspace_get(const char *num, bool *created) {
|
||||||
workspace->name = sstrdup(num);
|
workspace->name = sstrdup(num);
|
||||||
/* We set ->num to the number if this workspace’s name consists only of
|
/* We set ->num to the number if this workspace’s name consists only of
|
||||||
* a positive number. Otherwise it’s a named ws and num will be -1. */
|
* a positive number. Otherwise it’s a named ws and num will be -1. */
|
||||||
|
char *endptr = NULL;
|
||||||
long parsed_num = strtol(num, NULL, 10);
|
long parsed_num = strtol(num, &endptr, 10);
|
||||||
if (parsed_num == LONG_MIN ||
|
if (parsed_num == LONG_MIN ||
|
||||||
parsed_num == LONG_MAX ||
|
parsed_num == LONG_MAX ||
|
||||||
parsed_num < 0)
|
parsed_num < 0 ||
|
||||||
|
endptr == num)
|
||||||
workspace->num = -1;
|
workspace->num = -1;
|
||||||
else workspace->num = parsed_num;
|
else workspace->num = parsed_num;
|
||||||
LOG("num = %d\n", workspace->num);
|
LOG("num = %d\n", workspace->num);
|
||||||
|
|
|
@ -98,4 +98,23 @@ cmd 'workspace "prev"';
|
||||||
ok(workspace_exists('prev'), 'workspace "prev" exists');
|
ok(workspace_exists('prev'), 'workspace "prev" exists');
|
||||||
is(focused_ws(), 'prev', 'now on workspace prev');
|
is(focused_ws(), 'prev', 'now on workspace prev');
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# check that the numbers are assigned/recognized correctly
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
cmd "workspace 3: $tmp";
|
||||||
|
my $ws = get_ws("3: $tmp");
|
||||||
|
ok(defined($ws), "workspace 3: $tmp was created");
|
||||||
|
is($ws->{num}, 3, 'workspace number is 3');
|
||||||
|
|
||||||
|
cmd "workspace 0: $tmp";
|
||||||
|
my $ws = get_ws("0: $tmp");
|
||||||
|
ok(defined($ws), "workspace 0: $tmp was created");
|
||||||
|
is($ws->{num}, 0, 'workspace number is 0');
|
||||||
|
|
||||||
|
cmd "workspace aa: $tmp";
|
||||||
|
my $ws = get_ws("aa: $tmp");
|
||||||
|
ok(defined($ws), "workspace aa: $tmp was created");
|
||||||
|
is($ws->{num}, -1, 'workspace number is -1');
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue