refactor: ProtocolTypes EDirection => enum class Direction

This commit is contained in:
sithlord48 2025-07-03 15:12:35 -04:00 committed by Nick Bolton
parent dded2e3711
commit f12f312dab
10 changed files with 160 additions and 150 deletions

View file

@ -79,7 +79,7 @@ public:
//! Update configuration //! Update configuration
/*! /*!
This is called when the configuration has changed. \c activeSides This is called when the configuration has changed. \c activeSides
is a bitmask of EDirectionMask indicating which sides of the is a bitmask of DirectionMask indicating which sides of the
primary screen are linked to clients. Override to handle the primary screen are linked to clients. Override to handle the
possible change in jump zones. possible change in jump zones.
*/ */

View file

@ -158,16 +158,16 @@ static constexpr uint32_t PROTOCOL_MAX_STRING_LENGTH = 1024 * 1024;
* *
* @since Protocol version 1.0 * @since Protocol version 1.0
*/ */
enum EDirection enum class Direction : uint8_t
{ {
kNoDirection, ///< No specific direction NoDirection, ///< No specific direction
kLeft, ///< Left edge of screen Left, ///< Left edge of screen
kRight, ///< Right edge of screen Right, ///< Right edge of screen
kTop, ///< Top edge of screen Top, ///< Top edge of screen
kBottom, ///< Bottom edge of screen Bottom, ///< Bottom edge of screen
kFirstDirection = kLeft, ///< First valid direction value FirstDirection = Direction::Left, ///< First valid direction value
kLastDirection = kBottom, ///< Last valid direction value LastDirection = Direction::Bottom, ///< Last valid direction value
kNumDirections = kLastDirection - kFirstDirection + 1 ///< Total number of directions NumDirections = Direction::LastDirection - Direction::FirstDirection + 1 ///< Total number of directions
}; };
/** /**
@ -180,11 +180,11 @@ enum EDirection
*/ */
enum class DirectionMask enum class DirectionMask
{ {
NoDirMask = 0, ///< No direction mask NoDirMask = 0, ///< No direction mask
LeftMask = 1 << kLeft, ///< Left edge mask LeftMask = 1 << static_cast<int>(Direction::Left), ///< Left edge mask
RightMask = 1 << kRight, ///< Right edge mask RightMask = 1 << static_cast<int>(Direction::Right), ///< Right edge mask
TopMask = 1 << kTop, ///< Top edge mask TopMask = 1 << static_cast<int>(Direction::Top), ///< Top edge mask
BottomMask = 1 << kBottom ///< Bottom edge mask BottomMask = 1 << static_cast<int>(Direction::Bottom) ///< Bottom edge mask
}; };
/** /**

View file

@ -71,7 +71,7 @@ public:
//! Update configuration //! Update configuration
/*! /*!
This is called when the configuration has changed. \c activeSides This is called when the configuration has changed. \c activeSides
is a bitmask of EDirectionMask indicating which sides of the is a bitmask of DirectionMask indicating which sides of the
primary screen are linked to clients. primary screen are linked to clients.
*/ */
void reconfigure(uint32_t activeSides); void reconfigure(uint32_t activeSides);

View file

