[gnome-applets/wip/segeiger/height-for-width: 3/7] TaskItem: Implement width_for_height mode
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets/wip/segeiger/height-for-width: 3/7] TaskItem: Implement width_for_height mode
- Date: Tue, 14 Jul 2015 15:58:13 +0000 (UTC)
commit db61dde42e610934ec99ee7ce83a2af7a20eecd2
Author: Sebastian Geiger <sbastig gmx net>
Date: Thu Jun 11 00:51:02 2015 +0200
TaskItem: Implement width_for_height mode
Use height_for_width mode in vertical orientation.
This requires PANEL_APPLET_EXPAND_MAJOR to work correctly. With that flag, the panel
will expand to maximum size and the containers pass the available space to their children.
windowpicker/src/task-item.c | 111 +++++++++++++++++++++++++++++++++---------
1 files changed, 87 insertions(+), 24 deletions(-)
---
diff --git a/windowpicker/src/task-item.c b/windowpicker/src/task-item.c
index e03ca0d..fb6756e 100644
--- a/windowpicker/src/task-item.c
+++ b/windowpicker/src/task-item.c
@@ -182,14 +182,27 @@ static void task_item_set_visibility (TaskItem *item) {
}
}
+static GtkSizeRequestMode
+task_item_get_request_mode (GtkWidget* widget);
+
static void
task_item_get_preferred_width (GtkWidget *widget,
gint *minimal_width,
gint *natural_width)
{
- GtkRequisition requisition;
- requisition.width = DEFAULT_TASK_ITEM_WIDTH;
- *minimal_width = *natural_width = requisition.width;
+ if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT) {
+ gint min_height;
+
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, &min_height, NULL);
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, min_height,
+ minimal_width, natural_width);
+ } else {
+ if (minimal_width)
+ *minimal_width = DEFAULT_TASK_ITEM_WIDTH;
+ if (natural_width)
+ *natural_width = DEFAULT_TASK_ITEM_WIDTH;
+ }
+
}
static void
@@ -197,9 +210,73 @@ task_item_get_preferred_height (GtkWidget *widget,
gint *minimal_height,
gint *natural_height)
{
- GtkRequisition requisition;
- requisition.height = DEFAULT_TASK_ITEM_HEIGHT;
- *minimal_height = *natural_height = requisition.height;
+ if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) {
+ gint min_width;
+
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
+ minimal_height, natural_height);
+ } else {
+ if (minimal_height)
+ *minimal_height = DEFAULT_TASK_ITEM_HEIGHT;
+ if (natural_height)
+ *natural_height = DEFAULT_TASK_ITEM_HEIGHT;
+ }
+}
+
+static GtkSizeRequestMode
+task_item_get_request_mode (GtkWidget* widget)
+{
+ WpApplet *applet = TASK_ITEM (widget)->priv->windowPickerApplet;
+ GtkOrientation orientation = panel_applet_get_gtk_orientation (PANEL_APPLET (applet));
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+ } else {
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+ }
+}
+
+static void
+task_item_get_preferred_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT) {
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
+ } else {
+ *minimum_height = *natural_height = width + 6;
+ }
+}
+
+static void
+task_item_get_preferred_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ if (task_item_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) {
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
+ } else {
+ *minimum_width = *natural_width = height + 6;
+ }
+}
+
+static void on_size_allocate (
+ GtkWidget *widget,
+ GtkAllocation *allocation,
+ WpApplet *applet)
+{
+ g_return_if_fail (TASK_IS_ITEM (widget));
+ TaskItem *item = TASK_ITEM (widget);
+ TaskItemPrivate *priv = item->priv;
+ priv->area.x = allocation->x;
+ priv->area.y = allocation->y;
+ priv->area.width = allocation->width;
+ priv->area.height = allocation->height;
+
+ update_hints (item);
}
static GdkPixbuf *task_item_sized_pixbuf_for_window (
@@ -347,23 +424,6 @@ static gboolean task_item_draw (
return FALSE;
}
-static void on_size_allocate (
- GtkWidget *widget,
- GtkAllocation *allocation,
- TaskItem *item)
-{
- g_return_if_fail (TASK_IS_ITEM (item));
- TaskItemPrivate *priv;
- if (allocation->width != allocation->height + 6)
- gtk_widget_set_size_request (widget, allocation->height + 6, -1);
- priv = item->priv;
- priv->area.x = allocation->x;
- priv->area.y = allocation->y;
- priv->area.width = allocation->width;
- priv->area.height = allocation->height;
- update_hints (item);
-}
-
static gboolean on_button_pressed (
GtkWidget *button,
GdkEventButton *event,
@@ -753,6 +813,9 @@ static void task_item_class_init (TaskItemClass *klass) {
obj_class->finalize = task_item_finalize;
widget_class->get_preferred_width = task_item_get_preferred_width;
widget_class->get_preferred_height = task_item_get_preferred_height;
+ widget_class->get_request_mode = task_item_get_request_mode;
+ widget_class->get_preferred_height_for_width = task_item_get_preferred_height_for_width;
+ widget_class->get_preferred_width_for_height = task_item_get_preferred_width_for_height;
g_type_class_add_private (obj_class, sizeof (TaskItemPrivate));
task_item_signals [TASK_ITEM_CLOSED_SIGNAL] =
g_signal_new ("task-item-closed",
@@ -854,7 +917,7 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
g_signal_connect (item, "button-press-event",
G_CALLBACK (on_button_pressed), item);
g_signal_connect (item, "size-allocate",
- G_CALLBACK (on_size_allocate), item);
+ G_CALLBACK (on_size_allocate), windowPickerApplet);
g_signal_connect (item, "query-tooltip",
G_CALLBACK (on_query_tooltip), item);
g_signal_connect (item, "enter-notify-event",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]