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.
 
 
 
 
 
 

118 lines
3.1 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;
  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( ; ; )
  41. {
  42. unsigned int event = caca_wait_event(CACA_EVENT_ANY);
  43. if(!event)
  44. continue;
  45. memmove(events + 1, events, (h - 1) * sizeof(int));
  46. events[0] = event;
  47. caca_clear();
  48. /* Print current event */
  49. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
  50. caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
  51. print_event(0, 0, event);
  52. /* Print previous events */
  53. caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
  54. for(i = 1; i < h && events[i]; i++)
  55. print_event(0, i, events[i]);
  56. /* q quits */
  57. if(event == (CACA_EVENT_KEY_PRESS | 'q'))
  58. break;
  59. caca_refresh();
  60. }
  61. /* Clean up */
  62. caca_end();
  63. return 0;
  64. }
  65. static void print_event(int x, int y, unsigned int event)
  66. {
  67. switch(event & 0xff000000)
  68. {
  69. case CACA_EVENT_NONE:
  70. caca_printf(x, y, "CACA_EVENT_NONE");
  71. break;
  72. case CACA_EVENT_KEY_PRESS:
  73. caca_printf(x, y, "CACA_EVENT_KEY_PRESS 0x%06x",
  74. event & 0x00ffffff);
  75. break;
  76. case CACA_EVENT_KEY_RELEASE:
  77. caca_printf(x, y, "CACA_EVENT_KEY_RELEASE 0x%06x",
  78. event & 0x00ffffff);
  79. break;
  80. case CACA_EVENT_MOUSE_MOTION:
  81. caca_printf(x, y, "CACA_EVENT_MOUSE_MOTION 0x%03x 0x%03x",
  82. (event & 0x00fff000) >> 12, event & 0x00000fff);
  83. break;
  84. case CACA_EVENT_MOUSE_PRESS:
  85. caca_printf(x, y, "CACA_EVENT_MOUSE_PRESS 0x%06x",
  86. event & 0x00ffffff);
  87. break;
  88. case CACA_EVENT_MOUSE_RELEASE:
  89. caca_printf(x, y, "CACA_EVENT_MOUSE_RELEASE 0x%06x",
  90. event & 0x00ffffff);
  91. break;
  92. default:
  93. caca_printf(x, y, "CACA_EVENT_UNKNOWN");
  94. }
  95. }