summaryrefslogtreecommitdiffstats
path: root/src/app.cpp
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-04 17:56:18 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-04 17:56:18 +0200
commite0cc310d3f9b6a2a005c5dd3d3adf6bb16bd8277 (patch)
tree36daa90535858dd7c3e4bf7dfca547b17ac738f4 /src/app.cpp
parent1575879e922f6c49107ae13d769a057142acc66d (diff)
App: cleanup name/id mapping and its reverse
* Single name/id mapping in id_alloc. * Add Proxy methods to App. * Disable old API functions to activate surfaces by ID. Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src/app.cpp')
-rw-r--r--src/app.cpp83
1 files changed, 32 insertions, 51 deletions
diff --git a/src/app.cpp b/src/app.cpp
index b8d3a86..6a3e2e6 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -128,7 +128,6 @@ App::App(wl::display *d)
config(),
layouts(),
layers(),
- name_mapping(),
id_alloc{},
last_active() {
assert(g_app == nullptr);
@@ -357,14 +356,25 @@ void App::surface_set_layout(uint32_t surface_id) {
if (surface_id == static_cast<unsigned>(this->layers.main_surface)) {
logdebug("Activating main_surface (%d)", surface_id);
- this->activate_surface(surface_id);
+ this->activate_surface(this->lookup_name(surface_id).value_or("unknown-name").c_str());
}
logdebug("Surface %u now on layer %u with rect { %d, %d, %d, %d }",
surface_id, layer_id, x, y, w, h);
}
-char const *App::activate_surface(uint32_t surface_id) {
+char const *App::activate_surface(char const *drawing_name) {
+ int surface_id = -1;
+
+ {
+ auto oid = this->lookup_id(drawing_name);
+ if (oid) {
+ surface_id = oid.value();
+ } else {
+ return "Surface does not exist";
+ }
+ }
+
if (!this->controller->surface_exists(surface_id)) {
return "Surface does not exist";
}
@@ -400,7 +410,18 @@ char const *App::activate_surface(uint32_t surface_id) {
return nullptr;
}
-char const *App::deactivate_surface(uint32_t surface_id) {
+char const *App::deactivate_surface(char const *drawing_name) {
+ int surface_id = -1;
+
+ {
+ auto oid = this->lookup_id(drawing_name);
+ if (oid) {
+ surface_id = oid.value();
+ } else {
+ return "Surface does not exist";
+ }
+ }
+
if (surface_id == this->layers.main_surface) {
return "Cannot deactivate main_surface";
}
@@ -426,9 +447,9 @@ char const *App::deactivate_surface(uint32_t surface_id) {
if (! this->last_active.empty()) {
// Should be active already, shouldn't it?
- this->activate_surface(this->last_active.front());
+ this->activate_surface(this->lookup_name(this->last_active.front()).value_or("unknown-name").c_str());
} else {
- this->activate_surface(this->layers.main_surface);
+ this->activate_surface(this->layers.main_surface_name.c_str());
}
return nullptr;
@@ -500,7 +521,7 @@ result<int> App::request_surface(char const *drawing_name) {
if (!this->layers.main_surface_name.empty() &&
this->layers.main_surface_name == drawing_name) {
this->layers.main_surface = id;
- this->activate_surface(id);
+ this->activate_surface(drawing_name);
logdebug("Set main_surface id to %u", id);
}
@@ -511,36 +532,6 @@ result<int> App::request_surface(char const *drawing_name) {
return Err<int>("Surface already present");
}
-char const *App::activate_surface(char const *drawing_name) {
- auto osid = this->id_alloc.lookup(drawing_name);
-
- if (osid) {
- logdebug("ativate surface with name %s and id %u", drawing_name,
- osid.value());
- auto ret = this->activate_surface(osid.value());
- if (!ret) {
- this->emit_activated(drawing_name);
- }
- return ret;
- }
-
- logerror("surface %s unknown", drawing_name);
- return "Surface unknown";
-}
-
-char const *App::deactivate_surface(char const *drawing_name) {
- auto osid = this->id_alloc.lookup(drawing_name);
-
- if (osid) {
- logdebug("deativate surface with name %s and id %u", drawing_name,
- osid.value());
- return this->deactivate_surface(osid.value());
- }
-
- logerror("surface %s unknown", drawing_name);
- return "Surface unknown";
-}
-
// _ _ _ _ _ _ _
// | |__ (_)_ __ __| (_)_ __ __ _ __ _ _ __ (_) (_)_ __ ___ _ __ | |
// | '_ \| | '_ \ / _` | | '_ \ / _` | / _` | '_ \| | | | '_ ` _ \| '_ \| |
@@ -582,7 +573,7 @@ binding_api::result_type binding_api::enddraw(char const* drawing_name) {
binding_api::result_type binding_api::list_drawing_names() {
logdebug("%s", __func__);
- json j = this->app->id_alloc.names;
+ json j = this->app->id_alloc.name2id;
return Ok(json_tokener_parse(j.dump().c_str()));
}
@@ -612,22 +603,12 @@ binding_api::result_type binding_api::debug_terminate() {
return Ok(json_object_new_object());
}
-binding_api::result_type binding_api::demo_activate_surface(
- uint32_t surfaceid) {
- char const *e = this->app->activate_surface(surfaceid);
- if (e != nullptr) {
- return Err<json_object *>(e);
- }
- return Ok(json_object_new_object());
+binding_api::result_type binding_api::demo_activate_surface(uint32_t s) {
+ return Err<json_object *>("not implemented");
}
binding_api::result_type binding_api::demo_activate_all() {
- for (auto &s : this->app->controller->surfaces) {
- s.second->set_visibility(1);
- }
- this->app->controller->commit_changes();
- this->app->display->flush();
- return Ok(json_object_new_object());
+ return Err<json_object *>("not implemented");
}
// _ _ _ _ _