summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp66
-rw-r--r--src/app.hpp10
-rw-r--r--src/layers.hpp6
3 files changed, 36 insertions, 46 deletions
diff --git a/src/app.cpp b/src/app.cpp
index a6dd99c..a034fac 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -380,22 +380,17 @@ void App::surface_set_layout_split(uint32_t surface_id, uint32_t sub_surface_id)
}
char const *App::activate_surface(char const *drawing_name) {
- int surface_id = -1;
+ auto const &surface_id = this->lookup_id(drawing_name);
- {
- auto oid = this->lookup_id(drawing_name);
- if (oid) {
- surface_id = oid.value();
- } else {
- return "Surface does not exist";
- }
+ if (!surface_id) {
+ return "Surface does not exist";
}
- if (!this->controller->surface_exists(surface_id)) {
- return "Surface does not exist";
+ if (!this->controller->surface_exists(*surface_id)) {
+ return "Surface does not exist in controller!";
}
- if (this->state.main == surface_id || this->state.sub == surface_id) {
+ if (this->state.main == *surface_id || this->state.sub == *surface_id) {
return "Surface already active";
}
@@ -404,7 +399,7 @@ char const *App::activate_surface(char const *drawing_name) {
// XXX: input focus missing!!1
// Make it visible, no (or little effect) if already visible
- auto &s = this->controller->surfaces[surface_id];
+ auto &s = this->controller->surfaces[*surface_id];
//// Set all others invisible
//for (auto &i : this->controller->surfaces) {
@@ -416,27 +411,27 @@ char const *App::activate_surface(char const *drawing_name) {
//}
if (this->state.main == -1) {
- this->surface_set_layout_full(surface_id);
- this->activate(surface_id);
- this->state.main = surface_id;
+ this->surface_set_layout_full(*surface_id);
+ this->activate(*surface_id);
+ this->state.main = *surface_id;
this->state.sub = -1;
this->state.s = LayoutState::Single;
} else {
- bool can_split = this->can_split(surface_id);
+ bool can_split = this->can_split(*surface_id);
if (this->state.sub == -1) {
if (can_split) {
- if (this->state.main != surface_id) {
+ if (this->state.main != *surface_id) {
this->surface_set_layout_split(this->state.main,
- this->state.sub = surface_id);
+ this->state.sub = *surface_id);
this->activate(this->state.sub);
}
} else {
- this->surface_set_layout_full(surface_id);
+ this->surface_set_layout_full(*surface_id);
this->deactivate(this->state.main);
- this->activate(surface_id);
+ this->activate(*surface_id);
this->deactivate(this->state.sub);
- this->state.main = surface_id;
+ this->state.main = *surface_id;
this->state.sub = -1;
this->state.s = LayoutState::Single;
}
@@ -452,37 +447,32 @@ char const *App::activate_surface(char const *drawing_name) {
}
char const *App::deactivate_surface(char const *drawing_name) {
- int surface_id = -1;
+ auto const &surface_id = this->lookup_id(drawing_name);
- {
- auto oid = this->lookup_id(drawing_name);
- if (oid) {
- surface_id = oid.value();
- } else {
- return "Surface does not exist";
- }
+ if (!surface_id) {
+ return "Surface does not exist";
}
- if (surface_id == this->layers.main_surface) {
+ if (*surface_id == this->layers.main_surface) {
return "Cannot deactivate main_surface";
}
if (this->state.main == -1) {
return "No surface active";
} else {
- if (this->state.main == surface_id) {
+ if (this->state.main == *surface_id) {
if (this->state.sub != -1) {
- this->deactivate(surface_id);
+ this->deactivate(*surface_id);
this->surface_set_layout_full(this->state.sub);
this->state.main = this->state.sub;
this->state.sub = -1;
this->state.s = LayoutState::Single;
} else {
- this->deactivate(surface_id);
+ this->deactivate(*surface_id);
this->state.main = -1;
}
- }else if (this->state.sub == surface_id) {
- this->deactivate(surface_id);
+ }else if (this->state.sub == *surface_id) {
+ this->deactivate(*surface_id);
this->surface_set_layout_full(this->state.main);
this->state.sub = -1;
this->state.s = LayoutState::Single;
@@ -578,7 +568,7 @@ result<int> App::request_surface(char const *drawing_name) {
return Err<int>("Surface already present");
}
-void App::activate(unsigned id) {
+void App::activate(int id) {
if (this->controller->sprops[id].visibility == 0) {
this->controller->surfaces[id]->set_visibility(1);
char const *label =
@@ -588,7 +578,7 @@ void App::activate(unsigned id) {
}
}
-void App::deactivate(unsigned id) {
+void App::deactivate(int id) {
if (this->controller->sprops[id].visibility != 0) {
this->controller->surfaces[id]->set_visibility(0);
char const *label =
@@ -598,7 +588,7 @@ void App::deactivate(unsigned id) {
}
}
-bool App::can_split(unsigned new_id) {
+bool App::can_split(int new_id) {
if (this->state.main != -1 && this->state.main != new_id) {
auto new_id_layer = this->layers.get_layer_id(new_id).value();
auto current_id_layer =
diff --git a/src/app.hpp b/src/app.hpp
index c8ea01b..297b6af 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -120,10 +120,10 @@ struct App {
// ID allocation and proxy methods for lookup
struct id_allocator id_alloc;
- optional<unsigned> lookup_id(char const *name) {
+ optional<int> lookup_id(char const *name) {
return this->id_alloc.lookup(std::string(name));
}
- optional<std::string> lookup_name(unsigned id) {
+ optional<std::string> lookup_name(int id) {
return this->id_alloc.lookup(id);
}
@@ -177,10 +177,10 @@ struct App {
void emit_invisible(char const *label);
void emit_visible(char const *label);
- void activate(unsigned id);
- void deactivate(unsigned id);
+ void activate(int id);
+ void deactivate(int id);
- bool can_split(unsigned new_id);
+ bool can_split(int new_id);
};
} // namespace wm
diff --git a/src/layers.hpp b/src/layers.hpp
index 0601614..ee32054 100644
--- a/src/layers.hpp
+++ b/src/layers.hpp
@@ -71,9 +71,9 @@ struct layer_map {
using json = nlohmann::json;
using storage_type = std::set<struct layer>;
- using layers_type = std::vector<unsigned int>;
+ using layers_type = std::vector<uint32_t>;
using role_to_layer_map = std::vector<std::pair<std::string, int>>;
- using addsurf_layer_map = std::map<unsigned, unsigned>;
+ using addsurf_layer_map = std::map<int, int>;
// XXX: we also will need a layer_id to layer map, perhaps
// make this the primary map, and the surface_id->layer a
@@ -100,7 +100,7 @@ struct layer_map {
return this->layers.size();
}
- void add_surface(unsigned surface_id, unsigned layer_id) {
+ void add_surface(int surface_id, int layer_id) {
this->surfaces[surface_id] = layer_id;
}