shim.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) Milan Jurkulák 2026.
  3. * Contact:
  4. * e: mimoccc@gmail.com
  5. * e: mj@mjdev.org
  6. * w: https://mjdev.org
  7. *
  8. * Flat C API over wlroots for the mjdev compositor.
  9. * This header is self contained (no wlroots includes) so it can be
  10. * processed by Kotlin/Native cinterop directly.
  11. */
  12. #ifndef MJDEV_COMPOSITOR_SHIM_H
  13. #define MJDEV_COMPOSITOR_SHIM_H
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef struct mjc_server mjc_server;
  20. typedef struct mjc_view mjc_view;
  21. typedef enum mjc_layer {
  22. MJC_LAYER_BACKGROUND = 0,
  23. MJC_LAYER_BOTTOM = 1,
  24. MJC_LAYER_NORMAL = 2,
  25. MJC_LAYER_TOP = 3,
  26. MJC_LAYER_OVERLAY = 4,
  27. } mjc_layer;
  28. /* mask values for fd events, mirror wayland WL_EVENT_* */
  29. #define MJC_EVENT_READABLE 0x01
  30. #define MJC_EVENT_WRITABLE 0x02
  31. #define MJC_EVENT_HANGUP 0x04
  32. #define MJC_EVENT_ERROR 0x08
  33. /* keyboard modifiers, mirror wlroots WLR_MODIFIER_* */
  34. #define MJC_MOD_SHIFT 0x01
  35. #define MJC_MOD_CAPS 0x02
  36. #define MJC_MOD_CTRL 0x04
  37. #define MJC_MOD_ALT 0x08
  38. #define MJC_MOD_MOD2 0x10
  39. #define MJC_MOD_MOD3 0x20
  40. #define MJC_MOD_LOGO 0x40
  41. #define MJC_MOD_MOD5 0x80
  42. typedef struct mjc_callbacks {
  43. /* view lifecycle */
  44. void (*view_new)(void *ud, mjc_view *view, bool xwayland);
  45. void (*view_map)(void *ud, mjc_view *view);
  46. void (*view_unmap)(void *ud, mjc_view *view);
  47. void (*view_destroy)(void *ud, mjc_view *view);
  48. void (*view_title)(void *ud, mjc_view *view, const char *title);
  49. void (*view_app_id)(void *ud, mjc_view *view, const char *app_id);
  50. /* focus changed; view may be NULL when nothing is focused */
  51. void (*focus_change)(void *ud, mjc_view *view);
  52. /* keyboard binding hook, return true when the combo was consumed */
  53. bool (*key)(void *ud, uint32_t keysym, uint32_t modifiers, bool pressed);
  54. /* fd registered via mjc_loop_add_fd became ready */
  55. int (*fd_event)(void *ud, int fd, uint32_t mask);
  56. /* a child process spawned via mjc_spawn exited */
  57. void (*child_exit)(void *ud, int pid, int status);
  58. /* backend started, sockets exported - safe to spawn clients */
  59. void (*ready)(void *ud);
  60. /* pointer moved, in compositor layout coordinates (throttled) */
  61. void (*pointer)(void *ud, int x, int y);
  62. } mjc_callbacks;
  63. /* lifecycle */
  64. mjc_server *mjc_create(void);
  65. bool mjc_start(mjc_server *server, const mjc_callbacks *callbacks, void *userdata);
  66. void mjc_run(mjc_server *server);
  67. void mjc_terminate(mjc_server *server);
  68. void mjc_destroy(mjc_server *server);
  69. /* environment */
  70. const char *mjc_socket_name(mjc_server *server); /* WAYLAND_DISPLAY */
  71. const char *mjc_xwayland_display(mjc_server *server); /* DISPLAY or NULL */
  72. void mjc_output_size(mjc_server *server, int *width, int *height);
  73. /* process spawning (inherits WAYLAND_DISPLAY/DISPLAY), returns pid or -1 */
  74. int mjc_spawn(mjc_server *server, const char *command);
  75. /* event loop integration for the IPC server */
  76. bool mjc_loop_add_fd(mjc_server *server, int fd, uint32_t mask);
  77. void mjc_loop_remove_fd(mjc_server *server, int fd);
  78. /* unix socket helpers (sockaddr_un is unavailable in kotlin/native posix) */
  79. int mjc_unix_listen(const char *path, int backlog); /* nonblocking fd or -1 */
  80. int mjc_unix_accept(int server_fd); /* nonblocking fd or -1 */
  81. /* views */
  82. uint64_t mjc_view_id(mjc_view *view);
  83. int mjc_view_pid(mjc_view *view);
  84. const char *mjc_view_title(mjc_view *view);
  85. const char *mjc_view_app_id(mjc_view *view);
  86. bool mjc_view_is_xwayland(mjc_view *view);
  87. bool mjc_view_is_mapped(mjc_view *view);
  88. bool mjc_view_is_minimized(mjc_view *view);
  89. bool mjc_view_is_maximized(mjc_view *view);
  90. bool mjc_view_is_focused(mjc_view *view);
  91. void mjc_view_get_geometry(mjc_view *view, int *x, int *y, int *width, int *height);
  92. void mjc_view_focus(mjc_view *view);
  93. void mjc_view_close(mjc_view *view);
  94. void mjc_view_set_minimized(mjc_view *view, bool minimized);
  95. void mjc_view_set_maximized(mjc_view *view, bool maximized);
  96. void mjc_view_set_layer(mjc_view *view, mjc_layer layer);
  97. void mjc_view_set_focusable(mjc_view *view, bool focusable);
  98. void mjc_view_set_position(mjc_view *view, int x, int y);
  99. void mjc_view_set_geometry(mjc_view *view, int x, int y, int width, int height);
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* MJDEV_COMPOSITOR_SHIM_H */