Feature: Workspace assignment by number

Workspace assignments with bare numbers assign all workspaces with that
number to the specified output.

Workspace assignment by number is overridden by workspace assignment by
name.
This commit is contained in:
Tony Crisci
2014-05-17 23:36:58 -04:00
committed by Michael Stapelberg
parent cfd06718fc
commit f41e81bd96
5 changed files with 142 additions and 17 deletions

View File

@ -21,6 +21,7 @@
#include <pwd.h>
#include <yajl/yajl_version.h>
#include <libgen.h>
#include <ctype.h>
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launcher.h>
@ -47,6 +48,38 @@ Rect rect_add(Rect a, Rect b) {
a.height + b.height};
}
/*
* Returns true if the name consists of only digits.
*
*/
__attribute__ ((pure)) bool name_is_digits(const char *name) {
/* positive integers and zero are interpreted as numbers */
for (int i = 0; i < strlen(name); i++)
if (!isdigit(name[i]))
return false;
return true;
}
/*
* Parses the workspace name as a number. Returns -1 if the workspace should be
* interpreted as a "named workspace".
*
*/
long ws_name_to_number(const char *name) {
/* positive integers and zero are interpreted as numbers */
char *endptr = NULL;
long parsed_num = strtol(name, &endptr, 10);
if (parsed_num == LONG_MIN ||
parsed_num == LONG_MAX ||
parsed_num < 0 ||
endptr == name) {
parsed_num = -1;
}
return parsed_num;
}
/*
* Updates *destination with new_value and returns true if it was changed or false
* if it was the same