Skip to content

Commit

Permalink
GTK4 migration
Browse files Browse the repository at this point in the history
Signed-off-by: Viktar Lukashonak <[email protected]>
  • Loading branch information
LukashonakV committed Oct 23, 2024
1 parent dacecb9 commit 048c3e2
Show file tree
Hide file tree
Showing 129 changed files with 1,659 additions and 1,884 deletions.
6 changes: 4 additions & 2 deletions include/AAppIconLabel.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include <gtkmm/icontheme.h>

#include "AIconLabel.hpp"

Expand All @@ -19,9 +18,12 @@ class AAppIconLabel : public AIconLabel {
void updateAppIconName(const std::string &app_identifier,
const std::string &alternative_app_identifier);
void updateAppIcon();

private:
unsigned app_icon_size_{24};
bool update_app_icon_{true};
std::string app_icon_name_;
Glib::RefPtr<const Gtk::IconTheme> gtkTheme_;
};

} // namespace waybar
1 change: 1 addition & 0 deletions include/AIconLabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AIconLabel : public ALabel {
bool enable_click = false, bool enable_scroll = false);
virtual ~AIconLabel() = default;
auto update() -> void override;
operator Gtk::Widget &() override;

protected:
Gtk::Image image_;
Expand Down
20 changes: 9 additions & 11 deletions include/ALabel.hpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
#pragma once

#include <glibmm/markup.h>
#include <gtkmm/label.h>
#include <json/json.h>

#include <chrono>

#include "AModule.hpp"

namespace waybar {

class ALabel : public AModule {
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;
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::vector<std::string> &alts, uint16_t max = 0);
operator Gtk::Widget &() override;

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_;
Gtk::Label label_;
const std::chrono::seconds interval_;
bool alt_ = false;
std::string default_format_;

bool handleToggle(GdkEventButton *const &e) override;
void handleToggle(int n_press, double dx, double dy) override;
virtual std::string getState(uint8_t value, bool lesser = false);

std::map<std::string, GtkMenuItem *> submenus_;
std::map<std::string, std::string> menuActionsMap_;
static void handleGtkMenuEvent(GtkMenuItem *menuitem, gpointer data);
};

} // namespace waybar
119 changes: 76 additions & 43 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#pragma once

#include <glibmm/dispatcher.h>
#include <glibmm/markup.h>
#include <gtkmm.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/eventcontrollermotion.h>
#include <gtkmm/eventcontrollerscroll.h>
#include <gtkmm/gestureclick.h>
#include <json/json.h>

#include "IModule.hpp"

namespace waybar {

class AModule : public IModule {
public:
static constexpr const char *MODULE_CLASS = "module";
static constexpr const char *MODULE_CLASS{"module"};

~AModule() override;
auto update() -> void override;
Expand All @@ -28,54 +27,88 @@ class AModule : public IModule {
// Derived classes are able to use it
AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false,
bool enable_scroll = false);

const std::string name_;
const Json::Value &config_;
Glib::RefPtr<Gtk::GestureClick> controllClick_;
Glib::RefPtr<Gtk::EventControllerScroll> controllScroll_;
Glib::RefPtr<Gtk::EventControllerMotion> controllMotion_;
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };

SCROLL_DIR getScrollDir(GdkEventScroll *e);
void bindEvents(Gtk::Widget &wg);
void unBindEvents();
bool tooltipEnabled() const;

const std::string name_;
const Json::Value &config_;
Gtk::EventBox event_box_;

virtual void setCursor(Gdk::CursorType const &c);
virtual void setCursor(const Glib::RefPtr<Gdk::Cursor> &cur);
virtual void setCursor(const Glib::ustring &name);

virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleMouseEnter(GdkEventCrossing *const &ev);
virtual bool handleMouseLeave(GdkEventCrossing *const &ev);
virtual bool handleScroll(GdkEventScroll *);
virtual bool handleRelease(GdkEventButton *const &ev);
GObject *menu_;
virtual void handleToggle(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 void handleMouseEnter(double x, double y);
virtual void handleMouseLeave();
const SCROLL_DIR getScrollDir(Glib::RefPtr<const Gdk::Event> e);

private:
bool handleUserEvent(GdkEventButton *const &ev);
const bool isTooltip;
bool hasUserEvents_;
const bool isAfter{true};
bool enableClick_{false};
bool enableScroll_{false};
bool hasPressEvents_{false};
bool hasReleaseEvents_{false};
std::vector<int> pid_;
gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
double distance_scrolled_x_{0.0};
double distance_scrolled_y_{0.0};
const Glib::RefPtr<Gdk::Cursor> curDefault;
const Glib::RefPtr<Gdk::Cursor> curPoint;
Glib::RefPtr<const Gdk::Event> currEvent_;
std::map<std::string, std::string> eventActionMap_;
static const inline std::map<std::pair<uint, GdkEventType>, std::string> eventMap_{
{std::make_pair(1, GdkEventType::GDK_BUTTON_PRESS), "on-click"},
{std::make_pair(1, GdkEventType::GDK_BUTTON_RELEASE), "on-click-release"},
{std::make_pair(1, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click"},
{std::make_pair(1, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click"},
{std::make_pair(2, GdkEventType::GDK_BUTTON_PRESS), "on-click-middle"},
{std::make_pair(2, GdkEventType::GDK_BUTTON_RELEASE), "on-click-middle-release"},
{std::make_pair(2, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-middle"},
{std::make_pair(2, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-middle"},
{std::make_pair(3, GdkEventType::GDK_BUTTON_PRESS), "on-click-right"},
{std::make_pair(3, GdkEventType::GDK_BUTTON_RELEASE), "on-click-right-release"},
{std::make_pair(3, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-right"},
{std::make_pair(3, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-right"},
{std::make_pair(8, GdkEventType::GDK_BUTTON_PRESS), "on-click-backward"},
{std::make_pair(8, GdkEventType::GDK_BUTTON_RELEASE), "on-click-backward-release"},
{std::make_pair(8, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-backward"},
{std::make_pair(8, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-backward"},
{std::make_pair(9, GdkEventType::GDK_BUTTON_PRESS), "on-click-forward"},
{std::make_pair(9, GdkEventType::GDK_BUTTON_RELEASE), "on-click-forward-release"},
{std::make_pair(9, GdkEventType::GDK_2BUTTON_PRESS), "on-double-click-forward"},
{std::make_pair(9, GdkEventType::GDK_3BUTTON_PRESS), "on-triple-click-forward"}};
static const inline std::map<std::pair<std::pair<uint, int>, Gdk::Event::Type>, std::string>
eventMap_{
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click"},
{std::make_pair(std::make_pair(1u, 1), Gdk::Event::Type::BUTTON_RELEASE),
"on-click-release"},
{std::make_pair(std::make_pair(1u, 2), Gdk::Event::Type::BUTTON_PRESS),
"on-double-click"},
{std::make_pair(std::make_pair(1u, 3), Gdk::Event::Type::BUTTON_PRESS),
"on-triple-click"},
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_PRESS),
"on-click-middle"},
{std::make_pair(std::make_pair(2u, 1), Gdk::Event::Type::BUTTON_RELEASE),
"on-click-middle-release"},
{std::make_pair(std::make_pair(2u, 2), Gdk::Event::Type::BUTTON_PRESS),
"on-double-click-middle"},
{std::make_pair(std::make_pair(2u, 3), Gdk::Event::Type::BUTTON_PRESS),
"on-triple-click-middle"},
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_PRESS), "on-click-right"},
{std::make_pair(std::make_pair(3u, 1), Gdk::Event::Type::BUTTON_RELEASE),
"on-click-right-release"},
{std::make_pair(std::make_pair(3u, 2), Gdk::Event::Type::BUTTON_PRESS),
"on-double-click-right"},
{std::make_pair(std::make_pair(3u, 3), Gdk::Event::Type::BUTTON_PRESS),
"on-triple-click-right"},
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_PRESS),
"on-click-backward"},
{std::make_pair(std::make_pair(8u, 1), Gdk::Event::Type::BUTTON_RELEASE),
"on-click-backward-release"},
{std::make_pair(std::make_pair(8u, 2), Gdk::Event::Type::BUTTON_PRESS),
"on-double-click-backward"},
{std::make_pair(std::make_pair(8u, 3), Gdk::Event::Type::BUTTON_PRESS),
"on-triple-click-backward"},
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_PRESS),
"on-click-forward"},
{std::make_pair(std::make_pair(9u, 1), Gdk::Event::Type::BUTTON_RELEASE),
"on-click-forward-release"},
{std::make_pair(std::make_pair(9u, 2), Gdk::Event::Type::BUTTON_PRESS),
"on-double-click-forward"},
{std::make_pair(std::make_pair(9u, 3), Gdk::Event::Type::BUTTON_PRESS),
"on-triple-click-forward"}};
void handleClickEvent(uint n_button, int n_press, Gdk::Event::Type n_evtype);
void makeControllClick();
void makeControllScroll();
void makeControllMotion();
void removeControllClick();
void removeControllScroll();
void removeControllMotion();
};

} // namespace waybar
7 changes: 4 additions & 3 deletions include/ASlider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class ASlider : public AModule {
public:
ASlider(const Json::Value& config, const std::string& name, const std::string& id);
virtual void onValueChanged();
operator Gtk::Widget&() override;

protected:
bool vertical_ = false;
int min_ = 0, max_ = 100, curr_ = 50;
bool vertical_{false};
int min_{0}, max_{100}, curr_{50};
Gtk::Scale scale_;
};

} // namespace waybar
} // namespace waybar
25 changes: 10 additions & 15 deletions include/bar.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#pragma once

#include <gdkmm/monitor.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <gtkmm/centerbox.h>
#include <gtkmm/cssprovider.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <json/json.h>

#include <memory>
#include <optional>
#include <vector>

#include "AModule.hpp"
#include "group.hpp"
Expand Down Expand Up @@ -75,29 +69,30 @@ class Bar : public sigc::trackable {
struct wl_surface *surface;
bool visible = true;
Gtk::Window window;
Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL;
Gtk::PositionType position = Gtk::POS_TOP;

int x_global;
int y_global;
Gtk::Orientation orientation{Gtk::Orientation::HORIZONTAL};
Gtk::PositionType position{Gtk::PositionType::TOP};

#ifdef HAVE_SWAY
std::string bar_id;
#endif

private:
void onMap(GdkEventAny *);
void onMap();
auto setupWidgets() -> void;
void getModules(const Factory &, const std::string &, waybar::Group *);
void setupAltFormatKeyForModule(const std::string &module_name);
void setupAltFormatKeyForModuleList(const char *module_list_name);
void setMode(const bar_mode &);
void setPassThrough(bool passthrough);
void setPosition(Gtk::PositionType position);
void onConfigure(GdkEventConfigure *ev);
void onConfigure(int width, int height);
void configureGlobalOffset(int width, int height);
void onOutputGeometryChanged();

Glib::RefPtr<Gdk::Surface> gdk_surface_;
int x_global;
int y_global;

/* Copy initial set of modes to allow customization */
bar_mode_map configured_modes = PRESET_MODES;
std::string last_mode_{MODE_DEFAULT};
Expand All @@ -109,7 +104,7 @@ class Bar : public sigc::trackable {
Gtk::Box left_;
Gtk::Box center_;
Gtk::Box right_;
Gtk::Box box_;
Gtk::CenterBox box_;
std::vector<std::shared_ptr<waybar::AModule>> modules_left_;
std::vector<std::shared_ptr<waybar::AModule>> modules_center_;
std::vector<std::shared_ptr<waybar::AModule>> modules_right_;
Expand Down
7 changes: 2 additions & 5 deletions include/client.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include <fmt/format.h>
#include <gdk/gdk.h>
#include <gdk/gdkwayland.h>
#include <wayland-client.h>
#include <gdk/wayland/gdkwayland.h>

#include "bar.hpp"
#include "config.hpp"
Expand Down Expand Up @@ -33,6 +30,7 @@ class Client {

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

Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
std::unique_ptr<Portal> portal;
std::list<struct waybar_output> outputs_;
Expand Down
2 changes: 0 additions & 2 deletions include/factory.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <json/json.h>

#include <AModule.hpp>

namespace waybar {
Expand Down
30 changes: 14 additions & 16 deletions include/group.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
#pragma once

#include <gtkmm/box.h>
#include <gtkmm/widget.h>
#include <json/json.h>
#include <gtkmm/revealer.h>

#include "AModule.hpp"
#include "gtkmm/revealer.h"

namespace waybar {

class Group : public AModule {
class Group final : public AModule {
public:
Group(const std::string &, const std::string &, const Json::Value &, bool);
~Group() override = default;
auto update() -> void override;
operator Gtk::Widget &() override;

virtual Gtk::Box &getBox();
void addWidget(Gtk::Widget &widget);

protected:
Gtk::Box box;
Gtk::Box revealer_box;
Gtk::Revealer revealer;
bool is_first_widget = true;
bool is_drawer = false;
bool click_to_reveal = false;
std::string add_class_to_drawer_children;
bool handleMouseEnter(GdkEventCrossing *const &ev) override;
bool handleMouseLeave(GdkEventCrossing *const &ev) override;
bool handleToggle(GdkEventButton *const &ev) override;
private:
Gtk::Box box_;
Gtk::Box revealer_box_;
Gtk::Revealer revealer_;
bool is_first_widget_{true};
bool is_drawer_{false};
bool click_to_reveal_{false};
std::string add_class_to_drawer_children_;

void handleMouseEnter(double x, double y) override;
void handleMouseLeave() override;
void handleToggle(int n_press, double dx, double dy) override;
void show_group();
void hide_group();
};
Expand Down
Loading

0 comments on commit 048c3e2

Please sign in to comment.