Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Created March 28, 2016 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-osman/bf3a89df1cd98819f2e7 to your computer and use it in GitHub Desktop.
Save nathan-osman/bf3a89df1cd98819f2e7 to your computer and use it in GitHub Desktop.
Lookup an icon by name and size
cmake_minimum_required(VERSION 2.8.9)
project(gtktest LANGUAGES C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
add_executable(gtktest main.c)
target_link_libraries(gtktest ${GTK3_LIBRARIES})
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
GtkIconTheme *theme;
// Initialize GTK+
gtk_init(&argc, &argv);
// Load the default icon theme
theme = gtk_icon_theme_get_default();
if (!theme) {
printf("Unable to load default icon theme.\n");
exit(1);
}
// Enter a loop that prompts for an icon name and desired size
// The path of the closest matching icon is then displayed
do {
char name[40];
int size;
GtkIconInfo *info;
printf("Enter an icon name: ");
scanf("%39s", name);
printf("Enter the desired size: ");
scanf("%d", &size);
info = gtk_icon_theme_lookup_icon(
theme,
name,
size,
0
);
if (info) {
const gchar *filename = gtk_icon_info_get_filename(info);
if (filename) {
printf("Filename: %s\n", filename);
} else {
printf("Icon found but no filename.\n");
}
g_object_unref(info);
} else {
printf("Unable to find icon.\n");
}
} while(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment