-format
This commit is contained in:
		
							parent
							
								
									e5ebf7fef0
								
							
						
					
					
						commit
						cc1d90adca
					
				
							
								
								
									
										18
									
								
								README.1
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								README.1
									
									
									
									
									
								
							| @ -21,6 +21,8 @@ dunst \- dmenu\-ish universal notification system | ||||
| .IR color ] | ||||
| .RB [ \-to | ||||
| .IR secs ] | ||||
| .RB [ \-format | ||||
| .IR fmt ] | ||||
| .RB [ \-key | ||||
| .IR key ] | ||||
| .RB [ \-mod | ||||
| @ -69,6 +71,9 @@ close window by pressing key [a,b,space,Return etc.] (should be used in combinat | ||||
| .BI \-mod " modifier" | ||||
| defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to combine modifiers. | ||||
| .TP | ||||
| .BI \-format " fmt" | ||||
| defines the format of the messages. See FORMAT. | ||||
| .TP | ||||
| .BI \-mon " n" | ||||
| show the notification on monitor n. | ||||
| .TP | ||||
| @ -76,6 +81,19 @@ show the notification on monitor n. | ||||
| The geometry of the message window. The height is measured in lines everything else in pixels. If the width is omitted but the height is given ("-geometry x2"), the message window expands over the whole screen (dmenu-like). If width is 0, the window expands to the longest message displayed. A positive x is measured from the left, a negative from the right side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES | ||||
| show the notification on monitor n. | ||||
| 
 | ||||
| .SH FORMAT | ||||
| fmt is a string containing placeholders. The placeholders will be replaced with the corresponding text, or if the text is not present, nothing. | ||||
| Possible placeholders are: | ||||
| .TP | ||||
| %a  appname | ||||
| .TP | ||||
| %s  summary | ||||
| .TP | ||||
| %b  body | ||||
| .TP | ||||
| %i  iconname (including its path) | ||||
| .TP | ||||
| %I  iconname (without its path) | ||||
| .SH EXAMPLES | ||||
| .BI "dunst " \-geometry " x2" | ||||
| Displays a maximum of two lines across the top of the screen. | ||||
|  | ||||
							
								
								
									
										52
									
								
								dunst.c
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								dunst.c
									
									
									
									
									
								
							| @ -1,3 +1,4 @@ | ||||
| #define _GNU_SOURCE | ||||
| #include <unistd.h> | ||||
| #include <time.h> | ||||
| #include <stdio.h> | ||||
| @ -65,6 +66,7 @@ static KeySym mask = 0; | ||||
| static screen_info scr; | ||||
| static dimension_t geometry; | ||||
| static int font_h; | ||||
| static const char *format = "%s %b"; | ||||
| 
 | ||||
| /* list functions */ | ||||
| msg_queue_t *append(msg_queue_t *queue, char *msg, int to, int urgency); | ||||
| @ -77,7 +79,9 @@ int list_len(msg_queue_t *list); | ||||
| void check_timeouts(void); | ||||
| void delete_msg(msg_queue_t *elem); | ||||
| void drawmsg(void); | ||||
| char *format_msg(const char *app, const char *sum, const char *body, const char *icon); | ||||
| void handleXEvents(void); | ||||
| char *string_replace(const char *needle, const char *replacement, char *haystack); | ||||
| void run(void); | ||||
| void setup(void); | ||||
| void show_win(void); | ||||
| @ -303,6 +307,23 @@ drawmsg(void) { | ||||
|     mapdc(dc, win, width, height*font_h); | ||||
| } | ||||
| 
 | ||||
| char * | ||||
| _do_replace(char *buf, char *replace_buf, const char *to_replace, const char *replacement) { | ||||
|     char *replace_buf_old = strdup(replace_buf); | ||||
|     if(strstr(replace_buf, to_replace)) { | ||||
|         if(strlen(replacement) > 0) { | ||||
|             replace_buf = string_replace("%{", "", replace_buf); | ||||
| 
 | ||||
|             replace_buf = string_replace(to_replace, replacement, replace_buf); | ||||
|             replace_buf[strlen(replace_buf)-1] = '\0'; | ||||
|             buf = string_replace(replace_buf_old, replace_buf, buf); | ||||
|         } else { | ||||
|             buf = string_replace(replace_buf, "", buf); | ||||
|         } | ||||
|     } | ||||
|     return buf; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| handleXEvents(void) { | ||||
| 	XEvent ev; | ||||
| @ -333,6 +354,32 @@ handleXEvents(void) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| char * | ||||
| string_replace(const char *needle, const char *replacement, char *haystack) { | ||||
|     char *tmp, *start; | ||||
|     int size; | ||||
|     start = strstr(haystack, needle); | ||||
|     if(start == NULL) { | ||||
|         return haystack; | ||||
|     } | ||||
| 
 | ||||
|     size = (strlen(haystack) - strlen(needle)) + strlen(replacement) + 1; | ||||
|     tmp = calloc(sizeof(char), size); | ||||
|     memset(tmp, '\0', size); | ||||
| 
 | ||||
|     strncpy(tmp, haystack, start-haystack); | ||||
|     tmp[start-haystack] = '\0'; | ||||
| 
 | ||||
|     sprintf(tmp+strlen(tmp), "%s%s", replacement, start+strlen(needle)); | ||||
|     free(haystack); | ||||
| 
 | ||||
|     if(strstr(tmp, needle)) { | ||||
|         return string_replace(needle, replacement, tmp); | ||||
|     } else { | ||||
|         return tmp; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void | ||||
| run(void) { | ||||
| 
 | ||||
| @ -534,6 +581,9 @@ main(int argc, char *argv[]) { | ||||
|         else if(!strcmp(argv[i], "-mon")) { | ||||
|             scr.scr = atoi(argv[++i]); | ||||
|         } | ||||
|         else if(!strcmp(argv[i], "-format")) { | ||||
|             format = argv[++i]; | ||||
|         } | ||||
|         else if(!strcmp(argv[i], "-key")) { | ||||
|             key = XStringToKeysym(argv[i+1]); | ||||
|             if(key == NoSymbol) { | ||||
| @ -588,6 +638,6 @@ main(int argc, char *argv[]) { | ||||
| 
 | ||||
| void | ||||
| usage(int exit_status) { | ||||
|     fputs("usage: dunst [-h/--help] [-geometry geom] [-fn font]\n[-nb color] [-nf color] [-lb color] [-lf color] [-cb color] [ -cf color]\n[-to secs] [-key key] [-mod modifier] [-mon n] [-msg msg]\n", stderr); | ||||
|     fputs("usage: dunst [-h/--help] [-geometry geom] [-fn font] [-format fmt]\n[-nb color] [-nf color] [-lb color] [-lf color] [-cb color] [ -cf color]\n[-to secs] [-key key] [-mod modifier] [-mon n] [-msg msg]\n", stderr); | ||||
|     exit(exit_status); | ||||
| } | ||||
|  | ||||
							
								
								
									
										22
									
								
								dunst_dbus.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								dunst_dbus.c
									
									
									
									
									
								
							| @ -210,22 +210,12 @@ notify(DBusMessage *dmsg) { | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     if(strlen(body) > 0) { | ||||
|         msg = malloc( | ||||
|                   strlen(appname) | ||||
|                  +strlen(summary) | ||||
|                  +strlen(body) | ||||
|                  +strlen(":  -- ") | ||||
|                  +5); | ||||
|         sprintf(msg, "%s: %s -- %s", appname, summary, body); | ||||
|     } else { | ||||
|         msg = malloc( | ||||
|                   strlen(appname) | ||||
|                  +strlen(summary) | ||||
|                  +strlen(": ") | ||||
|                  +5); | ||||
|         sprintf(msg, "%s: %s", appname, summary); | ||||
|     } | ||||
|     msg = string_replace("%a", appname, strdup(format)); | ||||
|     msg = string_replace("%s", summary, msg); | ||||
|     msg = string_replace("%i", icon, msg); | ||||
|     msg = string_replace("%I", basename(icon), msg); | ||||
|     msg = string_replace("%b", body, msg); | ||||
| 
 | ||||
| 
 | ||||
|     if(expires > 0) { | ||||
|         expires = expires/1000; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sascha Kruse
						Sascha Kruse