summaryrefslogtreecommitdiff
path: root/libmdock
diff options
context:
space:
mode:
Diffstat (limited to 'libmdock')
-rw-r--r--libmdock/com.javispedro.mdock.widget.gschema.xml4
-rw-r--r--libmdock/mdock-item.c23
-rw-r--r--libmdock/mdock-widget.c51
3 files changed, 33 insertions, 45 deletions
diff --git a/libmdock/com.javispedro.mdock.widget.gschema.xml b/libmdock/com.javispedro.mdock.widget.gschema.xml
index 103a94d..812f0e7 100644
--- a/libmdock/com.javispedro.mdock.widget.gschema.xml
+++ b/libmdock/com.javispedro.mdock.widget.gschema.xml
@@ -5,9 +5,5 @@
<default>[]</default>
<summary>Items in the dock</summary>
</key>
- <key name="icon-size" type="u">
- <default>48</default>
- <summary>Icon size</summary>
- </key>
</schema>
</schemalist>
diff --git a/libmdock/mdock-item.c b/libmdock/mdock-item.c
index 67d3638..2dd1611 100644
--- a/libmdock/mdock-item.c
+++ b/libmdock/mdock-item.c
@@ -21,6 +21,8 @@
#define MDOCK_ITEM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), MDOCK_TYPE_ITEM, MDockItemPrivate))
+#define REQUISITION_ICON_SIZE 32
+
struct _MDockItemPrivate
{
gboolean pinned;
@@ -38,7 +40,6 @@ enum {
PROP_0,
PROP_PINNED,
PROP_DESKTOP_APP_INFO,
- PROP_ICON_SIZE,
PROP_N_WINDOWS,
PROP_DISPLAY_NAME,
N_PROPERTIES
@@ -107,13 +108,14 @@ static void mdock_item_realize(GtkWidget *widget)
static void mdock_item_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
MDockItem *self = MDOCK_ITEM(widget);
- requisition->width = requisition->height = self->priv->icon_size;
+ requisition->width = requisition->height = REQUISITION_ICON_SIZE;
}
static void mdock_item_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
MDockItem *self = MDOCK_ITEM(widget);
- allocation->width = allocation->height = self->priv->icon_size;
+ self->priv->icon_size = MIN(allocation->width, allocation->height);
+ mdock_item_update_icon(self);
GTK_WIDGET_CLASS(mdock_item_parent_class)->size_allocate(widget, allocation);
}
@@ -146,11 +148,6 @@ static void mdock_item_set_property(GObject *object,
self->priv->appinfo = g_value_dup_object(value);
mdock_item_update_icon(self);
break;
- case PROP_ICON_SIZE:
- self->priv->icon_size = g_value_get_uint(value);
- gtk_widget_queue_resize(GTK_WIDGET(self));
- mdock_item_update_icon(self);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -170,9 +167,6 @@ static void mdock_item_get_property(GObject *object,
case PROP_DESKTOP_APP_INFO:
g_value_set_object(value, self->priv->appinfo);
break;
- case PROP_ICON_SIZE:
- g_value_set_uint(value, self->priv->icon_size);
- break;
case PROP_N_WINDOWS:
g_value_set_uint(value, g_list_length(self->priv->windows));
break;
@@ -237,13 +231,6 @@ mdock_item_class_init(MDockItemClass *klass)
G_TYPE_DESKTOP_APP_INFO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- obj_properties[PROP_ICON_SIZE] = g_param_spec_uint("icon-size",
- "Icon size",
- "Set the icon size",
- 16, 256,
- 48,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
obj_properties[PROP_N_WINDOWS] = g_param_spec_uint("n-windows",
"Number of windows",
"Reads the current number of windows under this item",
diff --git a/libmdock/mdock-widget.c b/libmdock/mdock-widget.c
index 5b3daed..cdb942e 100644
--- a/libmdock/mdock-widget.c
+++ b/libmdock/mdock-widget.c
@@ -198,16 +198,16 @@ static void handle_item_pinned_changed(MDockWidget *self, GParamSpec *spec, MDoc
static gboolean handle_item_button_press(MDockWidget *self, GdkEventButton *event, MDockItem *item)
{
+ if (self->priv->popup_timer) {
+ g_source_remove(self->priv->popup_timer);
+ self->priv->popup_timer = 0;
+ }
+ if (self->priv->current_popup_item) {
+ hide_item_popup(self);
+ }
+
switch (event->button) {
case 3:
- if (self->priv->popup_timer) {
- g_source_remove(self->priv->popup_timer);
- self->priv->popup_timer = 0;
- }
- if (self->priv->current_popup_item) {
- hide_item_popup(self);
- }
-
gtk_menu_popup(GTK_MENU(g_object_get_qdata(G_OBJECT(item), mdock_widget_item_menu_quark())),
NULL, NULL, NULL, NULL, event->button, event->time);
@@ -276,16 +276,25 @@ static void handle_item_drag_data_delete(MDockWidget *self, GdkDragContext *dc,
g_debug("data delete");
}
-static GSequenceIter * find_drop_position_at_coordinates(MDockWidget *self, gint x, gint y)
+static GSequenceIter * find_drop_position_at_coordinates(MDockWidget *self, gint x, gint y, gboolean moving)
{
- const guint icon_size = g_settings_get_uint(self->priv->settings, "icon-size");
- const guint spacing = gtk_box_get_spacing(GTK_BOX(self));
- const guint offset = icon_size / 4;
- if (gtk_orientable_get_orientation(GTK_ORIENTABLE(self)) == GTK_ORIENTATION_HORIZONTAL) {
- g_debug("dropped in position %d", x / icon_size);
- return g_sequence_get_iter_at_pos(self->priv->items, (x + offset) / (icon_size + spacing)) ;
+ GtkOrientation orientation = gtk_orientable_get_orientation(GTK_ORIENTABLE(self));
+ gint nitems = g_sequence_get_length(self->priv->items) - (moving ? 1 : 0);
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(GTK_WIDGET(self), &allocation);
+ const gint major_length = orientation == GTK_ORIENTATION_HORIZONTAL ? allocation.width : allocation.height;
+
+ if (nitems == 0) {
+ return g_sequence_get_begin_iter(self->priv->items);
+ }
+
+ const gint item_size = major_length / nitems;
+ const guint offset = item_size / 3;
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ return g_sequence_get_iter_at_pos(self->priv->items, (x + offset) / item_size);
} else {
- return g_sequence_get_iter_at_pos(self->priv->items, (y + offset) / (icon_size + spacing));
+ return g_sequence_get_iter_at_pos(self->priv->items, (y + offset) / item_size);
}
}
@@ -306,7 +315,7 @@ static void mdock_widget_drag_data_received(GtkWidget *widget, GdkDragContext *c
g_debug("Got position %u", position);
GSequenceIter *iter = g_sequence_get_iter_at_pos(self->priv->items, position);
g_warn_if_fail(iter);
- GSequenceIter *pos_iter = find_drop_position_at_coordinates(self, x, y);
+ GSequenceIter *pos_iter = find_drop_position_at_coordinates(self, x, y, TRUE);
move_item_to_position(self, iter, pos_iter);
if (mdock_item_get_pinned(MDOCK_ITEM(g_sequence_get(iter)))) {
save_items_to_settings(self);
@@ -473,10 +482,6 @@ static void connect_item(MDockWidget *self, MDockItem *item, GSequenceIter *posi
G_CALLBACK(handle_item_pinned_changed), self,
G_CONNECT_SWAPPED);
- g_settings_bind(self->priv->settings, "icon-size",
- item, "icon-size",
- G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
-
gtk_drag_source_set(GTK_WIDGET(item), GDK_BUTTON1_MASK,
drag_types, G_N_ELEMENTS(drag_types),
GDK_ACTION_MOVE);
@@ -559,7 +564,7 @@ static void reload_items_from_settings(MDockWidget *self)
connect_item(self, item, iter);
gtk_widget_show(GTK_WIDGET(item));
- gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(item), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(item), TRUE, TRUE, 0);
if (!g_sequence_iter_is_end(seq_iter)) {
// Fix the order!
gtk_box_reorder_child(GTK_BOX(self), GTK_WIDGET(item),
@@ -667,7 +672,7 @@ static void handle_window_opened(MDockWidget *self, WnckWindow *window, WnckScre
g_hash_table_insert(self->priv->window_to_item, window, iter);
gtk_widget_show(GTK_WIDGET(item));
- gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(item), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(item), TRUE, TRUE, 0);
}
static void handle_settings_items_changed(MDockWidget *self, gchar *key, GSettings *settings)