[libwnck] Add wrap-on-scroll option for WnckPager widget
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libwnck] Add wrap-on-scroll option for WnckPager widget
- Date: Wed, 26 Apr 2017 03:21:36 +0000 (UTC)
commit 5e4c04a671eae5bd12e0f5fb40d79b6ab64bffba
Author: Moritz Bruder <muesli4 gmail com>
Date: Thu Mar 23 22:08:36 2017 +0100
Add wrap-on-scroll option for WnckPager widget
This commit is a minor and optional enhancement of the WnckPager
widget.
It allows to scroll over the borders of workspace boundaries.
This behavior, which is disabled by default, might be enabled with
wnck_pager_set_wrap_on_scroll. When activated, a scroll event which
would otherwise do nothing, i.e. over the border, will now scroll from
the first to the last workspace and from the last to the first. With
this option disabled the behavior is exactly the same as before.
https://bugzilla.gnome.org/show_bug.cgi?id=780490
libwnck/pager.c | 86 +++++++++++++++++++++++++++++++++++++++++++++----
libwnck/pager.h | 31 ++++++++++--------
libwnck/test-pager.c | 14 +++++---
3 files changed, 105 insertions(+), 26 deletions(-)
---
diff --git a/libwnck/pager.c b/libwnck/pager.c
index 96e3b77..20bf2da 100644
--- a/libwnck/pager.c
+++ b/libwnck/pager.c
@@ -67,6 +67,7 @@ struct _WnckPagerPrivate
WnckPagerDisplayMode display_mode;
gboolean show_all_workspaces;
GtkShadowType shadow_type;
+ gboolean wrap_on_scroll;
GtkOrientation orientation;
int workspace_size;
@@ -217,6 +218,7 @@ wnck_pager_init (WnckPager *pager)
pager->priv->display_mode = WNCK_PAGER_DISPLAY_CONTENT;
pager->priv->show_all_workspaces = TRUE;
pager->priv->shadow_type = GTK_SHADOW_NONE;
+ pager->priv->wrap_on_scroll = FALSE;
pager->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
pager->priv->workspace_size = 48;
@@ -2027,6 +2029,7 @@ wnck_pager_scroll_event (GtkWidget *widget,
int n_workspaces;
int n_columns;
int in_last_row;
+ gboolean wrap_workspaces;
gdouble smooth_x;
gdouble smooth_y;
@@ -2047,6 +2050,7 @@ wnck_pager_scroll_event (GtkWidget *widget,
if (n_workspaces % pager->priv->n_rows != 0)
n_columns++;
in_last_row = n_workspaces % n_columns;
+ wrap_workspaces = pager->priv->wrap_on_scroll;
if (gtk_widget_get_direction (GTK_WIDGET (pager)) == GTK_TEXT_DIR_RTL)
{
@@ -2075,31 +2079,62 @@ wnck_pager_scroll_event (GtkWidget *widget,
{
case GDK_SCROLL_DOWN:
if (index + n_columns < n_workspaces)
- index += n_columns;
+ {
+ index += n_columns;
+ }
+ else if (wrap_workspaces && index == n_workspaces - 1)
+ {
+ index = 0;
+ }
else if ((index < n_workspaces - 1 &&
index + in_last_row != n_workspaces - 1) ||
(index == n_workspaces - 1 &&
in_last_row != 0))
- index = (index % n_columns) + 1;
+ {
+ index = (index % n_columns) + 1;
+ }
break;
case GDK_SCROLL_RIGHT:
if (index < n_workspaces - 1)
- index++;
+ {
+ index++;
+ }
+ else if (wrap_workspaces)
+ {
+ index = 0;
+ }
break;
case GDK_SCROLL_UP:
if (index - n_columns >= 0)
- index -= n_columns;
+ {
+ index -= n_columns;
+ }
else if (index > 0)
- index = ((pager->priv->n_rows - 1) * n_columns) + (index % n_columns) - 1;
+ {
+ index = ((pager->priv->n_rows - 1) * n_columns) + (index % n_columns) - 1;
+ }
+ else if (wrap_workspaces)
+ {
+ index = n_workspaces - 1;
+ }
+
if (index >= n_workspaces)
- index -= n_columns;
+ {
+ index -= n_columns;
+ }
break;
case GDK_SCROLL_LEFT:
if (index > 0)
- index--;
+ {
+ index--;
+ }
+ else if (wrap_workspaces)
+ {
+ index = n_workspaces - 1;
+ }
break;
default:
g_assert_not_reached ();
@@ -2403,6 +2438,43 @@ wnck_pager_set_shadow_type (WnckPager * pager,
gtk_widget_queue_resize (GTK_WIDGET (pager));
}
+/**
+ * wnck_pager_set_wrap_on_scroll:
+ * @pager: a #WnckPager.
+ * @wrap_on_scroll: a boolean.
+ *
+ * Sets the wrapping behavior of the @pager. Setting it to %TRUE will
+ * wrap arround to the start when scrolling over the end and vice
+ * versa. By default it is set to %FALSE.
+ *
+ * Since: 3.20.2
+ */
+void
+wnck_pager_set_wrap_on_scroll (WnckPager *pager,
+ gboolean wrap_on_scroll)
+{
+ g_return_if_fail (WNCK_IS_PAGER (pager));
+
+ pager->priv->wrap_on_scroll = wrap_on_scroll;
+}
+
+/**
+ * wnck_pager_get_wrap_on_scroll:
+ * @pager: a #WnckPager.
+ *
+ * Return value: %TRUE if the @pager wraps workspaces on a scroll event that
+ * hits a border, %FALSE otherwise.
+ *
+ * Since: 3.20.2
+ */
+gboolean
+wnck_pager_get_wrap_on_scroll (WnckPager *pager)
+{
+ g_return_val_if_fail (WNCK_IS_PAGER (pager), FALSE);
+
+ return pager->priv->wrap_on_scroll;
+}
+
static void
active_window_changed_callback (WnckScreen *screen,
WnckWindow *previous_window,
diff --git a/libwnck/pager.h b/libwnck/pager.h
index 4ff6f01..5a43d05 100644
--- a/libwnck/pager.h
+++ b/libwnck/pager.h
@@ -80,20 +80,23 @@ typedef enum {
WNCK_PAGER_DISPLAY_CONTENT
} WnckPagerDisplayMode;
-GType wnck_pager_get_type (void) G_GNUC_CONST;
-
-GtkWidget* wnck_pager_new (void);
-
-gboolean wnck_pager_set_orientation (WnckPager *pager,
- GtkOrientation orientation);
-gboolean wnck_pager_set_n_rows (WnckPager *pager,
- int n_rows);
-void wnck_pager_set_display_mode (WnckPager *pager,
- WnckPagerDisplayMode mode);
-void wnck_pager_set_show_all (WnckPager *pager,
- gboolean show_all_workspaces);
-void wnck_pager_set_shadow_type (WnckPager *pager,
- GtkShadowType shadow_type);
+GType wnck_pager_get_type (void) G_GNUC_CONST;
+
+GtkWidget* wnck_pager_new (void);
+
+gboolean wnck_pager_set_orientation (WnckPager *pager,
+ GtkOrientation orientation);
+gboolean wnck_pager_set_n_rows (WnckPager *pager,
+ int n_rows);
+void wnck_pager_set_display_mode (WnckPager *pager,
+ WnckPagerDisplayMode mode);
+void wnck_pager_set_show_all (WnckPager *pager,
+ gboolean show_all_workspaces);
+void wnck_pager_set_shadow_type (WnckPager *pager,
+ GtkShadowType shadow_type);
+void wnck_pager_set_wrap_on_scroll (WnckPager *pager,
+ gboolean wrap_on_scroll);
+gboolean wnck_pager_get_wrap_on_scroll (WnckPager *pager);
G_END_DECLS
diff --git a/libwnck/test-pager.c b/libwnck/test-pager.c
index 5977d88..7e3a7a0 100644
--- a/libwnck/test-pager.c
+++ b/libwnck/test-pager.c
@@ -8,6 +8,7 @@ static gboolean only_current = FALSE;
static gboolean rtl = FALSE;
static gboolean show_name = FALSE;
static gboolean vertical = FALSE;
+static gboolean wrap_on_scroll = FALSE;
static GOptionEntry entries[] = {
{"n-rows", 'n', 0, G_OPTION_ARG_INT, &n_rows, "Use N_ROWS rows", "N_ROWS"},
@@ -15,14 +16,16 @@ static GOptionEntry entries[] = {
{"rtl", 'r', 0, G_OPTION_ARG_NONE, &rtl, "Use RTL as default direction", NULL},
{"show-name", 's', 0, G_OPTION_ARG_NONE, &show_name, "Show workspace names instead of workspace
contents", NULL},
{"vertical-orientation", 'v', 0, G_OPTION_ARG_NONE, &vertical, "Use a vertical orientation", NULL},
+ {"wrap-on-scroll", 'w', 0, G_OPTION_ARG_NONE, &wrap_on_scroll, "Wrap on scrolling over borders",
NULL},
{NULL }
};
static void
-create_pager_window (GtkOrientation orientation,
- gboolean show_all,
- WnckPagerDisplayMode mode,
- int n_rows)
+create_pager_window (GtkOrientation orientation,
+ gboolean show_all,
+ WnckPagerDisplayMode mode,
+ int n_rows,
+ gboolean wrap_on_scroll)
{
GtkWidget *win;
GtkWidget *pager;
@@ -51,6 +54,7 @@ create_pager_window (GtkOrientation orientation,
wnck_pager_set_orientation (WNCK_PAGER (pager), orientation);
wnck_pager_set_n_rows (WNCK_PAGER (pager), n_rows);
wnck_pager_set_shadow_type (WNCK_PAGER (pager), GTK_SHADOW_IN);
+ wnck_pager_set_wrap_on_scroll (WNCK_PAGER (pager), wrap_on_scroll);
gtk_container_add (GTK_CONTAINER (win), pager);
@@ -92,7 +96,7 @@ main (int argc, char **argv)
else
mode = WNCK_PAGER_DISPLAY_CONTENT;
- create_pager_window (orientation, !only_current, mode, n_rows);
+ create_pager_window (orientation, !only_current, mode, n_rows, wrap_on_scroll);
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]