Merge pull request #3389 from khaneliman/cleanup
This commit is contained in:
commit
64f54e1fce
|
@ -4,14 +4,11 @@
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
|
@ -53,17 +50,19 @@ class Workspaces : public AModule, public EventHandler {
|
||||||
void onEvent(const std::string& e) override;
|
void onEvent(const std::string& e) override;
|
||||||
void updateWindowCount();
|
void updateWindowCount();
|
||||||
void sortWorkspaces();
|
void sortWorkspaces();
|
||||||
void createWorkspace(Json::Value const& workspaceData,
|
void createWorkspace(Json::Value const& workspace_data,
|
||||||
Json::Value const& clientsData = Json::Value::nullRef);
|
Json::Value const& clients_data = Json::Value::nullRef);
|
||||||
|
|
||||||
Json::Value createMonitorWorkspaceData(std::string const& name, std::string const& monitor);
|
static Json::Value createMonitorWorkspaceData(std::string const& name,
|
||||||
|
std::string const& monitor);
|
||||||
void removeWorkspace(std::string const& name);
|
void removeWorkspace(std::string const& name);
|
||||||
void setUrgentWorkspace(std::string const& windowaddress);
|
void setUrgentWorkspace(std::string const& windowaddress);
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
void parseConfig(const Json::Value& config);
|
void parseConfig(const Json::Value& config);
|
||||||
auto populateIconsMap(const Json::Value& formatIcons) -> void;
|
auto populateIconsMap(const Json::Value& formatIcons) -> void;
|
||||||
auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member) -> void;
|
static auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member)
|
||||||
|
-> void;
|
||||||
auto populateSortByConfig(const Json::Value& config) -> void;
|
auto populateSortByConfig(const Json::Value& config) -> void;
|
||||||
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
||||||
|
@ -98,7 +97,7 @@ class Workspaces : public AModule, public EventHandler {
|
||||||
void doUpdate();
|
void doUpdate();
|
||||||
void removeWorkspacesToRemove();
|
void removeWorkspacesToRemove();
|
||||||
void createWorkspacesToCreate();
|
void createWorkspacesToCreate();
|
||||||
std::vector<std::string> getVisibleWorkspaces();
|
static std::vector<std::string> getVisibleWorkspaces();
|
||||||
void updateWorkspaceStates();
|
void updateWorkspaceStates();
|
||||||
bool updateWindowsToCreate();
|
bool updateWindowsToCreate();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ std::filesystem::path IPC::getSocketFolder(const char* instanceSig) {
|
||||||
const char* xdgRuntimeDirEnv = std::getenv("XDG_RUNTIME_DIR");
|
const char* xdgRuntimeDirEnv = std::getenv("XDG_RUNTIME_DIR");
|
||||||
std::filesystem::path xdgRuntimeDir;
|
std::filesystem::path xdgRuntimeDir;
|
||||||
// Only set path if env variable is set
|
// Only set path if env variable is set
|
||||||
if (xdgRuntimeDirEnv) {
|
if (xdgRuntimeDirEnv != nullptr) {
|
||||||
xdgRuntimeDir = std::filesystem::path(xdgRuntimeDirEnv);
|
xdgRuntimeDir = std::filesystem::path(xdgRuntimeDirEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,13 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value IPC::getSocket1JsonReply(const std::string& rq) {
|
Json::Value IPC::getSocket1JsonReply(const std::string& rq) {
|
||||||
return parser_.parse(getSocket1Reply("j/" + rq));
|
std::string reply = getSocket1Reply("j/" + rq);
|
||||||
|
|
||||||
|
if (reply.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return parser_.parse(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace waybar::modules::hyprland
|
} // namespace waybar::modules::hyprland
|
||||||
|
|
|
@ -38,12 +38,12 @@ Submap::~Submap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Submap::parseConfig(const Json::Value& config) -> void {
|
auto Submap::parseConfig(const Json::Value& config) -> void {
|
||||||
auto const alwaysOn = config["always-on"];
|
auto const& alwaysOn = config["always-on"];
|
||||||
if (alwaysOn.isBool()) {
|
if (alwaysOn.isBool()) {
|
||||||
always_on_ = alwaysOn.asBool();
|
always_on_ = alwaysOn.asBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const defaultSubmap = config["default-submap"];
|
auto const& defaultSubmap = config["default-submap"];
|
||||||
if (defaultSubmap.isString()) {
|
if (defaultSubmap.isString()) {
|
||||||
default_submap_ = defaultSubmap.asString();
|
default_submap_ = defaultSubmap.asString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,11 @@
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include "modules/hyprland/workspaces.hpp"
|
#include "modules/hyprland/workspaces.hpp"
|
||||||
#include "util/regex_collection.hpp"
|
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
#include "modules/hyprland/workspaces.hpp"
|
#include "modules/hyprland/workspaces.hpp"
|
||||||
#include "util/regex_collection.hpp"
|
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
#include "util/regex_collection.hpp"
|
#include "util/regex_collection.hpp"
|
||||||
|
|
||||||
|
@ -593,14 +592,14 @@ auto Workspaces::populateIconsMap(const Json::Value &formatIcons) -> void {
|
||||||
|
|
||||||
auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member)
|
auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member)
|
||||||
-> void {
|
-> void {
|
||||||
auto configValue = config[key];
|
const auto &configValue = config[key];
|
||||||
if (configValue.isBool()) {
|
if (configValue.isBool()) {
|
||||||
member = configValue.asBool();
|
member = configValue.asBool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
||||||
auto configSortBy = config["sort-by"];
|
const auto &configSortBy = config["sort-by"];
|
||||||
if (configSortBy.isString()) {
|
if (configSortBy.isString()) {
|
||||||
auto sortByStr = configSortBy.asString();
|
auto sortByStr = configSortBy.asString();
|
||||||
try {
|
try {
|
||||||
|
@ -633,7 +632,7 @@ auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> vo
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void {
|
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void {
|
||||||
auto formatWindowSeparator = config["format-window-separator"];
|
const auto &formatWindowSeparator = config["format-window-separator"];
|
||||||
m_formatWindowSeparator =
|
m_formatWindowSeparator =
|
||||||
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <cstdlib>
|
|
||||||
#if __has_include(<catch2/catch_test_macros.hpp>)
|
#if __has_include(<catch2/catch_test_macros.hpp>)
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#else
|
#else
|
||||||
|
@ -6,7 +5,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fixtures/IPCTestFixture.hpp"
|
#include "fixtures/IPCTestFixture.hpp"
|
||||||
#include "modules/hyprland/backend.hpp"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
namespace hyprland = waybar::modules::hyprland;
|
namespace hyprland = waybar::modules::hyprland;
|
||||||
|
@ -53,3 +51,11 @@ TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExistsNoHyprDir", "[getSocketFold
|
||||||
// Assert expected result
|
// Assert expected result
|
||||||
REQUIRE(actualPath == expectedPath);
|
REQUIRE(actualPath == expectedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_METHOD(IPCMock, "getSocket1JsonReply handles empty response", "[getSocket1JsonReply]") {
|
||||||
|
std::string request = "test_request";
|
||||||
|
|
||||||
|
Json::Value jsonResponse = getSocket1JsonReply(request);
|
||||||
|
|
||||||
|
REQUIRE(jsonResponse.isNull());
|
||||||
|
}
|
||||||
|
|
|
@ -14,3 +14,9 @@ class IPCTestFixture : public hyprland::IPC {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IPCMock : public IPCTestFixture {
|
||||||
|
public:
|
||||||
|
// Mock getSocket1Reply to return an empty string
|
||||||
|
static std::string getSocket1Reply(const std::string& rq) { return ""; }
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue