mirror of
https://github.com/hyprwm/hyprcursor.git
synced 2024-12-22 02:09:48 +01:00
core/API: add option to not use default fallbacks (env and first available) (#43)
* add option to not use default fallbacks (env and first available)
This commit is contained in:
parent
7c3aa03dff
commit
27ca640abe
2 changed files with 39 additions and 10 deletions
|
@ -47,6 +47,22 @@ namespace Hyprcursor {
|
||||||
eHyprcursorDataType type = HC_DATA_PNG;
|
eHyprcursorDataType type = HC_DATA_PNG;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
struct for cursor manager options
|
||||||
|
*/
|
||||||
|
struct SManagerOptions {
|
||||||
|
explicit SManagerOptions();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
The function used for logging by the cursor manager
|
||||||
|
*/
|
||||||
|
PHYPRCURSORLOGFUNC logFn;
|
||||||
|
/*!
|
||||||
|
Allow fallback to env and first theme found
|
||||||
|
*/
|
||||||
|
bool allowDefaultFallback;
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Basic Hyprcursor manager.
|
Basic Hyprcursor manager.
|
||||||
|
|
||||||
|
@ -68,6 +84,7 @@ namespace Hyprcursor {
|
||||||
\since 0.1.6
|
\since 0.1.6
|
||||||
*/
|
*/
|
||||||
CHyprcursorManager(const char* themeName, PHYPRCURSORLOGFUNC fn);
|
CHyprcursorManager(const char* themeName, PHYPRCURSORLOGFUNC fn);
|
||||||
|
CHyprcursorManager(const char* themeName, SManagerOptions options);
|
||||||
~CHyprcursorManager();
|
~CHyprcursorManager();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -172,9 +189,10 @@ namespace Hyprcursor {
|
||||||
private:
|
private:
|
||||||
void init(const char* themeName_);
|
void init(const char* themeName_);
|
||||||
|
|
||||||
CHyprcursorImplementation* impl = nullptr;
|
CHyprcursorImplementation* impl = nullptr;
|
||||||
bool finalizedAndValid = false;
|
bool finalizedAndValid = false;
|
||||||
PHYPRCURSORLOGFUNC logFn = nullptr;
|
bool allowDefaultFallback = true;
|
||||||
|
PHYPRCURSORLOGFUNC logFn = nullptr;
|
||||||
|
|
||||||
friend class CHyprcursorImplementation;
|
friend class CHyprcursorImplementation;
|
||||||
};
|
};
|
||||||
|
|
|
@ -108,7 +108,7 @@ static std::string getFirstTheme(PHYPRCURSORLOGFUNC logfn) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORLOGFUNC logfn) {
|
static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORLOGFUNC logfn, bool allowDefaultFallback) {
|
||||||
const auto HOMEENV = getenv("HOME");
|
const auto HOMEENV = getenv("HOME");
|
||||||
if (!HOMEENV)
|
if (!HOMEENV)
|
||||||
return "";
|
return "";
|
||||||
|
@ -134,7 +134,7 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
|
||||||
|
|
||||||
const auto MANIFESTPATH = themeDir.path().string() + "/manifest";
|
const auto MANIFESTPATH = themeDir.path().string() + "/manifest";
|
||||||
|
|
||||||
if (name.empty()) {
|
if (allowDefaultFallback && name.empty()) {
|
||||||
if (std::filesystem::exists(MANIFESTPATH + ".hl") || std::filesystem::exists(MANIFESTPATH + ".toml")) {
|
if (std::filesystem::exists(MANIFESTPATH + ".hl") || std::filesystem::exists(MANIFESTPATH + ".toml")) {
|
||||||
Debug::log(HC_LOG_INFO, logfn, "getFullPathForThemeName: found {}", themeDir.path().string());
|
Debug::log(HC_LOG_INFO, logfn, "getFullPathForThemeName: found {}", themeDir.path().string());
|
||||||
return std::filesystem::canonical(themeDir.path()).string();
|
return std::filesystem::canonical(themeDir.path()).string();
|
||||||
|
@ -193,14 +193,19 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name.empty()) { // try without name
|
if (allowDefaultFallback && !name.empty()) { // try without name
|
||||||
Debug::log(HC_LOG_INFO, logfn, "getFullPathForThemeName: failed, trying without name of {}", name);
|
Debug::log(HC_LOG_INFO, logfn, "getFullPathForThemeName: failed, trying without name of {}", name);
|
||||||
return getFullPathForThemeName("", logfn);
|
return getFullPathForThemeName("", logfn, allowDefaultFallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SManagerOptions::SManagerOptions() {
|
||||||
|
logFn = nullptr;
|
||||||
|
allowDefaultFallback = true;
|
||||||
|
}
|
||||||
|
|
||||||
CHyprcursorManager::CHyprcursorManager(const char* themeName_) {
|
CHyprcursorManager::CHyprcursorManager(const char* themeName_) {
|
||||||
init(themeName_);
|
init(themeName_);
|
||||||
}
|
}
|
||||||
|
@ -210,16 +215,22 @@ CHyprcursorManager::CHyprcursorManager(const char* themeName_, PHYPRCURSORLOGFUN
|
||||||
init(themeName_);
|
init(themeName_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHyprcursorManager::CHyprcursorManager(const char* themeName_, SManagerOptions options) {
|
||||||
|
logFn = options.logFn;
|
||||||
|
allowDefaultFallback = options.allowDefaultFallback;
|
||||||
|
init(themeName_);
|
||||||
|
}
|
||||||
|
|
||||||
void CHyprcursorManager::init(const char* themeName_) {
|
void CHyprcursorManager::init(const char* themeName_) {
|
||||||
std::string themeName = themeName_ ? themeName_ : "";
|
std::string themeName = themeName_ ? themeName_ : "";
|
||||||
|
|
||||||
if (themeName.empty()) {
|
if (allowDefaultFallback && themeName.empty()) {
|
||||||
// try reading from env
|
// try reading from env
|
||||||
Debug::log(HC_LOG_INFO, logFn, "CHyprcursorManager: attempting to find theme from env");
|
Debug::log(HC_LOG_INFO, logFn, "CHyprcursorManager: attempting to find theme from env");
|
||||||
themeName = themeNameFromEnv(logFn);
|
themeName = themeNameFromEnv(logFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (themeName.empty()) {
|
if (allowDefaultFallback && themeName.empty()) {
|
||||||
// try finding first, in the hierarchy
|
// try finding first, in the hierarchy
|
||||||
Debug::log(HC_LOG_INFO, logFn, "CHyprcursorManager: attempting to find any theme");
|
Debug::log(HC_LOG_INFO, logFn, "CHyprcursorManager: attempting to find any theme");
|
||||||
themeName = getFirstTheme(logFn);
|
themeName = getFirstTheme(logFn);
|
||||||
|
@ -234,7 +245,7 @@ void CHyprcursorManager::init(const char* themeName_) {
|
||||||
// initialize theme
|
// initialize theme
|
||||||
impl = new CHyprcursorImplementation(this, logFn);
|
impl = new CHyprcursorImplementation(this, logFn);
|
||||||
impl->themeName = themeName;
|
impl->themeName = themeName;
|
||||||
impl->themeFullDir = getFullPathForThemeName(themeName, logFn);
|
impl->themeFullDir = getFullPathForThemeName(themeName, logFn, allowDefaultFallback);
|
||||||
|
|
||||||
if (impl->themeFullDir.empty())
|
if (impl->themeFullDir.empty())
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue