draw: iso2utf now gets len as arg

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-01 14:44:19 +02:00
parent 282dc95042
commit 9b74cdbc0a
9 changed files with 52 additions and 41 deletions

View File

@ -67,13 +67,14 @@ DO_LUA_EQ(client_t, client, "client")
static bool
client_loadprops(client_t * c, screen_t *screen)
{
ssize_t len;
tag_array_t *tags = &screen->tags;
char *prop = NULL;
if(!xutil_gettextprop(globalconf.connection, c->win, _AWESOME_PROPERTIES, &prop))
if(!xutil_gettextprop(globalconf.connection, c->win, _AWESOME_PROPERTIES, &prop, &len))
return false;
if(a_strlen(prop) != tags->len + 2)
if(len != tags->len + 2)
{
/* ignore property if the tag count isn't matching */
p_delete(&prop);
@ -151,13 +152,14 @@ void
client_updatetitle(client_t *c)
{
char *name;
ssize_t len;
if(!xutil_gettextprop(globalconf.connection, c->win, _NET_WM_NAME, &name))
if(!xutil_gettextprop(globalconf.connection, c->win, WM_NAME, &name))
if(!xutil_gettextprop(globalconf.connection, c->win, _NET_WM_NAME, &name, &len))
if(!xutil_gettextprop(globalconf.connection, c->win, WM_NAME, &name, &len))
return;
p_delete(&c->name);
a_iso2utf8(name, &c->name);
a_iso2utf8(&c->name, name, len);
/* call hook */
luaA_client_userdata_new(globalconf.L, c);
@ -1311,10 +1313,11 @@ luaA_client_name_get(lua_State *L)
static int
luaA_client_name_set(lua_State *L)
{
size_t len;
client_t **c = luaA_checkudata(L, 1, "client");
const char *name = luaL_checkstring(L, 2);
const char *name = luaL_checklstring(L, 2, &len);
p_delete(&(*c)->name);
a_iso2utf8(name, &(*c)->name);
a_iso2utf8(&(*c)->name, name, len);
return 0;
}

View File

@ -56,18 +56,22 @@ void draw_parser_data_wipe(draw_parser_data_t *pdata)
draw_image_delete(&pdata->bg_image);
}
/** Convert text from any charset to UTF-8 using iconv
* \param iso the ISO string to convert
* \return NULL if error, otherwise pointer to the new converted string
/** Convert text from any charset to UTF-8 using iconv.
* \param iso The ISO string to convert.
* \param len The string size.
* \return NULL if error, otherwise pointer to the new converted string.
*/
char *
draw_iso2utf8(const char *iso)
draw_iso2utf8(const char *iso, size_t len)
{
iconv_t iso2utf8;
size_t len, utf8len;
size_t utf8len;
char *utf8, *utf8p;
if(!(len = a_strlen(iso)))
if(len < 0)
len = a_strlen(iso);
if(!len)
return NULL;
if(!a_strcmp(nl_langinfo(CODESET), "UTF-8"))

View File

@ -142,18 +142,18 @@ draw_context_delete(draw_context_t **ctx)
font_t *draw_font_new(xcb_connection_t *, int, const char *);
void draw_font_delete(font_t **);
char * draw_iso2utf8(const char *);
char * draw_iso2utf8(const char *, size_t);
static inline bool
a_iso2utf8(const char *str, char **res)
a_iso2utf8(char **dest, const char *str, ssize_t len)
{
char *utf8;
if((utf8 = draw_iso2utf8(str)))
if((utf8 = draw_iso2utf8(str, len)))
{
*res = utf8;
*dest = utf8;
return true;
}
*res = a_strdup(str);
*dest = a_strdup(str);
return false;
}

View File

@ -32,14 +32,15 @@
#include "common/atoms.h"
/** Get the string value of an atom.
* \param conn X connection
* \param w window
* \param atom the atom
* \param text buffer to fill
* \return true on sucess, falsse on failure
* \param conn X connection.
* \param w Window.
* \param atom The atom.
* \param text Buffer to fill.
* \param len Length of the filled buffer.
* \return True on sucess, false on failure.
*/
bool
xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, char **text)
xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, char **text, ssize_t *len)
{
xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r;
@ -72,6 +73,7 @@ xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, char
/* use memcpy() because prop_val may not be \0 terminated */
memcpy(*text, prop_val, prop_r->value_len);
(*text)[prop_r->value_len] = '\0';
*len = prop_r->value_len;
}
p_delete(&prop_r);

View File

@ -96,7 +96,7 @@ typedef struct
class_hint_t *xutil_get_class_hint(xcb_connection_t *, xcb_window_t);
bool xutil_gettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **);
bool xutil_gettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **, ssize_t *);
void xutil_getlockmask(xcb_connection_t *, xcb_key_symbols_t *,
unsigned int *, unsigned int *, unsigned int *);

