add gvim session
[staging/windowmanager.git] / src / main.c
1 #include "util.h"
2
3 #include "ivi-controller-client-protocol.h"
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include <wayland-client.h>
9
10 struct conn {
11    struct wl_display *d;
12    struct wl_registry *r;
13    struct wl_array outputs;
14
15    struct ivi_controller *c;
16 };
17
18 static void c_screen(void *data, struct ivi_controller *ivi_controller,
19               uint32_t id_screen, struct ivi_controller_screen *screen) {}
20
21 static void c_layer(void *data, struct ivi_controller *ivi_controller,
22              uint32_t id_layer) {}
23
24 static void c_surface(void *data, struct ivi_controller *ivi_controller,
25                uint32_t id_surface) {}
26
27 static void c_error(void *data, struct ivi_controller *ivi_controller,
28              int32_t object_id, int32_t object_type, int32_t error_code,
29              const char *error_text) {}
30
31 struct ivi_controller_listener c_listener = {c_screen, c_layer, c_surface,
32                                              c_error};
33
34 static void o_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y,
35                 int32_t physical_width, int32_t physical_height,
36                 int32_t subpixel, const char *make, const char *model,
37                 int32_t transform) {}
38
39 static void o_mode(void *data, struct wl_output *wl_output, uint32_t flags,
40             int32_t width, int32_t height, int32_t refresh) {}
41
42 static void o_done(void *data, struct wl_output *wl_output) {}
43
44 static void o_scale(void *data, struct wl_output *wl_output, int32_t factor) {}
45
46 struct wl_output_listener o_listener = {o_geometry, o_mode, o_done, o_scale};
47
48 static void r_global(void *data, struct wl_registry *r, uint32_t name,
49                      char const *iface, uint32_t v) {
50    struct conn *c = data;
51
52    if (strcmp(iface, "ivi_controller") == 0) {
53       c->c = wl_registry_bind(r, name, &ivi_controller_interface, v);
54       ivi_controller_add_listener(c->c, &c_listener, c);
55    } else if (strcmp(iface, "wl_output") == 0) {
56       struct wl_output **o = wl_array_add(&c->outputs, sizeof(*o));
57       *o = wl_registry_bind(r, name, &wl_output_interface, v);
58       wl_output_add_listener(*o, &o_listener, c);
59    }
60 }
61
62 static void r_global_remove(void *data, struct wl_registry *r, uint32_t name) {}
63
64 struct wl_registry_listener r_listener = {r_global, r_global_remove};
65
66 int main(int argc, char **argv) {
67    lognotice("WinMan ver. %s", WINMAN_VERSION_STRING);
68
69    if (!getenv("XDG_RUNTIME_DIR"))
70       fatal("Environment variable XDG_RUNTIME_DIR not set");
71
72    struct conn c;
73    wl_array_init(&c.outputs);
74    c.d = wl_display_connect(NULL);
75    if (!c.d)
76       fatal("Could not connect to compositor");
77    c.r = wl_display_get_registry(c.d);
78    wl_registry_add_listener(c.r, &r_listener, &c);
79
80    // First level objects
81    wl_display_roundtrip(c.d);
82    // Second level objects
83    wl_display_roundtrip(c.d);
84
85    if (!c.c)
86       fatal("ivi_controller global not available");
87
88    // main loop
89    while (wl_display_dispatch(c.d) != -1) {
90    }
91
92    ivi_controller_destroy(c.c);
93    wl_registry_destroy(c.r);
94    wl_display_disconnect(c.d);
95
96    return 0;
97 }