diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/window.c | 77 | ||||
-rw-r--r-- | source/view.c | 16 |
2 files changed, 49 insertions, 44 deletions
diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 9e6682a6..01da9e49 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -75,12 +75,11 @@ extern Display *display; typedef struct { Window *array; - void **data; + client **data; int len; } winlist; winlist *cache_client = NULL; -winlist *cache_xattr = NULL; /** * Create a window list, pre-seeded with WINLIST entries. @@ -92,7 +91,7 @@ static winlist* winlist_new () winlist *l = g_malloc ( sizeof ( winlist ) ); l->len = 0; 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; } @@ -105,11 +104,11 @@ static winlist* winlist_new () * * @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 ) ) { 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. // 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 ) { 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 ) { 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 ) { - winlist_free ( cache_xattr ); - cache_xattr = NULL; winlist_free ( cache_client ); cache_client = NULL; } @@ -201,21 +204,12 @@ static void x11_cache_free ( void ) */ 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 ) ); - - if ( XGetWindowAttributes ( display, w, cattr ) ) { - winlist_append ( cache_xattr, w, cattr ); - return cattr; - } + XWindowAttributes *cattr = g_malloc ( sizeof ( XWindowAttributes ) ); - g_free ( cattr ); - return NULL; + if ( XGetWindowAttributes ( display, w, cattr ) ) { + return cattr; } - - return cache_xattr->data[idx]; + return NULL; } // _NET_WM_STATE_* static int client_has_state ( client *c, Atom state ) @@ -272,24 +266,25 @@ static client* window_client ( Display *display, Window win ) if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { c->title = name; + name = NULL; } else if ( XFetchName ( display, c->window, &name ) ) { - c->title = g_strdup(name); + c->title = g_strdup ( name ); XFree ( name ); } name = window_get_text_prop ( display, c->window, XInternAtom ( display, "WM_WINDOW_ROLE", False ) ); if ( name != NULL ) { - c->role = g_strdup(name); + c->role = g_strdup ( name ); XFree ( name ); } XClassHint chint; if ( XGetClassHint ( display, c->window, &chint ) ) { - c->class = g_strdup(chint.res_class); - c->name = g_strdup(chint.res_name); + c->class = g_strdup ( chint.res_class ); + c->name = g_strdup ( chint.res_name ); XFree ( chint.res_class ); XFree ( chint.res_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 ); winlist_append ( cache_client, c->window, c ); + g_free ( attr ); return c; } @@ -425,7 +421,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) && !client_has_window_type ( c, netatoms[_NET_WM_WINDOW_TYPE_DESKTOP] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_PAGER] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_TASKBAR] ) ) { - classfield = MAX ( classfield, (c->class != NULL)?strlen ( c->class ):0 ); + classfield = MAX ( classfield, ( c->class != NULL ) ? strlen ( c->class ) : 0 ); if ( client_has_state ( c, netatoms[_NET_WM_STATE_DEMANDS_ATTENTION] ) ) { c->demands = TRUE; @@ -464,7 +460,8 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) unsigned long wmdesktop; char desktop[5]; 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 ); if ( !pd->config_i3_mode ) { // find client's desktop. @@ -481,10 +478,10 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) snprintf ( desktop, 5, "%d", (int) wmdesktop ); } - snprintf ( line, len, pattern, desktop, c->class?c->class:"", c->title?c->title:"" ); + snprintf ( line, len, pattern, desktop, c->class ? c->class : "", c->title ? c->title : "" ); } else{ - snprintf ( line, len, pattern, c->class?c->class:"", c->title?c->title:"" ); + snprintf ( line, len, pattern, c->class ? c->class : "", c->title ? c->title : "" ); } pd->cmd_list[pd->cmd_list_length++] = line; @@ -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] ); g_assert ( idx >= 0 ); client *c = cache_client->data[idx]; - if ( c->role && !g_str_is_ascii(c->role)) 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; + if ( c->role && !g_str_is_ascii ( c->role ) ) { + 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; } diff --git a/source/view.c b/source/view.c index 4abcafc5..5944bf13 100644 --- a/source/view.c +++ b/source/view.c @@ -690,14 +690,14 @@ static unsigned int rofi_scroll_per_page ( RofiViewState * state ) static unsigned int rofi_scroll_continious ( RofiViewState * state ) { - unsigned int middle = (state->menu_lines - ((state->menu_lines&1) == 0))/ 2; + unsigned int middle = ( state->menu_lines - ( ( state->menu_lines & 1 ) == 0 ) ) / 2; unsigned int offset = 0; if ( state->selected > middle ) { - if ( state->selected < ( state->filtered_lines - (state->menu_lines -middle) ) ) { + if ( state->selected < ( state->filtered_lines - ( state->menu_lines - middle ) ) ) { offset = state->selected - middle; } // Don't go below zero. - else if ( state->filtered_lines > state->menu_lines){ + else if ( state->filtered_lines > state->menu_lines ) { offset = state->filtered_lines - state->menu_lines; } } @@ -738,13 +738,13 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) element_width = ( element_width - ( columns - 1 ) * config.line_margin ) / columns; } - int element_height = state->line_height * config.element_height; - int y_offset = state->top_offset; - int x_offset = state->border; + int element_height = state->line_height * config.element_height; + int y_offset = state->top_offset; + int x_offset = state->border; if ( state->rchanged ) { // Move, resize visible boxes and show them. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ); // Move it around. @@ -764,7 +764,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) } else{ // Only do basic redrawing + highlight of row. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; int fstate = 0; mode_get_display_value ( state->sw, state->line_map[i + offset], &fstate, FALSE ); |