Force management of queues to queues.c
This commit is contained in:
		
							parent
							
								
									e3881766c0
								
							
						
					
					
						commit
						a536e3f60b
					
				| @ -60,11 +60,11 @@ gboolean run(void *data) | ||||
|                 timeout_cnt--; | ||||
|         } | ||||
| 
 | ||||
|         if (displayed->length > 0 && !xctx.visible) { | ||||
|         if (queues_length_displayed() > 0 && !xctx.visible) { | ||||
|                 x_win_show(); | ||||
|         } | ||||
| 
 | ||||
|         if (xctx.visible && displayed->length == 0) { | ||||
|         if (xctx.visible && queues_length_displayed() == 0) { | ||||
|                 x_win_hide(); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -137,7 +137,7 @@ void invoke_action(const char *action) | ||||
|         int appname_len = strlen(appname_begin) - 1; // remove ]
 | ||||
|         int action_len = strlen(action) - appname_len - 3; // remove space, [, ]
 | ||||
| 
 | ||||
|         for (GList *iter = g_queue_peek_head_link(displayed); iter; | ||||
|         for (const GList *iter = queues_get_displayed(); iter; | ||||
|              iter = iter->next) { | ||||
|                 notification *n = iter->data; | ||||
|                 if (g_str_has_prefix(appname_begin, n->appname) && strlen(n->appname) == appname_len) { | ||||
| @ -189,7 +189,7 @@ void context_menu(void) | ||||
|         } | ||||
|         char *dmenu_input = NULL; | ||||
| 
 | ||||
|         for (GList *iter = g_queue_peek_head_link(displayed); iter; | ||||
|         for (const GList *iter = queues_get_displayed(); iter; | ||||
|              iter = iter->next) { | ||||
|                 notification *n = iter->data; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										24
									
								
								src/queues.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/queues.c
									
									
									
									
									
								
							| @ -10,9 +10,9 @@ | ||||
| #include "settings.h" | ||||
| 
 | ||||
| /* notification lists */ | ||||
| GQueue *queue     = NULL; /* all new notifications get into here */ | ||||
| GQueue *displayed = NULL; /* currently displayed notifications */ | ||||
| GQueue *history   = NULL; /* history of displayed notifications */ | ||||
| static GQueue *queue     = NULL; /* all new notifications get into here */ | ||||
| static GQueue *displayed = NULL; /* currently displayed notifications */ | ||||
| static GQueue *history   = NULL; /* history of displayed notifications */ | ||||
| 
 | ||||
| unsigned int displayed_limit = 0; | ||||
| int next_notification_id = 1; | ||||
| @ -32,6 +32,24 @@ void queues_displayed_limit(unsigned int limit) | ||||
|         displayed_limit = limit; | ||||
| } | ||||
| 
 | ||||
| /* misc getter functions */ | ||||
| const GList *queues_get_displayed() | ||||
| { | ||||
|         return g_queue_peek_head_link(displayed); | ||||
| } | ||||
| unsigned int queues_length_waiting() | ||||
| { | ||||
|         return queue->length; | ||||
| } | ||||
| unsigned int queues_length_displayed() | ||||
| { | ||||
|         return displayed->length; | ||||
| } | ||||
| unsigned int queues_length_history() | ||||
| { | ||||
|         return history->length; | ||||
| } | ||||
| 
 | ||||
| int queues_notification_insert(notification *n, int replaces_id) | ||||
| { | ||||
|         if (replaces_id == 0) { | ||||
|  | ||||
							
								
								
									
										25
									
								
								src/queues.h
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/queues.h
									
									
									
									
									
								
							| @ -5,11 +5,6 @@ | ||||
| 
 | ||||
| #include "notification.h" | ||||
| 
 | ||||
| extern GQueue *queue; | ||||
| extern GQueue *displayed; | ||||
| extern GQueue *history; | ||||
| extern unsigned int displayed_limit; | ||||
| 
 | ||||
| /*
 | ||||
|  * Initialise neccessary queues | ||||
|  */ | ||||
| @ -21,6 +16,19 @@ void queues_init(void); | ||||
|  */ | ||||
| void queues_displayed_limit(unsigned int limit); | ||||
| 
 | ||||
| /*
 | ||||
|  * Return read only list of notifications | ||||
|  */ | ||||
| const GList *queues_get_displayed(); | ||||
| 
 | ||||
| /*
 | ||||
|  * Returns the current amount of notifications, | ||||
|  * which are shown, waiting or already in history | ||||
|  */ | ||||
| unsigned int queues_length_waiting(); | ||||
| unsigned int queues_length_displayed(); | ||||
| unsigned int queues_length_history(); | ||||
| 
 | ||||
| /*
 | ||||
|  * Insert a fully initialized notification into queues | ||||
|  * Respects stack_duplicates, and notification replacement | ||||
| @ -43,9 +51,12 @@ int queues_notification_insert(notification *n, int replaces_id); | ||||
| bool queues_notification_replace_id(notification *new); | ||||
| 
 | ||||
| /*
 | ||||
|  * Close the notification that has id. | ||||
|  * Close the notification that has n->id == id | ||||
|  * | ||||
|  * After closing, call wake_up to remove the notification from UI | ||||
|  * Sends a signal and pushes it automatically to history. | ||||
|  * | ||||
|  * After closing, call wake_up to synchronize the queues with the UI | ||||
|  * (which closes the notification on screen) | ||||
|  * | ||||
|  * reasons: | ||||
|  * -1 -> notification is a replacement, no NotificationClosed signal emitted | ||||
|  | ||||
							
								
								
									
										18
									
								
								src/x11/x.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/x11/x.c
									
									
									
									
									
								
							| @ -533,11 +533,11 @@ static GSList *r_create_layouts(cairo_t *c) | ||||
| { | ||||
|         GSList *layouts = NULL; | ||||
| 
 | ||||
|         int qlen = g_list_length(g_queue_peek_head_link(queue)); | ||||
|         int qlen = queues_length_waiting(); | ||||
|         bool xmore_is_needed = qlen > 0 && settings.indicate_hidden; | ||||
| 
 | ||||
|         notification *last = NULL; | ||||
|         for (GList *iter = g_queue_peek_head_link(displayed); | ||||
|         for (const GList *iter = queues_get_displayed(); | ||||
|                         iter; iter = iter->next) | ||||
|         { | ||||
|                 notification *n = iter->data; | ||||
| @ -854,12 +854,10 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, | ||||
|                             && XLookupKeysym(&ev.xkey, | ||||
|                                              0) == settings.close_ks.sym | ||||
|                             && settings.close_ks.mask == state) { | ||||
|                                 if (displayed) { | ||||
|                                         notification *n = g_queue_peek_head(displayed); | ||||
|                                         if (n) { | ||||
|                                                 queues_notification_close(n, 2); | ||||
|                                                 wake_up(); | ||||
|                                         } | ||||
|                                 const GList *displayed = queues_get_displayed(); | ||||
|                                 if (displayed && displayed->data) { | ||||
|                                         queues_notification_close(displayed->data, 2); | ||||
|                                         wake_up(); | ||||
|                                 } | ||||
|                         } | ||||
|                         if (settings.history_ks.str | ||||
| @ -926,7 +924,7 @@ static void x_handle_click(XEvent ev) | ||||
|                 int y = settings.separator_height; | ||||
|                 notification *n = NULL; | ||||
|                 int first = true; | ||||
|                 for (GList *iter = g_queue_peek_head_link(displayed); iter; | ||||
|                 for (const GList *iter = queues_get_displayed(); iter; | ||||
|                      iter = iter->next) { | ||||
|                         n = iter->data; | ||||
|                         if (ev.xbutton.y > y && ev.xbutton.y < y + n->displayed_height) | ||||
| @ -1127,7 +1125,7 @@ static void x_win_setup(void) | ||||
| void x_win_show(void) | ||||
| { | ||||
|         /* window is already mapped or there's nothing to show */ | ||||
|         if (xctx.visible || g_queue_is_empty(displayed)) { | ||||
|         if (xctx.visible || queues_length_displayed() == 0) { | ||||
|                 return; | ||||
|         } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Benedikt Heine
						Benedikt Heine