Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk4 #3857

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Gtk4 #3857

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 14 additions & 10 deletions include/ALabel.hpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
#pragma once

#include <glibmm/markup.h>
#include <gtkmm/label.h>
#include <json/json.h>
#include <gtkmm/popovermenu.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_;
std::unique_ptr<Gtk::PopoverMenu> menu_;

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);
void handleClick(const std::string &name) override;

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

} // namespace waybar
121 changes: 78 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 @@ -30,55 +29,91 @@ 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();
// Allow subclass to hook into specific
virtual void handleClick(const std::string &name);
const SCROLL_DIR getScrollDir(Glib::RefPtr<const Gdk::Event> e);

private:
bool handleUserEvent(GdkEventButton *const &ev);
const bool isTooltip;
const bool isExpand;
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 handleRawClickEvent(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
27 changes: 12 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,28 +69,31 @@ 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();
// Set hexpend or vexpand to true, depending on orientation
void setExpand(Gtk::Widget &widget);

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;
Expand All @@ -109,7 +106,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
Loading