diff options
-rw-r--r-- | doc/libwnck-sections.txt | 2 | ||||
-rw-r--r-- | libwnck/pager.c | 180 | ||||
-rw-r--r-- | libwnck/pager.h | 18 | ||||
-rw-r--r-- | libwnck/test-pager.c | 12 |
4 files changed, 147 insertions, 65 deletions
diff --git a/doc/libwnck-sections.txt b/doc/libwnck-sections.txt index a4de2f6..6fb1139 100644 --- a/doc/libwnck-sections.txt +++ b/doc/libwnck-sections.txt @@ -244,6 +244,8 @@ wnck_pager_set_orientation wnck_pager_set_n_rows WnckPagerDisplayMode wnck_pager_set_display_mode +WnckPagerScrollMode +wnck_pager_set_scroll_mode wnck_pager_set_show_all wnck_pager_set_shadow_type <SUBSECTION Private> diff --git a/libwnck/pager.c b/libwnck/pager.c index a0921ae..f75bdd8 100644 --- a/libwnck/pager.c +++ b/libwnck/pager.c @@ -65,6 +65,7 @@ struct _WnckPagerPrivate int n_rows; /* really columns for vertical orientation */ WnckPagerDisplayMode display_mode; + WnckPagerScrollMode scroll_mode; gboolean show_all_workspaces; GtkShadowType shadow_type; gboolean wrap_on_scroll; @@ -212,6 +213,7 @@ wnck_pager_init (WnckPager *pager) pager->priv->n_rows = 1; pager->priv->display_mode = WNCK_PAGER_DISPLAY_CONTENT; + pager->priv->scroll_mode = WNCK_PAGER_SCROLL_2D; pager->priv->show_all_workspaces = TRUE; pager->priv->shadow_type = GTK_SHADOW_NONE; pager->priv->wrap_on_scroll = FALSE; @@ -2078,73 +2080,103 @@ wnck_pager_scroll_event (GtkWidget *widget, } } - switch (absolute_direction) + if (pager->priv->scroll_mode == WNCK_PAGER_SCROLL_2D) { - case GDK_SCROLL_DOWN: - if (index + n_columns < n_workspaces) - { - 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; - } - break; - - case GDK_SCROLL_RIGHT: - if (index < n_workspaces - 1) - { - index++; - } - else if (wrap_workspaces) - { - index = 0; - } - break; - - case GDK_SCROLL_UP: - if (index - n_columns >= 0) - { - index -= n_columns; - } - else if (index > 0) - { - 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; - } - break; - - case GDK_SCROLL_LEFT: - if (index > 0) - { - index--; - } - else if (wrap_workspaces) + switch (absolute_direction) + { + case GDK_SCROLL_DOWN: + if (index + n_columns < n_workspaces) + { + 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; + } + break; + case GDK_SCROLL_RIGHT: + if (index < n_workspaces - 1) + { + index++; + } + else if (wrap_workspaces) + { + index = 0; + } + break; + case GDK_SCROLL_UP: + if (index - n_columns >= 0) + { + index -= n_columns; + } + else if (index > 0) + { + 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; + } + break; + case GDK_SCROLL_LEFT: + if (index > 0) + { + index--; + } + else if (wrap_workspaces) + { + index = n_workspaces - 1; + } + break; + case GDK_SCROLL_SMOOTH: + default: + g_assert_not_reached (); + break; + } + } + else + { + switch (absolute_direction) { - index = n_workspaces - 1; + case GDK_SCROLL_UP: + case GDK_SCROLL_LEFT: + if (index > 0) + { + index--; + } + else if (wrap_workspaces) + { + index = n_workspaces - 1; + } + break; + case GDK_SCROLL_DOWN: + case GDK_SCROLL_RIGHT: + if (index < n_workspaces - 1) + { + index++; + } + else if (wrap_workspaces) + { + index = 0; + } + break; + case GDK_SCROLL_SMOOTH: + default: + g_assert_not_reached (); + break; } - break; - - case GDK_SCROLL_SMOOTH: - default: - g_assert_not_reached (); - break; - } + } space = wnck_screen_get_workspace (pager->priv->screen, index); wnck_workspace_activate (space, event->time); @@ -2397,6 +2429,26 @@ wnck_pager_set_display_mode (WnckPager *pager, } /** + * wnck_pager_set_scroll_mode: + * @pager: a #WnckPager. + * @scroll_mode: a scroll mode. + * + * Sets @pager to react to input device scrolling in one of the + * available scroll modes. + */ +void +wnck_pager_set_scroll_mode (WnckPager *pager, + WnckPagerScrollMode scroll_mode) +{ + g_return_if_fail (WNCK_IS_PAGER (pager)); + + if (pager->priv->scroll_mode == scroll_mode) + return; + + pager->priv->scroll_mode = scroll_mode; +} + +/** * wnck_pager_set_show_all: * @pager: a #WnckPager. * @show_all_workspaces: whether to display all #WnckWorkspace in @pager. diff --git a/libwnck/pager.h b/libwnck/pager.h index 5a43d05..aaa667c 100644 --- a/libwnck/pager.h +++ b/libwnck/pager.h @@ -80,6 +80,22 @@ typedef enum { WNCK_PAGER_DISPLAY_CONTENT } WnckPagerDisplayMode; +/** + * WnckPagerScrollMode: + * @WNCK_PAGER_SCROLL_2D: given that the workspaces are set up in multiple rows, + * scrolling on the #WnckPager will cycle through the workspaces as if on a + * 2-dimensional map. Example cycling order with 2 rows and 4 workspaces: 1 3 2 4. + * @WNCK_PAGER_SCROLL_1D: the #WnckPager will always cycle workspaces in a linear + * manner, irrespective of how many rows are configured. (Hint: Better for mice) + * Example cycling order with 2 rows and 4 workspaces: 1 2 3 4. + * + * Mode defining in which order scrolling on a #WnckPager will cycle through workspaces. + */ +typedef enum { + WNCK_PAGER_SCROLL_2D, + WNCK_PAGER_SCROLL_1D +} WnckPagerScrollMode; + GType wnck_pager_get_type (void) G_GNUC_CONST; GtkWidget* wnck_pager_new (void); @@ -90,6 +106,8 @@ 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_scroll_mode (WnckPager *pager, + WnckPagerScrollMode scroll_mode); void wnck_pager_set_show_all (WnckPager *pager, gboolean show_all_workspaces); void wnck_pager_set_shadow_type (WnckPager *pager, diff --git a/libwnck/test-pager.c b/libwnck/test-pager.c index 316b13a..d60b047 100644 --- a/libwnck/test-pager.c +++ b/libwnck/test-pager.c @@ -7,6 +7,7 @@ static int n_rows = 1; static gboolean only_current = FALSE; static gboolean rtl = FALSE; static gboolean show_name = FALSE; +static gboolean simple_scrolling = FALSE; static gboolean vertical = FALSE; static gboolean wrap_on_scroll = FALSE; @@ -15,6 +16,7 @@ static GOptionEntry entries[] = { {"only-current", 'c', 0, G_OPTION_ARG_NONE, &only_current, "Only show current workspace", NULL}, {"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}, + {"simple-scrolling", 'd', 0, G_OPTION_ARG_NONE, &simple_scrolling, "Use the simple 1d scroll mode", 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 } @@ -24,6 +26,7 @@ static void create_pager_window (GtkOrientation orientation, gboolean show_all, WnckPagerDisplayMode mode, + WnckPagerScrollMode scroll_mode, int rows, gboolean wrap) { @@ -51,6 +54,7 @@ create_pager_window (GtkOrientation orientation, wnck_pager_set_show_all (WNCK_PAGER (pager), show_all); wnck_pager_set_display_mode (WNCK_PAGER (pager), mode); + wnck_pager_set_scroll_mode (WNCK_PAGER (pager), scroll_mode); wnck_pager_set_orientation (WNCK_PAGER (pager), orientation); wnck_pager_set_n_rows (WNCK_PAGER (pager), rows); wnck_pager_set_shadow_type (WNCK_PAGER (pager), GTK_SHADOW_IN); @@ -67,6 +71,7 @@ main (int argc, char **argv) GOptionContext *ctxt; GtkOrientation orientation; WnckPagerDisplayMode mode; + WnckPagerScrollMode scroll_mode; WnckScreen *screen; ctxt = g_option_context_new (""); @@ -96,7 +101,12 @@ main (int argc, char **argv) else mode = WNCK_PAGER_DISPLAY_CONTENT; - create_pager_window (orientation, !only_current, mode, n_rows, wrap_on_scroll); + if (simple_scrolling) + scroll_mode = WNCK_PAGER_SCROLL_1D; + else + scroll_mode = WNCK_PAGER_SCROLL_2D; + + create_pager_window (orientation, !only_current, mode, scroll_mode, n_rows, wrap_on_scroll); gtk_main (); |