[Xfce4-commits] <xfdesktop:master> Simplify adding icons to the desktop

Eric Koegel noreply at xfce.org
Mon Feb 10 14:02:01 CET 2014


Updating branch refs/heads/master
         to e339463f95c70578aae33f339ac54433f51cc5ae (commit)
       from 9cec4dbbd0dcd9f1d6a0e247a64c133324c6a9c2 (commit)

commit e339463f95c70578aae33f339ac54433f51cc5ae
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Feb 10 15:07:29 2014 +0300

    Simplify adding icons to the desktop
    
    Use xfdesktop_grid_get_next_free_position when placing icons on
    the desktop rather than having it spead over multiple functions.

 src/xfdesktop-file-icon-manager.c |   35 +++----
 src/xfdesktop-file-icon-manager.h |    4 +-
 src/xfdesktop-icon-view-manager.c |    8 +-
 src/xfdesktop-icon-view-manager.h |   16 +--
 src/xfdesktop-icon-view.c         |  198 +++++++++++++++++++------------------
 src/xfdesktop-icon.c              |   12 +--
 src/xfdesktop-icon.h              |    8 +-
 src/xfdesktop-window-icon.c       |    2 +-
 8 files changed, 145 insertions(+), 138 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 9e9ad3c..7a54d18 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -162,14 +162,14 @@ static void xfdesktop_file_icon_manager_fini(XfdesktopIconViewManager *manager);
 static gboolean xfdesktop_file_icon_manager_drag_drop(XfdesktopIconViewManager *manager,
                                                       XfdesktopIcon *drop_icon,
                                                       GdkDragContext *context,
-                                                      guint16 row,
-                                                      guint16 col,
+                                                      gint row,
+                                                      gint col,
                                                       guint time_);
 static void xfdesktop_file_icon_manager_drag_data_received(XfdesktopIconViewManager *manager,
                                                            XfdesktopIcon *drop_icon,
                                                            GdkDragContext *context,
-                                                           guint16 row,
-                                                           guint16 col,
+                                                           gint row,
+                                                           gint col,
                                                            GtkSelectionData *data,
                                                            guint info,
                                                            guint time_);
