[Xfce4-commits] <xfdesktop:master> Icon positions are saved/restored per resolution
Eric Koegel
noreply at xfce.org
Mon Mar 5 19:30:08 CET 2012
Updating branch refs/heads/master
to dc4f69b84425cc135c8a70ac04ea3e6ba318d02e (commit)
from ab5aac37a7855b79c2bb1b2df686e938c477ff34 (commit)
commit dc4f69b84425cc135c8a70ac04ea3e6ba318d02e
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Tue Feb 7 15:26:20 2012 +0300
Icon positions are saved/restored per resolution
Icon positions are now stored in seperate rc files per screen
resolution so that when reverting from a lower screen resolution
the icons aren't stuck at the upper-left. The old rc file is used
as a fallback so that the migration is seemless. For bug 6149.
src/xfdesktop-file-icon-manager.c | 38 +++++++++++++++++++++++++++---------
src/xfdesktop-file-icon-manager.h | 5 ++++
src/xfdesktop-icon-view.c | 29 ++++++++++++++++++++++++++-
3 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 92f8422..4a19539 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -430,8 +430,10 @@ __migrate_old_icon_positions(XfdesktopFileIconManager *fmanager)
{
gchar relpath[PATH_MAX], *old_file;
- g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d.rc",
- gdk_screen_get_number(fmanager->priv->gscreen));
+ g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d-%dx%d.rc",
+ gdk_screen_get_number(fmanager->priv->gscreen),
+ gdk_screen_get_width(fmanager->priv->gscreen),
+ gdk_screen_get_height(fmanager->priv->gscreen));
old_file = xfce_resource_save_location(XFCE_RESOURCE_CACHE, relpath, FALSE);
@@ -1764,8 +1766,10 @@ xfdesktop_file_icon_manager_save_icons(gpointer user_data)
fmanager->priv->save_icons_id = 0;
- g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d.rc",
- gdk_screen_get_number(fmanager->priv->gscreen));
+ g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d-%dx%d.rc",
+ gdk_screen_get_number(fmanager->priv->gscreen),
+ gdk_screen_get_width(fmanager->priv->gscreen),
+ gdk_screen_get_height(fmanager->priv->gscreen));
path = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, relpath, TRUE);
if(!path)
return FALSE;
@@ -1822,20 +1826,33 @@ xfdesktop_file_icon_position_changed(XfdesktopFileIcon *icon,
/* ***** */
-static gboolean
+gboolean
xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *fmanager,
const gchar *name,
gint16 *row,
gint16 *col)
{
gchar relpath[PATH_MAX];
- XfceRc *rcfile;
+ gchar *filename = NULL;
gboolean ret = FALSE;
- g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d.rc",
- gdk_screen_get_number(fmanager->priv->gscreen));
- rcfile = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, relpath, TRUE);
- if(rcfile) {
+ g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d-%dx%d.rc",
+ gdk_screen_get_number(fmanager->priv->gscreen),
+ gdk_screen_get_width(fmanager->priv->gscreen),
+ gdk_screen_get_height(fmanager->priv->gscreen));
+ 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) {
+ XfceRc *rcfile;
+ rcfile = xfce_rc_simple_open(filename, TRUE);
+
if(xfce_rc_has_group(rcfile, name)) {
xfce_rc_set_group(rcfile, name);
*row = xfce_rc_read_int_entry(rcfile, "row", -1);
@@ -1844,6 +1861,7 @@ xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *f
ret = TRUE;
}
xfce_rc_close(rcfile);
+ g_free(filename);
}
return ret;
diff --git a/src/xfdesktop-file-icon-manager.h b/src/xfdesktop-file-icon-manager.h
index 1c45ecb..decdb74 100644
--- a/src/xfdesktop-file-icon-manager.h
+++ b/src/xfdesktop-file-icon-manager.h
@@ -68,6 +68,11 @@ void xfdesktop_file_icon_manager_set_show_thumbnails(XfdesktopFileIconManager *m
gboolean show_thumbnails);
gboolean xfdesktop_file_icon_manager_get_show_thumbnails(XfdesktopFileIconManager *manager);
+gboolean xfdesktop_file_icon_manager_get_cached_icon_position(
+ XfdesktopFileIconManager *fmanager,
+ const gchar *name,
+ gint16 *row,
+ gint16 *col);
G_END_DECLS
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index c803206..2be8970 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -47,6 +47,7 @@
#endif
#include "xfdesktop-icon-view.h"
+#include "xfdesktop-file-icon-manager.h"
#include "xfdesktop-marshal.h"
#include "xfce-desktop.h"
@@ -2795,10 +2796,16 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
static void
xfdesktop_grid_do_resize(XfdesktopIconView *icon_view)
{
+ XfdesktopFileIconManager *fmanager;
GList *l, *leftovers = NULL;
- /* move all icons into the pending_icons list */
+ //* move all icons into the pending_icons list and remove from the desktop */
for(l = icon_view->priv->icons; l; l = l->next) {
+ guint16 old_row, old_col;
+
+ if(xfdesktop_icon_get_position(XFDESKTOP_ICON(l->data), &old_row, &old_col))
+ xfdesktop_grid_set_position_free(icon_view, old_row, old_col);
+
g_signal_handlers_disconnect_by_func(G_OBJECT(l->data),
G_CALLBACK(xfdesktop_icon_view_icon_changed),
icon_view);
@@ -2816,10 +2823,28 @@ xfdesktop_grid_do_resize(XfdesktopIconView *icon_view)
xfdesktop_setup_grids(icon_view);
DUMP_GRID_LAYOUT(icon_view);
-
+
+#ifdef ENABLE_FILE_ICONS
+ fmanager = XFDESKTOP_FILE_ICON_MANAGER(icon_view->priv->manager);
+#endif
+
/* add all icons back */
for(l = icon_view->priv->pending_icons; l; l = l->next) {
+ gint16 row, col;
XfdesktopIcon *icon = XFDESKTOP_ICON(l->data);
+
+#ifdef ENABLE_FILE_ICONS
+ /* Try to get the cached position for the new resolution */
+ if(xfdesktop_file_icon_manager_get_cached_icon_position(
+ fmanager,
+ xfdesktop_icon_peek_label(icon),
+ &row,
+ &col))
+ {
+ xfdesktop_icon_set_position(icon, row, col);
+ }
+#endif
+
if(xfdesktop_icon_view_icon_find_position(icon_view, icon))
xfdesktop_icon_view_add_item_internal(icon_view, icon);
else
More information about the Xfce4-commits
mailing list