2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / src / nautilus-desktop-window.c
blob1f23a8c82be7560c4be6e2f05012d065c4b0bb36
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /*
4 * Nautilus
6 * Copyright (C) 2000 Eazel, Inc.
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Authors: Darin Adler <darin@bentspoon.com>
25 #include <config.h>
26 #include "nautilus-desktop-window.h"
27 #include "nautilus-window-private.h"
28 #include "nautilus-actions.h"
30 #include <X11/Xatom.h>
31 #include <gdk/gdkx.h>
32 #include <gtk/gtklayout.h>
33 #include <eel/eel-gtk-macros.h>
34 #include <eel/eel-vfs-extensions.h>
35 #include <libgnome/gnome-macros.h>
36 #include <libnautilus-private/nautilus-file-utilities.h>
37 #include <libnautilus-private/nautilus-icon-names.h>
38 #include <gio/gio.h>
40 struct NautilusDesktopWindowDetails {
41 int dummy;
44 static void set_wmspec_desktop_hint (GdkWindow *window);
46 GNOME_CLASS_BOILERPLATE (NautilusDesktopWindow, nautilus_desktop_window,
47 NautilusSpatialWindow, NAUTILUS_TYPE_SPATIAL_WINDOW)
49 static void
50 nautilus_desktop_window_instance_init (NautilusDesktopWindow *window)
52 GtkAction *action;
54 window->details = g_new0 (NautilusDesktopWindowDetails, 1);
56 gtk_window_move (GTK_WINDOW (window), 0, 0);
58 /* shouldn't really be needed given our semantic type
59 * of _NET_WM_TYPE_DESKTOP, but why not
61 gtk_window_set_resizable (GTK_WINDOW (window),
62 FALSE);
64 g_object_set_data (G_OBJECT (window), "is_desktop_window",
65 GINT_TO_POINTER (1));
67 gtk_widget_hide (NAUTILUS_WINDOW (window)->details->statusbar);
68 gtk_widget_hide (NAUTILUS_WINDOW (window)->details->menubar);
70 /* Don't allow close action on desktop */
71 action = gtk_action_group_get_action (NAUTILUS_WINDOW (window)->details->main_action_group,
72 NAUTILUS_ACTION_CLOSE);
73 gtk_action_set_sensitive (action, FALSE);
76 static gint
77 nautilus_desktop_window_delete_event (NautilusDesktopWindow *window)
79 /* Returning true tells GTK+ not to delete the window. */
80 return TRUE;
83 void
84 nautilus_desktop_window_update_directory (NautilusDesktopWindow *window)
86 GFile *location;
88 g_assert (NAUTILUS_IS_DESKTOP_WINDOW (window));
90 NAUTILUS_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change = TRUE;
91 location = g_file_new_for_uri (EEL_DESKTOP_URI);
92 nautilus_window_go_to (NAUTILUS_WINDOW (window), location);
93 g_object_unref (location);
96 static void
97 nautilus_desktop_window_screen_size_changed (GdkScreen *screen,
98 NautilusDesktopWindow *window)
100 int width_request, height_request;
102 width_request = gdk_screen_get_width (screen);
103 height_request = gdk_screen_get_height (screen);
105 g_object_set (window,
106 "width_request", width_request,
107 "height_request", height_request,
108 NULL);
111 NautilusDesktopWindow *
112 nautilus_desktop_window_new (NautilusApplication *application,
113 GdkScreen *screen)
115 NautilusDesktopWindow *window;
116 int width_request, height_request;
118 width_request = gdk_screen_get_width (screen);
119 height_request = gdk_screen_get_height (screen);
121 window = NAUTILUS_DESKTOP_WINDOW
122 (gtk_widget_new (nautilus_desktop_window_get_type(),
123 "app", application,
124 "width_request", width_request,
125 "height_request", height_request,
126 "screen", screen,
127 NULL));
129 /* Special sawmill setting*/
130 gtk_window_set_wmclass (GTK_WINDOW (window), "desktop_window", "Nautilus");
132 g_signal_connect (window, "delete_event", G_CALLBACK (nautilus_desktop_window_delete_event), NULL);
134 /* Point window at the desktop folder.
135 * Note that nautilus_desktop_window_init is too early to do this.
137 nautilus_desktop_window_update_directory (window);
139 return window;
142 static void
143 finalize (GObject *object)
145 NautilusDesktopWindow *window;
147 window = NAUTILUS_DESKTOP_WINDOW (object);
149 g_free (window->details);
151 G_OBJECT_CLASS (parent_class)->finalize (object);
154 static void
155 map (GtkWidget *widget)
157 /* Chain up to realize our children */
158 GTK_WIDGET_CLASS (parent_class)->map (widget);
159 gdk_window_lower (widget->window);
163 static void
164 unrealize (GtkWidget *widget)
166 NautilusDesktopWindow *window;
167 GdkWindow *root_window;
169 window = NAUTILUS_DESKTOP_WINDOW (widget);
171 root_window = gdk_screen_get_root_window (
172 gtk_window_get_screen (GTK_WINDOW (window)));
174 gdk_property_delete (root_window,
175 gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", TRUE));
177 g_signal_handlers_disconnect_by_func (gtk_window_get_screen (GTK_WINDOW (window)),
178 G_CALLBACK (nautilus_desktop_window_screen_size_changed),
179 window);
181 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
184 static void
185 set_wmspec_desktop_hint (GdkWindow *window)
187 GdkAtom atom;
189 atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DESKTOP", FALSE);
191 gdk_property_change (window,
192 gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
193 gdk_x11_xatom_to_atom (XA_ATOM), 32,
194 GDK_PROP_MODE_REPLACE, (guchar *) &atom, 1);
197 static void
198 set_desktop_window_id (NautilusDesktopWindow *window,
199 GdkWindow *gdkwindow)
201 /* Tuck the desktop windows xid in the root to indicate we own the desktop.
203 Window window_xid;
204 GdkWindow *root_window;
206 root_window = gdk_screen_get_root_window (
207 gtk_window_get_screen (GTK_WINDOW (window)));
209 window_xid = GDK_WINDOW_XWINDOW (gdkwindow);
211 gdk_property_change (root_window,
212 gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", FALSE),
213 gdk_x11_xatom_to_atom (XA_WINDOW), 32,
214 GDK_PROP_MODE_REPLACE, (guchar *) &window_xid, 1);
217 static void
218 realize (GtkWidget *widget)
220 NautilusDesktopWindow *window;
222 window = NAUTILUS_DESKTOP_WINDOW (widget);
224 /* Make sure we get keyboard events */
225 gtk_widget_set_events (widget, gtk_widget_get_events (widget)
226 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
228 /* Do the work of realizing. */
229 GTK_WIDGET_CLASS (parent_class)->realize (widget);
231 /* This is the new way to set up the desktop window */
232 set_wmspec_desktop_hint (widget->window);
234 set_desktop_window_id (window, widget->window);
236 g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed",
237 G_CALLBACK (nautilus_desktop_window_screen_size_changed), window);
240 static void
241 real_add_current_location_to_history_list (NautilusWindow *window)
243 /* Do nothing. The desktop window's location should not
244 * show up in the history list.
248 static char *
249 real_get_title (NautilusWindow *window)
251 return g_strdup (_("Desktop"));
254 static NautilusIconInfo *
255 real_get_icon (NautilusWindow *window)
257 return nautilus_icon_info_lookup_from_name (NAUTILUS_ICON_DESKTOP, 48);
260 static void
261 nautilus_desktop_window_class_init (NautilusDesktopWindowClass *class)
263 G_OBJECT_CLASS (class)->finalize = finalize;
264 GTK_WIDGET_CLASS (class)->realize = realize;
265 GTK_WIDGET_CLASS (class)->unrealize = unrealize;
268 GTK_WIDGET_CLASS (class)->map = map;
270 NAUTILUS_WINDOW_CLASS (class)->window_type = NAUTILUS_WINDOW_DESKTOP;
272 NAUTILUS_WINDOW_CLASS (class)->add_current_location_to_history_list
273 = real_add_current_location_to_history_list;
274 NAUTILUS_WINDOW_CLASS (class)->get_title
275 = real_get_title;
276 NAUTILUS_WINDOW_CLASS (class)->get_icon
277 = real_get_icon;