summaryrefslogtreecommitdiff
path: root/libwnck/test-pager.c
blob: d60b04768880a96f35044b5ad1ad00fc1140c410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* vim: set sw=2 et: */

#include <libwnck/libwnck.h>
#include <gtk/gtk.h>

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;

static GOptionEntry entries[] = {
	{"n-rows", 'n', 0, G_OPTION_ARG_INT, &n_rows, "Use N_ROWS rows", "N_ROWS"},
	{"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 }
};

static void
create_pager_window (GtkOrientation       orientation,
                     gboolean             show_all,
                     WnckPagerDisplayMode mode,
                     WnckPagerScrollMode  scroll_mode,
                     int                  rows,
                     gboolean             wrap)
{
  GtkWidget *win;
  GtkWidget *pager;

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_stick (GTK_WINDOW (win));
#if 0
  wnck_gtk_window_set_dock_type (GTK_WINDOW (win));
#endif

  gtk_window_set_title (GTK_WINDOW (win), "Pager");

  /* very very random */
  gtk_window_move (GTK_WINDOW (win), 0, 0);

  /* quit on window close */
  g_signal_connect (G_OBJECT (win), "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);

  pager = wnck_pager_new ();

  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);
  wnck_pager_set_wrap_on_scroll (WNCK_PAGER (pager), wrap);

  gtk_container_add (GTK_CONTAINER (win), pager);

  gtk_widget_show_all (win);
}

int
main (int argc, char **argv)
{
  GOptionContext *ctxt;
  GtkOrientation  orientation;
  WnckPagerDisplayMode mode;
  WnckPagerScrollMode scroll_mode;
  WnckScreen *screen;

  ctxt = g_option_context_new ("");
  g_option_context_add_main_entries (ctxt, entries, NULL);
  g_option_context_add_group (ctxt, gtk_get_option_group (TRUE));
  g_option_context_parse (ctxt, &argc, &argv, NULL);
  g_option_context_free (ctxt);
  ctxt = NULL;

  gtk_init (&argc, &argv);

  if (rtl)
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  screen = wnck_screen_get_default ();

  /* because the pager doesn't respond to signals at the moment */
  wnck_screen_force_update (screen);

  if (vertical)
	  orientation = GTK_ORIENTATION_VERTICAL;
  else
	  orientation = GTK_ORIENTATION_HORIZONTAL;

  if (show_name)
	  mode = WNCK_PAGER_DISPLAY_NAME;
  else
	  mode = WNCK_PAGER_DISPLAY_CONTENT;

  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 ();

  return 0;
}