@ -197,11 +197,11 @@ void Config::removeAllAliases()
} }
bool Config::connect( bool Config::connect(
const std::string &srcName, EDirection srcSide, float srcStart, float srcEnd, const std::string &dstName, const std::string &srcName, Direction srcSide, float srcStart, float srcEnd, const std::string &dstName,
float dstStart, float dstEnd float dstStart, float dstEnd
) )
{ {
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); assert(srcSide >= Direction::FirstDirection && srcSide <= Direction::LastDirection);
// find source cell // find source cell
CellMap::iterator index = m_map.find(getCanonicalName(srcName)); CellMap::iterator index = m_map.find(getCanonicalName(srcName));
@ -215,9 +215,9 @@ bool Config::connect(
return index->second.add(srcEdge, dstEdge); return index->second.add(srcEdge, dstEdge);
} }
bool Config::disconnect(const std::string &srcName, EDirection srcSide) bool Config::disconnect(const std::string &srcName, Direction srcSide)
{ {
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); assert(srcSide >= Direction::FirstDirection && srcSide <= Direction::LastDirection);
// find source cell // find source cell
CellMap::iterator index = m_map.find(srcName); CellMap::iterator index = m_map.find(srcName);
@ -231,9 +231,9 @@ bool Config::disconnect(const std::string &srcName, EDirection srcSide)
return true; return true;
} }
bool Config::disconnect(const std::string &srcName, EDirection srcSide, float position) bool Config::disconnect(const std::string &srcName, Direction srcSide, float position)
{ {
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); assert(srcSide >= Direction::FirstDirection && srcSide <= Direction::LastDirection);
// find source cell // find source cell
CellMap::iterator index = m_map.find(srcName); CellMap::iterator index = m_map.find(srcName);
@ -405,10 +405,9 @@ std::string Config::getCanonicalName(const std::string &name) const
} }
} }
std::string std::string Config::getNeighbor(const std::string &srcName, Direction srcSide, float position, float *positionOut) const
Config::getNeighbor(const std::string &srcName, EDirection srcSide, float position, float *positionOut) const
{ {
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); assert(srcSide >= Direction::FirstDirection && srcSide <= Direction::LastDirection);
// find source cell // find source cell
CellMap::const_iterator index = m_map.find(getCanonicalName(srcName)); CellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
@ -433,14 +432,14 @@ Config::getNeighbor(const std::string &srcName, EDirection srcSide, float positi
} }
} }
bool Config::hasNeighbor(const std::string &srcName, EDirection srcSide) const bool Config::hasNeighbor(const std::string &srcName, Direction srcSide) const
{ {
return hasNeighbor(srcName, srcSide, 0.0f, 1.0f); return hasNeighbor(srcName, srcSide, 0.0f, 1.0f);
} }
bool Config::hasNeighbor(const std::string &srcName, EDirection srcSide, float start, float end) const bool Config::hasNeighbor(const std::string &srcName, Direction srcSide, float start, float end) const
{ {
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection); assert(srcSide >= Direction::FirstDirection && srcSide <= Direction::LastDirection);
// find source cell // find source cell
CellMap::const_iterator index = m_map.find(getCanonicalName(srcName)); CellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
@ -556,13 +555,13 @@ void Config::read(ConfigReadContext &context)
*this = tmp; *this = tmp;
} }
const char *Config::dirName(EDirection dir) const char *Config::dirName(Direction dir)
{ {
static const char *s_name[] = {"left", "right", "up", "down"}; static const char *s_name[] = {"left", "right", "up", "down"};
assert(dir >= kFirstDirection && dir <= kLastDirection); assert(dir >= Direction::FirstDirection && dir <= Direction::LastDirection);
return s_name[dir - kFirstDirection]; return s_name[static_cast<int>(dir) - static_cast<int>(Direction::FirstDirection)];
} }
InputFilter *Config::getInputFilter() InputFilter *Config::getInputFilter()
@ -855,15 +854,16 @@ void Config::readSectionLinks(ConfigReadContext &s)
Interval dstInterval(s.parseInterval(dstArgs)); Interval dstInterval(s.parseInterval(dstArgs));
// handle argument // handle argument
EDirection dir; using enum Direction;
Direction dir;
if (side == "left") { if (side == "left") {
dir = kLeft; dir = Left;
} else if (side == "right") { } else if (side == "right") {
dir = kRight; dir = Right;
} else if (side == "up") { } else if (side == "up") {
dir = kTop; dir = Top;
} else if (side == "down") { } else if (side == "down") {
dir = kBottom; dir = Bottom;
} else { } else {
// unknown argument // unknown argument
throw XConfigRead(s, "unknown side \"%{1}\" in link", side); throw XConfigRead(s, "unknown side \"%{1}\" in link", side);
@ -1048,15 +1048,16 @@ void Config::parseAction(
throw XConfigRead(s, "syntax for action: switchInDirection(<left|right|up|down>)"); throw XConfigRead(s, "syntax for action: switchInDirection(<left|right|up|down>)");
} }
EDirection direction; Direction direction;
using enum Direction;
if (args[0] == "left") { if (args[0] == "left") {
direction = kLeft; direction = Left;
} else if (args[0] == "right") { } else if (args[0] == "right") {
direction = kRight; direction = Right;
} else if (args[0] == "up") { } else if (args[0] == "up") {
direction = kTop; direction = Top;
} else if (args[0] == "down") { } else if (args[0] == "down") {
direction = kBottom; direction = Bottom;
} else { } else {
throw XConfigRead(s, "unknown direction \"%{1}\" in switchToScreen", args[0]); throw XConfigRead(s, "unknown direction \"%{1}\" in switchToScreen", args[0]);
} }
@ -1343,12 +1344,12 @@ bool Config::Name::operator==(const std::string &name) const
// Config::CellEdge // Config::CellEdge
// //
Config::CellEdge::CellEdge(EDirection side, float position) Config::CellEdge::CellEdge(Direction side, float position)
{ {
init("", side, Interval(position, position)); init("", side, Interval(position, position));
} }
Config::CellEdge::CellEdge(EDirection side, const Interval &interval) Config::CellEdge::CellEdge(Direction side, const Interval &interval)
{ {
assert(interval.first >= 0.0f); assert(interval.first >= 0.0f);
assert(interval.second <= 1.0f); assert(interval.second <= 1.0f);
@ -1357,7 +1358,7 @@ Config::CellEdge::CellEdge(EDirection side, const Interval &interval)
init("", side, interval); init("", side, interval);
} }
Config::CellEdge::CellEdge(const std::string &name, EDirection side, const Interval &interval) Config::CellEdge::CellEdge(const std::string &name, Direction side, const Interval &interval)
{ {
assert(interval.first >= 0.0f); assert(interval.first >= 0.0f);
assert(interval.second <= 1.0f); assert(interval.second <= 1.0f);
@ -1366,9 +1367,9 @@ Config::CellEdge::CellEdge(const std::string &name, EDirection side, const Inter
init(name, side, interval); init(name, side, interval);
} }
void Config::CellEdge::init(const std::string_view &name, EDirection side, const Interval &interval) void Config::CellEdge::init(const std::string_view &name, Direction side, const Interval &interval)
{ {
assert(side != kNoDirection); assert(side != Direction::NoDirection);
m_name = name; m_name = name;
m_side = side; m_side = side;
@ -1390,7 +1391,7 @@ std::string Config::CellEdge::getName() const
return m_name; return m_name;
} }
EDirection Config::CellEdge::getSide() const Direction Config::CellEdge::getSide() const
{ {
return m_side; return m_side;
} }
@ -1459,7 +1460,7 @@ bool Config::Cell::add(const CellEdge &src, const CellEdge &dst)
return true; return true;
} }
void Config::Cell::remove(EDirection side) void Config::Cell::remove(Direction side)
{ {
for (auto j = m_neighbors.begin(); j != m_neighbors.end();) { for (auto j = m_neighbors.begin(); j != m_neighbors.end();) {
if (j->first.getSide() == side) { if (j->first.getSide() == side) {
@ -1470,7 +1471,7 @@ void Config::Cell::remove(EDirection side)
} }
} }
void Config::Cell::remove(EDirection side, float position) void Config::Cell::remove(Direction side, float position)
{ {
for (auto j = m_neighbors.begin(); j != m_neighbors.end(); ++j) { for (auto j = m_neighbors.begin(); j != m_neighbors.end(); ++j) {
if (j->first.getSide() == side && j->first.isInside(position)) { if (j->first.getSide() == side && j->first.isInside(position)) {
@ -1517,7 +1518,7 @@ bool Config::Cell::overlaps(const CellEdge &edge) const
return false; return false;
} }
bool Config::Cell::getLink(EDirection side, float position, const CellEdge *&src, const CellEdge *&dst) const bool Config::Cell::getLink(Direction side, float position, const CellEdge *&src, const CellEdge *&dst) const
{ {
CellEdge edge(side, position); CellEdge edge(side, position);
EdgeLinks::const_iterator i = m_neighbors.upper_bound(edge); EdgeLinks::const_iterator i = m_neighbors.upper_bound(edge);

View file

@ -58,15 +58,15 @@ public:
class CellEdge class CellEdge
{ {
public: public:
CellEdge(EDirection side, float position); CellEdge(Direction side, float position);
CellEdge(EDirection side, const Interval &); CellEdge(Direction side, const Interval &);
CellEdge(const std::string &name, EDirection side, const Interval &); CellEdge(const std::string &name, Direction side, const Interval &);
~CellEdge() = default; ~CellEdge() = default;
Interval getInterval() const; Interval getInterval() const;
void setName(const std::string_view &newName); void setName(const std::string_view &newName);
std::string getName() const; std::string getName() const;
EDirection getSide() const; Direction getSide() const;
bool overlaps(const CellEdge &) const; bool overlaps(const CellEdge &) const;
bool isInside(float x) const; bool isInside(float x) const;
@ -84,11 +84,11 @@ public:
bool operator!=(const CellEdge &) const; bool operator!=(const CellEdge &) const;
private: private:
void init(const std::string_view &name, EDirection side, const Interval &); void init(const std::string_view &name, Direction side, const Interval &);
private: private:
std::string m_name; std::string m_name;
EDirection m_side; Direction m_side;
Interval m_interval; Interval m_interval;
}; };
@ -114,15 +114,15 @@ private:
using const_iterator = EdgeLinks::const_iterator; using const_iterator = EdgeLinks::const_iterator;
bool add(const CellEdge &src, const CellEdge &dst); bool add(const CellEdge &src, const CellEdge &dst);
void remove(EDirection side); void remove(Direction side);
void remove(EDirection side, float position); void remove(Direction side, float position);
void remove(const Name &destinationName); void remove(const Name &destinationName);
void rename(const Name &oldName, const std::string &newName); void rename(const Name &oldName, const std::string &newName);
bool hasEdge(const CellEdge &) const; bool hasEdge(const CellEdge &) const;
bool overlaps(const CellEdge &) const; bool overlaps(const CellEdge &) const;
bool getLink(EDirection side, float position, const CellEdge *&src, const CellEdge *&dst) const; bool getLink(Direction side, float position, const CellEdge *&src, const CellEdge *&dst) const;
bool operator==(const Cell &) const; bool operator==(const Cell &) const;
bool operator!=(const Cell &) const; bool operator!=(const Cell &) const;
@ -278,7 +278,7 @@ public:
be inside the range [0,1]. be inside the range [0,1].
*/ */
bool connect( bool connect(
const std::string &srcName, EDirection srcSide, float srcStart, float srcEnd, const std::string &dstName, const std::string &srcName, Direction srcSide, float srcStart, float srcEnd, const std::string &dstName,
float dstStart, float dstEnd float dstStart, float dstEnd
); );
@ -287,7 +287,7 @@ public:
Removes all connections created by connect() on side \c srcSide. Removes all connections created by connect() on side \c srcSide.
Returns false if \c srcName is unknown. Returns false if \c srcName is unknown.
*/ */
bool disconnect(const std::string &srcName, EDirection srcSide); bool disconnect(const std::string &srcName, Direction srcSide);
//! Disconnect screens //! Disconnect screens
/*! /*!
@ -295,7 +295,7 @@ public:
covering position \c position. Returns false if \c srcName is covering position \c position. Returns false if \c srcName is
unknown. unknown.
*/ */
bool disconnect(const std::string &srcName, EDirection srcSide, float position); bool disconnect(const std::string &srcName, Direction srcSide, float position);
//! Set server address //! Set server address
/*! /*!
@ -381,21 +381,21 @@ public:
saves the position on the neighbor in \c positionOut if it's not saves the position on the neighbor in \c positionOut if it's not
\c nullptr. \c nullptr.
*/ */
std::string getNeighbor(const std::string &, EDirection, float position, float *positionOut) const; std::string getNeighbor(const std::string &, Direction, float position, float *positionOut) const;
//! Check for neighbor //! Check for neighbor
/*! /*!
Returns \c true if the screen has a neighbor anywhere along the edge Returns \c true if the screen has a neighbor anywhere along the edge
given by the direction. given by the direction.
*/ */
bool hasNeighbor(const std::string &, EDirection) const; bool hasNeighbor(const std::string &, Direction) const;
//! Check for neighbor //! Check for neighbor
/*! /*!
Returns \c true if the screen has a neighbor in the given range along Returns \c true if the screen has a neighbor in the given range along
the edge given by the direction. the edge given by the direction.
*/ */
bool hasNeighbor(const std::string &, EDirection, float start, float end) const; bool hasNeighbor(const std::string &, Direction, float start, float end) const;
//! Get beginning neighbor iterator //! Get beginning neighbor iterator
link_const_iterator beginNeighbor(const std::string &) const; link_const_iterator beginNeighbor(const std::string &) const;
@ -448,7 +448,7 @@ public:
/*! /*!
Returns the name of a direction (for debugging). Returns the name of a direction (for debugging).
*/ */
static const char *dirName(EDirection); static const char *dirName(Direction);
//! Get interval as string //! Get interval as string
/*! /*!

View file

@ -297,14 +297,14 @@ void InputFilter::SwitchToScreenAction::perform(const Event &event)
m_events->addEvent(Event(EventTypes::ServerSwitchToScreen, event.getTarget(), info, Event::kDeliverImmediately)); m_events->addEvent(Event(EventTypes::ServerSwitchToScreen, event.getTarget(), info, Event::kDeliverImmediately));
} }
InputFilter::SwitchInDirectionAction::SwitchInDirectionAction(IEventQueue *events, EDirection direction) InputFilter::SwitchInDirectionAction::SwitchInDirectionAction(IEventQueue *events, Direction direction)
: m_direction(direction), : m_direction(direction),
m_events(events) m_events(events)
{ {
// do nothing // do nothing
} }
EDirection InputFilter::SwitchInDirectionAction::getDirection() const Direction InputFilter::SwitchInDirectionAction::getDirection() const
{ {
return m_direction; return m_direction;
} }
@ -318,7 +318,7 @@ std::string InputFilter::SwitchInDirectionAction::format() const
{ {
static const char *s_names[] = {"", "left", "right", "up", "down"}; static const char *s_names[] = {"", "left", "right", "up", "down"};
return deskflow::string::sprintf("switchInDirection(%s)", s_names[m_direction]); return deskflow::string::sprintf("switchInDirection(%s)", s_names[static_cast<int>(m_direction)]);
} }
void InputFilter::SwitchInDirectionAction::perform(const Event &event) void InputFilter::SwitchInDirectionAction::perform(const Event &event)

View file

@ -197,9 +197,9 @@ public:
class SwitchInDirectionAction : public Action class SwitchInDirectionAction : public Action
{ {
public: public:
SwitchInDirectionAction(IEventQueue *events, EDirection); SwitchInDirectionAction(IEventQueue *events, Direction);
EDirection getDirection() const; Direction getDirection() const;
// Action overrides // Action overrides
Action *clone() const override; Action *clone() const override;
@ -207,7 +207,7 @@ public:
void perform(const Event &) override; void perform(const Event &) override;
private: private:
EDirection m_direction; Direction m_direction;
IEventQueue *m_events; IEventQueue *m_events;
}; };

View file

@ -306,18 +306,19 @@ std::string Server::getName(const BaseClientProxy *client) const
uint32_t Server::getActivePrimarySides() const uint32_t Server::getActivePrimarySides() const
{ {
using enum DirectionMask; using enum DirectionMask;
using enum Direction;
uint32_t sides = 0; uint32_t sides = 0;
if (!isLockedToScreenServer()) { if (!isLockedToScreenServer()) {
if (hasAnyNeighbor(m_primaryClient, kLeft)) { if (hasAnyNeighbor(m_primaryClient, Left)) {
sides |= static_cast<int>(LeftMask); sides |= static_cast<int>(LeftMask);
} }
if (hasAnyNeighbor(m_primaryClient, kRight)) { if (hasAnyNeighbor(m_primaryClient, Right)) {
sides |= static_cast<int>(RightMask); sides |= static_cast<int>(RightMask);
} }
if (hasAnyNeighbor(m_primaryClient, kTop)) { if (hasAnyNeighbor(m_primaryClient, Top)) {
sides |= static_cast<int>(TopMask); sides |= static_cast<int>(TopMask);
} }
if (hasAnyNeighbor(m_primaryClient, kBottom)) { if (hasAnyNeighbor(m_primaryClient, Bottom)) {
sides |= static_cast<int>(BottomMask); sides |= static_cast<int>(BottomMask);
} }
} }
@ -490,7 +491,7 @@ void Server::jumpToScreen(BaseClientProxy *newScreen)
switchScreen(newScreen, x, y, false); switchScreen(newScreen, x, y, false);
} }
float Server::mapToFraction(const BaseClientProxy *client, EDirection dir, int32_t x, int32_t y) const float Server::mapToFraction(const BaseClientProxy *client, Direction dir, int32_t x, int32_t y) const
{ {
int32_t sx; int32_t sx;
int32_t sy; int32_t sy;
@ -498,22 +499,23 @@ float Server::mapToFraction(const BaseClientProxy *client, EDirection dir, int32
int32_t sh; int32_t sh;
client->getShape(sx, sy, sw, sh); client->getShape(sx, sy, sw, sh);
switch (dir) { switch (dir) {
case kLeft: using enum Direction;
case kRight: case Left:
case Right:
return static_cast<float>(y - sy + 0.5f) / static_cast<float>(sh); return static_cast<float>(y - sy + 0.5f) / static_cast<float>(sh);
case kTop: case Top:
case kBottom: case Bottom:
return static_cast<float>(x - sx + 0.5f) / static_cast<float>(sw); return static_cast<float>(x - sx + 0.5f) / static_cast<float>(sw);
case kNoDirection: case NoDirection:
assert(0 && "bad direction"); assert(0 && "bad direction");
break; break;
} }
return 0.0f; return 0.0f;
} }
void Server::mapToPixel(const BaseClientProxy *client, EDirection dir, float f, int32_t &x, int32_t &y) const void Server::mapToPixel(const BaseClientProxy *client, Direction dir, float f, int32_t &x, int32_t &y) const
{ {
int32_t sx; int32_t sx;
int32_t sy; int32_t sy;
@ -521,30 +523,31 @@ void Server::mapToPixel(const BaseClientProxy *client, EDirection dir, float f,
int32_t sh; int32_t sh;
client->getShape(sx, sy, sw, sh); client->getShape(sx, sy, sw, sh);
switch (dir) { switch (dir) {
case kLeft: using enum Direction;
case kRight: case Left:
case Right:
y = static_cast<int32_t>(f * sh) + sy; y = static_cast<int32_t>(f * sh) + sy;
break; break;
case kTop: case Top:
case kBottom: case Bottom:
x = static_cast<int32_t>(f * sw) + sx; x = static_cast<int32_t>(f * sw) + sx;
break; break;
case kNoDirection: case NoDirection:
assert(0 && "bad direction"); assert(0 && "bad direction");
break; break;
} }
} }
bool Server::hasAnyNeighbor(const BaseClientProxy *client, EDirection dir) const bool Server::hasAnyNeighbor(const BaseClientProxy *client, Direction dir) const
{ {
assert(client != nullptr); assert(client != nullptr);
return m_config->hasNeighbor(getName(client), dir); return m_config->hasNeighbor(getName(client), dir);
} }
BaseClientProxy *Server::getNeighbor(const BaseClientProxy *src, EDirection dir, int32_t &x, int32_t &y) const BaseClientProxy *Server::getNeighbor(const BaseClientProxy *src, Direction dir, int32_t &x, int32_t &y) const
{ {
// note -- must be locked on entry // note -- must be locked on entry
@ -589,7 +592,7 @@ BaseClientProxy *Server::getNeighbor(const BaseClientProxy *src, EDirection dir,
} }
} }
BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide, int32_t &x, int32_t &y) const BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, Direction srcSide, int32_t &x, int32_t &y) const
{ {
// note -- must be locked on entry // note -- must be locked on entry
@ -615,7 +618,8 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
// actual to canonical position on entry to and from canonical to // actual to canonical position on entry to and from canonical to
// actual on exit from the search. // actual on exit from the search.
switch (srcSide) { switch (srcSide) {
case kLeft: using enum Direction;
case Left:
x -= dx; x -= dx;
while (dst != nullptr) { while (dst != nullptr) {
lastGoodScreen = dst; lastGoodScreen = dst;
@ -631,7 +635,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
x += dx; x += dx;
break; break;
case kRight: case Right:
x -= dx; x -= dx;
while (dst != nullptr) { while (dst != nullptr) {
x -= dw; x -= dw;
@ -647,7 +651,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
x += dx; x += dx;
break; break;
case kTop: case Top:
y -= dy; y -= dy;
while (dst != nullptr) { while (dst != nullptr) {
lastGoodScreen = dst; lastGoodScreen = dst;
@ -663,7 +667,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
y += dy; y += dy;
break; break;
case kBottom: case Bottom:
y -= dy; y -= dy;
while (dst != nullptr) { while (dst != nullptr) {
y -= dh; y -= dh;
@ -679,7 +683,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
y += dy; y += dy;
break; break;
case kNoDirection: case NoDirection:
assert(0 && "bad direction"); assert(0 && "bad direction");
return nullptr; return nullptr;
} }
@ -697,7 +701,7 @@ BaseClientProxy *Server::mapToNeighbor(BaseClientProxy *src, EDirection srcSide,
return dst; return dst;
} }
void Server::avoidJumpZone(const BaseClientProxy *dst, EDirection dir, int32_t &x, int32_t &y) const void Server::avoidJumpZone(const BaseClientProxy *dst, Direction dir, int32_t &x, int32_t &y) const
{ {
// we only need to avoid jump zones on the primary screen // we only need to avoid jump zones on the primary screen
if (dst != m_primaryClient) { if (dst != m_primaryClient) {
@ -717,33 +721,34 @@ void Server::avoidJumpZone(const BaseClientProxy *dst, EDirection dir, int32_t &
// that doesn't have a neighbor (i.e. an asymmetrical side) then we // that doesn't have a neighbor (i.e. an asymmetrical side) then we
// don't need to move inwards because that side can't provoke a jump. // don't need to move inwards because that side can't provoke a jump.
switch (dir) { switch (dir) {
case kLeft: using enum Direction;
if (!m_config->getNeighbor(dstName, kRight, t, nullptr).empty() && x > dx + dw - 1 - z) case Left:
if (!m_config->getNeighbor(dstName, Right, t, nullptr).empty() && x > dx + dw - 1 - z)
x = dx + dw - 1 - z; x = dx + dw - 1 - z;
break; break;
case kRight: case Right:
if (!m_config->getNeighbor(dstName, kLeft, t, nullptr).empty() && x < dx + z) if (!m_config->getNeighbor(dstName, Left, t, nullptr).empty() && x < dx + z)
x = dx + z; x = dx + z;
break; break;
case kTop: case Top:
if (!m_config->getNeighbor(dstName, kBottom, t, nullptr).empty() && y > dy + dh - 1 - z) if (!m_config->getNeighbor(dstName, Bottom, t, nullptr).empty() && y > dy + dh - 1 - z)
y = dy + dh - 1 - z; y = dy + dh - 1 - z;
break; break;
case kBottom: case Bottom:
if (!m_config->getNeighbor(dstName, kTop, t, nullptr).empty() && y < dy + z) if (!m_config->getNeighbor(dstName, Top, t, nullptr).empty() && y < dy + z)
y = dy + z; y = dy + z;
break; break;
case kNoDirection: case NoDirection:
assert(0 && "bad direction"); assert(0 && "bad direction");
} }
} }
bool Server::isSwitchOkay( bool Server::isSwitchOkay(
BaseClientProxy *newScreen, EDirection dir, int32_t x, int32_t y, int32_t xActive, int32_t yActive BaseClientProxy *newScreen, Direction dir, int32_t x, int32_t y, int32_t xActive, int32_t yActive
) )
{ {
LOG((CLOG_DEBUG1 "try to leave \"%s\" on %s", getName(m_active).c_str(), Config::dirName(dir))); LOG((CLOG_DEBUG1 "try to leave \"%s\" on %s", getName(m_active).c_str(), Config::dirName(dir)));
@ -845,7 +850,7 @@ void Server::stopSwitch()
{ {
if (m_switchScreen != nullptr) { if (m_switchScreen != nullptr) {
m_switchScreen = nullptr; m_switchScreen = nullptr;
m_switchDir = kNoDirection; m_switchDir = Direction::NoDirection;
stopSwitchTwoTap(); stopSwitchTwoTap();
stopSwitchWait(); stopSwitchWait();
} }
@ -882,19 +887,20 @@ void Server::armSwitchTwoTap(int32_t x, int32_t y)
// move in the opposite direction that the mouse actually // move in the opposite direction that the mouse actually
// moved. try to ignore that crap here. // moved. try to ignore that crap here.
switch (m_switchDir) { switch (m_switchDir) {
case kLeft: using enum Direction;
case Left:
m_switchTwoTapArmed = (m_xDelta > 0 && m_xDelta2 > 0); m_switchTwoTapArmed = (m_xDelta > 0 && m_xDelta2 > 0);
break; break;
case kRight: case Right:
m_switchTwoTapArmed = (m_xDelta < 0 && m_xDelta2 < 0); m_switchTwoTapArmed = (m_xDelta < 0 && m_xDelta2 < 0);
break; break;
case kTop: case Top:
m_switchTwoTapArmed = (m_yDelta > 0 && m_yDelta2 > 0); m_switchTwoTapArmed = (m_yDelta > 0 && m_yDelta2 > 0);
break; break;
case kBottom: case Bottom:
m_switchTwoTapArmed = (m_yDelta < 0 && m_yDelta2 < 0); m_switchTwoTapArmed = (m_yDelta < 0 && m_yDelta2 < 0);
break; break;
@ -1609,36 +1615,38 @@ bool Server::onMouseMovePrimary(int32_t x, int32_t y)
// see if we should change screens // see if we should change screens
// when the cursor is in a corner, there may be a screen either // when the cursor is in a corner, there may be a screen either
// horizontally or vertically. check both directions. // horizontally or vertically. check both directions.
EDirection dirh = kNoDirection, dirv = kNoDirection; using enum Direction;
auto dirh = NoDirection;
auto dirv = NoDirection;
int32_t xh = x; int32_t xh = x;
int32_t yv = y; int32_t yv = y;
if (x < ax + zoneSize) { if (x < ax + zoneSize) {
xh -= zoneSize; xh -= zoneSize;
dirh = kLeft; dirh = Left;
} else if (x >= ax + aw - zoneSize) { } else if (x >= ax + aw - zoneSize) {
xh += zoneSize; xh += zoneSize;
dirh = kRight; dirh = Right;
} }
if (y < ay + zoneSize) { if (y < ay + zoneSize) {
yv -= zoneSize; yv -= zoneSize;
dirv = kTop; dirv = Top;
} else if (y >= ay + ah - zoneSize) { } else if (y >= ay + ah - zoneSize) {
yv += zoneSize; yv += zoneSize;
dirv = kBottom; dirv = Bottom;
} }
if (dirh == kNoDirection && dirv == kNoDirection) { if (dirh == NoDirection && dirv == NoDirection) {
// still on local screen // still on local screen
noSwitch(x, y); noSwitch(x, y);
return false; return false;
} }
// check both horizontally and vertically // check both horizontally and vertically
EDirection dirs[] = {dirh, dirv}; Direction dirs[] = {dirh, dirv};
int32_t xs[] = {xh, x}; int32_t xs[] = {xh, x};
int32_t ys[] = {y, yv}; int32_t ys[] = {y, yv};
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
EDirection dir = dirs[i]; Direction dir = dirs[i];
if (dir == kNoDirection) { if (dir == NoDirection) {
continue; continue;
} }
x = xs[i], y = ys[i]; x = xs[i], y = ys[i];
@ -1736,15 +1744,16 @@ void Server::onMouseMoveSecondary(int32_t dx, int32_t dy)
yc = ay + ah - 1; yc = ay + ah - 1;
} }
EDirection dir; Direction dir;
using enum Direction;
if (m_x < ax) { if (m_x < ax) {
dir = kLeft; dir = Left;
} else if (m_x > ax + aw - 1) { } else if (m_x > ax + aw - 1) {
dir = kRight; dir = Right;
} else if (m_y < ay) { } else if (m_y < ay) {
dir = kTop; dir = Top;
} else if (m_y > ay + ah - 1) { } else if (m_y > ay + ah - 1) {
dir = kBottom; dir = Bottom;
} else { } else {
// we haven't left the screen // we haven't left the screen
newScreen = m_active; newScreen = m_active;
@ -1757,19 +1766,19 @@ void Server::onMouseMoveSecondary(int32_t dx, int32_t dy)
bool clearWait; bool clearWait;
int32_t zoneSize = m_primaryClient->getJumpZoneSize(); int32_t zoneSize = m_primaryClient->getJumpZoneSize();
switch (m_switchDir) { switch (m_switchDir) {
case kLeft: case Left:
clearWait = (m_x >= ax + zoneSize); clearWait = (m_x >= ax + zoneSize);
break; break;
case kRight: case Right:
clearWait = (m_x <= ax + aw - 1 - zoneSize); clearWait = (m_x <= ax + aw - 1 - zoneSize);
break; break;
case kTop: case Top:
clearWait = (m_y >= ay + zoneSize); clearWait = (m_y >= ay + zoneSize);
break; break;
case kBottom: case Bottom:
clearWait = (m_y <= ay + ah - 1 + zoneSize); clearWait = (m_y <= ay + ah - 1 + zoneSize);
break; break;
@ -2042,7 +2051,7 @@ Server::SwitchToScreenInfo *Server::SwitchToScreenInfo::alloc(const std::string
// Server::SwitchInDirectionInfo // Server::SwitchInDirectionInfo
// //
Server::SwitchInDirectionInfo *Server::SwitchInDirectionInfo::alloc(EDirection direction) Server::SwitchInDirectionInfo *Server::SwitchInDirectionInfo::alloc(Direction direction)
{ {
auto *info = (SwitchInDirectionInfo *)malloc(sizeof(SwitchInDirectionInfo)); auto *info = (SwitchInDirectionInfo *)malloc(sizeof(SwitchInDirectionInfo));
info->m_direction = direction; info->m_direction = direction;

View file

@ -77,10 +77,10 @@ public:
class SwitchInDirectionInfo class SwitchInDirectionInfo
{ {
public: public:
static SwitchInDirectionInfo *alloc(EDirection direction); static SwitchInDirectionInfo *alloc(Direction direction);
public: public:
EDirection m_direction; Direction m_direction;
}; };
//! Screen connected data //! Screen connected data
@ -215,35 +215,35 @@ private:
// convert pixel position to fraction, using x or y depending on the // convert pixel position to fraction, using x or y depending on the
// direction. // direction.
float mapToFraction(const BaseClientProxy *, EDirection, int32_t x, int32_t y) const; float mapToFraction(const BaseClientProxy *, Direction, int32_t x, int32_t y) const;
// convert fraction to pixel position, writing only x or y depending // convert fraction to pixel position, writing only x or y depending
// on the direction. // on the direction.
void mapToPixel(const BaseClientProxy *, EDirection, float f, int32_t &x, int32_t &y) const; void mapToPixel(const BaseClientProxy *, Direction, float f, int32_t &x, int32_t &y) const;
// returns true if the client has a neighbor anywhere along the edge // returns true if the client has a neighbor anywhere along the edge
// indicated by the direction. // indicated by the direction.
bool hasAnyNeighbor(const BaseClientProxy *, EDirection) const; bool hasAnyNeighbor(const BaseClientProxy *, Direction) const;
// lookup neighboring screen, mapping the coordinate independent of // lookup neighboring screen, mapping the coordinate independent of
// the direction to the neighbor's coordinate space. // the direction to the neighbor's coordinate space.
BaseClientProxy *getNeighbor(const BaseClientProxy *, EDirection, int32_t &x, int32_t &y) const; BaseClientProxy *getNeighbor(const BaseClientProxy *, Direction, int32_t &x, int32_t &y) const;
// lookup neighboring screen. given a position relative to the // lookup neighboring screen. given a position relative to the
// source screen, find the screen we should move onto and where. // source screen, find the screen we should move onto and where.
// if the position is sufficiently far from the source then we // if the position is sufficiently far from the source then we
// cross multiple screens. if there is no suitable screen then // cross multiple screens. if there is no suitable screen then
// return nullptr and x,y are not modified. // return nullptr and x,y are not modified.
BaseClientProxy *mapToNeighbor(BaseClientProxy *, EDirection, int32_t &x, int32_t &y) const; BaseClientProxy *mapToNeighbor(BaseClientProxy *, Direction, int32_t &x, int32_t &y) const;
// adjusts x and y or neither to avoid ending up in a jump zone // adjusts x and y or neither to avoid ending up in a jump zone
// after entering the client in the given direction. // after entering the client in the given direction.
void avoidJumpZone(const BaseClientProxy *, EDirection, int32_t &x, int32_t &y) const; void avoidJumpZone(const BaseClientProxy *, Direction, int32_t &x, int32_t &y) const;
// test if a switch is permitted. this includes testing user // test if a switch is permitted. this includes testing user
// options like switch delay and tracking any state required to // options like switch delay and tracking any state required to
// implement them. returns true iff a switch is permitted. // implement them. returns true iff a switch is permitted.
bool isSwitchOkay(BaseClientProxy *dst, EDirection, int32_t x, int32_t y, int32_t xActive, int32_t yActive); bool isSwitchOkay(BaseClientProxy *dst, Direction, int32_t x, int32_t y, int32_t xActive, int32_t yActive);
// update switch state due to a mouse move at \p x, \p y that // update switch state due to a mouse move at \p x, \p y that
// doesn't switch screens. // doesn't switch screens.
@ -409,7 +409,7 @@ private:
// common state for screen switch tests. all tests are always // common state for screen switch tests. all tests are always
// trying to reach the same screen in the same direction. // trying to reach the same screen in the same direction.
EDirection m_switchDir = EDirection::kNoDirection; Direction m_switchDir = Direction::NoDirection;
BaseClientProxy *m_switchScreen = nullptr; BaseClientProxy *m_switchScreen = nullptr;
// state for delayed screen switching // state for delayed screen switching

View file

@ -41,12 +41,12 @@ void ServerConfigTests::equalityCheck()
QVERIFY(a.addScreen("screenB")); QVERIFY(a.addScreen("screenB"));
QVERIFY(a.addScreen("screenC")); QVERIFY(a.addScreen("screenC"));
QVERIFY(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(a.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(a.connect("screenB", EDirection::kLeft, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(a.connect("screenB", Direction::Left, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(b.addScreen("screenA")); QVERIFY(b.addScreen("screenA"));
QVERIFY(b.addScreen("screenC")); QVERIFY(b.addScreen("screenC"));
QVERIFY(b.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(b.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(b.connect("screenB", EDirection::kLeft, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(b.connect("screenB", Direction::Left, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(a.addOption("screenA", kOptionClipboardSharing, 1)); QVERIFY(a.addOption("screenA", kOptionClipboardSharing, 1));
QVERIFY(b.addOption("screenA", kOptionClipboardSharing, 1)); QVERIFY(b.addOption("screenA", kOptionClipboardSharing, 1));
QVERIFY(a.addOption(std::string(), kOptionClipboardSharing, 1)); QVERIFY(a.addOption(std::string(), kOptionClipboardSharing, 1));
@ -125,7 +125,7 @@ void ServerConfigTests::equalityCheck_diff_neighbours1()
Config b(nullptr); Config b(nullptr);
QVERIFY(a.addScreen("screenA")); QVERIFY(a.addScreen("screenA"));
QVERIFY(a.addScreen("screenB")); QVERIFY(a.addScreen("screenB"));
QVERIFY(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(a.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(b.addScreen("screenA")); QVERIFY(b.addScreen("screenA"));
QVERIFY(b.addScreen("screenB")); QVERIFY(b.addScreen("screenB"));
QVERIFY(a != b); QVERIFY(a != b);
@ -138,10 +138,10 @@ void ServerConfigTests::equalityCheck_diff_neighbours2()
Config b(nullptr); Config b(nullptr);
QVERIFY(a.addScreen("screenA")); QVERIFY(a.addScreen("screenA"));
QVERIFY(a.addScreen("screenB")); QVERIFY(a.addScreen("screenB"));
QVERIFY(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(a.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(b.addScreen("screenA")); QVERIFY(b.addScreen("screenA"));
QVERIFY(b.addScreen("screenB")); QVERIFY(b.addScreen("screenB"));
QVERIFY(b.connect("screenA", EDirection::kBottom, 0.0f, 0.25f, "screenB", 0.25f, 1.0f)); QVERIFY(b.connect("screenA", Direction::Bottom, 0.0f, 0.25f, "screenB", 0.25f, 1.0f));
QVERIFY(a != b); QVERIFY(a != b);
} }
@ -152,11 +152,11 @@ void ServerConfigTests::equalityCheck_diff_neighbours3()
QVERIFY(a.addScreen("screenA")); QVERIFY(a.addScreen("screenA"));
QVERIFY(a.addScreen("screenB")); QVERIFY(a.addScreen("screenB"));
QVERIFY(a.addScreen("screenC")); QVERIFY(a.addScreen("screenC"));
QVERIFY(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f)); QVERIFY(a.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
QVERIFY(b.addScreen("screenA")); QVERIFY(b.addScreen("screenA"));
QVERIFY(b.addScreen("screenB")); QVERIFY(b.addScreen("screenB"));
QVERIFY(b.addScreen("screenC")); QVERIFY(b.addScreen("screenC"));
QVERIFY(b.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenC", 0.5f, 1.0f)); QVERIFY(b.connect("screenA", Direction::Bottom, 0.0f, 0.5f, "screenC", 0.5f, 1.0f));
QVERIFY(a != b); QVERIFY(a != b);
} }