--- xfdesktop-file-icon-manager.c.original 2015-05-17 11:16:26.000000000 +0200 +++ xfdesktop-file-icon-manager.c 2016-08-02 19:24:22.979468345 +0200 @@ -127,6 +127,8 @@ GHashTable *removable_icons; GHashTable *special_icons; + XfceRc *icons_rc_file; + gboolean show_removable_media; gboolean show_network_volumes; gboolean show_device_volumes; @@ -201,6 +203,13 @@ static void xfdesktop_file_icon_manager_load_removable_media(XfdesktopFileIconManager *fmanager); static void xfdesktop_file_icon_manager_remove_removable_media(XfdesktopFileIconManager *fmanager); +static XfceRc* xfdesktop_open_icons_rc_file(XfdesktopFileIconManager *fmanager); +static void xfdesktop_close_icons_rc_file(XfdesktopFileIconManager *fmanager); +static gboolean xfdesktop_get_icon_position_from_rc_file(XfdesktopFileIconManager *fmanager, + const gchar *name, + const gchar *identifier, + gint16 *row, + gint16 *col); static void xfdesktop_file_icon_manager_set_show_special_file(XfdesktopFileIconManager *manager, XfdesktopSpecialFileIconType type, @@ -2035,6 +2044,85 @@ xfdesktop_file_icon_position_changed(NULL, user_data); } +XfceRc* +xfdesktop_open_icons_rc_file(XfdesktopFileIconManager *fmanager) +{ + gint x = 0, y = 0, width = 0, height = 0; + gchar relpath[PATH_MAX]; + gchar *filename = NULL; + + if(!fmanager || !fmanager->priv) return NULL; + + if(fmanager->priv->icons_rc_file) + xfdesktop_close_icons_rc_file(fmanager); + + xfdesktop_get_workarea_single(fmanager->priv->icon_view, + 0, + &x, + &y, + &width, + &height); + + g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d-%dx%d.rc", + gdk_screen_get_number(fmanager->priv->gscreen), + width, + height); + + filename = xfce_resource_lookup(XFCE_RESOURCE_CONFIG, relpath); + + /* Check if we have to migrate from the old file format. */ + if(filename == NULL) { + g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d.rc", + gdk_screen_get_number(fmanager->priv->gscreen)); + filename = xfce_resource_lookup(XFCE_RESOURCE_CONFIG, relpath); + } + + if(filename != NULL) { + fmanager->priv->icons_rc_file = xfce_rc_simple_open(filename, TRUE); + g_free(filename); + } + + return fmanager->priv->icons_rc_file; +} + +void +xfdesktop_close_icons_rc_file(XfdesktopFileIconManager *fmanager) +{ + if(!fmanager || !fmanager->priv || !fmanager->priv->icons_rc_file) return; + + xfce_rc_close(fmanager->priv->icons_rc_file); + fmanager->priv->icons_rc_file = NULL; +} + +gboolean +xfdesktop_get_icon_position_from_rc_file(XfdesktopFileIconManager *fmanager, + const gchar *name, + const gchar *identifier, + gint16 *row, + gint16 *col) +{ + gboolean icon_position_available = FALSE; + const gchar *icon_name; + + if(!fmanager || !fmanager->priv || !fmanager->priv->icons_rc_file) return FALSE; + + /* Newer versions use the identifier rather than the icon label when possible. */ + if(xfce_rc_has_group(fmanager->priv->icons_rc_file, XFDESKTOP_RC_VERSION_STAMP) && identifier) + icon_name = identifier; + else + icon_name = name; + + if(xfce_rc_has_group(fmanager->priv->icons_rc_file, icon_name)) { + xfce_rc_set_group(fmanager->priv->icons_rc_file, icon_name); + *row = xfce_rc_read_int_entry(fmanager->priv->icons_rc_file, "row", -1); + *col = xfce_rc_read_int_entry(fmanager->priv->icons_rc_file, "col", -1); + if(*row >= 0 && *col >= 0) + icon_position_available = TRUE; + } + + return icon_position_available; +} + gboolean xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *fmanager, const gchar *name, @@ -2207,12 +2295,13 @@ return; new_queue = g_queue_new(); + xfdesktop_open_icons_rc_file(fmanager); while((icon = g_queue_pop_head(fmanager->priv->pending_icons))) { name = xfdesktop_icon_peek_label(XFDESKTOP_ICON(icon)); identifier = xfdesktop_icon_get_identifier(XFDESKTOP_ICON(icon)); - if(xfdesktop_file_icon_manager_get_cached_icon_position(fmanager, + if(xfdesktop_get_icon_position_from_rc_file(fmanager, name, identifier, &row, &col)) { @@ -2232,6 +2321,7 @@ g_free(identifier); } + xfdesktop_close_icons_rc_file(fmanager); /* Free the old queue and replace it with the new one */ g_queue_free(fmanager->priv->pending_icons); fmanager->priv->pending_icons = new_queue; @@ -2262,11 +2352,11 @@ XF_DEBUG("attempting to set icon '%s' to position (%d,%d) [assigned location]", name, row, col); xfdesktop_icon_set_position(XFDESKTOP_ICON(icon), row, col); add_icon_to_iconview(fmanager, XFDESKTOP_ICON(icon)); - } else if(xfdesktop_file_icon_manager_get_cached_icon_position(fmanager, + } else if(xfdesktop_get_icon_position_from_rc_file(fmanager, name, identifier, &row, &col)) { - /* The icon has been looked up in the cache add it to the front of + /* The icon has been looked up in the cache (rc file) add it to the front of * the queue. The queue may get sorted if the icon view sends a * resize-event */ XF_DEBUG("attempting to set icon '%s' to position (%d,%d) [location in cache]", name, row, col); @@ -2915,6 +3005,8 @@ GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); } + xfdesktop_close_icons_rc_file(fmanager); + g_object_unref(fmanager->priv->enumerator); fmanager->priv->enumerator = NULL; @@ -2990,6 +3082,8 @@ NULL, NULL); if(fmanager->priv->enumerator) { + xfdesktop_open_icons_rc_file(fmanager); + g_file_enumerator_next_files_async(fmanager->priv->enumerator, 10, G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback) xfdesktop_file_icon_manager_files_ready,