summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2021-01-22 10:29:17 +0100
committerraveit65 <[email protected]>2021-02-02 08:28:13 +0100
commit08ae7f773ffe8f72795ee84a1c5d854554298314 (patch)
treed9e1dcb8ba3b003e152ff3fa27a165a2fcab2e47
parent602c2d8339a931aab09f09f417c41040ffdb4418 (diff)
downloadmate-settings-daemon-08ae7f773ffe8f72795ee84a1c5d854554298314.tar.bz2
mate-settings-daemon-08ae7f773ffe8f72795ee84a1c5d854554298314.tar.xz
background: promote MsdBackgroundManager class to final type
-rw-r--r--plugins/background/msd-background-manager.c184
-rw-r--r--plugins/background/msd-background-manager.h49
2 files changed, 92 insertions, 141 deletions
diff --git a/plugins/background/msd-background-manager.c b/plugins/background/msd-background-manager.c
index 404e729..bc2dd80 100644
--- a/plugins/background/msd-background-manager.c
+++ b/plugins/background/msd-background-manager.c
@@ -49,7 +49,9 @@
#define MATE_SESSION_MANAGER_DBUS_NAME "org.gnome.SessionManager"
#define MATE_SESSION_MANAGER_DBUS_PATH "/org/gnome/SessionManager"
-struct MsdBackgroundManagerPrivate {
+struct _MsdBackgroundManager {
+ GObject parent;
+
GSettings *settings;
MateBG *bg;
cairo_surface_t *surface;
@@ -67,7 +69,7 @@ struct MsdBackgroundManagerPrivate {
guint proxy_signal_id;
};
-G_DEFINE_TYPE_WITH_PRIVATE (MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE (MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT)
static gpointer manager_object = NULL;
@@ -75,21 +77,21 @@ static gpointer manager_object = NULL;
static gboolean
msd_can_draw_bg (MsdBackgroundManager *manager)
{
- return g_settings_get_boolean (manager->priv->settings, MATE_BG_KEY_DRAW_BACKGROUND);
+ return g_settings_get_boolean (manager->settings, MATE_BG_KEY_DRAW_BACKGROUND);
}
/* Whether to change background with a fade effect */
static gboolean
can_fade_bg (MsdBackgroundManager *manager)
{
- return g_settings_get_boolean (manager->priv->settings, MATE_BG_KEY_BACKGROUND_FADE);
+ return g_settings_get_boolean (manager->settings, MATE_BG_KEY_BACKGROUND_FADE);
}
/* Whether Caja is configured to draw desktop (show-desktop-icons) */
static gboolean
caja_can_draw_bg (MsdBackgroundManager *manager)
{
- return g_settings_get_boolean (manager->priv->settings, MATE_BG_KEY_SHOW_DESKTOP);
+ return g_settings_get_boolean (manager->settings, MATE_BG_KEY_SHOW_DESKTOP);
}
static gboolean
@@ -105,7 +107,7 @@ caja_is_drawing_bg (MsdBackgroundManager *manager)
GdkDisplay *gdk_display;
gboolean running = FALSE;
- if (!manager->priv->caja_can_draw)
+ if (!manager->caja_can_draw)
return FALSE;
caja_prop = XInternAtom (display, "CAJA_DESKTOP_WINDOW_ID", True);
@@ -154,27 +156,27 @@ caja_is_drawing_bg (MsdBackgroundManager *manager)
static void
free_fade (MsdBackgroundManager *manager)
{
- if (manager->priv->fade != NULL) {
- g_object_unref (manager->priv->fade);
- manager->priv->fade = NULL;
+ if (manager->fade != NULL) {
+ g_object_unref (manager->fade);
+ manager->fade = NULL;
}
}
static void
free_bg_surface (MsdBackgroundManager *manager)
{
- if (manager->priv->surface != NULL) {
- cairo_surface_destroy (manager->priv->surface);
- manager->priv->surface = NULL;
+ if (manager->surface != NULL) {
+ cairo_surface_destroy (manager->surface);
+ manager->surface = NULL;
}
}
static void
free_scr_sizes (MsdBackgroundManager *manager)
{
- if (manager->priv->scr_sizes != NULL) {
- g_list_free_full (manager->priv->scr_sizes, g_free);
- manager->priv->scr_sizes = NULL;
+ if (manager->scr_sizes != NULL) {
+ g_list_free_full (manager->scr_sizes, g_free);
+ manager->scr_sizes = NULL;
}
}
@@ -182,51 +184,48 @@ static void
real_draw_bg (MsdBackgroundManager *manager,
GdkScreen *screen)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
GdkWindow *window = gdk_screen_get_root_window (screen);
gint scale = gdk_window_get_scale_factor (window);
gint width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
gint height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
free_bg_surface (manager);
- p->surface = mate_bg_create_surface_scale (p->bg, window, width, height, scale, TRUE);
+ manager->surface = mate_bg_create_surface_scale (manager->bg, window, width, height, scale, TRUE);
- if (p->do_fade)
+ if (manager->do_fade)
{
free_fade (manager);
- p->fade = mate_bg_set_surface_as_root_with_crossfade (screen, p->surface);
- g_signal_connect_swapped (p->fade, "finished", G_CALLBACK (free_fade), manager);
+ manager->fade = mate_bg_set_surface_as_root_with_crossfade (screen, manager->surface);
+ g_signal_connect_swapped (manager->fade, "finished", G_CALLBACK (free_fade), manager);
}
else
{
- mate_bg_set_surface_as_root (screen, p->surface);
+ mate_bg_set_surface_as_root (screen, manager->surface);
}
- p->scr_sizes = g_list_prepend (p->scr_sizes, g_strdup_printf ("%dx%d", width, height));
+ manager->scr_sizes = g_list_prepend (manager->scr_sizes, g_strdup_printf ("%dx%d", width, height));
}
static void
draw_background (MsdBackgroundManager *manager,
gboolean may_fade)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
- if (!p->msd_can_draw || p->draw_in_progress || caja_is_drawing_bg (manager))
+ if (!manager->msd_can_draw || manager->draw_in_progress || caja_is_drawing_bg (manager))
return;
mate_settings_profile_start (NULL);
- GdkDisplay *display = gdk_display_get_default ();
+ GdkDisplay *display = gdk_display_get_default ();
- p->draw_in_progress = TRUE;
- p->do_fade = may_fade && can_fade_bg (manager);
+ manager->draw_in_progress = TRUE;
+ manager->do_fade = may_fade && can_fade_bg (manager);
free_scr_sizes (manager);
g_debug ("Drawing background on Screen");
real_draw_bg (manager, gdk_display_get_default_screen (display));
- p->scr_sizes = g_list_reverse (p->scr_sizes);
+ manager->scr_sizes = g_list_reverse (manager->scr_sizes);
- p->draw_in_progress = FALSE;
+ manager->draw_in_progress = FALSE;
mate_settings_profile_end (NULL);
}
@@ -250,15 +249,13 @@ static void
on_screen_size_changed (GdkScreen *screen,
MsdBackgroundManager *manager)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
- if (!p->msd_can_draw || p->draw_in_progress || caja_is_drawing_bg (manager))
+ if (!manager->msd_can_draw || manager->draw_in_progress || caja_is_drawing_bg (manager))
return;
GdkWindow *window = gdk_screen_get_root_window (screen);
gint scale = gdk_window_get_scale_factor (window);
gint scr_num = gdk_x11_screen_get_screen_number (screen);
- gchar *old_size = g_list_nth_data (manager->priv->scr_sizes, scr_num);
+ gchar *old_size = g_list_nth_data (manager->scr_sizes, scr_num);
gchar *new_size = g_strdup_printf ("%dx%d", WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale,
HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale);
if (g_strcmp0 (old_size, new_size) != 0)
@@ -299,7 +296,7 @@ settings_change_event_idle_cb (MsdBackgroundManager *manager)
{
mate_settings_profile_start ("settings_change_event_idle_cb");
- mate_bg_load_from_preferences (manager->priv->bg);
+ mate_bg_load_from_preferences (manager->bg);
mate_settings_profile_end ("settings_change_event_idle_cb");
@@ -312,13 +309,11 @@ settings_change_event_cb (GSettings *settings G_GNUC_UNUSED,
gint n_keys G_GNUC_UNUSED,
MsdBackgroundManager *manager)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
/* Complements on_bg_handling_changed() */
- p->msd_can_draw = msd_can_draw_bg (manager);
- p->caja_can_draw = caja_can_draw_bg (manager);
+ manager->msd_can_draw = msd_can_draw_bg (manager);
+ manager->caja_can_draw = caja_can_draw_bg (manager);
- if (p->msd_can_draw && p->bg != NULL && !caja_is_drawing_bg (manager))
+ if (manager->msd_can_draw && manager->bg != NULL && !caja_is_drawing_bg (manager))
{
/* Defer signal processing to avoid making the dconf backend deadlock */
g_idle_add ((GSourceFunc) settings_change_event_idle_cb, manager);
@@ -330,42 +325,39 @@ settings_change_event_cb (GSettings *settings G_GNUC_UNUSED,
static void
setup_background (MsdBackgroundManager *manager)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
- g_return_if_fail (p->bg == NULL);
+ g_return_if_fail (manager->bg == NULL);
- p->bg = mate_bg_new();
+ manager->bg = mate_bg_new();
- p->draw_in_progress = FALSE;
+ manager->draw_in_progress = FALSE;
- g_signal_connect(p->bg, "changed", G_CALLBACK (on_bg_changed), manager);
+ g_signal_connect(manager->bg, "changed", G_CALLBACK (on_bg_changed), manager);
- g_signal_connect(p->bg, "transitioned", G_CALLBACK (on_bg_transitioned), manager);
+ g_signal_connect(manager->bg, "transitioned", G_CALLBACK (on_bg_transitioned), manager);
- mate_bg_load_from_gsettings (p->bg, p->settings);
+ mate_bg_load_from_gsettings (manager->bg, manager->settings);
connect_screen_signals (manager);
- g_signal_connect (p->settings, "change-event",
+ g_signal_connect (manager->settings, "change-event",
G_CALLBACK (settings_change_event_cb), manager);
}
static void
remove_background (MsdBackgroundManager *manager)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
disconnect_screen_signals (manager);
- g_signal_handlers_disconnect_by_func (p->settings, settings_change_event_cb, manager);
+ g_signal_handlers_disconnect_by_func (manager->settings, settings_change_event_cb, manager);
- if (p->settings != NULL) {
- g_object_unref (G_OBJECT (p->settings));
- p->settings = NULL;
+ if (manager->settings != NULL) {
+ g_object_unref (manager->settings);
+ manager->settings = NULL;
}
- if (p->bg != NULL) {
- g_object_unref (G_OBJECT (p->bg));
- p->bg = NULL;
+ if (manager->bg != NULL) {
+ g_object_unref (manager->bg);
+ manager->bg = NULL;
}
free_scr_sizes (manager);
@@ -378,16 +370,14 @@ on_bg_handling_changed (GSettings *settings G_GNUC_UNUSED,
const char *key G_GNUC_UNUSED,
MsdBackgroundManager *manager)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
mate_settings_profile_start (NULL);
if (caja_is_drawing_bg (manager))
{
- if (p->bg != NULL)
+ if (manager->bg != NULL)
remove_background (manager);
}
- else if (p->msd_can_draw && p->bg == NULL)
+ else if (manager->msd_can_draw && manager->bg == NULL)
{
setup_background (manager);
}
@@ -398,7 +388,7 @@ on_bg_handling_changed (GSettings *settings G_GNUC_UNUSED,
static gboolean
queue_setup_background (MsdBackgroundManager *manager)
{
- manager->priv->timeout_id = 0;
+ manager->timeout_id = 0;
setup_background (manager);
@@ -408,7 +398,7 @@ queue_setup_background (MsdBackgroundManager *manager)
static void
queue_timeout (MsdBackgroundManager *manager)
{
- if (manager->priv->timeout_id > 0)
+ if (manager->timeout_id > 0)
return;
/* SessionRunning: now check if Caja is drawing background, and if not, set it.
@@ -417,17 +407,16 @@ queue_timeout (MsdBackgroundManager *manager)
* session manager that its ready before it sets the background.
* https://bugzilla.gnome.org/show_bug.cgi?id=568588
*/
- manager->priv->timeout_id =
+ manager->timeout_id =
g_timeout_add_seconds (8, (GSourceFunc) queue_setup_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;
+ if (manager->proxy && manager->proxy_signal_id) {
+ g_signal_handler_disconnect (manager->proxy, manager->proxy_signal_id);
+ manager->proxy_signal_id = 0;
}
}
@@ -454,22 +443,22 @@ draw_bg_after_session_loads (MsdBackgroundManager *manager)
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) {
+ manager->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->proxy == NULL) {
g_warning ("Could not listen to session manager: %s",
error->message);
g_error_free (error);
return;
}
- manager->priv->proxy_signal_id = g_signal_connect (manager->priv->proxy,
+ manager->proxy_signal_id = g_signal_connect (manager->proxy,
"g-signal",
G_CALLBACK (on_session_manager_signal),
manager);
@@ -479,35 +468,29 @@ gboolean
msd_background_manager_start (MsdBackgroundManager *manager,
GError **error)
{
- MsdBackgroundManagerPrivate *p = manager->priv;
-
g_debug ("Starting background manager");
mate_settings_profile_start (NULL);
- p->settings = g_settings_new (MATE_BG_SCHEMA);
+ manager->settings = g_settings_new (MATE_BG_SCHEMA);
- p->msd_can_draw = msd_can_draw_bg (manager);
- p->caja_can_draw = caja_can_draw_bg (manager);
+ manager->msd_can_draw = msd_can_draw_bg (manager);
+ manager->caja_can_draw = caja_can_draw_bg (manager);
- g_signal_connect (p->settings, "changed::" MATE_BG_KEY_DRAW_BACKGROUND,
- G_CALLBACK (on_bg_handling_changed), manager);
- g_signal_connect (p->settings, "changed::" MATE_BG_KEY_SHOW_DESKTOP,
- G_CALLBACK (on_bg_handling_changed), manager);
+ g_signal_connect (manager->settings, "changed::" MATE_BG_KEY_DRAW_BACKGROUND,
+ G_CALLBACK (on_bg_handling_changed), manager);
+ g_signal_connect (manager->settings, "changed::" MATE_BG_KEY_SHOW_DESKTOP,
+ G_CALLBACK (on_bg_handling_changed), manager);
/* If Caja is set to draw the background, it is very likely in our session.
* But it might not be started yet, so caja_is_drawing_bg() would fail.
* In this case, we wait till the session is loaded, to avoid double-draws.
*/
- if (p->msd_can_draw)
+ if (manager->msd_can_draw)
{
- if (p->caja_can_draw)
- {
+ if (manager->caja_can_draw)
draw_bg_after_session_loads (manager);
- }
else
- {
setup_background (manager);
- }
}
mate_settings_profile_end (NULL);
@@ -520,15 +503,15 @@ msd_background_manager_stop (MsdBackgroundManager *manager)
{
g_debug ("Stopping background manager");
- if (manager->priv->proxy)
+ if (manager->proxy)
{
disconnect_session_manager_listener (manager);
- g_object_unref (manager->priv->proxy);
+ g_object_unref (manager->proxy);
}
- if (manager->priv->timeout_id != 0) {
- g_source_remove (manager->priv->timeout_id);
- manager->priv->timeout_id = 0;
+ if (manager->timeout_id != 0) {
+ g_source_remove (manager->timeout_id);
+ manager->timeout_id = 0;
}
remove_background (manager);
@@ -553,17 +536,12 @@ msd_background_manager_finalize (GObject *object)
g_return_if_fail (object != NULL);
g_return_if_fail (MSD_IS_BACKGROUND_MANAGER (object));
- MsdBackgroundManager *manager = MSD_BACKGROUND_MANAGER (object);
-
- g_return_if_fail (manager->priv != NULL);
-
G_OBJECT_CLASS(msd_background_manager_parent_class)->finalize(object);
}
static void
msd_background_manager_init (MsdBackgroundManager* manager)
{
- manager->priv = msd_background_manager_get_instance_private(manager);
}
static void
diff --git a/plugins/background/msd-background-manager.h b/plugins/background/msd-background-manager.h
index 36231a3..c2fb7d0 100644
--- a/plugins/background/msd-background-manager.h
+++ b/plugins/background/msd-background-manager.h
@@ -18,51 +18,24 @@
*
*/
-#ifndef __MSD_BACKGROUND_MANAGER_H
-#define __MSD_BACKGROUND_MANAGER_H
+#ifndef MSD_BACKGROUND_MANAGER_H
+#define MSD_BACKGROUND_MANAGER_H
#include <glib-object.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+G_BEGIN_DECLS
-//class MsdBackgroundManager
-//{
- #define MSD_TYPE_BACKGROUND_MANAGER (msd_background_manager_get_type())
- #define MSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManager))
- #define MSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass))
- #define MSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MSD_TYPE_BACKGROUND_MANAGER))
- #define MSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), MSD_TYPE_BACKGROUND_MANAGER))
- #define MSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass))
+#define MSD_TYPE_BACKGROUND_MANAGER (msd_background_manager_get_type())
- typedef struct MsdBackgroundManagerPrivate MsdBackgroundManagerPrivate;
+G_DECLARE_FINAL_TYPE (MsdBackgroundManager, msd_background_manager, MSD, BACKGROUND_MANAGER, GObject)
- typedef struct {
- GObject parent;
- MsdBackgroundManagerPrivate* priv;
- } MsdBackgroundManager;
+MsdBackgroundManager * msd_background_manager_new (void);
- typedef struct {
- GObjectClass parent_class;
- } MsdBackgroundManagerClass;
+gboolean msd_background_manager_start (MsdBackgroundManager *manager,
+ GError **error);
- GType
- msd_background_manager_get_type (void);
+void msd_background_manager_stop (MsdBackgroundManager *manager);
- MsdBackgroundManager*
- msd_background_manager_new (void);
+G_END_DECLS
- gboolean
- msd_background_manager_start (MsdBackgroundManager* manager,
- GError** error);
-
- void
- msd_background_manager_stop (MsdBackgroundManager* manager);
-//}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MSD_BACKGROUND_MANAGER_H */
+#endif /* MSD_BACKGROUND_MANAGER_H */