diff options
author | Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> | 2006-12-13 15:25:06 +0000 |
---|---|---|
committer | Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> | 2006-12-13 15:25:06 +0000 |
commit | ffa5bba63eb37ff66c4b114256fe75feab6a4906 (patch) | |
tree | eeefac9a2a3d71f3e935f7540d2e14c9ac79779e /src/hildon-program.c | |
parent | 8420c2f3f8af84fcb7d265d7aaa5785dad51d5ad (diff) |
Cleaning up HildonProgram.
Diffstat (limited to 'src/hildon-program.c')
-rw-r--r-- | src/hildon-program.c | 269 |
1 files changed, 129 insertions, 140 deletions
diff --git a/src/hildon-program.c b/src/hildon-program.c index 6e45fe7..24ac55e 100644 --- a/src/hildon-program.c +++ b/src/hildon-program.c @@ -29,45 +29,31 @@ * */ -#include <config.h> -#include "hildon-program.h" -#include "hildon-window-private.h" -#include <X11/Xatom.h> - -#define HILDON_PROGRAM_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_PROGRAM, HildonProgramPriv)); - - -typedef struct _HildonProgramPriv HildonProgramPriv; - -struct _HildonProgramPriv -{ - gboolean killable; - gboolean is_topmost; - GdkWindow *group_leader; - guint window_count; - GtkWidget *common_menu; - GtkWidget *common_toolbar; - GSList *windows; - Window window_group; - gchar *name; -}; +#include <config.h> +#include "hildon-program.h" +#include "hildon-program-private.h" +#include "hildon-window-private.h" +#include <X11/Xatom.h> static void -hildon_program_init (HildonProgram *self); +hildon_program_init (HildonProgram *self); static void -hildon_program_finalize (GObject *self); +hildon_program_finalize (GObject *self); static void -hildon_program_class_init (HildonProgramClass *self); +hildon_program_class_init (HildonProgramClass *self); static void -hildon_program_get_property(GObject * object, guint property_id, - GValue * value, GParamSpec * pspec); +hildon_program_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); static void -hildon_program_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec); +hildon_program_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); enum { @@ -76,23 +62,22 @@ enum PROP_KILLABLE }; - GType -hildon_program_get_type (void) +hildon_program_get_type (void) { static GType program_type = 0; - if (!program_type) + if (! program_type) { static const GTypeInfo program_info = { - sizeof(HildonProgramClass), + sizeof (HildonProgramClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) hildon_program_class_init, NULL, /* class_finalize */ NULL, /* class_data */ - sizeof(HildonProgram), + sizeof (HildonProgram), 0, /* n_preallocs */ (GInstanceInitFunc) hildon_program_init, }; @@ -103,23 +88,24 @@ hildon_program_get_type (void) } static void -hildon_program_init (HildonProgram *self) +hildon_program_init (HildonProgram *self) { - HildonProgramPriv *priv = HILDON_PROGRAM_GET_PRIVATE (self); - + HildonProgramPrivate *priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); + priv->killable = FALSE; priv->window_count = 0; priv->is_topmost = FALSE; - priv->window_group = GDK_WINDOW_XID (gdk_display_get_default_group - (gdk_display_get_default())); + priv->window_group = GDK_WINDOW_XID (gdk_display_get_default_group (gdk_display_get_default())); priv->common_toolbar = NULL; priv->name = NULL; } static void -hildon_program_finalize (GObject *self) +hildon_program_finalize (GObject *self) { - HildonProgramPriv *priv = HILDON_PROGRAM_GET_PRIVATE (HILDON_PROGRAM (self)); + HildonProgramPrivate *priv = HILDON_PROGRAM_GET_PRIVATE (HILDON_PROGRAM (self)); + g_assert (priv); if (priv->common_toolbar) { @@ -134,20 +120,19 @@ hildon_program_finalize (GObject *self) } g_free (priv->name); - } static void -hildon_program_class_init (HildonProgramClass *self) +hildon_program_class_init (HildonProgramClass *self) { - GObjectClass *object_class = G_OBJECT_CLASS(self); + GObjectClass *object_class = G_OBJECT_CLASS (self); - g_type_class_add_private (self, sizeof(HildonProgramPriv)); + g_type_class_add_private (self, sizeof (HildonProgramPrivate)); /* Set up object virtual functions */ - object_class->finalize = hildon_program_finalize; - object_class->set_property = hildon_program_set_property; - object_class->get_property = hildon_program_get_property; + object_class->finalize = hildon_program_finalize; + object_class->set_property = hildon_program_set_property; + object_class->get_property = hildon_program_get_property; /* Install properties */ g_object_class_install_property (object_class, PROP_IS_TOPMOST, @@ -168,15 +153,16 @@ hildon_program_class_init (HildonProgramClass *self) return; } - static void -hildon_program_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) +hildon_program_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - switch (property_id){ + switch (property_id) { + case PROP_KILLABLE: - hildon_program_set_can_hibernate (HILDON_PROGRAM (object), - g_value_get_boolean (value)); + hildon_program_set_can_hibernate (HILDON_PROGRAM (object), g_value_get_boolean (value)); break; default: @@ -187,33 +173,37 @@ hildon_program_set_property (GObject * object, guint property_id, } static void -hildon_program_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) +hildon_program_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - HildonProgramPriv *priv = HILDON_PROGRAM_GET_PRIVATE (object); - - switch (property_id) - { - case PROP_KILLABLE: - g_value_set_boolean (value, priv->killable); - break; - case PROP_IS_TOPMOST: - g_value_set_boolean (value, priv->is_topmost); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } - + HildonProgramPrivate *priv = HILDON_PROGRAM_GET_PRIVATE (object); + g_assert (priv); + + switch (property_id) + { + case PROP_KILLABLE: + g_value_set_boolean (value, priv->killable); + break; + + case PROP_IS_TOPMOST: + g_value_set_boolean (value, priv->is_topmost); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } } /* Utilities */ static gint -hildon_program_window_list_compare (gconstpointer window_a, - gconstpointer window_b) +hildon_program_window_list_compare (gconstpointer window_a, + gconstpointer window_b) { - g_return_val_if_fail (1, HILDON_IS_WINDOW(window_a) && - HILDON_IS_WINDOW(window_b)); + g_return_val_if_fail (HILDON_IS_WINDOW(window_a) && + HILDON_IS_WINDOW(window_b), 1); return window_a != window_b; } @@ -222,7 +212,8 @@ hildon_program_window_list_compare (gconstpointer window_a, * foreach function, checks if a window is topmost and acts consequently */ static void -hildon_program_window_list_is_is_topmost (gpointer data, gpointer window_id_) +hildon_program_window_list_is_is_topmost (gpointer data, + gpointer window_id_) { if (data && HILDON_IS_WINDOW (data)) { @@ -238,13 +229,14 @@ hildon_program_window_list_is_is_topmost (gpointer data, gpointer window_id_) * the top_most status accordingly */ static void -hildon_program_update_top_most (HildonProgram *program) +hildon_program_update_top_most (HildonProgram *program) { XWMHints *wm_hints; Window active_window; - HildonProgramPriv *priv; + HildonProgramPrivate *priv; priv = HILDON_PROGRAM_GET_PRIVATE (program); + g_assert (priv); active_window = hildon_window_get_active_window(); @@ -277,18 +269,15 @@ hildon_program_update_top_most (HildonProgram *program) (GFunc)hildon_program_window_list_is_is_topmost, &active_window); } - -/* Event filter */ - /* * We keep track of the _MB_CURRENT_APP_WINDOW property on the root window, * to detect when a window belonging to this program was is_topmost. This * is based on the window group WM hint. */ static GdkFilterReturn -hildon_program_root_window_event_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) +hildon_program_root_window_event_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) { XAnyEvent *eventti = xevent; HildonProgram *program = HILDON_PROGRAM (data); @@ -307,40 +296,31 @@ hildon_program_root_window_event_filter (GdkXEvent *xevent, return GDK_FILTER_CONTINUE; } - -/** - * hildon_program_common_toolbar_topmost_window: - * @window: A @HildonWindow to be informed about its new common toolbar - * @data: Not used, it is here just to respect the API - * +/* * Checks if the window is the topmost window of the program and in * that case forces the window to take the common toolbar. - **/ + */ static void -hildon_program_common_toolbar_topmost_window (gpointer window, gpointer data) +hildon_program_common_toolbar_topmost_window (gpointer window, + gpointer data) { - if (HILDON_IS_WINDOW (window) && - hildon_window_get_is_topmost (HILDON_WINDOW (window))) - { + if (HILDON_IS_WINDOW (window) && hildon_window_get_is_topmost (HILDON_WINDOW (window))) hildon_window_take_common_toolbar (HILDON_WINDOW (window)); - } } -/* Public methods */ - /** * hildon_program_get_instance: * * Return value: Returns the #HildonProgram for the current process. * The object is created on the first call. **/ -HildonProgram * -hildon_program_get_instance () +HildonProgram* +hildon_program_get_instance (void) { static HildonProgram *program = NULL; - if (!program) + if (! program) { program = g_object_new (HILDON_TYPE_PROGRAM, NULL); } @@ -359,13 +339,15 @@ hildon_program_get_instance () * hildon_pogram_set_common_toolbar() **/ void -hildon_program_add_window (HildonProgram *self, HildonWindow *window) +hildon_program_add_window (HildonProgram *self, + HildonWindow *window) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_if_fail (self && HILDON_IS_PROGRAM (self)); + g_return_if_fail (HILDON_IS_PROGRAM (self)); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); if (g_slist_find_custom (priv->windows, window, hildon_program_window_list_compare) ) @@ -381,7 +363,8 @@ hildon_program_add_window (HildonProgram *self, HildonWindow *window) /* Now that we have a window we should start keeping track of * the root window */ gdk_window_set_events (gdk_get_default_root_window (), - gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK); + gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK); + gdk_window_add_filter (gdk_get_default_root_window (), hildon_program_root_window_event_filter, self ); } @@ -404,13 +387,15 @@ hildon_program_add_window (HildonProgram *self, HildonWindow *window) * will not affect the window **/ void -hildon_program_remove_window (HildonProgram *self, HildonWindow *window) +hildon_program_remove_window (HildonProgram *self, + HildonWindow *window) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_if_fail (self && HILDON_IS_PROGRAM (self)); + g_return_if_fail (HILDON_IS_PROGRAM (self)); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); hildon_window_unset_program (window); @@ -418,12 +403,10 @@ hildon_program_remove_window (HildonProgram *self, HildonWindow *window) priv->window_count --; - if (!priv->window_count) - { + if (! priv->window_count) gdk_window_remove_filter (gdk_get_default_root_window(), hildon_program_root_window_event_filter, self); - } } /** @@ -435,13 +418,15 @@ hildon_program_remove_window (HildonProgram *self, HildonWindow *window) * be able to set the program to hibernation in case of low memory **/ void -hildon_program_set_can_hibernate (HildonProgram *self, gboolean killable) +hildon_program_set_can_hibernate (HildonProgram *self, + gboolean killable) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_if_fail (self && HILDON_IS_PROGRAM (self)); + g_return_if_fail (HILDON_IS_PROGRAM (self)); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); if (priv->killable != killable) { @@ -450,7 +435,6 @@ hildon_program_set_can_hibernate (HildonProgram *self, gboolean killable) } priv->killable = killable; - } /** @@ -461,16 +445,16 @@ hildon_program_set_can_hibernate (HildonProgram *self, gboolean killable) * support hibernation from the Hildon task navigator **/ gboolean -hildon_program_get_can_hibernate (HildonProgram *self) +hildon_program_get_can_hibernate (HildonProgram *self) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_val_if_fail (self && HILDON_IS_PROGRAM (self), FALSE); + g_return_val_if_fail (HILDON_IS_PROGRAM (self), FALSE); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); return priv->killable; - } /** @@ -484,19 +468,21 @@ hildon_program_get_can_hibernate (HildonProgram *self) * can use it's own GtkMenu with @hildon_window_set_menu **/ void -hildon_program_set_common_menu (HildonProgram *self, GtkMenu *menu) +hildon_program_set_common_menu (HildonProgram *self, + GtkMenu *menu) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_if_fail (self && HILDON_IS_PROGRAM (self)); + g_return_if_fail (HILDON_IS_PROGRAM (self)); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); if (priv->common_menu) { if (GTK_WIDGET_VISIBLE (priv->common_menu)) { - gtk_menu_popdown (GTK_MENU(priv->common_menu)); + gtk_menu_popdown (GTK_MENU (priv->common_menu)); gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->common_menu)); } @@ -527,14 +513,15 @@ hildon_program_set_common_menu (HildonProgram *self, GtkMenu *menu) * Return value: the GtkMenu that was set as common menu for this * #HildonProgram, or NULL of no common menu was set. **/ -GtkMenu * -hildon_program_get_common_menu (HildonProgram *self) +GtkMenu* +hildon_program_get_common_menu (HildonProgram *self) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_val_if_fail (self && HILDON_IS_PROGRAM (self), NULL); + g_return_val_if_fail (HILDON_IS_PROGRAM (self), NULL); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); return GTK_MENU (priv->common_menu); } @@ -551,13 +538,15 @@ hildon_program_get_common_menu (HildonProgram *self) * #HildonProgram and @HildonWindow specific toolbars will be shown **/ void -hildon_program_set_common_toolbar (HildonProgram *self, GtkToolbar *toolbar) +hildon_program_set_common_toolbar (HildonProgram *self, + GtkToolbar *toolbar) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_if_fail (self && HILDON_IS_PROGRAM (self)); + g_return_if_fail (HILDON_IS_PROGRAM (self)); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); if (priv->common_toolbar) { @@ -594,14 +583,15 @@ hildon_program_set_common_toolbar (HildonProgram *self, GtkToolbar *toolbar) * Return value: the GtkToolbar that was set as common toolbar for this * #HildonProgram, or NULL of no common menu was set. **/ -GtkToolbar * -hildon_program_get_common_toolbar (HildonProgram *self) +GtkToolbar* +hildon_program_get_common_toolbar (HildonProgram *self) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_val_if_fail (self && HILDON_IS_PROGRAM (self), NULL); + g_return_val_if_fail (HILDON_IS_PROGRAM (self), NULL); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); return priv->common_toolbar ? GTK_TOOLBAR (priv->common_toolbar) : NULL; } @@ -614,15 +604,14 @@ hildon_program_get_common_toolbar (HildonProgram *self) * currenltly activated by the window manager. **/ gboolean -hildon_program_get_is_topmost (HildonProgram *self) +hildon_program_get_is_topmost (HildonProgram *self) { - HildonProgramPriv *priv; + HildonProgramPrivate *priv; - g_return_val_if_fail (self && HILDON_IS_PROGRAM (self), FALSE); + g_return_val_if_fail (HILDON_IS_PROGRAM (self), FALSE); priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); return priv->is_topmost; } - - |