diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-05-22 20:42:44 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-05-22 20:42:44 +0200 |
commit | 86f0e0ea7033a27a83a5c24091ae1fd5b579296d (patch) | |
tree | 124dd27fe79c1f2e604d131451df1f3220471994 | |
parent | ee9ca24f8726009f78a2e192b9d29c6e57bac45d (diff) | |
download | profani-tty-86f0e0ea7033a27a83a5c24091ae1fd5b579296d.tar.gz |
Dont show resource in titlebar if it is too long
Fix https://github.com/profanity-im/profanity/issues/715
-rw-r--r-- | src/ui/titlebar.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 14a73819..9c8adfe5 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -61,8 +61,8 @@ static gboolean typing; static GTimer *typing_elapsed; static void _title_bar_draw(void); -static void _show_self_presence(void); -static void _show_contact_presence(ProfChatWin *chatwin); +static int _show_self_presence(void); +static void _show_contact_presence(ProfChatWin *chatwin, int pos, int maxpos); static void _show_privacy(ProfChatWin *chatwin); static void _show_muc_privacy(ProfMucWin *mucwin); static void _show_scrolled(ProfWin *current); @@ -183,6 +183,8 @@ title_bar_set_typing(gboolean is_typing) static void _title_bar_draw(void) { + int pos; + int maxrightpos; ProfWin *current = wins_get_current(); werase(win); @@ -196,11 +198,16 @@ _title_bar_draw(void) mvwprintw(win, 0, 0, " %s", title); free(title); + pos = strlen(title) + 1; + + // presence is written from the right side + // calculate it first so we have a maxposition + maxrightpos = _show_self_presence(); if (current && current->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*) current; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - _show_contact_presence(chatwin); + _show_contact_presence(chatwin, pos, maxrightpos); _show_privacy(chatwin); _show_scrolled(current); @@ -214,8 +221,6 @@ _title_bar_draw(void) _show_scrolled(current); } - _show_self_presence(); - wnoutrefresh(win); inp_put_back(); } @@ -241,7 +246,7 @@ _show_scrolled(ProfWin *current) } } -static void +static int _show_self_presence(void) { int presence_attrs = 0; @@ -339,6 +344,8 @@ _show_self_presence(void) mvwaddch(win, 0, cols - (tls_start - 4), ']'); wattroff(win, bracket_attrs); } + + return tls_start - 1; } static void @@ -492,7 +499,7 @@ _show_privacy(ProfChatWin *chatwin) } static void -_show_contact_presence(ProfChatWin *chatwin) +_show_contact_presence(ProfChatWin *chatwin, int pos, int maxpos) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); char *resource = NULL; @@ -503,9 +510,13 @@ _show_contact_presence(ProfChatWin *chatwin) } else if (session && session->resource) { resource = session->resource; } + if (resource && prefs_get_boolean(PREF_RESOURCE_TITLE)) { - wprintw(win, "/"); - wprintw(win, resource); + int needed = strlen(resource) + 1; + if (pos + needed < maxpos) { + wprintw(win, "/"); + wprintw(win, resource); + } } if (prefs_get_boolean(PREF_PRESENCE)) { |