Skip to content

Commit d5e3e26

Browse files
AlexaysLukashonakV
authored andcommitted
Merge pull request Alexays#3604 from alebastr/tray-fix
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
1 parent 0d02f68 commit d5e3e26

File tree

134 files changed

+1668
-1887
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1668
-1887
lines changed

flake.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/AAppIconLabel.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

3-
#include <gtkmm/box.h>
4-
#include <gtkmm/image.h>
3+
#include <gtkmm/icontheme.h>
54

65
#include "AIconLabel.hpp"
76

@@ -19,9 +18,12 @@ class AAppIconLabel : public AIconLabel {
1918
void updateAppIconName(const std::string &app_identifier,
2019
const std::string &alternative_app_identifier);
2120
void updateAppIcon();
21+
22+
private:
2223
unsigned app_icon_size_{24};
2324
bool update_app_icon_{true};
2425
std::string app_icon_name_;
26+
Glib::RefPtr<const Gtk::IconTheme> gtkTheme_;
2527
};
2628

2729
} // namespace waybar

include/AIconLabel.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AIconLabel : public ALabel {
1414
bool enable_click = false, bool enable_scroll = false);
1515
virtual ~AIconLabel() = default;
1616
auto update() -> void override;
17+
operator Gtk::Widget &() override;
1718

1819
protected:
1920
Gtk::Image image_;

include/ALabel.hpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
#pragma once
22

3-
#include <glibmm/markup.h>
3+
#include <chrono>
44
#include <gtkmm/label.h>
5-
#include <json/json.h>
65

76
#include "AModule.hpp"
87

98
namespace waybar {
109

1110
class ALabel : public AModule {
1211
public:
13-
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
14-
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
15-
bool enable_scroll = false);
1612
virtual ~ALabel() = default;
1713
auto update() -> void override;
1814
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
1915
virtual std::string getIcon(uint16_t, const std::vector<std::string> &alts, uint16_t max = 0);
16+
operator Gtk::Widget &() override;
2017

2118
protected:
22-
Gtk::Label label_;
19+
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
20+
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
21+
bool enable_scroll = false);
22+
2323
std::string format_;
24+
Gtk::Label label_;
2425
const std::chrono::seconds interval_;
2526
bool alt_ = false;
2627
std::string default_format_;
2728

28-
bool handleToggle(GdkEventButton *const &e) override;
29+
void handleToggle(int n_press, double dx, double dy) override;
2930
virtual std::string getState(uint8_t value, bool lesser = false);
30-
31-
std::map<std::string, GtkMenuItem *> submenus_;
32-
std::map<std::string, std::string> menuActionsMap_;
33-
static void handleGtkMenuEvent(GtkMenuItem *menuitem, gpointer data);
3431
};
3532

3633
} // namespace waybar

include/AModule.hpp

+58-43
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#pragma once
22

33
#include <glibmm/dispatcher.h>
4-
#include <glibmm/markup.h>
5-
#include <gtkmm.h>
6-
#include <gtkmm/eventbox.h>
4+
#include <gtkmm/gestureclick.h>
5+
#include <gtkmm/eventcontrollerscroll.h>
6+
#include <gtkmm/eventcontrollermotion.h>
77
#include <json/json.h>
88

99
#include "IModule.hpp"
10-
1110
namespace waybar {
1211

1312
class AModule : public IModule {
1413
public:
15-
static constexpr const char *MODULE_CLASS = "module";
14+
static constexpr const char *MODULE_CLASS{"module"};
1615

1716
~AModule() override;
1817
auto update() -> void override;
@@ -28,54 +27,70 @@ class AModule : public IModule {
2827
// Derived classes are able to use it
2928
AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false,
3029
bool enable_scroll = false);
31-
30+
const std::string name_;
31+
const Json::Value &config_;
32+
Glib::RefPtr<Gtk::GestureClick> controllClick_;
33+
Glib::RefPtr<Gtk::EventControllerScroll> controllScroll_;
34+
Glib::RefPtr<Gtk::EventControllerMotion> controllMotion_;
3235
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
3336

34-
SCROLL_DIR getScrollDir(GdkEventScroll *e);
37+
void bindEvents(Gtk::Widget& wg);
38+
void unBindEvents();
3539
bool tooltipEnabled() const;
3640

37-
const std::string name_;
38-
const Json::Value &config_;
39-
Gtk::EventBox event_box_;
40-
41-
virtual void setCursor(Gdk::CursorType const &c);
41+
virtual void setCursor(const Glib::RefPtr<Gdk::Cursor> &cur);
42+
virtual void setCursor(const Glib::ustring &name);
4243

43-
virtual bool handleToggle(GdkEventButton *const &ev);
44-
virtual bool handleMouseEnter(GdkEventCrossing *const &ev);
45-
virtual bool handleMouseLeave(GdkEventCrossing *const &ev);
46-
virtual bool handleScroll(GdkEventScroll *);
47-
virtual bool handleRelease(GdkEventButton *const &ev);
48-
GObject *menu_;
44+
virtual void handleToggle(int n_press, double dx, double dy);
45+
virtual void handleRelease(int n_press, double dx, double dy);
46+
virtual bool handleScroll(double dx, double dy);
47+
virtual void handleMouseEnter(double x, double y);
48+
virtual void handleMouseLeave();
49+
const SCROLL_DIR getScrollDir(Glib::RefPtr<const Gdk::Event> e);
4950

5051
private:
51-
bool handleUserEvent(GdkEventButton *const &ev);
5252
const bool isTooltip;
53-
bool hasUserEvents_;
53+
const bool isAfter{true};
54+
bool enableClick_{false};
55+
bool enableScroll_{false};
56+
bool hasPressEvents_{false};
57+
bool hasReleaseEvents_{false};
5458
std::vector<int> pid_;
55-
gdouble distance_scrolled_y_;
56-
gdouble distance_scrolled_x_;
59+
double distance_scrolled_x_{0.0};
60+
double distance_scrolled_y_{0.0};
61+
const Glib::RefPtr<Gdk::Cursor> curDefault;
62+
const Glib::RefPtr<Gdk::Cursor> curPoint;
63+
Glib::RefPtr<const Gdk::Event> currEvent_;
5764
std::map<std::string, std::string> eventActionMap_;
58-
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
59-
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
60-
{std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"},
61-
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
62-
{std::make_pair(1, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click"},
63-
{std::make_pair(2, GdkEventType::GDK_BUTTON_PRESS), "on-click-middle"},
64-
{std::make_pair(2, GdkEventType::GDK_BUTTON_RELEASE), "on-click-middle-release"},
65-
{std::make_pair(2, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-middle"},
66-
{std::make_pair(2, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-middle"},
67-
{std::make_pair(3, GdkEventType::GDK_BUTTON_PRESS), "on-click-right"},
68-
{std::make_pair(3, GdkEventType::GDK_BUTTON_RELEASE), "on-click-right-release"},
69-
{std::make_pair(3, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-right"},
70-
{std::make_pair(3, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-right"},
71-
{std::make_pair(8, GdkEventType::GDK_BUTTON_PRESS), "on-click-backward"},
72-
{std::make_pair(8, GdkEventType::GDK_BUTTON_RELEASE), "on-click-backward-release"},
73-
{std::make_pair(8, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-backward"},
74-
{std::make_pair(8, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-backward"},
75-
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
76-
{std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"},
77-
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
78-
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};
65+
static const inline std::map<std::pair<std::pair<uint, int>,Gdk::Event::Type>, std::string> eventMap_ {
66+
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click"},
67+
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-release"},
68+
{std::make_pair(std::make_pair(1u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click"},
69+
{std::make_pair(std::make_pair(1u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click"},
70+
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-middle"},
71+
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-middle-release"},
72+
{std::make_pair(std::make_pair(2u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-middle"},
73+
{std::make_pair(std::make_pair(2u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-middle"},
74+
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-right"},
75+
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-right-release"},
76+
{std::make_pair(std::make_pair(3u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-right"},
77+
{std::make_pair(std::make_pair(3u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-right"},
78+
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-backward"},
79+
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-backward-release"},
80+
{std::make_pair(std::make_pair(8u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-backward"},
81+
{std::make_pair(std::make_pair(8u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-backward"},
82+
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-forward"},
83+
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_RELEASE), "on-click-forward-release"},
84+
{std::make_pair(std::make_pair(9u, 2), Gdk::Event::Type::BUTTON_PRESS), "on-double-click-forward"},
85+
{std::make_pair(std::make_pair(9u, 3), Gdk::Event::Type::BUTTON_PRESS), "on-triple-click-forward"}
86+
};
87+
void handleClickEvent(uint n_button, int n_press, Gdk::Event::Type n_evtype);
88+
void makeControllClick();
89+
void makeControllScroll();
90+
void makeControllMotion();
91+
void removeControllClick();
92+
void removeControllScroll();
93+
void removeControllMotion();
7994
};
8095

8196
} // namespace waybar

include/ASlider.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class ASlider : public AModule {
99
public:
1010
ASlider(const Json::Value& config, const std::string& name, const std::string& id);
1111
virtual void onValueChanged();
12+
operator Gtk::Widget &() override;
1213

1314
protected:
14-
bool vertical_ = false;
15-
int min_ = 0, max_ = 100, curr_ = 50;
15+
bool vertical_{false};
16+
int min_{0}, max_{100}, curr_{50};
1617
Gtk::Scale scale_;
1718
};
1819

19-
} // namespace waybar
20+
} // namespace waybar

include/bar.hpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#pragma once
22

33
#include <gdkmm/monitor.h>
4-
#include <glibmm/refptr.h>
54
#include <gtkmm/box.h>
5+
#include <gtkmm/centerbox.h>
66
#include <gtkmm/cssprovider.h>
7-
#include <gtkmm/main.h>
87
#include <gtkmm/window.h>
9-
#include <json/json.h>
10-
11-
#include <memory>
12-
#include <optional>
13-
#include <vector>
148

159
#include "AModule.hpp"
1610
#include "group.hpp"
@@ -42,7 +36,7 @@ struct bar_margins {
4236
};
4337

4438
struct bar_mode {
45-
std::optional<bar_layer> layer;
39+
bar_layer layer;
4640
bool exclusive;
4741
bool passthrough;
4842
bool visible;
@@ -71,33 +65,34 @@ class Bar : public sigc::trackable {
7165
void handleSignal(int);
7266

7367
struct waybar_output *output;
74-
Json::Value config;
7568
struct wl_surface *surface;
7669
bool visible = true;
7770
Gtk::Window window;
78-
Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL;
79-
Gtk::PositionType position = Gtk::POS_TOP;
80-
81-
int x_global;
82-
int y_global;
71+
Json::Value config;
72+
Gtk::Orientation orientation{Gtk::Orientation::HORIZONTAL};
73+
Gtk::PositionType position{Gtk::PositionType::TOP};
8374

8475
#ifdef HAVE_SWAY
8576
std::string bar_id;
8677
#endif
8778

8879
private:
89-
void onMap(GdkEventAny *);
80+
void onMap();
9081
auto setupWidgets() -> void;
9182
void getModules(const Factory &, const std::string &, waybar::Group *);
9283
void setupAltFormatKeyForModule(const std::string &module_name);
9384
void setupAltFormatKeyForModuleList(const char *module_list_name);
9485
void setMode(const bar_mode &);
9586
void setPassThrough(bool passthrough);
9687
void setPosition(Gtk::PositionType position);
97-
void onConfigure(GdkEventConfigure *ev);
88+
void onConfigure(int width, int height);
9889
void configureGlobalOffset(int width, int height);
9990
void onOutputGeometryChanged();
10091

92+
Glib::RefPtr<Gdk::Surface> gdk_surface_;
93+
int x_global;
94+
int y_global;
95+
10196
/* Copy initial set of modes to allow customization */
10297
bar_mode_map configured_modes = PRESET_MODES;
10398
std::string last_mode_{MODE_DEFAULT};
@@ -109,7 +104,7 @@ class Bar : public sigc::trackable {
109104
Gtk::Box left_;
110105
Gtk::Box center_;
111106
Gtk::Box right_;
112-
Gtk::Box box_;
107+
Gtk::CenterBox box_;
113108
std::vector<std::shared_ptr<waybar::AModule>> modules_left_;
114109
std::vector<std::shared_ptr<waybar::AModule>> modules_center_;
115110
std::vector<std::shared_ptr<waybar::AModule>> modules_right_;

include/client.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#pragma once
22

3-
#include <fmt/format.h>
4-
#include <gdk/gdk.h>
5-
#include <gdk/gdkwayland.h>
6-
#include <wayland-client.h>
3+
#include <gdk/wayland/gdkwayland.h>
74

85
#include "bar.hpp"
96
#include "config.hpp"
@@ -33,6 +30,7 @@ class Client {
3330

3431
private:
3532
Client() = default;
33+
Glib::RefPtr<Gio::ListModel> monitors_;
3634
const std::string getStyle(const std::string &style, std::optional<Appearance> appearance);
3735
void bindInterfaces();
3836
void handleOutput(struct waybar_output &output);
@@ -50,7 +48,6 @@ class Client {
5048
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
5149
void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor);
5250

53-
Glib::RefPtr<Gtk::StyleContext> style_context_;
5451
Glib::RefPtr<Gtk::CssProvider> css_provider_;
5552
std::unique_ptr<Portal> portal;
5653
std::list<struct waybar_output> outputs_;

include/factory.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <json/json.h>
4-
53
#include <AModule.hpp>
64

75
namespace waybar {

0 commit comments

Comments
 (0)