1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Make widget_free work on textbox and scrollbar, use widget specific free.

This commit is contained in:
Dave Davenport 2016-09-27 22:38:26 +02:00
parent 89acc7b6ed
commit 0da0587087
8 changed files with 39 additions and 39 deletions

View file

@ -32,13 +32,6 @@ typedef struct _scrollbar
*/ */
scrollbar *scrollbar_create ( short x, short y, short w, short h ); scrollbar *scrollbar_create ( short x, short y, short w, short h );
/**
* @param sb scrollbar object
*
* Free the resources used by the scrollbar.
*/
void scrollbar_free ( scrollbar *sb );
/** /**
* @param sb scrollbar object * @param sb scrollbar object
* @param pos_length new length * @param pos_length new length

View file

@ -73,13 +73,6 @@ textbox* textbox_create ( TextboxFlags flags,
short x, short y, short w, short h, short x, short y, short w, short h,
TextBoxFontType tbft, TextBoxFontType tbft,
const char *text ); const char *text );
/**
* @param tb Handle to the textbox
*
* Free the textbox and all allocated memory.
*/
void textbox_free ( textbox *tb );
/** /**
* @param tb Handle to the textbox * @param tb Handle to the textbox
* @param tbft The style of font to render. * @param tbft The style of font to render.

View file

@ -23,7 +23,8 @@ typedef struct _Widget
gboolean enabled; gboolean enabled;
/** Function prototypes */ /** Function prototypes */
void ( *draw )( struct _Widget *tb, cairo_t *draw ); void ( *draw )( struct _Widget *widget, cairo_t *draw );
void ( *free )( struct _Widget *widget );
} Widget; } Widget;
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */ /** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
@ -61,5 +62,12 @@ void widget_enable ( Widget *widget );
*/ */
void widget_draw ( Widget *widget, cairo_t *d ); void widget_draw ( Widget *widget, cairo_t *d );
/**
* @param tb Handle to the widget
*
* Free the widget and all allocated memory.
*/
void widget_free ( Widget *widget );
/*@}*/ /*@}*/
#endif // ROFI_WIDGET_H #endif // ROFI_WIDGET_H

View file

@ -30,16 +30,19 @@
#include "settings.h" #include "settings.h"
static void scrollbar_draw ( Widget *widget, cairo_t *draw ); static void scrollbar_draw ( Widget *widget, cairo_t *draw );
static void scrollbar_free ( Widget * );
scrollbar *scrollbar_create ( short x, short y, short w, short h ) scrollbar *scrollbar_create ( short x, short y, short w, short h )
{ {
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
sb->widget.x = x; sb->widget.x = x;
sb->widget.y = y; sb->widget.y = y;
sb->widget.w = MAX ( 1, w ); sb->widget.w = MAX ( 1, w );
sb->widget.h = MAX ( 1, h ); sb->widget.h = MAX ( 1, h );
sb->widget.draw = scrollbar_draw; sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free;
sb->length = 10; sb->length = 10;
sb->pos = 0; sb->pos = 0;
@ -50,11 +53,10 @@ scrollbar *scrollbar_create ( short x, short y, short w, short h )
return sb; return sb;
} }
void scrollbar_free ( scrollbar *sb ) static void scrollbar_free ( Widget *widget )
{ {
if ( sb != NULL ) { scrollbar *sb = (scrollbar *) widget;
g_free ( sb ); g_free ( sb );
}
} }
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max ) void scrollbar_set_max_value ( scrollbar *sb, unsigned int max )

View file

