Created
March 28, 2016 19:43
-
-
Save nathan-osman/bf3a89df1cd98819f2e7 to your computer and use it in GitHub Desktop.
Lookup an icon by name and size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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