~ubuntu-branches/debian/jessie/mate-control-center/jessie

« back to all changes in this revision

Viewing changes to capplets/appearance/appearance-support.c

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-05-02 23:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20140502232006-9626h14ggaz2hc9h
Tags: upstream-1.8.1+dfsg1
ImportĀ upstreamĀ versionĀ 1.8.1+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Stefano Karapetsas
 
3
 * Authors: Stefano Karapetsas <stefano@karapetsas.com>
 
4
 * All Rights Reserved
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
19
 */
 
20
 
 
21
#include "appearance.h"
 
22
#include "wm-common.h"
 
23
 
 
24
#include <glib.h>
 
25
#include <gio/gio.h>
 
26
 
 
27
static gboolean
 
28
is_program_in_path (const char *program)
 
29
{
 
30
    char *tmp = g_find_program_in_path (program);
 
31
    if (tmp != NULL)
 
32
    {
 
33
        g_free (tmp);
 
34
        return TRUE;
 
35
    }
 
36
    else
 
37
    {
 
38
        return FALSE;
 
39
    }
 
40
}
 
41
 
 
42
static gboolean
 
43
metacity_is_running()
 
44
{
 
45
    gboolean is_running = FALSE;
 
46
    gchar *current_wm = NULL;
 
47
 
 
48
    current_wm = wm_common_get_current_window_manager ();
 
49
 
 
50
    is_running = (g_strcmp0(current_wm, WM_COMMON_METACITY) == 0) ||
 
51
                 (g_strcmp0(current_wm, WM_COMMON_COMPIZ_OLD) == 0) ||
 
52
                 (g_strcmp0(current_wm, WM_COMMON_COMPIZ) == 0);
 
53
 
 
54
    g_free (current_wm);
 
55
 
 
56
    return is_running;
 
57
}
 
58
 
 
59
static void
 
60
metacity_theme_apply(const gchar *theme, const gchar *font)
 
61
{
 
62
    /* set theme, we use gconf and gsettings binaries to avoid schemas and versions issues */
 
63
    if (is_program_in_path ("gconftool-2"))
 
64
    {
 
65
        gchar *gconf_cmd = NULL;
 
66
 
 
67
        gconf_cmd = g_strdup_printf("gconftool-2 --set --type string /apps/metacity/general/theme '%s'", theme);
 
68
        g_spawn_command_line_async (gconf_cmd, NULL);
 
69
        g_free (gconf_cmd);
 
70
 
 
71
        gconf_cmd = g_strdup_printf("gconftool-2 --set --type string /apps/metacity/general/titlebar_font '%s'", font);
 
72
        g_spawn_command_line_async (gconf_cmd, NULL);
 
73
        g_free (gconf_cmd);
 
74
    }
 
75
 
 
76
    if (is_program_in_path ("gsettings"))
 
77
    {
 
78
        gchar *gsettings_cmd = NULL;
 
79
 
 
80
        gsettings_cmd = g_strdup_printf("gsettings set org.gnome.desktop.wm.preferences theme '%s'", theme);
 
81
        g_spawn_command_line_async (gsettings_cmd, NULL);
 
82
        g_free (gsettings_cmd);
 
83
 
 
84
        gsettings_cmd = g_strdup_printf("gsettings set org.gnome.desktop.wm.preferences titlebar-font '%s'", font);
 
85
        g_spawn_command_line_async (gsettings_cmd, NULL);
 
86
        g_free (gsettings_cmd);
 
87
 
 
88
    }
 
89
}
 
90
 
 
91
static void
 
92
marco_theme_changed(GSettings *settings, gchar *key, AppearanceData* data)
 
93
{
 
94
    gchar *theme = NULL;
 
95
    gchar *font = NULL;
 
96
    if (metacity_is_running ())
 
97
    {
 
98
        theme = g_settings_get_string (settings, MARCO_THEME_KEY);
 
99
        font = g_settings_get_string (settings, WINDOW_TITLE_FONT_KEY);
 
100
        metacity_theme_apply (theme, font);
 
101
        g_free (theme);
 
102
        g_free (font);
 
103
    }
 
104
}
 
105
 
 
106
void
 
107
support_init(AppearanceData* data)
 
108
{
 
109
    /* needed for wm_common_get_current_window_manager() */
 
110
    wm_common_update_window ();
 
111
    /* GSettings signals */
 
112
    g_signal_connect (data->marco_settings, "changed::" MARCO_THEME_KEY,
 
113
                      G_CALLBACK (marco_theme_changed), data);
 
114
    g_signal_connect (data->marco_settings, "changed::" WINDOW_TITLE_FONT_KEY,
 
115
                      G_CALLBACK (marco_theme_changed), data);
 
116
    /* apply theme at start */
 
117
    if (metacity_is_running ())
 
118
        marco_theme_changed (data->marco_settings, NULL, data);
 
119
}
 
120
 
 
121
void
 
122
support_shutdown(AppearanceData* data)
 
123
{
 
124
    /* nothing to do */
 
125
}