feat: fetch clients data when moving workspaces accross monitors

pull/2817/head
Brenno Lemos 2024-01-08 20:11:39 -03:00
parent bc7acbde5c
commit 4339030c9d
2 changed files with 18 additions and 23 deletions

View File

@ -145,7 +145,8 @@ class Workspaces : public AModule, public EventHandler {
// workspace events // workspace events
void onWorkspaceActivated(std::string const& payload); void onWorkspaceActivated(std::string const& payload);
void onWorkspaceDestroyed(std::string const& payload); void onWorkspaceDestroyed(std::string const& payload);
void onWorkspaceCreated(std::string const& payload); void onWorkspaceCreated(std::string const& workspaceName,
Json::Value const& clientsData = Json::Value::nullRef);
void onWorkspaceMoved(std::string const& payload); void onWorkspaceMoved(std::string const& payload);
void onWorkspaceRenamed(std::string const& payload); void onWorkspaceRenamed(std::string const& payload);
@ -199,7 +200,7 @@ class Workspaces : public AModule, public EventHandler {
uint64_t m_monitorId; uint64_t m_monitorId;
std::string m_activeWorkspaceName; std::string m_activeWorkspaceName;
std::vector<std::unique_ptr<Workspace>> m_workspaces; std::vector<std::unique_ptr<Workspace>> m_workspaces;
std::vector<Json::Value> m_workspacesToCreate; std::vector<std::pair<Json::Value, Json::Value>> m_workspacesToCreate;
std::vector<std::string> m_workspacesToRemove; std::vector<std::string> m_workspacesToRemove;
std::vector<WindowCreationPayload> m_windowsToCreate; std::vector<WindowCreationPayload> m_windowsToCreate;

View File

@ -170,8 +170,8 @@ void Workspaces::doUpdate() {
m_workspacesToRemove.clear(); m_workspacesToRemove.clear();
// add workspaces that wait to be created // add workspaces that wait to be created
for (auto &elem : m_workspacesToCreate) { for (auto &[workspaceData, clientsData] : m_workspacesToCreate) {
createWorkspace(elem); createWorkspace(workspaceData, clientsData);
} }
m_workspacesToCreate.clear(); m_workspacesToCreate.clear();
@ -301,16 +301,17 @@ void Workspaces::onWorkspaceDestroyed(std::string const &payload) {
} }
} }
void Workspaces::onWorkspaceCreated(std::string const &payload) { void Workspaces::onWorkspaceCreated(std::string const &workspaceName,
Json::Value const &clientsData) {
const Json::Value workspacesJson = gIPC->getSocket1JsonReply("workspaces"); const Json::Value workspacesJson = gIPC->getSocket1JsonReply("workspaces");
if (!isWorkspaceIgnored(payload)) { if (!isWorkspaceIgnored(workspaceName)) {
for (Json::Value workspaceJson : workspacesJson) { for (Json::Value workspaceJson : workspacesJson) {
std::string name = workspaceJson["name"].asString(); std::string name = workspaceJson["name"].asString();
if (name == payload && if (name == workspaceName &&
(allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) && (allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) &&
(showSpecial() || !name.starts_with("special")) && !isDoubleSpecial(payload)) { (showSpecial() || !name.starts_with("special")) && !isDoubleSpecial(workspaceName)) {
m_workspacesToCreate.push_back(workspaceJson); m_workspacesToCreate.emplace_back(workspaceJson, clientsData);
break; break;
} }
} }
@ -318,20 +319,14 @@ void Workspaces::onWorkspaceCreated(std::string const &payload) {
} }
void Workspaces::onWorkspaceMoved(std::string const &payload) { void Workspaces::onWorkspaceMoved(std::string const &payload) {
std::string workspace = payload.substr(0, payload.find(',')); std::string workspaceName = payload.substr(0, payload.find(','));
std::string newOutput = payload.substr(payload.find(',') + 1); std::string monitorName = payload.substr(payload.find(',') + 1);
bool shouldShow = showSpecial() || !workspace.starts_with("special");
if (shouldShow && m_bar.output->name == newOutput) { // TODO: implement this better if (m_bar.output->name == monitorName) {
const Json::Value workspacesJson = gIPC->getSocket1JsonReply("workspaces"); Json::Value clientsData = gIPC->getSocket1JsonReply("clients");
for (Json::Value workspaceJson : workspacesJson) { onWorkspaceCreated(workspaceName, clientsData);
std::string name = workspaceJson["name"].asString();
if (name == workspace && m_bar.output->name == workspaceJson["monitor"].asString()) {
m_workspacesToCreate.push_back(workspaceJson);
break;
}
}
} else { } else {
m_workspacesToRemove.push_back(workspace); onWorkspaceDestroyed(workspaceName);
} }
} }
@ -670,7 +665,6 @@ void Workspaces::init() {
for (Json::Value workspaceJson : workspacesJson) { for (Json::Value workspaceJson : workspacesJson) {
std::string workspaceName = workspaceJson["name"].asString(); std::string workspaceName = workspaceJson["name"].asString();
spdlog::info("initing workpsace {}:{}", workspaceJson["id"], workspaceJson["name"]);
if ((allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) && if ((allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) &&
(!workspaceName.starts_with("special") || showSpecial()) && (!workspaceName.starts_with("special") || showSpecial()) &&
!isWorkspaceIgnored(workspaceName)) { !isWorkspaceIgnored(workspaceName)) {