1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -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 );
/**
* @param sb scrollbar object
*
* Free the resources used by the scrollbar.
*/
void scrollbar_free ( scrollbar *sb );
/**
* @param sb scrollbar object
* @param pos_length new length

View file

@ -73,13 +73,6 @@ textbox* textbox_create ( TextboxFlags flags,
short x, short y, short w, short h,
TextBoxFontType tbft,
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 tbft The style of font to render.

View file

@ -23,7 +23,8 @@ typedef struct _Widget
gboolean enabled;
/** Function prototypes */
void ( *draw )( struct _Widget *tb, cairo_t *draw );
void ( *draw )( struct _Widget *widget, cairo_t *draw );
void ( *free )( struct _Widget *widget );
} Widget;
/** 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 );
/**
* @param tb Handle to the widget
*
* Free the widget and all allocated memory.
*/
void widget_free ( Widget *widget );
/*@}*/
#endif // ROFI_WIDGET_H

View file

@ -30,6 +30,7 @@
#include "settings.h"
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 )
{
@ -39,7 +40,9 @@ scrollbar *scrollbar_create ( short x, short y, short w, short h )
sb->widget.y = y;
sb->widget.w = MAX ( 1, w );
sb->widget.h = MAX ( 1, h );
sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free;
sb->length = 10;
sb->pos = 0;
@ -50,11 +53,10 @@ scrollbar *scrollbar_create ( short x, short y, short w, short h )
return sb;
}
void scrollbar_free ( scrollbar *sb )
static void scrollbar_free ( Widget *widget )
{
if ( sb != NULL ) {
scrollbar *sb = (scrollbar *) widget;
g_free ( sb );
}
}
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max )

View file

@ -38,7 +38,8 @@
#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.
@ -78,6 +79,7 @@ textbox* textbox_create ( TextboxFlags flags, short x, short y, short w, short h
textbox *tb = g_slice_new0 ( textbox );
tb->widget.draw = textbox_draw;
tb->widget.free = textbox_free;
tb->flags = flags;
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
void textbox_free ( textbox *tb )
static void textbox_free ( Widget *widget )
{
if ( tb == NULL ) {
return;
}
textbox *tb = (textbox *) widget;
if ( tb->blink_timeout > 0 ) {
g_source_remove ( tb->blink_timeout );
tb->blink_timeout = 0;

View file

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