Skip to content

Commit

Permalink
screencopy: fix handles not being restored
Browse files Browse the repository at this point in the history
fixes #264
  • Loading branch information
vaxerski committed Sep 23, 2024
1 parent 4880c50 commit 4adb6c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/portals/Screencopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,15 @@ void CScreencopyPortal::onSelectSources(sdbus::MethodCall& call) {
restoreData.timeIssued);
} else {
// ver 3
auto sv = data.get<std::unordered_map<std::string, sdbus::Variant>>();
auto sv = data.get<std::unordered_map<std::string, sdbus::Variant>>();

uint64_t windowHandle = 0;

restoreData.windowHandle = 0;
restoreData.exists = true;
restoreData.exists = true;

for (auto& [tkkey, tkval] : sv) {
if (tkkey == "output")
restoreData.output = tkval.get<std::string>();
else if (tkkey == "windowHandle")
windowHandle = tkval.get<uint64_t>();
restoreData.windowHandle = tkval.get<uint64_t>();
else if (tkkey == "windowClass")
restoreData.windowClass = tkval.get<std::string>();
else if (tkkey == "withCursor")
Expand All @@ -177,8 +174,8 @@ void CScreencopyPortal::onSelectSources(sdbus::MethodCall& call) {
Debug::log(LOG, "[screencopy] restore token v3, unknown prop {}", tkkey);
}

Debug::log(LOG, "[screencopy] Restore token v3 {} with data: {} {} {} {} {}", restoreData.token, windowHandle, restoreData.windowClass, restoreData.output,
restoreData.withCursor, restoreData.timeIssued);
Debug::log(LOG, "[screencopy] Restore token v3 {} with data: {} {} {} {} {}", restoreData.token, restoreData.windowHandle, restoreData.windowClass,
restoreData.output, restoreData.withCursor, restoreData.timeIssued);
}

} else if (key == "persist_mode") {
Expand All @@ -201,9 +198,12 @@ void CScreencopyPortal::onSelectSources(sdbus::MethodCall& call) {
if (RESTOREDATAVALID) {
Debug::log(LOG, "[screencopy] restore data valid, not prompting");

const bool WINDOW = !restoreData.windowClass.empty();
const auto HANDLEMATCH = WINDOW && restoreData.windowHandle != 0 ? g_pPortalManager->m_sHelpers.toplevel->handleFromHandleFull(restoreData.windowHandle) : nullptr;

SHAREDATA.output = restoreData.output;
SHAREDATA.type = !restoreData.windowClass.empty() ? TYPE_WINDOW : TYPE_OUTPUT;
SHAREDATA.windowHandle = !restoreData.windowClass.empty() ? g_pPortalManager->m_sHelpers.toplevel->handleFromClass(restoreData.windowClass)->handle : nullptr;
SHAREDATA.type = WINDOW ? TYPE_WINDOW : TYPE_OUTPUT;
SHAREDATA.windowHandle = WINDOW ? (HANDLEMATCH ? HANDLEMATCH->handle : g_pPortalManager->m_sHelpers.toplevel->handleFromClass(restoreData.windowClass)->handle) : nullptr;
SHAREDATA.windowClass = restoreData.windowClass;
SHAREDATA.allowToken = true; // user allowed token before
PSESSION->cursorMode = restoreData.withCursor;
Expand Down
11 changes: 10 additions & 1 deletion src/shared/ToplevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ SP<SToplevelHandle> CToplevelManager::handleFromHandleLower(uint32_t handle) {
}

return nullptr;
}
}

SP<SToplevelHandle> CToplevelManager::handleFromHandleFull(uint64_t handle) {
for (auto& tl : m_vToplevels) {
if ((uint64_t)tl->handle->resource() == handle)
return tl;
}

return nullptr;
}
1 change: 1 addition & 0 deletions src/shared/ToplevelManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CToplevelManager {
void deactivate();
SP<SToplevelHandle> handleFromClass(const std::string& windowClass);
SP<SToplevelHandle> handleFromHandleLower(uint32_t handle);
SP<SToplevelHandle> handleFromHandleFull(uint64_t handle);

std::vector<SP<SToplevelHandle>> m_vToplevels;

Expand Down

0 comments on commit 4adb6c4

Please sign in to comment.