Align the icons according to their size

This commit is contained in:
Pierre Pronchery 2018-10-26 15:26:49 -03:00
parent fee4a34ca4
commit e7622a3c44
4 changed files with 29 additions and 9 deletions

View File

@ -759,16 +759,18 @@ static void _alignment_horizontal(Desktop * desktop)
int x = desktop->workarea.x;
int y = desktop->workarea.y;
int width = x + desktop->workarea.width;
unsigned int wsize = desktop->icons_size * 2;
unsigned int hsize = wsize;
for(i = 0; i < desktop->icons_cnt; i++)
{
if(x + DESKTOPICON_WIDTH > width)
if(x + wsize > width)
{
y += DESKTOPICON_HEIGHT;
y += hsize;
x = desktop->workarea.x;
}
desktopiconwindow_move(desktop->icons[i], x, y);
x += DESKTOPICON_WIDTH;
x += wsize;
}
}
@ -778,16 +780,18 @@ static void _alignment_vertical(Desktop * desktop)
int x = desktop->workarea.x;
int y = desktop->workarea.y;
int height = desktop->workarea.y + desktop->workarea.height;
unsigned int wsize = desktop->icons_size * 2;
unsigned int hsize = wsize;
for(i = 0; i < desktop->icons_cnt; i++)
{
if(y + DESKTOPICON_HEIGHT > height)
if(y + hsize > height)
{
x += DESKTOPICON_WIDTH;
x += wsize;
y = desktop->workarea.y;
}
desktopiconwindow_move(desktop->icons[i], x, y);
y += DESKTOPICON_HEIGHT;
y += hsize;
}
}

View File

@ -407,6 +407,13 @@ gboolean desktopicon_get_first(DesktopIcon * desktopicon)
}
/* desktopicon_get_height */
unsigned int desktopicon_get_height(DesktopIcon * desktopicon)
{
return desktop_get_icons_size(desktopicon->desktop) * 2;
}
/* desktopicon_get_immutable */
gboolean desktopicon_get_immutable(DesktopIcon * desktopicon)
{
@ -456,6 +463,13 @@ GtkWidget * desktopicon_get_widget(DesktopIcon * desktopicon)
}
/* desktopicon_get_width */
unsigned int desktopicon_get_width(DesktopIcon * desktopicon)
{
return desktopicon_get_height(desktopicon);
}
/* desktopicon_set_background */
#if GTK_CHECK_VERSION(3, 0, 0)
void desktopicon_set_background(DesktopIcon * desktopicon, GdkRGBA * color)

View File

@ -39,8 +39,6 @@ typedef void (*DesktopIconCallback)(Desktop * desktop, gpointer data);
/* constants */
#define DESKTOPICON_ICON_SIZE 48
#define DESKTOPICON_HEIGHT (DESKTOPICON_ICON_SIZE << 1)
#define DESKTOPICON_WIDTH (DESKTOPICON_ICON_SIZE << 1)
/* functions */
@ -54,6 +52,7 @@ void desktopicon_delete(DesktopIcon * desktopicon);
/* accessors */
gboolean desktopicon_get_first(DesktopIcon * desktopicon);
unsigned int desktopicon_get_height(DesktopIcon * desktopicon);
GtkWidget * desktopicon_get_image(DesktopIcon * desktopicon);
gboolean desktopicon_get_immutable(DesktopIcon * desktopicon);
gboolean desktopicon_get_isdir(DesktopIcon * desktopicon);
@ -63,6 +62,7 @@ char const * desktopicon_get_path(DesktopIcon * desktopicon);
gboolean desktopicon_get_selected(DesktopIcon * desktopicon);
gboolean desktopicon_get_updated(DesktopIcon * desktopicon);
GtkWidget * desktopicon_get_widget(DesktopIcon * desktopicon);
unsigned int desktopicon_get_width(DesktopIcon * desktopicon);
# if GTK_CHECK_VERSION(3, 0, 0)
void desktopicon_set_background(DesktopIcon * desktopicon, GdkRGBA * color);

View File

@ -56,6 +56,7 @@ DesktopIconWindow * desktopiconwindow_new(DesktopIcon * icon)
DesktopIconWindow * window;
GtkWindow * w;
GtkWidget * widget;
unsigned int size;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%p)\n", __func__, icon);
@ -76,7 +77,8 @@ DesktopIconWindow * desktopiconwindow_new(DesktopIcon * icon)
#else
gtk_window_set_type_hint(w, GDK_WINDOW_TYPE_HINT_DOCK);
#endif
gtk_window_set_default_size(w, DESKTOPICON_WIDTH, DESKTOPICON_HEIGHT);
gtk_window_set_default_size(w, desktopicon_get_width(icon),
desktopicon_get_height(icon));
g_signal_connect(window->widget, "delete-event", G_CALLBACK(
_on_desktopiconwindow_closex), NULL);
/* icon */