./0000755000004100000410000000000013210416612011237 5ustar www-datawww-data./NEWS0000644000004100000410000000000013210416612011724 0ustar www-datawww-data./INSTALL0000644000004100000410000000000013210416612012256 0ustar www-datawww-data./configure.ac0000644000004100000410000000414113210416612013525 0ustar www-datawww-dataAC_PREREQ([2.69]) AC_INIT([unity-gtk-module], [0.0.0]) AC_REVISION([0.0.0]) AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([1.11 foreign -Wall -Woverride -Wno-portability]) AM_SILENT_RULES([yes]) LT_INIT AC_PROG_CC AC_PROG_LIBTOOL AC_PROG_INSTALL PKG_PROG_PKG_CONFIG([0.26]) AC_ARG_WITH([gtk], [AS_HELP_STRING([--with-gtk=2|3], [GTK+ version [default=3]])], [], [with_gtk=3]) AC_ARG_WITH([gtk-libdir], [AS_HELP_STRING([--with-gtk-libdir=DIR], [GTK+ library directory [default=`pkg-config --variable=libdir gtk+-3.0`]])], [], [with_gtk_libdir=`pkg-config --variable=libdir gtk+-\$with_gtk.0`]) AC_ARG_WITH([gtk-module-dir], [AS_HELP_STRING([--with-gtk-module-dir=DIR], [GTK+ module directory [default=`pkg-config --variable=libdir gtk+-3.0`/gtk-3.0/modules]])], [], [with_gtk_module_dir=$with_gtk_libdir/gtk-$with_gtk.0/modules]) AM_PATH_PYTHON GLIB_GSETTINGS AC_SUBST([GTK_VERSION], [$with_gtk]) AC_SUBST([GTK_MODULE_DIR], [$with_gtk_module_dir]) AM_CONDITIONAL([GTK3], [test GTK$with_gtk = GTK3]) PKG_CHECK_MODULES([GTK], [gtk+-$with_gtk.0]) AC_SUBST([GTK_CFLAGS]) AC_SUBST([GTK_LIBS]) PKG_CHECK_MODULES([X11], [x11]) AC_SUBST([X11_CFLAGS]) AC_SUBST([X11_LIBS]) AC_MSG_CHECKING([for the systemd user units directory]) PKG_CHECK_VAR([SYSTEMD_USERUNITDIR], [systemd], [systemduserunitdir]) AS_IF([test "x$SYSTEMD_USERUNITDIR" = "x"], [ SYSTEMD_USERUNITDIR='/usr/lib/systemd/user' AC_MSG_RESULT([systemd not found, using the default of $SYSTEMD_USERUNITDIR]) ], [ AC_MSG_RESULT([$SYSTEMD_USERUNITDIR]) ]) m4_ifdef([GTK_DOC_CHECK], [ GTK_DOC_CHECK([1.18], [--flavour no-tmpl]) ], [ AM_CONDITIONAL([ENABLE_GTK_DOC], false) ]) AC_CONFIG_FILES([Makefile data/Makefile data/unity-gtk2-parser.pc data/unity-gtk3-parser.pc docs/Makefile docs/reference/Makefile docs/reference/unity-gtk-module/Makefile lib/Makefile src/Makefile tests/Makefile tests/autopilot/Makefile]) AC_OUTPUT ./demos/0000755000004100000410000000000013210416612012346 5ustar www-datawww-data./demos/altmonitor.h0000644000004100000410000000174213210416612014713 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #ifndef __ALT_MONITOR_H__ #define __ALT_MONITOR_H__ #include #define ALT_MONITOR_TYPE (alt_monitor_get_type ()) #define ALT_MONITOR(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ ALT_MONITOR_TYPE, AltMonitor)) #define IS_ALT_MONITOR(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), ALT_MONITOR_TYPE)) typedef struct _AltMonitor AltMonitor; GType alt_monitor_get_type (void) G_GNUC_CONST; AltMonitor * alt_monitor_get_for_display (GdkDisplay *display); gboolean alt_monitor_get_alt_pressed (AltMonitor *monitor); #endif /* __ALT_MONITOR_H__ */ ./demos/test-radio.c0000644000004100000410000000443513210416612014573 0ustar www-datawww-data#include static void handle_window_destroy (GtkWindow *window, gpointer user_data) { gtk_main_quit (); } static void handle_menu_item_activate (GtkMenuItem *menu_item, gpointer user_data) { g_message ("%s: %s", __func__, (const gchar *) user_data); } static void handle_check_menu_item_toggled (GtkCheckMenuItem *check_menu_item, gpointer user_data) { g_message ("%s: %s", __func__, (const gchar *) user_data); } int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *grid; GtkWidget *menu_bar; GtkWidget *menu; GtkWidget *menu_item; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (handle_window_destroy), NULL); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); menu_bar = gtk_menu_bar_new (); gtk_grid_attach (GTK_GRID (grid), menu_bar, 0, 0, 1, 1); menu_item = gtk_menu_item_new_with_label ("File"); gtk_container_add (GTK_CONTAINER (menu_bar), menu_item); menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu); menu_item = gtk_radio_menu_item_new_with_label (NULL, "Radio A"); g_signal_connect (menu_item, "activate", G_CALLBACK (handle_menu_item_activate), "Radio A"); g_signal_connect (menu_item, "toggled", G_CALLBACK (handle_check_menu_item_toggled), "Radio A"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (menu_item), "Radio B"); g_signal_connect (menu_item, "activate", G_CALLBACK (handle_menu_item_activate), "Radio B"); g_signal_connect (menu_item, "toggled", G_CALLBACK (handle_check_menu_item_toggled), "Radio B"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (menu_item), "Radio C"); g_signal_connect (menu_item, "activate", G_CALLBACK (handle_menu_item_activate), "Radio C"); g_signal_connect (menu_item, "toggled", G_CALLBACK (handle_check_menu_item_toggled), "Radio C"); gtk_container_add (GTK_CONTAINER (menu), menu_item); gtk_widget_show_all (window); gtk_main (); return 0; } ./demos/altgrabber.h0000644000004100000410000000343413210416612014630 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #ifndef __ALT_GRABBER_H__ #define __ALT_GRABBER_H__ #include #define ALT_GRABBER_TYPE (alt_grabber_get_type ()) #define ALT_GRABBER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ ALT_GRABBER_TYPE, AltGrabber)) #define IS_ALT_GRABBER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), ALT_GRABBER_TYPE)) typedef struct _AltGrabber AltGrabber; typedef void (* AltGrabberCallback) (AltGrabber *grabber, gunichar c, gpointer user_data); GType alt_grabber_get_type (void) G_GNUC_CONST; AltGrabber * alt_grabber_get_for_screen (GdkScreen *screen); void alt_grabber_clear (AltGrabber *grabber); void alt_grabber_add_unichar (AltGrabber *grabber, gunichar c, AltGrabberCallback callback, gpointer user_data, GDestroyNotify notify); #endif /* __ALT_GRABBER_H__ */ ./demos/unity-gtk-menu-tester.c0000644000004100000410000003731213210416612016721 0ustar www-datawww-data#include enum { ITEM_COLUMN, SHELL_COLUMN, LABEL_COLUMN, TYPE_COLUMN, ACCEL_COLUMN, N_COLUMNS }; static GtkWidget *menu_bar; static GtkWidget *tree_view; static GtkTreeStore *tree_store; static GtkWidget *entry; static GSList *radio_group; static void destroy_window (GtkWindow *window, gpointer user_data) { gtk_main_quit (); } static void update_model (GtkTreeStore *tree_store, GtkTreeIter *iter, GtkMenuShell *menu_shell) { GtkTreeIter parent_iter; GtkTreeIter child_iter; GList *menu_items; if (iter == NULL) { if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tree_store), &parent_iter)) { gtk_tree_store_append (tree_store, &parent_iter, NULL); gtk_tree_store_set (tree_store, &parent_iter, SHELL_COLUMN, menu_shell, LABEL_COLUMN, "Menu bar", -1); } } else parent_iter = *iter; menu_items = g_list_first (gtk_container_get_children (GTK_CONTAINER (menu_shell))); while (menu_items != NULL) { GtkMenuItem *menu_item; GtkWidget *submenu; menu_item = menu_items->data; submenu = gtk_menu_item_get_submenu (menu_item); gtk_tree_store_append (tree_store, &child_iter, &parent_iter); gtk_tree_store_set (tree_store, &child_iter, ITEM_COLUMN, menu_item, SHELL_COLUMN, submenu, LABEL_COLUMN, gtk_menu_item_get_label (menu_item), -1); if (submenu != NULL) update_model (tree_store, &child_iter, GTK_MENU_SHELL (submenu)); menu_items = g_list_next (menu_items); } } static void add_menu_bar (GtkToolButton *button, gpointer user_data) { if (gtk_widget_get_parent (menu_bar) == NULL) { GtkWidget *window; window = gtk_widget_get_toplevel (GTK_WIDGET (button)); if (gtk_widget_is_toplevel (window)) { GtkWidget *grid; GtkTreeIter iter; grid = gtk_bin_get_child (GTK_BIN (window)); gtk_grid_attach (GTK_GRID (grid), menu_bar, 0, 0, 1, 1); gtk_widget_show_all (menu_bar); gtk_tree_store_clear (tree_store); update_model (tree_store, NULL, GTK_MENU_SHELL (menu_bar)); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); } } } static void remove_menu_bar (GtkToolButton *button, gpointer user_data) { GtkWidget *parent = gtk_widget_get_parent (menu_bar); if (parent != NULL) gtk_container_remove (GTK_CONTAINER (parent), menu_bar); gtk_tree_store_clear (tree_store); } static GtkMenuItem * get_menu_item (GtkMenuShell *menu_shell, GtkTreeModel *tree_model, GtkTreeIter *child_iter); static GtkMenuShell * get_menu_shell (GtkMenuShell *menu_shell, GtkTreeModel *tree_model, GtkTreeIter *child_iter) { if (child_iter != NULL) { GtkTreeIter parent_iter; if (gtk_tree_model_iter_parent (tree_model, &parent_iter, child_iter)) return GTK_MENU_SHELL (gtk_menu_item_get_submenu (get_menu_item (menu_shell, tree_model, child_iter))); else return menu_shell; } return NULL; } static GtkMenuItem * get_menu_item (GtkMenuShell *menu_shell, GtkTreeModel *tree_model, GtkTreeIter *child_iter) { GtkTreeIter parent_iter; if (child_iter != NULL && gtk_tree_model_iter_parent (tree_model, &parent_iter, child_iter)) { GtkTreeIter item_iter; GList *children; menu_shell = get_menu_shell (menu_shell, tree_model, &parent_iter); item_iter = *child_iter; children = gtk_container_get_children (GTK_CONTAINER (menu_shell)); while (gtk_tree_model_iter_previous (tree_model, &item_iter)) children = g_list_next (children); return children->data; } return NULL; } static GtkWidget * create_menu_item (void) { GSList *toggle_buttons; GtkToggleButton *toggle_button; guint toggle_index; const gchar *mnemonic; GtkWidget *menu_item; toggle_buttons = radio_group; for (toggle_index = 0; toggle_buttons != NULL; toggle_index++) { toggle_button = toggle_buttons->data; if (gtk_toggle_button_get_active (toggle_button)) break; toggle_buttons = g_slist_next (toggle_buttons); } if (toggle_buttons == NULL) return NULL; mnemonic = gtk_entry_get_text (GTK_ENTRY (entry)); switch (toggle_index) { case 3: menu_item = gtk_check_menu_item_new_with_mnemonic (mnemonic); break; case 2: /* XXX */ menu_item = gtk_radio_menu_item_new_with_mnemonic (NULL, mnemonic); break; case 1: menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE); break; case 0: menu_item = gtk_separator_menu_item_new (); break; default: menu_item = gtk_menu_item_new_with_mnemonic (mnemonic); break; } return menu_item; } static void add_menu_item (GtkToolButton *button, gpointer user_data) { GtkTreeSelection *selection; GtkTreeIter tree_iter; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); if (selection != NULL && gtk_tree_selection_get_selected (selection, NULL, &tree_iter)) { GtkWidget *submenu; submenu = GTK_WIDGET (get_menu_shell (GTK_MENU_SHELL (menu_bar), GTK_TREE_MODEL (tree_store), &tree_iter)); if (submenu == NULL) { GtkMenuItem *menu_item; menu_item = get_menu_item (GTK_MENU_SHELL (menu_bar), GTK_TREE_MODEL (tree_store), &tree_iter); if (menu_item != NULL) { submenu = gtk_menu_new (); gtk_menu_item_set_submenu (menu_item, submenu); } } if (submenu != NULL) { GtkWidget *menu_item; menu_item = create_menu_item (); gtk_container_add (GTK_CONTAINER (submenu), menu_item); gtk_widget_show (menu_item); gtk_tree_store_clear (tree_store); update_model (tree_store, NULL, GTK_MENU_SHELL (menu_bar)); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); } } } static void insert_menu_item (GtkToolButton *button, gpointer user_data) { GtkTreeSelection *selection; GtkTreeModel *tree_model; GtkTreeIter parent_iter; GtkTreeIter child_iter; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); tree_model = GTK_TREE_MODEL (tree_store); if (selection != NULL && gtk_tree_selection_get_selected (selection, NULL, &child_iter) && gtk_tree_model_iter_parent (tree_model, &parent_iter, &child_iter)) { GtkMenuShell *shell; GtkWidget *menu_item; guint shell_index; shell = get_menu_shell (GTK_MENU_SHELL (menu_bar), tree_model, &parent_iter); for (shell_index = 0; gtk_tree_model_iter_previous (tree_model, &child_iter); shell_index++); menu_item = create_menu_item (); gtk_menu_shell_insert (shell, menu_item, shell_index); gtk_widget_show (menu_item); gtk_tree_store_clear (tree_store); update_model (tree_store, NULL, GTK_MENU_SHELL (menu_bar)); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); } } static void remove_menu_item (GtkToolButton *button, gpointer user_data) { GtkTreeSelection *selection; GtkTreeIter tree_iter; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); if (selection != NULL && gtk_tree_selection_get_selected (selection, NULL, &tree_iter)) { GtkWidget *menu_item; menu_item = GTK_WIDGET (get_menu_item (GTK_MENU_SHELL (menu_bar), GTK_TREE_MODEL (tree_store), &tree_iter)); if (menu_item != NULL) { GtkWidget *parent; parent = gtk_widget_get_parent (menu_item); if (parent != NULL) { gtk_container_remove (GTK_CONTAINER (parent), menu_item); gtk_tree_store_clear (tree_store); update_model (tree_store, NULL, GTK_MENU_SHELL (menu_bar)); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); } } } } int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *outer_grid; GtkWidget *menu; GtkWidget *menu_item; GtkWidget *paned; GtkWidget *inner_grid; GtkCellRenderer *cell_renderer; GtkTreeViewColumn *tree_view_column; GtkWidget *toolbar; GtkToolItem *tool_item; GtkWidget *label; GtkWidget *radio_button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); g_signal_connect (window, "destroy", G_CALLBACK (destroy_window), NULL); outer_grid = gtk_grid_new (); menu_bar = g_object_ref (gtk_menu_bar_new ()); menu_item = gtk_menu_item_new_with_label ("File"); menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu); gtk_container_add (GTK_CONTAINER (menu_bar), menu_item); menu_item = gtk_menu_item_new_with_label ("New"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Open"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Save"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_separator_menu_item_new (); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Recent File 1"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Recent File 2"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Recent File 3"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Recent File 4"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_separator_menu_item_new (); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Quit"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Edit"); menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu); gtk_container_add (GTK_CONTAINER (menu_bar), menu_item); menu_item = gtk_menu_item_new_with_label ("Select All"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_separator_menu_item_new (); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Cut"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Copy"); gtk_container_add (GTK_CONTAINER (menu), menu_item); menu_item = gtk_menu_item_new_with_label ("Paste"); gtk_container_add (GTK_CONTAINER (menu), menu_item); paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); inner_grid = gtk_grid_new (); tree_store = gtk_tree_store_new (N_COLUMNS, GTK_TYPE_MENU_ITEM, GTK_TYPE_MENU_SHELL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); tree_view = g_object_ref (gtk_tree_view_new_with_model (GTK_TREE_MODEL (tree_store))); cell_renderer = gtk_cell_renderer_text_new (); tree_view_column = gtk_tree_view_column_new_with_attributes ("Label", cell_renderer, "text", LABEL_COLUMN, NULL); gtk_tree_view_column_set_min_width (tree_view_column, 160); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), tree_view_column); cell_renderer = gtk_cell_renderer_text_new (); tree_view_column = gtk_tree_view_column_new_with_attributes ("Type", cell_renderer, "text", TYPE_COLUMN, NULL); gtk_tree_view_column_set_min_width (tree_view_column, 80); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), tree_view_column); cell_renderer = gtk_cell_renderer_text_new (); tree_view_column = gtk_tree_view_column_new_with_attributes ("Accel", cell_renderer, "text", ACCEL_COLUMN, NULL); gtk_tree_view_column_set_min_width (tree_view_column, 80); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), tree_view_column); gtk_widget_set_vexpand (tree_view, TRUE); gtk_grid_attach (GTK_GRID (inner_grid), tree_view, 0, 0, 1, 1); toolbar = gtk_toolbar_new (); gtk_widget_set_hexpand (toolbar, TRUE); gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); tool_item = gtk_tool_button_new_from_stock (GTK_STOCK_YES); g_signal_connect (tool_item, "clicked", G_CALLBACK (add_menu_bar), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_item, 0); tool_item = gtk_tool_button_new_from_stock (GTK_STOCK_NO); g_signal_connect (tool_item, "clicked", G_CALLBACK (remove_menu_bar), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_item, 1); tool_item = gtk_tool_button_new_from_stock (GTK_STOCK_NEW); g_signal_connect (tool_item, "clicked", G_CALLBACK (add_menu_item), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_item, 2); tool_item = gtk_tool_button_new_from_stock (GTK_STOCK_ADD); g_signal_connect (tool_item, "clicked", G_CALLBACK (insert_menu_item), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_item, 3); tool_item = gtk_tool_button_new_from_stock (GTK_STOCK_REMOVE); g_signal_connect (tool_item, "clicked", G_CALLBACK (remove_menu_item), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_item, 4); gtk_grid_attach (GTK_GRID (inner_grid), toolbar, 0, 1, 1, 1); gtk_paned_add1 (GTK_PANED (paned), inner_grid); inner_grid = gtk_grid_new (); label = gtk_label_new_with_mnemonic ("_Label:"); entry = g_object_ref (gtk_entry_new ()); gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); gtk_grid_attach (GTK_GRID (inner_grid), label, 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (inner_grid), entry, 1, 0, 1, 1); label = gtk_label_new ("Type:"); gtk_grid_attach (GTK_GRID (inner_grid), label, 0, 1, 1, 1); radio_button = gtk_radio_button_new_with_mnemonic (NULL, "_Normal"); gtk_grid_attach (GTK_GRID (inner_grid), radio_button, 1, 1, 1, 1); radio_button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (radio_button), "_Check"); gtk_grid_attach (GTK_GRID (inner_grid), radio_button, 1, 2, 1, 1); radio_button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (radio_button), "_Radio"); gtk_grid_attach (GTK_GRID (inner_grid), radio_button, 1, 3, 1, 1); radio_button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (radio_button), "_Image"); gtk_grid_attach (GTK_GRID (inner_grid), radio_button, 1, 4, 1, 1); radio_button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (radio_button), "_Separator"); radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); gtk_grid_attach (GTK_GRID (inner_grid), radio_button, 1, 5, 1, 1); gtk_paned_add2 (GTK_PANED (paned), inner_grid); gtk_grid_attach (GTK_GRID (outer_grid), paned, 0, 1, 1, 1); gtk_container_add (GTK_CONTAINER (window), outer_grid); gtk_widget_show_all (window); gtk_main (); g_object_unref (entry); g_object_unref (tree_view); g_object_unref (menu_bar); return 0; } ./demos/altgrabber.c0000644000004100000410000002003313210416612014615 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #include "altgrabber.h" #include #include /** * SECTION:altgrabber * @title: AltGrabber * @short_description: a utility class to make grabs for keys * * #AltGrabber is a small utility class for establishing global grabs on * particular Alt+letter key sequences. Letters to grab are added with * alt_grabber_add_unichar() and the list of grabs is cleared with * alt_grabber_clear(). * * When one of the grabbed key sequences is used, the "activated" signal * is emitted. **/ /** * AltGrabber: * * AltGrabber is an opaque structure type with no public fields. **/ typedef GObjectClass AltGrabberClass; struct _AltGrabber { GObject parent_instance; GHashTable *grabs; guint finish_clear_id; GdkScreen *screen; GdkKeymap *keymap; GdkWindow *root; }; typedef struct { gunichar c; gint ref_count; AltGrabberCallback callback; gpointer user_data; GDestroyNotify notify; } KeyGrab; static GSList *alt_grabbers; G_DEFINE_TYPE (AltGrabber, alt_grabber, G_TYPE_OBJECT); static GdkFilterReturn alt_grabber_event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) { XAnyEvent *any_event = (XAnyEvent *) xevent; AltGrabber *grabber = user_data; if (any_event->type == KeyPress) { XKeyEvent *key_event = (XKeyEvent *) any_event; guint keycode = key_event->keycode; GSList *grabs; grabs = g_hash_table_lookup (grabber->grabs, GINT_TO_POINTER (keycode)); while (grabs) { KeyGrab *grab = grabs->data; (* grab->callback) (grabber, grab->c, grab->user_data); grabs = grabs->next; } } return GDK_FILTER_CONTINUE; } static gboolean alt_grabber_finish_clear (gpointer data) { AltGrabber *grabber = data; GHashTableIter iter; gpointer key, value; Display *dpy; Window root; dpy = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (grabber->screen)); root = GDK_WINDOW_XID (grabber->root); gdk_error_trap_push (); g_hash_table_iter_init (&iter, grabber->grabs); while (g_hash_table_iter_next (&iter, &key, &value)) if (value == NULL) { guint keycode = GPOINTER_TO_INT (key); guint mask; for (mask = 0; mask < 0x100; mask++) if ((mask & (ShiftMask | ControlMask | Mod1Mask)) == Mod1Mask) XUngrabKey (dpy, keycode, mask, root); g_hash_table_iter_remove (&iter); } gdk_error_trap_pop_ignored (); grabber->finish_clear_id = 0; return FALSE; } static void alt_grabber_finalize (GObject *object) { AltGrabber *grabber = ALT_GRABBER (object); alt_grabber_clear (grabber); if (grabber->finish_clear_id != 0) { g_source_remove (grabber->finish_clear_id); alt_grabber_finish_clear (grabber); } alt_grabbers = g_slist_remove (alt_grabbers, grabber); g_assert (g_hash_table_size (grabber->grabs) == 0); g_hash_table_unref (grabber->grabs); g_object_unref (grabber->screen); g_object_unref (grabber->keymap); gdk_window_remove_filter (grabber->root, alt_grabber_event_filter, grabber); g_object_unref (grabber->root); G_OBJECT_CLASS (alt_grabber_parent_class) ->finalize (object); } static void alt_grabber_init (AltGrabber *grabber) { grabber->grabs = g_hash_table_new (NULL, NULL); } static void alt_grabber_class_init (AltGrabberClass *class) { class->finalize = alt_grabber_finalize; } static AltGrabber * alt_grabber_new (GdkScreen *screen) { AltGrabber *grabber; GdkDisplay *display; display = gdk_screen_get_display (screen); grabber = g_object_new (ALT_GRABBER_TYPE, NULL); grabber->keymap = g_object_ref (gdk_keymap_get_for_display (display)); grabber->root = g_object_ref (gdk_screen_get_root_window (screen)); grabber->screen = g_object_ref (screen); gdk_window_add_filter (grabber->root, alt_grabber_event_filter, grabber); /* We can not safely reverse this... */ XSelectInput (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (grabber->root), KeyPressMask); return grabber; } /** * alt_grabber_get_for_screen: * @screen: a #GdkScreen * * Gets the #AltGrabber for @screen. * * If an #AltGrabber already exists for @screen, it is returned. * Otherwise, one is created. * * In any case, you get a reference. Use g_object_unref() when you're * done. * * Returns: (transfer full): the #AltGrabber for @screen **/ AltGrabber * alt_grabber_get_for_screen (GdkScreen *screen) { AltGrabber *grabber; GSList *node; for (node = alt_grabbers; node; node = node->next) { grabber = node->data; if (grabber->screen == screen) return g_object_ref (grabber); } grabber = alt_grabber_new (screen); alt_grabbers = g_slist_prepend (alt_grabbers, grabber); return grabber; } /** * alt_grabber_clear: * @grabber: an #AltGrabber * * Clears all grab requests on @grabber. **/ void alt_grabber_clear (AltGrabber *grabber) { gboolean clear_needed = FALSE; GHashTableIter iter; gpointer value; g_hash_table_iter_init (&iter, grabber->grabs); while (g_hash_table_iter_next (&iter, NULL, &value)) { GSList *list = value; while (list) { KeyGrab *grab = list->data; if (0 == --grab->ref_count) { if (grab->notify) (* grab->notify) (grab->user_data); g_slice_free (KeyGrab, grab); } list = g_slist_remove_link (list, list); } g_hash_table_iter_replace (&iter, NULL); clear_needed = TRUE; } if (clear_needed && grabber->finish_clear_id == 0) grabber->finish_clear_id = g_idle_add (alt_grabber_finish_clear, grabber); } /** * alt_grabber_add_unichar: * @grabber: an #AltGrabber * @c: the #gunichar to grab * @callback: the callback to call when the character is pressed * @user_data: the user_data parameter for @callback * @notify: the #GDestroyNotift for @user_data, or %NULL * * Adds a new grab to @grabber. * * When Alt+@c is pressed, @callback will be called with @user_data. * * The effect of this call can be reversed with alt_grabber_clear(). **/ void alt_grabber_add_unichar (AltGrabber *grabber, gunichar c, AltGrabberCallback callback, gpointer user_data, GDestroyNotify notify) { GdkKeymapKey *codes; gint n_codes; guint keyval; keyval = gdk_unicode_to_keyval (c); keyval = gdk_keyval_to_lower (keyval); if (keyval != 0 && gdk_keymap_get_entries_for_keyval (grabber->keymap, keyval, &codes, &n_codes)) { KeyGrab *grab; Display *dpy; Window root; gint i; g_assert (n_codes > 0); grab = g_slice_new (KeyGrab); grab->c = c; grab->ref_count = n_codes; grab->callback = callback; grab->user_data = user_data; grab->notify = notify; dpy = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (grabber->screen)); root = GDK_WINDOW_XID (grabber->root); gdk_error_trap_push (); for (i = 0; i < n_codes; i++) { gpointer list = NULL; if (!g_hash_table_lookup_extended (grabber->grabs, GINT_TO_POINTER (codes[i].keycode), NULL, &list)) { guint mask; for (mask = 0; mask < 0x100; mask++) if ((mask & (ShiftMask | ControlMask | Mod1Mask)) == Mod1Mask) XGrabKey (dpy, codes[i].keycode, mask, root, False, GrabModeAsync, GrabModeAsync); } list = g_slist_prepend (list, grab); g_hash_table_insert (grabber->grabs, GINT_TO_POINTER (codes[i].keycode), list); } if (gdk_error_trap_pop ()) { gchar outbuf[8]; gint s; s = g_unichar_to_utf8 (c, outbuf); outbuf[s] = '\0'; g_warning ("failed to acquire (some) keyboard grabs for '%s'", outbuf); } } else { if (notify) (* notify) (user_data); } } ./demos/altmonitor.c0000644000004100000410000001370413210416612014707 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #include "altmonitor.h" #include #include /** * SECTION:altmonitor * @title: AltMonitor * @short_description: a utility class to monitor the Alt key * * #AltMonitor is a small utility class for monitoring the state of the * 'Alt' key on a particular #GdkDisplay. It depends on a functioning * Xkb extension on the display. * * #AltMonitor has one property: "alt-pressed". * * To watch for changes, connect to the GObject::notify signal for the * "alt-pressed" property. Query the current state with * alt_monitor_get_alt_pressed(). **/ /** * AltMonitor: * * AltMonitor is an opaque structure type with no public fields. **/ typedef GObjectClass AltMonitorClass; struct _AltMonitor { GObject parent_instance; GdkDisplay *display; gint xkb_event_type; gboolean is_pressed; }; static GParamSpec *alt_pressed_param; static GSList *alt_monitors; G_DEFINE_TYPE (AltMonitor, alt_monitor, G_TYPE_OBJECT); static GdkFilterReturn alt_monitor_event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) { XAnyEvent *any_event = (XAnyEvent *) xevent; AltMonitor *monitor = NULL; /* This is all a little bit silly. GDK has no per-GdkDisplay event * filters, so we have no chance to attach the user-data per-display. * * Instead, we have to scan our list for the correct display. * * In practice, this is going to be quite fast... :) */ { GSList *node; for (node = alt_monitors; node; node = node->next) { AltMonitor *item = node->data; if (GDK_DISPLAY_XDISPLAY (item->display) == any_event->display) { monitor = item; break; } } } if (monitor != NULL && monitor->xkb_event_type != 0 && monitor->xkb_event_type == any_event->type) { XkbAnyEvent *xkb_event = (XkbAnyEvent *) any_event; if (xkb_event->xkb_type == XkbStateNotify) { XkbStateNotifyEvent *sn_event = (XkbStateNotifyEvent *) xkb_event; gboolean is_pressed; is_pressed = (sn_event->mods & Mod1Mask) != 0; if (is_pressed != monitor->is_pressed) { monitor->is_pressed = is_pressed; g_object_notify_by_pspec (G_OBJECT (monitor), alt_pressed_param); } } } return GDK_FILTER_CONTINUE; } static void alt_monitor_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { AltMonitor *monitor = ALT_MONITOR (object); g_assert (pspec == alt_pressed_param); g_value_set_boolean (value, monitor->is_pressed); } static void alt_monitor_finalize (GObject *object) { AltMonitor *monitor = ALT_MONITOR (object); alt_monitors = g_slist_remove (alt_monitors, monitor); g_object_unref (monitor->display); /* If this is the last one, remove the filter */ if (alt_monitors == NULL) gdk_window_remove_filter (NULL, alt_monitor_event_filter, NULL); G_OBJECT_CLASS (alt_monitor_parent_class) ->finalize (object); } static void alt_monitor_init (AltMonitor *monitor) { } static void alt_monitor_class_init (AltMonitorClass *class) { class->finalize = alt_monitor_finalize; class->get_property = alt_monitor_get_property; alt_pressed_param = g_param_spec_boolean ("alt-pressed", "alt key pressed", "TRUE if 'Alt' is currently pressed", TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (class, 1, alt_pressed_param); } static gint alt_monitor_get_xkb_event_type (Display *dpy) { gint major = XkbMajorVersion; gint minor = XkbMinorVersion; gint event_type; if (!XkbLibraryVersion (&major, &minor)) return 0; if (!XkbQueryExtension (dpy, NULL, &event_type, NULL, &major, &minor)) return 0; return event_type; } static AltMonitor * alt_monitor_new (GdkDisplay *display) { AltMonitor *monitor; Display *dpy; dpy = GDK_DISPLAY_XDISPLAY (display); monitor = g_object_new (ALT_MONITOR_TYPE, NULL); monitor->display = g_object_ref (display); monitor->xkb_event_type = alt_monitor_get_xkb_event_type (dpy); if (monitor->xkb_event_type) { XkbStateRec state; /* Since we have no way of knowing if someone else comes along * after us and requests XkbModifierStateMask, we can never undo * this... */ XkbSelectEventDetails (dpy, XkbUseCoreKbd, XkbStateNotify, XkbModifierStateMask, XkbModifierStateMask); /* Get the initial state in case 'Alt' was pressed to start. */ XkbGetState (dpy, XkbUseCoreKbd, &state); monitor->is_pressed = (state.mods & Mod1Mask) != 0; } return monitor; } /** * alt_monitor_get_for_display: * @display: a #GdkDisplay * * Gets the #AltMonitor for @display. * * If an #AltMonitor already exists for @display, it is returned. * Otherwise, one is created. * * In any case, you get a reference. Use g_object_unref() when you're * done. * * Returns: (transfer full): the #AltMonitor for @display **/ AltMonitor * alt_monitor_get_for_display (GdkDisplay *display) { AltMonitor *monitor; GSList *node; for (node = alt_monitors; node; node = node->next) { monitor = node->data; if (monitor->display == display) return g_object_ref (monitor); } monitor = alt_monitor_new (display); /* if this is the first one, add the filter */ if (alt_monitors == NULL) gdk_window_add_filter (NULL, alt_monitor_event_filter, NULL); alt_monitors = g_slist_prepend (alt_monitors, monitor); return monitor; } /** * alt_monitor_get_alt_pressed: * @monitor: an #AltMonitor * * Checks if the 'Alt' key is pressed. * * Returns: %TRUE if 'Alt' is currently being held down **/ gboolean alt_monitor_get_alt_pressed (AltMonitor *monitor) { g_return_val_if_fail (IS_ALT_MONITOR (monitor), FALSE); return monitor->is_pressed; } ./demos/menusource.c0000644000004100000410000002450613210416612014706 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #include "menusource.h" #define WNCK_I_KNOW_THIS_IS_UNSTABLE #include #include #include #include "../src/enums.h" enum { XPROP_BUS_NAME, XPROP_OBJECT_PATH, N_XPROP }; typedef GObjectClass MenuSourceClass; struct _MenuSource { GObject parent_instance; GDBusConnection *session; GdkScreen *gdk_screen; WnckScreen *screen; gulong active_window_changed_id; WnckWindow *active_window; gulong state_changed_id; GdkWindow *gdk_window; gboolean maximised; gchar *properties[N_XPROP]; GActionGroup *actions; GMenuModel *menu; }; G_DEFINE_TYPE(MenuSource, menu_source, G_TYPE_OBJECT) static GParamSpec *menu_source_menu_param; static GSettings *menubar_mode_settings; static MenuBarMode menubar_mode; static GSList *menu_sources; static Atom atoms[N_XPROP]; static void menu_source_update (MenuSource *menu_source) { g_print ("msu\n"); if (menu_source->menu) g_object_unref (menu_source->menu); if (menu_source->properties[0] && menu_source->properties[1]) { GDBusMenuModel *proxy; proxy = g_dbus_menu_model_get (menu_source->session, menu_source->properties[0], menu_source->properties[1]); menu_source->menu = G_MENU_MODEL (proxy); } else menu_source->menu = NULL; g_object_notify_by_pspec (G_OBJECT (menu_source), menu_source_menu_param); } static void menubar_mode_changed (GSettings *settings, const gchar *key, gpointer user_data) { MenuBarMode new_mode; new_mode = g_settings_get_enum (settings, "menubar-mode"); if (new_mode != menubar_mode) { GSList *node; menubar_mode = new_mode; for (node = menu_sources; node; node = node->next) menu_source_update (node->data); } } gboolean menu_source_is_maximised (WnckWindowState state) { WnckWindowState maximised_mask; maximised_mask = WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY | WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY; return (state & maximised_mask) == maximised_mask; } static void menu_source_state_changed (WnckWindow *window, WnckWindowState changed_mask, WnckWindowState new_state, gpointer user_data) { MenuSource *menu_source = user_data; gboolean maximised; maximised = menu_source_is_maximised (new_state); if (maximised != menu_source->maximised) { menu_source->maximised = maximised; if (menubar_mode == MENU_BAR_MODE_WHEN_MAXIMIZED) menu_source_update (menu_source); } } static gboolean menu_source_update_window_property (MenuSource *menu_source, gint atom_index, gboolean deleted) { gchar *value = NULL; gboolean changed; g_print ("uwp %d\n", deleted); if (!deleted) { gchar *name = "UTF8_STRING"; unsigned long bytes_after_return; unsigned long nitems_return; unsigned char *prop_return; gint actual_format_return; Atom actual_type_return; Atom utf8_atom; XInternAtoms (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &name, 1, False, &utf8_atom); if (XGetWindowProperty (GDK_SCREEN_XDISPLAY (menu_source->gdk_screen), gdk_x11_window_get_xid (menu_source->gdk_window), atoms[atom_index], 0, 1024, False, utf8_atom, &actual_type_return, &actual_format_return, &nitems_return, &bytes_after_return, &prop_return) == Success) { if (actual_format_return == 8 && bytes_after_return == 0) { g_print ("I see %s\n", value); value = g_strndup ((gchar *) prop_return, nitems_return); } XFree (prop_return); } } changed = g_strcmp0 (menu_source->properties[atom_index], value) != 0; g_free (menu_source->properties[atom_index]); menu_source->properties[atom_index] = value; return changed; } static GdkFilterReturn window_filter_func (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) { MenuSource *menu_source = user_data; XAnyEvent *any = (XAnyEvent *) xevent; if (any->type == PropertyNotify) { XPropertyEvent *property = (XPropertyEvent *) xevent; gint i; for (i = 0; i < N_XPROP; i++) { if (property->atom != atoms[i]) continue; if (menu_source_update_window_property (menu_source, i, property->state == PropertyDelete)) menu_source_update (menu_source); break; } } return GDK_FILTER_CONTINUE; } static void menu_source_active_window_changed (WnckScreen *screen, WnckWindow *previously_active_window, gpointer user_data) { MenuSource *menu_source = user_data; WnckWindow *active_window; active_window = wnck_screen_get_active_window (screen); if (active_window != menu_source->active_window) { gboolean changed = FALSE; gint i; if (menu_source->active_window != NULL) { gdk_window_remove_filter (menu_source->gdk_window, window_filter_func, menu_source); g_object_unref (menu_source->gdk_window); menu_source->gdk_window = NULL; g_signal_handler_disconnect (menu_source->active_window, menu_source->state_changed_id); g_object_unref (menu_source->active_window); menu_source->active_window = NULL; } if (active_window != NULL) { Window xid; menu_source->active_window = g_object_ref (active_window); menu_source->state_changed_id = g_signal_connect (active_window, "state-changed", G_CALLBACK (menu_source_state_changed), menu_source); menu_source->maximised = menu_source_is_maximised (wnck_window_get_state (active_window)); xid = wnck_window_get_xid (active_window); menu_source->gdk_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), xid); gdk_window_add_filter (menu_source->gdk_window, window_filter_func, menu_source); } for (i = 0; i < N_XPROP; i++) changed |= menu_source_update_window_property (menu_source, i, active_window == NULL); if (changed) menu_source_update (menu_source); } } static void menu_source_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { MenuSource *menu_source = MENU_SOURCE (object); g_assert (prop_id == 1); g_value_set_object (value, menu_source->menu); } static void menu_source_finalize (GObject *object) { MenuSource *menu_source = MENU_SOURCE (object); menu_sources = g_slist_remove (menu_sources, menu_source); /* If this is the last one, stop watching GSettings */ if (menu_sources == NULL) { /* no need to remove the signal handler -- this is the only ref */ g_object_unref (menubar_mode_settings); menubar_mode_settings = NULL; } if (menu_source->screen != NULL) { g_signal_handler_disconnect (menu_source->screen, menu_source->active_window_changed_id); g_object_unref (menu_source->screen); } if (menu_source->active_window != NULL) { g_signal_handler_disconnect (menu_source->active_window, menu_source->state_changed_id); g_object_unref (menu_source->active_window); } g_object_unref (menu_source->gdk_screen); g_object_unref (menu_source->screen); G_OBJECT_CLASS (menu_source_parent_class) ->finalize (object); } static void menu_source_init (MenuSource *menu_source) { } static void menu_source_class_init (MenuSourceClass *class) { class->get_property = menu_source_get_property; class->finalize = menu_source_finalize; menu_source_menu_param = g_param_spec_object ("menu", "active menu", "the GMenuModel for the active window", G_TYPE_MENU_MODEL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (class, 1, menu_source_menu_param); } static MenuSource * menu_source_new (GdkScreen *screen) { MenuSource *menu_source; menu_source = g_object_new (MENU_SOURCE_TYPE, NULL); menu_source->session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); menu_source->gdk_screen = g_object_ref (screen); menu_source->screen = g_object_ref (wnck_screen_get (gdk_screen_get_number (screen))); g_signal_connect (menu_source->screen, "active-window-changed", G_CALLBACK (menu_source_active_window_changed), menu_source); menu_source_active_window_changed (menu_source->screen, NULL, menu_source); return menu_source; } GMenuModel * menu_source_get_menu (MenuSource *menu_source) { g_return_val_if_fail (IS_MENU_SOURCE (menu_source), NULL); return menu_source->menu; } MenuSource * menu_source_get_for_screen (GdkScreen *screen) { MenuSource *menu_source; GSList *node; for (node = menu_sources; node; node = node->next) { menu_source = node->data; if (menu_source->gdk_screen == screen) return g_object_ref (menu_source); } g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); g_return_val_if_fail (gdk_screen_get_display (screen) == gdk_display_get_default (), NULL); menu_source = menu_source_new (screen); /* if this is the first one, create the GSettings */ if (menu_sources == NULL) { //menubar_mode_settings = g_settings_new ("com.canonical.Unity.GtkModule"); //g_signal_connect (menubar_mode_settings, "changed::menubar-mode", G_CALLBACK (menubar_mode_changed), NULL); //menubar_mode = g_settings_get_enum (menubar_mode_settings, "menubar-mode"); } menubar_mode = MENU_BAR_MODE_GLOBAL; menu_sources = g_slist_prepend (menu_sources, menu_source); if (atoms[0] == 0) { const gchar * const names[] = { "_GTK_UNIQUE_BUS_NAME", "_GTK_MENUBAR_OBJECT_PATH" }; G_STATIC_ASSERT(G_N_ELEMENTS(names) == G_N_ELEMENTS(atoms)); XInternAtoms (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), (char **) names, 2, False, atoms); } return menu_source; } ./demos/black.c0000644000004100000410000002155513210416612013576 0ustar www-datawww-data/* black.c generated by valac 0.18.0.28-4dffb, the Vala compiler * generated from black.vala, do not modify */ #include #include #include #include #include #include #include #include #define TYPE_BLACK_BOX (black_box_get_type ()) #define BLACK_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BLACK_BOX, BlackBox)) #define BLACK_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BLACK_BOX, BlackBoxClass)) #define IS_BLACK_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BLACK_BOX)) #define IS_BLACK_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BLACK_BOX)) #define BLACK_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BLACK_BOX, BlackBoxClass)) typedef struct _BlackBox BlackBox; typedef struct _BlackBoxClass BlackBoxClass; typedef struct _BlackBoxPrivate BlackBoxPrivate; #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) struct _BlackBox { GtkBox parent_instance; BlackBoxPrivate * priv; }; struct _BlackBoxClass { GtkBoxClass parent_class; }; static gpointer black_box_parent_class = NULL; GType black_box_get_type (void) G_GNUC_CONST; enum { BLACK_BOX_DUMMY_PROPERTY }; static gboolean black_box_real_draw (GtkWidget* base, cairo_t* cr); BlackBox* black_box_new (void); BlackBox* black_box_construct (GType object_type); void _vala_main (gchar** args, int args_length1); static gboolean black_box_real_draw (GtkWidget* base, cairo_t* cr) { BlackBox * self; gboolean result = FALSE; cairo_t* _tmp0_; cairo_t* _tmp1_; self = (BlackBox*) base; g_return_val_if_fail (cr != NULL, FALSE); _tmp0_ = cr; cairo_set_source_rgb (_tmp0_, 0.0, 0.0, 0.0); _tmp1_ = cr; cairo_paint (_tmp1_); result = FALSE; return result; } BlackBox* black_box_construct (GType object_type) { BlackBox * self = NULL; self = (BlackBox*) g_object_new (object_type, NULL); return self; } BlackBox* black_box_new (void) { return black_box_construct (TYPE_BLACK_BOX); } static void black_box_class_init (BlackBoxClass * klass) { black_box_parent_class = g_type_class_peek_parent (klass); GTK_WIDGET_CLASS (klass)->draw = black_box_real_draw; } static void black_box_instance_init (BlackBox * self) { } GType black_box_get_type (void) { static volatile gsize black_box_type_id__volatile = 0; if (g_once_init_enter (&black_box_type_id__volatile)) { static const GTypeInfo g_define_type_info = { sizeof (BlackBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) black_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BlackBox), 0, (GInstanceInitFunc) black_box_instance_init, NULL }; GType black_box_type_id; black_box_type_id = g_type_register_static (GTK_TYPE_BOX, "BlackBox", &g_define_type_info, 0); g_once_init_leave (&black_box_type_id__volatile, black_box_type_id); } return black_box_type_id__volatile; } void _vala_main (gchar** args, int args_length1) { GdkColor red = {0}; GdkColor _tmp0_ = {0}; GtkWindow* _tmp1_; GtkWindow* window; GdkColor _tmp2_; GtkVBox* _tmp3_; GtkVBox* box; GtkMenuBar* _tmp4_; GtkMenuBar* menubar; GtkMenuItem* _tmp5_; GtkMenuItem* file_item; GtkMenu* _tmp6_; GtkMenu* file; GtkMenuItem* _tmp7_; GtkMenuItem* _tmp8_; GtkMenuItem* _tmp9_; GtkMenuItem* _tmp10_; GtkMenuItem* _tmp11_; GtkMenuItem* _tmp12_; GtkMenuItem* _tmp13_; GtkMenuItem* _tmp14_; GtkMenuItem* _tmp15_; GtkMenuItem* edit_item; GtkMenu* _tmp16_; GtkMenu* edit; GtkMenuItem* _tmp17_; GtkMenuItem* _tmp18_; GtkMenuItem* _tmp19_; GtkMenuItem* _tmp20_; GtkMenuItem* _tmp21_; GtkMenuItem* _tmp22_; GtkMenuItem* _tmp23_; GtkMenuItem* view_item; GtkMenu* _tmp24_; GtkMenu* view; GtkCheckMenuItem* _tmp25_; GtkCheckMenuItem* _tmp26_; GtkMenuItem* _tmp27_; GtkMenuItem* help_item; GtkMenu* _tmp28_; GtkMenu* help; GtkMenuItem* _tmp29_; GtkMenuItem* _tmp30_; GtkMenuItem* _tmp31_; GtkMenuItem* _tmp32_; BlackBox* _tmp33_; BlackBox* _tmp34_; gtk_init (&args_length1, &args); gdk_color_parse ("red", &_tmp0_); red = _tmp0_; g_bus_own_name_with_closures (G_BUS_TYPE_SESSION, "demo.black", 0, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, NULL))); _tmp1_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL); g_object_ref_sink (_tmp1_); window = _tmp1_; gtk_window_set_default_size (window, 400, 300); _tmp2_ = red; gtk_widget_modify_bg ((GtkWidget*) window, GTK_STATE_NORMAL, &_tmp2_); _tmp3_ = (GtkVBox*) gtk_vbox_new (FALSE, 0); g_object_ref_sink (_tmp3_); box = _tmp3_; gtk_container_add ((GtkContainer*) window, (GtkWidget*) box); _tmp4_ = (GtkMenuBar*) gtk_menu_bar_new (); g_object_ref_sink (_tmp4_); menubar = _tmp4_; _tmp5_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("File"); g_object_ref_sink (_tmp5_); file_item = _tmp5_; _tmp6_ = (GtkMenu*) gtk_menu_new (); g_object_ref_sink (_tmp6_); file = _tmp6_; gtk_menu_item_set_submenu (file_item, (GtkWidget*) file); gtk_container_add ((GtkContainer*) menubar, (GtkWidget*) file_item); _tmp7_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("New"); g_object_ref_sink (_tmp7_); _tmp8_ = _tmp7_; gtk_container_add ((GtkContainer*) file, (GtkWidget*) _tmp8_); _g_object_unref0 (_tmp8_); _tmp9_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Open"); g_object_ref_sink (_tmp9_); _tmp10_ = _tmp9_; gtk_container_add ((GtkContainer*) file, (GtkWidget*) _tmp10_); _g_object_unref0 (_tmp10_); _tmp11_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Save"); g_object_ref_sink (_tmp11_); _tmp12_ = _tmp11_; gtk_container_add ((GtkContainer*) file, (GtkWidget*) _tmp12_); _g_object_unref0 (_tmp12_); _tmp13_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Quit"); g_object_ref_sink (_tmp13_); _tmp14_ = _tmp13_; gtk_container_add ((GtkContainer*) file, (GtkWidget*) _tmp14_); _g_object_unref0 (_tmp14_); _tmp15_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Edit"); g_object_ref_sink (_tmp15_); edit_item = _tmp15_; _tmp16_ = (GtkMenu*) gtk_menu_new (); g_object_ref_sink (_tmp16_); edit = _tmp16_; gtk_menu_item_set_submenu (edit_item, (GtkWidget*) edit); gtk_container_add ((GtkContainer*) menubar, (GtkWidget*) edit_item); _tmp17_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Cut"); g_object_ref_sink (_tmp17_); _tmp18_ = _tmp17_; gtk_container_add ((GtkContainer*) edit, (GtkWidget*) _tmp18_); _g_object_unref0 (_tmp18_); _tmp19_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Copy"); g_object_ref_sink (_tmp19_); _tmp20_ = _tmp19_; gtk_container_add ((GtkContainer*) edit, (GtkWidget*) _tmp20_); _g_object_unref0 (_tmp20_); _tmp21_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Paste"); g_object_ref_sink (_tmp21_); _tmp22_ = _tmp21_; gtk_container_add ((GtkContainer*) edit, (GtkWidget*) _tmp22_); _g_object_unref0 (_tmp22_); _tmp23_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("View"); g_object_ref_sink (_tmp23_); view_item = _tmp23_; _tmp24_ = (GtkMenu*) gtk_menu_new (); g_object_ref_sink (_tmp24_); view = _tmp24_; gtk_menu_item_set_submenu (view_item, (GtkWidget*) view); gtk_container_add ((GtkContainer*) menubar, (GtkWidget*) view_item); _tmp25_ = (GtkCheckMenuItem*) gtk_check_menu_item_new_with_label ("Fullscreen"); g_object_ref_sink (_tmp25_); _tmp26_ = _tmp25_; gtk_container_add ((GtkContainer*) view, (GtkWidget*) _tmp26_); _g_object_unref0 (_tmp26_); _tmp27_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Help"); g_object_ref_sink (_tmp27_); help_item = _tmp27_; _tmp28_ = (GtkMenu*) gtk_menu_new (); g_object_ref_sink (_tmp28_); help = _tmp28_; gtk_menu_item_set_submenu (help_item, (GtkWidget*) help); gtk_container_add ((GtkContainer*) menubar, (GtkWidget*) help_item); _tmp29_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Contents"); g_object_ref_sink (_tmp29_); _tmp30_ = _tmp29_; gtk_container_add ((GtkContainer*) help, (GtkWidget*) _tmp30_); _g_object_unref0 (_tmp30_); _tmp31_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("About"); g_object_ref_sink (_tmp31_); _tmp32_ = _tmp31_; gtk_container_add ((GtkContainer*) help, (GtkWidget*) _tmp32_); _g_object_unref0 (_tmp32_); gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) menubar, FALSE, FALSE, (guint) 0); _tmp33_ = black_box_new (); g_object_ref_sink (_tmp33_); _tmp34_ = _tmp33_; gtk_box_pack_start ((GtkBox*) box, (GtkWidget*) _tmp34_, TRUE, TRUE, (guint) 0); _g_object_unref0 (_tmp34_); gtk_widget_show_all ((GtkWidget*) window); gtk_main (); _g_object_unref0 (help); _g_object_unref0 (help_item); _g_object_unref0 (view); _g_object_unref0 (view_item); _g_object_unref0 (edit); _g_object_unref0 (edit_item); _g_object_unref0 (file); _g_object_unref0 (file_item); _g_object_unref0 (menubar); _g_object_unref0 (box); _g_object_unref0 (window); } int main (int argc, char ** argv) { g_type_init (); _vala_main (argv, argc); return 0; } ./demos/client.c0000644000004100000410000000333513210416612013774 0ustar www-datawww-data#include #include "menusource.h" #include "altgrabber.h" #include "altmonitor.h" #if 0 static void items_changed (GMenuModel *menu, gint position, gint removed, gint added, gpointer user_data) { g_print ("\n change"); g_menu_markup_print_stderr (menu); g_print ("\n"); } #endif static void menu_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { static GActionGroup *actions; GtkMenuBar *bar = user_data; GMenuModel *menu; if (!actions) actions = G_ACTION_GROUP (g_simple_action_group_new ()); menu = menu_source_get_menu (MENU_SOURCE (object)); g_print ("\n"); if (menu) { // g_signal_connect (menu, "items-changed", G_CALLBACK (items_changed), NULL); gtk_menu_shell_bind_model (GTK_MENU_SHELL (bar), G_MENU_MODEL (menu), 0, 0); } else { GMenu *empty; empty = g_menu_new(); gtk_menu_shell_bind_model (GTK_MENU_SHELL (bar), G_MENU_MODEL (empty), 0, 0); g_print ("[no menu]\n"); } g_print ("\n"); } int main (int argc, char **argv) { MenuSource *source; GMenuModel *m; GtkWidget *bar; GtkWidget *win; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); bar = gtk_menu_bar_new (); gtk_window_set_accept_focus (GTK_WINDOW (win), FALSE); gtk_container_add (GTK_CONTAINER (win), bar); gtk_window_set_default_size (GTK_WINDOW (win), 800, 200); gtk_widget_show_all (win); source = menu_source_get_for_screen (gdk_screen_get_default ()); g_signal_connect (source, "notify::menu", G_CALLBACK (menu_changed), bar); menu_changed (G_OBJECT (source), NULL, bar); gtk_main (); return 0; } ./demos/menusource.h0000644000004100000410000000174513210416612014713 0ustar www-datawww-data/* * Copyright © 2011 Canonical Limited * * All rights reserved. * * Author: Ryan Lortie */ #ifndef __MENU_SOURCE_H__ #define __MENU_SOURCE_H__ #include #define MENU_SOURCE_TYPE (menu_source_get_type ()) #define MENU_SOURCE(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ MENU_SOURCE_TYPE, MenuSource)) #define IS_MENU_SOURCE(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), MENU_SOURCE_TYPE)) typedef struct _MenuSource MenuSource; GType menu_source_get_type (void) G_GNUC_CONST; MenuSource * menu_source_get_for_screen (GdkScreen *screen); GMenuModel * menu_source_get_menu (MenuSource *menu_source); #endif /* __MENU_SOURCE_H__ */ ./demos/black.vala0000644000004100000410000000335413210416612014274 0ustar www-datawww-dataclass BlackBox : Gtk.Box { protected override bool draw (Cairo.Context cr) { cr.set_source_rgb (0.0, 0.0, 0.0); cr.paint (); return false; } } void main (string[] args) { Gtk.init (ref args); Gdk.Color red; Gdk.Color.parse ("red", out red); Bus.own_name (BusType.SESSION, "demo.black", 0, null, null, null); var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL); window.set_default_size (400, 300); window.modify_bg (Gtk.StateType.NORMAL, red); var box = new Gtk.VBox (false, 0); window.add (box); var menubar = new Gtk.MenuBar (); var file_item = new Gtk.MenuItem.with_label ("File"); var file = new Gtk.Menu (); file_item.set_submenu (file); menubar.add (file_item); file.add (new Gtk.MenuItem.with_label ("New")); file.add (new Gtk.MenuItem.with_label ("Open")); file.add (new Gtk.MenuItem.with_label ("Save")); file.add (new Gtk.MenuItem.with_label ("Quit")); var edit_item = new Gtk.MenuItem.with_label ("Edit"); var edit = new Gtk.Menu (); edit_item.set_submenu (edit); menubar.add (edit_item); edit.add (new Gtk.MenuItem.with_label ("Cut")); edit.add (new Gtk.MenuItem.with_label ("Copy")); edit.add (new Gtk.MenuItem.with_label ("Paste")); var view_item = new Gtk.MenuItem.with_label ("View"); var view = new Gtk.Menu (); view_item.set_submenu (view); menubar.add (view_item); view.add (new Gtk.CheckMenuItem.with_label ("Fullscreen")); var help_item = new Gtk.MenuItem.with_label ("Help"); var help = new Gtk.Menu (); help_item.set_submenu (help); menubar.add (help_item); help.add (new Gtk.MenuItem.with_label ("Contents")); help.add (new Gtk.MenuItem.with_label ("About")); box.pack_start (menubar, false, false, 0); box.pack_start (new BlackBox (), true, true, 0); window.show_all (); Gtk.main (); } ./demos/Makefile.am0000644000004100000410000000110013210416612014372 0ustar www-datawww-datanoinst_PROGRAMS = client black unity-gtk-menu-tester test-radio hello AM_CFLAGS = $(libwnck_CFLAGS) $(gtk_CFLAGS) $(gtkapp_CFLAGS) -Wall client_LDADD = $(libwnck_LIBS) $(gtk_LIBS) $(gtkapp_LIBS) -lX11 client_SOURCES = \ altgrabber.h \ altgrabber.c \ altmonitor.h \ altmonitor.c \ menusource.h \ menusource.c \ client.c black_CFLAGS = $(gtk_CFLAGS) black_VALAFLAGS = --pkg gtk+-3.0 black_LDADD = $(gtk_LIBS) black_SOURCES = black.vala unity_gtk_menu_tester_SOURCES = \ unity-gtk-menu-tester.c test_radio_SOURCES = \ test-radio.c hello_SOURCES = \ hello.c ./demos/hello.c0000644000004100000410000001170213210416612013616 0ustar www-datawww-data#include static GtkWidget *menubar; static GtkWidget *submenuitem; static void destroy_window (GtkWindow *window, gpointer user_data) { gtk_main_quit (); } static void realize_menubar (GtkButton *button, gpointer user_data) { if (gtk_widget_get_parent (menubar) == NULL) { GtkWidget *window; GtkWidget *grid; window = gtk_widget_get_toplevel (GTK_WIDGET (button)); grid = gtk_bin_get_child (GTK_BIN (window)); gtk_grid_insert_row (GTK_GRID (grid), 0); gtk_grid_attach (GTK_GRID (grid), menubar, 0, 0, 1, 1); } } static void unrealize_menubar (GtkButton *button, gpointer user_data) { if (gtk_widget_get_parent (menubar) != NULL) { GtkWidget *window; GtkWidget *grid; window = gtk_widget_get_toplevel (GTK_WIDGET (button)); grid = gtk_bin_get_child (GTK_BIN (window)); gtk_container_remove (GTK_CONTAINER (grid), menubar); } } static void add_submenu (GtkButton *button, gpointer user_data) { if (gtk_widget_get_parent (submenuitem) == NULL) { if (submenuitem == NULL) { GtkWidget *submenu; GtkWidget *item; submenuitem = gtk_menu_item_new_with_label ("Extras"); submenu = gtk_menu_new (); item = gtk_menu_item_new_with_label ("Extra 1"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Extra 2"); gtk_container_add (GTK_CONTAINER (submenu), item); gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu); } gtk_container_add (GTK_CONTAINER (menubar), submenuitem); } } static void remove_submenu (GtkButton *button, gpointer user_data) { if (submenuitem != NULL && gtk_widget_get_parent (submenuitem) != NULL) gtk_container_remove (GTK_CONTAINER (menubar), submenuitem); } int main (int argc, char **argv) { GtkWidget *window; GtkWidget *grid; GtkWidget *submenu; GtkWidget *item; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (destroy_window), NULL); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); menubar = gtk_menu_bar_new (); gtk_grid_attach (GTK_GRID (grid), menubar, 0, 0, 1, 1); g_object_ref (menubar); item = gtk_menu_item_new_with_label ("File"); submenu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); gtk_container_add (GTK_CONTAINER (menubar), item); item = gtk_menu_item_new_with_label ("New"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Open"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Save"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_separator_menu_item_new (); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_radio_menu_item_new_with_label (NULL, "Item 1"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (item), "Item 2"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (item), "Item 3"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_radio_menu_item_new_with_label_from_widget (GTK_RADIO_MENU_ITEM (item), "Item 4"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_separator_menu_item_new (); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Quit"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Edit"); submenu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); gtk_container_add (GTK_CONTAINER (menubar), item); item = gtk_menu_item_new_with_label ("Copy"); gtk_container_add (GTK_CONTAINER (submenu), item); item = gtk_menu_item_new_with_label ("Paste"); gtk_container_add (GTK_CONTAINER (submenu), item); button = gtk_button_new_with_label ("Realize menubar"); g_signal_connect (button, "clicked", G_CALLBACK (realize_menubar), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1); button = gtk_button_new_with_label ("Unrealize menubar"); g_signal_connect (button, "clicked", G_CALLBACK (unrealize_menubar), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 1, 1); button = gtk_button_new_with_label ("Add submenu"); g_signal_connect (button, "clicked", G_CALLBACK (add_submenu), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 1, 1); button = gtk_button_new_with_label ("Remove submenu"); g_signal_connect (button, "clicked", G_CALLBACK (remove_submenu), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 1, 1); gtk_widget_show_all (window); gtk_main (); g_object_unref (menubar); return 0; } ./README0000644000004100000410000000000013210416612012105 0ustar www-datawww-data./gtk-doc.make0000644000004100000410000001726713210416612013443 0ustar www-datawww-data# -*- mode: makefile -*- #################################### # Everything below here is generic # #################################### if GTK_DOC_USE_LIBTOOL GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) $(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(GTKDOC_DEPS_LIBS) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) GTKDOC_RUN = $(LIBTOOL) --mode=execute else GTKDOC_CC = $(CC) $(INCLUDES) $(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) GTKDOC_LD = $(CC) $(GTKDOC_DEPS_LIBS) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) GTKDOC_RUN = endif # We set GPATH here; this gives us semantics for GNU make # which are more like other make's VPATH, when it comes to # whether a source that is a target of one rule is then # searched for in VPATH/GPATH. # GPATH = $(srcdir) TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) SETUP_FILES = \ $(content_files) \ $(DOC_MAIN_SGML_FILE) \ $(DOC_MODULE)-sections.txt \ $(DOC_MODULE)-overrides.txt EXTRA_DIST = \ $(HTML_IMAGES) \ $(SETUP_FILES) DOC_STAMPS=setup-build.stamp scan-build.stamp sgml-build.stamp \ html-build.stamp pdf-build.stamp \ sgml.stamp html.stamp pdf.stamp SCANOBJ_FILES = \ $(DOC_MODULE).args \ $(DOC_MODULE).hierarchy \ $(DOC_MODULE).interfaces \ $(DOC_MODULE).prerequisites \ $(DOC_MODULE).signals REPORT_FILES = \ $(DOC_MODULE)-undocumented.txt \ $(DOC_MODULE)-undeclared.txt \ $(DOC_MODULE)-unused.txt CLEANFILES = $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS) if ENABLE_GTK_DOC if GTK_DOC_BUILD_HTML HTML_BUILD_STAMP=html-build.stamp else HTML_BUILD_STAMP= endif if GTK_DOC_BUILD_PDF PDF_BUILD_STAMP=pdf-build.stamp else PDF_BUILD_STAMP= endif all-local: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP) else all-local: endif docs: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP) $(REPORT_FILES): sgml-build.stamp #### setup #### setup-build.stamp: -@if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \ echo ' DOC Preparing build'; \ files=`echo $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types`; \ if test "x$$files" != "x" ; then \ for file in $$files ; do \ test -f $(abs_srcdir)/$$file && \ cp -pu $(abs_srcdir)/$$file $(abs_builddir)/ || true; \ done; \ fi; \ fi @touch setup-build.stamp #### scan #### scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB) @echo ' DOC Scanning header files' @_source_dir='' ; \ for i in $(DOC_SOURCE_DIR) ; do \ _source_dir="$${_source_dir} --source-dir=$$i" ; \ done ; \ gtkdoc-scan --module=$(DOC_MODULE) --ignore-headers="$(IGNORE_HFILES)" $${_source_dir} $(SCAN_OPTIONS) $(EXTRA_HFILES) @if grep -l '^..*$$' $(DOC_MODULE).types > /dev/null 2>&1 ; then \ echo " DOC Introspecting gobjects"; \ scanobj_options=""; \ gtkdoc-scangobj 2>&1 --help | grep >/dev/null "\-\-verbose"; \ if test "$(?)" = "0"; then \ if test "x$(V)" = "x1"; then \ scanobj_options="--verbose"; \ fi; \ fi; \ CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" \ gtkdoc-scangobj $(SCANGOBJ_OPTIONS) $$scanobj_options --module=$(DOC_MODULE); \ else \ for i in $(SCANOBJ_FILES) ; do \ test -f $$i || touch $$i ; \ done \ fi @touch scan-build.stamp $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt: scan-build.stamp @true #### xml #### sgml-build.stamp: setup-build.stamp $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt $(expand_content_files) @echo ' DOC Building XML' @_source_dir='' ; \ for i in $(DOC_SOURCE_DIR) ; do \ _source_dir="$${_source_dir} --source-dir=$$i" ; \ done ; \ gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $${_source_dir} $(MKDB_OPTIONS) @touch sgml-build.stamp sgml.stamp: sgml-build.stamp @true #### html #### html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) @echo ' DOC Building HTML' @rm -rf html @mkdir html @mkhtml_options=""; \ gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-verbose"; \ if test "$(?)" = "0"; then \ if test "x$(V)" = "x1"; then \ mkhtml_options="$$mkhtml_options --verbose"; \ fi; \ fi; \ gtkdoc-mkhtml 2>&1 --help | grep >/dev/null "\-\-path"; \ if test "$(?)" = "0"; then \ mkhtml_options="$$mkhtml_options --path=\"$(abs_srcdir)\""; \ fi; \ cd html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) -@test "x$(HTML_IMAGES)" = "x" || \ for file in $(HTML_IMAGES) ; do \ if test -f $(abs_srcdir)/$$file ; then \ cp $(abs_srcdir)/$$file $(abs_builddir)/html; \ fi; \ if test -f $(abs_builddir)/$$file ; then \ cp $(abs_builddir)/$$file $(abs_builddir)/html; \ fi; \ done; @echo ' DOC Fixing cross-references' @gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS) @touch html-build.stamp #### pdf #### pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files) @echo ' DOC Building PDF' @rm -f $(DOC_MODULE).pdf @mkpdf_options=""; \ gtkdoc-mkpdf 2>&1 --help | grep >/dev/null "\-\-verbose"; \ if test "$(?)" = "0"; then \ if test "x$(V)" = "x1"; then \ mkpdf_options="$$mkpdf_options --verbose"; \ fi; \ fi; \ if test "x$(HTML_IMAGES)" != "x"; then \ for img in $(HTML_IMAGES); do \ part=`dirname $$img`; \ echo $$mkpdf_options | grep >/dev/null "\-\-imgdir=$$part "; \ if test $$? != 0; then \ mkpdf_options="$$mkpdf_options --imgdir=$$part"; \ fi; \ done; \ fi; \ gtkdoc-mkpdf --path="$(abs_srcdir)" $$mkpdf_options $(DOC_MODULE) $(DOC_MAIN_SGML_FILE) $(MKPDF_OPTIONS) @touch pdf-build.stamp ############## clean-local: @rm -f *~ *.bak @rm -rf .libs distclean-local: @rm -rf xml html $(REPORT_FILES) $(DOC_MODULE).pdf \ $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt @if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \ rm -f $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types; \ fi maintainer-clean-local: clean @rm -rf xml html install-data-local: @installfiles=`echo $(builddir)/html/*`; \ if test "$$installfiles" = '$(builddir)/html/*'; \ then echo 1>&2 'Nothing to install' ; \ else \ if test -n "$(DOC_MODULE_VERSION)"; then \ installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \ else \ installdir="$(DESTDIR)$(TARGET_DIR)"; \ fi; \ $(mkinstalldirs) $${installdir} ; \ for i in $$installfiles; do \ echo ' $(INSTALL_DATA) '$$i ; \ $(INSTALL_DATA) $$i $${installdir}; \ done; \ if test -n "$(DOC_MODULE_VERSION)"; then \ mv -f $${installdir}/$(DOC_MODULE).devhelp2 \ $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \ fi; \ $(GTKDOC_REBASE) --relative --dest-dir=$(DESTDIR) --html-dir=$${installdir}; \ fi uninstall-local: @if test -n "$(DOC_MODULE_VERSION)"; then \ installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \ else \ installdir="$(DESTDIR)$(TARGET_DIR)"; \ fi; \ rm -rf $${installdir} # # Require gtk-doc when making dist # if ENABLE_GTK_DOC dist-check-gtkdoc: else dist-check-gtkdoc: @echo "*** gtk-doc must be installed and enabled in order to make dist" @false endif dist-hook: dist-check-gtkdoc dist-hook-local @mkdir $(distdir)/html @cp ./html/* $(distdir)/html @-cp ./$(DOC_MODULE).pdf $(distdir)/ @-cp ./$(DOC_MODULE).types $(distdir)/ @-cp ./$(DOC_MODULE)-sections.txt $(distdir)/ @cd $(distdir) && rm -f $(DISTCLEANFILES) @$(GTKDOC_REBASE) --online --relative --html-dir=$(distdir)/html .PHONY : dist-hook-local docs ./docs/0000755000004100000410000000000013210416612012167 5ustar www-datawww-data./docs/reference/0000755000004100000410000000000013210416612014125 5ustar www-datawww-data./docs/reference/unity-gtk-module/0000755000004100000410000000000013210416612017343 5ustar www-datawww-data./docs/reference/unity-gtk-module/unity-gtk-module.types0000644000004100000410000000007613210416612023652 0ustar www-datawww-dataunity_gtk_action_group_get_type unity_gtk_menu_shell_get_type ./docs/reference/unity-gtk-module/unity-gtk-module-sections.txt0000644000004100000410000000156213210416612025153 0ustar www-datawww-data
unity-gtk-action-group UnityGtkActionGroup UnityGtkActionGroupClass unity_gtk_action_group_new unity_gtk_action_group_connect_shell unity_gtk_action_group_disconnect_shell unity_gtk_action_group_set_debug UNITY_GTK_ACTION_GROUP UNITY_GTK_ACTION_GROUP_CLASS UNITY_GTK_ACTION_GROUP_GET_CLASS UNITY_GTK_IS_ACTION_GROUP UNITY_GTK_IS_ACTION_GROUP_CLASS UNITY_GTK_TYPE_ACTION_GROUP unity_gtk_action_group_get_type
unity-gtk-menu-shell UnityGtkMenuShell UnityGtkMenuShellClass unity_gtk_menu_shell_new unity_gtk_menu_shell_set_debug UNITY_GTK_IS_MENU_SHELL UNITY_GTK_IS_MENU_SHELL_CLASS UNITY_GTK_MENU_SHELL UNITY_GTK_MENU_SHELL_CLASS UNITY_GTK_MENU_SHELL_GET_CLASS UNITY_GTK_TYPE_MENU_SHELL unity_gtk_menu_shell_get_type
unity-gtk-parser
./docs/reference/unity-gtk-module/unity-gtk-module-docs.sgml0000644000004100000410000000235513210416612024400 0ustar www-datawww-data ]> unity-gtk-module Reference Manual for unity-gtk-module 0.0.0. The latest version of this documentation can be found on-line at http://[SERVER]/unity-gtk-module/. API Reference Object Hierarchy API Index Index of deprecated API ./docs/reference/unity-gtk-module/unity-gtk-module-overrides.txt0000644000004100000410000000000013210416612025310 0ustar www-datawww-data./docs/reference/unity-gtk-module/Makefile.am0000644000004100000410000000727513210416612021412 0ustar www-datawww-data## Process this file with automake to produce Makefile.in # We require automake 1.6 at least. AUTOMAKE_OPTIONS = 1.6 # This is a blank Makefile.am for using gtk-doc. # Copy this to your project's API docs directory and modify the variables to # suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples # of using the various options. # The name of the module, e.g. 'glib'. DOC_MODULE=unity-gtk-module # Uncomment for versioned docs and specify the version of the module, e.g. '2'. #DOC_MODULE_VERSION=2 # The top-level SGML file. You can change this if you want to. DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml # Directories containing the source code. # gtk-doc will search all .c and .h files beneath these paths # for inline comments documenting functions and macros. # e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk DOC_SOURCE_DIR=$(top_srcdir)/lib # Extra options to pass to gtkdoc-scangobj. Not normally needed. SCANGOBJ_OPTIONS= # Extra options to supply to gtkdoc-scan. # e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" SCAN_OPTIONS= # Extra options to supply to gtkdoc-mkdb. # e.g. MKDB_OPTIONS=--xml-mode --output-format=xml MKDB_OPTIONS=--xml-mode --output-format=xml # Extra options to supply to gtkdoc-mktmpl # e.g. MKTMPL_OPTIONS=--only-section-tmpl MKTMPL_OPTIONS= # Extra options to supply to gtkdoc-mkhtml MKHTML_OPTIONS= # Extra options to supply to gtkdoc-fixref. Not normally needed. # e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html FIXXREF_OPTIONS= # Used for dependencies. The docs will be rebuilt if any of these change. # e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h # e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c HFILE_GLOB=$(top_srcdir)/lib/*.h CFILE_GLOB=$(top_srcdir)/lib/*.c # Extra header to include when scanning, which are not under DOC_SOURCE_DIR # e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h EXTRA_HFILES= # Header files or dirs to ignore when scanning. Use base file/dir names # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code IGNORE_HFILES= \ unity-gtk-menu-shell-private.h \ unity-gtk-menu-section-private.h \ unity-gtk-menu-item-private.h \ unity-gtk-action-group-private.h \ unity-gtk-action-private.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png HTML_IMAGES= # Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). # e.g. content_files=running.sgml building.sgml changes-2.0.sgml content_files= # SGML files where gtk-doc abbrevations (#GtkWidget) are expanded # These files must be listed here *and* in content_files # e.g. expand_content_files=running.sgml expand_content_files= # CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. # Only needed if you are using gtkdoc-scangobj to dynamically query widget # signals and properties. # e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) GTKDOC_CFLAGS= GTKDOC_LIBS=$(top_builddir)/lib/libunity-gtk$(GTK_VERSION)-parser.la # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make # Other files to distribute # e.g. EXTRA_DIST += version.xml.in EXTRA_DIST += # Files not to distribute # for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types # for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt #DISTCLEANFILES += # Comment this out if you want 'make check' to test you doc status # and run some sanity checks if ENABLE_GTK_DOC TESTS_ENVIRONMENT = cd $(srcdir) && \ DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \ SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir) #TESTS = $(GTKDOC_CHECK) endif -include $(top_srcdir)/git.mk ./docs/reference/Makefile.am0000644000004100000410000000003313210416612016155 0ustar www-datawww-dataSUBDIRS = unity-gtk-module ./docs/Makefile.am0000644000004100000410000000002413210416612014217 0ustar www-datawww-dataSUBDIRS = reference ./COPYING0000644000004100000410000010451313210416612012276 0ustar www-datawww-data GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ./src/0000755000004100000410000000000013210416612012026 5ustar www-datawww-data./src/main.c0000644000004100000410000006622313210416612013127 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #include #include #include "unity-gtk-parser.h" /* * Default list of apps which should not be patched. * Use xprop | grep CLASS to find the name to use. */ static const char * const BLACKLIST[] = { "acroread", "anjuta", "emacs", "emacs23", "emacs23-lucid", "emacs24", "emacs24-lucid", "freeciv", "freeciv-gtk2", "freeciv-gtk3", "glade", "gwyddion", NULL }; #define UNITY_GTK_MODULE_SCHEMA "com.canonical.unity-gtk-module" #define BLACKLIST_KEY "blacklist" #define WHITELIST_KEY "whitelist" #define _GTK_UNIQUE_BUS_NAME "_GTK_UNIQUE_BUS_NAME" #define _UNITY_OBJECT_PATH "_UNITY_OBJECT_PATH" #define _GTK_MENUBAR_OBJECT_PATH "_GTK_MENUBAR_OBJECT_PATH" #define OBJECT_PATH "/com/canonical/unity/gtk/window" G_DEFINE_QUARK (window_data, window_data); G_DEFINE_QUARK (menu_shell_data, menu_shell_data); typedef struct _WindowData WindowData; typedef struct _MenuShellData MenuShellData; struct _WindowData { guint window_id; GMenu *menu_model; guint menu_model_export_id; GSList *menus; GMenuModel *old_model; UnityGtkActionGroup *action_group; guint action_group_export_id; }; struct _MenuShellData { GtkWindow *window; }; static void (* pre_hijacked_window_realize) (GtkWidget *widget); static void (* pre_hijacked_window_unrealize) (GtkWidget *widget); #if GTK_MAJOR_VERSION == 3 static void (* pre_hijacked_application_window_realize) (GtkWidget *widget); #endif static void (* pre_hijacked_menu_bar_realize) (GtkWidget *widget); static void (* pre_hijacked_menu_bar_unrealize) (GtkWidget *widget); static void (* pre_hijacked_widget_size_allocate) (GtkWidget *widget, GtkAllocation *allocation); static void (* pre_hijacked_menu_bar_size_allocate) (GtkWidget *widget, GtkAllocation *allocation); #if GTK_MAJOR_VERSION == 2 static void (* pre_hijacked_menu_bar_size_request) (GtkWidget *widget, GtkRequisition *requisition); #elif GTK_MAJOR_VERSION == 3 static void (* pre_hijacked_menu_bar_get_preferred_width) (GtkWidget *widget, gint *minimum_width, gint *natural_width); static void (* pre_hijacked_menu_bar_get_preferred_height) (GtkWidget *widget, gint *minimum_height, gint *natural_height); static void (* pre_hijacked_menu_bar_get_preferred_width_for_height) (GtkWidget *widget, gint height, gint *minimum_width, gint *natural_width); static void (* pre_hijacked_menu_bar_get_preferred_height_for_width) (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height); #endif static gboolean is_string_in_array (const gchar *string, GVariant *array) { GVariantIter iter; const gchar *element; g_return_val_if_fail (array != NULL, FALSE); g_return_val_if_fail (g_variant_is_of_type (array, G_VARIANT_TYPE ("as")), FALSE); g_variant_iter_init (&iter, array); while (g_variant_iter_next (&iter, "&s", &element)) { if (g_strcmp0 (element, string) == 0) return TRUE; } return FALSE; } static gboolean is_listed (const gchar *name, const gchar *key) { GSettings *settings; GVariant *array; gboolean listed; settings = g_settings_new (UNITY_GTK_MODULE_SCHEMA); array = g_settings_get_value (settings, key); listed = is_string_in_array (name, array); g_variant_unref (array); g_object_unref (settings); return listed; } static gboolean is_blacklisted (const gchar *name) { guint n; guint i; n = sizeof (BLACKLIST) / sizeof (const char *); for (i = 0; i < n; i++) { if (g_strcmp0 (name, BLACKLIST[i]) == 0) return !is_listed (name, WHITELIST_KEY); } return is_listed (name, BLACKLIST_KEY); } static gboolean is_true (const gchar *value) { return value != NULL && value[0] != '\0' && g_ascii_strcasecmp (value, "0") != 0 && g_ascii_strcasecmp (value, "no") != 0 && g_ascii_strcasecmp (value, "off") != 0 && g_ascii_strcasecmp (value, "false") != 0; } static gchar * gtk_widget_get_x11_property_string (GtkWidget *widget, const gchar *name) { GdkWindow *window; GdkDisplay *display; Display *xdisplay; Window xwindow; Atom property; Atom actual_type; int actual_format; unsigned long nitems; unsigned long bytes_after; unsigned char *prop; g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); window = gtk_widget_get_window (widget); display = gdk_window_get_display (window); xdisplay = GDK_DISPLAY_XDISPLAY (display); xwindow = GDK_WINDOW_XID (window); property = None; if (display != NULL) property = gdk_x11_get_xatom_by_name_for_display (display, name); if (property == None) property = gdk_x11_get_xatom_by_name (name); g_return_val_if_fail (property != None, NULL); if (XGetWindowProperty (xdisplay, xwindow, property, 0, G_MAXLONG, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success) { if (actual_format) { gchar *string = g_strdup ((const gchar *) prop); if (prop != NULL) XFree (prop); return string; } else return NULL; } return NULL; } static void gtk_widget_set_x11_property_string (GtkWidget *widget, const gchar *name, const gchar *value) { GdkWindow *window; GdkDisplay *display; Display *xdisplay; Window xwindow; Atom property; Atom type; g_return_if_fail (GTK_IS_WIDGET (widget)); window = gtk_widget_get_window (widget); display = gdk_window_get_display (window); xdisplay = GDK_DISPLAY_XDISPLAY (display); xwindow = GDK_WINDOW_XID (window); property = None; if (display != NULL) property = gdk_x11_get_xatom_by_name_for_display (display, name); if (property == None) property = gdk_x11_get_xatom_by_name (name); g_return_if_fail (property != None); type = None; if (display != NULL) type = gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"); if (type == None) type = gdk_x11_get_xatom_by_name ("UTF8_STRING"); g_return_if_fail (type != None); if (value != NULL) XChangeProperty (xdisplay, xwindow, property, type, 8, PropModeReplace, (unsigned char *) value, g_utf8_strlen (value, -1)); else XDeleteProperty (xdisplay, xwindow, property); } static WindowData * window_data_new (void) { return g_slice_new0 (WindowData); } static void window_data_free (gpointer data) { WindowData *window_data = data; if (window_data != NULL) { GDBusConnection *session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if (window_data->action_group_export_id) g_dbus_connection_unexport_action_group (session, window_data->action_group_export_id); if (window_data->menu_model_export_id) g_dbus_connection_unexport_menu_model (session, window_data->menu_model_export_id); if (window_data->action_group != NULL) g_object_unref (window_data->action_group); if (window_data->menu_model != NULL) g_object_unref (window_data->menu_model); if (window_data->old_model != NULL) g_object_unref (window_data->old_model); if (window_data->menus != NULL) g_slist_free_full (window_data->menus, g_object_unref); g_slice_free (WindowData, window_data); } } static MenuShellData * menu_shell_data_new (void) { return g_slice_new0 (MenuShellData); } static void menu_shell_data_free (gpointer data) { if (data != NULL) g_slice_free (MenuShellData, data); } static MenuShellData * gtk_menu_shell_get_menu_shell_data (GtkMenuShell *menu_shell) { MenuShellData *menu_shell_data; g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), NULL); menu_shell_data = g_object_get_qdata (G_OBJECT (menu_shell), menu_shell_data_quark ()); if (menu_shell_data == NULL) { menu_shell_data = menu_shell_data_new (); g_object_set_qdata_full (G_OBJECT (menu_shell), menu_shell_data_quark (), menu_shell_data, menu_shell_data_free); } return menu_shell_data; } static WindowData * gtk_window_get_window_data (GtkWindow *window) { WindowData *window_data; g_return_val_if_fail (GTK_IS_WINDOW (window), NULL); window_data = g_object_get_qdata (G_OBJECT (window), window_data_quark ()); if (window_data == NULL) { static guint window_id; GDBusConnection *session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); gchar *object_path = g_strdup_printf (OBJECT_PATH "/%d", window_id); gchar *old_unique_bus_name = gtk_widget_get_x11_property_string (GTK_WIDGET (window), _GTK_UNIQUE_BUS_NAME); gchar *old_unity_object_path = gtk_widget_get_x11_property_string (GTK_WIDGET (window), _UNITY_OBJECT_PATH); gchar *old_menubar_object_path = gtk_widget_get_x11_property_string (GTK_WIDGET (window), _GTK_MENUBAR_OBJECT_PATH); GDBusActionGroup *old_action_group = NULL; GDBusMenuModel *old_menu_model = NULL; if (old_unique_bus_name != NULL) { if (old_unity_object_path != NULL) old_action_group = g_dbus_action_group_get (session, old_unique_bus_name, old_unity_object_path); if (old_menubar_object_path != NULL) old_menu_model = g_dbus_menu_model_get (session, old_unique_bus_name, old_menubar_object_path); } window_data = window_data_new (); window_data->window_id = window_id++; window_data->menu_model = g_menu_new (); window_data->action_group = unity_gtk_action_group_new (G_ACTION_GROUP (old_action_group)); if (old_menu_model != NULL) { window_data->old_model = g_object_ref (old_menu_model); g_menu_append_section (window_data->menu_model, NULL, G_MENU_MODEL (old_menu_model)); } window_data->menu_model_export_id = g_dbus_connection_export_menu_model (session, old_menubar_object_path != NULL ? old_menubar_object_path : object_path, G_MENU_MODEL (window_data->menu_model), NULL); window_data->action_group_export_id = g_dbus_connection_export_action_group (session, old_unity_object_path != NULL ? old_unity_object_path : object_path, G_ACTION_GROUP (window_data->action_group), NULL); if (old_unique_bus_name == NULL) gtk_widget_set_x11_property_string (GTK_WIDGET (window), _GTK_UNIQUE_BUS_NAME, g_dbus_connection_get_unique_name (session)); if (old_unity_object_path == NULL) gtk_widget_set_x11_property_string (GTK_WIDGET (window), _UNITY_OBJECT_PATH, object_path); if (old_menubar_object_path == NULL) gtk_widget_set_x11_property_string (GTK_WIDGET (window), _GTK_MENUBAR_OBJECT_PATH, object_path); g_object_set_qdata_full (G_OBJECT (window), window_data_quark (), window_data, window_data_free); g_free (old_menubar_object_path); g_free (old_unity_object_path); g_free (old_unique_bus_name); g_free (object_path); } return window_data; } static void gtk_window_disconnect_menu_shell (GtkWindow *window, GtkMenuShell *menu_shell) { WindowData *window_data; MenuShellData *menu_shell_data; g_return_if_fail (GTK_IS_WINDOW (window)); g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); menu_shell_data = gtk_menu_shell_get_menu_shell_data (menu_shell); g_warn_if_fail (window == menu_shell_data->window); window_data = gtk_window_get_window_data (menu_shell_data->window); if (window_data != NULL) { GSList *iter; guint i = 0; if (window_data->old_model != NULL) i++; for (iter = window_data->menus; iter != NULL; iter = g_slist_next (iter), i++) if (UNITY_GTK_MENU_SHELL (iter->data)->menu_shell == menu_shell) break; if (iter != NULL) { g_menu_remove (window_data->menu_model, i); unity_gtk_action_group_disconnect_shell (window_data->action_group, iter->data); g_object_unref (iter->data); window_data->menus = g_slist_delete_link (window_data->menus, iter); } menu_shell_data->window = NULL; } } static void gtk_window_connect_menu_shell (GtkWindow *window, GtkMenuShell *menu_shell) { MenuShellData *menu_shell_data; g_return_if_fail (GTK_IS_WINDOW (window)); g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); menu_shell_data = gtk_menu_shell_get_menu_shell_data (menu_shell); if (window != menu_shell_data->window) { WindowData *window_data; if (menu_shell_data->window != NULL) gtk_window_disconnect_menu_shell (menu_shell_data->window, menu_shell); window_data = gtk_window_get_window_data (window); if (window_data != NULL) { GSList *iter; for (iter = window_data->menus; iter != NULL; iter = g_slist_next (iter)) if (UNITY_GTK_MENU_SHELL (iter->data)->menu_shell == menu_shell) break; if (iter == NULL) { UnityGtkMenuShell *shell = unity_gtk_menu_shell_new (menu_shell); unity_gtk_action_group_connect_shell (window_data->action_group, shell); g_menu_append_section (window_data->menu_model, NULL, G_MENU_MODEL (shell)); window_data->menus = g_slist_append (window_data->menus, shell); } } menu_shell_data->window = window; } } static gboolean gtk_widget_shell_shows_menubar (GtkWidget *widget) { GtkSettings *settings; GParamSpec *pspec; gboolean shell_shows_menubar; g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); settings = gtk_widget_get_settings (widget); g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), "gtk-shell-shows-menubar"); g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE); g_return_val_if_fail (pspec->value_type == G_TYPE_BOOLEAN, FALSE); g_object_get (settings, "gtk-shell-shows-menubar", &shell_shows_menubar, NULL); return shell_shows_menubar; } static void gtk_settings_handle_gtk_shell_shows_menubar (GObject *object, GParamSpec *pspec, gpointer user_data) { gtk_widget_queue_resize (user_data); } static void hijacked_window_realize (GtkWidget *widget) { g_return_if_fail (GTK_IS_WINDOW (widget)); GdkScreen *screen = gtk_widget_get_screen(widget); GdkVisual *visual = gdk_screen_get_rgba_visual(screen); if (visual && (gtk_window_get_type_hint (GTK_WINDOW (widget)) == GDK_WINDOW_TYPE_HINT_DND)) gtk_widget_set_visual(widget, visual); if (pre_hijacked_window_realize != NULL) (* pre_hijacked_window_realize) (widget); #if GTK_MAJOR_VERSION == 3 if ((!GTK_IS_APPLICATION_WINDOW (widget)) #else if (1 #endif && !(gtk_window_get_type_hint (GTK_WINDOW (widget)) == GDK_WINDOW_TYPE_HINT_DND)) gtk_window_get_window_data (GTK_WINDOW (widget)); } static void hijacked_window_unrealize (GtkWidget *widget) { g_return_if_fail (GTK_IS_WINDOW (widget)); if (pre_hijacked_window_unrealize != NULL) (* pre_hijacked_window_unrealize) (widget); g_object_set_qdata (G_OBJECT (widget), window_data_quark (), NULL); } #if GTK_MAJOR_VERSION == 3 static void hijacked_application_window_realize (GtkWidget *widget) { g_return_if_fail (GTK_IS_APPLICATION_WINDOW (widget)); if (pre_hijacked_application_window_realize != NULL) (* pre_hijacked_application_window_realize) (widget); gtk_window_get_window_data (GTK_WINDOW (widget)); } #endif static void hijacked_menu_bar_realize (GtkWidget *widget) { GtkWidget *window; GtkSettings *settings; g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_realize != NULL) (* pre_hijacked_menu_bar_realize) (widget); window = gtk_widget_get_toplevel (widget); if (GTK_IS_WINDOW (window)) gtk_window_connect_menu_shell (GTK_WINDOW (window), GTK_MENU_SHELL (widget)); settings = gtk_widget_get_settings (widget); g_signal_connect (settings, "notify::gtk-shell-shows-menubar", G_CALLBACK (gtk_settings_handle_gtk_shell_shows_menubar), widget); } static void hijacked_menu_bar_unrealize (GtkWidget *widget) { GtkSettings *settings; MenuShellData *menu_shell_data; g_return_if_fail (GTK_IS_MENU_BAR (widget)); settings = gtk_widget_get_settings (widget); menu_shell_data = gtk_menu_shell_get_menu_shell_data (GTK_MENU_SHELL (widget)); if (settings != NULL) g_signal_handlers_disconnect_by_data (settings, widget); if (menu_shell_data->window != NULL) gtk_window_disconnect_menu_shell (menu_shell_data->window, GTK_MENU_SHELL (widget)); if (pre_hijacked_menu_bar_unrealize != NULL) (* pre_hijacked_menu_bar_unrealize) (widget); } static void hijacked_menu_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkAllocation zero = { 0, 0, 0, 0 }; GdkWindow *window; g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (gtk_widget_shell_shows_menubar (widget)) { /* * We manually assign an empty allocation to the menu bar to * prevent the container from attempting to draw it at all. */ if (pre_hijacked_widget_size_allocate != NULL) (* pre_hijacked_widget_size_allocate) (widget, &zero); /* * Then we move the GdkWindow belonging to the menu bar outside of * the clipping rectangle of the parent window so that we can't * see it. */ window = gtk_widget_get_window (widget); if (window != NULL) gdk_window_move_resize (window, -1, -1, 1, 1); } else if (pre_hijacked_menu_bar_size_allocate != NULL) (* pre_hijacked_menu_bar_size_allocate) (widget, allocation); } #if GTK_MAJOR_VERSION == 2 static void hijacked_menu_bar_size_request (GtkWidget *widget, GtkRequisition *requisition) { g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_size_request != NULL) (* pre_hijacked_menu_bar_size_request) (widget, requisition); if (gtk_widget_shell_shows_menubar (widget)) { requisition->width = 0; requisition->height = 0; } } #elif GTK_MAJOR_VERSION == 3 static void hijacked_menu_bar_get_preferred_width (GtkWidget *widget, gint *minimum_width, gint *natural_width) { g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_get_preferred_width != NULL) (* pre_hijacked_menu_bar_get_preferred_width) (widget, minimum_width, natural_width); if (gtk_widget_shell_shows_menubar (widget)) { *minimum_width = 0; *natural_width = 0; } } static void hijacked_menu_bar_get_preferred_height (GtkWidget *widget, gint *minimum_height, gint *natural_height) { g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_get_preferred_height != NULL) (* pre_hijacked_menu_bar_get_preferred_height) (widget, minimum_height, natural_height); if (gtk_widget_shell_shows_menubar (widget)) { *minimum_height = 0; *natural_height = 0; } } static void hijacked_menu_bar_get_preferred_width_for_height (GtkWidget *widget, gint height, gint *minimum_width, gint *natural_width) { g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_get_preferred_width_for_height != NULL) (* pre_hijacked_menu_bar_get_preferred_width_for_height) (widget, height, minimum_width, natural_width); if (gtk_widget_shell_shows_menubar (widget)) { *minimum_width = 0; *natural_width = 0; } } static void hijacked_menu_bar_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) { g_return_if_fail (GTK_IS_MENU_BAR (widget)); if (pre_hijacked_menu_bar_get_preferred_height_for_width != NULL) (* pre_hijacked_menu_bar_get_preferred_height_for_width) (widget, width, minimum_height, natural_height); if (gtk_widget_shell_shows_menubar (widget)) { *minimum_height = 0; *natural_height = 0; } } #endif static void hijack_window_class_vtable (GType type) { GtkWidgetClass *widget_class = g_type_class_ref (type); GType *children; guint n; guint i; if (widget_class->realize == pre_hijacked_window_realize) widget_class->realize = hijacked_window_realize; #if GTK_MAJOR_VERSION == 3 if (widget_class->realize == pre_hijacked_application_window_realize) widget_class->realize = hijacked_application_window_realize; #endif if (widget_class->unrealize == pre_hijacked_window_unrealize) widget_class->unrealize = hijacked_window_unrealize; children = g_type_children (type, &n); for (i = 0; i < n; i++) hijack_window_class_vtable (children[i]); g_free (children); } static void hijack_menu_bar_class_vtable (GType type) { GtkWidgetClass *widget_class = g_type_class_ref (type); GType *children; guint n; guint i; /* This fixes lp:1113008. */ widget_class->hierarchy_changed = NULL; if (widget_class->realize == pre_hijacked_menu_bar_realize) widget_class->realize = hijacked_menu_bar_realize; if (widget_class->unrealize == pre_hijacked_menu_bar_unrealize) widget_class->unrealize = hijacked_menu_bar_unrealize; if (widget_class->size_allocate == pre_hijacked_menu_bar_size_allocate) widget_class->size_allocate = hijacked_menu_bar_size_allocate; #if GTK_MAJOR_VERSION == 2 if (widget_class->size_request == pre_hijacked_menu_bar_size_request) widget_class->size_request = hijacked_menu_bar_size_request; #elif GTK_MAJOR_VERSION == 3 if (widget_class->get_preferred_width == pre_hijacked_menu_bar_get_preferred_width) widget_class->get_preferred_width = hijacked_menu_bar_get_preferred_width; if (widget_class->get_preferred_height == pre_hijacked_menu_bar_get_preferred_height) widget_class->get_preferred_height = hijacked_menu_bar_get_preferred_height; if (widget_class->get_preferred_width_for_height == pre_hijacked_menu_bar_get_preferred_width_for_height) widget_class->get_preferred_width_for_height = hijacked_menu_bar_get_preferred_width_for_height; if (widget_class->get_preferred_height_for_width == pre_hijacked_menu_bar_get_preferred_height_for_width) widget_class->get_preferred_height_for_width = hijacked_menu_bar_get_preferred_height_for_width; #endif children = g_type_children (type, &n); for (i = 0; i < n; i++) hijack_menu_bar_class_vtable (children[i]); g_free (children); } void gtk_module_init (void) { const gchar *proxy = g_getenv ("UBUNTU_MENUPROXY"); /* We only support X11 */ #if GTK_MAJOR_VERSION == 3 if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ())) return; #endif if ((proxy == NULL || is_true (proxy)) && !is_blacklisted (g_get_prgname ())) { GtkWidgetClass *widget_class; unity_gtk_menu_shell_set_debug (is_true (g_getenv ("UNITY_GTK_MENU_SHELL_DEBUG"))); unity_gtk_action_group_set_debug (is_true (g_getenv ("UNITY_GTK_ACTION_GROUP_DEBUG"))); /* store the base GtkWidget size_allocate vfunc */ widget_class = g_type_class_ref (GTK_TYPE_WIDGET); pre_hijacked_widget_size_allocate = widget_class->size_allocate; #if GTK_MAJOR_VERSION == 3 /* store the base GtkApplicationWindow realize vfunc */ widget_class = g_type_class_ref (GTK_TYPE_APPLICATION_WINDOW); pre_hijacked_application_window_realize = widget_class->realize; #endif /* intercept window realize vcalls on GtkWindow */ widget_class = g_type_class_ref (GTK_TYPE_WINDOW); pre_hijacked_window_realize = widget_class->realize; pre_hijacked_window_unrealize = widget_class->unrealize; hijack_window_class_vtable (GTK_TYPE_WINDOW); /* intercept size request and allocate vcalls on GtkMenuBar (for hiding) */ widget_class = g_type_class_ref (GTK_TYPE_MENU_BAR); pre_hijacked_menu_bar_realize = widget_class->realize; pre_hijacked_menu_bar_unrealize = widget_class->unrealize; pre_hijacked_menu_bar_size_allocate = widget_class->size_allocate; #if GTK_MAJOR_VERSION == 2 pre_hijacked_menu_bar_size_request = widget_class->size_request; #elif GTK_MAJOR_VERSION == 3 pre_hijacked_menu_bar_get_preferred_width = widget_class->get_preferred_width; pre_hijacked_menu_bar_get_preferred_height = widget_class->get_preferred_height; pre_hijacked_menu_bar_get_preferred_width_for_height = widget_class->get_preferred_width_for_height; pre_hijacked_menu_bar_get_preferred_height_for_width = widget_class->get_preferred_height_for_width; #endif hijack_menu_bar_class_vtable (GTK_TYPE_MENU_BAR); } } ./src/Makefile.am0000644000004100000410000000057313210416612014067 0ustar www-datawww-dataAM_CPPFLAGS = -I$(top_srcdir)/lib AM_CFLAGS = $(GTK_CFLAGS) $(X11_CFLAGS) -Wall AM_LDFLAGS = $(GTK_LIBS) $(X11_LIBS) -avoid-version -module -shared libunity_gtk_moduledir = $(GTK_MODULE_DIR) libunity_gtk_module_LTLIBRARIES = libunity-gtk-module.la libunity_gtk_module_la_SOURCES = main.c libunity_gtk_module_la_LIBADD = $(top_builddir)/lib/libunity-gtk$(GTK_VERSION)-parser.la ./autogen.sh0000755000004100000410000000014413210416612013237 0ustar www-datawww-data#!/bin/sh -e mkdir -p m4 gtkdocize --copy autoreconf -i test -n "$NOCONFIGURE" || ./configure "$@" ./lib/0000755000004100000410000000000013210416612012005 5ustar www-datawww-data./lib/unity-gtk-action-group-private.h0000644000004100000410000000314613210416612020172 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_ACTION_GROUP_PRIVATE_H__ #define __UNITY_GTK_ACTION_GROUP_PRIVATE_H__ #include #include "unity-gtk-action-group.h" #include "unity-gtk-menu-item-private.h" G_BEGIN_DECLS void unity_gtk_action_group_connect_item (UnityGtkActionGroup *group, UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_action_group_disconnect_item (UnityGtkActionGroup *group, UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_action_group_print (UnityGtkActionGroup *group, guint indent) G_GNUC_INTERNAL; gboolean unity_gtk_action_group_is_debug (void) G_GNUC_INTERNAL; G_END_DECLS #endif /* __UNITY_GTK_ACTION_GROUP_PRIVATE_H__ */ ./lib/unity-gtk-menu-shell.c0000644000004100000410000011351513210416612016161 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ /** * SECTION:unity-gtk-menu-shell * @short_description: Menu shell proxy * @include: unity-gtk-parser.h * * A #UnityGtkMenuShell is a #GMenuModel that acts as a proxy for a * #GtkMenuShell. This can be used for purposes such as exporting menu * shells over DBus with g_dbus_connection_export_menu_model (). * * #UnityGtkMenuShells are most useful when used with * #UnityGtkActionGroups. */ #include "unity-gtk-menu-shell-private.h" #include "unity-gtk-menu-section-private.h" #include "unity-gtk-action-group-private.h" G_DEFINE_QUARK (menu_shell, menu_shell); G_DEFINE_TYPE (UnityGtkMenuShell, unity_gtk_menu_shell, G_TYPE_MENU_MODEL); static gboolean unity_gtk_menu_shell_debug; static gint g_uintcmp (gconstpointer a, gconstpointer b, gpointer user_data) { return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b); } static guint g_sequence_get_uint (GSequenceIter *iter) { return GPOINTER_TO_UINT (g_sequence_get (iter)); } static void g_sequence_set_uint (GSequenceIter *iter, guint i) { g_sequence_set (iter, GUINT_TO_POINTER (i)); } static GSequenceIter * g_sequence_insert_sorted_uint (GSequence *sequence, guint i) { return g_sequence_insert_sorted (sequence, GUINT_TO_POINTER (i), g_uintcmp, NULL); } static GSequenceIter * g_sequence_lookup_uint (GSequence *sequence, guint i) { return g_sequence_lookup (sequence, GUINT_TO_POINTER (i), g_uintcmp, NULL); } static GSequenceIter * g_sequence_search_uint (GSequence *sequence, guint i) { return g_sequence_search (sequence, GUINT_TO_POINTER (i), g_uintcmp, NULL); } static GSequenceIter * g_sequence_search_inf_uint (GSequence *sequence, guint i) { GSequenceIter *iter = g_sequence_iter_prev (g_sequence_search_uint (sequence, i)); return !g_sequence_iter_is_end (iter) && g_sequence_get_uint (iter) <= i ? iter : NULL; } static gboolean gtk_menu_item_handle_idle_activate (gpointer user_data) { g_return_val_if_fail (GTK_IS_MENU_ITEM (user_data), G_SOURCE_REMOVE); gtk_menu_item_activate (user_data); return G_SOURCE_REMOVE; } static GPtrArray * unity_gtk_menu_shell_get_items (UnityGtkMenuShell *shell) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (shell), NULL); if (shell->items == NULL) { GList *children; GList *iter; guint i; g_return_val_if_fail (shell->menu_shell != NULL, NULL); shell->items = g_ptr_array_new_with_free_func (g_object_unref); children = gtk_container_get_children (GTK_CONTAINER (shell->menu_shell)); for (iter = children, i = 0; iter != NULL; i++) { g_ptr_array_add (shell->items, unity_gtk_menu_item_new (iter->data, shell, i)); iter = g_list_next (iter); } g_list_free (children); } return shell->items; } static GPtrArray * unity_gtk_menu_shell_get_sections (UnityGtkMenuShell *shell) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (shell), NULL); if (shell->sections == NULL) { GSequence *separator_indices = unity_gtk_menu_shell_get_separator_indices (shell); guint n = g_sequence_get_length (separator_indices); guint i; shell->sections = g_ptr_array_new_full (n + 1, g_object_unref); for (i = 0; i <= n; i++) g_ptr_array_add (shell->sections, unity_gtk_menu_section_new (shell, i)); } return shell->sections; } static void unity_gtk_menu_shell_show_item (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GSequence *visible_indices; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); visible_indices = shell->visible_indices; if (visible_indices != NULL) { GSequence *separator_indices = shell->separator_indices; guint item_index = item->item_index; GSequenceIter *insert_iter = g_sequence_lookup_uint (visible_indices, item_index); gboolean already_visible = insert_iter != NULL; if (!already_visible) insert_iter = g_sequence_insert_sorted_uint (visible_indices, item_index); else g_warn_if_reached (); if (shell->action_group != NULL) { unity_gtk_action_group_connect_item (shell->action_group, item); if (item->child_shell != NULL) { if (item->child_shell_valid) unity_gtk_action_group_connect_shell (shell->action_group, item->child_shell); else g_warn_if_reached (); } } if (separator_indices != NULL) { GPtrArray *sections = shell->sections; GSequenceIter *separator_iter = g_sequence_search_inf_uint (separator_indices, item_index); guint section_index = separator_iter == NULL ? 0 : g_sequence_iter_get_position (separator_iter) + 1; gboolean separator_already_visible = separator_iter != NULL && g_sequence_get_uint (separator_iter) == item_index; if (!separator_already_visible) { if (unity_gtk_menu_item_is_separator (item)) { g_sequence_insert_sorted_uint (separator_indices, item_index); if (sections != NULL) { UnityGtkMenuSection *section = g_ptr_array_index (sections, section_index); GSequenceIter *section_iter = unity_gtk_menu_section_get_begin_iter (section); guint position = g_sequence_iter_get_position (insert_iter) - g_sequence_iter_get_position (section_iter); UnityGtkMenuSection *new_section = unity_gtk_menu_section_new (shell, section_index + 1); guint removed = g_menu_model_get_n_items (G_MENU_MODEL (new_section)); guint i; g_ptr_array_insert (sections, section_index + 1, new_section); for (i = section_index + 2; i < sections->len; i++) UNITY_GTK_MENU_SECTION (g_ptr_array_index (sections, i))->section_index = i; if (removed) g_menu_model_items_changed (G_MENU_MODEL (section), position, removed, 0); g_menu_model_items_changed (G_MENU_MODEL (shell), section_index + 1, 0, 1); } } else { if (sections != NULL) { UnityGtkMenuSection *section = g_ptr_array_index (sections, section_index); GSequenceIter *section_iter = unity_gtk_menu_section_get_begin_iter (section); guint position = g_sequence_iter_get_position (insert_iter) - g_sequence_iter_get_position (section_iter); g_menu_model_items_changed (G_MENU_MODEL (section), position, 0, 1); } } } else g_warn_if_reached (); } } } static void unity_gtk_menu_shell_hide_item (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GSequence *visible_indices; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); visible_indices = shell->visible_indices; if (visible_indices != NULL) { GSequence *separator_indices = shell->separator_indices; guint item_index = item->item_index; GSequenceIter *visible_iter = g_sequence_lookup_uint (visible_indices, item_index); if (shell->action_group != NULL) { if (item->child_shell != NULL) { if (item->child_shell_valid) unity_gtk_action_group_disconnect_shell (shell->action_group, item->child_shell); else g_warn_if_reached (); } unity_gtk_action_group_disconnect_item (shell->action_group, item); } if (separator_indices != NULL) { if (unity_gtk_menu_item_is_separator (item)) { GSequenceIter *separator_iter = g_sequence_lookup_uint (separator_indices, item_index); if (separator_iter != NULL) { GPtrArray *sections = shell->sections; guint section_index = g_sequence_iter_get_position (separator_iter); if (shell->sections != NULL) { UnityGtkMenuSection *section = g_ptr_array_index (sections, section_index); UnityGtkMenuSection *next_section = g_ptr_array_index (sections, section_index + 1); guint position = g_menu_model_get_n_items (G_MENU_MODEL (section)); guint added = g_menu_model_get_n_items (G_MENU_MODEL (next_section)); guint i; g_sequence_remove (separator_iter); if (visible_iter != NULL) g_sequence_remove (visible_iter); else g_warn_if_reached (); g_menu_model_items_changed (G_MENU_MODEL (shell), section_index + 1, 1, 0); if (added) g_menu_model_items_changed (G_MENU_MODEL (section), position, 0, added); g_ptr_array_remove_index (sections, section_index + 1); for (i = section_index + 1; i < sections->len; i++) UNITY_GTK_MENU_SECTION (g_ptr_array_index (sections, i))->section_index = i; } else { g_sequence_remove (separator_iter); if (visible_iter != NULL) g_sequence_remove (visible_iter); else g_warn_if_reached (); } } else { g_warn_if_reached (); if (visible_iter != NULL) g_sequence_remove (visible_iter); else g_warn_if_reached (); } } else { if (visible_iter != NULL) { GPtrArray *sections = shell->sections; GSequenceIter *separator_iter = g_sequence_search_inf_uint (separator_indices, item_index); guint section_index = separator_iter == NULL ? 0 : g_sequence_iter_get_position (separator_iter) + 1; if (shell->sections != NULL) { UnityGtkMenuSection *section = g_ptr_array_index (sections, section_index); GSequenceIter *section_iter = unity_gtk_menu_section_get_begin_iter (section); guint position = g_sequence_iter_get_position (visible_iter) - g_sequence_iter_get_position (section_iter); g_sequence_remove (visible_iter); g_menu_model_items_changed (G_MENU_MODEL (section), position, 1, 0); } } else g_warn_if_reached (); } } else { if (visible_iter != NULL) g_sequence_remove (visible_iter); else g_warn_if_reached (); } } } static void unity_gtk_menu_shell_update_item (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GSequence *visible_indices; GSequenceIter *visible_iter; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); visible_indices = unity_gtk_menu_shell_get_visible_indices (shell); visible_iter = g_sequence_lookup_uint (visible_indices, item->item_index); if (visible_iter != NULL) { GSequence *separator_indices; GSequenceIter *separator_iter; guint section_index; GPtrArray *sections; UnityGtkMenuSection *section; GSequenceIter *section_iter; guint position; separator_indices = unity_gtk_menu_shell_get_separator_indices (shell); separator_iter = g_sequence_search_inf_uint (separator_indices, item->item_index); section_index = separator_iter == NULL ? 0 : g_sequence_iter_get_position (separator_iter) + 1; sections = unity_gtk_menu_shell_get_sections (shell); section = g_ptr_array_index (sections, section_index); section_iter = unity_gtk_menu_section_get_begin_iter (section); position = g_sequence_iter_get_position (visible_iter) - g_sequence_iter_get_position (section_iter); g_menu_model_items_changed (G_MENU_MODEL (section), position, 1, 1); } } static void unity_gtk_menu_shell_handle_item_visible (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GSequence *visible_indices; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); visible_indices = shell->visible_indices; if (visible_indices != NULL) { GSequenceIter *visible_iter = g_sequence_lookup_uint (visible_indices, item->item_index); gboolean was_visible = visible_iter != NULL; gboolean is_visible = unity_gtk_menu_item_is_visible (item); if (!was_visible && is_visible) unity_gtk_menu_shell_show_item (shell, item); else if (was_visible && !is_visible) unity_gtk_menu_shell_hide_item (shell, item); } } static void unity_gtk_menu_shell_handle_item_sensitive (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GActionGroup *action_group; UnityGtkAction *action; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); action_group = G_ACTION_GROUP (shell->action_group); action = item->action; if (action_group != NULL && action != NULL) { gboolean enabled = unity_gtk_menu_item_is_sensitive (item); g_action_group_action_enabled_changed (action_group, action->name, enabled); } } static void unity_gtk_menu_shell_handle_item_label (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); g_free (item->label_label); item->label_label = NULL; unity_gtk_menu_shell_update_item (shell, item); } static void unity_gtk_menu_shell_handle_item_use_underline (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { unity_gtk_menu_shell_handle_item_label (shell, item); } static void unity_gtk_menu_shell_handle_item_accel_path (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { unity_gtk_menu_shell_update_item (shell, item); } static void unity_gtk_menu_shell_handle_item_active (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GActionGroup *action_group; UnityGtkAction *action; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); action_group = G_ACTION_GROUP (shell->action_group); action = item->action; if (action_group != NULL && action != NULL) { if (action->items_by_name != NULL) { const gchar *name = NULL; GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init (&iter, action->items_by_name); while (name == NULL && g_hash_table_iter_next (&iter, &key, &value)) if (unity_gtk_menu_item_is_active (value)) name = key; if (name != NULL) { GVariant *state = g_variant_new_string (name); g_action_group_action_state_changed (action_group, action->name, state); } else g_action_group_action_state_changed (action_group, action->name, NULL); } else if (unity_gtk_menu_item_is_check (item)) { gboolean active = unity_gtk_menu_item_is_active (item); GVariant *state = g_variant_new_boolean (active); g_action_group_action_state_changed (action_group, action->name, state); } } } static void unity_gtk_menu_shell_handle_item_parent (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { GtkMenuItem *menu_item; GtkWidget *parent; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); menu_item = item->menu_item; parent = gtk_widget_get_parent (GTK_WIDGET (menu_item)); if (parent == NULL) { GPtrArray *items = shell->items; if (unity_gtk_menu_item_is_visible (item)) unity_gtk_menu_shell_hide_item (shell, item); if (items != NULL) { GSequence *visible_indices = shell->visible_indices; GSequence *separator_indices = shell->separator_indices; guint item_index = item->item_index; guint i; g_ptr_array_remove_index (items, item_index); for (i = item_index; i < items->len; i++) UNITY_GTK_MENU_ITEM (g_ptr_array_index (items, i))->item_index = i; if (visible_indices != NULL) { GSequenceIter *iter = g_sequence_search_uint (visible_indices, item_index); while (!g_sequence_iter_is_end (iter)) { g_sequence_set_uint (iter, g_sequence_get_uint (iter) - 1); iter = g_sequence_iter_next (iter); } } if (separator_indices != NULL) { GSequenceIter *iter = g_sequence_search_uint (separator_indices, item_index); while (!g_sequence_iter_is_end (iter)) { g_sequence_set_uint (iter, g_sequence_get_uint (iter) - 1); iter = g_sequence_iter_next (iter); } } } } } static void unity_gtk_menu_shell_handle_item_submenu (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell == shell); if (shell->action_group != NULL) { /* If a submenu was added or removed, we need to update the submenu action. */ unity_gtk_action_group_disconnect_item (shell->action_group, item); unity_gtk_action_group_connect_item (shell->action_group, item); } if (item->child_shell_valid) { GtkMenuShell *old_submenu = item->child_shell != NULL ? item->child_shell->menu_shell : NULL; GtkMenuShell *new_submenu = item->menu_item != NULL ? GTK_MENU_SHELL (gtk_menu_item_get_submenu (item->menu_item)) : NULL; if (new_submenu != old_submenu) { UnityGtkMenuShell *child_shell = item->child_shell; GSequence *visible_indices = unity_gtk_menu_shell_get_visible_indices (shell); GSequence *separator_indices = unity_gtk_menu_shell_get_separator_indices (shell); GSequenceIter *separator_iter = g_sequence_search_inf_uint (separator_indices, item->item_index); guint section_index = separator_iter == NULL ? 0 : g_sequence_iter_get_position (separator_iter) + 1; GPtrArray *sections = unity_gtk_menu_shell_get_sections (shell); UnityGtkMenuSection *section = g_ptr_array_index (sections, section_index); GSequenceIter *section_iter = unity_gtk_menu_section_get_begin_iter (section); GSequenceIter *visible_iter = g_sequence_lookup_uint (visible_indices, item->item_index); guint position = g_sequence_iter_get_position (visible_iter) - g_sequence_iter_get_position (section_iter); if (child_shell != NULL) { item->child_shell = NULL; g_object_unref (child_shell); } item->child_shell_valid = FALSE; g_menu_model_items_changed (G_MENU_MODEL (section), position, 1, 1); } } } static void unity_gtk_menu_shell_handle_shell_insert (GtkMenuShell *menu_shell, GtkWidget *child, gint position, gpointer user_data) { UnityGtkMenuShell *shell; GPtrArray *items; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (user_data)); if (unity_gtk_menu_shell_is_debug ()) g_print ("%s ((%s *) %p, (%s *) %p \"%s\", %d, (%s *) %p)\n", G_STRFUNC, G_OBJECT_TYPE_NAME (menu_shell), menu_shell, G_OBJECT_TYPE_NAME (child), child, gtk_menu_item_get_label (GTK_MENU_ITEM (child)), position, G_OBJECT_TYPE_NAME (user_data), user_data); shell = UNITY_GTK_MENU_SHELL (user_data); items = shell->items; if (items != NULL) { UnityGtkMenuItem *item; GtkMenuItem *menu_item; GSequence *visible_indices; GSequence *separator_indices; guint i; if (position < 0) position = items->len; menu_item = GTK_MENU_ITEM (child); item = unity_gtk_menu_item_new (menu_item, shell, position); g_ptr_array_insert (items, position, item); for (i = position + 1; i < items->len; i++) UNITY_GTK_MENU_ITEM (g_ptr_array_index (items, i))->item_index = i; visible_indices = shell->visible_indices; separator_indices = shell->separator_indices; if (visible_indices != NULL) { GSequenceIter *iter = g_sequence_search_uint (visible_indices, position - 1); while (!g_sequence_iter_is_end (iter)) { g_sequence_set_uint (iter, g_sequence_get_uint (iter) + 1); iter = g_sequence_iter_next (iter); } } if (separator_indices != NULL) { GSequenceIter *iter = g_sequence_search_uint (separator_indices, position - 1); while (!g_sequence_iter_is_end (iter)) { g_sequence_set_uint (iter, g_sequence_get_uint (iter) + 1); iter = g_sequence_iter_next (iter); } } if (unity_gtk_menu_item_is_visible (item)) unity_gtk_menu_shell_show_item (shell, item); } } static void unity_gtk_menu_shell_set_has_mnemonics (UnityGtkMenuShell *shell, gboolean has_mnemonics) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); if (has_mnemonics != shell->has_mnemonics) { shell->has_mnemonics = has_mnemonics; if (shell->items != NULL) { guint i; for (i = 0; i < shell->items->len; i++) unity_gtk_menu_shell_handle_item_label (shell, g_ptr_array_index (shell->items, i)); } } } static void unity_gtk_menu_shell_handle_settings_notify (GObject *object, GParamSpec *pspec, gpointer user_data) { gboolean has_mnemonics; g_return_if_fail (GTK_IS_SETTINGS (object)); g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (user_data)); g_object_get (GTK_SETTINGS (object), "gtk-enable-mnemonics", &has_mnemonics, NULL); unity_gtk_menu_shell_set_has_mnemonics (UNITY_GTK_MENU_SHELL (user_data), has_mnemonics); } static void unity_gtk_menu_shell_clear_menu_shell (UnityGtkMenuShell *shell); static void unity_gtk_menu_shell_set_menu_shell (UnityGtkMenuShell *shell, GtkMenuShell *menu_shell) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); if (menu_shell != shell->menu_shell) { GPtrArray *items = shell->items; GPtrArray *sections = shell->sections; GSequence *visible_indices = shell->visible_indices; GSequence *separator_indices = shell->separator_indices; if (shell->action_group != NULL) unity_gtk_action_group_disconnect_shell (shell->action_group, shell); if (shell->menu_shell != NULL) g_signal_handlers_disconnect_by_data (shell->menu_shell, shell); if (separator_indices != NULL) { shell->separator_indices = NULL; g_sequence_free (separator_indices); } if (visible_indices != NULL) { shell->visible_indices = NULL; g_sequence_free (visible_indices); } if (sections != NULL) { shell->sections = NULL; g_ptr_array_unref (sections); } if (items != NULL) { shell->items = NULL; g_ptr_array_unref (items); } if (shell->menu_shell != NULL) g_object_steal_qdata (G_OBJECT (shell->menu_shell), menu_shell_quark ()); shell->menu_shell = menu_shell; if (menu_shell != NULL) { g_object_set_qdata_full (G_OBJECT (menu_shell), menu_shell_quark (), shell, (GDestroyNotify) unity_gtk_menu_shell_clear_menu_shell); g_signal_connect (menu_shell, "insert", G_CALLBACK (unity_gtk_menu_shell_handle_shell_insert), shell); } } } static void unity_gtk_menu_shell_clear_menu_shell (UnityGtkMenuShell *shell) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); unity_gtk_menu_shell_set_menu_shell (shell, NULL); } static void unity_gtk_menu_shell_dispose (GObject *object) { UnityGtkMenuShell *shell; GtkSettings *settings; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (object)); shell = UNITY_GTK_MENU_SHELL (object); settings = gtk_settings_get_default (); unity_gtk_menu_shell_set_menu_shell (shell, NULL); if (settings != NULL) g_signal_handlers_disconnect_by_data (settings, shell); G_OBJECT_CLASS (unity_gtk_menu_shell_parent_class)->dispose (object); } static gboolean unity_gtk_menu_shell_is_mutable (GMenuModel *model) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (model), TRUE); return TRUE; } static gint unity_gtk_menu_shell_get_n_items (GMenuModel *model) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (model), 0); return unity_gtk_menu_shell_get_sections (UNITY_GTK_MENU_SHELL (model))->len; } static void unity_gtk_menu_shell_get_item_attributes (GMenuModel *model, gint item_index, GHashTable **attributes) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (model)); g_return_if_fail (0 <= item_index && item_index < g_menu_model_get_n_items (model)); g_return_if_fail (attributes != NULL); *attributes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref); } static void unity_gtk_menu_shell_get_item_links (GMenuModel *model, gint item_index, GHashTable **links) { UnityGtkMenuShell *shell; GPtrArray *sections; UnityGtkMenuSection *section; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (model)); g_return_if_fail (0 <= item_index && item_index < g_menu_model_get_n_items (model)); g_return_if_fail (links != NULL); shell = UNITY_GTK_MENU_SHELL (model); sections = unity_gtk_menu_shell_get_sections (shell); section = g_ptr_array_index (sections, item_index); *links = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); g_hash_table_insert (*links, G_MENU_LINK_SECTION, g_object_ref (section)); } static void unity_gtk_menu_shell_class_init (UnityGtkMenuShellClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GMenuModelClass *menu_model_class = G_MENU_MODEL_CLASS (klass); object_class->dispose = unity_gtk_menu_shell_dispose; menu_model_class->is_mutable = unity_gtk_menu_shell_is_mutable; menu_model_class->get_n_items = unity_gtk_menu_shell_get_n_items; menu_model_class->get_item_attributes = unity_gtk_menu_shell_get_item_attributes; menu_model_class->get_item_links = unity_gtk_menu_shell_get_item_links; } static void unity_gtk_menu_shell_init (UnityGtkMenuShell *self) { self->has_mnemonics = TRUE; } /** * unity_gtk_menu_shell_new: * @menu_shell: a #GtkMenuShell to watch. * * Creates a new #UnityGtkMenuShell based on the contents of the given * @menu_shell. Any subsequent changes to @menu_shell are reflected in * the returned #UnityGtkMenuShell. * * Returns: a new #UnityGtkMenuShell based on @menu_shell. */ UnityGtkMenuShell * unity_gtk_menu_shell_new (GtkMenuShell *menu_shell) { UnityGtkMenuShell *shell = g_object_new (UNITY_GTK_TYPE_MENU_SHELL, NULL); GtkSettings *settings = gtk_settings_get_default (); if (settings != NULL) { g_signal_connect (settings, "notify::gtk-enable-mnemonics", G_CALLBACK (unity_gtk_menu_shell_handle_settings_notify), shell); g_object_get (settings, "gtk-enable-mnemonics", &shell->has_mnemonics, NULL); } unity_gtk_menu_shell_set_menu_shell (shell, menu_shell); return shell; } UnityGtkMenuShell * unity_gtk_menu_shell_new_internal (GtkMenuShell *menu_shell) { UnityGtkMenuShell *shell = g_object_new (UNITY_GTK_TYPE_MENU_SHELL, NULL); unity_gtk_menu_shell_set_menu_shell (shell, menu_shell); return shell; } UnityGtkMenuItem * unity_gtk_menu_shell_get_item (UnityGtkMenuShell *shell, guint index) { GPtrArray *items; g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (shell), NULL); items = unity_gtk_menu_shell_get_items (shell); g_return_val_if_fail (0 <= index && index < items->len, NULL); return g_ptr_array_index (items, index); } GSequence * unity_gtk_menu_shell_get_visible_indices (UnityGtkMenuShell *shell) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (shell), NULL); if (shell->visible_indices == NULL) { GPtrArray *items = unity_gtk_menu_shell_get_items (shell); guint i; shell->visible_indices = g_sequence_new (NULL); for (i = 0; i < items->len; i++) { UnityGtkMenuItem *item = g_ptr_array_index (items, i); if (unity_gtk_menu_item_is_visible (item)) g_sequence_append (shell->visible_indices, GUINT_TO_POINTER (i)); } if (shell->action_group != NULL) unity_gtk_action_group_connect_shell (shell->action_group, shell); } return shell->visible_indices; } GSequence * unity_gtk_menu_shell_get_separator_indices (UnityGtkMenuShell *shell) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SHELL (shell), NULL); unity_gtk_menu_shell_get_visible_indices (shell); if (shell->separator_indices == NULL) { GPtrArray *items = unity_gtk_menu_shell_get_items (shell); guint i; shell->separator_indices = g_sequence_new (NULL); for (i = 0; i < items->len; i++) { UnityGtkMenuItem *item = g_ptr_array_index (items, i); if (unity_gtk_menu_item_is_visible (item) && unity_gtk_menu_item_is_separator (item)) g_sequence_append (shell->separator_indices, GUINT_TO_POINTER (i)); } } return shell->separator_indices; } void unity_gtk_menu_shell_handle_item_notify (UnityGtkMenuShell *shell, UnityGtkMenuItem *item, const gchar *property) { static const gchar *visible_name; static const gchar *sensitive_name; static const gchar *label_name; static const gchar *use_underline_name; static const gchar *accel_path_name; static const gchar *active_name; static const gchar *parent_name; static const gchar *submenu_name; const gchar *name; g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); if (G_UNLIKELY (visible_name == NULL)) visible_name = g_intern_static_string ("visible"); if (G_UNLIKELY (sensitive_name == NULL)) sensitive_name = g_intern_static_string ("sensitive"); if (G_UNLIKELY (label_name == NULL)) label_name = g_intern_static_string ("label"); if (G_UNLIKELY (use_underline_name == NULL)) use_underline_name = g_intern_static_string ("use-underline"); if (G_UNLIKELY (accel_path_name == NULL)) accel_path_name = g_intern_static_string ("accel-path"); if (G_UNLIKELY (active_name == NULL)) active_name = g_intern_static_string ("active"); if (G_UNLIKELY (parent_name == NULL)) parent_name = g_intern_static_string ("parent"); if (G_UNLIKELY (submenu_name == NULL)) submenu_name = g_intern_static_string ("submenu"); name = g_intern_string (property); if (unity_gtk_menu_shell_is_debug ()) g_print ("%s ((%s *) %p, (%s *) %p { \"%s\" }, %s)\n", G_STRFUNC, G_OBJECT_TYPE_NAME (shell), shell, G_OBJECT_TYPE_NAME (item), item, unity_gtk_menu_item_get_label (item), name); if (name == visible_name) unity_gtk_menu_shell_handle_item_visible (shell, item); else if (name == sensitive_name) unity_gtk_menu_shell_handle_item_sensitive (shell, item); else if (name == label_name) unity_gtk_menu_shell_handle_item_label (shell, item); else if (name == use_underline_name) unity_gtk_menu_shell_handle_item_use_underline (shell, item); else if (name == accel_path_name) unity_gtk_menu_shell_handle_item_accel_path (shell, item); else if (name == active_name) unity_gtk_menu_shell_handle_item_active (shell, item); else if (name == parent_name) unity_gtk_menu_shell_handle_item_parent (shell, item); else if (name == submenu_name) unity_gtk_menu_shell_handle_item_submenu (shell, item); } void unity_gtk_menu_shell_activate_item (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); if (item->menu_item != NULL) { if (GTK_IS_MENU (shell->menu_shell)) gtk_menu_set_active (GTK_MENU (shell->menu_shell), item->item_index); /* * We dispatch the menu item activation in an idle to fix LP: #1258669. * * We get a deadlock when the menu item is activated if something like * gtk_dialog_run () is called. gtk_dialog_run () releases the GDK lock * just before starting its own main loop, and tries to re-acquire it * once it terminates. For whatever reason, a direct call to * gtk_menu_item_activate () here causes the GDK lock to be acquired * before gtk_dialog_run () tries to acquire it, whereas dispatching it * using gdk_threads_add_idle_full () seems to cleanly acquire the lock * once only at the beginning, preventing the deadlock. * * Suspicion is that this was executing during the main context * iteration of gtk_main_iteration (), which grabs the GDK lock * immediately after. But it's still not clear how that's possible.... */ gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE, gtk_menu_item_handle_idle_activate, g_object_ref (item->menu_item), g_object_unref); } } void unity_gtk_menu_shell_print (UnityGtkMenuShell *shell, guint indent) { gchar *space; g_return_if_fail (shell == NULL || UNITY_GTK_IS_MENU_SHELL (shell)); space = g_strnfill (indent, ' '); if (shell != NULL) { g_print ("%s(%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (shell)), shell); if (shell->menu_shell != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (shell->menu_shell)), shell->menu_shell); if (shell->items != NULL) { guint i; for (i = 0; i < shell->items->len; i++) unity_gtk_menu_item_print (g_ptr_array_index (shell->items, i), indent + 2); } if (shell->sections != NULL) { guint i; for (i = 0; i < shell->sections->len; i++) unity_gtk_menu_section_print (g_ptr_array_index (shell->sections, i), indent + 2); } if (shell->visible_indices != NULL) { GSequenceIter *iter = g_sequence_get_begin_iter (shell->visible_indices); g_print ("%s ", space); while (!g_sequence_iter_is_end (iter)) { g_print (" %u", g_sequence_get_uint (iter)); iter = g_sequence_iter_next (iter); } g_print ("\n"); } if (shell->separator_indices != NULL) { GSequenceIter *iter = g_sequence_get_begin_iter (shell->separator_indices); g_print ("%s ", space); while (!g_sequence_iter_is_end (iter)) { g_print (" %u", g_sequence_get_uint (iter)); iter = g_sequence_iter_next (iter); } g_print ("\n"); } if (shell->action_group != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (shell->action_group)), shell->action_group); } else g_print ("%sNULL\n", space); g_free (space); } gboolean unity_gtk_menu_shell_is_debug (void) { return unity_gtk_menu_shell_debug; } /** * unity_gtk_menu_shell_set_debug: * @debug: #TRUE to enable debugging output * * Sets if menu shell changes should be logged using g_print (). */ void unity_gtk_menu_shell_set_debug (gboolean debug) { unity_gtk_menu_shell_debug = debug; } ./lib/unity-gtk-menu-item-private.h0000644000004100000410000001101013210416612017450 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_MENU_ITEM_PRIVATE_H__ #define __UNITY_GTK_MENU_ITEM_PRIVATE_H__ #include G_BEGIN_DECLS typedef struct _UnityGtkMenuItem UnityGtkMenuItem; typedef GObjectClass UnityGtkMenuItemClass; #define UNITY_GTK_TYPE_MENU_ITEM (unity_gtk_menu_item_get_type ()) #define UNITY_GTK_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_GTK_TYPE_MENU_ITEM, UnityGtkMenuItem)) #define UNITY_GTK_IS_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_GTK_TYPE_MENU_ITEM)) #define UNITY_GTK_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_GTK_TYPE_MENU_ITEM, UnityGtkMenuItemClass)) #define UNITY_GTK_IS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_GTK_TYPE_MENU_ITEM)) #define UNITY_GTK_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_GTK_TYPE_MENU_ITEM, UnityGtkMenuItemClass)) G_END_DECLS #include "unity-gtk-menu-shell-private.h" #include "unity-gtk-action-private.h" G_BEGIN_DECLS struct _UnityGtkMenuItem { GObject parent_instance; /*< private >*/ GtkMenuItem *menu_item; UnityGtkMenuShell *parent_shell; UnityGtkMenuShell *child_shell; guchar child_shell_valid : 1; guint item_index; UnityGtkAction *action; GtkLabel *first_label; GtkLabel *second_label; gchar *label_label; }; GType unity_gtk_menu_item_get_type (void) G_GNUC_INTERNAL; UnityGtkMenuItem * unity_gtk_menu_item_new (GtkMenuItem *menu_item, UnityGtkMenuShell *parent_shell, guint item_index) G_GNUC_INTERNAL; UnityGtkMenuShell * unity_gtk_menu_item_get_child_shell (UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_menu_item_set_action (UnityGtkMenuItem *item, UnityGtkAction *action) G_GNUC_INTERNAL; const gchar * unity_gtk_menu_item_get_label (UnityGtkMenuItem *item) G_GNUC_INTERNAL; GIcon * unity_gtk_menu_item_get_icon (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_visible (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_sensitive (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_active (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_separator (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_check (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_is_radio (UnityGtkMenuItem *item) G_GNUC_INTERNAL; gboolean unity_gtk_menu_item_get_draw_as_radio (UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_menu_item_activate (UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_menu_item_print (UnityGtkMenuItem *item, guint indent) G_GNUC_INTERNAL; GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item, guint index) G_GNUC_INTERNAL; const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item, guint index) G_GNUC_INTERNAL; G_END_DECLS #endif /* __UNITY_GTK_MENU_ITEM_PRIVATE_H__ */ ./lib/unity-gtk-parser.h0000644000004100000410000000164013210416612015404 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_PARSER_H__ #define __UNITY_GTK_PARSER_H__ #include #include #endif /* __UNITY_GTK_PARSER_H__ */ ./lib/unity-gtk-menu-shell.h0000644000004100000410000000456113210416612016166 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_MENU_SHELL_H__ #define __UNITY_GTK_MENU_SHELL_H__ #include G_BEGIN_DECLS typedef struct _UnityGtkMenuShell UnityGtkMenuShell; typedef GMenuModelClass UnityGtkMenuShellClass; #define UNITY_GTK_TYPE_MENU_SHELL (unity_gtk_menu_shell_get_type ()) #define UNITY_GTK_MENU_SHELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_GTK_TYPE_MENU_SHELL, UnityGtkMenuShell)) #define UNITY_GTK_IS_MENU_SHELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_GTK_TYPE_MENU_SHELL)) #define UNITY_GTK_MENU_SHELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_GTK_TYPE_MENU_SHELL, UnityGtkMenuShellClass)) #define UNITY_GTK_IS_MENU_SHELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_GTK_TYPE_MENU_SHELL)) #define UNITY_GTK_MENU_SHELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_GTK_TYPE_MENU_SHELL, UnityGtkMenuShellClass)) G_END_DECLS #include "unity-gtk-action-group.h" G_BEGIN_DECLS /** * UnityGtkMenuShell: * * Opaque #GMenuModel proxy for #GtkMenuShell. */ struct _UnityGtkMenuShell { GMenuModel parent_instance; /*< private >*/ GtkMenuShell *menu_shell; gboolean has_mnemonics; GPtrArray *items; GPtrArray *sections; GSequence *visible_indices; GSequence *separator_indices; UnityGtkActionGroup *action_group; }; GType unity_gtk_menu_shell_get_type (void); UnityGtkMenuShell * unity_gtk_menu_shell_new (GtkMenuShell *menu_shell); void unity_gtk_menu_shell_set_debug (gboolean debug); G_END_DECLS #endif /* __UNITY_GTK_MENU_SHELL_H__ */ ./lib/unity-gtk-action.c0000644000004100000410000001042013210416612015354 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #include "unity-gtk-action-private.h" G_DEFINE_TYPE (UnityGtkAction, unity_gtk_action, G_TYPE_OBJECT); static void unity_gtk_action_dispose (GObject *object) { UnityGtkAction *action; GHashTable *items_by_name; g_return_if_fail (UNITY_GTK_IS_ACTION (object)); action = UNITY_GTK_ACTION (object); items_by_name = action->items_by_name; if (items_by_name != NULL) { action->items_by_name = NULL; g_hash_table_unref (items_by_name); } unity_gtk_action_set_item (action, NULL); unity_gtk_action_set_subname (action, NULL); unity_gtk_action_set_name (action, NULL); G_OBJECT_CLASS (unity_gtk_action_parent_class)->dispose (object); } static void unity_gtk_action_class_init (UnityGtkActionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = unity_gtk_action_dispose; } static void unity_gtk_action_init (UnityGtkAction *self) { } UnityGtkAction * unity_gtk_action_new (const gchar *name, UnityGtkMenuItem *item) { UnityGtkAction *action = g_object_new (UNITY_GTK_TYPE_ACTION, NULL); unity_gtk_action_set_name (action, name); unity_gtk_action_set_item (action, item); return action; } UnityGtkAction * unity_gtk_action_new_radio (const gchar *name) { UnityGtkAction *action = g_object_new (UNITY_GTK_TYPE_ACTION, NULL); unity_gtk_action_set_name (action, name); action->items_by_name = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); return action; } void unity_gtk_action_set_name (UnityGtkAction *action, const gchar *name) { g_return_if_fail (UNITY_GTK_IS_ACTION (action)); g_free (action->name); action->name = g_strdup (name); } void unity_gtk_action_set_subname (UnityGtkAction *action, const gchar *subname) { g_return_if_fail (UNITY_GTK_IS_ACTION (action)); g_free (action->subname); action->subname = g_strdup (subname); } void unity_gtk_action_set_item (UnityGtkAction *action, UnityGtkMenuItem *item) { UnityGtkMenuItem *old_item; g_return_if_fail (UNITY_GTK_IS_ACTION (action)); old_item = action->item; if (item != old_item) { if (old_item != NULL) { action->item = NULL; g_object_unref (old_item); } if (item != NULL) action->item = g_object_ref (item); } } void unity_gtk_action_print (UnityGtkAction *action, guint indent) { gchar *space; g_return_if_fail (action == NULL || UNITY_GTK_IS_ACTION (action)); space = g_strnfill (indent, ' '); if (action != NULL) { g_print ("%s(%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (action)), action); if (action->name != NULL) g_print ("%s \"%s\"\n", space, action->name); if (action->subname != NULL) g_print ("%s \"%s\"\n", space, action->subname); if (action->item != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (action->item)), action->item); if (action->items_by_name != NULL) { GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init (&iter, action->items_by_name); while (g_hash_table_iter_next (&iter, &key, &value)) g_print ("%s \"%s\" -> (%s *) %p\n", space, (const gchar *) key, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (value)), value); } } else g_print ("%sNULL\n", space); g_free (space); } ./lib/unity-gtk-menu-section-private.h0000644000004100000410000000564613210416612020200 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_MENU_SECTION_PRIVATE_H__ #define __UNITY_GTK_MENU_SECTION_PRIVATE_H__ #include G_BEGIN_DECLS typedef struct _UnityGtkMenuSection UnityGtkMenuSection; typedef GMenuModelClass UnityGtkMenuSectionClass; #define UNITY_GTK_TYPE_MENU_SECTION (unity_gtk_menu_section_get_type ()) #define UNITY_GTK_MENU_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_GTK_TYPE_MENU_SECTION, UnityGtkMenuSection)) #define UNITY_GTK_IS_MENU_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_GTK_TYPE_MENU_SECTION)) #define UNITY_GTK_MENU_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_GTK_TYPE_MENU_SECTION, UnityGtkMenuSectionClass)) #define UNITY_GTK_IS_MENU_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_GTK_TYPE_MENU_SECTION)) #define UNITY_GTK_MENU_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_GTK_TYPE_MENU_SECTION, UnityGtkMenuSectionClass)) G_END_DECLS #include "unity-gtk-menu-shell-private.h" G_BEGIN_DECLS struct _UnityGtkMenuSection { GMenuModel parent_instance; /*< private >*/ UnityGtkMenuShell *parent_shell; guint section_index; }; GType unity_gtk_menu_section_get_type (void) G_GNUC_INTERNAL; UnityGtkMenuSection * unity_gtk_menu_section_new (UnityGtkMenuShell *parent_shell, guint section_index) G_GNUC_INTERNAL; GSequenceIter * unity_gtk_menu_section_get_begin_iter (UnityGtkMenuSection *section) G_GNUC_INTERNAL; GSequenceIter * unity_gtk_menu_section_get_end_iter (UnityGtkMenuSection *section) G_GNUC_INTERNAL; GSequenceIter * unity_gtk_menu_section_get_iter (UnityGtkMenuSection *section, guint index) G_GNUC_INTERNAL; void unity_gtk_menu_section_print (UnityGtkMenuSection *section, guint indent) G_GNUC_INTERNAL; G_END_DECLS #endif /* __UNITY_GTK_MENU_SECTION_PRIVATE_H__ */ ./lib/unity-gtk-action-private.h0000644000004100000410000000557013210416612017043 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_ACTION_PRIVATE_H__ #define __UNITY_GTK_ACTION_PRIVATE_H__ #include G_BEGIN_DECLS typedef struct _UnityGtkAction UnityGtkAction; typedef GObjectClass UnityGtkActionClass; #define UNITY_GTK_TYPE_ACTION (unity_gtk_action_get_type ()) #define UNITY_GTK_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_GTK_TYPE_ACTION, UnityGtkAction)) #define UNITY_GTK_IS_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_GTK_TYPE_ACTION)) #define UNITY_GTK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_GTK_TYPE_ACTION, UnityGtkActionClass)) #define UNITY_GTK_IS_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_GTK_TYPE_ACTION)) #define UNITY_GTK_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_GTK_TYPE_ACTION, UnityGtkActionClass)) G_END_DECLS #include "unity-gtk-menu-item-private.h" G_BEGIN_DECLS struct _UnityGtkAction { GObject parent_instance; /*< private >*/ gchar *name; gchar *subname; UnityGtkMenuItem *item; GHashTable *items_by_name; }; GType unity_gtk_action_get_type (void) G_GNUC_INTERNAL; UnityGtkAction * unity_gtk_action_new (const gchar *name, UnityGtkMenuItem *item) G_GNUC_INTERNAL; UnityGtkAction * unity_gtk_action_new_radio (const gchar *name) G_GNUC_INTERNAL; void unity_gtk_action_set_name (UnityGtkAction *action, const gchar *name) G_GNUC_INTERNAL; void unity_gtk_action_set_subname (UnityGtkAction *action, const gchar *subname) G_GNUC_INTERNAL; void unity_gtk_action_set_item (UnityGtkAction *action, UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_action_print (UnityGtkAction *action, guint indent) G_GNUC_INTERNAL; G_END_DECLS #endif /* __UNITY_GTK_ACTION_PRIVATE_H__ */ ./lib/unity-gtk-menu-section.c0000644000004100000410000003075413210416612016521 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #include "unity-gtk-menu-section-private.h" #ifndef G_MENU_ATTRIBUTE_ACCEL #define G_MENU_ATTRIBUTE_ACCEL "accel" #endif #ifndef G_MENU_ATTRIBUTE_ACCEL_TEXT #define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel" #endif #ifndef G_MENU_ATTRIBUTE_SUBMENU_ACTION #define G_MENU_ATTRIBUTE_SUBMENU_ACTION "submenu-action" #endif G_DEFINE_TYPE (UnityGtkMenuSection, unity_gtk_menu_section, G_TYPE_MENU_MODEL); static gint g_uintcmp (gconstpointer a, gconstpointer b, gpointer user_data) { return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b); } static gboolean g_closure_equal (GtkAccelKey *key, GClosure *closure, gpointer data) { return closure == data; } static void unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section, UnityGtkMenuShell *parent_shell) { g_return_if_fail (UNITY_GTK_IS_MENU_SECTION (section)); section->parent_shell = parent_shell; } static void unity_gtk_menu_section_dispose (GObject *object) { UnityGtkMenuSection *section; g_return_if_fail (UNITY_GTK_IS_MENU_SECTION (object)); section = UNITY_GTK_MENU_SECTION (object); unity_gtk_menu_section_set_parent_shell (section, NULL); G_OBJECT_CLASS (unity_gtk_menu_section_parent_class)->dispose (object); } static gboolean unity_gtk_menu_section_is_mutable (GMenuModel *model) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SECTION (model), TRUE); return TRUE; } static gint unity_gtk_menu_section_get_n_items (GMenuModel *model) { UnityGtkMenuSection *section; GSequenceIter *begin; GSequenceIter *end; g_return_val_if_fail (UNITY_GTK_IS_MENU_SECTION (model), 0); section = UNITY_GTK_MENU_SECTION (model); begin = unity_gtk_menu_section_get_begin_iter (section); end = unity_gtk_menu_section_get_end_iter (section); g_return_val_if_fail (begin != NULL && end != NULL, 0); return g_sequence_iter_get_position (end) - g_sequence_iter_get_position (begin); } static void unity_gtk_menu_section_get_item_attributes (GMenuModel *model, gint item_index, GHashTable **attributes) { UnityGtkMenuSection *section; UnityGtkMenuShell *parent_shell; UnityGtkMenuItem *item; GSequenceIter *iter; guint index; const gchar *label; GIcon *icon; UnityGtkAction *action; g_return_if_fail (UNITY_GTK_IS_MENU_SECTION (model)); g_return_if_fail (attributes != NULL); section = UNITY_GTK_MENU_SECTION (model); parent_shell = section->parent_shell; g_return_if_fail (parent_shell != NULL); iter = unity_gtk_menu_section_get_iter (section, item_index); index = GPOINTER_TO_UINT (g_sequence_get (iter)); item = unity_gtk_menu_shell_get_item (parent_shell, index); label = unity_gtk_menu_item_get_label (item); icon = unity_gtk_menu_item_get_icon (item); action = item->action; *attributes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref); if (label != NULL) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_LABEL, g_variant_ref_sink (g_variant_new_string (label))); if (icon != NULL) { g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ICON, g_icon_serialize (icon)); g_object_unref (icon); } if (action != NULL) { if (action->name != NULL) { gchar *name = g_strdup_printf ("unity.%s", action->name); GVariant *variant = g_variant_ref_sink (g_variant_new_string (name)); g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACTION, variant); if (action->items_by_name != NULL) { GHashTableIter iter; gpointer key; gpointer value; const gchar *target = NULL; g_hash_table_iter_init (&iter, action->items_by_name); while (target == NULL && g_hash_table_iter_next (&iter, &key, &value)) if (value == item) target = key; if (target != NULL) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (target))); } else if (unity_gtk_menu_item_get_draw_as_radio (item)) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_TARGET, g_variant_ref_sink (g_variant_new_string (action->name))); g_free (name); } if (action->subname != NULL) { gchar *subname = g_strdup_printf ("unity.%s", action->subname); GVariant *variant = g_variant_ref_sink (g_variant_new_string (subname)); g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_SUBMENU_ACTION, variant); g_free (subname); } } if (item->menu_item != NULL) { gchar *accel_name = NULL; const gchar *accel_path = gtk_menu_item_get_accel_path (item->menu_item); if (accel_path != NULL) { GtkAccelKey accel_key; if (gtk_accel_map_lookup_entry (accel_path, &accel_key)) accel_name = gtk_accelerator_name (accel_key.accel_key, accel_key.accel_mods); } if (accel_name == NULL) { GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item)); GList *iter; for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter)) { GClosure *closure = iter->data; GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure); if (accel_group != NULL) { GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure); if (accel_key != NULL) accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods); } } g_list_free (closures); } if (accel_name != NULL) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name))); else { #if GTK_MAJOR_VERSION == 2 /* LP: #1208019 */ GtkLabel *accel_label = gtk_menu_item_get_nth_label (item->menu_item, 0); if (GTK_IS_ACCEL_LABEL (accel_label)) { /* Eclipse uses private API. */ if (GTK_ACCEL_LABEL (accel_label)->accel_string != NULL) accel_name = g_strdup (GTK_ACCEL_LABEL (accel_label)->accel_string); } #endif if (accel_name == NULL) accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1)); if (accel_name != NULL) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL_TEXT, g_variant_ref_sink (g_variant_new_string (accel_name))); } g_free (accel_name); } } static void unity_gtk_menu_section_get_item_links (GMenuModel *model, gint item_index, GHashTable **links) { UnityGtkMenuSection *section; UnityGtkMenuShell *parent_shell; UnityGtkMenuItem *item; GSequenceIter *iter; guint index; UnityGtkMenuShell *child_shell; g_return_if_fail (UNITY_GTK_IS_MENU_SECTION (model)); g_return_if_fail (links != NULL); section = UNITY_GTK_MENU_SECTION (model); parent_shell = section->parent_shell; g_return_if_fail (parent_shell != NULL); iter = unity_gtk_menu_section_get_iter (section, item_index); index = GPOINTER_TO_UINT (g_sequence_get (iter)); item = unity_gtk_menu_shell_get_item (parent_shell, index); child_shell = unity_gtk_menu_item_get_child_shell (item); *links = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); if (child_shell != NULL) g_hash_table_insert (*links, G_MENU_LINK_SUBMENU, g_object_ref (child_shell)); } static void unity_gtk_menu_section_class_init (UnityGtkMenuSectionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GMenuModelClass *menu_model_class = G_MENU_MODEL_CLASS (klass); object_class->dispose = unity_gtk_menu_section_dispose; menu_model_class->is_mutable = unity_gtk_menu_section_is_mutable; menu_model_class->get_n_items = unity_gtk_menu_section_get_n_items; menu_model_class->get_item_attributes = unity_gtk_menu_section_get_item_attributes; menu_model_class->get_item_links = unity_gtk_menu_section_get_item_links; } static void unity_gtk_menu_section_init (UnityGtkMenuSection *self) { } UnityGtkMenuSection * unity_gtk_menu_section_new (UnityGtkMenuShell *parent_shell, guint section_index) { UnityGtkMenuSection *section = g_object_new (UNITY_GTK_TYPE_MENU_SECTION, NULL); unity_gtk_menu_section_set_parent_shell (section, parent_shell); section->section_index = section_index; return section; } GSequenceIter * unity_gtk_menu_section_get_begin_iter (UnityGtkMenuSection *section) { UnityGtkMenuShell *parent_shell; GSequence *separator_indices; GSequence *visible_indices; GSequenceIter *separator_iter; GSequenceIter *visible_iter; guint section_index; g_return_val_if_fail (UNITY_GTK_IS_MENU_SECTION (section), NULL); parent_shell = section->parent_shell; g_return_val_if_fail (parent_shell != NULL, NULL); separator_indices = unity_gtk_menu_shell_get_separator_indices (parent_shell); visible_indices = unity_gtk_menu_shell_get_visible_indices (parent_shell); section_index = section->section_index; if (section_index > 0) separator_iter = g_sequence_get_iter_at_pos (separator_indices, section_index - 1); else separator_iter = NULL; if (separator_iter != NULL) { gpointer separator_index = g_sequence_get (separator_iter); visible_iter = g_sequence_lookup (visible_indices, separator_index, g_uintcmp, NULL); visible_iter = g_sequence_iter_next (visible_iter); } else visible_iter = g_sequence_get_begin_iter (visible_indices); return visible_iter; } GSequenceIter * unity_gtk_menu_section_get_end_iter (UnityGtkMenuSection *section) { UnityGtkMenuShell *parent_shell; GSequence *separator_indices; GSequence *visible_indices; GSequenceIter *separator_iter; GSequenceIter *visible_iter; g_return_val_if_fail (UNITY_GTK_IS_MENU_SECTION (section), NULL); parent_shell = section->parent_shell; g_return_val_if_fail (parent_shell != NULL, NULL); separator_indices = unity_gtk_menu_shell_get_separator_indices (parent_shell); visible_indices = unity_gtk_menu_shell_get_visible_indices (parent_shell); separator_iter = g_sequence_get_iter_at_pos (separator_indices, section->section_index); if (g_sequence_iter_is_end (separator_iter)) separator_iter = NULL; if (separator_iter != NULL) visible_iter = g_sequence_lookup (visible_indices, g_sequence_get (separator_iter), g_uintcmp, NULL); else visible_iter = g_sequence_get_end_iter (visible_indices); return visible_iter; } GSequenceIter * unity_gtk_menu_section_get_iter (UnityGtkMenuSection *section, guint index) { g_return_val_if_fail (UNITY_GTK_IS_MENU_SECTION (section), NULL); return g_sequence_iter_move (unity_gtk_menu_section_get_begin_iter (section), index); } void unity_gtk_menu_section_print (UnityGtkMenuSection *section, guint indent) { gchar *space; g_return_if_fail (section == NULL || UNITY_GTK_IS_MENU_SECTION (section)); space = g_strnfill (indent, ' '); if (section != NULL) { g_print ("%s%u (%s *) %p\n", space, section->section_index, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (section)), section); if (section->parent_shell != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (section->parent_shell)), section->parent_shell); } else g_print ("%sNULL\n", space); g_free (space); } ./lib/unity-gtk-menu-shell-private.h0000644000004100000410000000450713210416612017636 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_MENU_SHELL_PRIVATE_H__ #define __UNITY_GTK_MENU_SHELL_PRIVATE_H__ #include #include "unity-gtk-menu-shell.h" #include "unity-gtk-menu-item-private.h" G_BEGIN_DECLS UnityGtkMenuShell * unity_gtk_menu_shell_new_internal (GtkMenuShell *menu_shell) G_GNUC_INTERNAL; UnityGtkMenuItem * unity_gtk_menu_shell_get_item (UnityGtkMenuShell *shell, guint index) G_GNUC_INTERNAL; GSequence * unity_gtk_menu_shell_get_visible_indices (UnityGtkMenuShell *shell) G_GNUC_INTERNAL; GSequence * unity_gtk_menu_shell_get_separator_indices (UnityGtkMenuShell *shell) G_GNUC_INTERNAL; void unity_gtk_menu_shell_handle_item_notify (UnityGtkMenuShell *shell, UnityGtkMenuItem *item, const gchar *property) G_GNUC_INTERNAL; void unity_gtk_menu_shell_activate_item (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) G_GNUC_INTERNAL; void unity_gtk_menu_shell_print (UnityGtkMenuShell *shell, guint indent) G_GNUC_INTERNAL; gboolean unity_gtk_menu_shell_is_debug (void) G_GNUC_INTERNAL; G_END_DECLS #endif /* __UNITY_GTK_MENU_SHELL_PRIVATE_H__ */ ./lib/unity-gtk-menu-item.c0000644000004100000410000005717713210416612016023 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #include "unity-gtk-menu-item-private.h" #include "unity-gtk-action-group-private.h" #include G_DEFINE_TYPE (UnityGtkMenuItem, unity_gtk_menu_item, G_TYPE_OBJECT); typedef struct _UnityGtkSearch UnityGtkSearch; struct _UnityGtkSearch { GType type; guint index; GObject *object; }; static void g_object_get_nth_object (GObject *object, gpointer data) { UnityGtkSearch *search = data; g_return_if_fail (G_IS_OBJECT (object)); if (search->object == NULL) { if (g_type_is_a (G_OBJECT_TYPE (object), search->type)) { if (search->index == 0) search->object = object; else search->index--; } if (search->object == NULL && GTK_IS_CONTAINER (object)) gtk_container_forall (GTK_CONTAINER (object), (GtkCallback) g_object_get_nth_object, data); } } GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item, guint index) { UnityGtkSearch search; g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL); search.type = GTK_TYPE_LABEL; search.index = index; search.object = NULL; g_object_get_nth_object (G_OBJECT (menu_item), &search); return search.object != NULL ? GTK_LABEL (search.object) : NULL; } const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item, guint index) { GtkLabel *label; const gchar *label_label; g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL); label = gtk_menu_item_get_nth_label (menu_item, index); label_label = NULL; if (label != NULL) label_label = gtk_label_get_label (label); return label_label != NULL && label_label[0] != '\0' ? label_label : NULL; } static GtkImage * gtk_menu_item_get_nth_image (GtkMenuItem *menu_item, guint index) { UnityGtkSearch search; g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL); search.type = GTK_TYPE_IMAGE; search.index = index; search.object = NULL; g_object_get_nth_object (G_OBJECT (menu_item), &search); return search.object != NULL ? GTK_IMAGE (search.object) : NULL; } static GIcon * gtk_image_get_icon (GtkImage *image) { GIcon *icon = NULL; g_return_val_if_fail (GTK_IS_IMAGE (image), NULL); switch (gtk_image_get_storage_type (image)) { case GTK_IMAGE_GICON: { gtk_image_get_gicon (image, &icon, NULL); if (icon != NULL) g_object_ref (icon); } break; case GTK_IMAGE_ICON_NAME: { const gchar *name = NULL; gtk_image_get_icon_name (image, &name, NULL); if (name != NULL) icon = G_ICON (g_themed_icon_new_with_default_fallbacks (name)); } break; case GTK_IMAGE_PIXBUF: { GdkPixbuf *pixbuf = gtk_image_get_pixbuf (image); if (pixbuf != NULL) icon = g_object_ref (pixbuf); } break; case GTK_IMAGE_ANIMATION: { GdkPixbufAnimation *animation = gtk_image_get_animation (image); if (animation != NULL) { GdkPixbuf *pixbuf = gdk_pixbuf_animation_get_static_image (animation); if (pixbuf != NULL) icon = g_object_ref (pixbuf); } } break; case GTK_IMAGE_STOCK: #if GTK_MAJOR_VERSION == 2 { gchar *stock = NULL; GtkIconSize size = GTK_ICON_SIZE_INVALID; gtk_image_get_stock (image, &stock, &size); if (stock != NULL) { GdkPixbuf *pixbuf = gtk_widget_render_icon (GTK_WIDGET (image), stock, size, NULL); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } #elif GTK_MAJOR_VERSION == 3 { GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (image)); if (context != NULL) { gchar *stock = NULL; GtkIconSize size = GTK_ICON_SIZE_INVALID; gtk_image_get_stock (image, &stock, &size); if (stock != NULL) { GtkIconSet *set = gtk_style_context_lookup_icon_set (context, stock); if (set != NULL) { GdkPixbuf *pixbuf = gtk_icon_set_render_icon_pixbuf (set, context, size); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } } } #endif break; case GTK_IMAGE_ICON_SET: #if GTK_MAJOR_VERSION == 2 { GtkIconSet *set = NULL; GtkIconSize size = GTK_ICON_SIZE_INVALID; gtk_image_get_icon_set (image, &set, &size); if (set != NULL) { GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (image)); GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (image)); GtkStateType state = gtk_widget_get_state (GTK_WIDGET (image)); GdkPixbuf *pixbuf = gtk_icon_set_render_icon (set, style, direction, state, size, GTK_WIDGET (image), NULL); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } #elif GTK_MAJOR_VERSION == 3 { GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (image)); if (context != NULL) { GtkIconSet *set = NULL; GtkIconSize size = GTK_ICON_SIZE_INVALID; gtk_image_get_icon_set (image, &set, &size); if (set != NULL) { GdkPixbuf *pixbuf = gtk_icon_set_render_icon_pixbuf (set, context, size); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } } #endif break; #if GTK_MAJOR_VERSION == 2 case GTK_IMAGE_IMAGE: { GdkImage *gdk_image = NULL; gtk_image_get_image (image, &gdk_image, NULL); if (gdk_image != NULL) { GdkColormap *colourmap = gtk_widget_get_colormap (GTK_WIDGET (image)); GdkPixbuf *pixbuf = gdk_pixbuf_get_from_image (NULL, gdk_image, colourmap, 0, 0, 0, 0, gdk_image->width, gdk_image->height); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } break; case GTK_IMAGE_PIXMAP: { GdkPixmap *pixmap = NULL; gtk_image_get_pixmap (image, &pixmap, NULL); if (pixmap != NULL) { GdkPixbuf *pixbuf; GdkColormap *colourmap; gint width = 0; gint height = 0; gdk_pixmap_get_size (pixmap, &width, &height); colourmap = gtk_widget_get_colormap (GTK_WIDGET (image)); pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colourmap, 0, 0, 0, 0, width, height); if (pixbuf != NULL) icon = G_ICON (pixbuf); } } break; #endif default: break; } return icon; } static void unity_gtk_menu_item_handle_item_notify (GObject *object, GParamSpec *pspec, gpointer user_data) { static const gchar *label_name; static const gchar *use_underline_name; UnityGtkMenuItem *item; UnityGtkMenuShell *parent_shell; GObject *menu_item; const gchar *name; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data)); item = UNITY_GTK_MENU_ITEM (user_data); parent_shell = item->parent_shell; menu_item = G_OBJECT (item->menu_item); g_return_if_fail (parent_shell != NULL); g_warn_if_fail (object == menu_item); if (G_UNLIKELY (label_name == NULL)) label_name = g_intern_static_string ("label"); if (G_UNLIKELY (use_underline_name == NULL)) use_underline_name = g_intern_static_string ("use-underline"); name = g_param_spec_get_name (pspec); if (name != label_name && name != use_underline_name) unity_gtk_menu_shell_handle_item_notify (parent_shell, item, name); } static void unity_gtk_menu_item_handle_label_notify (GObject *object, GParamSpec *pspec, gpointer user_data) { static const gchar *label_name; static const gchar *use_underline_name; UnityGtkMenuItem *item; UnityGtkMenuShell *parent_shell; const gchar *name; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data)); item = UNITY_GTK_MENU_ITEM (user_data); parent_shell = item->parent_shell; g_return_if_fail (parent_shell != NULL); if (G_UNLIKELY (label_name == NULL)) label_name = g_intern_static_string ("label"); if (G_UNLIKELY (use_underline_name == NULL)) use_underline_name = g_intern_static_string ("use-underline"); name = g_param_spec_get_name (pspec); if (name == label_name || name == use_underline_name) unity_gtk_menu_shell_handle_item_notify (parent_shell, item, name); } static void unity_gtk_menu_item_disconnect_labels (UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); if (item->second_label != NULL) { g_signal_handlers_disconnect_by_data (item->second_label, item); item->second_label = NULL; } if (item->first_label != NULL) { g_signal_handlers_disconnect_by_data (item->first_label, item); item->first_label = NULL; } } static gboolean unity_gtk_menu_item_connect_labels (UnityGtkMenuItem *item) { GtkLabel *first_label = NULL; GtkLabel *second_label = NULL; g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); if (item->menu_item != NULL) { /* ensure label is available */ gtk_menu_item_get_label (item->menu_item); first_label = gtk_menu_item_get_nth_label (item->menu_item, 0); second_label = gtk_menu_item_get_nth_label (item->menu_item, 1); } if (first_label != item->first_label || second_label != item->second_label) { unity_gtk_menu_item_disconnect_labels (item); item->first_label = first_label; item->second_label = second_label; if (item->first_label != NULL) g_signal_connect (item->first_label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item); if (item->second_label != NULL) g_signal_connect (item->second_label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item); return TRUE; } return FALSE; } static void unity_gtk_menu_item_handle_add_or_remove (GtkContainer *container, GtkWidget *widget, gpointer user_data) { UnityGtkMenuItem *item; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data)); item = UNITY_GTK_MENU_ITEM (user_data); /* just ignore the case when parent_shell is NULL */ if (item->parent_shell != NULL && unity_gtk_menu_item_connect_labels (item)) unity_gtk_menu_shell_handle_item_notify (item->parent_shell, item, "label"); } static void unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget, gpointer user_data) { UnityGtkMenuItem *item; UnityGtkMenuShell *parent_shell; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data)); item = UNITY_GTK_MENU_ITEM (user_data); parent_shell = item->parent_shell; g_return_if_fail (parent_shell != NULL); unity_gtk_menu_shell_handle_item_notify (parent_shell, item, "accel-path"); } static void unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item, GtkMenuItem *menu_item) { g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); if (menu_item != item->menu_item) { UnityGtkMenuShell *child_shell = item->child_shell; unity_gtk_menu_item_disconnect_labels (item); if (item->menu_item != NULL) g_signal_handlers_disconnect_by_data (item->menu_item, item); if (child_shell != NULL) { g_warn_if_fail (item->child_shell_valid); item->child_shell = NULL; g_object_unref (child_shell); } item->child_shell_valid = FALSE; item->menu_item = menu_item; if (menu_item != NULL) { g_signal_connect (menu_item, "notify", G_CALLBACK (unity_gtk_menu_item_handle_item_notify), item); g_signal_connect (menu_item, "add", G_CALLBACK (unity_gtk_menu_item_handle_add_or_remove), item); g_signal_connect (menu_item, "remove", G_CALLBACK (unity_gtk_menu_item_handle_add_or_remove), item); g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item); /* * LP: #1208019: We do this because Eclipse sets menu item * accelerators using private API, and there's no way for us to * detect when they change. */ if (gtk_menu_item_get_submenu (menu_item) != NULL) g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show"); } unity_gtk_menu_item_connect_labels (item); } } static void unity_gtk_menu_item_set_parent_shell (UnityGtkMenuItem *item, UnityGtkMenuShell *parent_shell) { g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); item->parent_shell = parent_shell; } static void unity_gtk_menu_item_dispose (GObject *object) { UnityGtkMenuItem *item; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (object)); item = UNITY_GTK_MENU_ITEM (object); unity_gtk_menu_item_set_action (item, NULL); unity_gtk_menu_item_set_parent_shell (item, NULL); unity_gtk_menu_item_set_menu_item (item, NULL); G_OBJECT_CLASS (unity_gtk_menu_item_parent_class)->dispose (object); } static void unity_gtk_menu_item_finalize (GObject *object) { UnityGtkMenuItem *item; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (object)); item = UNITY_GTK_MENU_ITEM (object); g_free (item->label_label); item->label_label = NULL; G_OBJECT_CLASS (unity_gtk_menu_item_parent_class)->finalize (object); } static void unity_gtk_menu_item_class_init (UnityGtkMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = unity_gtk_menu_item_dispose; object_class->finalize = unity_gtk_menu_item_finalize; } static void unity_gtk_menu_item_init (UnityGtkMenuItem *self) { } UnityGtkMenuItem * unity_gtk_menu_item_new (GtkMenuItem *menu_item, UnityGtkMenuShell *parent_shell, guint item_index) { UnityGtkMenuItem *item = g_object_new (UNITY_GTK_TYPE_MENU_ITEM, NULL); unity_gtk_menu_item_set_menu_item (item, menu_item); unity_gtk_menu_item_set_parent_shell (item, parent_shell); item->item_index = item_index; return item; } UnityGtkMenuShell * unity_gtk_menu_item_get_child_shell (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL); if (!item->child_shell_valid) { GtkMenuItem *menu_item = item->menu_item; UnityGtkMenuShell *child_shell = item->child_shell; if (child_shell != NULL) { g_warn_if_reached (); item->child_shell = NULL; g_object_unref (child_shell); } if (menu_item != NULL) { GtkWidget *submenu = gtk_menu_item_get_submenu (menu_item); if (submenu != NULL) item->child_shell = unity_gtk_menu_shell_new_internal (GTK_MENU_SHELL (submenu)); } item->child_shell_valid = TRUE; if (unity_gtk_menu_item_is_visible (item) && item->child_shell != NULL) { UnityGtkMenuShell *parent_shell = item->parent_shell; if (parent_shell != NULL) { if (parent_shell->action_group != NULL) unity_gtk_action_group_connect_shell (parent_shell->action_group, item->child_shell); } else g_warn_if_reached (); } } return item->child_shell; } void unity_gtk_menu_item_set_action (UnityGtkMenuItem *item, UnityGtkAction *action) { UnityGtkAction *old_action; g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); old_action = item->action; if (action != old_action) { if (old_action != NULL) { item->action = NULL; g_object_unref (old_action); } if (action != NULL) item->action = g_object_ref (action); } } static gchar * g_strdup_no_mnemonics (const gchar *str) { if (str != NULL) { gchar *string; gchar *out; const gchar *in; gboolean underscore; string = g_malloc (strlen (str) + 1); out = string; underscore = FALSE; for (in = str; *in != '\0'; in++) { if (*in != '_') { underscore = FALSE; *out++ = *in; } else { if (!underscore) underscore = TRUE; else { /* double underscores are not accelerator markers */ underscore = FALSE; *out++ = '_'; *out++ = '_'; } } } /* trailing underscores are not accelerator markers */ if (underscore) *out++ = '_'; *out++ = '\0'; return string; } return NULL; } static gchar * g_strdup_escape_underscores (const gchar *str) { if (str != NULL) { gchar *string; gchar *out; const gchar *in; guint underscores; underscores = 0; for (in = strchr (str, '_'); in != NULL; in = strchr (in + 1, '_')) underscores++; if (underscores == 0) return g_strdup (str); string = g_malloc (strlen (str) + underscores + 1); out = string; for (in = str; *in != '\0'; in++) { *out++ = *in; if (*in == '_') *out++ = '_'; } *out++ = '\0'; return string; } return NULL; } const gchar * unity_gtk_menu_item_get_label (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL); g_return_val_if_fail (item->menu_item != NULL, NULL); if (item->label_label == NULL) { const gchar *label_label = gtk_menu_item_get_label (item->menu_item); if (label_label != NULL && label_label[0] != '\0') { if (GTK_IS_IMAGE_MENU_ITEM (item->menu_item)) { GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (item->menu_item); if (gtk_image_menu_item_get_use_stock (image_menu_item)) { GtkStockItem stock_item; if (gtk_stock_lookup (label_label, &stock_item)) label_label = stock_item.label; } } } if (label_label == NULL || label_label[0] == '\0') label_label = gtk_menu_item_get_nth_label_label (item->menu_item, 0); if (label_label != NULL && label_label[0] != '\0') { GtkLabel *label = gtk_menu_item_get_nth_label (item->menu_item, 0); if (gtk_label_get_use_underline (label)) { if (item->parent_shell == NULL || item->parent_shell->has_mnemonics) item->label_label = g_strdup (label_label); else item->label_label = g_strdup_no_mnemonics (label_label); } else item->label_label = g_strdup_escape_underscores (label_label); } } return item->label_label; } GIcon * unity_gtk_menu_item_get_icon (UnityGtkMenuItem *item) { GIcon *icon = NULL; g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL); if (item->menu_item != NULL && !GTK_IS_IMAGE_MENU_ITEM (item->menu_item)) { GtkImage *image = gtk_menu_item_get_nth_image (item->menu_item, 0); if (image != NULL) icon = gtk_image_get_icon (image); } return icon; } gboolean unity_gtk_menu_item_is_visible (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return item->menu_item != NULL && gtk_widget_get_visible (GTK_WIDGET (item->menu_item)) && !GTK_IS_TEAROFF_MENU_ITEM (item->menu_item); } gboolean unity_gtk_menu_item_is_sensitive (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return item->menu_item != NULL && gtk_widget_is_sensitive (GTK_WIDGET (item->menu_item)); } gboolean unity_gtk_menu_item_is_active (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return GTK_IS_CHECK_MENU_ITEM (item->menu_item) && gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item->menu_item)); } gboolean unity_gtk_menu_item_is_separator (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return GTK_IS_SEPARATOR_MENU_ITEM (item->menu_item); } gboolean unity_gtk_menu_item_is_check (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return GTK_IS_CHECK_MENU_ITEM (item->menu_item); } gboolean unity_gtk_menu_item_is_radio (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return GTK_IS_RADIO_MENU_ITEM (item->menu_item); } gboolean unity_gtk_menu_item_get_draw_as_radio (UnityGtkMenuItem *item) { g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), FALSE); return GTK_IS_CHECK_MENU_ITEM (item->menu_item) && gtk_check_menu_item_get_draw_as_radio (GTK_CHECK_MENU_ITEM (item->menu_item)); } void unity_gtk_menu_item_activate (UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_return_if_fail (item->parent_shell != NULL); unity_gtk_menu_shell_activate_item (item->parent_shell, item); } void unity_gtk_menu_item_print (UnityGtkMenuItem *item, guint indent) { gchar *space; g_return_if_fail (item == NULL || UNITY_GTK_IS_MENU_ITEM (item)); space = g_strnfill (indent, ' '); if (item != NULL) { const gchar *label = unity_gtk_menu_item_get_label (item); if (label != NULL) g_print ("%s%u (%s *) %p \"%s\"\n", space, item->item_index, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (item)), item, label); else g_print ("%s%u (%s *) %p\n", space, item->item_index, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (item)), item); if (item->menu_item != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (item->menu_item)), item->menu_item); if (item->parent_shell != NULL) g_print ("%s (%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (item->parent_shell)), item->parent_shell); if (item->child_shell_valid || item->child_shell != NULL) { if (!item->child_shell_valid) g_print ("%s invalid\n", space); unity_gtk_menu_shell_print (item->child_shell, indent + 2); } if (item->action != NULL) unity_gtk_action_print (item->action, indent + 2); } else g_print ("%sNULL\n", space); g_free (space); } ./lib/unity-gtk-action-group.c0000644000004100000410000011657613210416612016531 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ /** * SECTION:unity-gtk-action-group * @short_description: Action group collector * @include: unity-gtk-parser.h * * A #UnityGtkActionGroup is a #GActionGroup that accumulates the * actions of multiple #UnityGtkMenuShells into a single object. * This can be used for purposes such as exporting actions over DBus * with g_dbus_connection_export_action_group (). */ #include "unity-gtk-action-group-private.h" #include "unity-gtk-action-private.h" #include static void unity_gtk_action_group_action_group_init (GActionGroupInterface *iface); G_DEFINE_TYPE_WITH_CODE (UnityGtkActionGroup, unity_gtk_action_group, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, unity_gtk_action_group_action_group_init)); static gboolean unity_gtk_action_group_debug; static gboolean g_signal_emit_hide (gpointer user_data) { g_signal_emit_by_name (user_data, "hide"); return G_SOURCE_REMOVE; } static void unity_gtk_action_group_handle_group_action_added (GActionGroup *action_group, gchar *action_name, gpointer user_data) { UnityGtkActionGroup *group; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (user_data)); group = UNITY_GTK_ACTION_GROUP (user_data); g_warn_if_fail (action_group == group->old_group); g_action_group_action_added (G_ACTION_GROUP (group), action_name); } static void unity_gtk_action_group_handle_group_action_removed (GActionGroup *action_group, gchar *action_name, gpointer user_data) { UnityGtkActionGroup *group; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (user_data)); group = UNITY_GTK_ACTION_GROUP (user_data); g_warn_if_fail (action_group == group->old_group); g_action_group_action_removed (G_ACTION_GROUP (group), action_name); } static void unity_gtk_action_group_handle_group_action_enabled_changed (GActionGroup *action_group, gchar *action_name, gboolean enabled, gpointer user_data) { UnityGtkActionGroup *group; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (user_data)); group = UNITY_GTK_ACTION_GROUP (user_data); g_warn_if_fail (action_group == group->old_group); g_action_group_action_enabled_changed (G_ACTION_GROUP (group), action_name, enabled); } static void unity_gtk_action_group_handle_group_action_state_changed (GActionGroup *action_group, gchar *action_name, GVariant *value, gpointer user_data) { UnityGtkActionGroup *group; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (user_data)); group = UNITY_GTK_ACTION_GROUP (user_data); g_warn_if_fail (action_group == group->old_group); g_action_group_action_state_changed (G_ACTION_GROUP (group), action_name, value); } static void unity_gtk_action_group_set_old_group (UnityGtkActionGroup *group, GActionGroup *old_group) { GActionGroup *old_old_group; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (group)); old_old_group = group->old_group; if (old_group != old_old_group) { if (old_old_group != NULL) { gchar **names; g_signal_handlers_disconnect_by_data (old_old_group, group); names = g_action_group_list_actions (old_old_group); group->old_group = NULL; g_object_unref (old_old_group); if (names != NULL) { gchar **i; for (i = names; *i != NULL; i++) g_action_group_action_removed (G_ACTION_GROUP (group), *i); g_strfreev (names); } } if (old_group != NULL) { gchar **names = g_action_group_list_actions (old_group); group->old_group = g_object_ref (old_group); g_signal_connect (old_group, "action-added", G_CALLBACK (unity_gtk_action_group_handle_group_action_added), group); g_signal_connect (old_group, "action-removed", G_CALLBACK (unity_gtk_action_group_handle_group_action_removed), group); g_signal_connect (old_group, "action-enabled-changed", G_CALLBACK (unity_gtk_action_group_handle_group_action_enabled_changed), group); g_signal_connect (old_group, "action-state-changed", G_CALLBACK (unity_gtk_action_group_handle_group_action_state_changed), group); if (names != NULL) { gchar **i; for (i = names; *i != NULL; i++) g_action_group_action_added (G_ACTION_GROUP (group), *i); g_strfreev (names); } } } } static void unity_gtk_action_group_dispose (GObject *object) { UnityGtkActionGroup *group; GHashTable *actions_by_name; GHashTable *names_by_radio_menu_item; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (object)); group = UNITY_GTK_ACTION_GROUP (object); actions_by_name = group->actions_by_name; names_by_radio_menu_item = group->names_by_radio_menu_item; if (names_by_radio_menu_item != NULL) { group->names_by_radio_menu_item = NULL; g_hash_table_unref (names_by_radio_menu_item); } if (actions_by_name != NULL) { group->actions_by_name = NULL; g_hash_table_unref (actions_by_name); } unity_gtk_action_group_set_old_group (group, NULL); G_OBJECT_CLASS (unity_gtk_action_group_parent_class)->dispose (object); } static gchar ** unity_gtk_action_group_list_actions (GActionGroup *action_group) { UnityGtkActionGroup *group; g_return_val_if_fail (UNITY_GTK_IS_ACTION_GROUP (action_group), NULL); group = UNITY_GTK_ACTION_GROUP (action_group); if (group->actions_by_name != NULL) { gchar **names; gchar **new_names; GHashTableIter iter; gpointer key; guint n; guint i; names = NULL; new_names = NULL; n = g_hash_table_size (group->actions_by_name); if (group->old_group != NULL) { gchar **old_names = g_action_group_list_actions (group->old_group); if (old_names != NULL) { for (i = 0; old_names[i] != NULL; i++); names = g_malloc_n (i + n + 1, sizeof (gchar *)); new_names = names + i; for (i = 0; old_names[i] != NULL; i++) names[i] = old_names[i]; g_free (old_names); } else g_warn_if_reached (); } if (names == NULL) new_names = names = g_malloc_n (n + 1, sizeof (gchar *)); g_hash_table_iter_init (&iter, group->actions_by_name); for (i = 0; i < n && g_hash_table_iter_next (&iter, &key, NULL); i++) new_names[i] = g_strdup (key); new_names[i] = NULL; return names; } g_warn_if_reached (); return group->old_group != NULL ? g_action_group_list_actions (group->old_group) : NULL; } static void unity_gtk_action_group_really_change_action_state (GActionGroup *action_group, const gchar *name, GVariant *value) { UnityGtkActionGroup *group; GHashTable *actions_by_name; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (action_group)); group = UNITY_GTK_ACTION_GROUP (action_group); actions_by_name = group->actions_by_name; if (actions_by_name != NULL) { UnityGtkAction *action = g_hash_table_lookup (actions_by_name, name); if (action != NULL) { if (g_strcmp0 (name, action->name) == 0) { if (action->items_by_name != NULL) { if (value != NULL) { const gchar *name; UnityGtkMenuItem *item; g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)); name = g_variant_get_string (value, NULL); item = g_hash_table_lookup (action->items_by_name, name); if (item == NULL || !unity_gtk_menu_item_is_check (item)) { g_warn_if_reached (); value = NULL; } else gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), TRUE); } if (value == NULL) { GHashTableIter iter; gpointer value; g_hash_table_iter_init (&iter, action->items_by_name); while (g_hash_table_iter_next (&iter, NULL, &value)) { UnityGtkMenuItem *item = value; if (unity_gtk_menu_item_is_check (item)) gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item->menu_item), FALSE); } } } else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item)) { g_return_if_fail (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (action->item->menu_item), g_variant_get_boolean (value)); } else g_warn_if_fail (value == NULL); return; } else if (g_strcmp0 (name, action->subname) == 0) { GtkWidget *submenu; g_return_if_fail (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)); g_return_if_fail (action->item != NULL && action->item->menu_item != NULL); submenu = gtk_menu_item_get_submenu (action->item->menu_item); g_return_if_fail (submenu != NULL); if (g_variant_get_boolean (value)) g_signal_emit_by_name (submenu, "show"); else g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, g_signal_emit_hide, g_object_ref (submenu), g_object_unref); return; } else g_warn_if_reached (); } else g_warn_if_reached (); } else g_warn_if_reached (); if (group->old_group != NULL) g_action_group_change_action_state (group->old_group, name, value); else g_warn_if_reached (); } static void unity_gtk_action_group_change_action_state (GActionGroup *action_group, const gchar *name, GVariant *value) { g_variant_ref_sink (value); unity_gtk_action_group_really_change_action_state (action_group, name, value); g_variant_unref (value); } static void unity_gtk_action_group_activate_action (GActionGroup *action_group, const gchar *name, GVariant *parameter) { UnityGtkActionGroup *group; GHashTable *actions_by_name; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (action_group)); group = UNITY_GTK_ACTION_GROUP (action_group); actions_by_name = group->actions_by_name; if (actions_by_name != NULL) { UnityGtkAction *action = g_hash_table_lookup (actions_by_name, name); if (action != NULL) { if (g_strcmp0 (name, action->name) == 0) { if (action->items_by_name != NULL) { const gchar *name; UnityGtkMenuItem *item; g_return_if_fail (parameter != NULL && g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING)); name = g_variant_get_string (parameter, NULL); item = g_hash_table_lookup (action->items_by_name, name); if (item != NULL) unity_gtk_menu_item_activate (item); g_action_group_action_state_changed (G_ACTION_GROUP (group), action->name, parameter); } else if (action->item != NULL) { if (unity_gtk_menu_item_get_draw_as_radio (action->item)) g_warn_if_fail (g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING)); else g_warn_if_fail (parameter == NULL); unity_gtk_menu_item_activate (action->item); } return; } else g_warn_if_reached (); } else g_warn_if_reached (); } else g_warn_if_reached (); if (group->old_group != NULL) g_action_group_activate_action (group->old_group, name, parameter); else g_warn_if_reached (); } static gboolean unity_gtk_action_group_query_action (GActionGroup *action_group, const gchar *name, gboolean *enabled, const GVariantType **parameter_type, const GVariantType **state_type, GVariant **state_hint, GVariant **state) { UnityGtkActionGroup *group; GHashTable *actions_by_name; g_return_val_if_fail (UNITY_GTK_IS_ACTION_GROUP (action_group), FALSE); group = UNITY_GTK_ACTION_GROUP (action_group); actions_by_name = group->actions_by_name; if (actions_by_name != NULL) { UnityGtkAction *action = g_hash_table_lookup (actions_by_name, name); if (action != NULL) { if (g_strcmp0 (name, action->name) == 0) { if (enabled != NULL) { if (action->items_by_name != NULL) { GHashTableIter iter; gpointer value; *enabled = FALSE; g_hash_table_iter_init (&iter, action->items_by_name); while (!*enabled && g_hash_table_iter_next (&iter, NULL, &value)) *enabled = unity_gtk_menu_item_is_sensitive (value); } else *enabled = action->item != NULL && unity_gtk_menu_item_is_sensitive (action->item); } if (parameter_type != NULL) { if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item))) *parameter_type = G_VARIANT_TYPE_STRING; else *parameter_type = NULL; } if (state_type != NULL) { if (action->items_by_name != NULL || (action->item != NULL && unity_gtk_menu_item_get_draw_as_radio (action->item))) *state_type = G_VARIANT_TYPE_STRING; else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item)) *state_type = G_VARIANT_TYPE_BOOLEAN; else *state_type = NULL; } if (state_hint != NULL) { if (action->items_by_name != NULL) { GVariantBuilder builder; GHashTableIter iter; gpointer key; g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); g_hash_table_iter_init (&iter, action->items_by_name); while (g_hash_table_iter_next (&iter, &key, NULL)) g_variant_builder_add (&builder, "s", key); *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder)); } else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item)) { GVariantBuilder builder; if (unity_gtk_menu_item_get_draw_as_radio (action->item)) { g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add (&builder, "s", action->name); *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder)); } else { g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_add (&builder, "b", FALSE); g_variant_builder_add (&builder, "b", TRUE); *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder)); } } else *state_hint = NULL; } if (state != NULL) { if (action->items_by_name != NULL) { GHashTableIter iter; gpointer key; gpointer value; *state = NULL; g_hash_table_iter_init (&iter, action->items_by_name); while (*state == NULL && g_hash_table_iter_next (&iter, &key, &value)) if (unity_gtk_menu_item_is_active (value)) *state = g_variant_ref_sink (g_variant_new_string (key)); } else if (action->item != NULL && unity_gtk_menu_item_is_check (action->item)) { if (unity_gtk_menu_item_get_draw_as_radio (action->item)) { if (unity_gtk_menu_item_is_active (action->item)) *state = g_variant_ref_sink (g_variant_new_string (action->name)); else *state = g_variant_ref_sink (g_variant_new_string ("")); } else *state = g_variant_ref_sink (g_variant_new_boolean (unity_gtk_menu_item_is_active (action->item))); } else *state = NULL; } return TRUE; } else if (g_strcmp0 (name, action->subname) == 0) { if (enabled != NULL) *enabled = TRUE; if (parameter_type != NULL) *parameter_type = NULL; if (state_type != NULL) *state_type = G_VARIANT_TYPE_BOOLEAN; if (state_hint != NULL) { GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_add (&builder, "b", FALSE); g_variant_builder_add (&builder, "b", TRUE); *state_hint = g_variant_ref_sink (g_variant_builder_end (&builder)); } if (state != NULL) *state = g_variant_ref_sink (g_variant_new_boolean (TRUE)); return TRUE; } else g_warn_if_reached (); } } else g_warn_if_reached (); if (group->old_group != NULL) return g_action_group_query_action (group->old_group, name, enabled, parameter_type, state_type, state_hint, state); g_warn_if_reached (); return FALSE; } static void unity_gtk_action_group_class_init (UnityGtkActionGroupClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = unity_gtk_action_group_dispose; } static void unity_gtk_action_group_action_group_init (GActionGroupInterface *iface) { iface->list_actions = unity_gtk_action_group_list_actions; iface->change_action_state = unity_gtk_action_group_change_action_state; iface->activate_action = unity_gtk_action_group_activate_action; iface->query_action = unity_gtk_action_group_query_action; } static void unity_gtk_action_group_init (UnityGtkActionGroup *self) { self->actions_by_name = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); self->names_by_radio_menu_item = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); } /** * unity_gtk_action_group_new: * @old_group: a fallback #GActionGroup. * * Creates a new #UnityGtkMenuShell based on the contents of the given * @menu_shell. Any subsequent changes to @menu_shell are reflected in * the returned #UnityGtkMenuShell. * * Actions not found in an attached #UnityGtkMenuShell are queried in * @old_group before failing. * * Returns: a new #UnityGtkActionGroup. */ UnityGtkActionGroup * unity_gtk_action_group_new (GActionGroup *old_group) { UnityGtkActionGroup *group = g_object_new (UNITY_GTK_TYPE_ACTION_GROUP, NULL); unity_gtk_action_group_set_old_group (group, old_group); return group; } static gchar * g_strdup_normalize (const gchar *str) { gchar *string = NULL; if (str != NULL) { guint i = 0; guint j; string = g_strdup (str); for (j = 0; str[j] != '\0'; j++) { if (g_ascii_isalnum (str[j])) string[i++] = str[j]; else string[i++] = '-'; } string[i] = '\0'; } return string; } static gchar * unity_gtk_action_group_get_action_name (UnityGtkActionGroup *group, UnityGtkMenuItem *item) { GtkMenuItem *menu_item; GtkAction *action; const gchar *name; gchar *normalized_name; GHashTable *actions_by_name; GActionGroup *old_group; g_return_val_if_fail (UNITY_GTK_IS_ACTION_GROUP (group), NULL); g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL); menu_item = item->menu_item; g_return_val_if_fail (menu_item != NULL, NULL); if (GTK_IS_RADIO_MENU_ITEM (menu_item)) { GtkRadioMenuItem *radio_menu_item = GTK_RADIO_MENU_ITEM (menu_item); GSList *iter = g_slist_last (gtk_radio_menu_item_get_group (radio_menu_item)); if (iter != NULL) menu_item = iter->data; } name = NULL; action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (menu_item)); if (action != NULL) name = gtk_action_get_name (action); if (name == NULL || name[0] == '\0') name = gtk_menu_item_get_label (menu_item); if (name == NULL || name[0] == '\0') name = gtk_menu_item_get_nth_label_label (menu_item, 0); if (name != NULL && name[0] == '\0') name = NULL; normalized_name = g_strdup_normalize (name); actions_by_name = group->actions_by_name; old_group = group->old_group; if (normalized_name == NULL || (actions_by_name != NULL && g_hash_table_contains (actions_by_name, normalized_name)) || (old_group != NULL && g_action_group_has_action (old_group, normalized_name))) { gchar *next_normalized_name = NULL; guint i = 0; do { g_free (next_normalized_name); if (normalized_name != NULL) next_normalized_name = g_strdup_printf ("%s-%u", normalized_name, i++); else next_normalized_name = g_strdup_printf ("%u", i++); } while ((actions_by_name != NULL && g_hash_table_contains (actions_by_name, next_normalized_name)) || (old_group != NULL && g_action_group_has_action (old_group, next_normalized_name))); g_free (normalized_name); normalized_name = next_normalized_name; } return normalized_name; } static gchar * unity_gtk_action_group_get_state_name (UnityGtkActionGroup *group, UnityGtkMenuItem *item) { gchar *name = NULL; g_return_val_if_fail (UNITY_GTK_IS_ACTION_GROUP (group), NULL); g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL); if (unity_gtk_menu_item_is_radio (item)) { const gchar *label = unity_gtk_menu_item_get_label (item); if (label != NULL && label[0] != '\0') { gchar *normalized_label = g_strdup_normalize (label); UnityGtkAction *action = item->action; if (action != NULL) { if (action->items_by_name != NULL) { if (g_hash_table_contains (action->items_by_name, normalized_label)) { guint i = 0; do { g_free (name); name = g_strdup_printf ("%s-%u", normalized_label, i++); } while (g_hash_table_contains (action->items_by_name, name)); g_free (normalized_label); } else name = normalized_label; } else { g_warn_if_reached (); name = normalized_label; } } else name = normalized_label; } else { GtkActivatable *activatable = GTK_ACTIVATABLE (item->menu_item); GtkAction *action = gtk_activatable_get_related_action (activatable); if (action != NULL) { GtkRadioAction *radio_action = GTK_RADIO_ACTION (action); const gchar *action_name = gtk_action_get_name (action); gchar *normalized_action_name = NULL; gint value; g_object_get (radio_action, "value", &value, NULL); if (action_name != NULL && action_name[0] != '\0') normalized_action_name = g_strdup_normalize (action_name); if (normalized_action_name != NULL) { if (normalized_action_name[0] != '\0') name = g_strdup_printf ("%s-%d", normalized_action_name, value); else name = g_strdup_printf ("%d", value); g_free (normalized_action_name); } else name = g_strdup_printf ("%d", value); if (item->action != NULL) { GHashTable *items_by_name = item->action->items_by_name; if (items_by_name != NULL && g_hash_table_contains (items_by_name, name)) { gchar *next_name = NULL; guint i = 0; do { g_free (next_name); next_name = g_strdup_printf ("%s-%u", name, i++); } while (g_hash_table_contains (items_by_name, next_name)); g_free (name); name = next_name; } } } } if (name == NULL) { /* * We tried to find a good name for this radio menu item state, but * the application wasn't nice enough to give us one, either by label * or by action. So we have to pick a bad name which is unique for * any given UnityGtkMenuItem. */ name = g_strdup_printf ("%p", item); } } return name; } void unity_gtk_action_group_connect_item (UnityGtkActionGroup *group, UnityGtkMenuItem *item) { g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (group)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); if (item->parent_shell != NULL && (item->parent_shell->action_group != group || item->action == NULL)) { UnityGtkAction *new_action = NULL; UnityGtkAction *action = NULL; if (item->action != NULL) { if (item->parent_shell->action_group != NULL) unity_gtk_action_group_disconnect_item (item->parent_shell->action_group, item); else unity_gtk_menu_item_set_action (item, NULL); } if (unity_gtk_menu_item_is_radio (item)) { GtkRadioMenuItem *radio_menu_item = GTK_RADIO_MENU_ITEM (item->menu_item); const gchar *action_name; gchar *state_name; g_return_if_fail (group->actions_by_name != NULL); g_return_if_fail (group->names_by_radio_menu_item != NULL); action_name = g_hash_table_lookup (group->names_by_radio_menu_item, radio_menu_item); if (action_name == NULL) { GtkRadioMenuItem *last_radio_menu_item = NULL; GSList *iter = gtk_radio_menu_item_get_group (radio_menu_item); while (action_name == NULL && iter != NULL) { last_radio_menu_item = iter->data; action_name = g_hash_table_lookup (group->names_by_radio_menu_item, last_radio_menu_item); iter = g_slist_next (iter); } if (action_name == NULL) { gchar *new_action_name = unity_gtk_action_group_get_action_name (group, item); g_hash_table_insert (group->names_by_radio_menu_item, radio_menu_item, new_action_name); if (last_radio_menu_item != NULL && last_radio_menu_item != radio_menu_item) g_hash_table_insert (group->names_by_radio_menu_item, last_radio_menu_item, g_strdup (new_action_name)); action_name = new_action_name; } else g_hash_table_insert (group->names_by_radio_menu_item, radio_menu_item, g_strdup (action_name)); } action = g_hash_table_lookup (group->actions_by_name, action_name); if (action == NULL) action = new_action = unity_gtk_action_new_radio (action_name); state_name = unity_gtk_action_group_get_state_name (group, item); g_hash_table_insert (action->items_by_name, state_name, g_object_ref (item)); } else if (!unity_gtk_menu_item_is_separator (item)) { gchar *name = unity_gtk_action_group_get_action_name (group, item); action = new_action = unity_gtk_action_new (name, item); g_free (name); } unity_gtk_menu_item_set_action (item, action); if (new_action != NULL) { if (group->actions_by_name != NULL) g_hash_table_insert (group->actions_by_name, new_action->name, new_action); else g_warn_if_reached (); g_action_group_action_added (G_ACTION_GROUP (group), new_action->name); /* Add a new submenu action so we can detect opening and closing. */ if (item->menu_item != NULL && gtk_menu_item_get_submenu (item->menu_item) != NULL) { gchar *subname = unity_gtk_action_group_get_action_name (group, item); unity_gtk_action_set_subname (new_action, subname); g_free (subname); if (group->actions_by_name != NULL) g_hash_table_insert (group->actions_by_name, new_action->subname, g_object_ref (new_action)); else g_warn_if_reached (); g_action_group_action_added (G_ACTION_GROUP (group), new_action->subname); } } } } void unity_gtk_action_group_disconnect_item (UnityGtkActionGroup *group, UnityGtkMenuItem *item) { UnityGtkAction *action; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (group)); g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (item)); g_warn_if_fail (item->parent_shell != NULL); action = item->action; if (action != NULL) { if (action->items_by_name != NULL) { if (group->names_by_radio_menu_item != NULL) { const gchar *name = NULL; GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init (&iter, action->items_by_name); while (name == NULL && g_hash_table_iter_next (&iter, &key, &value)) if (value == item) name = key; if (name != NULL) { g_hash_table_remove (action->items_by_name, name); if (group->names_by_radio_menu_item != NULL) g_hash_table_remove (group->names_by_radio_menu_item, item->menu_item); else g_warn_if_reached (); if (g_hash_table_size (action->items_by_name) == 0) { /* Remove the submenu action used to detect opening and closing. */ if (action->subname != NULL) { if (group->actions_by_name != NULL) g_hash_table_remove (group->actions_by_name, action->subname); else g_warn_if_reached (); g_action_group_action_removed (G_ACTION_GROUP (group), action->subname); } if (group->actions_by_name != NULL) g_hash_table_remove (group->actions_by_name, action->name); else g_warn_if_reached (); g_action_group_action_removed (G_ACTION_GROUP (group), action->name); } } else g_warn_if_reached (); } else g_warn_if_reached (); } else { /* Remove the submenu action used to detect opening and closing. */ if (action->subname != NULL) { if (group->actions_by_name != NULL) g_hash_table_remove (group->actions_by_name, action->subname); else g_warn_if_reached (); g_action_group_action_removed (G_ACTION_GROUP (group), action->subname); } if (group->actions_by_name != NULL) g_hash_table_remove (group->actions_by_name, action->name); else g_warn_if_reached (); g_action_group_action_removed (G_ACTION_GROUP (group), action->name); } } unity_gtk_menu_item_set_action (item, NULL); } /** * unity_gtk_action_group_connect_shell: * @group: a #UnityGtkActionGroup. * @shell: a #UnityGtkMenuShell. * * Creates actions for all menu items in @shell and adds them to @group. * Subsequent changes to @shell also affect @group. */ void unity_gtk_action_group_connect_shell (UnityGtkActionGroup *group, UnityGtkMenuShell *shell) { GSequence *visible_indices; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (group)); g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); visible_indices = shell->visible_indices; if (shell->action_group != NULL && shell->action_group != group) unity_gtk_action_group_disconnect_shell (shell->action_group, shell); if (visible_indices != NULL) { GSequenceIter *iter = g_sequence_get_begin_iter (visible_indices); while (!g_sequence_iter_is_end (iter)) { guint i = GPOINTER_TO_UINT (g_sequence_get (iter)); UnityGtkMenuItem *item = g_ptr_array_index (shell->items, i); unity_gtk_action_group_connect_item (group, item); if (item->child_shell != NULL) { if (item->child_shell_valid) unity_gtk_action_group_connect_shell (group, item->child_shell); else g_warn_if_reached (); } iter = g_sequence_iter_next (iter); } } if (shell->action_group == NULL) shell->action_group = g_object_ref (group); } /** * unity_gtk_action_group_disconnect_shell: * @group: a #UnityGtkActionGroup. * @shell: a #UnityGtkMenuShell. * * Removes the actions for @shell from @group. */ void unity_gtk_action_group_disconnect_shell (UnityGtkActionGroup *group, UnityGtkMenuShell *shell) { UnityGtkActionGroup *action_group; GSequence *visible_indices; g_return_if_fail (UNITY_GTK_IS_ACTION_GROUP (group)); g_return_if_fail (UNITY_GTK_IS_MENU_SHELL (shell)); g_warn_if_fail (shell->action_group == NULL || shell->action_group == group); visible_indices = shell->visible_indices; if (visible_indices != NULL) { GSequenceIter *iter = g_sequence_get_begin_iter (visible_indices); while (!g_sequence_iter_is_end (iter)) { guint i = GPOINTER_TO_UINT (g_sequence_get (iter)); UnityGtkMenuItem *item = g_ptr_array_index (shell->items, i); unity_gtk_action_group_disconnect_item (group, item); if (item->child_shell != NULL) { if (item->child_shell_valid) unity_gtk_action_group_disconnect_shell (group, item->child_shell); else g_warn_if_reached (); } iter = g_sequence_iter_next (iter); } } action_group = shell->action_group; if (action_group != NULL) { shell->action_group = NULL; g_object_unref (action_group); } } void unity_gtk_action_group_print (UnityGtkActionGroup *group, guint indent) { gchar *space; g_return_if_fail (group == NULL || UNITY_GTK_IS_ACTION_GROUP (group)); space = g_strnfill (indent, ' '); if (group != NULL) { g_print ("%s(%s *) %p\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (group)), group); if (group->actions_by_name != NULL) { GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init (&iter, group->actions_by_name); while (g_hash_table_iter_next (&iter, &key, &value)) { g_print ("%s \"%s\" ->\n", space, (const gchar *) key); unity_gtk_action_print (value, indent + 4); } } if (group->names_by_radio_menu_item != NULL) { GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init (&iter, group->names_by_radio_menu_item); while (g_hash_table_iter_next (&iter, &key, &value)) g_print ("%s (%s *) %p -> \"%s\"\n", space, G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (key)), key, (const gchar *) value); } } else g_print ("%sNULL\n", space); g_free (space); } gboolean unity_gtk_action_group_is_debug (void) { return unity_gtk_action_group_debug; } /** * unity_gtk_action_group_set_debug: * @debug: #TRUE to enable debugging output * * Sets if action group changes should be logged using g_print (). */ void unity_gtk_action_group_set_debug (gboolean debug) { unity_gtk_action_group_debug = debug; } ./lib/Makefile.am0000644000004100000410000000177513210416612014053 0ustar www-datawww-dataAM_CFLAGS = -Wall SOURCES = \ unity-gtk-menu-shell.h \ unity-gtk-menu-shell-private.h \ unity-gtk-menu-shell.c \ unity-gtk-menu-section-private.h \ unity-gtk-menu-section.c \ unity-gtk-menu-item-private.h \ unity-gtk-menu-item.c \ unity-gtk-action-group.h \ unity-gtk-action-group-private.h \ unity-gtk-action-group.c \ unity-gtk-action-private.h \ unity-gtk-action.c if GTK3 lib_LTLIBRARIES = libunity-gtk3-parser.la libunity_gtk3_parser_la_SOURCES = $(SOURCES) libunity_gtk3_parser_la_CFLAGS = $(GTK_CFLAGS) $(AM_CFLAGS) libunity_gtk3_parser_la_LDFLAGS = $(GTK_LIBS) $(AM_LDFLAGS) else lib_LTLIBRARIES = libunity-gtk2-parser.la libunity_gtk2_parser_la_SOURCES = $(SOURCES) libunity_gtk2_parser_la_CFLAGS = $(GTK_CFLAGS) $(AM_CFLAGS) libunity_gtk2_parser_la_LDFLAGS = $(GTK_LIBS) $(AM_LDFLAGS) endif libunity_gtk_parser_la_includedir = $(includedir)/unity-gtk-parser libunity_gtk_parser_la_include_HEADERS = \ unity-gtk-parser.h \ unity-gtk-menu-shell.h \ unity-gtk-action-group.h ./lib/unity-gtk-action-group.h0000644000004100000410000000525713210416612016527 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Ryan Lortie * William Hua */ #ifndef __UNITY_GTK_ACTION_GROUP_H__ #define __UNITY_GTK_ACTION_GROUP_H__ #include G_BEGIN_DECLS typedef struct _UnityGtkActionGroup UnityGtkActionGroup; typedef GObjectClass UnityGtkActionGroupClass; #define UNITY_GTK_TYPE_ACTION_GROUP (unity_gtk_action_group_get_type ()) #define UNITY_GTK_ACTION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNITY_GTK_TYPE_ACTION_GROUP, UnityGtkActionGroup)) #define UNITY_GTK_IS_ACTION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNITY_GTK_TYPE_ACTION_GROUP)) #define UNITY_GTK_ACTION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNITY_GTK_TYPE_ACTION_GROUP, UnityGtkActionGroupClass)) #define UNITY_GTK_IS_ACTION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNITY_GTK_TYPE_ACTION_GROUP)) #define UNITY_GTK_ACTION_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNITY_GTK_TYPE_ACTION_GROUP, UnityGtkActionGroupClass)) G_END_DECLS #include "unity-gtk-menu-shell.h" G_BEGIN_DECLS /** * UnityGtkActionGroup: * * Opaque action group collector for #UnityGtkMenuShell. */ struct _UnityGtkActionGroup { GObject parent_instance; /*< private >*/ GActionGroup *old_group; GHashTable *actions_by_name; GHashTable *names_by_radio_menu_item; }; GType unity_gtk_action_group_get_type (void); UnityGtkActionGroup * unity_gtk_action_group_new (GActionGroup *old_group); void unity_gtk_action_group_connect_shell (UnityGtkActionGroup *group, UnityGtkMenuShell *shell); void unity_gtk_action_group_disconnect_shell (UnityGtkActionGroup *group, UnityGtkMenuShell *shell); void unity_gtk_action_group_set_debug (gboolean debug); G_END_DECLS #endif /* __UNITY_GTK_ACTION_GROUP_H__ */ ./tests/0000755000004100000410000000000013210416612012401 5ustar www-datawww-data./tests/autopilot/0000755000004100000410000000000013210416612014421 5ustar www-datawww-data./tests/autopilot/test.sh0000755000004100000410000000016013210416612015734 0ustar www-datawww-data#!/bin/sh for name in `autopilot list tests | head -n -3 | tail -n +3` do autopilot run $name || exit 1 done ./tests/autopilot/__init__.py0000644000004100000410000000031613210416612016532 0ustar www-datawww-data# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- # Copyright 2013 Canonical # # This file is part of unity-gtk-module. """unity-gtk-module autopilot tests - top level package.""" ./tests/autopilot/tests/0000755000004100000410000000000013210416612015563 5ustar www-datawww-data./tests/autopilot/tests/__init__.py0000644000004100000410000000000013210416612017662 0ustar www-datawww-data./tests/autopilot/tests/test_gedit.py0000644000004100000410000003406513210416612020300 0ustar www-datawww-dataimport autopilot.introspection.gtk import os import pyatspi.registry import pyatspi.utils import time import unity.tests def print_accessible(root, level=0): print level * ' ', root for node in root: print_accessible(node, level + 1) def get_accessible_with_name_and_role(root, name, role): is_accessible = lambda a: a.name == name and a.get_role_name() == role return pyatspi.utils.findDescendant(root, is_accessible, True); def get_panel_accessible(root): return get_accessible_with_name_and_role(root, 'unity-panel-service', 'application') def get_app_menu_accessible(root): is_app_menu = lambda a: len(a) > 0 and a[0].name == 'File' and a[0].get_role_name() == 'label' return pyatspi.utils.findDescendant(root, is_app_menu, True) def get_label_accessible_with_name(root, name): return get_accessible_with_name_and_role(root, name, 'label') def get_submenu_accessible(root): return root[0] def get_menu_item_accessible_with_name(root, name): is_menu_item = lambda a: a.name == name and a.get_role_name() in ('menu item', 'check menu item', 'radio menu item') return pyatspi.utils.findDescendant(root, is_menu_item, True); def get_accessible_index(root, node): for i in xrange(len(root)): if root[i] == node: return i return -1 class GeditTestCase(unity.tests.UnityTestCase): def setUp(self): super(GeditTestCase, self).setUp() registry = pyatspi.registry.Registry() self.desktop = registry.getDesktop(0) module_name = 'unity-gtk-module' if os.path.isfile(module_name): modules = [module for module in os.getenv('GTK_MODULES', '').split(':') if module] modules = [module for module in modules if module != 'unity-gtk-module'] modules.append(module_name) self.patch_environment('GTK_MODULES', ':'.join(modules)) # This is needed on systems other than the EN locale os.putenv("LC_ALL", "C") self.addCleanup(os.unsetenv, "LC_ALL") def test_file_new(self): """Test if menu item insertion works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Open and close the Documents menu panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that Untitled Document 1 is checked panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) documents_item = get_label_accessible_with_name(app_menu, 'Documents') documents_menu = get_submenu_accessible(documents_item) untitled_document_1_item = get_menu_item_accessible_with_name(documents_menu, 'Untitled Document 1') untitled_document_1_index = get_accessible_index(documents_menu, untitled_document_1_item) self.assertTrue(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) # Activate File > New panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_File') menu.mouse_click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') # Open and close the Documents menu menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that two documents are open tabs = self.app.select_many('GeditTab') self.assertTrue(len(tabs) == 2) self.assertTrue(tabs[0].name == 'Untitled Document 1') self.assertTrue(tabs[1].name == 'Untitled Document 2') # Assert that Untitled Document 2 is checked untitled_document_1_item = documents_menu[untitled_document_1_index] untitled_document_2_item = documents_menu[untitled_document_1_index + 1] self.assertTrue(untitled_document_1_item.name == 'Untitled Document 1') self.assertTrue(untitled_document_2_item.name == 'Untitled Document 2') self.assertFalse(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) self.assertTrue(untitled_document_2_item.get_state_set().contains(pyatspi.STATE_CHECKED)) def test_file_close(self): """Test if menu item removal works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Open and close the Documents menu panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that Untitled Document 1 is checked panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) documents_item = get_label_accessible_with_name(app_menu, 'Documents') documents_menu = get_submenu_accessible(documents_item) untitled_document_1_item = get_menu_item_accessible_with_name(documents_menu, 'Untitled Document 1') self.assertTrue(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) # Activate File > Close panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_File') menu.mouse_click() self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Enter') # Open and close the Documents menu menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that no documents are open tabs = self.app.select_many('GeditTab') self.assertFalse(tabs) # Assert that Untitled Document 1 was removed untitled_document_1_item = get_menu_item_accessible_with_name(documents_menu, 'Untitled Document 1') self.assertFalse(untitled_document_1_item) def test_file_quit(self): """Test if menu item activation works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Activate File > Quit panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_File') menu.mouse_click() self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Enter') # Assert that the application quit self.assertFalse(self.process_manager.app_is_running('Text Editor')) def test_edit_undo(self): """Test if menu item sensitivity works.""" self.app = self.launch_test_application('gedit') time.sleep(2.2) # Hi! self.keyboard.type('hi') # Assert that Undo is sensitive panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) edit_item = get_label_accessible_with_name(app_menu, 'Edit') edit_menu = get_submenu_accessible(edit_item) undo_item = get_menu_item_accessible_with_name(edit_menu, 'Undo') self.assertTrue(undo_item.get_state_set().contains(pyatspi.STATE_SENSITIVE)) # Activate Edit > Undo panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Edit') menu.mouse_click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') # Open and close the Edit menu menu.mouse_click() menu.mouse_click() # Assert that Undo is insensitive self.assertFalse(undo_item.get_state_set().contains(pyatspi.STATE_SENSITIVE)) def test_view_toolbar(self): """Test if check menu item activation works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Assert that View > Toolbar matches the visibility of the tool bar panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) view_item = get_label_accessible_with_name(app_menu, 'View') view_menu = get_submenu_accessible(view_item) toolbar_item = get_menu_item_accessible_with_name(view_menu, 'Toolbar') checked = toolbar_item.get_state_set().contains(pyatspi.STATE_CHECKED) toolbar = self.app.select_many('GtkToolbar')[0] visible = toolbar.visible self.assertTrue(checked == visible) # Activate View > Toolbar panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_View') menu.mouse_click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') # Open and close the View menu menu.mouse_click() menu.mouse_click() # Assert that the visibility changed self.assertTrue(checked == visible) self.assertFalse(toolbar.visible == visible) self.assertFalse(toolbar_item.get_state_set().contains(pyatspi.STATE_CHECKED) == checked) # Activate View > Toolbar menu.mouse_click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') # Open and close the View menu menu.mouse_click() menu.mouse_click() # Assert that the visibility is restored self.assertTrue(checked == visible) self.assertTrue(toolbar.visible == visible) self.assertTrue(toolbar_item.get_state_set().contains(pyatspi.STATE_CHECKED) == checked) def test_documents_untitled_document(self): """Test if radio menu item activation works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Open and close the Documents menu panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that Untitled Document 1 is checked panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) documents_item = get_label_accessible_with_name(app_menu, 'Documents') documents_menu = get_submenu_accessible(documents_item) untitled_document_1_item = get_menu_item_accessible_with_name(documents_menu, 'Untitled Document 1') untitled_document_1_index = get_accessible_index(documents_menu, untitled_document_1_item) self.assertTrue(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) # Activate File > New panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_File') menu.mouse_click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') # Open and close the Documents menu menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that two documents are open tabs = self.app.select_many('GeditTab') self.assertTrue(len(tabs) == 2) self.assertTrue(tabs[0].name == 'Untitled Document 1') self.assertTrue(tabs[1].name == 'Untitled Document 2') # Assert that Untitled Document 2 is checked untitled_document_1_item = documents_menu[untitled_document_1_index] untitled_document_2_item = documents_menu[untitled_document_1_index + 1] self.assertTrue(untitled_document_1_item.name == 'Untitled Document 1') self.assertTrue(untitled_document_2_item.name == 'Untitled Document 2') self.assertFalse(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) self.assertTrue(untitled_document_2_item.get_state_set().contains(pyatspi.STATE_CHECKED)) # Activate Documents > Untitled Document 1 menu.mouse_click() self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Enter') # Open and close the Documents menu menu.mouse_click() menu.mouse_click() # Assert that Untitled Document 1 is checked self.assertTrue(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) self.assertFalse(untitled_document_2_item.get_state_set().contains(pyatspi.STATE_CHECKED)) def test_ctrl_n(self): """Test if menu item insertion works.""" self.app = self.launch_test_application('gedit') time.sleep(0.2) # Open and close the Documents menu panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that Untitled Document 1 is checked panel = get_panel_accessible(self.desktop) app_menu = get_app_menu_accessible(panel) documents_item = get_label_accessible_with_name(app_menu, 'Documents') documents_menu = get_submenu_accessible(documents_item) untitled_document_1_item = get_menu_item_accessible_with_name(documents_menu, 'Untitled Document 1') untitled_document_1_index = get_accessible_index(documents_menu, untitled_document_1_item) self.assertTrue(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) # Activate File > New self.keyboard.press_and_release('Ctrl+n') # Open and close the Documents menu panel = self.unity.panels.get_active_panel() menu = panel.menus.get_menu_by_label('_Documents') menu.mouse_click() menu.mouse_click() # Assert that two documents are open tabs = self.app.select_many('GeditTab') self.assertTrue(len(tabs) == 2) self.assertTrue(tabs[0].name == 'Untitled Document 1') self.assertTrue(tabs[1].name == 'Untitled Document 2') # Assert that Untitled Document 2 is checked untitled_document_1_item = documents_menu[untitled_document_1_index] untitled_document_2_item = documents_menu[untitled_document_1_index + 1] self.assertTrue(untitled_document_1_item.name == 'Untitled Document 1') self.assertTrue(untitled_document_2_item.name == 'Untitled Document 2') self.assertFalse(untitled_document_1_item.get_state_set().contains(pyatspi.STATE_CHECKED)) self.assertTrue(untitled_document_2_item.get_state_set().contains(pyatspi.STATE_CHECKED)) ./tests/autopilot/tests/Makefile.am0000644000004100000410000000005113210416612017613 0ustar www-datawww-datacheck_PYTHON = __init__.py test_gedit.py ./tests/autopilot/Makefile.am0000644000004100000410000000026213210416612016455 0ustar www-datawww-data autopilotdir = $(pythondir)/unity_gtk_module autopilot_DATA = __init__.py autopilottestsdir = $(autopilotdir)/tests autopilottests_DATA = tests/__init__.py tests/test_gedit.py ./tests/Makefile.am0000644000004100000410000000002413210416612014431 0ustar www-datawww-dataSUBDIRS = autopilot ./TODO0000644000004100000410000000006313210416612011726 0ustar www-datawww-dataActivating active radio menu item de-activates it. ./COPYING.LESSER0000644000004100000410000001674313210416612013301 0ustar www-datawww-data GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ./Makefile.am0000644000004100000410000000015013210416612013267 0ustar www-datawww-dataACLOCAL_AMFLAGS = -I m4 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc SUBDIRS = lib src data docs tests ./m4/0000755000004100000410000000000013210416612011557 5ustar www-datawww-data./AUTHORS0000644000004100000410000000010513210416612012303 0ustar www-datawww-dataRyan Lortie William Hua ./data/0000755000004100000410000000000013210416612012150 5ustar www-datawww-data./data/unity-gtk-module.conf0000644000004100000410000000073613210416612016243 0ustar www-datawww-datadescription "Unity GTK Module Environment variables" start on starting dbus pre-start script for DESKTOP in $(echo "$XDG_CURRENT_DESKTOP" | sed 's/:/ /g') do if [ "x$DESKTOP" = "xUnity" ]; then exit 0 fi done stop end script script if [ -n "$GTK_MODULES" ] then GTK_MODULES="$GTK_MODULES:unity-gtk-module" else GTK_MODULES="unity-gtk-module" fi initctl set-env --global GTK_MODULES=$GTK_MODULES end script ./data/com.canonical.unity-gtk-module.gschema.xml0000644000004100000410000000113413210416612022220 0ustar www-datawww-data Application blacklist List of applications where unity-gtk-module should be disabled. [] Application whitelist List of applications where unity-gtk-module should be enabled. [] ./data/unity-gtk2-parser.pc.in0000644000004100000410000000041713210416612016412 0ustar www-datawww-dataprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: unity-gtk2-parser Description: GtkMenuShell to GMenuModel parser Version: @VERSION@ Requires: gtk+-2.0 Cflags: -I${includedir}/unity-gtk-parser Libs: -L${libdir} -lunity-gtk2-parser ./data/unity-gtk3-parser.pc.in0000644000004100000410000000041713210416612016413 0ustar www-datawww-dataprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: unity-gtk3-parser Description: GtkMenuShell to GMenuModel parser Version: @VERSION@ Requires: gtk+-3.0 Cflags: -I${includedir}/unity-gtk-parser Libs: -L${libdir} -lunity-gtk3-parser ./data/unity-gtk-module.service0000644000004100000410000000121513210416612016747 0ustar www-datawww-data[Unit] Description=Unity GTK Module Environment variables Before=unity7.service unity-panel-service.service gnome-session.service PartOf=graphical-session.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/sh -ec '\ GTK_MODULES="$${GTK_MODULES:+$GTK_MODULES:}unity-gtk-module";\ dbus-update-activation-environment --verbose --systemd GTK_MODULES' ExecStopPost=/bin/sh -ec '\ GTK_MODULES=$$(echo -n $${GTK_MODULES} | awk -v RS=: -v ORS=: "/^unity-gtk-module$/ {next} {print}" | sed -e "s/:*$//");\ dbus-update-activation-environment --verbose --systemd GTK_MODULES' [Install] WantedBy=unity-session.target ./data/Makefile.am0000644000004100000410000000061313210416612014204 0ustar www-datawww-datagsettings_SCHEMAS = com.canonical.unity-gtk-module.gschema.xml @GSETTINGS_RULES@ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = unity-gtk$(GTK_VERSION)-parser.pc upstart_jobdir = $(datadir)/upstart/sessions/ dist_upstart_job_DATA = unity-gtk-module.conf systemd_userunitdir = $(SYSTEMD_USERUNITDIR) systemd_userunit_DATA = unity-gtk-module.service EXTRA_DIST = $(dist_upstart_job_DATA)