refactor: OptionTypes, Remove corner related enums and uses static items for corner masks instead

This commit is contained in:
sithlord48 2025-07-30 19:55:46 -04:00 committed by Nick Bolton
parent 7c06ae39ef
commit 9673943556
3 changed files with 25 additions and 42 deletions

View file

@ -62,31 +62,14 @@ static const OptionID kOptionClipboardSharing = OPTION_CODE("CLPS");
static const OptionID kOptionClipboardSharingSize = OPTION_CODE("CLSZ"); static const OptionID kOptionClipboardSharingSize = OPTION_CODE("CLSZ");
//@} //@}
//! @name Screen switch corner enumeration
//@{
enum EScreenSwitchCorners
{
kNoCorner,
kTopLeft,
kTopRight,
kBottomLeft,
kBottomRight,
kFirstCorner = kTopLeft,
kLastCorner = kBottomRight
};
//@}
//! @name Screen switch corner masks //! @name Screen switch corner masks
//@{ //@{
enum EScreenSwitchCornerMasks inline static const auto s_noCornerMask = 0;
{ inline static const auto s_topLeftCornerMask = 1 << 0;
kNoCornerMask = 0, inline static const auto s_topRightCornerMask = 1 << 1;
kTopLeftMask = 1 << (kTopLeft - kFirstCorner), inline static const auto s_bottomLeftCornerMask = 1 << 2;
kTopRightMask = 1 << (kTopRight - kFirstCorner), inline static const auto s_bottomRightCornerMask = 1 << 3;
kBottomLeftMask = 1 << (kBottomLeft - kFirstCorner), inline static const auto s_allCornersMask = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3;
kBottomRightMask = 1 << (kBottomRight - kFirstCorner),
kAllCornersMask = kTopLeftMask | kTopRightMask | kBottomLeftMask | kBottomRightMask
};
//@} //@}
//! @name Network protocol //! @name Network protocol

View file

@ -1296,16 +1296,16 @@ std::string Config::getOptionValue(OptionID id, OptionValue value)
} }
if (id == kOptionScreenSwitchCorners) { if (id == kOptionScreenSwitchCorners) {
std::string result("none"); std::string result("none");
if ((value & kTopLeftMask) != 0) { if ((value & s_topLeftCornerMask) != 0) {
result += " +top-left"; result += " +top-left";
} }
if ((value & kTopRightMask) != 0) { if ((value & s_topRightCornerMask) != 0) {
result += " +top-right"; result += " +top-right";
} }
if ((value & kBottomLeftMask) != 0) { if ((value & s_bottomLeftCornerMask) != 0) {
result += " +bottom-left"; result += " +bottom-left";
} }
if ((value & kBottomRightMask) != 0) { if ((value & s_bottomRightCornerMask) != 0) {
result += " +bottom-right"; result += " +bottom-right";
} }
return result; return result;
@ -1783,25 +1783,25 @@ OptionValue ConfigReadContext::parseModifierKey(const std::string &arg) const
OptionValue ConfigReadContext::parseCorner(const std::string &arg) const OptionValue ConfigReadContext::parseCorner(const std::string &arg) const
{ {
if (CaselessCmp::equal(arg, "left")) { if (CaselessCmp::equal(arg, "left")) {
return kTopLeftMask | kBottomLeftMask; return s_topLeftCornerMask | s_bottomLeftCornerMask;
} else if (CaselessCmp::equal(arg, "right")) { } else if (CaselessCmp::equal(arg, "right")) {
return kTopRightMask | kBottomRightMask; return s_topRightCornerMask | s_bottomRightCornerMask;
} else if (CaselessCmp::equal(arg, "top")) { } else if (CaselessCmp::equal(arg, "top")) {
return kTopLeftMask | kTopRightMask; return s_topLeftCornerMask | s_topRightCornerMask;
} else if (CaselessCmp::equal(arg, "bottom")) { } else if (CaselessCmp::equal(arg, "bottom")) {
return kBottomLeftMask | kBottomRightMask; return s_bottomLeftCornerMask | s_bottomRightCornerMask;
} else if (CaselessCmp::equal(arg, "top-left")) { } else if (CaselessCmp::equal(arg, "top-left")) {
return kTopLeftMask; return s_topLeftCornerMask;
} else if (CaselessCmp::equal(arg, "top-right")) { } else if (CaselessCmp::equal(arg, "top-right")) {
return kTopRightMask; return s_topRightCornerMask;
} else if (CaselessCmp::equal(arg, "bottom-left")) { } else if (CaselessCmp::equal(arg, "bottom-left")) {
return kBottomLeftMask; return s_bottomLeftCornerMask;
} else if (CaselessCmp::equal(arg, "bottom-right")) { } else if (CaselessCmp::equal(arg, "bottom-right")) {
return kBottomRightMask; return s_bottomRightCornerMask;
} else if (CaselessCmp::equal(arg, "none")) { } else if (CaselessCmp::equal(arg, "none")) {
return kNoCornerMask; return s_noCornerMask;
} else if (CaselessCmp::equal(arg, "all")) { } else if (CaselessCmp::equal(arg, "all")) {
return kAllCornersMask; return s_allCornersMask;
} }
throw XConfigRead(*this, "invalid argument \"%{1}\"", arg); throw XConfigRead(*this, "invalid argument \"%{1}\"", arg);
} }

View file

@ -989,22 +989,22 @@ uint32_t Server::getCorner(const BaseClientProxy *client, int32_t x, int32_t y,
// if against the left or right then check if y is within size // if against the left or right then check if y is within size
if (xSide != 0) { if (xSide != 0) {
if (y < ay + size) { if (y < ay + size) {
return (xSide < 0) ? kTopLeftMask : kTopRightMask; return (xSide < 0) ? s_topLeftCornerMask : s_topRightCornerMask;
} else if (y >= ay + ah - size) { } else if (y >= ay + ah - size) {
return (xSide < 0) ? kBottomLeftMask : kBottomRightMask; return (xSide < 0) ? s_bottomLeftCornerMask : s_bottomRightCornerMask;
} }
} }
// if against the left or right then check if y is within size // if against the left or right then check if y is within size
if (ySide != 0) { if (ySide != 0) {
if (x < ax + size) { if (x < ax + size) {
return (ySide < 0) ? kTopLeftMask : kBottomLeftMask; return (ySide < 0) ? s_topLeftCornerMask : s_bottomLeftCornerMask;
} else if (x >= ax + aw - size) { } else if (x >= ax + aw - size) {
return (ySide < 0) ? kTopRightMask : kBottomRightMask; return (ySide < 0) ? s_topRightCornerMask : s_bottomRightCornerMask;
} }
} }
return kNoCornerMask; return s_noCornerMask;
} }
void Server::stopRelativeMoves() void Server::stopRelativeMoves()