Indent icon code rework

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Quentin Glidic 2017-05-31 20:21:58 +02:00
parent 4e3830a519
commit ac8868f3b1
No known key found for this signature in database
GPG Key ID: AC203F96E2C34BB7
5 changed files with 58 additions and 56 deletions

View File

@ -86,7 +86,7 @@ typedef enum
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
TB_ICON = 1<<24,
TB_ICON = 1 << 24,
} TextboxFlags;
/**
* Flags indicating current state of the textbox.

View File

@ -89,9 +89,9 @@ typedef struct
unsigned int cmd_list_length_actual;
unsigned int history_length;
// List of disabled entries.
GHashTable *disabled_entries;
unsigned int disabled_entries_length;
GThread *thread;
GHashTable *disabled_entries;
unsigned int disabled_entries_length;
GThread *thread;
} DRunModePrivateData;
struct RegexEvalArg
@ -423,41 +423,44 @@ static void drun_icon_fetch ( gpointer data )
{
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
// this should be fine running in another thread.
GTimer *t = g_timer_new ();
DRunModePrivateData *pd = (DRunModePrivateData*)data;
for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
DRunModeEntry *dr = &( pd->entry_list[i] );
if ( dr->icon_name == NULL )
continue;
gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
if ( icon_path == NULL ) {
g_free(dr->icon_name);
dr->icon_name = NULL;
continue;
}
else
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Icon %s(%d): %s", dr->icon_name, 32, icon_path );
GTimer *t = g_timer_new ();
DRunModePrivateData *pd = (DRunModePrivateData *) data;
for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
DRunModeEntry *dr = &( pd->entry_list[i] );
if ( dr->icon_name == NULL ) {
continue;
}
gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
if ( icon_path == NULL ) {
g_free ( dr->icon_name );
dr->icon_name = NULL;
continue;
}
else{
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Icon %s(%d): %s", dr->icon_name, 32, icon_path );
}
if ( g_str_has_suffix ( icon_path, ".png" ) )
dr->icon = cairo_image_surface_create_from_png(icon_path);
else if ( g_str_has_suffix ( icon_path, ".svg" ) )
dr->icon = cairo_image_surface_create_from_svg(icon_path, 32);
else {
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
char *r = dr->icon_name;
dr->icon_name = NULL;
g_free(r);
}
g_free(icon_path);
// if ( (i%100) == 99 )
{
rofi_view_reload();
}
}
rofi_view_reload();
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "elapsed: %f\n" , g_timer_elapsed ( t, NULL));
g_timer_destroy ( t );
if ( g_str_has_suffix ( icon_path, ".png" ) ) {
dr->icon = cairo_image_surface_create_from_png ( icon_path );
}
else if ( g_str_has_suffix ( icon_path, ".svg" ) ) {
dr->icon = cairo_image_surface_create_from_svg ( icon_path, 32 );
}
else {
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
char *r = dr->icon_name;
dr->icon_name = NULL;
g_free ( r );
}
g_free ( icon_path );
// if ( (i%100) == 99 )
{
rofi_view_reload ();
}
}
rofi_view_reload ();
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "elapsed: %f\n", g_timer_elapsed ( t, NULL ) );
g_timer_destroy ( t );
}
static int drun_mode_init ( Mode *sw )
@ -531,7 +534,7 @@ static void drun_mode_destroy ( Mode *sw )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
if ( rmpd->thread ){
if ( rmpd->thread ) {
g_thread_join ( rmpd->thread );
rmpd->thread = NULL;
}
@ -572,7 +575,7 @@ static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line,
{
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->entry_list != NULL, NULL );
DRunModeEntry *dr = &( pd->entry_list[selected_line] );
DRunModeEntry *dr = &( pd->entry_list[selected_line] );
return dr->icon;
}

View File

@ -906,7 +906,7 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB
else{
list = pango_attr_list_new ();
}
int icon_height = textbox_get_font_height ( t );
int icon_height = textbox_get_font_height ( t );
cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
textbox_icon ( t, icon );

View File

@ -243,7 +243,7 @@ static void listview_recompute_elements ( listview *lv )
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
flags |= ((config.show_icons)? TB_ICON:0);
flags |= ( ( config.show_icons ) ? TB_ICON : 0 );
lv->boxes[i] = textbox_create_full ( WIDGET_TYPE_LISTVIEW_ELEMENT, name, flags, NORMAL, "" );
widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i] ), listview_element_trigger_action, lv );
}

View File

@ -143,8 +143,8 @@ textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags f
tb->changed = FALSE;
tb->layout = pango_layout_new ( p_context );
if ( (tb->flags&TB_ICON) == TB_ICON) {
tb->left_offset = 1.2*textbox_get_estimated_char_height();
if ( ( tb->flags & TB_ICON ) == TB_ICON ) {
tb->left_offset = 1.2 * textbox_get_estimated_char_height ();
}
textbox_font ( tb, tbft );
@ -189,7 +189,6 @@ textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags f
tb->widget.trigger_action = textbox_editable_trigger_action;
}
// Enabled by default
tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
return tb;
@ -366,7 +365,7 @@ static void textbox_free ( widget *wid )
static void textbox_draw ( widget *wid, cairo_t *draw )
{
textbox *tb = (textbox *) wid;
unsigned int offset = tb->left_offset + (( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0);
unsigned int offset = tb->left_offset + ( ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0 );
if ( tb->changed ) {
__textbox_update_pango_text ( tb );
@ -378,21 +377,21 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
int y = top + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
// draw Icon
if ( (tb->flags&TB_ICON) == TB_ICON && tb->icon != NULL ) {
if ( ( tb->flags & TB_ICON ) == TB_ICON && tb->icon != NULL ) {
int iconheight = textbox_get_font_height ( tb );
cairo_save(draw);
cairo_save ( draw );
/*int iconw = cairo_image_surface_get_width (tb->icon);*/
int iconh = cairo_image_surface_get_height (tb->icon);
double scale = (double)iconheight / iconh;
int iconh = cairo_image_surface_get_height ( tb->icon );
double scale = (double) iconheight / iconh;
cairo_translate(draw, x, y);
cairo_scale(draw, scale, scale);
cairo_set_source_surface(draw, tb->icon, 0,0);
cairo_paint(draw);
cairo_restore(draw);
cairo_translate ( draw, x, y );
cairo_scale ( draw, scale, scale );
cairo_set_source_surface ( draw, tb->icon, 0, 0 );
cairo_paint ( draw );
cairo_restore ( draw );
}
x+=offset;
x += offset;
if ( tb->flags & TB_RIGHT ) {
int line_width = 0;