[libwnck/wip/muktupavels/pager: 2/2] pager: add wnck_pager_set_workspace_size
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libwnck/wip/muktupavels/pager: 2/2] pager: add wnck_pager_set_workspace_size
- Date: Fri, 30 Apr 2021 21:41:07 +0000 (UTC)
commit 9a5c9b51b327d9daf6c42310f2ff95c988f535ba
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sat May 1 00:24:00 2021 +0300
pager: add wnck_pager_set_workspace_size
It should be enough to have only minimum size like it was before
a414519d7b45 commit. Widget should request minimum size it needs!
Using allocated size is wrong as it means widgets will get only
bigger. To reduce size container will need to underallocate
widget and GTK will warn about that if consistency checks are
enabled.
libwnck/pager.c | 82 ++++++++++++++++-----------------------------------------
libwnck/pager.h | 3 +++
2 files changed, 26 insertions(+), 59 deletions(-)
---
diff --git a/libwnck/pager.c b/libwnck/pager.c
index a563a4d..a24646a 100644
--- a/libwnck/pager.c
+++ b/libwnck/pager.c
@@ -122,8 +122,6 @@ static void wnck_pager_get_preferred_height_for_width (GtkWidget *widget,
int width,
int *minimum_height,
int *natural_height);
-static void wnck_pager_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
static gboolean wnck_pager_draw (GtkWidget *widget,
cairo_t *cr);
static gboolean wnck_pager_button_press (GtkWidget *widget,
@@ -249,7 +247,6 @@ wnck_pager_class_init (WnckPagerClass *klass)
widget_class->get_preferred_width_for_height = wnck_pager_get_preferred_width_for_height;
widget_class->get_preferred_height = wnck_pager_get_preferred_height;
widget_class->get_preferred_height_for_width = wnck_pager_get_preferred_height_for_width;
- widget_class->size_allocate = wnck_pager_size_allocate;
widget_class->draw = wnck_pager_draw;
widget_class->button_press_event = wnck_pager_button_press;
widget_class->button_release_event = wnck_pager_button_release;
@@ -687,62 +684,6 @@ wnck_pager_get_preferred_height_for_width (GtkWidget *widget,
*natural_height = *minimum_height = MAX (height, 0);
}
-static gboolean
-_wnck_pager_queue_resize (gpointer data)
-{
- gtk_widget_queue_resize (GTK_WIDGET (data));
- return FALSE;
-}
-
-static void
-wnck_pager_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- WnckPager *pager;
- int workspace_size;
- GtkBorder padding;
- int width;
- int height;
-
- pager = WNCK_PAGER (widget);
-
- width = allocation->width;
- height = allocation->height;
-
- _wnck_pager_get_padding (pager, &padding);
- width -= padding.left + padding.right;
- height -= padding.top + padding.bottom;
-
- g_assert (pager->priv->n_rows > 0);
-
- if (pager->priv->orientation == GTK_ORIENTATION_VERTICAL)
- {
- if (pager->priv->show_all_workspaces)
- workspace_size = (width - (pager->priv->n_rows - 1)) / pager->priv->n_rows;
- else
- workspace_size = width;
- }
- else
- {
- if (pager->priv->show_all_workspaces)
- workspace_size = (height - (pager->priv->n_rows - 1))/ pager->priv->n_rows;
- else
- workspace_size = height;
- }
-
- workspace_size = MAX (workspace_size, 1);
-
- if (workspace_size != pager->priv->workspace_size)
- {
- pager->priv->workspace_size = workspace_size;
- g_idle_add (_wnck_pager_queue_resize, pager);
- return;
- }
-
- GTK_WIDGET_CLASS (wnck_pager_parent_class)->size_allocate (widget,
- allocation);
-}
-
static void
get_workspace_rect (WnckPager *pager,
int space,
@@ -2536,6 +2477,29 @@ wnck_pager_get_wrap_on_scroll (WnckPager *pager)
return pager->priv->wrap_on_scroll;
}
+/**
+ * wnck_pager_set_workspace_size:
+ * @pager: a #WnckPager.
+ * @workspace_size: workspace size.
+ *
+ * Sets wrokspace size.
+ *
+ * Since: 3.36
+ */
+void
+wnck_pager_set_workspace_size (WnckPager *pager,
+ int workspace_size)
+{
+ g_return_if_fail (WNCK_IS_PAGER (pager));
+
+ if (pager->priv->workspace_size == workspace_size)
+ return;
+
+ pager->priv->workspace_size = workspace_size;
+
+ gtk_widget_queue_resize (GTK_WIDGET (pager));
+}
+
static void
active_window_changed_callback (WnckScreen *screen,
WnckWindow *previous_window,
diff --git a/libwnck/pager.h b/libwnck/pager.h
index c67f2fa..8b85b66 100644
--- a/libwnck/pager.h
+++ b/libwnck/pager.h
@@ -120,6 +120,9 @@ void wnck_pager_set_wrap_on_scroll (WnckPager *pager,
gboolean wrap_on_scroll);
gboolean wnck_pager_get_wrap_on_scroll (WnckPager *pager);
+void wnck_pager_set_workspace_size (WnckPager *pager,
+ int workspace_size);
+
G_END_DECLS
#endif /* WNCK_PAGER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]