Skip to content

Instantly share code, notes, and snippets.

@hgn
Last active December 14, 2015 11:08
Show Gist options
  • Save hgn/5076654 to your computer and use it in GitHub Desktop.
Save hgn/5076654 to your computer and use it in GitHub Desktop.
Gtk3 CSS for MenuItems
/* COMPILE WITH: gcc -Wall -o icon3 `pkg-config --cflags --libs gtk+-3.0` a.c */
#include <gtk/gtk.h>
#include <string.h>
static void cb_left_click(GtkStatusIcon * icon, gpointer data)
{
static GtkWidget *window = NULL;
if (window == NULL) {
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Status Icon");
g_signal_connect(window, "delete-event",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(window);
}
}
static void cb_right_click(GtkStatusIcon * icon, int button, int time,
gpointer data)
{
GtkWidget *menu;
menu = gtk_menu_new();
gtk_widget_set_name(GTK_WIDGET(menu), "mymenu");
GtkWidget *item1 = gtk_menu_item_new_with_label("First");
GtkWidget *item2 = gtk_menu_item_new_with_label("Second");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item1);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item2);
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu),
NULL,
NULL, gtk_status_icon_position_menu, icon, button, time);
}
int main(int argc, char *argv[])
{
GtkStatusIcon *icon;
GtkCssProvider *provider;
GdkDisplay *display;
GdkScreen *screen;
gtk_init(&argc, &argv);
icon = gtk_status_icon_new_from_stock(GTK_STOCK_MEDIA_PLAY);
g_signal_connect(G_OBJECT(icon), "activate", G_CALLBACK(cb_left_click),
NULL);
g_signal_connect(G_OBJECT(icon), "popup-menu",
G_CALLBACK(cb_right_click), NULL);
provider = gtk_css_provider_new();
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gsize bytes_written, bytes_read;
const gchar *home = "g.css";
GError *error = 0;
gtk_css_provider_load_from_path(provider,
g_filename_to_utf8(home, strlen(home),
&bytes_read,
&bytes_written,
&error), NULL);
g_object_unref(provider);
gtk_main();
return 0;
}
/*
#mymenu {
background-color: red;
color: green;
font-weight:bold;
}
#mymenu :hover {
background-color: red;
color: blue;
font-weight:bold;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment