GTK4. First success run win clock module
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>pull/2956/head
parent
54ef531501
commit
c5b726ae5a
|
@ -1,32 +1,29 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <glibmm/markup.h>
|
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <json/json.h>
|
|
||||||
|
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
class ALabel : public AModule {
|
class ALabel : public AModule, public Gtk::Label {
|
||||||
public:
|
public:
|
||||||
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
|
||||||
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
|
|
||||||
bool enable_scroll = false);
|
|
||||||
virtual ~ALabel() = default;
|
virtual ~ALabel() = default;
|
||||||
auto update() -> void override;
|
auto update() -> void override;
|
||||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||||
virtual std::string getIcon(uint16_t, const std::vector<std::string> &alts, uint16_t max = 0);
|
virtual std::string getIcon(uint16_t, const std::vector<std::string> &alts, uint16_t max = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Gtk::Label label_;
|
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||||
|
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
|
||||||
|
bool enable_scroll = false);
|
||||||
|
|
||||||
std::string format_;
|
std::string format_;
|
||||||
const std::chrono::seconds interval_;
|
const std::chrono::seconds interval_;
|
||||||
bool alt_ = false;
|
bool alt_ = false;
|
||||||
std::string default_format_;
|
std::string default_format_;
|
||||||
|
|
||||||
//todo bool handleToggle(GdkEventButton *const &e) override;
|
|
||||||
void handleToggle(int n_press, double dx, double dy);
|
void handleToggle(int n_press, double dx, double dy);
|
||||||
virtual std::string getState(uint8_t value, bool lesser = false);
|
virtual std::string getState(uint8_t value, bool lesser = false);
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,8 +35,8 @@ class AModule : public IModule {
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
const Json::Value &config_;
|
const Json::Value &config_;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::GestureClick> handleClick_;
|
Glib::RefPtr<Gtk::GestureClick> controllClick_;
|
||||||
Glib::RefPtr<Gtk::EventControllerScroll> handleScroll_;
|
Glib::RefPtr<Gtk::EventControllerScroll> controllScroll_;
|
||||||
virtual void handleToggle(int n_press, double dx, double dy);
|
virtual void handleToggle(int n_press, double dx, double dy);
|
||||||
virtual void handleRelease(int n_press, double dx, double dy);
|
virtual void handleRelease(int n_press, double dx, double dy);
|
||||||
virtual bool handleScroll(double dx, double dy);
|
virtual bool handleScroll(double dx, double dy);
|
||||||
|
@ -44,8 +44,8 @@ class AModule : public IModule {
|
||||||
private:
|
private:
|
||||||
const bool isTooltip;
|
const bool isTooltip;
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
double distance_scrolled_y_{0.0};
|
|
||||||
double distance_scrolled_x_{0.0};
|
double distance_scrolled_x_{0.0};
|
||||||
|
double distance_scrolled_y_{0.0};
|
||||||
Glib::RefPtr<const Gdk::Event> currEvent_;
|
Glib::RefPtr<const Gdk::Event> currEvent_;
|
||||||
std::map<std::string, std::string> eventActionMap_;
|
std::map<std::string, std::string> eventActionMap_;
|
||||||
static const inline std::map<std::pair<std::pair<uint, int>,Gdk::Event::Type>, std::string> eventMap_ {
|
static const inline std::map<std::pair<std::pair<uint, int>,Gdk::Event::Type>, std::string> eventMap_ {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
|
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
//#include "group.hpp"
|
#include "group.hpp"
|
||||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
@ -83,7 +83,7 @@ class Bar {
|
||||||
private:
|
private:
|
||||||
void onMap();
|
void onMap();
|
||||||
auto setupWidgets() -> void;
|
auto setupWidgets() -> void;
|
||||||
// void getModules(const Factory &, const std::string &, waybar::Group *);
|
void getModules(const Factory &, const std::string &, waybar::Group *);
|
||||||
void setupAltFormatKeyForModule(const std::string &module_name);
|
void setupAltFormatKeyForModule(const std::string &module_name);
|
||||||
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
||||||
void setMode(const bar_mode &);
|
void setMode(const bar_mode &);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <json/json.h>
|
|
||||||
|
|
||||||
#include <AModule.hpp>
|
#include <AModule.hpp>
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtkmm/box.h>
|
|
||||||
#include <gtkmm/widget.h>
|
|
||||||
#include <json/json.h>
|
|
||||||
|
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
|
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/eventcontrollermotion.h>
|
||||||
#include "gtkmm/revealer.h"
|
#include "gtkmm/revealer.h"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
@ -19,17 +18,19 @@ class Group : public AModule {
|
||||||
virtual Gtk::Box& getBox();
|
virtual Gtk::Box& getBox();
|
||||||
void addWidget(Gtk::Widget& widget);
|
void addWidget(Gtk::Widget& widget);
|
||||||
|
|
||||||
// bool handleMouseHover(GdkEventCrossing* const& e);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Gtk::Box box;
|
Gtk::Box box;
|
||||||
Gtk::Box revealer_box;
|
Gtk::Box revealer_box;
|
||||||
Gtk::Revealer revealer;
|
Gtk::Revealer revealer;
|
||||||
bool is_first_widget = true;
|
bool is_first_widget{true};
|
||||||
bool is_drawer = false;
|
bool is_drawer{false};
|
||||||
std::string add_class_to_drawer_children;
|
std::string add_class_to_drawer_children;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Glib::RefPtr<Gtk::EventControllerMotion> controllMotion_;
|
||||||
void addHoverHandlerTo(Gtk::Widget& widget);
|
void addHoverHandlerTo(Gtk::Widget& widget);
|
||||||
|
void onMotionEnter(double x, double y);
|
||||||
|
void onMotionLeave();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
|
@ -136,7 +136,8 @@ src_files = files(
|
||||||
'src/AModule.cpp',
|
'src/AModule.cpp',
|
||||||
'src/ALabel.cpp',
|
'src/ALabel.cpp',
|
||||||
'src/factory.cpp',
|
'src/factory.cpp',
|
||||||
'src/util/ustring_clen.cpp'
|
'src/util/ustring_clen.cpp',
|
||||||
|
'src/group.cpp'
|
||||||
)
|
)
|
||||||
|
|
||||||
man_files = files(
|
man_files = files(
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include <util/command.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,
|
||||||
|
@ -16,22 +12,22 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
||||||
: std::chrono::seconds(
|
: std::chrono::seconds(
|
||||||
config_["interval"].isUInt() ? config_["interval"].asUInt() : interval)),
|
config_["interval"].isUInt() ? config_["interval"].asUInt() : interval)),
|
||||||
default_format_(format_) {
|
default_format_(format_) {
|
||||||
label_.set_name(name);
|
Gtk::Label::set_name(name);
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
label_.get_style_context()->add_class(id);
|
Gtk::Label::get_style_context()->add_class(id);
|
||||||
}
|
}
|
||||||
label_.get_style_context()->add_class(MODULE_CLASS);
|
Gtk::Label::get_style_context()->add_class(MODULE_CLASS);
|
||||||
if (config_["max-length"].isUInt()) {
|
if (config_["max-length"].isUInt()) {
|
||||||
label_.set_max_width_chars(config_["max-length"].asInt());
|
Gtk::Label::set_max_width_chars(config_["max-length"].asInt());
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::END);
|
Gtk::Label::set_ellipsize(Pango::EllipsizeMode::END);
|
||||||
label_.set_single_line_mode(true);
|
Gtk::Label::set_single_line_mode(true);
|
||||||
} else if (ellipsize && label_.get_max_width_chars() == -1) {
|
} else if (ellipsize && Gtk::Label::get_max_width_chars() == -1) {
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::END);
|
Gtk::Label::set_ellipsize(Pango::EllipsizeMode::END);
|
||||||
label_.set_single_line_mode(true);
|
Gtk::Label::set_single_line_mode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_["min-length"].isUInt()) {
|
if (config_["min-length"].isUInt()) {
|
||||||
label_.set_width_chars(config_["min-length"].asUInt());
|
Gtk::Label::set_width_chars(config_["min-length"].asUInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint rotate = 0;
|
uint rotate = 0;
|
||||||
|
@ -45,9 +41,9 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
||||||
if (config_["align"].isDouble()) {
|
if (config_["align"].isDouble()) {
|
||||||
auto align = config_["align"].asFloat();
|
auto align = config_["align"].asFloat();
|
||||||
if (rotate == 90 || rotate == 270) {
|
if (rotate == 90 || rotate == 270) {
|
||||||
label_.set_yalign(align);
|
Gtk::Label::set_yalign(align);
|
||||||
} else {
|
} else {
|
||||||
label_.set_xalign(align);
|
Gtk::Label::set_xalign(align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +99,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::ALabel::handleToggle(int n_press, double dx, double dy) {
|
void waybar::ALabel::handleToggle(int n_press, double dx, double dy) {
|
||||||
if (config_["format-alt-click"].isUInt() && handleClick_->get_button() == config_["format-alt-click"].asUInt()) {
|
if (config_["format-alt-click"].isUInt() && controllClick_->get_button() == config_["format-alt-click"].asUInt()) {
|
||||||
alt_ = !alt_;
|
alt_ = !alt_;
|
||||||
if (alt_ && config_["format-alt"].isString()) {
|
if (alt_ && config_["format-alt"].isString()) {
|
||||||
format_ = config_["format-alt"].asString();
|
format_ = config_["format-alt"].asString();
|
||||||
|
@ -135,10 +131,10 @@ std::string ALabel::getState(uint8_t value, bool lesser) {
|
||||||
std::string valid_state;
|
std::string valid_state;
|
||||||
for (auto const& state : states) {
|
for (auto const& state : states) {
|
||||||
if ((lesser ? value <= state.second : value >= state.second) && valid_state.empty()) {
|
if ((lesser ? value <= state.second : value >= state.second) && valid_state.empty()) {
|
||||||
label_.get_style_context()->add_class(state.first);
|
Gtk::Label::get_style_context()->add_class(state.first);
|
||||||
valid_state = state.first;
|
valid_state = state.first;
|
||||||
} else {
|
} else {
|
||||||
label_.get_style_context()->remove_class(state.first);
|
Gtk::Label::get_style_context()->remove_class(state.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return valid_state;
|
return valid_state;
|
||||||
|
|
|
@ -8,11 +8,9 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
|
||||||
bool enable_click, bool enable_scroll)
|
bool enable_click, bool enable_scroll)
|
||||||
: name_(std::move(name)),
|
: name_(std::move(name)),
|
||||||
config_(std::move(config)),
|
config_(std::move(config)),
|
||||||
isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true},
|
controllClick_{Gtk::GestureClick::create()},
|
||||||
distance_scrolled_y_(0.0),
|
controllScroll_{Gtk::EventControllerScroll::create()},
|
||||||
distance_scrolled_x_(0.0),
|
isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true} {
|
||||||
handleClick_(Gtk::GestureClick::create()),
|
|
||||||
handleScroll_(Gtk::EventControllerScroll::create()){
|
|
||||||
// Configure module action Map
|
// Configure module action Map
|
||||||
const Json::Value actions{config_["actions"]};
|
const Json::Value actions{config_["actions"]};
|
||||||
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
|
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
|
||||||
|
@ -42,19 +40,19 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
|
||||||
}) != eventMap_.cend()};
|
}) != eventMap_.cend()};
|
||||||
|
|
||||||
if (enable_click || hasUserPressEvent || hasUserReleaseEvent) {
|
if (enable_click || hasUserPressEvent || hasUserReleaseEvent) {
|
||||||
handleClick_->set_propagation_phase(Gtk::PropagationPhase::TARGET);
|
controllClick_->set_propagation_phase(Gtk::PropagationPhase::TARGET);
|
||||||
((Gtk::Widget&)*this).add_controller(handleClick_);
|
// (this->operator Gtk::Widget&()).add_controller(controllClick_);
|
||||||
|
|
||||||
if (enable_click || hasUserPressEvent)
|
if (enable_click || hasUserPressEvent)
|
||||||
handleClick_->signal_pressed().connect(sigc::mem_fun(*this, &AModule::handleToggle), after);
|
controllClick_->signal_pressed().connect(sigc::mem_fun(*this, &AModule::handleToggle), after);
|
||||||
if (hasUserReleaseEvent)
|
if (hasUserReleaseEvent)
|
||||||
handleClick_->signal_released().connect(sigc::mem_fun(*this, &AModule::handleRelease), after);
|
controllClick_->signal_released().connect(sigc::mem_fun(*this, &AModule::handleRelease), after);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enable_scroll || config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
if (enable_scroll || config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||||
handleScroll_->set_propagation_phase(Gtk::PropagationPhase::TARGET);
|
controllScroll_->set_propagation_phase(Gtk::PropagationPhase::TARGET);
|
||||||
((Gtk::Widget&)*this).add_controller(handleScroll_);
|
// ((Gtk::Widget&)*this).add_controller(controllScroll_);
|
||||||
handleScroll_->signal_scroll().connect(sigc::mem_fun(*this, &AModule::handleScroll), after);
|
controllScroll_->signal_scroll().connect(sigc::mem_fun(*this, &AModule::handleScroll), after);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +81,10 @@ auto AModule::doAction(const std::string& name) -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AModule::handleToggle(int n_press, double dx, double dy) {
|
void AModule::handleToggle(int n_press, double dx, double dy) {
|
||||||
handleClickEvent(handleClick_->get_current_button(), n_press, Gdk::Event::Type::BUTTON_PRESS);
|
handleClickEvent(controllClick_->get_current_button(), n_press, Gdk::Event::Type::BUTTON_PRESS);
|
||||||
}
|
}
|
||||||
void AModule::handleRelease(int n_press, double dx, double dy) {
|
void AModule::handleRelease(int n_press, double dx, double dy) {
|
||||||
handleClickEvent(handleClick_->get_current_button(), n_press, Gdk::Event::Type::BUTTON_RELEASE);
|
handleClickEvent(controllClick_->get_current_button(), n_press, Gdk::Event::Type::BUTTON_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AModule::handleClickEvent(uint n_button, int n_press, Gdk::Event::Type n_evtype) {
|
void AModule::handleClickEvent(uint n_button, int n_press, Gdk::Event::Type n_evtype) {
|
||||||
|
@ -176,7 +174,7 @@ const AModule::SCROLL_DIR AModule::getScrollDir(Glib::RefPtr<const Gdk::Event> e
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AModule::handleScroll(double dx, double dy) {
|
bool AModule::handleScroll(double dx, double dy) {
|
||||||
currEvent_ = handleScroll_->get_current_event();
|
currEvent_ = controllScroll_->get_current_event();
|
||||||
|
|
||||||
if (currEvent_) {
|
if (currEvent_) {
|
||||||
std::string format{};
|
std::string format{};
|
||||||
|
@ -201,6 +199,6 @@ bool AModule::handleScroll(double dx, double dy) {
|
||||||
|
|
||||||
bool AModule::tooltipEnabled() { return isTooltip; }
|
bool AModule::tooltipEnabled() { return isTooltip; }
|
||||||
|
|
||||||
AModule::operator Gtk::Widget&() { return *this; }
|
AModule::operator Gtk::Widget&() { return dynamic_cast<Gtk::Widget&>(*this); }
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
18
src/bar.cpp
18
src/bar.cpp
|
@ -4,8 +4,7 @@
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
//#include "factory.hpp"
|
#include "factory.hpp"
|
||||||
//#include "group.hpp"
|
|
||||||
|
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
#include "modules/sway/bar.hpp"
|
#include "modules/sway/bar.hpp"
|
||||||
|
@ -108,6 +107,8 @@ Glib::ustring to_string(Gtk::PositionType pos) {
|
||||||
return "top";
|
return "top";
|
||||||
case Gtk::PositionType::BOTTOM:
|
case Gtk::PositionType::BOTTOM:
|
||||||
return "bottom";
|
return "bottom";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,8 +459,6 @@ void waybar::Bar::handleSignal(int signal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo gtkmm4
|
|
||||||
/*
|
|
||||||
void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
||||||
waybar::Group* group = nullptr) {
|
waybar::Group* group = nullptr) {
|
||||||
auto module_list = group ? config[pos]["modules"] : config[pos];
|
auto module_list = group ? config[pos]["modules"] : config[pos];
|
||||||
|
@ -512,7 +511,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
auto waybar::Bar::setupWidgets() -> void {
|
auto waybar::Bar::setupWidgets() -> void {
|
||||||
box_.set_start_widget(left_);
|
box_.set_start_widget(left_);
|
||||||
if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) {
|
if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) {
|
||||||
|
@ -526,11 +525,10 @@ auto waybar::Bar::setupWidgets() -> void {
|
||||||
setupAltFormatKeyForModuleList("modules-right");
|
setupAltFormatKeyForModuleList("modules-right");
|
||||||
setupAltFormatKeyForModuleList("modules-center");
|
setupAltFormatKeyForModuleList("modules-center");
|
||||||
|
|
||||||
// todo gtkmm4
|
Factory factory(*this, config);
|
||||||
// Factory factory(*this, config);
|
getModules(factory, "modules-left");
|
||||||
// getModules(factory, "modules-left");
|
getModules(factory, "modules-center");
|
||||||
// getModules(factory, "modules-center");
|
getModules(factory, "modules-right");
|
||||||
// getModules(factory, "modules-right");
|
|
||||||
for (auto const& module : modules_left_) {
|
for (auto const& module : modules_left_) {
|
||||||
left_.prepend(*module);
|
left_.prepend(*module);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,19 @@
|
||||||
#include "group.hpp"
|
#include "group.hpp"
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include <util/command.hpp>
|
|
||||||
|
|
||||||
#include "gdkmm/device.h"
|
|
||||||
#include "gtkmm/widget.h"
|
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
const Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical, bool left_to_right) {
|
const Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical, bool left_to_right) {
|
||||||
if (is_vertical) {
|
if (is_vertical) {
|
||||||
if (left_to_right) {
|
if (left_to_right) {
|
||||||
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_DOWN;
|
return Gtk::RevealerTransitionType::SLIDE_DOWN;
|
||||||
} else {
|
} else {
|
||||||
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_UP;
|
return Gtk::RevealerTransitionType::SLIDE_UP;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (left_to_right) {
|
if (left_to_right) {
|
||||||
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_RIGHT;
|
return Gtk::RevealerTransitionType::SLIDE_RIGHT;
|
||||||
} else {
|
} else {
|
||||||
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_LEFT;
|
return Gtk::RevealerTransitionType::SLIDE_LEFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +21,9 @@ const Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical, b
|
||||||
Group::Group(const std::string& name, const std::string& id, const Json::Value& config,
|
Group::Group(const std::string& name, const std::string& id, const Json::Value& config,
|
||||||
bool vertical)
|
bool vertical)
|
||||||
: AModule(config, name, id, true, true),
|
: AModule(config, name, id, true, true),
|
||||||
box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0},
|
box{vertical ? Gtk::Orientation::VERTICAL : Gtk::Orientation::HORIZONTAL, 0},
|
||||||
revealer_box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} {
|
revealer_box{vertical ? Gtk::Orientation::VERTICAL : Gtk::Orientation::HORIZONTAL, 0},
|
||||||
|
controllMotion_{Gtk::EventControllerMotion::create()} {
|
||||||
box.set_name(name_);
|
box.set_name(name_);
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
box.get_style_context()->add_class(id);
|
box.get_style_context()->add_class(id);
|
||||||
|
@ -41,11 +35,11 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
|
||||||
if (orientation == "inherit") {
|
if (orientation == "inherit") {
|
||||||
// keep orientation passed
|
// keep orientation passed
|
||||||
} else if (orientation == "orthogonal") {
|
} else if (orientation == "orthogonal") {
|
||||||
box.set_orientation(vertical ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL);
|
box.set_orientation(vertical ? Gtk::Orientation::HORIZONTAL : Gtk::Orientation::VERTICAL);
|
||||||
} else if (orientation == "vertical") {
|
} else if (orientation == "vertical") {
|
||||||
box.set_orientation(Gtk::ORIENTATION_VERTICAL);
|
box.set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
} else if (orientation == "horizontal") {
|
} else if (orientation == "horizontal") {
|
||||||
box.set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
box.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Invalid orientation value: " + orientation);
|
throw std::runtime_error("Invalid orientation value: " + orientation);
|
||||||
}
|
}
|
||||||
|
@ -72,32 +66,26 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
|
||||||
|
|
||||||
revealer.get_style_context()->add_class("drawer");
|
revealer.get_style_context()->add_class("drawer");
|
||||||
|
|
||||||
revealer.add(revealer_box);
|
revealer.set_child(revealer_box);
|
||||||
box.pack_start(revealer);
|
box.prepend(revealer);
|
||||||
|
|
||||||
addHoverHandlerTo(revealer);
|
addHoverHandlerTo(revealer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Group::handleMouseHover(GdkEventCrossing* const& e) {
|
void Group::onMotionEnter(double x, double y) {
|
||||||
switch (e->type) {
|
|
||||||
case GDK_ENTER_NOTIFY:
|
|
||||||
revealer.set_reveal_child(true);
|
revealer.set_reveal_child(true);
|
||||||
break;
|
}
|
||||||
case GDK_LEAVE_NOTIFY:
|
|
||||||
revealer.set_reveal_child(false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
void Group::onMotionLeave() {
|
||||||
|
revealer.set_reveal_child(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::addHoverHandlerTo(Gtk::Widget& widget) {
|
void Group::addHoverHandlerTo(Gtk::Widget& widget) {
|
||||||
widget.add_events(Gdk::EventMask::ENTER_NOTIFY_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK);
|
controllMotion_->set_propagation_phase(Gtk::PropagationPhase::TARGET);
|
||||||
widget.signal_enter_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
|
box.add_controller(controllMotion_);
|
||||||
widget.signal_leave_notify_event().connect(sigc::mem_fun(*this, &Group::handleMouseHover));
|
controllMotion_->signal_enter().connect(sigc::mem_fun(*this, &Group::onMotionEnter));
|
||||||
|
controllMotion_->signal_leave().connect(sigc::mem_fun(*this, &Group::onMotionLeave));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Group::update() -> void {
|
auto Group::update() -> void {
|
||||||
|
@ -107,7 +95,7 @@ auto Group::update() -> void {
|
||||||
Gtk::Box& Group::getBox() { return is_drawer ? (is_first_widget ? box : revealer_box) : box; }
|
Gtk::Box& Group::getBox() { return is_drawer ? (is_first_widget ? box : revealer_box) : box; }
|
||||||
|
|
||||||
void Group::addWidget(Gtk::Widget& widget) {
|
void Group::addWidget(Gtk::Widget& widget) {
|
||||||
getBox().pack_start(widget, false, false);
|
getBox().prepend(widget);
|
||||||
|
|
||||||
if (is_drawer) {
|
if (is_drawer) {
|
||||||
// Necessary because of GTK's hitbox detection
|
// Necessary because of GTK's hitbox detection
|
||||||
|
|
|
@ -132,7 +132,7 @@ auto waybar::modules::Clock::update() -> void {
|
||||||
auto tz{tzList_[tzCurrIdx_]};
|
auto tz{tzList_[tzCurrIdx_]};
|
||||||
const zoned_time now{tz, floor<seconds>(system_clock::now())};
|
const zoned_time now{tz, floor<seconds>(system_clock::now())};
|
||||||
|
|
||||||
label_.set_markup(fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(now)));
|
Gtk::Label::set_markup(fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(now)));
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
const year_month_day today{floor<days>(now.get_local_time())};
|
const year_month_day today{floor<days>(now.get_local_time())};
|
||||||
|
@ -151,7 +151,7 @@ auto waybar::modules::Clock::update() -> void {
|
||||||
|
|
||||||
tlpText_ = fmt_lib::vformat(locale_, tlpText_, fmt_lib::make_format_args(shiftedNow));
|
tlpText_ = fmt_lib::vformat(locale_, tlpText_, fmt_lib::make_format_args(shiftedNow));
|
||||||
|
|
||||||
label_.set_tooltip_markup(tlpText_);
|
Gtk::Label::set_tooltip_markup(tlpText_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
|
|
Loading…
Reference in New Issue