Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2016 19:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)
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");
// 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(
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");
} 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