summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-11-11 19:25:46 -0500
committerPatrick Griffis <tingping@tingping.se>2016-11-11 19:27:57 -0500
commit241dd69b081779a77718763561a779cdffcaf11f (patch)
treec9ee1ac451506f8b17efbf1b5b98cd97fe19aee5
parent539949973c484f14d40f1886d67ec09df057315c (diff)
Further tab color improvements
- Combine the three properties into a single one
- Finally fully fix the handling with plugins handling events

TODO: Look into lastact handling of these, seems wrong
-rw-r--r--src/common/hexchat.c6
-rw-r--r--src/common/hexchat.h13
-rw-r--r--src/common/inbound.c16
-rw-r--r--src/common/outbound.c2
-rw-r--r--src/common/text.c11
-rw-r--r--src/fe-gtk/fe-gtk.c10
-rw-r--r--src/fe-gtk/maingui.c44
7 files changed, 42 insertions, 60 deletions
diff --git a/src/common/hexchat.c b/src/common/hexchat.c
index 64fd351e..487c96f4 100644
--- a/src/common/hexchat.c
+++ b/src/common/hexchat.c
@@ -126,11 +126,11 @@ lastact_update(session *sess)
 	int newidx = LACT_NONE;
 	int dia = (sess->type == SESS_DIALOG);
 
-	if (sess->nick_said)
+	if (sess->tab_state & TAB_STATE_NEW_HILIGHT)
 		newidx = dia? LACT_QUERY_HI: LACT_CHAN_HI;
-	else if (sess->msg_said)
+	else if (sess->tab_state & TAB_STATE_NEW_MSG)
 		newidx = dia? LACT_QUERY: LACT_CHAN;
-	else if (sess->new_data)
+	else if (sess->tab_state & TAB_STATE_NEW_DATA)
 		newidx = dia? LACT_QUERY: LACT_CHAN_DATA;
 
 	/* If already first at the right position, just return */
diff --git a/src/common/hexchat.h b/src/common/hexchat.h
index 2bdfb656..38a3e830 100644
--- a/src/common/hexchat.h
+++ b/src/common/hexchat.h
@@ -352,6 +352,13 @@ typedef enum gtk_xtext_search_flags_e {
 	regexp = 16
 } gtk_xtext_search_flags;
 
+typedef enum {
+	TAB_STATE_NONE = 0,
+	TAB_STATE_NEW_DATA = (1 << 0),
+	TAB_STATE_NEW_MSG = (1 << 1),
+	TAB_STATE_NEW_HILIGHT = (1 << 2),
+} tab_state_flags;
+
 typedef struct session
 {
 	/* Per-Channel Alerts */
@@ -406,16 +413,14 @@ typedef struct session
 	int lastact_idx;		/* the sess_list_by_lastact[] index of the list we're in.
 							 * For valid values, see defines of LACT_*. */
 
-	int new_data:1;			/* new data avail? (purple tab) */
-	int nick_said:1;		/* your nick mentioned? (blue tab) */
-	int msg_said:1;			/* new msg available? (red tab) */
-
 	int ignore_date:1;
 	int ignore_mode:1;
 	int ignore_names:1;
 	int end_of_names:1;
 	int doing_who:1;		/* /who sent on this channel */
 	int done_away_check:1;	/* done checking for away status changes */
+	tab_state_flags tab_state;
+	tab_state_flags last_tab_state; /* before event is handled */
 	gtk_xtext_search_flags lastlog_flags;
 	void (*scrollback_replay_marklast) (struct session *sess);
 } session;
diff --git a/src/common/inbound.c b/src/common/inbound.c
index aa87cfab..fae0fd34 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -316,7 +316,7 @@ is_hilight (char *from, char *text, session *sess, server *serv)
 		g_free (text);
 		if (sess != current_tab)
 		{
-			sess->nick_said = TRUE;
+			sess->tab_state |= TAB_STATE_NEW_HILIGHT;
 			lastact_update (sess);
 		}
 		return 1;
