Skip to content

Commit

Permalink
tablet: add absolute_region_position option
Browse files Browse the repository at this point in the history
  • Loading branch information
JManch committed Nov 5, 2024
1 parent 6f230cd commit be87d0b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
8 changes: 7 additions & 1 deletion src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,16 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
},
SConfigOptionDescription{
.value = "input:tablet:region_position",
.description = "position of the mapped region in monitor layout.",
.description = "position of the mapped region in monitor layout relative to the top left corner of the bound monitor or all monitors.",
.type = CONFIG_OPTION_VECTOR,
.data = SConfigOptionDescription::SVectorData{{}, {-20000, -20000}, {20000, 20000}},
},
SConfigOptionDescription{
.value = "input:tablet:absolute_region_position",
.description = "whether to treat the region_position as an absolute position in monitor layout. Only applies when output is empty",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "input:tablet:region_size",
.description = "size of the mapped region. When this variable is set, tablet input will be mapped to the region. [0, 0] or invalid size means unset.",
Expand Down
2 changes: 2 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("input:tablet:transform", Hyprlang::INT{0});
m_pConfig->addConfigValue("input:tablet:output", {STRVAL_EMPTY});
m_pConfig->addConfigValue("input:tablet:region_position", Hyprlang::VEC2{0, 0});
m_pConfig->addConfigValue("input:tablet:absolute_region_position", Hyprlang::INT{0});
m_pConfig->addConfigValue("input:tablet:region_size", Hyprlang::VEC2{0, 0});
m_pConfig->addConfigValue("input:tablet:relative_input", Hyprlang::INT{0});
m_pConfig->addConfigValue("input:tablet:left_handed", Hyprlang::INT{0});
Expand Down Expand Up @@ -623,6 +624,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY});
m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices
m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "absolute_region_position", Hyprlang::INT{0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "region_size", Hyprlang::VEC2{0, 0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "active_area_position", Hyprlang::VEC2{0, 0}); // only for tablets
Expand Down
3 changes: 2 additions & 1 deletion src/devices/Tablet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ class CTablet : public IHID {
WP<CTablet> self;

bool relativeInput = false;
bool absolutePos = false;
std::string hlName = "";
std::string boundOutput = "";
CBox activeArea;
CBox boundBox; // output-local
CBox boundBox;

private:
CTablet(SP<Aquamarine::ITablet> tablet);
Expand Down
26 changes: 13 additions & 13 deletions src/managers/PointerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,36 +697,36 @@ void CPointerManager::warpAbsolute(Vector2D abs, SP<IHID> dev) {
CTablet* TAB = reinterpret_cast<CTablet*>(dev.get());
if (!TAB->boundOutput.empty()) {
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TAB->boundOutput); PMONITOR) {
if (const auto boundMonitor = PMONITOR->self.lock(); boundMonitor)
mappedArea = boundMonitor->logicalBox();
mappedArea = PMONITOR->logicalBox();

// apply the bound box relative to the bound output
mappedArea.translate(TAB->boundBox.pos());
}
}
} else if (TAB->absolutePos) {
mappedArea.x = TAB->boundBox.x;
mappedArea.y = TAB->boundBox.y;
} else
mappedArea.translate(TAB->boundBox.pos());

mappedArea.translate(TAB->boundBox.pos());
if (!TAB->boundBox.empty()) {
mappedArea.w = TAB->boundBox.w;
mappedArea.h = TAB->boundBox.h;
}

break;
}
case HID_TYPE_TOUCH: {
ITouch* TOUCH = reinterpret_cast<ITouch*>(dev.get());
if (!TOUCH->boundOutput.empty()) {
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TOUCH->boundOutput); PMONITOR) {
if (const auto boundMonitor = PMONITOR->self.lock(); boundMonitor)
mappedArea = boundMonitor->logicalBox();
}
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TOUCH->boundOutput); PMONITOR)
mappedArea = PMONITOR->logicalBox();
}
break;
}
case HID_TYPE_POINTER: {
IPointer* POINTER = reinterpret_cast<IPointer*>(dev.get());
if (!POINTER->boundOutput.empty()) {
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(POINTER->boundOutput); PMONITOR) {
if (const auto boundMonitor = PMONITOR->self.lock(); boundMonitor)
mappedArea = boundMonitor->logicalBox();
}
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(POINTER->boundOutput); PMONITOR)
mappedArea = PMONITOR->logicalBox();
}
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,9 @@ void CInputManager::setTabletConfigs() {
const auto REGION_SIZE = g_pConfigManager->getDeviceVec(NAME, "region_size", "input:tablet:region_size");
t->boundBox = {REGION_POS, REGION_SIZE};

const auto ABSOLUTE_REGION_POS = g_pConfigManager->getDeviceInt(NAME, "absolute_region_position", "input:tablet:absolute_region_position");
t->absolutePos = ABSOLUTE_REGION_POS;

const auto ACTIVE_AREA_SIZE = g_pConfigManager->getDeviceVec(NAME, "active_area_size", "input:tablet:active_area_size");
const auto ACTIVE_AREA_POS = g_pConfigManager->getDeviceVec(NAME, "active_area_position", "input:tablet:active_area_position");
if (ACTIVE_AREA_SIZE.x != 0 || ACTIVE_AREA_SIZE.y != 0) {
Expand Down

0 comments on commit be87d0b

Please sign in to comment.