diff options
Diffstat (limited to 'mate-applet')
-rw-r--r-- | mate-applet/mdock-mate-panel-applet.c | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/mate-applet/mdock-mate-panel-applet.c b/mate-applet/mdock-mate-panel-applet.c index 7079c27..ba18f43 100644 --- a/mate-applet/mdock-mate-panel-applet.c +++ b/mate-applet/mdock-mate-panel-applet.c @@ -51,36 +51,63 @@ static const GtkActionEntry menu_verbs[] = { G_CALLBACK (display_about_dialog) } }; -static gboolean transform_applet_orient_to_orientation(GBinding *binding, const GValue *from_value, GValue *to_value, gpointer user_data) +static inline GtkOrientation applet_orient_to_orientation(MatePanelAppletOrient orient) { - MatePanelAppletOrient orient = g_value_get_enum(from_value); switch (orient) { case MATE_PANEL_APPLET_ORIENT_DOWN: case MATE_PANEL_APPLET_ORIENT_UP: - g_value_set_enum(to_value, GTK_ORIENTATION_HORIZONTAL); - break; + return GTK_ORIENTATION_HORIZONTAL; case MATE_PANEL_APPLET_ORIENT_LEFT: case MATE_PANEL_APPLET_ORIENT_RIGHT: - g_value_set_enum(to_value, GTK_ORIENTATION_VERTICAL); - break; + return GTK_ORIENTATION_VERTICAL; + default: + g_return_val_if_reached(GTK_ORIENTATION_HORIZONTAL); } } +static gboolean transform_applet_orient_to_orientation(GBinding *binding, const GValue *from_value, GValue *to_value, gpointer user_data) +{ + MatePanelAppletOrient orient = g_value_get_uint(from_value); + g_value_set_enum(to_value, applet_orient_to_orientation(orient)); +} + +static GtkOrientation mdock_mate_panel_applet_get_orientation(MDockMatePanelApplet *self) +{ + MatePanelAppletOrient orient = mate_panel_applet_get_orient(MATE_PANEL_APPLET(self)); + return applet_orient_to_orientation(orient); +} + static void mdock_mate_panel_applet_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { MDockMatePanelApplet *self = MDOCK_MATE_PANEL_APPLET(widget); - if (self->dock) { - gtk_widget_size_allocate(GTK_WIDGET(self->dock), allocation); - } GTK_WIDGET_CLASS(mdock_mate_panel_applet_parent_class)->size_allocate(widget, allocation); + gtk_widget_size_allocate(GTK_WIDGET(self->dock), allocation); } static void mdock_mate_panel_applet_size_request(GtkWidget *widget, GtkRequisition *requisition) { MDockMatePanelApplet *self = MDOCK_MATE_PANEL_APPLET(widget); - if (self->dock) { - gtk_widget_size_request(GTK_WIDGET(self->dock), requisition); + gint nitems = mdock_widget_get_n_items(self->dock); + + gtk_widget_size_request(GTK_WIDGET(self->dock), requisition); + + g_debug("size request %dx%d", requisition->width, requisition->height); + + // Try to force a square aspect ratio for the icons + // by requesting a big enough major panel dimension + GtkAllocation allocation; + gtk_widget_get_allocation(GTK_WIDGET(self), &allocation); + gint spacing = gtk_box_get_spacing(GTK_BOX(self->dock)); + + if (mdock_mate_panel_applet_get_orientation(self) == GTK_ORIENTATION_HORIZONTAL) { + requisition->width = MAX(requisition->width, nitems * (allocation.height + spacing)); + requisition->height = MAX(requisition->height, allocation.height); + } else { + requisition->width = MAX(requisition->width, allocation.width); + requisition->height = MAX(requisition->height, nitems * (requisition->width + spacing)); } + + g_debug("size request %dx%d", requisition->width, requisition->height); } static void mdock_mate_panel_applet_class_init(MDockMatePanelAppletClass *klass) @@ -92,9 +119,20 @@ static void mdock_mate_panel_applet_class_init(MDockMatePanelAppletClass *klass) static void mdock_mate_panel_applet_init(MDockMatePanelApplet *self) { - self->dock = MDOCK_WIDGET(mdock_widget_new()); + MatePanelApplet *applet = MATE_PANEL_APPLET(self); + gchar *prefs_path = mate_panel_applet_get_preferences_path(applet); + + g_warn_if_fail(prefs_path); + + if (prefs_path) { + self->dock = MDOCK_WIDGET(mdock_widget_new_with_settings_path(prefs_path)); + } else { + self->dock = MDOCK_WIDGET(mdock_widget_new()); + } gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->dock)); + g_free(prefs_path); + g_object_bind_property_full(self, "orient", self->dock, "orientation", G_BINDING_DEFAULT, transform_applet_orient_to_orientation, @@ -104,12 +142,13 @@ static void mdock_mate_panel_applet_init(MDockMatePanelApplet *self) gtk_action_group_add_actions(action_group, menu_verbs, G_N_ELEMENTS(menu_verbs), self); - mate_panel_applet_set_flags(MATE_PANEL_APPLET(self), + mate_panel_applet_set_flags(applet, MATE_PANEL_APPLET_EXPAND_MINOR); - mate_panel_applet_setup_menu(MATE_PANEL_APPLET(self), + mate_panel_applet_setup_menu(applet, "<menuitem name=\"MDock Preferences Item\" action=\"MDockPreferences\"/>" "<menuitem name=\"MDock About Item\" action=\"MDockAbout\"/>", action_group); + mate_panel_applet_set_background_widget(applet, GTK_WIDGET(self)); g_object_unref(action_group); |