~ubuntu-branches/ubuntu/vivid/gnome-flashback/vivid

« back to all changes in this revision

Viewing changes to gnome-flashback/libdesktop-background/flashback-desktop-background.c

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2014-09-19 17:09:43 UTC
  • Revision ID: package-import@ubuntu.com-20140919170943-oboafsedi6z69951
Tags: upstream-3.10.0
Import upstream version 3.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (C) 2014 Alberts Muktupāvels
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation, either version 3 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 
16
 */
 
17
 
 
18
#include <gtk/gtk.h>
 
19
#include <libgnome-desktop/gnome-bg.h>
 
20
#include "flashback-desktop-background.h"
 
21
 
 
22
/*#define FLASHBACK_BACKGROUND_SCHEMA "org.gnome.gnome-flashback.background"
 
23
#define KEY_FADE                    "fade"*/
 
24
 
 
25
struct _FlashbackDesktopBackgroundPrivate {
 
26
        GnomeBG   *gnome_bg;
 
27
        GSettings *gnome_settings;
 
28
        gulong     screen_size_handler;
 
29
        gulong     screen_monitors_handler;
 
30
};
 
31
 
 
32
G_DEFINE_TYPE (FlashbackDesktopBackground, flashback_desktop_background, G_TYPE_OBJECT);
 
33
 
 
34
static void
 
35
flashback_desktop_background_draw (FlashbackDesktopBackground *background)
 
36
{
 
37
        GdkScreen *screen = gdk_screen_get_default ();
 
38
        cairo_surface_t *surface = gnome_bg_create_surface (background->priv->gnome_bg,
 
39
                                                            gdk_screen_get_root_window (screen),
 
40
                                                            gdk_screen_get_width (screen),
 
41
                                                            gdk_screen_get_height (screen),
 
42
                                                            TRUE);
 
43
        gnome_bg_set_surface_as_root (screen, surface);
 
44
        cairo_surface_destroy (surface);
 
45
}
 
46
 
 
47
static void
 
48
flashback_desktop_background_changed (GnomeBG  *bg,
 
49
                                      gpointer  user_data)
 
50
{
 
51
        FlashbackDesktopBackground *background = FLASHBACK_DESKTOP_BACKGROUND (user_data);
 
52
 
 
53
        flashback_desktop_background_draw (background);
 
54
}
 
55
 
 
56
static void
 
57
flashback_desktop_background_transitioned (GnomeBG  *bg,
 
58
                                           gpointer  user_data)
 
59
{
 
60
        FlashbackDesktopBackground *background = FLASHBACK_DESKTOP_BACKGROUND (user_data);
 
61
 
 
62
        flashback_desktop_background_draw (background);
 
63
}
 
64
 
 
65
static void
 
66
flashback_desktop_background_screen_size_changed (GdkScreen                  *screen,
 
67
                                                  FlashbackDesktopBackground *background)
 
68
{
 
69
        flashback_desktop_background_draw (background);
 
70
}
 
71
 
 
72
static gboolean
 
73
flashback_desktop_background_settings_change_event (GSettings *settings,
 
74
                                                    gpointer   keys,
 
75
                                                    gint       n_keys,
 
76
                                                    gpointer   user_data)
 
77
{
 
78
        FlashbackDesktopBackground *background = FLASHBACK_DESKTOP_BACKGROUND (user_data);
 
79
 
 
80
        gnome_bg_load_from_preferences (background->priv->gnome_bg, background->priv->gnome_settings);
 
81
 
 
82
        return TRUE;
 
83
}
 
84
 
 
85
static void
 
86
flashback_desktop_background_finalize (GObject *object)
 
87
{
 
88
        FlashbackDesktopBackground *background = FLASHBACK_DESKTOP_BACKGROUND (object);
 
89
 
 
90
        if (background->priv->screen_size_handler > 0) {
 
91
                g_signal_handler_disconnect (gdk_screen_get_default (),
 
92
                                             background->priv->screen_size_handler);
 
93
                background->priv->screen_size_handler = 0;
 
94
        }
 
95
 
 
96
        if (background->priv->screen_monitors_handler > 0) {
 
97
                g_signal_handler_disconnect (gdk_screen_get_default (),
 
98
                                             background->priv->screen_monitors_handler);
 
99
                background->priv->screen_monitors_handler = 0;
 
100
        }
 
101
 
 
102
        g_signal_handlers_disconnect_by_func (background->priv->gnome_settings,
 
103
                                              flashback_desktop_background_settings_change_event,
 
104
                                              background);
 
105
 
 
106
        if (background->priv->gnome_bg) {
 
107
                g_object_unref (background->priv->gnome_bg);
 
108
                background->priv->gnome_bg = NULL;
 
109
        }
 
110
 
 
111
        if (background->priv->gnome_settings) {
 
112
                g_object_unref (background->priv->gnome_settings);
 
113
                background->priv->gnome_settings = NULL;
 
114
        }
 
115
 
 
116
        G_OBJECT_CLASS (flashback_desktop_background_parent_class)->finalize (object);
 
117
}
 
118
 
 
119
static void
 
120
flashback_desktop_background_init (FlashbackDesktopBackground *background)
 
121
{
 
122
        background->priv = G_TYPE_INSTANCE_GET_PRIVATE (background, FLASHBACK_TYPE_DESKTOP_BACKGROUND, FlashbackDesktopBackgroundPrivate);
 
123
 
 
124
        background->priv->gnome_bg = gnome_bg_new ();
 
125
        background->priv->gnome_settings = g_settings_new ("org.gnome.desktop.background");
 
126
 
 
127
        g_signal_connect (background->priv->gnome_bg, "changed",
 
128
                          G_CALLBACK (flashback_desktop_background_changed), background);
 
129
        g_signal_connect (background->priv->gnome_bg, "transitioned",
 
130
                          G_CALLBACK (flashback_desktop_background_transitioned), background);
 
131
 
 
132
        background->priv->screen_size_handler = g_signal_connect (gdk_screen_get_default (), "size-changed",
 
133
                                                                  G_CALLBACK (flashback_desktop_background_screen_size_changed), background);
 
134
        background->priv->screen_monitors_handler = g_signal_connect (gdk_screen_get_default (), "monitors-changed",
 
135
                                                                      G_CALLBACK (flashback_desktop_background_screen_size_changed), background);
 
136
 
 
137
        gnome_bg_load_from_preferences (background->priv->gnome_bg, background->priv->gnome_settings);
 
138
 
 
139
        g_signal_connect (background->priv->gnome_settings, "change-event",
 
140
                          G_CALLBACK (flashback_desktop_background_settings_change_event), background);
 
141
}
 
142
 
 
143
static void
 
144
flashback_desktop_background_class_init (FlashbackDesktopBackgroundClass *class)
 
145
{
 
146
        GObjectClass *object_class = G_OBJECT_CLASS (class);
 
147
 
 
148
        object_class->finalize = flashback_desktop_background_finalize;
 
149
 
 
150
        g_type_class_add_private (class, sizeof (FlashbackDesktopBackgroundPrivate));
 
151
}
 
152
 
 
153
FlashbackDesktopBackground *
 
154
flashback_desktop_background_new (void)
 
155
{
 
156
        return g_object_new (FLASHBACK_TYPE_DESKTOP_BACKGROUND,
 
157
                             NULL);
 
158
}