You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

128 rivejä
3.5 KiB

  1. /*
  2. * event event lister for libcaca
  3. * Copyright (c) 2004 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "config.h"
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "caca.h"
  27. static void print_event(int, int, unsigned int);
  28. int main(int argc, char **argv)
  29. {
  30. int *events;
  31. int i, h, quit;
  32. if(caca_init())
  33. return 1;
  34. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
  35. caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
  36. caca_refresh();
  37. h = caca_get_height();
  38. events = malloc(h * sizeof(int));
  39. memset(events, 0, h * sizeof(int));
  40. for(quit = 0; !quit; )
  41. {
  42. unsigned int event = caca_wait_event(CACA_EVENT_ANY);
  43. if(!event)
  44. continue;
  45. do
  46. {
  47. /* q quits */
  48. if(event == (CACA_EVENT_KEY_PRESS | 'q'))
  49. quit = 1;
  50. memmove(events + 1, events, (h - 1) * sizeof(int));
  51. events[0] = event;
  52. event = caca_get_event(CACA_EVENT_ANY);
  53. }
  54. while(event);
  55. caca_clear();
  56. /* Print current event */
  57. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
  58. caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
  59. print_event(0, 0, events[0]);
  60. /* Print previous events */
  61. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
  62. for(i = 1; i < h && events[i]; i++)
  63. print_event(0, i, events[i]);
  64. caca_refresh();
  65. }
  66. /* Clean up */
  67. caca_end();
  68. return 0;
  69. }
  70. static void print_event(int x, int y, unsigned int event)
  71. {
  72. int character;
  73. switch(event & 0xff000000)
  74. {
  75. case CACA_EVENT_NONE:
  76. caca_printf(x, y, "CACA_EVENT_NONE");
  77. break;
  78. case CACA_EVENT_KEY_PRESS:
  79. character = event & 0x00ffffff;
  80. caca_printf(x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
  81. (character > 0x20 && character < 0x80) ? character : '?');
  82. break;
  83. case CACA_EVENT_KEY_RELEASE:
  84. character = event & 0x00ffffff;
  85. caca_printf(x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
  86. (character > 0x20 && character < 0x80) ? character : '?');
  87. break;
  88. case CACA_EVENT_MOUSE_MOTION:
  89. caca_printf(x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
  90. (event & 0x00fff000) >> 12, event & 0x00000fff);
  91. break;
  92. case CACA_EVENT_MOUSE_PRESS:
  93. caca_printf(x, y, "CACA_EVENT_MOUSE_PRESS %u",
  94. event & 0x00ffffff);
  95. break;
  96. case CACA_EVENT_MOUSE_RELEASE:
  97. caca_printf(x, y, "CACA_EVENT_MOUSE_RELEASE %u",
  98. event & 0x00ffffff);
  99. break;
  100. default:
  101. caca_printf(x, y, "CACA_EVENT_UNKNOWN");
  102. }
  103. }