Back to index

indicator-appmenu  12.10.0
Classes | Defines | Typedefs | Functions
window-menu-model.h File Reference
#include <glib.h>
#include <glib-object.h>
#include <libbamf/bamf-window.h>
#include "window-menu.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _WindowMenuModelClass
struct  _WindowMenuModel

Defines

#define WINDOW_MENU_MODEL_TYPE   (window_menu_model_get_type ())
#define WINDOW_MENU_MODEL(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModel))
#define WINDOW_MENU_MODEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass))
#define IS_WINDOW_MENU_MODEL(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINDOW_MENU_MODEL_TYPE))
#define IS_WINDOW_MENU_MODEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), WINDOW_MENU_MODEL_TYPE))
#define WINDOW_MENU_MODEL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass))

Typedefs

typedef struct _WindowMenuModel
typedef struct _WindowMenuModelClass
typedef struct _WindowMenuModelPrivate

Functions

GType window_menu_model_get_type (void)
WindowMenuModel * window_menu_model_new (BamfApplication *app, BamfWindow *window)

Class Documentation

struct _WindowMenuModelClass

Definition at line 41 of file window-menu-model.h.

Class Members
WindowMenuClass parent_class
struct _WindowMenuModel

Definition at line 45 of file window-menu-model.h.

Class Members
WindowMenu parent
WindowMenuModelPrivate * priv

Define Documentation

#define IS_WINDOW_MENU_MODEL (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINDOW_MENU_MODEL_TYPE))

Definition at line 33 of file window-menu-model.h.

#define IS_WINDOW_MENU_MODEL_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), WINDOW_MENU_MODEL_TYPE))

Definition at line 34 of file window-menu-model.h.

#define WINDOW_MENU_MODEL (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModel))

Definition at line 31 of file window-menu-model.h.

#define WINDOW_MENU_MODEL_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass))

Definition at line 32 of file window-menu-model.h.

#define WINDOW_MENU_MODEL_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass))

Definition at line 35 of file window-menu-model.h.

Definition at line 30 of file window-menu-model.h.


Typedef Documentation

typedef struct _WindowMenuModel

Definition at line 37 of file window-menu-model.h.

typedef struct _WindowMenuModelClass

Definition at line 38 of file window-menu-model.h.

typedef struct _WindowMenuModelPrivate

Definition at line 39 of file window-menu-model.h.


Function Documentation

GType window_menu_model_get_type ( void  )
WindowMenuModel* window_menu_model_new ( BamfApplication *  app,
BamfWindow *  window 
)

Definition at line 449 of file window-menu-model.c.

{
       g_return_val_if_fail(BAMF_IS_APPLICATION(app), NULL);
       g_return_val_if_fail(BAMF_IS_WINDOW(window), NULL);

       WindowMenuModel * menu = g_object_new(WINDOW_MENU_MODEL_TYPE, NULL);

       menu->priv->xid = bamf_window_get_xid(window);

       gchar *unique_bus_name;
       gchar *app_menu_object_path;
       gchar *menubar_object_path;
       gchar *application_object_path;
       gchar *window_object_path;
       GDBusConnection *session;

       unique_bus_name = bamf_window_get_utf8_prop (window, "_GTK_UNIQUE_BUS_NAME");

       if (unique_bus_name == NULL) {
              /* If this isn't set, we won't get very far... */
              return NULL;
       }

       app_menu_object_path = bamf_window_get_utf8_prop (window, "_GTK_APP_MENU_OBJECT_PATH");
       menubar_object_path = bamf_window_get_utf8_prop (window, "_GTK_MENUBAR_OBJECT_PATH");
       application_object_path = bamf_window_get_utf8_prop (window, "_GTK_APPLICATION_OBJECT_PATH");
       window_object_path = bamf_window_get_utf8_prop (window, "_GTK_WINDOW_OBJECT_PATH");

       session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);

       /* Setup actions */
       if (application_object_path != NULL) {
              g_action_muxer_insert(menu->priv->action_mux, ACTION_MUX_PREFIX_APP, G_ACTION_GROUP(g_dbus_action_group_get (session, unique_bus_name, application_object_path)));
       }

       if (window_object_path != NULL) {
              g_action_muxer_insert(menu->priv->action_mux, ACTION_MUX_PREFIX_WIN, G_ACTION_GROUP(g_dbus_action_group_get (session, unique_bus_name, window_object_path)));
       }

       /* Build us some menus */
       if (app_menu_object_path != NULL) {
              const gchar * desktop_path = bamf_application_get_desktop_file(app);
              gchar * app_name = NULL;

              if (desktop_path != NULL) {
                     GDesktopAppInfo * desktop = g_desktop_app_info_new_from_filename(desktop_path);

                     if (desktop != NULL) {
                            app_name = g_strdup(g_app_info_get_name(G_APP_INFO(desktop)));

                            g_object_unref(desktop);
                     }
              }

              GMenuModel * model = G_MENU_MODEL(g_dbus_menu_model_get (session, unique_bus_name, app_menu_object_path));

              add_application_menu(menu, app_name, model);

              g_object_unref(model);
              g_free(app_name);
       }

       if (menubar_object_path != NULL) {
              GMenuModel * model = G_MENU_MODEL(g_dbus_menu_model_get (session, unique_bus_name, menubar_object_path));

              add_window_menu(menu, model);

              g_object_unref(model);
       }

       /* when the action groups change, we could end up having items
        * enabled/disabled.  how to deal with that?
        */

       g_free (unique_bus_name);
       g_free (app_menu_object_path);
       g_free (menubar_object_path);
       g_free (application_object_path);
       g_free (window_object_path);

       g_object_unref (session);

       return menu;
}

Here is the call graph for this function: