Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

147 rindas
4.0 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 Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include "cucul.h"
  18. #include "caca.h"
  19. static cucul_t *qq;
  20. static caca_t *kk;
  21. static void print_event(int, int, unsigned int);
  22. int main(int argc, char **argv)
  23. {
  24. int *events;
  25. int i, h, quit;
  26. qq = cucul_init();
  27. if(!qq)
  28. return 1;
  29. kk = caca_attach(qq);
  30. if(!kk)
  31. return 1;
  32. h = cucul_get_height(qq) - 1;
  33. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  34. cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, ' ');
  35. cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, ' ');
  36. cucul_putstr(qq, 0, h, "type \"quit\" to exit");
  37. caca_display(kk);
  38. events = malloc(h * sizeof(int));
  39. memset(events, 0, h * sizeof(int));
  40. for(quit = 0; quit < 4; )
  41. {
  42. static char const * quit_string[] = { "", "q", "qu", "qui", "quit" };
  43. unsigned int event = caca_wait_event(kk, CACA_EVENT_ANY);
  44. if(!event)
  45. continue;
  46. do
  47. {
  48. /* "quit" quits */
  49. if(event & CACA_EVENT_KEY_PRESS)
  50. {
  51. int key = event & ~CACA_EVENT_KEY_PRESS;
  52. if((key == 'q' && quit == 0) || (key == 'u' && quit == 1)
  53. || (key == 'i' && quit == 2) || (key == 't' && quit == 3))
  54. quit++;
  55. else if(key == 'q')
  56. quit = 1;
  57. else
  58. quit = 0;
  59. }
  60. memmove(events + 1, events, (h - 1) * sizeof(int));
  61. events[0] = event;
  62. event = caca_get_event(kk, CACA_EVENT_ANY);
  63. }
  64. while(event);
  65. cucul_clear(qq);
  66. /* Print current event */
  67. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  68. cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, ' ');
  69. print_event(0, 0, events[0]);
  70. cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, ' ');
  71. cucul_printf(qq, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);
  72. /* Print previous events */
  73. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  74. for(i = 1; i < h && events[i]; i++)
  75. print_event(0, i, events[i]);
  76. caca_display(kk);
  77. }
  78. /* Clean up */
  79. caca_detach(kk);
  80. cucul_end(qq);
  81. return 0;
  82. }
  83. static void print_event(int x, int y, unsigned int event)
  84. {
  85. int character;
  86. switch(event & 0xff000000)
  87. {
  88. case CACA_EVENT_NONE:
  89. cucul_printf(qq, x, y, "CACA_EVENT_NONE");
  90. break;
  91. case CACA_EVENT_KEY_PRESS:
  92. character = event & 0x00ffffff;
  93. cucul_printf(qq, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
  94. (character > 0x20 && character < 0x80) ? character : '?');
  95. break;
  96. case CACA_EVENT_KEY_RELEASE:
  97. character = event & 0x00ffffff;
  98. cucul_printf(qq, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
  99. (character > 0x20 && character < 0x80) ? character : '?');
  100. break;
  101. case CACA_EVENT_MOUSE_MOTION:
  102. cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
  103. (event & 0x00fff000) >> 12, event & 0x00000fff);
  104. break;
  105. case CACA_EVENT_MOUSE_PRESS:
  106. cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_PRESS %u",
  107. event & 0x00ffffff);
  108. break;
  109. case CACA_EVENT_MOUSE_RELEASE:
  110. cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
  111. event & 0x00ffffff);
  112. break;
  113. case CACA_EVENT_RESIZE:
  114. cucul_printf(qq, x, y, "CACA_EVENT_RESIZE");
  115. break;
  116. default:
  117. cucul_printf(qq, x, y, "CACA_EVENT_UNKNOWN");
  118. }
  119. }