@@ -373,14 +373,9 @@ inbound_action (session *sess, char *chan, char *from, char *ip, char *text,
 	if (sess != current_tab)
 	{
 		if (fromme)
-		{
-			sess->msg_said = FALSE;
-			sess->new_data = TRUE;
-		} else
-		{
-			sess->msg_said = TRUE;
-			sess->new_data = FALSE;
-		}
+			sess->tab_state |= TAB_STATE_NEW_DATA;
+		else
+			sess->tab_state |= TAB_STATE_NEW_MSG;
 		lastact_update (sess);
 	}
 
@@ -448,8 +443,7 @@ inbound_chanmsg (server *serv, session *sess, char *chan, char *from,
 
 	if (sess != current_tab)
 	{
-		sess->msg_said = TRUE;
-		sess->new_data = FALSE;
+		sess->tab_state |= TAB_STATE_NEW_MSG;
 		lastact_update (sess);
 	}
 
diff --git a/src/common/outbound.c b/src/common/outbound.c
index 3c717526..6dd42fb4 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -631,7 +631,7 @@ cmd_clear (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 		while (list)
 		{
 			sess = list->data;
-			if (!sess->nick_said)
+			if (!(sess->tab_state & TAB_STATE_NEW_HILIGHT))
 				fe_text_clear (list->data, 0);
 			list = list->next;
 		}
diff --git a/src/common/text.c b/src/common/text.c
index 799af833..9d7935f2 100644
--- a/src/common/text.c
+++ b/src/common/text.c
@@ -2008,6 +2008,7 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
 {
 	char *word[PDIWORDS];
 	int i;
+	tab_state_flags current_state = sess->tab_state;
 	unsigned int stripcolor_args = (chanopt_is_set (prefs.hex_text_stripcolor_msg, sess->text_strip) ? 0xFFFFFFFF : 0);
 	char tbuf[NICKLEN + 4];
 
@@ -2026,14 +2027,12 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
 	for (i = 5; i < PDIWORDS; i++)
 		word[i] = "\000";
 
+	/* We want to ignore the tab state if the plugin emits new events
+	 * and restore it if it doesn't eat the current one */
+	sess->tab_state = sess->last_tab_state;
 	if (plugin_emit_print (sess, word, timestamp))
-	{
-		/* Reset the state that never printed */
-		sess->nick_said = FALSE;
-		sess->msg_said = FALSE;
-		sess->new_data = FALSE;
 		return;
-	}
+	sess->tab_state = current_state;
 
 	/* If a plugin's callback executes "/close", 'sess' may be invalid */
 	if (!is_session (sess))
diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c
index ef9f3ab3..0f23f7f7 100644
--- a/src/fe-gtk/fe-gtk.c
+++ b/src/fe-gtk/fe-gtk.c
@@ -664,14 +664,10 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
 		return;
 
 	if (sess == current_tab)
-	{
-		sess->nick_said = FALSE;
-		sess->msg_said = FALSE;
-		sess->new_data = FALSE;
-	}
-	else if (sess->nick_said)
+		fe_set_tab_color (sess, 0);
+	else if (sess->tab_state & TAB_STATE_NEW_HILIGHT)
 		fe_set_tab_color (sess, 3);
-	else if (sess->msg_said)
+	else if (sess->tab_state & TAB_STATE_NEW_MSG)
 		fe_set_tab_color (sess, 2);
 	else
 		fe_set_tab_color (sess, 1);
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c
index 572f30e4..20edf1ba 100644
--- a/src/fe-gtk/maingui.c
+++ b/src/fe-gtk/maingui.c
@@ -178,62 +178,50 @@ fe_set_tab_color (struct session *sess, int col)
 		switch (col)
 		{
 		case 0:	/* no particular color (theme default) */
-			sess->new_data = FALSE;
-			sess->msg_said = FALSE;
-			sess->nick_said = FALSE;
+			sess->tab_state = TAB_STATE_NONE;
 			chan_set_color (sess->res->tab, plain_list);
 			break;
 		case 1:	/* new data has been displayed (dark red) */
-			sess->new_data = TRUE;
-			sess->msg_said = FALSE;
-			sess->nick_said = FALSE;
+			sess->tab_state = TAB_STATE_NEW_DATA;
 			chan_set_color (sess->res->tab, newdata_list);
 
 			if (chan_is_collapsed (sess->res->tab)
-				&& !(server_sess->msg_said || server_sess->nick_said)
+				&& !((server_sess->tab_state & TAB_STATE_NEW_MSG)
+					 || (server_sess->tab_state & TAB_STATE_NEW_HILIGHT))
 				&& !(server_sess == current_tab))
 			{
-				server_sess->new_data = TRUE;
-				server_sess->msg_said = FALSE;
-				server_sess->nick_said = FALSE;
+				server_sess->tab_state = TAB_STATE_NEW_DATA;
 				chan_set_color (chan_get_parent (sess->res->tab), newdata_list);
 			}
-				
+
 			break;
 		case 2:	/* new message arrived in channel (light red) */
-			sess->new_data = FALSE;
-			sess->msg_said = TRUE;
-			sess->nick_said = FALSE;
+			sess->tab_state = TAB_STATE_NEW_MSG;
 			chan_set_color (sess->res->tab, newmsg_list);
-			
-			if (chan_is_collapsed (sess->res->tab) 
-				&& !server_sess->nick_said
+
+			if (chan_is_collapsed (sess->res->tab)
+				&& !(server_sess->tab_state & TAB_STATE_NEW_HILIGHT)
 				&& !(server_sess == current_tab))
 			{
-				server_sess->new_data = FALSE;
-				server_sess->msg_said = TRUE;
-				server_sess->nick_said = FALSE;
+				server_sess->tab_state = TAB_STATE_NEW_MSG;
 				chan_set_color (chan_get_parent (sess->res->tab), newmsg_list);
 			}
-			
+
 			break;
 		case 3:	/* your nick has been seen (blue) */
-			sess->new_data = FALSE;
-			sess->msg_said = FALSE;
-			sess->nick_said = TRUE;
+			sess->tab_state = TAB_STATE_NEW_HILIGHT;
 			chan_set_color (sess->res->tab, nickseen_list);
 
 			if (chan_is_collapsed (sess->res->tab) && !(server_sess == current_tab))
 			{
-				server_sess->new_data = FALSE;
-				server_sess->msg_said = FALSE;
-				server_sess->nick_said = TRUE;
+				server_sess->tab_state = TAB_STATE_NEW_MSG;
 				chan_set_color (chan_get_parent (sess->res->tab), nickseen_list);
 			}
-				
+
 			break;
 		}
 		lastact_update (sess);
+		sess->last_tab_state = sess->tab_state; /* For plugins handling future prints */
 	}
 }