mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Moved typing notification from main chat to title bar
This commit is contained in:
parent
46c9a5ed4b
commit
d9c47c9b0d
@ -24,11 +24,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
static WINDOW *title_bar;
|
static WINDOW *title_bar;
|
||||||
static char *current_title = NULL;
|
static char *current_title = NULL;
|
||||||
|
static char *recipient = NULL;
|
||||||
|
static GTimer *typing_elapsed;
|
||||||
static int dirty;
|
static int dirty;
|
||||||
static jabber_presence_t current_status;
|
static jabber_presence_t current_status;
|
||||||
|
|
||||||
@ -51,6 +55,8 @@ create_title_bar(void)
|
|||||||
void
|
void
|
||||||
title_bar_title(void)
|
title_bar_title(void)
|
||||||
{
|
{
|
||||||
|
recipient = NULL;
|
||||||
|
typing_elapsed = NULL;
|
||||||
title_bar_show("Profanity. Type /help for help information.");
|
title_bar_show("Profanity. Type /help for help information.");
|
||||||
dirty = TRUE;
|
dirty = TRUE;
|
||||||
}
|
}
|
||||||
@ -72,6 +78,27 @@ title_bar_resize(void)
|
|||||||
void
|
void
|
||||||
title_bar_refresh(void)
|
title_bar_refresh(void)
|
||||||
{
|
{
|
||||||
|
if (recipient != NULL) {
|
||||||
|
|
||||||
|
if (typing_elapsed != NULL) {
|
||||||
|
gdouble seconds = g_timer_elapsed(typing_elapsed, NULL);
|
||||||
|
|
||||||
|
if (seconds >= 10) {
|
||||||
|
|
||||||
|
if (current_title != NULL) {
|
||||||
|
free(current_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char));
|
||||||
|
strcpy(current_title, recipient);
|
||||||
|
|
||||||
|
title_bar_draw();
|
||||||
|
|
||||||
|
dirty = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
wrefresh(title_bar);
|
wrefresh(title_bar);
|
||||||
inp_put_back();
|
inp_put_back();
|
||||||
@ -97,8 +124,57 @@ title_bar_set_status(jabber_presence_t status)
|
|||||||
_title_bar_draw_status();
|
_title_bar_draw_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
title_bar_set_recipient(char *from)
|
||||||
|
{
|
||||||
|
typing_elapsed = NULL;
|
||||||
|
recipient = from;
|
||||||
|
|
||||||
|
if (current_title != NULL) {
|
||||||
|
free(current_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
current_title = (char *) malloc((strlen(from) + 1) * sizeof(char));
|
||||||
|
strcpy(current_title, from);
|
||||||
|
|
||||||
|
dirty = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
title_bar_set_typing(gboolean is_typing)
|
||||||
|
{
|
||||||
|
if (is_typing) {
|
||||||
|
if (typing_elapsed != NULL) {
|
||||||
|
g_timer_start(typing_elapsed);
|
||||||
|
} else {
|
||||||
|
typing_elapsed = g_timer_new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_title != NULL) {
|
||||||
|
free(current_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_typing) {
|
||||||
|
current_title = (char *) malloc((strlen(recipient) + 13) * sizeof(char));
|
||||||
|
sprintf(current_title, "%s (typing...)", recipient);
|
||||||
|
} else {
|
||||||
|
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char));
|
||||||
|
strcpy(current_title, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
dirty = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
title_bar_draw(void)
|
||||||
|
{
|
||||||
|
_title_bar_draw_status();
|
||||||
|
_title_bar_draw_title();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_title_bar_draw_status()
|
_title_bar_draw_status(void)
|
||||||
{
|
{
|
||||||
int rows, cols;
|
int rows, cols;
|
||||||
getmaxyx(stdscr, rows, cols);
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
3
src/ui.h
3
src/ui.h
@ -55,6 +55,9 @@ void title_bar_resize(void);
|
|||||||
void title_bar_show(const char * const title);
|
void title_bar_show(const char * const title);
|
||||||
void title_bar_title(void);
|
void title_bar_title(void);
|
||||||
void title_bar_set_status(jabber_presence_t status);
|
void title_bar_set_status(jabber_presence_t status);
|
||||||
|
void title_bar_set_recipient(char *from);
|
||||||
|
void title_bar_set_typing(gboolean is_typing);
|
||||||
|
void title_bar_draw(void);
|
||||||
|
|
||||||
// main window actions
|
// main window actions
|
||||||
int win_close_win(void);
|
int win_close_win(void);
|
||||||
|
@ -208,9 +208,8 @@ win_show_typing(const char * const from)
|
|||||||
|
|
||||||
// in chat window with user
|
// in chat window with user
|
||||||
} else {
|
} else {
|
||||||
WINDOW *win = _wins[win_index].win;
|
title_bar_set_typing(TRUE);
|
||||||
_win_show_time(win);
|
title_bar_draw();
|
||||||
_win_show_typing(win, short_from);
|
|
||||||
|
|
||||||
status_bar_active(win_index);
|
status_bar_active(win_index);
|
||||||
dirty = TRUE;
|
dirty = TRUE;
|
||||||
@ -239,6 +238,8 @@ win_show_incomming_msg(const char * const from, const char * const message)
|
|||||||
_win_show_message(win, message);
|
_win_show_message(win, message);
|
||||||
|
|
||||||
if (win_index == _curr_prof_win) {
|
if (win_index == _curr_prof_win) {
|
||||||
|
title_bar_set_typing(FALSE);
|
||||||
|
title_bar_draw();
|
||||||
status_bar_active(win_index);
|
status_bar_active(win_index);
|
||||||
dirty = TRUE;
|
dirty = TRUE;
|
||||||
} else {
|
} else {
|
||||||
@ -713,7 +714,8 @@ _win_switch_if_active(const int i)
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
title_bar_title();
|
title_bar_title();
|
||||||
} else {
|
} else {
|
||||||
title_bar_show(_wins[i].from);
|
title_bar_set_recipient(_wins[i].from);
|
||||||
|
title_bar_draw();;
|
||||||
status_bar_active(i);
|
status_bar_active(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user