Merge pull request #1793 from Dordovel/master

This commit is contained in:
Alex 2022-11-16 07:41:29 +01:00 committed by GitHub
commit 56b4a11a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 14 deletions

View File

@ -14,16 +14,14 @@ class User : public AIconLabel {
~User() = default;
auto update() -> void;
bool handleToggle(GdkEventButton* const& e) override;
private:
util::SleeperThread thread_;
Glib::RefPtr<Gdk::Pixbuf> pixbuf_;
static constexpr inline int defaultUserImageWidth_ = 20;
static constexpr inline int defaultUserImageHeight_ = 20;
bool signal_label(GdkEventButton* button) const;
long uptime_as_seconds();
std::string get_user_login() const;
std::string get_user_home_dir() const;

View File

@ -7,6 +7,7 @@
#include <algorithm>
#include <chrono>
#include "gdkmm/cursor.h"
#include "gdkmm/event.h"
#include "gdkmm/types.h"
#include "sigc++/functors/mem_fun.h"
@ -20,25 +21,31 @@
#include <time.h>
#endif
#define LEFT_MOUSE_BUTTON 1
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, false, true) {
: AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", 60, false, true, true) {
if (AIconLabel::iconEnabled()) {
this->init_avatar(AIconLabel::config_);
}
this->init_update_worker();
AModule::event_box_.signal_button_press_event().connect(sigc::mem_fun(this, &User::signal_label));
}
bool User::signal_label(GdkEventButton* button) const {
if (button->type != GDK_BUTTON_PRESS) return true;
if (button->button == LEFT_MOUSE_BUTTON) {
Gio::AppInfo::launch_default_for_uri("file:///" + this->get_user_home_dir());
bool User::handleToggle(GdkEventButton* const& e) {
if (AIconLabel::config_["open-on-click"].isBool() &&
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);
}
return false;
}
Gio::AppInfo::launch_default_for_uri("file:///" + openPath);
}
return true;
}
long User::uptime_as_seconds() {
@ -99,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<Gdk::Pixbuf> pixbuf_ = Gdk::Pixbuf::create_from_file(path, width, height);
AIconLabel::image_.set(pixbuf_);
}
auto User::update() -> void {