commit f013665af293c88769d6e6d40d2c732eb17cc68f
parent 4e6dfa7c08712b4ac2fb51ad30156e8f737cc44c
Author: deurzen <m.deurzen@tum.de>
Date: Sun, 26 Sep 2021 22:50:21 +0200
refactors code
Diffstat:
4 files changed, 119 insertions(+), 14 deletions(-)
diff --git a/src/core/model.cc b/src/core/model.cc
@@ -863,12 +863,12 @@ Model::acquire_partitions()
if (connected_outputs.size() > m_contexts.size()) {
// TODO: generate more contexts?
- spdlog::warn("more outputs than available contexts");
+ spdlog::info("more outputs than available contexts");
return;
}
if (connected_outputs.empty()) {
- spdlog::warn("could not acquire any partitions");
+ spdlog::info("could not acquire any partitions");
return;
}
@@ -3390,17 +3390,17 @@ Model::handle_mouse(MouseEvent event)
MouseInput input = event.capture.input;
switch (event.capture.kind) {
- case MouseCapture::MouseCaptureKind::Release:
+ case MouseCapture::MouseCaptureKind::Motion:
{
- stop_moving();
- stop_resizing();
+ perform_move(event.capture.root_rpos);
+ perform_resize(event.capture.root_rpos);
return;
}
- case MouseCapture::MouseCaptureKind::Motion:
+ case MouseCapture::MouseCaptureKind::Release:
{
- perform_move(event.capture.root_rpos);
- perform_resize(event.capture.root_rpos);
+ stop_moving();
+ stop_resizing();
return;
}
diff --git a/src/winsys/geometry.cc b/src/winsys/geometry.cc
@@ -5,14 +5,14 @@
using namespace winsys;
void
-Region::apply_minimum_dim(const Dim& dim)
+Region::apply_minimum_dim(Dim const& dim)
{
this->dim.w = std::max(this->dim.w, dim.w);
this->dim.h = std::max(this->dim.h, dim.h);
}
void
-Region::apply_extents(const Extents& extents)
+Region::apply_extents(Extents const& extents)
{
pos.x -= extents.left;
pos.y -= extents.top;
@@ -21,10 +21,32 @@ Region::apply_extents(const Extents& extents)
}
void
-Region::remove_extents(const Extents& extents)
+Region::remove_extents(Extents const& extents)
{
pos.x += extents.left;
pos.y += extents.top;
dim.w -= extents.left + extents.right;
dim.h -= extents.top + extents.bottom;
}
+
+bool
+Region::contains(Pos pos) const
+{
+ return pos.x >= this->pos.x
+ && pos.y >= this->pos.y
+ && pos.x < this->pos.x + this->dim.w
+ && pos.y < this->pos.y + this->dim.h;
+}
+
+bool
+Region::contains(Region const& region) const
+{
+ return contains(region.pos)
+ && contains(region.pos + region.dim);
+}
+
+Pos
+Region::center() const
+{
+ return pos + Pos::from_center_of_dim(dim);
+}
diff --git a/src/winsys/geometry.hh b/src/winsys/geometry.hh
@@ -4,6 +4,8 @@
#include "common.hh"
#include "window.hh"
+#include <ostream>
+
namespace winsys
{
@@ -41,6 +43,11 @@ namespace winsys
return lhs.w == rhs.w && lhs.h == rhs.h;
}
+ inline std::ostream&
+ operator<<(std::ostream& os, Dim const& dim) {
+ return os << "(" << dim.w << "×" << dim.h << ")";
+ }
+
struct Pos final
{
int x;
@@ -68,6 +75,47 @@ namespace winsys
return lhs.x == rhs.x && lhs.y == rhs.y;
}
+ inline std::ostream&
+ operator<<(std::ostream& os, Pos const& pos) {
+ return os << "(" << pos.x << ", " << pos.y << ")";
+ }
+
+ inline Pos
+ operator+(Pos const& pos1, Pos const& pos2)
+ {
+ return Pos{
+ pos1.x + pos2.x,
+ pos1.y + pos2.y
+ };
+ }
+
+ inline Pos
+ operator-(Pos const& pos1, Pos const& pos2)
+ {
+ return Pos{
+ pos1.x - pos2.x,
+ pos1.y - pos2.y
+ };
+ }
+
+ inline Pos
+ operator+(Pos const& pos, Dim const& dim)
+ {
+ return Pos{
+ pos.x + dim.w,
+ pos.y + dim.h
+ };
+ }
+
+ inline Pos
+ operator-(Pos const& pos, Dim const& dim)
+ {
+ return Pos{
+ pos.x - dim.w,
+ pos.y - dim.h
+ };
+ }
+
struct Padding final
{
int left;
@@ -78,14 +126,27 @@ namespace winsys
typedef Padding Extents;
+ inline std::ostream&
+ operator<<(std::ostream& os, Padding const& padding) {
+ return os << "[" << padding.left
+ << "; " << padding.top
+ << "; " << padding.right
+ << "; " << padding.bottom << "]";
+ }
+
struct Region final
{
Pos pos;
Dim dim;
- void apply_minimum_dim(const Dim&);
- void apply_extents(const Extents&);
- void remove_extents(const Extents&);
+ void apply_minimum_dim(Dim const&);
+ void apply_extents(Extents const&);
+ void remove_extents(Extents const&);
+
+ bool contains(Pos) const;
+ bool contains(Region const&) const;
+
+ Pos center() const;
};
inline bool
@@ -94,12 +155,22 @@ namespace winsys
return lhs.pos == rhs.pos && lhs.dim == rhs.dim;
}
+ inline std::ostream&
+ operator<<(std::ostream& os, Region const& region) {
+ return os << "[" << region.pos << " " << region.dim << "]";
+ }
+
struct Distance final
{
int dx;
int dy;
};
+ inline std::ostream&
+ operator<<(std::ostream& os, Distance const& dist) {
+ return os << "𝛿(" << dist.dx << ", " << dist.dy << ")";
+ }
+
struct Ratio final
{
int numerator;
diff --git a/src/winsys/screen.hh b/src/winsys/screen.hh
@@ -54,6 +54,18 @@ namespace winsys
return m_windows.count(window) > 0;
}
+ bool
+ contains(Pos pos) const
+ {
+ return m_full_region.contains(pos);
+ }
+
+ bool
+ contains(Region region) const
+ {
+ return m_full_region.contains(region);
+ }
+
Index
index() const
{