kwin_fake_input.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Drives KWin's pointer via org_kde_kwin_fake_input (needs KWIN_WAYLAND_NO_PERMISSION_CHECKS).
  2. * Usage: kwin_fake_input move X Y | down BUTTON | up BUTTON ... (evdev codes, 272 = left) */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <wayland-client.h>
  7. #include "fake-input-client-protocol.h"
  8. static struct org_kde_kwin_fake_input* fake_input;
  9. static void global (void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
  10. if (strcmp (interface, org_kde_kwin_fake_input_interface.name) == 0) {
  11. fake_input = wl_registry_bind (registry, name, &org_kde_kwin_fake_input_interface, version < 4 ? version : 4);
  12. }
  13. }
  14. static void global_remove (void* data, struct wl_registry* registry, uint32_t name) { }
  15. static const struct wl_registry_listener registry_listener = { global, global_remove };
  16. int main (int argc, char** argv) {
  17. struct wl_display* display = wl_display_connect (NULL);
  18. if (!display) {
  19. fprintf (stderr, "no Wayland display\n");
  20. return 1;
  21. }
  22. wl_registry_add_listener (wl_display_get_registry (display), &registry_listener, NULL);
  23. wl_display_roundtrip (display);
  24. if (!fake_input) {
  25. fprintf (stderr, "the compositor offers no org_kde_kwin_fake_input\n");
  26. return 1;
  27. }
  28. org_kde_kwin_fake_input_authenticate (fake_input, "lwe-lab", "desktop tests");
  29. for (int i = 1; i < argc; i++) {
  30. if (strcmp (argv[i], "move") == 0 && i + 2 < argc) {
  31. org_kde_kwin_fake_input_pointer_motion_absolute (
  32. fake_input, wl_fixed_from_double (atof (argv[i + 1])), wl_fixed_from_double (atof (argv[i + 2]))
  33. );
  34. i += 2;
  35. } else if ((strcmp (argv[i], "down") == 0 || strcmp (argv[i], "up") == 0) && i + 1 < argc) {
  36. org_kde_kwin_fake_input_button (fake_input, atoi (argv[i + 1]), strcmp (argv[i], "down") == 0);
  37. i += 1;
  38. } else {
  39. fprintf (stderr, "unknown command %s\n", argv[i]);
  40. return 1;
  41. }
  42. wl_display_roundtrip (display);
  43. }
  44. wl_display_disconnect (display);
  45. return 0;
  46. }