]> git.sur5r.net Git - i3/i3/commitdiff
Add support for short_text 1562/head
authorIngo Bürk <ingo.buerk@tngtech.com>
Sat, 21 Mar 2015 20:36:15 +0000 (21:36 +0100)
committerIngo Bürk <ingo.buerk@tngtech.com>
Mon, 23 Mar 2015 10:24:30 +0000 (11:24 +0100)
When the statusline is too long, try to use the short_text property of each status block before falling back to truncating it.
fixes #1092

i3bar/src/xcb.c
libi3/string.c

index 96fcb3fa39157bb75e8935a9cca288d77a024760..06eac7ea3a4bf8059b78c4c75695bb877af1b018 100644 (file)
@@ -159,7 +159,7 @@ int get_tray_width(struct tc_head *trayclients) {
  * Redraws the statusline to the buffer
  *
  */
-void refresh_statusline(void) {
+void refresh_statusline(bool use_short_text) {
     struct status_block *block;
 
     uint32_t old_statusline_width = statusline_width;
@@ -167,6 +167,12 @@ void refresh_statusline(void) {
 
     /* Predict the text width of all blocks (in pixels). */
     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)
             continue;
 
@@ -1760,7 +1766,7 @@ void draw_bars(bool unhide) {
     DLOG("Drawing bars...\n");
     int workspace_width = 0;
 
-    refresh_statusline();
+    refresh_statusline(false);
 
     i3_output *outputs_walk;
     SLIST_FOREACH(outputs_walk, outputs, slist) {
@@ -1904,14 +1910,17 @@ void draw_bars(bool unhide) {
         if (!TAILQ_EMPTY(&statusline_head)) {
             DLOG("Printing statusline!\n");
 
-            /* Luckily we already prepared a seperate pixmap containing the rendered
-             * statusline, we just have to copy the relevant parts to the relevant
-             * position */
             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);
 
-            int visible_statusline_width = MIN(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
+             * statusline, we just have to copy the relevant parts to the relevant
+             * position */
+            int visible_statusline_width = MIN(statusline_width, max_statusline_width);
             xcb_copy_area(xcb_connection,
                           statusline_pm,
                           outputs_walk->buffer,
index a28cc899195f8fc0bfe23b4f05a4caccc167b2d5..88fd198639bd377a9c40d57dc12f6ac944333a09 100644 (file)
@@ -114,10 +114,9 @@ i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) {
  * Note that this will not free the source string.
  */
 i3String *i3string_copy(i3String *str) {
-    if (str->is_markup)
-        return i3string_from_markup(i3string_as_utf8(str));
-    else
-        return i3string_from_utf8(i3string_as_utf8(str));
+    i3String *copy = i3string_from_utf8(i3string_as_utf8(str));
+    copy->is_markup = str->is_markup;
+    return copy;
 }
 
 /*