From 1111763251661751ba38addedf5b287781f13c70 Mon Sep 17 00:00:00 2001 From: Dordovel Date: Wed, 16 Nov 2022 08:04:18 +0300 Subject: [PATCH] added path settings --- include/modules/user.hpp | 2 -- src/modules/user.cpp | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/modules/user.hpp b/include/modules/user.hpp index 68eef521..ac14d25f 100644 --- a/include/modules/user.hpp +++ b/include/modules/user.hpp @@ -19,8 +19,6 @@ class User : public AIconLabel { private: util::SleeperThread thread_; - Glib::RefPtr pixbuf_; - static constexpr inline int defaultUserImageWidth_ = 20; static constexpr inline int defaultUserImageHeight_ = 20; diff --git a/src/modules/user.cpp b/src/modules/user.cpp index 1118634c..eab14106 100644 --- a/src/modules/user.cpp +++ b/src/modules/user.cpp @@ -7,6 +7,7 @@ #include #include +#include "gdkmm/cursor.h" #include "gdkmm/event.h" #include "gdkmm/types.h" #include "sigc++/functors/mem_fun.h" @@ -20,6 +21,8 @@ #include #endif +const static int LEFT_MOUSE_BUTTON_CODE = 1; + namespace waybar::modules { User::User(const std::string& id, const Json::Value& config) : AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", 60, false, true, true) { @@ -31,10 +34,18 @@ User::User(const std::string& id, const Json::Value& config) bool User::handleToggle(GdkEventButton* const& e) { if (AIconLabel::config_["open-on-click"].isBool() && - AIconLabel::config_["open-on-click"].asBool()) { - Gio::AppInfo::launch_default_for_uri("file:///" + this->get_user_home_dir()); + AIconLabel::config_["open-on-click"].asBool() && e->button == LEFT_MOUSE_BUTTON_CODE) { + std::string openPath = this->get_user_home_dir(); + if (AIconLabel::config_["open-path"].isString()) { + std::string customPath = AIconLabel::config_["open-path"].asString(); + if (!customPath.empty()) { + openPath = std::move(customPath); + } + } + + Gio::AppInfo::launch_default_for_uri("file:///" + openPath); } - return ALabel::handleToggle(e); + return true; } long User::uptime_as_seconds() { @@ -95,8 +106,8 @@ void User::init_default_user_avatar(int width, int height) { } void User::init_user_avatar(const std::string& path, int width, int height) { - this->pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height); - AIconLabel::image_.set(this->pixbuf_); + Glib::RefPtr pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height); + AIconLabel::image_.set(pixbuf_); } auto User::update() -> void {