@ -38,7 +38,8 @@
#define DOT_OFFSET 15 #define DOT_OFFSET 15
static void textbox_draw ( Widget *tb, cairo_t *draw ); static void textbox_draw ( Widget *, cairo_t * );
static void textbox_free ( Widget * );
/** /**
* Font + font color cache. * Font + font color cache.
@ -78,6 +79,7 @@ textbox* textbox_create ( TextboxFlags flags, short x, short y, short w, short h
textbox *tb = g_slice_new0 ( textbox ); textbox *tb = g_slice_new0 ( textbox );
tb->widget.draw = textbox_draw; tb->widget.draw = textbox_draw;
tb->widget.free = textbox_free;
tb->flags = flags; tb->flags = flags;
tb->widget.x = x; tb->widget.x = x;
@ -243,11 +245,9 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
} }
// will also unmap the window if still displayed // will also unmap the window if still displayed
void textbox_free ( textbox *tb ) static void textbox_free ( Widget *widget )
{ {
if ( tb == NULL ) { textbox *tb = (textbox *) widget;
return;
}
if ( tb->blink_timeout > 0 ) { if ( tb->blink_timeout > 0 ) {
g_source_remove ( tb->blink_timeout ); g_source_remove ( tb->blink_timeout );
tb->blink_timeout = 0; tb->blink_timeout = 0;

View file

@ -323,16 +323,14 @@ void rofi_view_free ( RofiViewState *state )
{ {
// Do this here? // Do this here?
// Wait for final release? // Wait for final release?
textbox_free ( state->text ); widget_free ( WIDGET ( state->text ) );
textbox_free ( state->prompt_tb ); widget_free ( WIDGET ( state->prompt_tb ) );
textbox_free ( state->case_indicator ); widget_free ( WIDGET ( state->case_indicator ) );
scrollbar_free ( state->scrollbar ); widget_free ( WIDGET ( state->scrollbar ) );
if ( state->overlay ) { widget_free ( WIDGET ( state->overlay ) );
textbox_free ( state->overlay );
}
for ( unsigned int i = 0; i < state->max_elements; i++ ) { for ( unsigned int i = 0; i < state->max_elements; i++ ) {
textbox_free ( state->boxes[i] ); widget_free ( WIDGET ( state->boxes[i] ) );
} }
g_free ( state->boxes ); g_free ( state->boxes );
@ -342,7 +340,7 @@ void rofi_view_free ( RofiViewState *state )
// When state is free'ed we should no longer need these. // When state is free'ed we should no longer need these.
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
for ( unsigned int j = 0; j < state->num_modi; j++ ) { for ( unsigned int j = 0; j < state->num_modi; j++ ) {
textbox_free ( state->modi[j] ); widget_free ( WIDGET ( state->modi[j] ) );
state->modi[j] = NULL; state->modi[j] = NULL;
} }
g_free ( state->modi ); g_free ( state->modi );
@ -431,7 +429,7 @@ static void rofi_view_resize ( RofiViewState *state )
state->max_elements = state->max_rows * config.menu_columns; state->max_elements = state->max_rows * config.menu_columns;
// Free boxes no longer needed. // Free boxes no longer needed.
for ( unsigned int i = state->max_elements; i < last_length; i++ ) { for ( unsigned int i = state->max_elements; i < last_length; i++ ) {
textbox_free ( state->boxes[i] ); widget_free ( WIDGET ( state->boxes[i] ) );
} }
// resize array. // resize array.
state->boxes = g_realloc ( state->boxes, state->max_elements * sizeof ( textbox* ) ); state->boxes = g_realloc ( state->boxes, state->max_elements * sizeof ( textbox* ) );

View file

@ -50,3 +50,9 @@ void widget_draw ( Widget *widget, cairo_t *d )
widget->draw ( widget, d ); widget->draw ( widget, d );
} }
} }
void widget_free ( Widget *widget )
{
if ( widget ) {
widget->free ( widget );
}
}

View file

@ -129,6 +129,6 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
TASSERT ( box->widget.x == 12 ); TASSERT ( box->widget.x == 12 );
TASSERT ( box->widget.y == 13 ); TASSERT ( box->widget.y == 13 );
textbox_free ( box ); widget_free ( WIDGET ( box ) );
textbox_cleanup ( ); textbox_cleanup ( );
} }