[gnome-applets/window-picker-size] window-picker: fix size-allocation issues
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets/window-picker-size] window-picker: fix size-allocation issues
- Date: Sun, 22 Mar 2020 21:40:07 +0000 (UTC)
commit dfa891136b630b98739785df06b345261abec2ab
Author: Sebastian Geiger <sbastig gmx net>
Date: Sun Mar 22 21:48:41 2020 +0100
window-picker: fix size-allocation issues
Widgets should not call gtk_widget_set_size_request in the size-allocate
callback. This commit adds height-for-width/width-for-height management
to the TaskItem to correctly set the required size of the TaskItem.
We also add handling of the "placement-changed" signal in the TaskItem
to handle changes in the applet orientation.
To avoid clipping of the Tasklist we also update the size_hints of the
applet. Without this TaskItems will have the correct size, but TaskList
will be clipped.
Co-authored-by: Alberts Muktupāvels <alberts muktupavels gmail com>
window-picker/src/task-item.c | 85 ++++++++++++++++++++++++++++++++++++++-----
window-picker/src/wp-applet.c | 4 +-
2 files changed, 78 insertions(+), 11 deletions(-)
---
diff --git a/window-picker/src/task-item.c b/window-picker/src/task-item.c
index c9a802491..b9f0db830 100644
--- a/window-picker/src/task-item.c
+++ b/window-picker/src/task-item.c
@@ -77,6 +77,35 @@ static const gint n_drag_types = G_N_ELEMENTS(drag_types);
static void task_item_close (TaskItem *item);
+static void
+update_expand (TaskItem *self,
+ GtkOrientation orientation)
+{
+ GtkWidget *widget;
+
+ widget = GTK_WIDGET (self);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_widget_set_hexpand (widget, FALSE);
+ gtk_widget_set_vexpand (widget, TRUE);
+ }
+ else
+ {
+ gtk_widget_set_hexpand (widget, TRUE);
+ gtk_widget_set_vexpand (widget, FALSE);
+ }
+}
+
+static void
+placement_changed_cb (GpApplet *applet,
+ GtkOrientation orientation,
+ GtkPositionType position,
+ TaskItem *self)
+{
+ update_expand (self, orientation);
+}
+
static void
update_hints (TaskItem *item)
{
@@ -183,14 +212,34 @@ task_item_set_visibility (TaskItem *item)
}
}
+static GtkSizeRequestMode
+task_item_get_request_mode (GtkWidget *widget)
+{
+ TaskItem *self;
+
+ self = TASK_ITEM (widget);
+
+ if (gp_applet_get_orientation (self->windowPickerApplet) == GTK_ORIENTATION_HORIZONTAL)
+ return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+ else
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
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;
+ *minimal_width = *natural_width = DEFAULT_TASK_ITEM_WIDTH;
+}
+
+static void
+task_item_get_preferred_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ *minimal_width = *natural_width = height + 6;
}
static void
@@ -198,9 +247,16 @@ 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;
+ *minimal_height = *natural_height = DEFAULT_TASK_ITEM_HEIGHT;
+}
+
+static void
+task_item_get_preferred_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ *minimal_height = *natural_height = width + 6;
}
static GdkPixbuf *
@@ -381,8 +437,7 @@ static void on_size_allocate (
TaskItem *item)
{
g_return_if_fail (TASK_IS_ITEM (item));
- if (allocation->width != allocation->height + 6)
- gtk_widget_set_size_request (widget, allocation->height + 6, -1);
+
item->area.x = allocation->x;
item->area.y = allocation->y;
item->area.width = allocation->width;
@@ -929,8 +984,12 @@ static void task_item_class_init (TaskItemClass *klass) {
obj_class->finalize = task_item_finalize;
+ widget_class->get_request_mode = task_item_get_request_mode;
widget_class->get_preferred_width = task_item_get_preferred_width;
+ widget_class->get_preferred_width_for_height = task_item_get_preferred_width_for_height;
widget_class->get_preferred_height = task_item_get_preferred_height;
+ widget_class->get_preferred_height_for_width = task_item_get_preferred_height_for_width;
+
task_item_signals [TASK_ITEM_CLOSED_SIGNAL] =
g_signal_new ("task-item-closed",
G_TYPE_FROM_CLASS (klass),
@@ -962,7 +1021,6 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
"above-child", TRUE,
NULL
);
- gtk_widget_set_vexpand(item, TRUE);
gtk_widget_add_events (item, GDK_ALL_EVENTS_MASK);
gtk_container_set_border_width (GTK_CONTAINER (item), 0);
taskItem = TASK_ITEM (item);
@@ -972,6 +1030,15 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
taskItem->windowPickerApplet = windowPickerApplet;
taskItem->monitor = get_window_monitor (window);
+ g_signal_connect_object (windowPickerApplet,
+ "placement-changed",
+ G_CALLBACK (placement_changed_cb),
+ taskItem,
+ 0);
+
+ update_expand (taskItem,
+ gp_applet_get_orientation (GP_APPLET (windowPickerApplet)));
+
/** Drag and Drop code
* This item can be both the target and the source of a drag and drop
* operation. As a target it can receive strings (e.g. links).
diff --git a/window-picker/src/wp-applet.c b/window-picker/src/wp-applet.c
index 33bc7629f..f30438ead 100644
--- a/window-picker/src/wp-applet.c
+++ b/window-picker/src/wp-applet.c
@@ -243,9 +243,9 @@ wp_applet_size_allocate (GtkWidget *widget,
orientation = gp_applet_get_orientation (panel_applet);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_preferred_width (applet->tasks, NULL, &size);
+ gtk_widget_get_preferred_width_for_height (applet->tasks, allocation->height, NULL, &size);
else
- gtk_widget_get_preferred_height (applet->tasks, NULL, &size);
+ gtk_widget_get_preferred_height_for_width (applet->tasks, allocation->width, NULL, &size);
size_hints[0] = size;
size_hints[1] = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]