Fix previous commit.

This commit is contained in:
Dave Davenport 2016-02-23 19:34:48 +01:00
parent faf5c49b8c
commit 87546caa8f
3 changed files with 58 additions and 53 deletions

View File

@ -75,12 +75,11 @@ extern Display *display;
typedef struct typedef struct
{ {
Window *array; Window *array;
void **data; client **data;
int len; int len;
} winlist; } winlist;
winlist *cache_client = NULL; winlist *cache_client = NULL;
winlist *cache_xattr = NULL;
/** /**
* Create a window list, pre-seeded with WINLIST entries. * Create a window list, pre-seeded with WINLIST entries.
@ -92,7 +91,7 @@ static winlist* winlist_new ()
winlist *l = g_malloc ( sizeof ( winlist ) ); winlist *l = g_malloc ( sizeof ( winlist ) );
l->len = 0; l->len = 0;
l->array = g_malloc_n ( WINLIST + 1, sizeof ( Window ) ); l->array = g_malloc_n ( WINLIST + 1, sizeof ( Window ) );
l->data = g_malloc_n ( WINLIST + 1, sizeof ( void* ) ); l->data = g_malloc_n ( WINLIST + 1, sizeof ( client* ) );
return l; return l;
} }
@ -105,11 +104,11 @@ static winlist* winlist_new ()
* *
* @returns 0 if failed, 1 is successful. * @returns 0 if failed, 1 is successful.
*/ */
static int winlist_append ( winlist *l, Window w, void *d ) static int winlist_append ( winlist *l, Window w, client *d )
{ {
if ( l->len > 0 && !( l->len % WINLIST ) ) { if ( l->len > 0 && !( l->len % WINLIST ) ) {
l->array = g_realloc ( l->array, sizeof ( Window ) * ( l->len + WINLIST + 1 ) ); l->array = g_realloc ( l->array, sizeof ( Window ) * ( l->len + WINLIST + 1 ) );
l->data = g_realloc ( l->data, sizeof ( void* ) * ( l->len + WINLIST + 1 ) ); l->data = g_realloc ( l->data, sizeof ( client* ) * ( l->len + WINLIST + 1 ) );
} }
// Make clang-check happy. // Make clang-check happy.
// TODO: make clang-check clear this should never be 0. // TODO: make clang-check clear this should never be 0.
@ -125,7 +124,16 @@ static int winlist_append ( winlist *l, Window w, void *d )
static void winlist_empty ( winlist *l ) static void winlist_empty ( winlist *l )
{ {
while ( l->len > 0 ) { while ( l->len > 0 ) {
g_free ( l->data[--( l->len )] ); client *c = l->data[l->len];
if ( c != NULL ) {
g_free ( c->title );
g_free ( c->class );
g_free ( c->name );
g_free ( c->role );
g_free ( c );
}
l->len--;
} }
} }
@ -174,9 +182,6 @@ static void x11_cache_create ( void )
if ( cache_client == NULL ) { if ( cache_client == NULL ) {
cache_client = winlist_new (); cache_client = winlist_new ();
} }
if ( cache_xattr == NULL ) {
cache_xattr = winlist_new ();
}
} }
/** /**
@ -184,8 +189,6 @@ static void x11_cache_create ( void )
*/ */
static void x11_cache_free ( void ) static void x11_cache_free ( void )
{ {
winlist_free ( cache_xattr );
cache_xattr = NULL;
winlist_free ( cache_client ); winlist_free ( cache_client );
cache_client = NULL; cache_client = NULL;
} }
@ -201,22 +204,13 @@ static void x11_cache_free ( void )
*/ */
static XWindowAttributes* window_get_attributes ( Display *display, Window w ) static XWindowAttributes* window_get_attributes ( Display *display, Window w )
{ {
int idx = winlist_find ( cache_xattr, w );
if ( idx < 0 ) {
XWindowAttributes *cattr = g_malloc ( sizeof ( XWindowAttributes ) ); XWindowAttributes *cattr = g_malloc ( sizeof ( XWindowAttributes ) );
if ( XGetWindowAttributes ( display, w, cattr ) ) { if ( XGetWindowAttributes ( display, w, cattr ) ) {
winlist_append ( cache_xattr, w, cattr );
return cattr; return cattr;
} }
g_free ( cattr );
return NULL; return NULL;
} }
return cache_xattr->data[idx];
}
// _NET_WM_STATE_* // _NET_WM_STATE_*
static int client_has_state ( client *c, Atom state ) static int client_has_state ( client *c, Atom state )
{ {
@ -272,6 +266,7 @@ static client* window_client ( Display *display, Window win )
if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) {
c->title = name; c->title = name;
name = NULL;
} }
else if ( XFetchName ( display, c->window, &name ) ) { else if ( XFetchName ( display, c->window, &name ) ) {
c->title = g_strdup ( name ); c->title = g_strdup ( name );
@ -302,6 +297,7 @@ static client* window_client ( Display *display, Window win )
monitor_dimensions ( display, c->xattr.screen, c->xattr.x, c->xattr.y, &c->monitor ); monitor_dimensions ( display, c->xattr.screen, c->xattr.x, c->xattr.y, &c->monitor );
winlist_append ( cache_client, c->window, c ); winlist_append ( cache_client, c->window, c );
g_free ( attr );
return c; return c;
} }
@ -464,7 +460,8 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
unsigned long wmdesktop; unsigned long wmdesktop;
char desktop[5]; char desktop[5];
desktop[0] = 0; desktop[0] = 0;
size_t len = c->title?strlen ( c->title ):0 + c->class?strlen ( c->class ):0 + classfield + 50; size_t len =
( ( c->title != NULL ) ? strlen ( c->title ) : 0 ) + ( c->class ? strlen ( c->class ) : 0 ) + classfield + 50;
char *line = g_malloc ( len ); char *line = g_malloc ( len );
if ( !pd->config_i3_mode ) { if ( !pd->config_i3_mode ) {
// find client's desktop. // find client's desktop.
@ -579,10 +576,18 @@ static int window_is_not_ascii ( const Mode *sw, unsigned int index )
int idx = winlist_find ( cache_client, ids->array[index] ); int idx = winlist_find ( cache_client, ids->array[index] );
g_assert ( idx >= 0 ); g_assert ( idx >= 0 );
client *c = cache_client->data[idx]; client *c = cache_client->data[idx];
if ( c->role && !g_str_is_ascii(c->role)) return TRUE; if ( c->role && !g_str_is_ascii ( c->role ) ) {
if ( c->class && !g_str_is_ascii(c->class)) return TRUE; return TRUE;
if ( c->title && !g_str_is_ascii(c->title)) return TRUE; }
if ( c->name && !g_str_is_ascii(c->name)) return TRUE; if ( c->class && !g_str_is_ascii ( c->class ) ) {
return TRUE;
}
if ( c->title && !g_str_is_ascii ( c->title ) ) {
return TRUE;
}
if ( c->name && !g_str_is_ascii ( c->name ) ) {
return TRUE;
}
return FALSE; return FALSE;
} }