Add a menu display to applications
ShellAppMonitor now depends on gmenu to load menus. Use the menu data from ShellAppMonitor to show a menu list. GenericDisplay implementations can now have a sidebar area. We handle keystrokes such as left/right explicitly. Some internal API changes to account for the fact that a display can have another filter in addition to the search.
This commit is contained in:
@ -51,6 +51,8 @@ libgnome_shell_la_SOURCES = \
|
||||
gnome-shell-plugin.c \
|
||||
shell-app-monitor.c \
|
||||
shell-app-monitor.h \
|
||||
shell-arrow.c \
|
||||
shell-arrow.h \
|
||||
shell-gtkwindow-actor.c \
|
||||
shell-gtkwindow-actor.h \
|
||||
shell-process.c \
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define GMENU_I_KNOW_THIS_IS_UNSTABLE
|
||||
#include <gmenu-tree.h>
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
@ -17,16 +20,41 @@ enum {
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
struct _ShellAppMonitorPrivate {
|
||||
GList *desktop_dir_monitors;
|
||||
GMenuTree *tree;
|
||||
GMenuTreeDirectory *trunk;
|
||||
|
||||
GList *cached_menus;
|
||||
};
|
||||
|
||||
static void shell_app_monitor_finalize (GObject *object);
|
||||
static void on_monitor_changed (GFileMonitor *monitor, GFile *file,
|
||||
GFile *other_file, GFileMonitorEvent event_type,
|
||||
gpointer user_data);
|
||||
static void on_tree_changed (GMenuTree *tree, gpointer user_data);
|
||||
static void reread_menus (ShellAppMonitor *self);
|
||||
|
||||
G_DEFINE_TYPE(ShellAppMonitor, shell_app_monitor, G_TYPE_OBJECT);
|
||||
|
||||
static gpointer
|
||||
shell_app_menu_entry_copy (gpointer entryp)
|
||||
{
|
||||
ShellAppMenuEntry *entry;
|
||||
ShellAppMenuEntry *copy;
|
||||
entry = entryp;
|
||||
copy = g_new0 (ShellAppMenuEntry, 1);
|
||||
copy->name = g_strdup (entry->name);
|
||||
copy->id = g_strdup (entry->id);
|
||||
copy->icon = g_strdup (entry->icon);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void
|
||||
shell_app_menu_entry_free (gpointer entryp)
|
||||
{
|
||||
ShellAppMenuEntry *entry = entryp;
|
||||
g_free (entry->name);
|
||||
g_free (entry->id);
|
||||
g_free (entry->icon);
|
||||
g_free (entry);
|
||||
}
|
||||
|
||||
static void shell_app_monitor_class_init(ShellAppMonitorClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = (GObjectClass *)klass;
|
||||
@ -48,33 +76,18 @@ static void shell_app_monitor_class_init(ShellAppMonitorClass *klass)
|
||||
static void
|
||||
shell_app_monitor_init (ShellAppMonitor *self)
|
||||
{
|
||||
const gchar *const *iter;
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
||||
SHELL_TYPE_APP_MONITOR,
|
||||
ShellAppMonitorPrivate);
|
||||
for (iter = g_get_system_data_dirs (); *iter; iter++)
|
||||
{
|
||||
char *app_path;
|
||||
GFile *dir;
|
||||
GFileMonitor *monitor;
|
||||
GError *error = NULL;
|
||||
ShellAppMonitorPrivate *priv;
|
||||
self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
||||
SHELL_TYPE_APP_MONITOR,
|
||||
ShellAppMonitorPrivate);
|
||||
|
||||
app_path = g_build_filename (*iter, "applications", NULL);
|
||||
priv->tree = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_NONE);
|
||||
|
||||
dir = g_file_new_for_path (app_path);
|
||||
g_free (app_path);
|
||||
monitor = g_file_monitor_directory (dir, 0, NULL, &error);
|
||||
if (!monitor) {
|
||||
g_warning ("failed to monitor %s", error->message);
|
||||
g_clear_error (&error);
|
||||
continue;
|
||||
}
|
||||
g_signal_connect (monitor, "changed", G_CALLBACK (on_monitor_changed), self);
|
||||
self->priv->desktop_dir_monitors
|
||||
= g_list_prepend (self->priv->desktop_dir_monitors,
|
||||
monitor);
|
||||
g_object_unref (dir);
|
||||
}
|
||||
priv->trunk = gmenu_tree_get_root_directory (priv->tree);
|
||||
|
||||
gmenu_tree_add_monitor (priv->tree, on_tree_changed, self);
|
||||
|
||||
reread_menus (self);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -82,18 +95,112 @@ shell_app_monitor_finalize (GObject *object)
|
||||
{
|
||||
ShellAppMonitor *self = SHELL_APP_MONITOR (object);
|
||||
|
||||
g_list_foreach (self->priv->desktop_dir_monitors, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (self->priv->desktop_dir_monitors);
|
||||
|
||||
G_OBJECT_CLASS (shell_app_monitor_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitor_changed (GFileMonitor *monitor, GFile *file,
|
||||
GFile *other_file, GFileMonitorEvent event_type,
|
||||
gpointer user_data)
|
||||
reread_menus (ShellAppMonitor *self)
|
||||
{
|
||||
GSList *entries = gmenu_tree_directory_get_contents (self->priv->trunk);
|
||||
GSList *iter;
|
||||
ShellAppMonitorPrivate *priv = self->priv;
|
||||
|
||||
g_list_foreach (self->priv->cached_menus, (GFunc)shell_app_menu_entry_free, NULL);
|
||||
g_list_free (self->priv->cached_menus);
|
||||
self->priv->cached_menus = NULL;
|
||||
|
||||
for (iter = entries; iter; iter = iter->next)
|
||||
{
|
||||
GMenuTreeEntry *entry = iter->data;
|
||||
ShellAppMenuEntry *shell_entry = g_new0 (ShellAppMenuEntry, 1);
|
||||
|
||||
shell_entry->name = g_strdup (gmenu_tree_entry_get_name (entry));
|
||||
shell_entry->id = g_strdup (gmenu_tree_entry_get_desktop_file_id (entry));
|
||||
shell_entry->icon = g_strdup (gmenu_tree_entry_get_icon (entry));
|
||||
|
||||
priv->cached_menus = g_list_prepend (priv->cached_menus, shell_entry);
|
||||
|
||||
gmenu_tree_item_unref (entry);
|
||||
}
|
||||
priv->cached_menus = g_list_reverse (priv->cached_menus);
|
||||
|
||||
g_slist_free (entries);
|
||||
}
|
||||
|
||||
static void
|
||||
on_tree_changed (GMenuTree *monitor, gpointer user_data)
|
||||
{
|
||||
ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
|
||||
|
||||
g_signal_emit (self, signals[CHANGED], 0);
|
||||
|
||||
reread_menus (self);
|
||||
}
|
||||
|
||||
GType
|
||||
shell_app_menu_entry_get_type (void)
|
||||
{
|
||||
static GType gtype = G_TYPE_INVALID;
|
||||
if (gtype == G_TYPE_INVALID)
|
||||
{
|
||||
gtype = g_boxed_type_register_static ("ShellAppMenuEntry",
|
||||
shell_app_menu_entry_copy,
|
||||
shell_app_menu_entry_free);
|
||||
}
|
||||
return gtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_monitor_get_applications_for_menu:
|
||||
*
|
||||
* Return value: (transfer full) (element-type utf8): List of desktop file ids
|
||||
*/
|
||||
GList *
|
||||
shell_app_monitor_get_applications_for_menu (ShellAppMonitor *monitor,
|
||||
const char *menu)
|
||||
{
|
||||
GList *ret = NULL;
|
||||
GSList *contents;
|
||||
GSList *iter;
|
||||
char *path;
|
||||
GMenuTreeDirectory *menu_entry;
|
||||
|
||||
path = g_strdup_printf ("/%s", menu);
|
||||
menu_entry = gmenu_tree_get_directory_from_path (monitor->priv->tree, path);
|
||||
g_free (path);
|
||||
g_assert (menu_entry != NULL);
|
||||
|
||||
contents = gmenu_tree_directory_get_contents (menu_entry);
|
||||
|
||||
for (iter = contents; iter; iter = iter->next)
|
||||
{
|
||||
GMenuTreeItem *item = iter->data;
|
||||
switch (gmenu_tree_item_get_type (item))
|
||||
{
|
||||
case GMENU_TREE_ITEM_ENTRY:
|
||||
{
|
||||
GMenuTreeEntry *entry = (GMenuTreeEntry *)item;
|
||||
const char *id = gmenu_tree_entry_get_desktop_file_id (entry);
|
||||
ret = g_list_prepend (ret, g_strdup (id));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
gmenu_tree_item_unref (item);
|
||||
}
|
||||
g_slist_free (contents);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_monitor_get_menus:
|
||||
*
|
||||
* Return value: (transfer none) (element-type AppMenuEntry): List of toplevel menus
|
||||
*/
|
||||
GList *
|
||||
shell_app_monitor_get_menus (ShellAppMonitor *monitor)
|
||||
{
|
||||
return monitor->priv->cached_menus;
|
||||
}
|
||||
|
@ -31,4 +31,18 @@ struct _ShellAppMonitorClass
|
||||
GType shell_app_monitor_get_type (void) G_GNUC_CONST;
|
||||
ShellAppMonitor* shell_app_monitor_new(void);
|
||||
|
||||
GList *shell_app_monitor_get_applications_for_menu (ShellAppMonitor *monitor, const char *menu);
|
||||
|
||||
typedef struct _ShellAppMenuEntry ShellAppMenuEntry;
|
||||
|
||||
struct _ShellAppMenuEntry {
|
||||
char *name;
|
||||
char *id;
|
||||
char *icon;
|
||||
};
|
||||
|
||||
GType shell_app_menu_entry_get_type (void);
|
||||
|
||||
GList *shell_app_monitor_get_menus (ShellAppMonitor *monitor);
|
||||
|
||||
#endif /* __SHELL_APP_MONITOR_H__ */
|
||||
|
141
src/shell-arrow.c
Normal file
141
src/shell-arrow.c
Normal file
@ -0,0 +1,141 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
#include "shell-arrow.h"
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <cairo.h>
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
PROP_DIRECTION
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ShellArrow, shell_arrow, CLUTTER_TYPE_CAIRO_TEXTURE);
|
||||
|
||||
struct _ShellArrowPrivate {
|
||||
GtkArrowType direction;
|
||||
};
|
||||
|
||||
static void shell_arrow_redraw (ShellArrow *self);
|
||||
|
||||
static void
|
||||
shell_arrow_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ShellArrow *self = SHELL_ARROW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DIRECTION:
|
||||
self->priv->direction = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
|
||||
shell_arrow_redraw (self);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_arrow_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ShellArrow *self = SHELL_ARROW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DIRECTION:
|
||||
g_value_set_enum (value, self->priv->direction);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
shell_arrow_redraw (ShellArrow *self)
|
||||
{
|
||||
cairo_t *cr;
|
||||
guint width, height;
|
||||
|
||||
g_object_get (G_OBJECT (self), "surface-width", &width,
|
||||
"surface-height", &height,
|
||||
NULL);
|
||||
|
||||
if (width == 0)
|
||||
return;
|
||||
|
||||
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (self));
|
||||
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
|
||||
switch (self->priv->direction)
|
||||
{
|
||||
case GTK_ARROW_RIGHT:
|
||||
cairo_move_to (cr, 0, 0);
|
||||
cairo_line_to (cr, width, height*0.5);
|
||||
cairo_line_to (cr, 0, height);
|
||||
break;
|
||||
case GTK_ARROW_LEFT:
|
||||
cairo_move_to (cr, width, 0);
|
||||
cairo_line_to (cr, 0, height*0.5);
|
||||
cairo_line_to (cr, width, height);
|
||||
break;
|
||||
case GTK_ARROW_UP:
|
||||
cairo_move_to (cr, 0, height);
|
||||
cairo_line_to (cr, width*0.5, 0);
|
||||
cairo_line_to (cr, width, height);
|
||||
break;
|
||||
case GTK_ARROW_DOWN:
|
||||
cairo_move_to (cr, 0, 0);
|
||||
cairo_line_to (cr, width*0.5, height);
|
||||
cairo_line_to (cr, width, height);
|
||||
break;
|
||||
case GTK_ARROW_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cairo_close_path (cr);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_arrow_class_init (ShellArrowClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (ShellArrowPrivate));
|
||||
|
||||
object_class->get_property = shell_arrow_get_property;
|
||||
object_class->set_property = shell_arrow_set_property;
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_DIRECTION,
|
||||
g_param_spec_enum ("direction",
|
||||
"Direction",
|
||||
"Direction",
|
||||
GTK_TYPE_ARROW_TYPE,
|
||||
GTK_ARROW_NONE,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
shell_arrow_init (ShellArrow *actor)
|
||||
{
|
||||
actor->priv = G_TYPE_INSTANCE_GET_PRIVATE (actor, SHELL_TYPE_ARROW,
|
||||
ShellArrowPrivate);
|
||||
g_signal_connect (actor, "notify::surface-width", G_CALLBACK (shell_arrow_redraw), NULL);
|
||||
}
|
33
src/shell-arrow.h
Normal file
33
src/shell-arrow.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef __SHELL_ARROW_H__
|
||||
#define __SHELL_ARROW_H__
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define SHELL_TYPE_ARROW (shell_arrow_get_type ())
|
||||
#define SHELL_ARROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHELL_TYPE_ARROW, ShellArrow))
|
||||
#define SHELL_ARROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_ARROW, ShellArrowClass))
|
||||
#define SHELL_IS_ARROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHELL_TYPE_ARROW))
|
||||
#define SHELL_IS_ARROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_ARROW))
|
||||
#define SHELL_ARROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_ARROW, ShellArrowClass))
|
||||
|
||||
typedef struct _ShellArrow ShellArrow;
|
||||
typedef struct _ShellArrowClass ShellArrowClass;
|
||||
|
||||
typedef struct _ShellArrowPrivate ShellArrowPrivate;
|
||||
|
||||
struct _ShellArrow
|
||||
{
|
||||
ClutterCairoTexture parent;
|
||||
|
||||
ShellArrowPrivate *priv;
|
||||
};
|
||||
|
||||
struct _ShellArrowClass
|
||||
{
|
||||
ClutterCairoTextureClass parent_class;
|
||||
};
|
||||
|
||||
GType shell_arrow_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#endif /* __SHELL_ARROW_H__ */
|
Reference in New Issue
Block a user