aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-06-07 14:28:57 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:23:31 +0200
commit5194d08da23a315c1405b108889f4c6ae9cb0426 (patch)
tree11bc1667c7f6956bc7b304f6c9e38c39b2ee60d7 /src
initial commit
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt14
-rw-r--r--src/main.c97
-rw-r--r--src/util.c55
-rw-r--r--src/util.h8
4 files changed, 174 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..d38a6f6
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,14 @@
+wlproto(IVI_APP ivi-application)
+wlproto(IVI_CON ivi-controller)
+
+add_executable(winman
+ main.c
+ util.c
+ util.h
+ ${IVI_APP_PROTO}
+ ${IVI_CON_PROTO})
+
+add_definitions(-DWINMAN_VERSION_STRING="${PACKAGE_VERSION}")
+
+target_link_libraries(winman
+ ${WLC_LIBRARIES})
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..7cdef06
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,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;
+}
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..ee4b7b6
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,55 @@
+#include "util.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+struct strftime_cache {
+ time_t time;
+ char buf[128];
+};
+
+void log_(char const *log_type, FILE *stream, char const *fmt, va_list args) {
+ static struct strftime_cache strft;
+
+ time_t t = time(NULL);
+ if (t != strft.time) {
+ strft.time = t;
+ struct tm tm;
+ struct tm *tmp = localtime_r(&t, &tm);
+ strftime(strft.buf, sizeof(strft.buf), "%Y-%m-%dT%H:%M:%S", tmp);
+ }
+
+ fputs(program_invocation_short_name, stream);
+ fputs(" ", stream);
+ fputs(strft.buf, stream);
+ fputs(" ", stream);
+ fputs(log_type, stream);
+ fputs(" ", stream);
+ vfprintf(stream, fmt, args);
+ fputs("\n", stream);
+}
+
+void lognotice(char const *fmt, ...) {
+ va_list a;
+ va_start(a, fmt);
+ log_("notice", stdout, fmt, a);
+ va_end(a);
+}
+
+void logerror(char const *fmt, ...) {
+ va_list a;
+ va_start(a, fmt);
+ log_("error", stderr, fmt, a);
+ va_end(a);
+}
+
+void fatal(char const *fmt, ...) {
+ va_list a;
+ va_start(a, fmt);
+ log_("fatal", stderr, fmt, a);
+ va_end(a);
+ abort();
+}
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..7a15454
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,8 @@
+#ifndef WM_UTIL_H
+#define WM_UTIL_H
+
+void lognotice(char const *fmt, ...);
+void logerror(char const *fmt, ...);
+void fatal(char const *fmt, ...);
+
+#endif // !WM_UTIL_H