pager.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * xsimplepager
  3. *
  4. * Copyright (C) 2016 Alexander Andrejevic <theflash AT sdf DOT lonestar DOT org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <gtk/gtk.h>
  20. #define WNCK_I_KNOW_THIS_IS_UNSTABLE
  21. #include <libwnck/libwnck.h>
  22. static gint x = 0;
  23. static gint y = 0;
  24. static gint width = 100;
  25. static gint height = 24;
  26. static gint rows = 1;
  27. static gboolean vertical = FALSE;
  28. static gdouble red = 0.2;
  29. static gdouble green = 0.2;
  30. static gdouble blue = 0.2;
  31. static gdouble alpha = 0.8;
  32. static const GOptionEntry options[] = {
  33. { "x", 'x', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &x, "The X coordinate of the pager, in pixels.", NULL },
  34. { "y", 'y', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &y, "The Y coordinate of the pager, in pixels.", NULL },
  35. { "width", 'w', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &width, "The width of the pager, in pixels.", NULL },
  36. { "height", 'h', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &height, "The height of the pager, in pixels.", NULL },
  37. {
  38. "rows", 'r', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &rows,
  39. "The number of rows in which workspace thumbnails should be displayed.", NULL
  40. },
  41. {
  42. "horizontal", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &vertical,
  43. "Make the pager horizontal (the default).", NULL
  44. },
  45. { "vertical", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &vertical, "Make the pager vertical.", NULL },
  46. {
  47. "red", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_DOUBLE, &red,
  48. "The red component of the background color, between 0 and 1 (default: 0.2).", NULL
  49. },
  50. {
  51. "green", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_DOUBLE, &green,
  52. "The green component of the background color, between 0 and 1 (default: 0.2).", NULL
  53. },
  54. {
  55. "blue", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_DOUBLE, &blue,
  56. "The blue component of the background color, between 0 and 1 (default: 0.2).", NULL
  57. },
  58. {
  59. "alpha", 'a', G_OPTION_FLAG_NONE, G_OPTION_ARG_DOUBLE, &alpha,
  60. "The alpha component of the background color, between 0 and 1 (default: 0.8).", NULL
  61. },
  62. { NULL, '\0', 0, 0, NULL, NULL, NULL }
  63. };
  64. static gboolean on_pager_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data)
  65. {
  66. cairo_t *cr = gdk_cairo_create(widget->window);
  67. cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
  68. cairo_set_source_rgba(cr, red, green, blue, alpha);
  69. cairo_paint(cr);
  70. cairo_destroy(cr);
  71. return FALSE;
  72. }
  73. int main(int argc, char *argv[])
  74. {
  75. gtk_init(&argc, &argv);
  76. GOptionContext *context = g_option_context_new(" - Display a pager on the screen.");
  77. g_option_context_add_main_entries(context, options, NULL);
  78. GError *error = NULL;
  79. if (!g_option_context_parse(context, &argc, &argv, &error))
  80. {
  81. fprintf(stderr, "Error: %s\n", error->message);
  82. g_error_free(error);
  83. g_option_context_free(context);
  84. return 2;
  85. }
  86. g_option_context_free(context);
  87. GtkWindow *window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_POPUP));
  88. gtk_window_stick(window);
  89. gtk_window_move(window, x, y);
  90. GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
  91. GdkColormap *rgba = gdk_screen_get_rgba_colormap(screen);
  92. gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
  93. WnckPager *pager = WNCK_PAGER(wnck_pager_new(wnck_screen_get_default()));
  94. gtk_widget_set_size_request(GTK_WIDGET(pager), width, height);
  95. wnck_pager_set_orientation(pager, vertical ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
  96. wnck_pager_set_n_rows(pager, rows);
  97. wnck_pager_set_display_mode(pager, WNCK_PAGER_DISPLAY_CONTENT);
  98. g_signal_connect(G_OBJECT(pager), "expose-event", G_CALLBACK(on_pager_expose), NULL);
  99. gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(pager));
  100. gtk_widget_show_all(GTK_WIDGET(window));
  101. gtk_main();
  102. return 0;
  103. }