diff options
Diffstat (limited to 'plugins/background/msd-background-manager.c')
-rw-r--r-- | plugins/background/msd-background-manager.c | 985 |
1 files changed, 514 insertions, 471 deletions
diff --git a/plugins/background/msd-background-manager.c b/plugins/background/msd-background-manager.c index 5353c94..033f8a3 100644 --- a/plugins/background/msd-background-manager.c +++ b/plugins/background/msd-background-manager.c @@ -32,8 +32,6 @@ #include <locale.h> -#include <dbus/dbus.h> - #include <glib.h> #include <glib/gi18n.h> #include <gdk/gdk.h> @@ -47,568 +45,613 @@ #include "mate-settings-profile.h" #include "msd-background-manager.h" -#define CAJA_SCHEMA "org.mate.caja.preferences" -#define CAJA_SHOW_DESKTOP_KEY "show-desktop" - -#define MSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerPrivate)) - -//class MsdBackgroundManager -//{ - struct MsdBackgroundManagerPrivate { - GSettings* bg_settings; - GSettings* caja_settings; - MateBG* bg; - guint timeout_id; - - DBusConnection* dbus_connection; - }; +#if !GTK_CHECK_VERSION(3, 0, 0) +#define cairo_surface_t GdkPixmap +#define cairo_surface_destroy g_object_unref +#define mate_bg_create_surface mate_bg_create_pixmap +#define mate_bg_set_surface_as_root mate_bg_set_pixmap_as_root +#define mate_bg_set_surface_as_root_with_crossfade mate_bg_set_pixmap_as_root_with_crossfade +#endif - static void - msd_background_manager_class_init (MsdBackgroundManagerClass* klass); +#define MATE_BG_SHOW_DESKTOP_ICONS "show-desktop-icons" +#define MATE_BG_DRAW_BACKGROUND "draw-background" - static void +#define MATE_SESSION_MANAGER_DBUS_NAME "org.mate.SessionManager" +#define MATE_SESSION_MANAGER_DBUS_PATH "/org/mate/SessionManager" - msd_background_manager_init (MsdBackgroundManager* background_manager); +#define MSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerPrivate)) - static void - msd_background_manager_finalize (GObject* object); +struct MsdBackgroundManagerPrivate { + GSettings *settings; + MateBG *bg; + guint timeout_id; - G_DEFINE_TYPE(MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT) + MateBGCrossfade *fade; - static gpointer manager_object = NULL; + GDBusProxy *proxy; + guint proxy_signal_id; +}; - static gboolean - caja_is_running (void) - { - Atom window_id_atom; - Window caja_xid; - Atom actual_type; - int actual_format; - unsigned long nitems; - unsigned long bytes_after; - unsigned char* data; - int retval; - Atom wmclass_atom; - gboolean running; - gint error; - - window_id_atom = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - "CAJA_DESKTOP_WINDOW_ID", True); - - if (window_id_atom == None) - { - return FALSE; - } - - retval = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - GDK_ROOT_WINDOW(), - window_id_atom, - 0, - 1, - False, - XA_WINDOW, - &actual_type, - &actual_format, - &nitems, - &bytes_after, - &data); - - if (data != NULL) - { - caja_xid = *(Window*) data; - XFree(data); - } - else - { - return FALSE; - } - - if (actual_type != XA_WINDOW) - { - return FALSE; - } +static void +msd_background_manager_class_init (MsdBackgroundManagerClass* klass); - if (actual_format != 32) - { - return FALSE; - } +static void - wmclass_atom = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "WM_CLASS", False); +msd_background_manager_init (MsdBackgroundManager* background_manager); - gdk_error_trap_push(); +static void +msd_background_manager_finalize (GObject* object); - retval = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - caja_xid, - wmclass_atom, - 0, - 24, - False, - XA_STRING, - &actual_type, - &actual_format, - &nitems, - &bytes_after, - &data); +static void setup_bg (MsdBackgroundManager *manager); +static void connect_screen_signals (MsdBackgroundManager *manager); - error = gdk_error_trap_pop(); +G_DEFINE_TYPE(MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT) - if (error == BadWindow) - { - return FALSE; - } +static gpointer manager_object = NULL; - if (actual_type == XA_STRING && - nitems == 24 && - bytes_after == 0 && - actual_format == 8 && - data != NULL && - !strcmp((char*) data, "desktop_window") && - !strcmp((char*) data + strlen((char*) data) + 1, "Caja")) - { - running = TRUE; - } - else - { - running = FALSE; - } +static gboolean +dont_draw_background (MsdBackgroundManager *manager) +{ + return !g_settings_get_boolean (manager->priv->settings, + MATE_BG_DRAW_BACKGROUND); +} - if (data != NULL) - { - XFree(data); - } +static gboolean +caja_is_drawing_background (MsdBackgroundManager *manager) +{ + Atom window_id_atom; + Window caja_xid; + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes_after; + unsigned char* data; + Atom wmclass_atom; + gboolean running; + gint error; + gboolean show_desktop_icons; - return running; + show_desktop_icons = g_settings_get_boolean (manager->priv->settings, + MATE_BG_SHOW_DESKTOP_ICONS); + if (!show_desktop_icons) { + return FALSE; } - static void - draw_background (MsdBackgroundManager* manager, - gboolean use_crossfade) - { - GdkDisplay* display; - int n_screens; - int i; - - if (caja_is_running()) - { - return; - } - - mate_settings_profile_start(NULL); + window_id_atom = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + "CAJA_DESKTOP_WINDOW_ID", True); - display = gdk_display_get_default(); - n_screens = gdk_display_get_n_screens(display); - - for (i = 0; i < n_screens; ++i) - { - GdkScreen* screen; - GdkWindow* root_window; - GdkPixmap* pixmap; - - screen = gdk_display_get_screen(display, i); - - root_window = gdk_screen_get_root_window(screen); - - pixmap = mate_bg_create_pixmap(manager->priv->bg, - root_window, - gdk_screen_get_width(screen), - gdk_screen_get_height(screen), - TRUE); - - if (use_crossfade) - { - MateBGCrossfade* fade; - - fade = mate_bg_set_pixmap_as_root_with_crossfade(screen, pixmap); - g_signal_connect(fade, - "finished", - G_CALLBACK (g_object_unref), NULL); - } - else - { - mate_bg_set_pixmap_as_root(screen, pixmap); - } - - g_object_unref(pixmap); - } - - mate_settings_profile_end(NULL); + if (window_id_atom == None) { + return FALSE; } - static void - on_bg_changed (MateBG* bg, - MsdBackgroundManager* manager) + XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + GDK_ROOT_WINDOW(), + window_id_atom, + 0, + 1, + False, + XA_WINDOW, + &actual_type, + &actual_format, + &nitems, + &bytes_after, + &data); + + if (data != NULL) { - draw_background(manager, TRUE); + caja_xid = *(Window*) data; + XFree(data); } - - static void - on_bg_transitioned (MateBG* bg, - MsdBackgroundManager* manager) + else { - draw_background(manager, FALSE); + return FALSE; } - static void - settings_changed_callback (GSettings* settings, - gchar* key, - MsdBackgroundManager* manager) + if (actual_type != XA_WINDOW) { - mate_bg_load_from_preferences(manager->priv->bg); + return FALSE; } - static void - watch_bg_preferences (MsdBackgroundManager* manager) + if (actual_format != 32) { - g_signal_connect (manager->priv->bg_settings, - "changed", - G_CALLBACK (settings_changed_callback), - manager); + return FALSE; } - static void - setup_bg (MsdBackgroundManager* manager) - { - g_return_if_fail(manager->priv->bg == NULL); + wmclass_atom = XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "WM_CLASS", False); - manager->priv->bg = mate_bg_new(); + gdk_error_trap_push(); - /*g_signal_connect(manager->priv->bg, - "changed", - G_CALLBACK(on_bg_changed), - manager);*/ + XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + caja_xid, + wmclass_atom, + 0, + 20, + False, + XA_STRING, + &actual_type, + &actual_format, + &nitems, + &bytes_after, + &data); - /*g_signal_connect(manager->priv->bg, - "transitioned", - G_CALLBACK(on_bg_transitioned), - manager);*/ + error = gdk_error_trap_pop(); - watch_bg_preferences(manager); - mate_bg_load_from_preferences(manager->priv->bg); + if (error == BadWindow) + { + return FALSE; } - static gboolean - queue_draw_background (MsdBackgroundManager* manager) + if (actual_type == XA_STRING && + nitems == 20 && + bytes_after == 0 && + actual_format == 8 && + data != NULL && + !strcmp((char*) data, "desktop_window") && + !strcmp((char*) data + strlen((char*) data) + 1, "Caja")) { - manager->priv->timeout_id = 0; - - if (caja_is_running()) - { - return FALSE; - } - - setup_bg(manager); - draw_background(manager, FALSE); + running = TRUE; + } + else + { + running = FALSE; + } - return FALSE; + if (data != NULL) + { + XFree(data); } - static DBusHandlerResult - on_bus_message (DBusConnection* connection, - DBusMessage* message, - void* user_data) + return running; +} + +static void +on_crossfade_finished (MsdBackgroundManager *manager) +{ + g_object_unref (manager->priv->fade); + manager->priv->fade = NULL; +} + +static void +draw_background (MsdBackgroundManager *manager, + gboolean use_crossfade) +{ + GdkDisplay *display; + int n_screens; + int i; + + if (caja_is_drawing_background (manager) || dont_draw_background (manager)) { - MsdBackgroundManager* manager = user_data; + return; + } - if (dbus_message_is_signal(message, "org.mate.SessionManager", "SessionRunning")) - { - /* If the session finishes then check if caja is - * running and if not, set the background. - * - * We wait a few seconds after the session is up - * because caja tells the session manager that its - * ready before it sets the background. - */ - manager->priv->timeout_id = g_timeout_add_seconds(8, - (GSourceFunc) queue_draw_background, - manager); - dbus_connection_remove_filter(connection, - on_bus_message, - manager); - - manager->priv->dbus_connection = NULL; - } + mate_settings_profile_start(NULL); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } + display = gdk_display_get_default(); + n_screens = gdk_display_get_n_screens(display); - static void - draw_background_after_session_loads (MsdBackgroundManager* manager) + for (i = 0; i < n_screens; ++i) { - DBusConnection* connection; + GdkScreen *screen; + cairo_surface_t *surface; - connection = dbus_bus_get(DBUS_BUS_SESSION, NULL); + screen = gdk_display_get_screen(display, i); - if (connection == NULL) - { - return; - } + surface = mate_bg_create_surface (manager->priv->bg, + gdk_screen_get_root_window (screen), + gdk_screen_get_width (screen), + gdk_screen_get_height (screen), + TRUE); - if (!dbus_connection_add_filter(connection, on_bus_message, manager, NULL)) + if (use_crossfade) { - return; + if (manager->priv->fade != NULL) + g_object_unref (manager->priv->fade); + + manager->priv->fade = mate_bg_set_surface_as_root_with_crossfade (screen, + surface); + g_signal_connect_swapped (manager->priv->fade, "finished", + G_CALLBACK (on_crossfade_finished), + manager); + } else { + mate_bg_set_surface_as_root (screen, surface); } - manager->priv->dbus_connection = connection; + cairo_surface_destroy (surface); } - static void - on_screen_size_changed (GdkScreen* screen, - MsdBackgroundManager* manager) - { - gboolean caja_show_desktop; + mate_settings_profile_end(NULL); +} + +static void +on_bg_transitioned (MateBG *bg, + MsdBackgroundManager *manager) +{ + draw_background (manager, FALSE); +} + +static gboolean +settings_change_event_idle_cb (MsdBackgroundManager *manager) +{ + mate_bg_load_from_gsettings (manager->priv->bg, + manager->priv->settings); + + return FALSE; /* remove from the list of event sources */ +} + +static gboolean +settings_change_event_cb (GSettings *settings, + gpointer keys, + gint n_keys, + MsdBackgroundManager *manager) +{ + /* Defer signal processing to avoid making the dconf backend deadlock */ + g_idle_add ((GSourceFunc) settings_change_event_idle_cb, manager); + + return FALSE; /* let the event propagate further */ +} + +static void +on_screen_size_changed (GdkScreen *screen, + MsdBackgroundManager *manager) +{ + draw_background (manager, FALSE); +} + +static void +on_bg_changed (MateBG *bg, + MsdBackgroundManager *manager) +{ + draw_background (manager, TRUE); +} + +static void +setup_bg (MsdBackgroundManager *manager) +{ + g_return_if_fail (manager->priv->bg == NULL); + + manager->priv->bg = mate_bg_new(); + + g_signal_connect(manager->priv->bg, + "changed", + G_CALLBACK (on_bg_changed), + manager); + + g_signal_connect(manager->priv->bg, + "transitioned", + G_CALLBACK (on_bg_transitioned), + manager); + + connect_screen_signals (manager); + + mate_bg_load_from_gsettings (manager->priv->bg, + manager->priv->settings); + + /* Connect to "change-event" signal to receive *groups of changes* before + * they are split out into multiple emissions of the "changed" signal. + */ + g_signal_connect (manager->priv->settings, + "change-event", + G_CALLBACK (settings_change_event_cb), + manager); +} + +static gboolean +queue_draw_background (MsdBackgroundManager *manager) +{ + manager->priv->timeout_id = 0; + + if (manager->priv->bg == NULL) + setup_bg (manager); + + draw_background (manager, FALSE); + + return FALSE; +} + +static void +queue_timeout (MsdBackgroundManager *manager) +{ + if (manager->priv->timeout_id > 0) + return; + + /* If the session finishes then check if caja is + * running and if not, set the background. + * + * We wait a few seconds after the session is up + * because caja tells the session manager that its + * ready before it sets the background. + */ + manager->priv->timeout_id = g_timeout_add_seconds(8, + (GSourceFunc) queue_draw_background, + manager); +} + +static void +disconnect_session_manager_listener (MsdBackgroundManager* manager) +{ + if (manager->priv->proxy && manager->priv->proxy_signal_id) { + g_signal_handler_disconnect (manager->priv->proxy, + manager->priv->proxy_signal_id); + manager->priv->proxy_signal_id = 0; + } +} + +static void +on_session_manager_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + MsdBackgroundManager *manager = MSD_BACKGROUND_MANAGER (user_data); + + if (g_strcmp0 (signal_name, "SessionRunning") == 0) { + queue_timeout (manager); + disconnect_session_manager_listener (manager); + } +} + +static void +draw_background_after_session_loads (MsdBackgroundManager *manager) +{ + GError *error = NULL; + GDBusProxyFlags flags; + + flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; + manager->priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + flags, + NULL, /* GDBusInterfaceInfo */ + MATE_SESSION_MANAGER_DBUS_NAME, + MATE_SESSION_MANAGER_DBUS_PATH, + MATE_SESSION_MANAGER_DBUS_NAME, + NULL, /* GCancellable */ + &error); + if (manager->priv->proxy == NULL) { + g_warning ("Could not listen to session manager: %s", + error->message); + g_error_free (error); + return; + } - caja_show_desktop = g_settings_get_boolean (manager->priv->caja_settings, - CAJA_SHOW_DESKTOP_KEY); + manager->priv->proxy_signal_id = g_signal_connect (manager->priv->proxy, + "g-signal", + G_CALLBACK (on_session_manager_signal), + manager); +} - if (!caja_is_running() || !caja_show_desktop) - { - if (manager->priv->bg == NULL) - { - setup_bg(manager); - } +static void +disconnect_screen_signals (MsdBackgroundManager* manager) +{ + GdkDisplay* display; + int i; + int n_screens; - draw_background(manager, FALSE); - } - } + display = gdk_display_get_default(); + n_screens = gdk_display_get_n_screens(display); - static void - disconnect_screen_signals (MsdBackgroundManager* manager) + for (i = 0; i < n_screens; ++i) { - GdkDisplay* display; - int i; - int n_screens; + GdkScreen *screen; - display = gdk_display_get_default(); - n_screens = gdk_display_get_n_screens(display); + screen = gdk_display_get_screen(display, i); - for (i = 0; i < n_screens; ++i) - { - GdkScreen *screen; - - screen = gdk_display_get_screen(display, i); - - g_signal_handlers_disconnect_by_func(screen, - G_CALLBACK(on_screen_size_changed), - manager); - } + g_signal_handlers_disconnect_by_func(screen, + G_CALLBACK(on_screen_size_changed), + manager); } +} - static void - connect_screen_signals (MsdBackgroundManager* manager) - { - GdkDisplay* display; - int i; - int n_screens; +static void +connect_screen_signals (MsdBackgroundManager* manager) +{ + GdkDisplay* display; + int i; + int n_screens; - display = gdk_display_get_default(); - n_screens = gdk_display_get_n_screens(display); + display = gdk_display_get_default(); + n_screens = gdk_display_get_n_screens(display); - for (i = 0; i < n_screens; ++i) - { - GdkScreen* screen; - screen = gdk_display_get_screen(display, i); - g_signal_connect(screen, - "monitors-changed", - G_CALLBACK(on_screen_size_changed), - manager); - - g_signal_connect(screen, - "size-changed", - G_CALLBACK(on_screen_size_changed), - manager); - } + for (i = 0; i < n_screens; ++i) + { + GdkScreen* screen; + screen = gdk_display_get_screen(display, i); + g_signal_connect(screen, + "monitors-changed", + G_CALLBACK(on_screen_size_changed), + manager); + + g_signal_connect(screen, + "size-changed", + G_CALLBACK(on_screen_size_changed), + manager); } - - gboolean - msd_background_manager_start (MsdBackgroundManager* manager, - GError** error) +} + +static void +background_handling_changed (GSettings *settings, + const char *key, + MsdBackgroundManager *manager) +{ + if (!dont_draw_background (manager) && + !caja_is_drawing_background (manager)) { - gboolean caja_show_desktop; - - g_debug("Starting background manager"); - mate_settings_profile_start(NULL); - - manager->priv->bg_settings = g_settings_new (MATE_BG_SCHEMA); - manager->priv->caja_settings = g_settings_new (CAJA_SCHEMA); - - /* If this is set, caja will draw the background and is - * almost definitely in our session. however, it may not be - * running yet (so is_caja_running() will fail). so, on - * startup, just don't do anything if this key is set so we - * don't waste time setting the background only to have - * caja overwrite it. - */ - caja_show_desktop = g_settings_get_boolean (manager->priv->caja_settings, - CAJA_SHOW_DESKTOP_KEY); - - if (!caja_show_desktop) - { - setup_bg(manager); - } - else - { - draw_background_after_session_loads(manager); - } - - connect_screen_signals(manager); - - mate_settings_profile_end(NULL); - - return TRUE; + queue_timeout (manager); } - - void - msd_background_manager_stop (MsdBackgroundManager* manager) +} + +gboolean +msd_background_manager_start (MsdBackgroundManager *manager, + GError **error) +{ + gboolean show_desktop_icons; + + g_debug("Starting background manager"); + mate_settings_profile_start(NULL); + + manager->priv->settings = g_settings_new (MATE_BG_SCHEMA); + g_signal_connect (manager->priv->settings, "changed::" MATE_BG_DRAW_BACKGROUND, + G_CALLBACK (background_handling_changed), manager); + g_signal_connect (manager->priv->settings, "changed::" MATE_BG_SHOW_DESKTOP_ICONS, + G_CALLBACK (background_handling_changed), manager); + + /* If this is set, caja will draw the background and is + * almost definitely in our session. however, it may not be + * running yet (so is_caja_running() will fail). so, on + * startup, just don't do anything if this key is set so we + * don't waste time setting the background only to have + * caja overwrite it. + */ + show_desktop_icons = g_settings_get_boolean (manager->priv->settings, + MATE_BG_SHOW_DESKTOP_ICONS); + + if (!show_desktop_icons) { - MsdBackgroundManagerPrivate* p = manager->priv; + setup_bg(manager); + } + else + { + draw_background_after_session_loads(manager); + } - g_debug("Stopping background manager"); + mate_settings_profile_end(NULL); - disconnect_screen_signals(manager); + return TRUE; +} - if (manager->priv->dbus_connection != NULL) - { - dbus_connection_remove_filter(manager->priv->dbus_connection, - on_bus_message, - manager); - } - - if (p->bg_settings != NULL) - { - g_object_unref(p->bg_settings); - p->bg_settings = NULL; - } +void +msd_background_manager_stop (MsdBackgroundManager *manager) +{ + MsdBackgroundManagerPrivate* p = manager->priv; - if (p->caja_settings != NULL) - { - g_object_unref(p->caja_settings); - p->caja_settings = NULL; - } + g_debug("Stopping background manager"); - if (p->timeout_id != 0) - { - g_source_remove(p->timeout_id); - p->timeout_id = 0; - } + disconnect_screen_signals(manager); - if (p->bg != NULL) - { - g_object_unref(p->bg); - p->bg = NULL; - } - } - - static void - msd_background_manager_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec) + if (manager->priv->proxy) { - MsdBackgroundManager* self; - - self = MSD_BACKGROUND_MANAGER(object); - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + disconnect_session_manager_listener (manager); + g_object_unref (manager->priv->proxy); } - static void - msd_background_manager_get_property (GObject* object, - guint prop_id, - GValue* value, - GParamSpec* pspec) - { - MsdBackgroundManager* self; + g_signal_handlers_disconnect_by_func (manager->priv->settings, + settings_change_event_cb, + manager); - self = MSD_BACKGROUND_MANAGER(object); - - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + if (p->settings != NULL) + { + g_object_unref(p->settings); + p->settings = NULL; } - static GObject* - msd_background_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam* construct_properties) + if (p->timeout_id != 0) { - MsdBackgroundManager* background_manager; - MsdBackgroundManagerClass* klass; - - klass = MSD_BACKGROUND_MANAGER_CLASS(g_type_class_peek(MSD_TYPE_BACKGROUND_MANAGER)); - - background_manager = MSD_BACKGROUND_MANAGER(G_OBJECT_CLASS(msd_background_manager_parent_class)->constructor(type, - n_construct_properties, - construct_properties)); - return G_OBJECT(background_manager); + g_source_remove(p->timeout_id); + p->timeout_id = 0; } - static void - msd_background_manager_dispose (GObject* object) + if (p->bg != NULL) { - MsdBackgroundManager* background_manager; - - background_manager = MSD_BACKGROUND_MANAGER(object); - - G_OBJECT_CLASS(msd_background_manager_parent_class)->dispose(object); + g_object_unref(p->bg); + p->bg = NULL; } - - static void - msd_background_manager_class_init (MsdBackgroundManagerClass* klass) +} + +static void +msd_background_manager_set_property (GObject* object, + guint prop_id, + const GValue* value, + GParamSpec* pspec) +{ + switch (prop_id) { - GObjectClass* object_class = G_OBJECT_CLASS(klass); - - object_class->get_property = msd_background_manager_get_property; - object_class->set_property = msd_background_manager_set_property; - object_class->constructor = msd_background_manager_constructor; - object_class->dispose = msd_background_manager_dispose; - object_class->finalize = msd_background_manager_finalize; - - g_type_class_add_private(klass, sizeof(MsdBackgroundManagerPrivate)); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; } - - static void - msd_background_manager_init (MsdBackgroundManager* manager) +} + +static void +msd_background_manager_get_property (GObject* object, + guint prop_id, + GValue* value, + GParamSpec* pspec) +{ + switch (prop_id) { - manager->priv = MSD_BACKGROUND_MANAGER_GET_PRIVATE(manager); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; } - - static void - msd_background_manager_finalize (GObject* object) +} + +static GObject* +msd_background_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam* construct_properties) +{ + MsdBackgroundManager* background_manager; + + background_manager = MSD_BACKGROUND_MANAGER(G_OBJECT_CLASS(msd_background_manager_parent_class)->constructor(type, + n_construct_properties, + construct_properties)); + return G_OBJECT(background_manager); +} + +static void +msd_background_manager_dispose (GObject* object) +{ + G_OBJECT_CLASS(msd_background_manager_parent_class)->dispose(object); +} + +static void +msd_background_manager_class_init (MsdBackgroundManagerClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = msd_background_manager_get_property; + object_class->set_property = msd_background_manager_set_property; + object_class->constructor = msd_background_manager_constructor; + object_class->dispose = msd_background_manager_dispose; + object_class->finalize = msd_background_manager_finalize; + + g_type_class_add_private(klass, sizeof(MsdBackgroundManagerPrivate)); +} + +static void +msd_background_manager_init (MsdBackgroundManager* manager) +{ + manager->priv = MSD_BACKGROUND_MANAGER_GET_PRIVATE(manager); +} + +static void +msd_background_manager_finalize (GObject* object) +{ + MsdBackgroundManager* background_manager; + + g_return_if_fail(object != NULL); + g_return_if_fail(MSD_IS_BACKGROUND_MANAGER(object)); + + background_manager = MSD_BACKGROUND_MANAGER(object); + + g_return_if_fail(background_manager->priv != NULL); + + G_OBJECT_CLASS(msd_background_manager_parent_class)->finalize(object); +} + +MsdBackgroundManager* +msd_background_manager_new (void) +{ + if (manager_object != NULL) { - MsdBackgroundManager* background_manager; - - g_return_if_fail(object != NULL); - g_return_if_fail(MSD_IS_BACKGROUND_MANAGER(object)); - - background_manager = MSD_BACKGROUND_MANAGER(object); - - g_return_if_fail(background_manager->priv != NULL); - - G_OBJECT_CLASS(msd_background_manager_parent_class)->finalize(object); + g_object_ref(manager_object); } - - MsdBackgroundManager* - msd_background_manager_new (void) + else { - if (manager_object != NULL) - { - g_object_ref(manager_object); - } - else - { - manager_object = g_object_new(MSD_TYPE_BACKGROUND_MANAGER, NULL); - - g_object_add_weak_pointer(manager_object, (gpointer*) &manager_object); - } + manager_object = g_object_new(MSD_TYPE_BACKGROUND_MANAGER, NULL); - return MSD_BACKGROUND_MANAGER(manager_object); + g_object_add_weak_pointer(manager_object, (gpointer*) &manager_object); } -//} + + return MSD_BACKGROUND_MANAGER(manager_object); +} |