aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 7cdef06d4778faa309e71f707153cd2ef6cb74f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "util.h"

#include "ivi-controller-client-protocol.h"

#include <stdlib.h>
#include <string.h>

#include <wayland-client.h>

struct conn {
   struct wl_display *d;
   struct wl_registry *r;
   struct wl_array outputs;

   struct ivi_controller *c;
};

static void c_screen(void *data, struct ivi_controller *ivi_controller,
              uint32_t id_screen, struct ivi_controller_screen *screen) {}

static void c_layer(void *data, struct ivi_controller *ivi_controller,
             uint32_t id_layer) {}

static void c_surface(void *data, struct ivi_controller *ivi_controller,
               uint32_t id_surface) {}

static void c_error(void *data, struct ivi_controller *ivi_controller,
             int32_t object_id, int32_t object_type, int32_t error_code,
             const char *error_text) {}

struct ivi_controller_listener c_listener = {c_screen, c_layer, c_surface,
                                             c_error};

static void o_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y,
                int32_t physical_width, int32_t physical_height,
                int32_t subpixel, const char *make, const char *model,
                int32_t transform) {}

static void o_mode(void *data, struct wl_output *wl_output, uint32_t flags,
            int32_t width, int32_t height, int32_t refresh) {}

static void o_done(void *data, struct wl_output *wl_output) {}

static void o_scale(void *data, struct wl_output *wl_output, int32_t factor) {}

struct wl_output_listener o_listener = {o_geometry, o_mode, o_done, o_scale};

static void r_global(void *data, struct wl_registry *r, uint32_t name,
                     char const *iface, uint32_t v) {
   struct conn *c = data;

   if (strcmp(iface, "ivi_controller") == 0) {
      c->c = wl_registry_bind(r, name, &ivi_controller_interface, v);
      ivi_controller_add_listener(c->c, &c_listener, c);
   } else if (strcmp(iface, "wl_output") == 0) {
      struct wl_output **o = wl_array_add(&c->outputs, sizeof(*o));
      *o = wl_registry_bind(r, name, &wl_output_interface, v);
      wl_output_add_listener(*o, &o_listener, c);
   }
}

static void r_global_remove(void *data, struct wl_registry *r, uint32_t name) {}

struct wl_registry_listener r_listener = {r_global, r_global_remove};

int main(int argc, char **argv) {
   lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);

   if (!getenv("XDG_RUNTIME_DIR"))
      fatal("Environment variable XDG_RUNTIME_DIR not set");

   struct conn c;
   wl_array_init(&c.outputs);
   c.d = wl_display_connect(NULL);
   if (!c.d)
      fatal("Could not connect to compositor");
   c.r = wl_display_get_registry(c.d);
   wl_registry_add_listener(c.r, &r_listener, &c);

   // First level objects
   wl_display_roundtrip(c.d);
   // Second level objects
   wl_display_roundtrip(c.d);

   if (!c.c)
      fatal("ivi_controller global not available");

   // main loop
   while (wl_display_dispatch(c.d) != -1) {
   }

   ivi_controller_destroy(c.c);
   wl_registry_destroy(c.r);
   wl_display_disconnect(c.d);

   return 0;
}