app/main: dispatch wayland events using ping(), WIP on split layout
[staging/windowmanager.git] / src / app.hpp
index 37122ef..00a2ba2 100644 (file)
 #define TMCAGLWM_APP_HPP
 
 #include <json-c/json.h>
+
+#include <atomic>
 #include <memory>
 #include <unordered_map>
 #include <unordered_set>
-#include <deque>
+#include <experimental/optional>
 
 #include "afb_binding_api.hpp"
 #include "config.hpp"
@@ -41,6 +43,8 @@ struct controller;
 
 namespace wm {
 
+using std::experimental::optional;
+
 struct id_allocator {
    constexpr static const unsigned id_shift = 22;
    constexpr static const unsigned id_mask = (1 << id_shift) - 1;
@@ -100,13 +104,21 @@ struct id_allocator {
 
 struct LayoutState {
    enum States {
+      LayoutNone,  // Not useful...
       LayoutSingle,
       LayoutSplit,
    };
 
-   enum States state;
-   int main;
-   int sub;
+   enum States state{LayoutSingle};
+   int main{-1};
+   int sub{-1};
+
+   bool operator==(const LayoutState &b) const {
+      return state == b.state && main == b.main && sub == b.sub;
+   }
+   bool operator!=(const LayoutState &b) const {
+      return !(*this == b);
+   }
 };
 
 struct App {
@@ -121,7 +133,8 @@ struct App {
 
    struct config config;
 
-   layouts_type layouts;
+   // track current layouts separately
+   std::map<int, struct LayoutState> layouts;
    layer_map layers;
 
    // ID allocation and proxy methods for lookup
@@ -135,6 +148,8 @@ struct App {
 
    struct LayoutState state;
 
+   std::atomic<bool> pending_events;
+
    explicit App(wl::display *d);
    ~App();
 
@@ -148,7 +163,8 @@ struct App {
 
    int dispatch_events();
 
-   void surface_init_layout(uint32_t surface_id);
+   void surface_set_layout_full(uint32_t surface_id);
+   void surface_set_layout_split(uint32_t surface_id, uint32_t sub_surface_id);
 
    // Allocate a surface ID for this role
    result<int> request_surface(char const *drawing_name);