mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1793 from Dordovel/master
This commit is contained in:
commit
56b4a11a9c
@ -14,16 +14,14 @@ class User : public AIconLabel {
|
|||||||
~User() = default;
|
~User() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
|
bool handleToggle(GdkEventButton* const& e) override;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
bool signal_label(GdkEventButton* button) const;
|
|
||||||
|
|
||||||
long uptime_as_seconds();
|
long uptime_as_seconds();
|
||||||
std::string get_user_login() const;
|
std::string get_user_login() const;
|
||||||
std::string get_user_home_dir() const;
|
std::string get_user_home_dir() const;
|
||||||
|
@ -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,25 +21,31 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LEFT_MOUSE_BUTTON 1
|
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, false, true) {
|
: AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", 60, false, true, true) {
|
||||||
if (AIconLabel::iconEnabled()) {
|
if (AIconLabel::iconEnabled()) {
|
||||||
this->init_avatar(AIconLabel::config_);
|
this->init_avatar(AIconLabel::config_);
|
||||||
}
|
}
|
||||||
this->init_update_worker();
|
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 {
|
bool User::handleToggle(GdkEventButton* const& e) {
|
||||||
if (button->type != GDK_BUTTON_PRESS) return true;
|
if (AIconLabel::config_["open-on-click"].isBool() &&
|
||||||
|
AIconLabel::config_["open-on-click"].asBool() && e->button == LEFT_MOUSE_BUTTON_CODE) {
|
||||||
if (button->button == LEFT_MOUSE_BUTTON) {
|
std::string openPath = this->get_user_home_dir();
|
||||||
Gio::AppInfo::launch_default_for_uri("file:///" + 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() {
|
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) {
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user