]> git.sur5r.net Git - i3/i3/blob - src/workspace.c
Some little fixes for bapt’s patch, use predict_text_width, support UTF8, pre-render...
[i3/i3] / src / workspace.c
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  * workspace.c: Functions for modifying workspaces
11  *
12  */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <err.h>
16
17 #include "util.h"
18 #include "data.h"
19
20 /*
21  * Sets the name (or just its number) for the given workspace. This has to
22  * be called for every workspace as the rendering function
23  * (render_internal_bar) relies on workspace->name and workspace->name_len
24  * being ready-to-use.
25  *
26  */
27 void workspace_set_name(Workspace *ws, const char *name) {
28         char *label;
29         int ret;
30
31         if (name != NULL)
32                 ret = asprintf(&label, "%d: %s", ws->num + 1, name);
33         else ret = asprintf(&label, "%d", ws->num + 1);
34
35         if (ret == -1)
36                 errx(1, "asprintf() failed");
37
38         FREE(ws->name);
39
40         ws->name = convert_utf8_to_ucs2(label, &(ws->name_len));
41
42         free(label);
43 }