~ubuntu-branches/ubuntu/trusty/pcmanfm/trusty-proposed

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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 *      main.c - desktop manager of pcmanfm
 *
 *      Copyright 2008 PCMan <pcman.tw@gmail.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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include "desktop.h"

#ifdef DESKTOP_INTEGRATION

#include <gtk/gtk.h>
//#include "fm-desktop.h"

#include "vfs-file-info.h"
#include "vfs-mime-type.h"
//#include "vfs-app-desktop.h"

#include "vfs-file-monitor.h"
#include "vfs-volume.h"
#include "vfs-thumbnail-loader.h"
#include "vfs-dir.h"

#include "desktop-window.h"

#include "settings.h"

static GtkWindowGroup* group = NULL;

static GdkFilterReturn on_rootwin_event ( GdkXEvent *xevent, GdkEvent *event, gpointer data );

static GtkWidget **desktops = NULL;
static gint n_screens = 0;

static guint theme_change_notify = 0;

static void on_icon_theme_changed( GtkIconTheme* theme, gpointer data )
{
	/* reload icons of desktop windows */
    int i;
    for ( i = 0; i < n_screens; i++ )
        desktop_window_reload_icons( (DesktopWindow*)desktops[ i ] );
}

void fm_turn_on_desktop_icons()
{
    GdkDisplay * gdpy;
    gint i;
    int big = 0;

    if( ! group )
        group = gtk_window_group_new();

    theme_change_notify = g_signal_connect( gtk_icon_theme_get_default(), "changed",
                                                                                                        G_CALLBACK(on_icon_theme_changed), NULL );

    vfs_mime_type_get_icon_size( &big, NULL );

    gdpy = gdk_display_get_default();

    n_screens = gdk_display_get_n_screens( gdpy );
    desktops = g_new( GtkWidget *, n_screens );
    for ( i = 0; i < n_screens; i++ )
    {
        desktops[ i ] = desktop_window_new();
        desktop_window_set_icon_size( (DesktopWindow*)desktops[ i ], big );
        desktop_window_set_single_click( (DesktopWindow*)desktops[ i ], app_settings.single_click );

        gtk_widget_realize( desktops[ i ] );  /* without this, setting wallpaper won't work */
        gtk_widget_show_all( desktops[ i ] );
        gdk_window_lower( desktops[ i ] ->window );

        gtk_window_group_add_window( group, desktops[i] );
    }
    fm_desktop_update_colors();
    fm_desktop_update_wallpaper();
}

void fm_turn_off_desktop_icons()
{
    int i;

    if( theme_change_notify )
    {
        g_signal_handler_disconnect( gtk_icon_theme_get_default(), theme_change_notify );
        theme_change_notify = 0;
    }

    for ( i = 0; i < n_screens; i++ )
    {
        gtk_widget_destroy( desktops[ i ] );
        /* gtk_window_group_remove_window() */
    }
    g_free( desktops );

//    if ( busy_cursor > 0 )
//        g_source_remove( busy_cursor );
    g_object_unref( group );
    group = NULL;
}

void fm_desktop_update_thumbnails()
{
    /* FIXME: thumbnail on desktop cannot be turned off. */
}

void fm_desktop_update_wallpaper()
{
    DWBgType type;
    GdkPixbuf* pix;
    int i;

    if( app_settings.show_wallpaper && app_settings.wallpaper )
    {
        switch( app_settings.wallpaper_mode )
        {
        case WPM_FULL:
            type = DW_BG_FULL;
            break;
        case WPM_CENTER:
            type = DW_BG_CENTER;
            break;
        case WPM_TILE:
            type = DW_BG_TILE;
            break;
        case WPM_STRETCH:
        default:
            type = DW_BG_STRETCH;
        }
        pix = gdk_pixbuf_new_from_file( app_settings.wallpaper, NULL );
    }
    else
    {
        type = DW_BG_COLOR;
        pix = NULL;
    }

    for ( i = 0; i < n_screens; i++ )
        desktop_window_set_background( desktops[ i ], pix, type );

    if( pix )
        g_object_unref( pix );
}

void fm_desktop_update_colors()
{
    int i;
    for ( i = 0; i < n_screens; i++ )
    {
        desktop_window_set_bg_color( desktops[ i ], &app_settings.desktop_bg1 );
        desktop_window_set_text_color( desktops[ i ], &app_settings.desktop_text, &app_settings.desktop_shadow );
    }
}

void fm_desktop_update_icons()
{
    int i;
    int big = 0;

    vfs_mime_type_get_icon_size( &big, NULL );

    for ( i = 0; i < n_screens; i++ )
        desktop_window_set_icon_size( (DesktopWindow*)desktops[ i ], big );
}

void fm_desktop_set_single_click( gboolean single_click )
{
    int i;
    for ( i = 0; i < n_screens; i++ )
        desktop_window_set_single_click( (DesktopWindow*)desktops[ i ], single_click );
}

#else /* ! DESKTOP_INTEGRATION */

/* dummy implementations */
void fm_turn_on_desktop_icons() { }
void fm_turn_off_desktop_icons() { }
void fm_desktop_update_thumbnails() { }
void fm_desktop_update_wallpaper() { }
void fm_desktop_update_colors() { }
void fm_desktop_update_icons() { }
void fm_desktop_set_single_click( gboolean single_click ) { }
#endif