2
lua.c
View File

@ -571,7 +571,7 @@ luaA_parserc(const char* rcfile)
/* Assure there's at least one tag */
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
if(!globalconf.screens[screen].tags.len)
tag_append_to_screen(tag_new("default", layout_tile, 0.5, 1, 0), screen);
tag_append_to_screen(tag_new("default", sizeof("default"), layout_tile, 0.5, 1, 0), screen);
return true;
}

26
tag.c
View File

@ -55,20 +55,21 @@ tag_view(tag_t *tag, bool view)
}
/** Create a new tag. Parameters values are checked.
* \param name tag name
* \param layout layout to use
* \param mwfact master width factor
* \param nmaster number of master windows
* \param ncol number of columns for slaves windows
* \return a new tag with all these parameters
* \param name Tag name.
* \param len Tag name length.
* \param layout Layout to use.
* \param mwfact Master width factor.
* \param nmaster Number of master windows.
* \param ncol Number of columns for slaves windows.
* \return A new tag with all these parameters.
*/
tag_t *
tag_new(const char *name, layout_t *layout, double mwfact, int nmaster, int ncol)
tag_new(const char *name, ssize_t len, layout_t *layout, double mwfact, int nmaster, int ncol)
{
tag_t *tag;
tag = p_new(tag_t, 1);
a_iso2utf8(name, &tag->name);
a_iso2utf8(&tag->name, name, len);
tag->layout = layout;
/* to avoid error */
@ -313,6 +314,7 @@ luaA_tag_geti(lua_State *L)
static int
luaA_tag_new(lua_State *L)
{
size_t len;
tag_t *tag;
int ncol, nmaster;
const char *name, *lay;
@ -327,11 +329,11 @@ luaA_tag_new(lua_State *L)
mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5);
ncol = luaA_getopt_number(L, 2, "ncol", 1);
nmaster = luaA_getopt_number(L, 2, "nmaster", 1);
lay = luaA_getopt_string(L, 2, "layout", "tile");
lay = luaA_getopt_lstring(L, 2, "layout", "tile", &len);
layout = name_func_lookup(lay, LayoutList);
tag = tag_new(name,
tag = tag_new(name, len,
layout,
mwfact, nmaster, ncol);
@ -443,9 +445,9 @@ luaA_tag_newindex(lua_State *L)
switch(a_tokenize(attr, len))
{
case A_TK_NAME:
buf = luaL_checkstring(L, 3);
buf = luaL_checklstring(L, 3, &len);
p_delete(&(*tag)->name);
a_iso2utf8(buf, &(*tag)->name);
a_iso2utf8(&(*tag)->name, buf, len);
if((*tag)->screen != TAG_SCREEN_UNDEF)
widget_invalidate_cache((*tag)->screen, WIDGET_CACHE_TAGS);
return 0;

2
tag.h
View File

@ -29,7 +29,7 @@
#define IS_TILED(client, screen) (client && !client->isfloating && !client->ismax && client_isvisible(client, screen))
/* Contructor, destructor and referencors */
tag_t *tag_new(const char *, layout_t *, double, int, int);
tag_t *tag_new(const char *, ssize_t, layout_t *, double, int, int);
static inline void
tag_delete(tag_t **tag)

View File

@ -136,10 +136,10 @@ luaA_textbox_newindex(lua_State *L)
switch(a_tokenize(attr, len))
{
case A_TK_TEXT:
if((buf = luaL_checkstring(L, 3)))
if((buf = luaL_checklstring(L, 3, &len)))
{
p_delete(&d->text);
a_iso2utf8(buf, &d->text);
a_iso2utf8(&d->text, buf, len);
}
break;
case A_TK_WIDTH: