added path settings

This commit is contained in:
Dordovel 2022-11-16 08:04:18 +03:00
parent 769858fbb4
commit 1111763251
2 changed files with 16 additions and 7 deletions

View File

@ -19,8 +19,6 @@ class User : public AIconLabel {
private: private:
util::SleeperThread thread_; util::SleeperThread thread_;
Glib::RefPtr<Gdk::Pixbuf> pixbuf_;
static constexpr inline int defaultUserImageWidth_ = 20; static constexpr inline int defaultUserImageWidth_ = 20;
static constexpr inline int defaultUserImageHeight_ = 20; static constexpr inline int defaultUserImageHeight_ = 20;

View File

@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
#include "gdkmm/cursor.h"
#include "gdkmm/event.h" #include "gdkmm/event.h"
#include "gdkmm/types.h" #include "gdkmm/types.h"
#include "sigc++/functors/mem_fun.h" #include "sigc++/functors/mem_fun.h"
@ -20,6 +21,8 @@
#include <time.h> #include <time.h>
#endif #endif
const static int LEFT_MOUSE_BUTTON_CODE = 1;
namespace waybar::modules { namespace waybar::modules {
User::User(const std::string& id, const Json::Value& config) User::User(const std::string& id, const Json::Value& config)
: AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", 60, false, true, true) { : 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) { bool User::handleToggle(GdkEventButton* const& e) {
if (AIconLabel::config_["open-on-click"].isBool() && if (AIconLabel::config_["open-on-click"].isBool() &&
AIconLabel::config_["open-on-click"].asBool()) { AIconLabel::config_["open-on-click"].asBool() && e->button == LEFT_MOUSE_BUTTON_CODE) {
Gio::AppInfo::launch_default_for_uri("file:///" + this->get_user_home_dir()); 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);
} }
return ALabel::handleToggle(e); }
Gio::AppInfo::launch_default_for_uri("file:///" + openPath);
}
return true;
} }
long User::uptime_as_seconds() { 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) { void User::init_user_avatar(const std::string& path, int width, int height) {
this->pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height); Glib::RefPtr<Gdk::Pixbuf> pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height);
AIconLabel::image_.set(this->pixbuf_); AIconLabel::image_.set(pixbuf_);
} }
auto User::update() -> void { auto User::update() -> void {