@@ -1723,7 +1723,7 @@ file_icon_hash_write_icons(gpointer key,
 {
     XfceRc *rcfile = data;
     XfdesktopIcon *icon = value;
-    guint16 row, col;
+    gint row, col;
     gchar *identifier = xfdesktop_icon_get_identifier(icon);
 
     if(xfdesktop_icon_get_position(icon, &row, &col)) {
@@ -1832,8 +1832,8 @@ gboolean
 xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *fmanager,
                                                      const gchar *name,
                                                      const gchar *identifier,
-                                                     gint16 *row,
-                                                     gint16 *col)
+                                                     gint *row,
+                                                     gint *col)
 {
     gchar relpath[PATH_MAX];
     gchar *filename = NULL;
@@ -2055,7 +2055,7 @@ process_icon_from_queue(gpointer user_data)
 static void
 xfdesktop_file_icon_manager_add_icon(XfdesktopFileIconManager *fmanager,
                                      XfdesktopFileIcon *icon,
-                                     gint16 row, gint16 col)
+                                     gint row, gint col)
 {
     const gchar *name;
     gchar *identifier;
@@ -2081,11 +2081,12 @@ xfdesktop_file_icon_manager_add_icon(XfdesktopFileIconManager *fmanager,
                                                                    name, identifier,
                                                                    &row, &col))
     {
-        DBG("attempting to set icon '%s' to position (%d,%d)", name, row, col);
+        DBG("attempting to set icon '%s' to cached position (%d,%d)", name, row, col);
         xfdesktop_icon_set_position(XFDESKTOP_ICON(icon), row, col);
         g_queue_push_head(fmanager->priv->pending_icons, icon);
     } else {
         /* Didn't have a spot, push it to the end of the stack */
+        xfdesktop_icon_set_position(XFDESKTOP_ICON(icon), row, col);
         g_queue_push_tail(fmanager->priv->pending_icons, icon);
     }
 
@@ -2146,7 +2147,7 @@ static XfdesktopFileIcon *
 xfdesktop_file_icon_manager_add_regular_icon(XfdesktopFileIconManager *fmanager,
                                              GFile *file,
                                              GFileInfo *info,
-                                             guint16 row, guint16 col,
+                                             gint row, gint col,
                                              gboolean defer_if_missing)
 {
     XfdesktopRegularFileIcon *icon = NULL;
@@ -2456,7 +2457,7 @@ xfdesktop_file_icon_manager_file_changed(GFileMonitor     *monitor,
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     XfdesktopFileIcon *icon, *moved_icon;
     GFileInfo *file_info;
-    guint16 row = 0, col = 0;
+    gint row = 0, col = 0;
     gchar *filename;
 
     switch(event) {
@@ -3142,8 +3143,8 @@ static gboolean
 xfdesktop_file_icon_manager_drag_drop(XfdesktopIconViewManager *manager,
                                       XfdesktopIcon *drop_icon,
                                       GdkDragContext *context,
-                                      guint16 row,
-                                      guint16 col,
+                                      gint row,
+                                      gint col,
                                       guint time_)
 {
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(manager);
@@ -3249,8 +3250,8 @@ static void xfdesktop_dnd_menu (XfdesktopIconViewManager *manager,
                                 XfdesktopIcon *drop_icon,
                                 GdkDragContext *context,
                                 GdkDragAction *action,
-                                guint16 row,
-                                guint16 col,
+                                gint row,
+                                gint col,
                                 guint time_)
 {
     static GdkDragAction    actions[] = { GDK_ACTION_COPY, GDK_ACTION_MOVE, GDK_ACTION_LINK };
@@ -3311,8 +3312,8 @@ static void
 xfdesktop_file_icon_manager_drag_data_received(XfdesktopIconViewManager *manager,
                                                XfdesktopIcon *drop_icon,
                                                GdkDragContext *context,
-                                               guint16 row,
-                                               guint16 col,
+                                               gint row,
+                                               gint col,
                                                GtkSelectionData *data,
                                                guint info,
                                                guint time_)
diff --git a/src/xfdesktop-file-icon-manager.h b/src/xfdesktop-file-icon-manager.h
index 847f573..5e7b2d9 100644
--- a/src/xfdesktop-file-icon-manager.h
+++ b/src/xfdesktop-file-icon-manager.h
@@ -59,8 +59,8 @@ gboolean xfdesktop_file_icon_manager_get_cached_icon_position(
                                                     XfdesktopFileIconManager *fmanager,
                                                     const gchar *name,
                                                     const gchar *identifier,
-                                                    gint16 *row,
-                                                    gint16 *col);
+                                                    gint *row,
+                                                    gint *col);
 
 G_END_DECLS
 
diff --git a/src/xfdesktop-icon-view-manager.c b/src/xfdesktop-icon-view-manager.c
index 9f9d15a..cdd1961 100644
--- a/src/xfdesktop-icon-view-manager.c
+++ b/src/xfdesktop-icon-view-manager.c
@@ -86,8 +86,8 @@ gboolean
 xfdesktop_icon_view_manager_drag_drop(XfdesktopIconViewManager *manager,
                                       XfdesktopIcon *drop_icon,
                                       GdkDragContext *context,
-                                      guint16 row,
-                                      guint16 col,
+                                      gint row,
+                                      gint col,
                                       guint time_)
 {
     XfdesktopIconViewManagerIface *iface;
@@ -104,8 +104,8 @@ void
 xfdesktop_icon_view_manager_drag_data_received(XfdesktopIconViewManager *manager,
                                                XfdesktopIcon *drop_icon,
                                                GdkDragContext *context,
-                                               guint16 row,
-                                               guint16 col,
+                                               gint row,
+                                               gint col,
                                                GtkSelectionData *data,
                                                guint info,
                                                guint time_)
diff --git a/src/xfdesktop-icon-view-manager.h b/src/xfdesktop-icon-view-manager.h
index 7751511..d1bb2a7 100644
--- a/src/xfdesktop-icon-view-manager.h
+++ b/src/xfdesktop-icon-view-manager.h
@@ -51,14 +51,14 @@ struct _XfdesktopIconViewManagerIface
     gboolean (*drag_drop)(XfdesktopIconViewManager *manager,
                           XfdesktopIcon *drop_icon,
                           GdkDragContext *context,
-                          guint16 row,
-                          guint16 col,
+                          gint row,
+                          gint col,
                           guint time_);
     void (*drag_data_received)(XfdesktopIconViewManager *manager,
                                XfdesktopIcon *drop_icon,
                                GdkDragContext *context,
-                               guint16 row,
-                               guint16 col,
+                               gint row,
+                               gint col,
                                GtkSelectionData *data,
                                guint info,
                                guint time_);
@@ -87,14 +87,14 @@ void xfdesktop_icon_view_manager_fini(XfdesktopIconViewManager *manager);
 gboolean xfdesktop_icon_view_manager_drag_drop(XfdesktopIconViewManager *manager,
                                                XfdesktopIcon *drop_icon,
                                                GdkDragContext *context,
-                                               guint16 row,
-                                               guint16 col,
+                                               gint row,
+                                               gint col,
                                                guint time_);
 void xfdesktop_icon_view_manager_drag_data_received(XfdesktopIconViewManager *manager,
                                                     XfdesktopIcon *drop_icon,
                                                     GdkDragContext *context,
-                                                    guint16 row,
-                                                    guint16 col,
+                                                    gint row,
+                                                    gint col,
                                                     GtkSelectionData *data,
                                                     guint info,
                                                     guint time_);
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index 0bbfc3d..8f64603 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -124,9 +124,9 @@ struct _XfdesktopIconViewPrivate
     gint yorigin;
     gint width;
     gint height;
-    
-    guint16 nrows;
-    guint16 ncols;
+
+    gint nrows;
+    gint ncols;
     XfdesktopIcon **grid_layout;
     
     guint grid_resize_timeout;
@@ -162,7 +162,7 @@ struct _XfdesktopIconViewPrivate
 
     gboolean dropped;
     GdkDragAction proposed_drop_action;
-    guint16 hover_row, hover_col;
+    gint hover_row, hover_col;
     
     guchar    label_alpha;
     guchar    selected_label_alpha;
@@ -286,25 +286,25 @@ static void xfdesktop_icon_view_repaint_icons(XfdesktopIconView *icon_view,
                                   
 static void xfdesktop_setup_grids(XfdesktopIconView *icon_view);
 static gboolean xfdesktop_grid_get_next_free_position(XfdesktopIconView *icon_view,
-                                                      guint16 *row,
-                                                      guint16 *col);
+                                                      gint *row,
+                                                      gint *col);
 static inline gboolean xfdesktop_grid_is_free_position(XfdesktopIconView *icon_view,
-                                                       guint16 row,
-                                                       guint16 col);
+                                                       gint row,
+                                                       gint col);
 static inline void xfdesktop_grid_set_position_free(XfdesktopIconView *icon_view,
-                                                    guint16 row,
-                                                    guint16 col);
+                                                    gint row,
+                                                    gint col);
 static inline gboolean xfdesktop_grid_unset_position_free_raw(XfdesktopIconView *icon_view,
-                                                              guint16 row,
-                                                              guint16 col,
+                                                              gint row,
+                                                              gint col,
                                                               gpointer data);
 static inline gboolean xfdesktop_grid_unset_position_free(XfdesktopIconView *icon_view,
                                                           XfdesktopIcon *icon);
 static inline XfdesktopIcon *xfdesktop_icon_view_icon_in_cell_raw(XfdesktopIconView *icon_view,
                                                                   gint idx);
 static inline XfdesktopIcon *xfdesktop_icon_view_icon_in_cell(XfdesktopIconView *icon_view,
-                                                              guint16 row,
-                                                              guint16 col);
+                                                              gint row,
+                                                              gint col);
 static gint xfdesktop_check_icon_clicked(gconstpointer data,
                                          gconstpointer user_data);
 static void xfdesktop_list_foreach_invalidate(gpointer data,
@@ -313,8 +313,8 @@ static void xfdesktop_list_foreach_invalidate(gpointer data,
 static inline void xfdesktop_xy_to_rowcol(XfdesktopIconView *icon_view,
                                           gint x,
                                           gint y,
-                                          guint16 *row,
-                                          guint16 *col);
+                                          gint *row,
+                                          gint *col);
 static gboolean xfdesktop_grid_resize_timeout(gpointer user_data);
 static void xfdesktop_screen_size_changed_cb(GdkScreen *gscreen,
                                              gpointer user_data);
@@ -1393,8 +1393,8 @@ static inline void
 xfdesktop_xy_to_rowcol(XfdesktopIconView *icon_view,
                        gint x,
                        gint y,
-                       guint16 *row,
-                       guint16 *col)
+                       gint *row,
+                       gint *col)
 {
     g_return_if_fail(row && col);
     
@@ -1450,8 +1450,8 @@ xfdesktop_icon_view_clear_drag_highlight(XfdesktopIconView *icon_view,
 static inline void
 xfdesktop_icon_view_draw_drag_highlight(XfdesktopIconView *icon_view,
                                         GdkDragContext *context,
-                                        guint16 row,
-                                        guint16 col)
+                                        gint row,
+                                        gint col)
 {
     GtkWidget *widget = GTK_WIDGET(icon_view);
     cairo_t *cr;
@@ -1495,7 +1495,7 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
 {
     XfdesktopIconView *icon_view = XFDESKTOP_ICON_VIEW(widget);
     GdkAtom target;
-    guint16 hover_row = 0, hover_col = 0;
+    gint hover_row = 0, hover_col = 0;
     XfdesktopIcon *icon_on_dest = NULL;
     GdkDragAction our_action = 0;
     gboolean is_local_drag;
@@ -1542,7 +1542,7 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
         if(is_local_drag) {  /* #2 */
             /* check to make sure we aren't just hovering over ourself */
             GList *l;
-            guint16 sel_row, sel_col;
+            gint sel_row, sel_col;
             
             for(l = icon_view->priv->selected_icons; l; l = l->next) {
                 XfdesktopIcon *sel_icon = l->data;
@@ -1616,7 +1616,7 @@ xfdesktop_icon_view_drag_drop(GtkWidget *widget,
     XfdesktopIconView *icon_view = XFDESKTOP_ICON_VIEW(widget);
     GdkAtom target;
     XfdesktopIcon *icon;
-    guint16 old_row, old_col, row, col;
+    gint old_row, old_col, row, col;
     GList *l;
     XfdesktopIcon *icon_on_dest = NULL;
     
@@ -1676,8 +1676,7 @@ xfdesktop_icon_view_drag_drop(GtkWidget *widget,
         xfdesktop_icon_set_position(icon, row, col);
         xfdesktop_grid_unset_position_free(icon_view, icon);
         
-        /* clear out old extents, if any */
-        /* FIXME: is this right? */
+        /* clear out old extents */
         xfdesktop_icon_view_invalidate_icon(icon_view, icon, TRUE);
 
         /* Now that we have moved the icon the user selected,
@@ -1687,21 +1686,13 @@ xfdesktop_icon_view_drag_drop(GtkWidget *widget,
                 continue;
 
             /* Find the next available spot for an icon */
-            do {
-                if(row + 1 >= icon_view->priv->nrows) {
-                    ++col;
-                    row = 0;
-                } else {
-                    ++row;
-                }
-            } while(!xfdesktop_grid_is_free_position(icon_view, row, col));
+            xfdesktop_grid_get_next_free_position(icon_view, &row, &col);
 
             /* set new position */
             xfdesktop_icon_set_position(l->data, row, col);
             xfdesktop_grid_unset_position_free(icon_view, l->data);
 
-            /* clear out old extents, if any */
-            /* FIXME: is this right? */
+            /* clear out old extents */
             xfdesktop_icon_view_invalidate_icon(icon_view, l->data, TRUE);
         }
         
@@ -1751,7 +1742,7 @@ xfdesktop_icon_view_drag_data_received(GtkWidget *widget,
                                        guint time_)
 {
     XfdesktopIconView *icon_view = XFDESKTOP_ICON_VIEW(widget);
-    guint16 row, col;
+    gint row, col;
     XfdesktopIcon *icon_on_dest;
     
     TRACE("entering");
@@ -1813,27 +1804,23 @@ xfdesktop_icon_view_compare_icons(gconstpointer *a,
 static void
 xfdesktop_icon_view_append_icons(XfdesktopIconView *icon_view,
                                  GList *icon_list,
-                                 guint16 *row,
-                                 guint16 *col)
+                                 gint *row,
+                                 gint *col)
 {
     GList *l = NULL;
     for(l = icon_list; l != NULL; l = g_list_next(l)) {
 
         /* Find the next available spot for an icon */
-        do {
-            if(*row + 1 >= icon_view->priv->nrows) {
-                ++*col;
-                *row = 0;
-            } else {
-                ++*row;
-            }
-        } while(!xfdesktop_grid_is_free_position(icon_view, *row, *col));
-
-        /* set new position */
-        xfdesktop_icon_set_position(l->data, *row, *col);
-        xfdesktop_grid_unset_position_free(icon_view, l->data);
+        if(xfdesktop_grid_get_next_free_position(icon_view, row, col)) {
+            /* set new position */
+            xfdesktop_icon_set_position(l->data, *row, *col);
+            xfdesktop_grid_unset_position_free(icon_view, l->data);
 
-        xfdesktop_icon_view_invalidate_icon(icon_view, l->data, TRUE);
+            xfdesktop_icon_view_invalidate_icon(icon_view, l->data, TRUE);
+        } else {
+            /* no space for icons on the desktop, exit now */
+            return;
+        }
     }
 }
 
@@ -1845,11 +1832,11 @@ xfdesktop_icon_view_sort_icons(XfdesktopIconView *icon_view)
     GList *special_icons = NULL;
     GList *folder_icons = NULL;
     GList *regular_icons = NULL;
-    guint16 row = 0;
-    guint16 col = -1; /* start at -1 because we'll increment it */
+    gint row = 0;
+    gint col = -1; /* start at -1 because we'll increment it */
 
     for(l = icon_view->priv->icons; l; l = l->next) {
-        guint16 old_row, old_col;
+        gint old_row, old_col;
 
         /* clear out old position */
         xfdesktop_icon_view_invalidate_icon(icon_view, l->data, FALSE);
@@ -2286,7 +2273,7 @@ xfdesktop_icon_view_select_between(XfdesktopIconView *icon_view,
                                    XfdesktopIcon *start_icon,
                                    XfdesktopIcon *end_icon)
 {
-    guint16 start_row, start_col, end_row, end_col;
+    gint start_row, start_col, end_row, end_col;
     gint i, j;
     XfdesktopIcon *icon;
 
@@ -2295,7 +2282,7 @@ xfdesktop_icon_view_select_between(XfdesktopIconView *icon_view,
     {
         if(start_row > end_row || (start_row == end_row && start_col > end_col)) {
             /* flip start and end */
-            guint16 tmpr = start_row, tmpc = start_col;
+            gint tmpr = start_row, tmpc = start_col;
 
             start_row = end_row;
             start_col = end_col;
@@ -2362,7 +2349,7 @@ xfdesktop_icon_view_move_cursor_left_right(XfdesktopIconView *icon_view,
                                            gint count,
                                            GdkModifierType modmask)
 {
-    guint16 row, col;
+    gint row, col;
     gint i, j;
     guint left = (count < 0 ? -count : count);
     gint step = (count < 0 ? -1 : 1);
@@ -2425,7 +2412,7 @@ xfdesktop_icon_view_move_cursor_up_down(XfdesktopIconView *icon_view,
                                         gint count,
                                         GdkModifierType modmask)
 {
-    guint16 row, col;
+    gint row, col;
     gint i, j;
     guint left = (count < 0 ? -count : count);
     gint step = (count < 0 ? -1 : 1);
@@ -2706,7 +2693,7 @@ xfdesktop_setup_grids(XfdesktopIconView *icon_view)
     DBG("CELL_SIZE=%0.3f, TEXT_WIDTH=%0.3f, ICON_SIZE=%u", CELL_SIZE, TEXT_WIDTH, ICON_SIZE);
     DBG("grid size is %dx%d", icon_view->priv->nrows, icon_view->priv->ncols);
 
-    new_size = (guint)icon_view->priv->nrows * icon_view->priv->ncols
+    new_size = icon_view->priv->nrows * icon_view->priv->ncols
                * sizeof(XfdesktopIcon *);
 
     if(icon_view->priv->grid_layout) {
@@ -2714,7 +2701,7 @@ xfdesktop_setup_grids(XfdesktopIconView *icon_view)
                                                  new_size);
         
         if(new_size > old_size) {
-            memset(((guint8 *)icon_view->priv->grid_layout) + old_size, 0,
+            memset(((guint *)icon_view->priv->grid_layout) + old_size, 0,
                    new_size - old_size);
         }
     } else
@@ -2967,7 +2954,7 @@ xfdesktop_icon_view_shift_area_to_cell(XfdesktopIconView *icon_view,
                                        XfdesktopIcon *icon,
                                        GdkRectangle *area)
 {
-    guint16 row, col;
+    gint row, col;
 
     if(!xfdesktop_icon_get_position(icon, &row, &col)) {
         g_warning("trying to calculate without a position for icon '%s'",
@@ -3171,7 +3158,7 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
 #if 0 /*def DEBUG*/
     {
         GdkRectangle cell = { 0, };
-        guint16 row, col;
+        gint row, col;
 
         if(!xfdesktop_icon_get_position(icon, &row, &col))
             DBG("can't get icon position for '%s'", xfdesktop_icon_peek_label(icon));
@@ -3220,7 +3207,7 @@ xfdesktop_move_all_icons_to_pending_icons_list(XfdesktopIconView *icon_view)
     
     /* 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;
+        gint 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);
@@ -3234,7 +3221,7 @@ xfdesktop_move_all_icons_to_pending_icons_list(XfdesktopIconView *icon_view)
     icon_view->priv->icons = NULL;
 
     memset(icon_view->priv->grid_layout, 0,
-           (guint)icon_view->priv->nrows * icon_view->priv->ncols
+           icon_view->priv->nrows * icon_view->priv->ncols
            * sizeof(XfdesktopIcon *));
     
     xfdesktop_setup_grids(icon_view);
@@ -3260,7 +3247,7 @@ xfdesktop_move_all_cached_icons_to_desktop(XfdesktopIconView *icon_view)
 
     /* add all cached icons back */
     for(l = icon_view->priv->pending_icons; l; l = l->next) {
-        gint16 row, col;
+        gint row, col;
         XfdesktopIcon *icon = XFDESKTOP_ICON(l->data);
         gchar *identifier = xfdesktop_icon_get_identifier(icon);
 
@@ -3309,7 +3296,7 @@ xfdesktop_move_all_previous_icons_to_desktop(XfdesktopIconView *icon_view)
 
     /* add all pending icons back if their space is still available */
     for(l = icon_view->priv->pending_icons; l; l = l->next) {
-        guint16 row, col;
+        gint row, col;
         XfdesktopIcon *icon = XFDESKTOP_ICON(l->data);
 
         if(!xfdesktop_icon_get_position(icon, &row, &col)) {
@@ -3339,7 +3326,7 @@ xfdesktop_append_all_pending_icons(XfdesktopIconView *icon_view)
 
     /* add all pending icons back if space is available */
     for(l = icon_view->priv->pending_icons; l; l = l->next) {
-        guint16 row, col;
+        gint row = -1, col = -1;
         XfdesktopIcon *icon = XFDESKTOP_ICON(l->data);
 
         if(xfdesktop_grid_get_next_free_position(icon_view, &row, &col)) {
@@ -3378,7 +3365,7 @@ xfdesktop_grid_do_resize(XfdesktopIconView *icon_view)
 #endif
 
     memset(icon_view->priv->grid_layout, 0,
-           (guint)icon_view->priv->nrows * icon_view->priv->ncols
+           icon_view->priv->nrows * icon_view->priv->ncols
            * sizeof(XfdesktopIcon *));
     
     xfdesktop_setup_grids(icon_view);
@@ -3476,8 +3463,8 @@ xfdesktop_get_workarea_single(XfdesktopIconView *icon_view,
 
 static inline gboolean
 xfdesktop_grid_is_free_position(XfdesktopIconView *icon_view,
-                                guint16 row,
-                                guint16 col)
+                                gint row,
+                                gint col)
 {
     g_return_val_if_fail(icon_view->priv->grid_layout != NULL, FALSE);
 
@@ -3493,30 +3480,49 @@ xfdesktop_grid_is_free_position(XfdesktopIconView *icon_view,
 
 static gboolean
 xfdesktop_grid_get_next_free_position(XfdesktopIconView *icon_view,
-                                      guint16 *row,
-                                      guint16 *col)
+                                      gint *row,
+                                      gint *col)
 {
-    gint i, maxi;
-    
+    gint current_row, current_col, start_row, start_col;
+    gboolean wrap_flag = FALSE;
+
     g_return_val_if_fail(row && col, FALSE);
-    
-    maxi = icon_view->priv->nrows * icon_view->priv->ncols;
-    for(i = 0; i < maxi; ++i) {
-        if(!icon_view->priv->grid_layout[i]) {
-            *row = i % icon_view->priv->nrows;
-            *col = i / icon_view->priv->nrows;
-            return TRUE;
+
+    /* If row/col are invalid start at upper left */
+    start_row = *row >= 0 && *row < icon_view->priv->nrows ? *row : 0;
+    start_col = *col >= 0 && *col < icon_view->priv->ncols ? *col : 0;
+
+    current_row = start_row;
+    current_col = start_col;
+
+    while(TRUE) {
+        for(; current_col < icon_view->priv->ncols; ++current_col) {
+            for(; current_row < icon_view->priv->nrows; ++current_row) {
+                if(!icon_view->priv->grid_layout[current_col * icon_view->priv->nrows + current_row]) {
+                    *row = current_row;
+                    *col = current_col;
+                    return TRUE;
+                }
+            }
+            /* First row we start at row, after that 0 */
+            current_row = 0;
+            /* If we wrapped around on ourselves there's no space for an icon */
+            if(wrap_flag && current_col >= start_col)
+                return FALSE;
         }
+        /* First time around we start at col, once we wrap around we start at 0 */
+        current_col = 0;
+        wrap_flag = TRUE;
     }
-    
+
     return FALSE;
 }
 
 
 static inline void
 xfdesktop_grid_set_position_free(XfdesktopIconView *icon_view,
-                                 guint16 row,
-                                 guint16 col)
+                                 gint row,
+                                 gint col)
 {
     g_return_if_fail(row < icon_view->priv->nrows
                      && col < icon_view->priv->ncols);
@@ -3528,8 +3534,8 @@ xfdesktop_grid_set_position_free(XfdesktopIconView *icon_view,
 
 static inline gboolean
 xfdesktop_grid_unset_position_free_raw(XfdesktopIconView *icon_view,
-                                       guint16 row,
-                                       guint16 col,
+                                       gint row,
+                                       gint col,
                                        gpointer data)
 {
     gint idx;
@@ -3558,7 +3564,7 @@ static inline gboolean
 xfdesktop_grid_unset_position_free(XfdesktopIconView *icon_view,
                                    XfdesktopIcon *icon)
 {
-    guint16 row, col;
+    gint row, col;
     
     if(!xfdesktop_icon_get_position(icon, &row, &col)) {
         g_warning("Trying to set free position of an icon with no position");
@@ -3582,8 +3588,8 @@ xfdesktop_icon_view_icon_in_cell_raw(XfdesktopIconView *icon_view,
 
 static inline XfdesktopIcon *
 xfdesktop_icon_view_icon_in_cell(XfdesktopIconView *icon_view,
-                                 guint16 row,
-                                 guint16 col)
+                                 gint row,
+                                 gint col)
 {
     gint idx;
     
@@ -3702,7 +3708,7 @@ xfdesktop_icon_view_new(XfdesktopIconViewManager *manager)
                            G_TYPE_DOUBLE,
                            G_OBJECT(icon_view),
                            "tooltip_size");
-    
+
     return GTK_WIDGET(icon_view);
 }
 
@@ -3710,7 +3716,7 @@ static void
 xfdesktop_icon_view_add_item_internal(XfdesktopIconView *icon_view,
                                       XfdesktopIcon *icon)
 {
-    guint16 row, col;
+    gint row, col;
     GdkRectangle fake_area;
     
     /* sanity check: at this point this should be taken care of */
@@ -3740,7 +3746,7 @@ static gboolean
 xfdesktop_icon_view_icon_find_position(XfdesktopIconView *icon_view,
                                        XfdesktopIcon *icon)
 {
-    guint16 row, col;
+    gint row, col;
     
     if(!xfdesktop_icon_get_position(icon, &row, &col)
        || !xfdesktop_grid_is_free_position(icon_view, row, col))
@@ -3762,7 +3768,7 @@ void
 xfdesktop_icon_view_add_item(XfdesktopIconView *icon_view,
                              XfdesktopIcon *icon)
 {
-    guint16 row, col;
+    gint row, col;
     
     g_return_if_fail(XFDESKTOP_IS_ICON_VIEW(icon_view)
                      && XFDESKTOP_IS_ICON(icon));
@@ -3798,7 +3804,7 @@ void
 xfdesktop_icon_view_remove_item(XfdesktopIconView *icon_view,
                                 XfdesktopIcon *icon)
 {
-    guint16 row, col;
+    gint row, col;
     GList *l;
     
     g_return_if_fail(XFDESKTOP_IS_ICON_VIEW(icon_view)
@@ -3848,7 +3854,7 @@ void
 xfdesktop_icon_view_remove_all(XfdesktopIconView *icon_view)
 {
     GList *l;
-    guint16 row, col;
+    gint row, col;
     
     g_return_if_fail(XFDESKTOP_IS_ICON_VIEW(icon_view));
     
@@ -4045,7 +4051,7 @@ xfdesktop_icon_view_widget_coords_to_item(XfdesktopIconView *icon_view,
                                           gint wx,
                                           gint wy)
 {
-    guint16 row, col;
+    gint row, col;
     
     xfdesktop_xy_to_rowcol(icon_view, wx, wy, &row, &col);
     if(row >= icon_view->priv->nrows
diff --git a/src/xfdesktop-icon.c b/src/xfdesktop-icon.c
index 4d58855..936ecf7 100644
--- a/src/xfdesktop-icon.c
+++ b/src/xfdesktop-icon.c
@@ -34,8 +34,8 @@
 
 struct _XfdesktopIconPrivate
 {
-    gint16 row;
-    gint16 col;
+    gint row;
+    gint col;
 
     GdkRectangle pixbuf_extents;
     GdkRectangle text_extents;
@@ -136,8 +136,8 @@ xfdesktop_icon_finalize(GObject *obj)
 
 void
 xfdesktop_icon_set_position(XfdesktopIcon *icon,
-                            gint16 row,
-                            gint16 col)
+                            gint row,
+                            gint col)
 {
     g_return_if_fail(XFDESKTOP_IS_ICON(icon));
     
@@ -149,8 +149,8 @@ xfdesktop_icon_set_position(XfdesktopIcon *icon,
 
 gboolean
 xfdesktop_icon_get_position(XfdesktopIcon *icon,
-                            guint16 *row,
-                            guint16 *col)
+                            gint *row,
+                            gint *col)
 {
     g_return_val_if_fail(XFDESKTOP_IS_ICON(icon) && row && col, FALSE);
     
diff --git a/src/xfdesktop-icon.h b/src/xfdesktop-icon.h
index 577b123..ca85e12 100644
--- a/src/xfdesktop-icon.h
+++ b/src/xfdesktop-icon.h
@@ -100,11 +100,11 @@ G_CONST_RETURN gchar *xfdesktop_icon_peek_tooltip(XfdesktopIcon *icon);
 gchar *xfdesktop_icon_get_identifier(XfdesktopIcon *icon);
 
 void xfdesktop_icon_set_position(XfdesktopIcon *icon,
-                                 gint16 row,
-                                 gint16 col);
+                                 gint row,
+                                 gint col);
 gboolean xfdesktop_icon_get_position(XfdesktopIcon *icon,
-                                     guint16 *row,
-                                     guint16 *col);
+                                     gint *row,
+                                     gint *col);
 
 GdkDragAction xfdesktop_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
 
diff --git a/src/xfdesktop-window-icon.c b/src/xfdesktop-window-icon.c
index 77e8cc3..78e732d 100644
--- a/src/xfdesktop-window-icon.c
+++ b/src/xfdesktop-window-icon.c
@@ -88,7 +88,7 @@ xfdesktop_window_icon_finalize(GObject *obj)
 {
     XfdesktopWindowIcon *icon = XFDESKTOP_WINDOW_ICON(obj);
     gchar data_name[256];
-    guint16 row, col;
+    gint row, col;
     
     g_free(icon->priv->label);
     


More information about the Xfce4-commits mailing list