[feat] add panel desktop takeover with exclusive input ownership

This commit is contained in:
dijunkun
2026-11-06 21:52:47 +08:00
parent b167b24cb3
commit 02b10d0d8e
14 changed files with 353 additions and 21 deletions
+2 -1
View File
@@ -86,7 +86,7 @@ public:
void ForgetRemoteRequest(uint64_t request) { remote_results_.erase(request); }
uint64_t Clipboard(bool write, const std::string &text = {});
nlohmann::json Files(const nlohmann::json &request);
void BeginInput();
void BeginInput(bool acknowledge = true);
std::string InputResult();
bool InputAcknowledged() const { return remote_capabilities_.value("input_ack", nlohmann::json{}) == true; }
std::optional<DecodedFrame> TakeFrame(DecodedFrame *recycle = nullptr);
@@ -130,6 +130,7 @@ private:
std::vector<uint64_t> input_requests_;
std::string input_result_ = "applied";
bool input_ack_active_ = false;
bool input_ack_transport_ = false;
bool clipboard_ready_ = false;
web_clipboard::Assembler clipboard_assembler_;
std::unique_ptr<ControllerFiles> files_;
+6 -4
View File
@@ -25,20 +25,22 @@ std::optional<json> ControllerSession::TakeRemoteResult(uint64_t request) {
return result;
}
void ControllerSession::BeginInput() {
void ControllerSession::BeginInput(bool acknowledge) {
action_keys_ = keys_;
action_buttons_ = buttons_;
for (const auto id : input_requests_) remote_results_.erase(id);
input_requests_.clear();
input_result_ = "applied";
input_ack_active_ = InputAcknowledged();
input_ack_transport_ = InputAcknowledged();
input_ack_active_ = acknowledge && input_ack_transport_;
}
bool ControllerSession::SendInput(const char *stream, const RemoteAction &action) {
if (!input_ack_active_) return Send(stream, action.to_json());
if (!input_ack_transport_) return Send(stream, action.to_json());
const auto id = RequestRemote("input", json::parse(action.to_json()));
if (!id) return false;
input_requests_.push_back(id);
if (input_ack_active_) input_requests_.push_back(id);
else remote_results_.erase(id);
return true;
}