xfdesktop window-list menu patch

Jens Luedicke jens at irs-net.com
Thu Jan 23 12:03:32 CET 2003


Hi :)

Thanks for your comments. I rewrote the patch, so that 
it uses g_string for the string manipulation.

If its ok, I'll apply and commit it. 

Index: menu.c
===================================================================
RCS file: /cvsroot/xfce/xfce-devel/xfdesktop/src/menu.c,v
retrieving revision 1.1
diff -r1.1 menu.c
124c124
<     char *label;
---
>     GString *str;
131a132,145
>    
>     str = g_string_new(name);
> 
>     if (str->len >= 15) {
>     	g_string_truncate(str, 15);
> 	g_string_append(str, " ...");
>     }
> 
>     if (netk_window_is_minimized(win)) {
> 	g_string_prepend(str, "[");
> 	g_string_append(str, "]");
>     }
> 	
>     mi = gtk_menu_item_new_with_label(str->str);
133,136c147
<     if (netk_window_is_minimized(win))
< 	label = g_strconcat("(", name, ")", NULL);
<     else
< 	label = g_strdup(name);
---
>     g_string_free(str,TRUE);
138,140d148
<     mi = gtk_menu_item_new_with_label(label);
<     g_free(label);
< 


On Wed, Jan 22, 2003 at 11:57:52PM +0100, Olivier Fourdan wrote:
> Hi Jens,
> 
> Sorry, but the way you manage your strings isn't correct...
> 
> g_strdup allocates memory, it doesn't make much sense to use a char
> array for that, you leak memory...
> 
> It's better to do :
> 
> gchar *my_string;
> 
> my_string=g_strdup(another_string);
> 
> /* so some processing with the string */
> 
> g_free(my_string);
> 
> 
> => this way, you don't leak memory. Can you try to make this patch a bit
> cleaner ?
> 
> Note: It's usually a bad idea to use char arrays IMHO :)
> 
> Thanks in advance,
> 
> Cheers,
> Olivier.
> 
> On Wed, 2003-01-22 at 23:44, Jens Luedicke wrote:
> > Hi ...
> > 
> > I hacked some code to shorten the 
> > window-titles in the window-list menu.
> > 
> > Its mainly basic C knowledge and ignores
> > probably good and safe coding style ;)
> -- 
> Olivier Fourdan <fourdan at xfce.org>
> http://www.xfce.org
> 
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at moongroup.com
> http://moongroup.com/mailman/listinfo/xfce4-dev

-- 
Jens Luedicke <jens at irs-net.com>

"Never offend people with style when you can offend them with substance."
--Sam Brown




More information about the Xfce4-dev mailing list