Implement notification_create function
notification_create currently simply allocates memory and zeroes it to properly initialise a notification. Since we currently have at least 2 places in the code that create notifications(startup notification in dunst.c and notifications from dbus in dbus.c) the creation should be handled from a central location in case we ever need to change the creation procedure later on.
This commit is contained in:
		
							parent
							
								
									6c9de72c7d
								
							
						
					
					
						commit
						de9c52f98f
					
				| @ -295,7 +295,7 @@ static void onNotify(GDBusConnection * connection, | ||||
|                 } | ||||
|         } | ||||
| 
 | ||||
|         notification *n = malloc(sizeof(notification)); | ||||
|         notification *n = notification_create(); | ||||
|         if(n == NULL) { | ||||
|                 die("Unable to allocate memory", EXIT_FAILURE); | ||||
|         } | ||||
|  | ||||
| @ -343,7 +343,7 @@ int dunst_main(int argc, char *argv[]) | ||||
|         x_setup(); | ||||
| 
 | ||||
|         if (settings.startup_notification) { | ||||
|                 notification *n = malloc(sizeof(notification)); | ||||
|                 notification *n = notification_create(); | ||||
|                 if(n == NULL) { | ||||
|                         die("Unable to allocate memory", EXIT_FAILURE); | ||||
|                 } | ||||
|  | ||||
| @ -311,6 +311,20 @@ char *notification_extract_markup_urls(char **str_ptr) { | ||||
|     return urls; | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  * This is a helper function that allocates, initialises a notification and | ||||
|  * returns a pointer to it. All notifications should be created using this | ||||
|  * function. After setting all the necessary fields(i.e. appname, summary, | ||||
|  * body, icon etc) notification_init should be called to do the actual | ||||
|  * initialisation. | ||||
|  */ | ||||
| notification *notification_create(void) | ||||
| { | ||||
|         notification *n = malloc(sizeof(notification)); | ||||
|         memset(n, 0, sizeof(notification)); | ||||
|         return n; | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  * Initialize the given notification and add it to | ||||
|  * the queue. Replace notification with id if id > 0. | ||||
|  | ||||
| @ -54,6 +54,7 @@ typedef struct _notification { | ||||
|         Actions *actions; | ||||
| } notification; | ||||
| 
 | ||||
| notification *notification_create(void); | ||||
| int notification_init(notification * n, int id); | ||||
| void notification_free(notification * n); | ||||
| int notification_close_by_id(int id, int reason); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikos Tsipinakis
						Nikos Tsipinakis