river_min_wm.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Minimal river 0.4 WM: ends every manage/render sequence at once and binds river_layer_shell_v1, without which
  2. // river closes all layer surfaces. Exits when the WM role is taken or the connection ends.
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <wayland-client.h>
  6. #include "river-layer-shell-v1-client-protocol.h"
  7. #include "river-window-management-v1-client-protocol.h"
  8. static struct river_window_manager_v1* wm;
  9. static struct river_layer_shell_v1* layer_shell;
  10. static int running = 1;
  11. static void global (void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
  12. if (strcmp (interface, river_window_manager_v1_interface.name) == 0) {
  13. wm = wl_registry_bind (registry, name, &river_window_manager_v1_interface, 1);
  14. } else if (strcmp (interface, river_layer_shell_v1_interface.name) == 0) {
  15. layer_shell = wl_registry_bind (registry, name, &river_layer_shell_v1_interface, 1);
  16. }
  17. }
  18. static void global_remove (void* data, struct wl_registry* registry, uint32_t name) { }
  19. static const struct wl_registry_listener registry_listener = { global, global_remove };
  20. static void unavailable (void* data, struct river_window_manager_v1* wm) {
  21. fprintf (stderr, "another window manager is running\n");
  22. running = 0;
  23. }
  24. static void finished (void* data, struct river_window_manager_v1* wm) { running = 0; }
  25. static void manage_start (void* data, struct river_window_manager_v1* wm) { river_window_manager_v1_manage_finish (wm); }
  26. static void render_start (void* data, struct river_window_manager_v1* wm) { river_window_manager_v1_render_finish (wm); }
  27. static void session_locked (void* data, struct river_window_manager_v1* wm) { }
  28. static void session_unlocked (void* data, struct river_window_manager_v1* wm) { }
  29. static void window (void* data, struct river_window_manager_v1* wm, struct river_window_v1* window) { }
  30. static void output (void* data, struct river_window_manager_v1* wm, struct river_output_v1* output) { }
  31. static void seat (void* data, struct river_window_manager_v1* wm, struct river_seat_v1* seat) { }
  32. static const struct river_window_manager_v1_listener wm_listener = {
  33. unavailable, finished, manage_start, render_start, session_locked, session_unlocked, window, output, seat,
  34. };
  35. int main (void) {
  36. struct wl_display* display = wl_display_connect (NULL);
  37. if (!display) {
  38. fprintf (stderr, "no wayland display\n");
  39. return 1;
  40. }
  41. wl_registry_add_listener (wl_display_get_registry (display), &registry_listener, NULL);
  42. wl_display_roundtrip (display);
  43. if (!wm || !layer_shell) {
  44. fprintf (stderr, "the compositor has no river_window_manager_v1 or river_layer_shell_v1\n");
  45. return 1;
  46. }
  47. river_window_manager_v1_add_listener (wm, &wm_listener, NULL);
  48. printf ("ready\n");
  49. fflush (stdout);
  50. while (running && wl_display_dispatch (display) != -1) { }
  51. return 0;
  52. }