Skip to content

Commit

Permalink
feat: use optionals rather than empty strings for on created empty ru…
Browse files Browse the repository at this point in the history
…n cmd
  • Loading branch information
Syndelis committed Oct 22, 2023
1 parent d8d258e commit 0f0711f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,8 @@ void CCompositor::sanityCheckWorkspaces() {
continue;
}
if (!WORKSPACE->m_bOnCreatedEmptyExecuted) {
if (!WORKSPACERULE.onCreatedEmptyRunCmd.empty())
g_pKeybindManager->spawn(WORKSPACERULE.onCreatedEmptyRunCmd);
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
g_pKeybindManager->spawn(*cmd);

WORKSPACE->m_bOnCreatedEmptyExecuted = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct SWorkspaceRule {
std::optional<int> rounding;
std::optional<int> decorate;
std::optional<int> shadow;
std::string onCreatedEmptyRunCmd;
std::optional<std::string> onCreatedEmptyRunCmd;
};

struct SMonitorAdditionalReservedArea {
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/MiscFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../defines.hpp"
#include <algorithm>
#include "../Compositor.hpp"
#include <optional>
#include <set>
#include <sys/utsname.h>
#include <iomanip>
Expand Down Expand Up @@ -503,7 +504,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
return result;
}

std::string cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {
std::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {


std::string cmd = removeBeginEndSpacesTabs(dirtyCmd);
Expand Down Expand Up @@ -535,10 +536,10 @@ std::string cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string
rules = "[" + workspaceRule + "]";
}

return rules + " " + cmd;
return std::optional<std::string>(rules + " " + cmd);
}

return "";
return std::nullopt;
}

float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2) {
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/MiscFunctions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <optional>
#include <string>
#include <wayland-server.h>
#include <wlr/util/box.h>
Expand All @@ -20,7 +21,7 @@ std::string removeBeginEndSpacesTabs(std::string);
bool isNumber(const std::string&, bool allowfloat = false);
bool isDirection(const std::string&);
int getWorkspaceIDFromString(const std::string&, std::string&);
std::string cleanCmdForWorkspace(const std::string&, std::string);
std::optional<std::string> cleanCmdForWorkspace(const std::string&, std::string);
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
void logSystemInfo();
std::string execAndGet(const char*);
Expand Down

0 comments on commit 0f0711f

Please sign in to comment.