summaryrefslogtreecommitdiff
path: root/gnome-settings-daemon/gnome-settings-background.c
blob: 269b9049830caeb211a5ef269f75912102383fb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* -*- mode: c; style: linux -*- */

/* gnome-settings-background.c
 *
 * Copyright © 2001 Ximian, Inc.
 *
 * Written by Bradford Hovinen <hovinen@ximian.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gconf/gconf.h>

#include "gnome-settings-keyboard.h"
#include "gnome-settings-daemon.h"

#include "preferences.h"
#include "applier.h"

#ifdef HAVE_GTK_MULTIHEAD
static BGApplier **bg_appliers;
#else
static BGApplier *bg_applier;
#endif
static BGPreferences *prefs;

static void
background_callback (GConfEntry *entry) 
{
#ifdef HAVE_GTK_MULTIHEAD
	int i;
#endif

	bg_preferences_merge_entry (prefs, entry);

#ifdef HAVE_GTK_MULTIHEAD
	for (i = 0; bg_appliers [i]; i++)
		bg_applier_apply_prefs (bg_appliers [i], prefs);
#else
	bg_applier_apply_prefs (bg_applier, prefs);
#endif
}

void
gnome_settings_background_init (GConfClient *client)
{
#ifdef HAVE_GTK_MULTIHEAD
	GdkDisplay *display;
	int         n_screens;
	int         i;

	display = gdk_display_get_default ();
	n_screens = gdk_display_get_n_screens (display);

	bg_appliers = g_new (BGApplier *, n_screens + 1);

	for (i = 0; i < n_screens; i++) {
		GdkScreen *screen;

		screen = gdk_display_get_screen (display, i);

		bg_appliers [i] = BG_APPLIER (bg_applier_new_for_screen (BG_APPLIER_ROOT, screen));
	}
	bg_appliers [i] = NULL;
#else
	bg_applier = BG_APPLIER (bg_applier_new (BG_APPLIER_ROOT));
#endif

	prefs = BG_PREFERENCES (bg_preferences_new ());
	bg_preferences_load (prefs);

	gnome_settings_daemon_register_callback ("/desktop/gnome/background", background_callback);
}

void
gnome_settings_background_load (GConfClient *client)
{
#ifdef HAVE_GTK_MULTIHEAD
	int i;
#endif

	/* If this is set, nautilus will draw the background and is
	 * almost definitely in our session.  however, it may not be
	 * running yet (so is_nautilus_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
	 * nautilus overwrite it.
	 */

	if (gconf_client_get_bool (client, "/apps/nautilus/preferences/show_desktop", NULL))
		return;

#ifdef HAVE_GTK_MULTIHEAD
	for (i = 0; bg_appliers [i]; i++)
		bg_applier_apply_prefs (bg_appliers [i], prefs);
#else
	bg_applier_apply_prefs (bg_applier, prefs);
#endif
}