From 7bc1e74a2ab1c7e78f43bb105d52e7e423a4ad66 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Wed, 3 Sep 2014 22:29:25 -0300 Subject: [PATCH] Adds a small stacing between icons to distribute its correctly and fill the screen. --- src/xfdesktop-icon-view.c | 110 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 29 deletions(-) diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c index d914d6c..7abb878 100644 --- a/src/xfdesktop-icon-view.c +++ b/src/xfdesktop-icon-view.c @@ -64,7 +64,7 @@ #define SPACING (icon_view->priv->cell_spacing) #define LABEL_RADIUS (icon_view->priv->label_radius) #define TEXT_HEIGHT (CELL_SIZE - ICON_SIZE - SPACING - (CELL_PADDING * 2) - LABEL_RADIUS) -#define SCREEN_MARGIN 8 +#define MIN_MARGIN 8 #define DEFAULT_RUBBERBAND_ALPHA 64 #if defined(DEBUG) && DEBUG > 0 @@ -1395,10 +1395,21 @@ xfdesktop_xy_to_rowcol(XfdesktopIconView *icon_view, guint16 *row, guint16 *col) { + guint16 x_rest, x_spacing, x_margin; + guint16 y_rest, y_spacing, y_margin; + g_return_if_fail(row && col); - *row = (y - icon_view->priv->yorigin - SCREEN_MARGIN) / CELL_SIZE; - *col = (x - icon_view->priv->xorigin - SCREEN_MARGIN) / CELL_SIZE; + x_rest = icon_view->priv->width - icon_view->priv->ncols * CELL_SIZE; + x_spacing = (x_rest - MIN_MARGIN * 2) / (icon_view->priv->ncols - 1); + x_margin = (x_rest - (icon_view->priv->ncols - 1) * x_spacing) / 2; + + y_rest = icon_view->priv->height - icon_view->priv->nrows * CELL_SIZE; + y_spacing = (y_rest - MIN_MARGIN * 2) / (icon_view->priv->nrows - 1); + y_margin = (y_rest - (icon_view->priv->nrows - 1) * y_spacing) / 2; + + *row = (y - icon_view->priv->yorigin - y_margin) / (CELL_SIZE + y_spacing); + *col = (x - icon_view->priv->xorigin - x_margin) / (CELL_SIZE + x_spacing); } static inline void @@ -1455,10 +1466,20 @@ xfdesktop_icon_view_draw_drag_highlight(XfdesktopIconView *icon_view, GtkWidget *widget = GTK_WIDGET(icon_view); cairo_t *cr; GdkRectangle *cell_highlight; + guint16 x_rest, x_spacing, x_margin; + guint16 y_rest, y_spacing, y_margin; gint newx, newy; - - newx = SCREEN_MARGIN + icon_view->priv->xorigin + col * CELL_SIZE; - newy = SCREEN_MARGIN + icon_view->priv->yorigin + row * CELL_SIZE; + + x_rest = icon_view->priv->width - icon_view->priv->ncols * CELL_SIZE; + x_spacing = (x_rest - MIN_MARGIN * 2) / (icon_view->priv->ncols - 1); + x_margin = (x_rest - (icon_view->priv->ncols - 1) * x_spacing) / 2; + + y_rest = icon_view->priv->height - icon_view->priv->nrows * CELL_SIZE; + y_spacing = (y_rest - MIN_MARGIN * 2) / (icon_view->priv->nrows - 1); + y_margin = (y_rest - (icon_view->priv->nrows - 1) * y_spacing) / 2; + + newx = x_margin + icon_view->priv->xorigin + col * CELL_SIZE + col * x_spacing; + newy = y_margin + icon_view->priv->yorigin + row * CELL_SIZE + row * y_spacing; cell_highlight = g_object_get_qdata(G_OBJECT(context), xfdesktop_cell_highlight_quark); @@ -2634,6 +2655,8 @@ xfdesktop_icon_view_setup_grids_xinerama(XfdesktopIconView *icon_view) { GdkScreen *gscreen; GdkRectangle *monitor_geoms, cell_rect; + guint16 x_rest, x_spacing, x_margin; + guint16 y_rest, y_spacing, y_margin; gint nmonitors, i, row, col; TRACE("entering"); @@ -2647,16 +2670,24 @@ xfdesktop_icon_view_setup_grids_xinerama(XfdesktopIconView *icon_view) monitor_geoms = g_new0(GdkRectangle, nmonitors); for(i = 0; i < nmonitors; ++i) gdk_screen_get_monitor_geometry(gscreen, i, &monitor_geoms[i]); - + + x_rest = icon_view->priv->width - icon_view->priv->ncols * CELL_SIZE; + x_spacing = (x_rest - MIN_MARGIN * 2) / (icon_view->priv->ncols - 1); + x_margin = (x_rest - (icon_view->priv->ncols - 1) * x_spacing) / 2; + + y_rest = icon_view->priv->height - icon_view->priv->nrows * CELL_SIZE; + y_spacing = (y_rest - MIN_MARGIN * 2) / (icon_view->priv->nrows - 1); + y_margin = (y_rest - (icon_view->priv->nrows - 1) * y_spacing) / 2; + /* cubic time; w00t! */ cell_rect.width = cell_rect.height = CELL_SIZE; for(row = 0; row < icon_view->priv->nrows; ++row) { for(col = 0; col < icon_view->priv->ncols; ++col) { gboolean bounded = FALSE; - - cell_rect.x = SCREEN_MARGIN + icon_view->priv->xorigin + col * CELL_SIZE; - cell_rect.y = SCREEN_MARGIN + icon_view->priv->yorigin + row * CELL_SIZE; - + + cell_rect.x = x_margin + icon_view->priv->xorigin + col * CELL_SIZE + col * x_spacing; + cell_rect.y = y_margin + icon_view->priv->yorigin + row * CELL_SIZE + row * y_spacing; + for(i = 0; i < nmonitors; ++i) { if(xfdesktop_rectangle_is_bounded_by(&cell_rect, &monitor_geoms[i])) @@ -2702,13 +2733,13 @@ xfdesktop_setup_grids(XfdesktopIconView *icon_view) icon_view->priv->yorigin = yorigin; icon_view->priv->width = width; icon_view->priv->height = height; - - icon_view->priv->nrows = (height - SCREEN_MARGIN * 2) / CELL_SIZE; - icon_view->priv->ncols = (width - SCREEN_MARGIN * 2) / CELL_SIZE; + + icon_view->priv->nrows = (height - MIN_MARGIN * 2) / CELL_SIZE; + icon_view->priv->ncols = (width - MIN_MARGIN * 2) / CELL_SIZE; new_size = (guint)icon_view->priv->nrows * icon_view->priv->ncols * sizeof(XfdesktopIcon *); - + if(old_size == new_size) { DBG("old_size == new_size exiting"); return; @@ -2975,17 +3006,27 @@ xfdesktop_icon_view_shift_area_to_cell(XfdesktopIconView *icon_view, XfdesktopIcon *icon, GdkRectangle *area) { + guint16 x_rest, x_spacing, x_margin; + guint16 y_rest, y_spacing, y_margin; guint16 row, col; - + if(!xfdesktop_icon_get_position(icon, &row, &col)) { g_warning("trying to calculate without a position for icon '%s'", xfdesktop_icon_peek_label(icon)); return FALSE; } - - area->x += SCREEN_MARGIN + icon_view->priv->xorigin + col * CELL_SIZE; - area->y += SCREEN_MARGIN + icon_view->priv->yorigin + row * CELL_SIZE; - + + x_rest = icon_view->priv->width - icon_view->priv->ncols * CELL_SIZE; + x_spacing = (x_rest - MIN_MARGIN * 2) / (icon_view->priv->ncols - 1); + x_margin = (x_rest - (icon_view->priv->ncols - 1) * x_spacing) / 2; + + y_rest = icon_view->priv->height - icon_view->priv->nrows * CELL_SIZE; + y_spacing = (y_rest - MIN_MARGIN * 2) / (icon_view->priv->nrows - 1); + y_margin = (y_rest - (icon_view->priv->nrows - 1) * y_spacing) / 2; + + area->x = x_margin + icon_view->priv->xorigin + col * CELL_SIZE + col * x_spacing; + area->y = y_margin + icon_view->priv->yorigin + row * CELL_SIZE + row * y_spacing; + return TRUE; } @@ -3396,8 +3437,8 @@ xfdesktop_grid_do_resize(XfdesktopIconView *icon_view) height = gdk_screen_get_height(gscreen); } - new_rows = (height - SCREEN_MARGIN * 2) / CELL_SIZE; - new_cols = (width - SCREEN_MARGIN * 2) / CELL_SIZE; + new_rows = (height - MIN_MARGIN * 2) / CELL_SIZE; + new_cols = (width - MIN_MARGIN * 2) / CELL_SIZE; new_size = (guint)new_rows * new_cols * sizeof(XfdesktopIcon *); @@ -3495,13 +3536,13 @@ xfdesktop_get_workarea_single(XfdesktopIconView *icon_view, /* there's probably a better way to do this. */ if(i + (glong)nitems >= first_id && first_id - (glong)offset >= 0) - *xorigin = data[first_id - offset] + SCREEN_MARGIN; + *xorigin = data[first_id - offset] + MIN_MARGIN; if(i + (glong)nitems >= first_id + 1 && first_id - (glong)offset + 1 >= 0) - *yorigin = data[first_id - offset + 1] + SCREEN_MARGIN; + *yorigin = data[first_id - offset + 1] + MIN_MARGIN; if(i + (glong)nitems >= first_id + 2 && first_id - (glong)offset + 2 >= 0) - *width = data[first_id - offset + 2] - 2 * SCREEN_MARGIN; + *width = data[first_id - offset + 2] - 2 * MIN_MARGIN; if(i + (glong)nitems >= first_id + 3 && first_id - (glong)offset + 3 >= 0) { - *height = data[first_id - offset + 3] - 2 * SCREEN_MARGIN; + *height = data[first_id - offset + 3] - 2 * MIN_MARGIN; ret = TRUE; XFree(data_p); g_free(data); @@ -3762,6 +3803,8 @@ static void xfdesktop_icon_view_add_item_internal(XfdesktopIconView *icon_view, XfdesktopIcon *icon) { + guint16 x_rest, x_spacing, x_margin; + guint16 y_rest, y_spacing, y_margin; guint16 row, col; GdkRectangle fake_area; @@ -3781,10 +3824,19 @@ xfdesktop_icon_view_add_item_internal(XfdesktopIconView *icon_view, g_signal_connect(G_OBJECT(icon), "label-changed", G_CALLBACK(xfdesktop_icon_view_icon_changed), icon_view); - - fake_area.x = SCREEN_MARGIN + icon_view->priv->xorigin + col * CELL_SIZE; - fake_area.y = SCREEN_MARGIN + icon_view->priv->yorigin + row * CELL_SIZE; + + x_rest = icon_view->priv->width - icon_view->priv->ncols * CELL_SIZE; + x_spacing = (x_rest - MIN_MARGIN * 2) / (icon_view->priv->ncols - 1); + x_margin = (x_rest - (icon_view->priv->ncols - 1) * x_spacing) / 2; + + y_rest = icon_view->priv->height - icon_view->priv->nrows * CELL_SIZE; + y_spacing = (y_rest - MIN_MARGIN * 2) / (icon_view->priv->nrows - 1); + y_margin = (y_rest - (icon_view->priv->nrows - 1) * y_spacing) / 2; + + fake_area.x = x_margin + icon_view->priv->xorigin + col * CELL_SIZE + col * x_spacing; + fake_area.y = y_margin + icon_view->priv->yorigin + row * CELL_SIZE + row * y_spacing; fake_area.width = fake_area.height = CELL_SIZE; + xfdesktop_icon_view_paint_icon(icon_view, icon, &fake_area); } -- 1.9.3