summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-06-07 18:02:36 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:24:00 +0200
commit11369e6592800fcf03138b109fee3d4c0736f21a (patch)
treed0c04f5d9f5088ab298fdbdba506df132e9224cc
parentacfd4316ac0678aa622b116359821246f06aa080 (diff)
cpp, more listeners
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--session.vim26
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/main.c97
-rw-r--r--src/main.cpp172
-rw-r--r--src/util.h8
6 files changed, 196 insertions, 110 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 31417c6..791e645 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,5 +43,6 @@ endmacro()
add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c99 ${CMAKE_C_FLAGS}")
+set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -std=c++14 ${CMAKE_CXX_FLAGS}")
add_subdirectory(src)
diff --git a/session.vim b/session.vim
index 47dd26f..63ede7e 100644
--- a/session.vim
+++ b/session.vim
@@ -7,16 +7,18 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
-badd +34 src/main.c
-badd +1 term://.//32710:/usr/bin/fish
-badd +2 src/CMakeLists.txt
-badd +8 CMakeLists.txt
+badd +77 src/main.c
+badd +10 src/CMakeLists.txt
+badd +46 CMakeLists.txt
badd +19 src/util.c
-badd +8 src/util.h
+badd +14 src/util.h
+badd +1 term://.//9732:/usr/bin/fish
+badd +1 main.cpp
+badd +26 src/main.cpp
argglobal
silent! argdel *
argadd src/main.c
-edit src/main.c
+edit src/main.cpp
set splitbelow splitright
wincmd _ | wincmd |
vsplit
@@ -37,15 +39,15 @@ setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
-let s:l = 54 - ((32 * winheight(0) + 33) / 66)
+let s:l = 125 - ((60 * winheight(0) + 33) / 66)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
-54
-normal! 04|
+125
+normal! 022|
wincmd w
argglobal
-edit term://.//32710:/usr/bin/fish
+edit term://.//9732:/usr/bin/fish
setlocal fdm=marker
setlocal fde=0
setlocal fmr={{{,}}}
@@ -54,11 +56,11 @@ setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
-let s:l = 14 - ((13 * winheight(0) + 33) / 66)
+let s:l = 41 - ((13 * winheight(0) + 33) / 66)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
-14
+41
normal! 0
wincmd w
exe 'vert 1resize ' . ((&columns * 137 + 137) / 274)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d38a6f6..86e7ecd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,7 @@ wlproto(IVI_APP ivi-application)
wlproto(IVI_CON ivi-controller)
add_executable(winman
- main.c
+ main.cpp
util.c
util.h
${IVI_APP_PROTO}
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 7cdef06..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#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/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..794d9af
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,172 @@
+#include "util.h"
+
+#include "ivi-controller-client-protocol.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <wayland-client.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+struct ivi_surface;
+struct ivi_layer;
+
+struct conn {
+ wl_display *d;
+ wl_registry *r;
+ ivi_controller *c;
+ std::vector<std::unique_ptr<wl_output, void (*)(wl_output *)>> outputs;
+ std::map<uint32_t, std::unique_ptr<ivi_layer>> layers;
+ std::map<uint32_t, std::unique_ptr<ivi_surface>> surfaces;
+
+ ~conn();
+};
+
+struct ivi_surface {
+ ivi_controller_surface *controller;
+ uint32_t id;
+ conn *con;
+ ivi_surface(ivi_controller_surface *c, uint32_t i, conn *co)
+ : controller(c), id(i), con(co) {}
+ ~ivi_surface() { ivi_controller_surface_destroy(this->controller, 1); }
+};
+
+struct ivi_layer {
+ ivi_controller_layer *controller;
+ uint32_t id;
+ conn *con;
+ ivi_layer(ivi_controller_layer *c, uint32_t i, conn *co)
+ : controller(c), id(i), con(co) {}
+ ~ivi_layer() { ivi_controller_layer_destroy(this->controller, 1); }
+};
+
+conn::~conn() {
+ this->layers.clear();
+ this->surfaces.clear();
+ ivi_controller_destroy(this->c);
+ this->outputs.clear();
+ wl_registry_destroy(this->r);
+ wl_display_disconnect(this->d);
+}
+
+static ivi_controller_surface_listener cs_listener = {};
+
+static ivi_controller_layer_listener cl_listener = {};
+
+static void c_screen(void *data, struct ivi_controller *ivi_controller,
+ uint32_t id_screen, struct ivi_controller_screen *screen) {
+ lognotice("ivi_controller @ %p screen %u (%x) @ %p", ivi_controller,
+ id_screen, id_screen, screen);
+}
+
+static void c_layer(void *data, struct ivi_controller *ivi_controller,
+ uint32_t id_layer) {
+ lognotice("ivi_controller @ %p layer %u (%x)", ivi_controller, id_layer,
+ id_layer);
+ auto c = static_cast<conn *>(data);
+ auto i = std::make_unique<ivi_layer>(
+ ivi_controller_layer_create(c->c, id_layer, 0, 0), id_layer, c);
+ ivi_controller_layer_add_listener(i->controller, &cl_listener, i.get());
+ c->layers[id_layer] = std::move(i);
+}
+
+static void c_surface(void *data, struct ivi_controller *ivi_controller,
+ uint32_t id_surface) {
+ lognotice("ivi_controller @ %p surface %u (%x)", ivi_controller, id_surface,
+ id_surface);
+ auto c = static_cast<conn *>(data);
+ auto i = std::make_unique<ivi_surface>(
+ ivi_controller_surface_create(c->c, id_surface), id_surface, c);
+ ivi_controller_surface_add_listener(i->controller, &cs_listener, i.get());
+ c->surfaces[id_surface] = std::move(i);
+}
+
+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) {
+ lognotice("ivi_controller @ %p error o %i t %i c %i text %s", ivi_controller,
+ object_id, object_type, error_code, error_text);
+}
+
+static 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) {
+ lognotice("output @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
+ wl_output, x, y, physical_width, physical_height, subpixel, make,
+ model, transform);
+}
+
+static void o_mode(void *data, struct wl_output *wl_output, uint32_t flags,
+ int32_t width, int32_t height, int32_t refresh) {
+ lognotice("output @ %p mode f %x w %i h %i r %i", wl_output, flags, width,
+ height, refresh);
+}
+
+static void o_done(void *data, struct wl_output *wl_output) {
+ lognotice("output @ %p done");
+}
+
+static void o_scale(void *data, struct wl_output *wl_output, int32_t factor) {
+ lognotice("output @ %p scale %i", wl_output, factor);
+}
+
+static 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 = static_cast<conn *>(data);
+
+ if (strcmp(iface, "ivi_controller") == 0) {
+ c->c = static_cast<ivi_controller *>(
+ 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) {
+ auto o = static_cast<wl_output *>(
+ wl_registry_bind(r, name, &wl_output_interface, v));
+ c->outputs.emplace_back(std::unique_ptr<wl_output, void (*)(wl_output *)>(
+ o, wl_output_destroy));
+ wl_output_add_listener(o, &o_listener, c);
+ } else {
+ lognotice("registry @ %p global n %u i %s v %u", r, name, iface, v);
+ }
+}
+
+static void r_global_remove(void *data, struct wl_registry *r, uint32_t name) {}
+
+static 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 = {};
+
+ 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
+
+ return 0;
+}
diff --git a/src/util.h b/src/util.h
index 7a15454..27d1015 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,8 +1,16 @@
#ifndef WM_UTIL_H
#define WM_UTIL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void lognotice(char const *fmt, ...);
void logerror(char const *fmt, ...);
void fatal(char const *fmt, ...);
+#ifdef __cplusplus
+}
+#endif
+
#endif // !WM_UTIL_H