draw: iso2utf now gets len as arg
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
282dc95042
commit
9b74cdbc0a
17
client.c
17
client.c
|
@ -67,13 +67,14 @@ DO_LUA_EQ(client_t, client, "client")
|
||||||
static bool
|
static bool
|
||||||
client_loadprops(client_t * c, screen_t *screen)
|
client_loadprops(client_t * c, screen_t *screen)
|
||||||
{
|
{
|
||||||
|
ssize_t len;
|
||||||
tag_array_t *tags = &screen->tags;
|
tag_array_t *tags = &screen->tags;
|
||||||
char *prop = NULL;
|
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;
|
return false;
|
||||||
|
|
||||||
if(a_strlen(prop) != tags->len + 2)
|
if(len != tags->len + 2)
|
||||||
{
|
{
|
||||||
/* ignore property if the tag count isn't matching */
|
/* ignore property if the tag count isn't matching */
|
||||||
p_delete(&prop);
|
p_delete(&prop);
|
||||||
|
@ -151,13 +152,14 @@ void
|
||||||
client_updatetitle(client_t *c)
|
client_updatetitle(client_t *c)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
if(!xutil_gettextprop(globalconf.connection, c->win, _NET_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))
|
if(!xutil_gettextprop(globalconf.connection, c->win, WM_NAME, &name, &len))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p_delete(&c->name);
|
p_delete(&c->name);
|
||||||
a_iso2utf8(name, &c->name);
|
a_iso2utf8(&c->name, name, len);
|
||||||
|
|
||||||
/* call hook */
|
/* call hook */
|
||||||
luaA_client_userdata_new(globalconf.L, c);
|
luaA_client_userdata_new(globalconf.L, c);
|
||||||
|
@ -1311,10 +1313,11 @@ luaA_client_name_get(lua_State *L)
|
||||||
static int
|
static int
|
||||||
luaA_client_name_set(lua_State *L)
|
luaA_client_name_set(lua_State *L)
|
||||||
{
|
{
|
||||||
|
size_t len;
|
||||||
client_t **c = luaA_checkudata(L, 1, "client");
|
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);
|
p_delete(&(*c)->name);
|
||||||
a_iso2utf8(name, &(*c)->name);
|
a_iso2utf8(&(*c)->name, name, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,18 +56,22 @@ void draw_parser_data_wipe(draw_parser_data_t *pdata)
|
||||||
draw_image_delete(&pdata->bg_image);
|
draw_image_delete(&pdata->bg_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert text from any charset to UTF-8 using iconv
|
/** Convert text from any charset to UTF-8 using iconv.
|
||||||
* \param iso the ISO string to convert
|
* \param iso The ISO string to convert.
|
||||||
* \return NULL if error, otherwise pointer to the new converted string
|
* \param len The string size.
|
||||||
|
* \return NULL if error, otherwise pointer to the new converted string.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
draw_iso2utf8(const char *iso)
|
draw_iso2utf8(const char *iso, size_t len)
|
||||||
{
|
{
|
||||||
iconv_t iso2utf8;
|
iconv_t iso2utf8;
|
||||||
size_t len, utf8len;
|
size_t utf8len;
|
||||||
char *utf8, *utf8p;
|
char *utf8, *utf8p;
|
||||||
|
|
||||||
if(!(len = a_strlen(iso)))
|
if(len < 0)
|
||||||
|
len = a_strlen(iso);
|
||||||
|
|
||||||
|
if(!len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(!a_strcmp(nl_langinfo(CODESET), "UTF-8"))
|
if(!a_strcmp(nl_langinfo(CODESET), "UTF-8"))
|
||||||
|
|
|
@ -142,18 +142,18 @@ draw_context_delete(draw_context_t **ctx)
|
||||||
font_t *draw_font_new(xcb_connection_t *, int, const char *);
|
font_t *draw_font_new(xcb_connection_t *, int, const char *);
|
||||||
void draw_font_delete(font_t **);
|
void draw_font_delete(font_t **);
|
||||||
|
|
||||||
char * draw_iso2utf8(const char *);
|
char * draw_iso2utf8(const char *, size_t);
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
a_iso2utf8(const char *str, char **res)
|
a_iso2utf8(char **dest, const char *str, ssize_t len)
|
||||||
{
|
{
|
||||||
char *utf8;
|
char *utf8;
|
||||||
if((utf8 = draw_iso2utf8(str)))
|
if((utf8 = draw_iso2utf8(str, len)))
|
||||||
{
|
{
|
||||||
*res = utf8;
|
*dest = utf8;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*res = a_strdup(str);
|
*dest = a_strdup(str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,15 @@
|
||||||
#include "common/atoms.h"
|
#include "common/atoms.h"
|
||||||
|
|
||||||
/** Get the string value of an atom.
|
/** Get the string value of an atom.
|
||||||
* \param conn X connection
|
* \param conn X connection.
|
||||||
* \param w window
|
* \param w Window.
|
||||||
* \param atom the atom
|
* \param atom The atom.
|
||||||
* \param text buffer to fill
|
* \param text Buffer to fill.
|
||||||
* \return true on sucess, falsse on failure
|
* \param len Length of the filled buffer.
|
||||||
|
* \return True on sucess, false on failure.
|
||||||
*/
|
*/
|
||||||
bool
|
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_cookie_t prop_c;
|
||||||
xcb_get_property_reply_t *prop_r;
|
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 */
|
/* use memcpy() because prop_val may not be \0 terminated */
|
||||||
memcpy(*text, prop_val, prop_r->value_len);
|
memcpy(*text, prop_val, prop_r->value_len);
|
||||||
(*text)[prop_r->value_len] = '\0';
|
(*text)[prop_r->value_len] = '\0';
|
||||||
|
*len = prop_r->value_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_delete(&prop_r);
|
p_delete(&prop_r);
|
||||||
|
|
|
@ -96,7 +96,7 @@ typedef struct
|
||||||
|
|
||||||
class_hint_t *xutil_get_class_hint(xcb_connection_t *, xcb_window_t);
|
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 *,
|
void xutil_getlockmask(xcb_connection_t *, xcb_key_symbols_t *,
|
||||||
unsigned int *, unsigned int *, unsigned int *);
|
unsigned int *, unsigned int *, unsigned int *);
|
||||||
|
|
2
lua.c
2
lua.c
|
@ -571,7 +571,7 @@ luaA_parserc(const char* rcfile)
|
||||||
/* Assure there's at least one tag */
|
/* Assure there's at least one tag */
|
||||||
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
||||||
if(!globalconf.screens[screen].tags.len)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
26
tag.c
26
tag.c
|
@ -55,20 +55,21 @@ tag_view(tag_t *tag, bool view)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new tag. Parameters values are checked.
|
/** Create a new tag. Parameters values are checked.
|
||||||
* \param name tag name
|
* \param name Tag name.
|
||||||
* \param layout layout to use
|
* \param len Tag name length.
|
||||||
* \param mwfact master width factor
|
* \param layout Layout to use.
|
||||||
* \param nmaster number of master windows
|
* \param mwfact Master width factor.
|
||||||
* \param ncol number of columns for slaves windows
|
* \param nmaster Number of master windows.
|
||||||
* \return a new tag with all these parameters
|
* \param ncol Number of columns for slaves windows.
|
||||||
|
* \return A new tag with all these parameters.
|
||||||
*/
|
*/
|
||||||
tag_t *
|
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_t *tag;
|
||||||
|
|
||||||
tag = p_new(tag_t, 1);
|
tag = p_new(tag_t, 1);
|
||||||
a_iso2utf8(name, &tag->name);
|
a_iso2utf8(&tag->name, name, len);
|
||||||
tag->layout = layout;
|
tag->layout = layout;
|
||||||
|
|
||||||
/* to avoid error */
|
/* to avoid error */
|
||||||
|
@ -313,6 +314,7 @@ luaA_tag_geti(lua_State *L)
|
||||||
static int
|
static int
|
||||||
luaA_tag_new(lua_State *L)
|
luaA_tag_new(lua_State *L)
|
||||||
{
|
{
|
||||||
|
size_t len;
|
||||||
tag_t *tag;
|
tag_t *tag;
|
||||||
int ncol, nmaster;
|
int ncol, nmaster;
|
||||||
const char *name, *lay;
|
const char *name, *lay;
|
||||||
|
@ -327,11 +329,11 @@ luaA_tag_new(lua_State *L)
|
||||||
mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5);
|
mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5);
|
||||||
ncol = luaA_getopt_number(L, 2, "ncol", 1);
|
ncol = luaA_getopt_number(L, 2, "ncol", 1);
|
||||||
nmaster = luaA_getopt_number(L, 2, "nmaster", 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);
|
layout = name_func_lookup(lay, LayoutList);
|
||||||
|
|
||||||
tag = tag_new(name,
|
tag = tag_new(name, len,
|
||||||
layout,
|
layout,
|
||||||
mwfact, nmaster, ncol);
|
mwfact, nmaster, ncol);
|
||||||
|
|
||||||
|
@ -443,9 +445,9 @@ luaA_tag_newindex(lua_State *L)
|
||||||
switch(a_tokenize(attr, len))
|
switch(a_tokenize(attr, len))
|
||||||
{
|
{
|
||||||
case A_TK_NAME:
|
case A_TK_NAME:
|
||||||
buf = luaL_checkstring(L, 3);
|
buf = luaL_checklstring(L, 3, &len);
|
||||||
p_delete(&(*tag)->name);
|
p_delete(&(*tag)->name);
|
||||||
a_iso2utf8(buf, &(*tag)->name);
|
a_iso2utf8(&(*tag)->name, buf, len);
|
||||||
if((*tag)->screen != TAG_SCREEN_UNDEF)
|
if((*tag)->screen != TAG_SCREEN_UNDEF)
|
||||||
widget_invalidate_cache((*tag)->screen, WIDGET_CACHE_TAGS);
|
widget_invalidate_cache((*tag)->screen, WIDGET_CACHE_TAGS);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
2
tag.h
2
tag.h
|
@ -29,7 +29,7 @@
|
||||||
#define IS_TILED(client, screen) (client && !client->isfloating && !client->ismax && client_isvisible(client, screen))
|
#define IS_TILED(client, screen) (client && !client->isfloating && !client->ismax && client_isvisible(client, screen))
|
||||||
|
|
||||||
/* Contructor, destructor and referencors */
|
/* 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
|
static inline void
|
||||||
tag_delete(tag_t **tag)
|
tag_delete(tag_t **tag)
|
||||||
|
|
|
@ -136,10 +136,10 @@ luaA_textbox_newindex(lua_State *L)
|
||||||
switch(a_tokenize(attr, len))
|
switch(a_tokenize(attr, len))
|
||||||
{
|
{
|
||||||
case A_TK_TEXT:
|
case A_TK_TEXT:
|
||||||
if((buf = luaL_checkstring(L, 3)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
{
|
{
|
||||||
p_delete(&d->text);
|
p_delete(&d->text);
|
||||||
a_iso2utf8(buf, &d->text);
|
a_iso2utf8(&d->text, buf, len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case A_TK_WIDTH:
|
case A_TK_WIDTH:
|
||||||
|
|
Loading…
Reference in New Issue