Merge pull request #1562 from Airblader/feature-short-text
Add support for the short_text property
This commit is contained in:
commit
d3b8b3cac0
|
@ -35,6 +35,7 @@ typedef enum {
|
||||||
* up one status line. */
|
* up one status line. */
|
||||||
struct status_block {
|
struct status_block {
|
||||||
i3String *full_text;
|
i3String *full_text;
|
||||||
|
i3String *short_text;
|
||||||
|
|
||||||
char *color;
|
char *color;
|
||||||
uint32_t min_width;
|
uint32_t min_width;
|
||||||
|
|
|
@ -70,6 +70,7 @@ static void clear_statusline(struct statusline_head *head, bool free_resources)
|
||||||
first = TAILQ_FIRST(head);
|
first = TAILQ_FIRST(head);
|
||||||
if (free_resources) {
|
if (free_resources) {
|
||||||
I3STRING_FREE(first->full_text);
|
I3STRING_FREE(first->full_text);
|
||||||
|
I3STRING_FREE(first->short_text);
|
||||||
FREE(first->color);
|
FREE(first->color);
|
||||||
FREE(first->name);
|
FREE(first->name);
|
||||||
FREE(first->instance);
|
FREE(first->instance);
|
||||||
|
@ -188,6 +189,9 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
|
||||||
if (strcasecmp(ctx->last_map_key, "full_text") == 0) {
|
if (strcasecmp(ctx->last_map_key, "full_text") == 0) {
|
||||||
ctx->block.full_text = i3string_from_markup_with_length((const char *)val, len);
|
ctx->block.full_text = i3string_from_markup_with_length((const char *)val, len);
|
||||||
}
|
}
|
||||||
|
if (strcasecmp(ctx->last_map_key, "short_text") == 0) {
|
||||||
|
ctx->block.short_text = i3string_from_markup_with_length((const char *)val, len);
|
||||||
|
}
|
||||||
if (strcasecmp(ctx->last_map_key, "color") == 0) {
|
if (strcasecmp(ctx->last_map_key, "color") == 0) {
|
||||||
sasprintf(&(ctx->block.color), "%.*s", len, val);
|
sasprintf(&(ctx->block.color), "%.*s", len, val);
|
||||||
}
|
}
|
||||||
|
@ -261,6 +265,7 @@ static int stdin_end_array(void *context) {
|
||||||
struct status_block *current;
|
struct status_block *current;
|
||||||
TAILQ_FOREACH(current, &statusline_head, blocks) {
|
TAILQ_FOREACH(current, &statusline_head, blocks) {
|
||||||
DLOG("full_text = %s\n", i3string_as_utf8(current->full_text));
|
DLOG("full_text = %s\n", i3string_as_utf8(current->full_text));
|
||||||
|
DLOG("short_text = %s\n", i3string_as_utf8(current->short_text));
|
||||||
DLOG("color = %s\n", current->color);
|
DLOG("color = %s\n", current->color);
|
||||||
}
|
}
|
||||||
DLOG("end of dump\n");
|
DLOG("end of dump\n");
|
||||||
|
|
|
@ -159,7 +159,7 @@ int get_tray_width(struct tc_head *trayclients) {
|
||||||
* Redraws the statusline to the buffer
|
* Redraws the statusline to the buffer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void refresh_statusline(void) {
|
void refresh_statusline(bool use_short_text) {
|
||||||
struct status_block *block;
|
struct status_block *block;
|
||||||
|
|
||||||
uint32_t old_statusline_width = statusline_width;
|
uint32_t old_statusline_width = statusline_width;
|
||||||
|
@ -167,6 +167,12 @@ void refresh_statusline(void) {
|
||||||
|
|
||||||
/* Predict the text width of all blocks (in pixels). */
|
/* Predict the text width of all blocks (in pixels). */
|
||||||
TAILQ_FOREACH(block, &statusline_head, blocks) {
|
TAILQ_FOREACH(block, &statusline_head, blocks) {
|
||||||
|
/* Try to use the shorter text if necessary and possible. */
|
||||||
|
if (use_short_text && block->short_text != NULL) {
|
||||||
|
I3STRING_FREE(block->full_text);
|
||||||
|
block->full_text = i3string_copy(block->short_text);
|
||||||
|
}
|
||||||
|
|
||||||
if (i3string_get_num_bytes(block->full_text) == 0)
|
if (i3string_get_num_bytes(block->full_text) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1760,7 +1766,7 @@ void draw_bars(bool unhide) {
|
||||||
DLOG("Drawing bars...\n");
|
DLOG("Drawing bars...\n");
|
||||||
int workspace_width = 0;
|
int workspace_width = 0;
|
||||||
|
|
||||||
refresh_statusline();
|
refresh_statusline(false);
|
||||||
|
|
||||||
i3_output *outputs_walk;
|
i3_output *outputs_walk;
|
||||||
SLIST_FOREACH(outputs_walk, outputs, slist) {
|
SLIST_FOREACH(outputs_walk, outputs, slist) {
|
||||||
|
@ -1904,14 +1910,17 @@ void draw_bars(bool unhide) {
|
||||||
if (!TAILQ_EMPTY(&statusline_head)) {
|
if (!TAILQ_EMPTY(&statusline_head)) {
|
||||||
DLOG("Printing statusline!\n");
|
DLOG("Printing statusline!\n");
|
||||||
|
|
||||||
|
int tray_width = get_tray_width(outputs_walk->trayclients);
|
||||||
|
int max_statusline_width = outputs_walk->rect.w - workspace_width - tray_width - 2 * logical_px(sb_hoff_px);
|
||||||
|
|
||||||
|
/* If the statusline is too long, try to use short texts. */
|
||||||
|
if (statusline_width > max_statusline_width)
|
||||||
|
refresh_statusline(true);
|
||||||
|
|
||||||
/* Luckily we already prepared a seperate pixmap containing the rendered
|
/* Luckily we already prepared a seperate pixmap containing the rendered
|
||||||
* statusline, we just have to copy the relevant parts to the relevant
|
* statusline, we just have to copy the relevant parts to the relevant
|
||||||
* position */
|
* position */
|
||||||
int tray_width = get_tray_width(outputs_walk->trayclients);
|
int visible_statusline_width = MIN(statusline_width, max_statusline_width);
|
||||||
|
|
||||||
int visible_statusline_width = MIN(statusline_width,
|
|
||||||
outputs_walk->rect.w - workspace_width - tray_width - 2 * logical_px(sb_hoff_px));
|
|
||||||
|
|
||||||
xcb_copy_area(xcb_connection,
|
xcb_copy_area(xcb_connection,
|
||||||
statusline_pm,
|
statusline_pm,
|
||||||
outputs_walk->buffer,
|
outputs_walk->buffer,
|
||||||
|
|
|
@ -169,6 +169,12 @@ i3String *i3string_from_markup_with_length(const char *from_markup, size_t num_b
|
||||||
*/
|
*/
|
||||||
i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs);
|
i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the given i3string.
|
||||||
|
* Note that this will not free the source string.
|
||||||
|
*/
|
||||||
|
i3String *i3string_copy(i3String *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free an i3String.
|
* Free an i3String.
|
||||||
*
|
*
|
||||||
|
|
|
@ -109,6 +109,16 @@ i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the given i3string.
|
||||||
|
* Note that this will not free the source string.
|
||||||
|
*/
|
||||||
|
i3String *i3string_copy(i3String *str) {
|
||||||
|
i3String *copy = i3string_from_utf8(i3string_as_utf8(str));
|
||||||
|
copy->is_markup = str->is_markup;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free an i3String.
|
* Free an i3String.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue