mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-10 15:44:41 -05:00
Indent icon code rework
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
4e3830a519
commit
ac8868f3b1
5 changed files with 58 additions and 56 deletions
|
@ -86,7 +86,7 @@ typedef enum
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
TB_INDICATOR = 1 << 23,
|
TB_INDICATOR = 1 << 23,
|
||||||
TB_ICON = 1<<24,
|
TB_ICON = 1 << 24,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
/**
|
/**
|
||||||
* Flags indicating current state of the textbox.
|
* Flags indicating current state of the textbox.
|
||||||
|
|
|
@ -89,9 +89,9 @@ typedef struct
|
||||||
unsigned int cmd_list_length_actual;
|
unsigned int cmd_list_length_actual;
|
||||||
unsigned int history_length;
|
unsigned int history_length;
|
||||||
// List of disabled entries.
|
// List of disabled entries.
|
||||||
GHashTable *disabled_entries;
|
GHashTable *disabled_entries;
|
||||||
unsigned int disabled_entries_length;
|
unsigned int disabled_entries_length;
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
} DRunModePrivateData;
|
} DRunModePrivateData;
|
||||||
|
|
||||||
struct RegexEvalArg
|
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?)
|
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
|
||||||
// this should be fine running in another thread.
|
// this should be fine running in another thread.
|
||||||
GTimer *t = g_timer_new ();
|
GTimer *t = g_timer_new ();
|
||||||
DRunModePrivateData *pd = (DRunModePrivateData*)data;
|
DRunModePrivateData *pd = (DRunModePrivateData *) data;
|
||||||
for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
|
for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
|
||||||
DRunModeEntry *dr = &( pd->entry_list[i] );
|
DRunModeEntry *dr = &( pd->entry_list[i] );
|
||||||
if ( dr->icon_name == NULL )
|
if ( dr->icon_name == NULL ) {
|
||||||
continue;
|
continue;
|
||||||
gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
|
}
|
||||||
if ( icon_path == NULL ) {
|
gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
|
||||||
g_free(dr->icon_name);
|
if ( icon_path == NULL ) {
|
||||||
dr->icon_name = NULL;
|
g_free ( dr->icon_name );
|
||||||
continue;
|
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 );
|
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" ) )
|
if ( g_str_has_suffix ( icon_path, ".png" ) ) {
|
||||||
dr->icon = cairo_image_surface_create_from_png(icon_path);
|
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 if ( g_str_has_suffix ( icon_path, ".svg" ) ) {
|
||||||
else {
|
dr->icon = cairo_image_surface_create_from_svg ( icon_path, 32 );
|
||||||
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
|
}
|
||||||
char *r = dr->icon_name;
|
else {
|
||||||
dr->icon_name = NULL;
|
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
|
||||||
g_free(r);
|
char *r = dr->icon_name;
|
||||||
}
|
dr->icon_name = NULL;
|
||||||
g_free(icon_path);
|
g_free ( r );
|
||||||
// if ( (i%100) == 99 )
|
}
|
||||||
{
|
g_free ( icon_path );
|
||||||
|
// if ( (i%100) == 99 )
|
||||||
rofi_view_reload();
|
{
|
||||||
}
|
rofi_view_reload ();
|
||||||
}
|
}
|
||||||
rofi_view_reload();
|
}
|
||||||
g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "elapsed: %f\n" , g_timer_elapsed ( t, NULL));
|
rofi_view_reload ();
|
||||||
g_timer_destroy ( t );
|
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 )
|
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 );
|
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw );
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
if ( rmpd->thread ){
|
if ( rmpd->thread ) {
|
||||||
g_thread_join ( rmpd->thread );
|
g_thread_join ( rmpd->thread );
|
||||||
rmpd->thread = NULL;
|
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 );
|
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
|
||||||
g_return_val_if_fail ( pd->entry_list != NULL, NULL );
|
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;
|
return dr->icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -906,7 +906,7 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB
|
||||||
else{
|
else{
|
||||||
list = pango_attr_list_new ();
|
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 );
|
cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
|
||||||
textbox_icon ( t, icon );
|
textbox_icon ( t, icon );
|
||||||
|
|
|
@ -243,7 +243,7 @@ static void listview_recompute_elements ( listview *lv )
|
||||||
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
|
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
|
||||||
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
|
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
|
||||||
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
|
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, "" );
|
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 );
|
widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i] ), listview_element_trigger_action, lv );
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,8 +143,8 @@ textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags f
|
||||||
tb->changed = FALSE;
|
tb->changed = FALSE;
|
||||||
|
|
||||||
tb->layout = pango_layout_new ( p_context );
|
tb->layout = pango_layout_new ( p_context );
|
||||||
if ( (tb->flags&TB_ICON) == TB_ICON) {
|
if ( ( tb->flags & TB_ICON ) == TB_ICON ) {
|
||||||
tb->left_offset = 1.2*textbox_get_estimated_char_height();
|
tb->left_offset = 1.2 * textbox_get_estimated_char_height ();
|
||||||
}
|
}
|
||||||
textbox_font ( tb, tbft );
|
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;
|
tb->widget.trigger_action = textbox_editable_trigger_action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Enabled by default
|
// Enabled by default
|
||||||
tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
|
tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
|
||||||
return tb;
|
return tb;
|
||||||
|
@ -366,7 +365,7 @@ static void textbox_free ( widget *wid )
|
||||||
static void textbox_draw ( widget *wid, cairo_t *draw )
|
static void textbox_draw ( widget *wid, cairo_t *draw )
|
||||||
{
|
{
|
||||||
textbox *tb = (textbox *) wid;
|
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 ) {
|
if ( tb->changed ) {
|
||||||
__textbox_update_pango_text ( tb );
|
__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;
|
int y = top + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
|
||||||
|
|
||||||
// draw Icon
|
// 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 );
|
int iconheight = textbox_get_font_height ( tb );
|
||||||
cairo_save(draw);
|
cairo_save ( draw );
|
||||||
|
|
||||||
/*int iconw = cairo_image_surface_get_width (tb->icon);*/
|
/*int iconw = cairo_image_surface_get_width (tb->icon);*/
|
||||||
int iconh = cairo_image_surface_get_height (tb->icon);
|
int iconh = cairo_image_surface_get_height ( tb->icon );
|
||||||
double scale = (double)iconheight / iconh;
|
double scale = (double) iconheight / iconh;
|
||||||
|
|
||||||
cairo_translate(draw, x, y);
|
cairo_translate ( draw, x, y );
|
||||||
cairo_scale(draw, scale, scale);
|
cairo_scale ( draw, scale, scale );
|
||||||
cairo_set_source_surface(draw, tb->icon, 0,0);
|
cairo_set_source_surface ( draw, tb->icon, 0, 0 );
|
||||||
cairo_paint(draw);
|
cairo_paint ( draw );
|
||||||
cairo_restore(draw);
|
cairo_restore ( draw );
|
||||||
}
|
}
|
||||||
x+=offset;
|
x += offset;
|
||||||
|
|
||||||
if ( tb->flags & TB_RIGHT ) {
|
if ( tb->flags & TB_RIGHT ) {
|
||||||
int line_width = 0;
|
int line_width = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue