2009-07-28 07:55:09 -04:00
|
|
|
/*
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
*
|
|
|
|
* © 2009 Michael Stapelberg and contributors
|
|
|
|
*
|
|
|
|
* See file LICENSE for license information.
|
|
|
|
*
|
|
|
|
* workspace.c: Functions for modifying workspaces
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "data.h"
|
2009-08-02 15:32:35 -04:00
|
|
|
#include "i3.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "xcb.h"
|
2009-07-28 07:55:09 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets the name (or just its number) for the given workspace. This has to
|
|
|
|
* be called for every workspace as the rendering function
|
|
|
|
* (render_internal_bar) relies on workspace->name and workspace->name_len
|
|
|
|
* being ready-to-use.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void workspace_set_name(Workspace *ws, const char *name) {
|
|
|
|
char *label;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
ret = asprintf(&label, "%d: %s", ws->num + 1, name);
|
|
|
|
else ret = asprintf(&label, "%d", ws->num + 1);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
errx(1, "asprintf() failed");
|
|
|
|
|
|
|
|
FREE(ws->name);
|
|
|
|
|
|
|
|
ws->name = convert_utf8_to_ucs2(label, &(ws->name_len));
|
2009-08-07 09:48:13 -04:00
|
|
|
if (config.font != NULL)
|
|
|
|
ws->text_width = predict_text_width(global_conn, config.font, ws->name, ws->name_len);
|
|
|
|
else ws->text_width = 0;
|
2009-07-28 07:55:09 -04:00
|
|
|
|
|
|
|
free(label);
|
|
|
|
}
|
2009-08-02 16:31:52 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true if the workspace is currently visible. Especially important for
|
|
|
|
* multi-monitor environments, as they can have multiple currenlty active
|
|
|
|
* workspaces.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool workspace_is_visible(Workspace *ws) {
|
|
|
|
return (ws->screen->current_workspace == ws->num);
|
|
|
|
}
|