Commit 1b8ae829 authored by Dave Davenport's avatar Dave Davenport

Add icon support.

parent bbf714e4
......@@ -32,6 +32,7 @@
#include <rofi/mode.h>
#include <rofi/helper.h>
#include <rofi/mode-private.h>
#include <rofi/rofi-icon-fetcher.h>
#include <stdint.h>
......@@ -44,9 +45,13 @@ G_MODULE_EXPORT Mode mode;
/**
* The internal data structure holding the private data of the TEST Mode.
*/
typedef struct {
GAppInfo *app;
uint32_t icon_fetch_uid;
} GRunModeEntry;
typedef struct
{
GAppInfo **array;
GRunModeEntry *array;
unsigned int array_length;
} GRUNModePrivateData;
......@@ -62,13 +67,13 @@ static void get_grun ( Mode *sw )
GTimer *t = g_timer_new();
GList *list = g_app_info_get_all ();
pd->array_length = g_list_length(list);
pd->array = g_malloc0_n(pd->array_length,sizeof(GAppInfo*));
pd->array = g_malloc0_n(pd->array_length,sizeof(GRunModeEntry));
printf("elapsed calling g_app_info_get_all: %f\n" , g_timer_elapsed(t,NULL));
int i = 0;
for (GList *iter = g_list_first ( list ); iter; iter = g_list_next(iter)) {
GAppInfo *app = (GAppInfo*)iter->data;
if ( g_app_info_should_show ( app ) ) {
pd->array[i] = app;
pd->array[i].app = app;
i++;
}
else {
......@@ -112,7 +117,7 @@ static ModeMode grun_mode_result ( Mode *sw, int mretv, char **input, unsigned i
} else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK );
} else if ( ( mretv & MENU_OK ) ) {
GAppInfo *app = pd->array[selected_line];
GAppInfo *app = pd->array[selected_line].app;
if ( app ) {
g_app_info_launch ( app, NULL, NULL, NULL );
}
......@@ -128,7 +133,7 @@ static void grun_mode_destroy ( Mode *sw )
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
for ( int i = 0; i < pd->array_length; i++) {
g_object_unref ( pd->array[i] );
g_object_unref ( pd->array[i].app );
}
g_free ( pd->array );
g_free ( pd );
......@@ -142,7 +147,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
if ( get_entry )
{
GAppInfo *app = pd->array[selected_line];
GAppInfo *app = pd->array[selected_line].app;
if ( app ) {
*state |= MARKUP;
const char *description = g_app_info_get_description ( app );
......@@ -159,6 +164,25 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
// Only return the string if requested, otherwise only set state.
return NULL;
}
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{
GRUNModePrivateData *pd = (GRUNModePrivateData*) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->array != NULL, NULL );
if ( pd->array[selected_line].icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( pd->array[selected_line].icon_fetch_uid );
}
GAppInfo *app = pd->array[selected_line].app;
if ( app ) {
GDesktopAppInfo *da = G_DESKTOP_APP_INFO ( app );
if ( da ){
const char *icon = g_desktop_app_info_get_string ( da, "Icon" );
if ( icon ) {
pd->array[selected_line].icon_fetch_uid = rofi_icon_fetcher_query ( icon, height );
}
}
}
return NULL;
}
/**
* @param sw The mode object.
......@@ -172,7 +196,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
static int grun_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
GRUNModePrivateData *pd = (GRUNModePrivateData *) mode_get_private_data ( sw );
GAppInfo *app = pd->array[index];
GAppInfo *app = pd->array[index].app;
int match = 1;
if ( app && tokens ) {
const char *name = g_app_info_get_name ( app );
......@@ -214,6 +238,7 @@ Mode mode =
._get_display_value = _get_display_value,
._get_message = NULL,
._get_completion = NULL,
._get_icon = _get_icon,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment