fix #3490: expand menu file before opening it
This commit is contained in:
parent
003dd3a9a2
commit
7ec1343ad5
|
@ -20,6 +20,9 @@ class Config {
|
||||||
static std::optional<std::string> findConfigPath(
|
static std::optional<std::string> findConfigPath(
|
||||||
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
||||||
|
|
||||||
|
static std::optional<std::string> tryExpandPath(const std::string &base,
|
||||||
|
const std::string &filename);
|
||||||
|
|
||||||
Config() = default;
|
Config() = default;
|
||||||
|
|
||||||
void load(const std::string &config);
|
void load(const std::string &config);
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <util/command.hpp>
|
#include <util/command.hpp>
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
||||||
|
@ -61,6 +63,14 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
||||||
try {
|
try {
|
||||||
// Check that the file exists
|
// Check that the file exists
|
||||||
std::string menuFile = config_["menu-file"].asString();
|
std::string menuFile = config_["menu-file"].asString();
|
||||||
|
|
||||||
|
// there might be "~" or "$HOME" in original path, try to expand it.
|
||||||
|
auto result = Config::tryExpandPath(menuFile, "");
|
||||||
|
if (!result.has_value()) {
|
||||||
|
throw std::runtime_error("Failed to expand file: " + menuFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
menuFile = result.value();
|
||||||
// Read the menu descriptor file
|
// Read the menu descriptor file
|
||||||
std::ifstream file(menuFile);
|
std::ifstream file(menuFile);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
|
@ -170,7 +180,7 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
||||||
return AModule::handleToggle(e);
|
return AModule::handleToggle(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALabel::handleGtkMenuEvent(GtkMenuItem* menuitem, gpointer data) {
|
void ALabel::handleGtkMenuEvent(GtkMenuItem* /*menuitem*/, gpointer data) {
|
||||||
waybar::util::command::res res = waybar::util::command::exec((char*)data, "GtkMenu");
|
waybar::util::command::res res = waybar::util::command::exec((char*)data, "GtkMenu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ const std::vector<std::string> Config::CONFIG_DIRS = {
|
||||||
|
|
||||||
const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR";
|
const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR";
|
||||||
|
|
||||||
std::optional<std::string> tryExpandPath(const std::string &base, const std::string &filename) {
|
std::optional<std::string> Config::tryExpandPath(const std::string &base,
|
||||||
|
const std::string &filename) {
|
||||||
fs::path path;
|
fs::path path;
|
||||||
|
|
||||||
if (!filename.empty()) {
|
if (!filename.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue