From 64b3babd3da45b6901f86e94cccbdf74d7f794c4 Mon Sep 17 00:00:00 2001 From: Arif Hasanic Date: Thu, 5 Feb 2026 14:33:19 +0100 Subject: [PATCH] some refactore --- CMakeLists.txt | 6 +- include/bar/bar.hpp | 5 +- include/components/base/button.hpp | 18 ----- include/components/button/iconButton.hpp | 12 ++++ include/components/button/tabButton.hpp | 9 +++ include/components/button/textButton.hpp | 13 ++++ include/components/popover.hpp | 7 +- include/components/types/icon.hpp | 48 ++++++++++++++ .../widgets/controlCenter/controlCenter.hpp | 13 ++-- .../widgets/controlCenter/mediaControl.hpp | 7 +- include/widgets/tray.hpp | 6 +- include/widgets/webWidget.hpp | 3 +- resources/bar.css | 35 ++++------ src/bar/bar.cpp | 1 + src/components/base/button.cpp | 14 ---- src/components/button/iconButton.cpp | 10 +++ src/components/button/tabButton.cpp | 13 ++++ src/components/button/textButton.cpp | 9 +++ src/components/popover.cpp | 3 +- src/widgets/controlCenter/controlCenter.cpp | 42 +++++++----- src/widgets/controlCenter/mediaControl.cpp | 65 +++++++++++-------- src/widgets/notification/baseNotification.cpp | 1 - src/widgets/notification/copyNotification.cpp | 14 ++-- .../notification/notificationWindow.cpp | 6 +- .../notification/spotifyNotification.cpp | 11 ++-- src/widgets/tray.cpp | 6 +- src/widgets/webWidget.cpp | 3 +- 27 files changed, 239 insertions(+), 141 deletions(-) delete mode 100644 include/components/base/button.hpp create mode 100644 include/components/button/iconButton.hpp create mode 100644 include/components/button/tabButton.hpp create mode 100644 include/components/button/textButton.hpp create mode 100644 include/components/types/icon.hpp delete mode 100644 src/components/base/button.cpp create mode 100644 src/components/button/iconButton.cpp create mode 100644 src/components/button/tabButton.cpp create mode 100644 src/components/button/textButton.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ad2bd2d..046c5dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,13 @@ add_library(bar_lib) target_sources(bar_lib PUBLIC src/app.cpp + src/bar/bar.cpp + src/components/button/iconButton.cpp + src/components/button/textButton.cpp + src/components/button/tabButton.cpp + src/connection/httpConnection.cpp src/connection/dbus/notification.cpp src/connection/dbus/mpris.cpp @@ -63,7 +68,6 @@ target_sources(bar_lib src/components/popover.cpp src/components/workspaceIndicator.cpp - src/components/base/button.cpp ) include_directories(bar_lib PRIVATE include diff --git a/include/bar/bar.hpp b/include/bar/bar.hpp index 5c410fd..e8efee6 100644 --- a/include/bar/bar.hpp +++ b/include/bar/bar.hpp @@ -4,6 +4,7 @@ #include #include +#include "components/button/iconButton.hpp" #include "widgets/clock.hpp" #include "widgets/date.hpp" #include "widgets/tray.hpp" @@ -27,8 +28,8 @@ class Bar : public Gtk::Window { Clock clock; Date date; - WebWidget homeAssistant{"\uf024", "Home Assistant", "https://home.rivercry.com"}; - ControlCenter controlCenter{"\ue062", "Control Center"}; + WebWidget homeAssistant{Icon::HOME_ASSISTANT, "Home Assistant", "https://home.rivercry.com"}; + ControlCenter controlCenter{Icon::CONTROL_CENTER, "Control Center"}; std::shared_ptr trayWidget = nullptr; std::shared_ptr volumeWidget = nullptr; diff --git a/include/components/base/button.hpp b/include/components/base/button.hpp deleted file mode 100644 index c5d7efc..0000000 --- a/include/components/base/button.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include "gtkmm/image.h" -#include "sigc++/signal.h" - -class Button : public Gtk::Button { - public: - Button(const std::string label); - Button(Gtk::Image &image); - - sigc::signal onClickedSignal; - - private: - void on_clicked() { - onClickedSignal.emit(); - } -}; \ No newline at end of file diff --git a/include/components/button/iconButton.hpp b/include/components/button/iconButton.hpp new file mode 100644 index 0000000..99e52f1 --- /dev/null +++ b/include/components/button/iconButton.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +#include "components/button/textButton.hpp" +#include "components/types/icon.hpp" + +class IconButton : public TextButton { + public: + IconButton(Icon::Type icon, std::string fontFamilyCss = "materia-icons"); + void setIcon(Icon::Type icon); +}; \ No newline at end of file diff --git a/include/components/button/tabButton.hpp b/include/components/button/tabButton.hpp new file mode 100644 index 0000000..4187dd0 --- /dev/null +++ b/include/components/button/tabButton.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "components/button/iconButton.hpp" + +class TabButton : public IconButton { + public: + TabButton(Icon::Type icon); + void setActive(bool active); +}; \ No newline at end of file diff --git a/include/components/button/textButton.hpp b/include/components/button/textButton.hpp new file mode 100644 index 0000000..a40b868 --- /dev/null +++ b/include/components/button/textButton.hpp @@ -0,0 +1,13 @@ +#pragma once + + + +#include + +#include "gtkmm/button.h" + +class TextButton : public Gtk::Button { + public: + TextButton(const std::string &label); + void setText(const std::string &text); +}; \ No newline at end of file diff --git a/include/components/popover.hpp b/include/components/popover.hpp index 5ed2769..c75e6bf 100644 --- a/include/components/popover.hpp +++ b/include/components/popover.hpp @@ -3,11 +3,12 @@ #include #include #include -#include "components/base/button.hpp" +#include "components/button/iconButton.hpp" +#include "components/button/textButton.hpp" -class Popover : public Button { +class Popover : public IconButton { public: - Popover(const std::string icon, std::string name); + Popover(Icon::Type icon, std::string name); ~Popover() override; protected: diff --git a/include/components/types/icon.hpp b/include/components/types/icon.hpp new file mode 100644 index 0000000..815b893 --- /dev/null +++ b/include/components/types/icon.hpp @@ -0,0 +1,48 @@ + +#include +#include +#include + +class Icon { + + public: + enum Type { + + HOME_ASSISTANT, + CONTROL_CENTER, + + SKIP_PREVIOUS, + SKIP_NEXT, + PLAY_ARROW, + PAUSE, + + PLAY_CIRCLE, + + EMPTY_DASHBOARD, + + SAVE, + CONTENT_COPY, + }; + + static const std::string toString(Type type) { + return typeToString[type]; + } + + private: + static inline std::map typeToString = { + {HOME_ASSISTANT, "\uf024"}, + {CONTROL_CENTER, "\ue062"}, + + {SKIP_PREVIOUS, "\ue045"}, + {SKIP_NEXT, "\ue044"}, + {PLAY_ARROW, "\ue037"}, + {PAUSE, "\ue034"}, + + {PLAY_CIRCLE, "\ue1c4"}, + + {EMPTY_DASHBOARD, "\uf844"}, + + {SAVE, "\ue161"}, + {CONTENT_COPY, "\ue14d"}, + }; +}; \ No newline at end of file diff --git a/include/widgets/controlCenter/controlCenter.hpp b/include/widgets/controlCenter/controlCenter.hpp index 063d130..7b6e384 100644 --- a/include/widgets/controlCenter/controlCenter.hpp +++ b/include/widgets/controlCenter/controlCenter.hpp @@ -1,27 +1,30 @@ #pragma once +#include "components/button/iconButton.hpp" +#include "components/button/tabButton.hpp" #include "components/popover.hpp" #include "gtkmm/box.h" -#include "gtkmm/button.h" -#include "gtkmm/label.h" +#include "gtkmm/scrolledwindow.h" #include "gtkmm/stack.h" #include "widgets/controlCenter/mediaControl.hpp" #include "widgets/weather.hpp" +#include #include class ControlCenter : public Popover { public: - ControlCenter(std::string icon, std::string name); + ControlCenter(Icon::Type icon, std::string name); private: + Gtk::ScrolledWindow scrollview; Gtk::Box container; Gtk::Box tabRow; Gtk::Stack contentStack; Gtk::Box controlCenterContainer; WeatherWidget weatherWidget; - Gtk::Button mediaControl; - Gtk::Button testTabButton; + std::unique_ptr mediaControl; + std::unique_ptr testTabButton; std::shared_ptr mprisController = MprisController::getInstance(); std::unordered_map mediaWidgets; diff --git a/include/widgets/controlCenter/mediaControl.hpp b/include/widgets/controlCenter/mediaControl.hpp index 2b01c89..391e960 100644 --- a/include/widgets/controlCenter/mediaControl.hpp +++ b/include/widgets/controlCenter/mediaControl.hpp @@ -7,6 +7,7 @@ #include "gtkmm/scale.h" #include "gtkmm/scrolledwindow.h" +#include "components/button/iconButton.hpp" #include "connection/dbus/mpris.hpp" class MediaControlWidget : public Gtk::Box { @@ -48,9 +49,9 @@ class MediaControlWidget : public Gtk::Box { // playback controls Gtk::Box bottomContainer; - Gtk::Button previousButton; - Gtk::Button playPauseButton; - Gtk::Button nextButton; + std::unique_ptr previousButton; + std::unique_ptr playPauseButton; + std::unique_ptr nextButton; Gtk::ScrolledWindow imageWrapper; diff --git a/include/widgets/tray.hpp b/include/widgets/tray.hpp index 3ae2327..ebccd97 100644 --- a/include/widgets/tray.hpp +++ b/include/widgets/tray.hpp @@ -17,12 +17,12 @@ #include #include +#include "components/button/iconButton.hpp" #include "connection/dbus/tray.hpp" -#include "components/base/button.hpp" -class TrayIconWidget : public Button { +class TrayIconWidget : public IconButton { public: - TrayIconWidget(std::string id); + TrayIconWidget(Icon::Type icon, std::string id); ~TrayIconWidget() override; void update(const TrayService::Item &item); diff --git a/include/widgets/webWidget.hpp b/include/widgets/webWidget.hpp index f368520..f6c6798 100644 --- a/include/widgets/webWidget.hpp +++ b/include/widgets/webWidget.hpp @@ -3,9 +3,10 @@ #include #include +#include "components/button/iconButton.hpp" #include "components/popover.hpp" class WebWidget : public Popover { public: - WebWidget(std::string icon, std::string title, std::string url); + WebWidget(Icon::Type icon, std::string title, std::string url); }; diff --git a/resources/bar.css b/resources/bar.css index 75bf709..9998ea0 100644 --- a/resources/bar.css +++ b/resources/bar.css @@ -23,11 +23,13 @@ window { .material-icons { font-family: var(--icon-font-material); - font-size: 18px; +} + +.icon-button { + font-size: 16px; } .tab-icon { - font-family: var(--icon-font-material); font-size: 20px; margin-right: 6px; border-radius: 4px; @@ -35,13 +37,7 @@ window { padding: 2px 4px; } -.tab-icon:hover { - background-color: rgba(255, 255, 255, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); -} - .control-center-tab-row { - /* mordern and sleek */ background-color: rgba(50, 50, 50, 0.8); border-radius: 8px; padding: 2px 4px; @@ -58,7 +54,6 @@ window { popover { margin-top: 4px; font-family: var(--text-font); - /* padding: 6px; TODO: create better padding*/ border-radius: 8px; background: rgba(25, 25, 25, 0.8); @@ -105,8 +100,6 @@ popover { } .control-center-seek-bar { - min-height: 6px; - min-width: 120px; margin: 0 6px; border-bottom: 1px solid var(--color-border); } @@ -139,8 +132,14 @@ tooltip { } button { - font-size: 20px; - padding: 3px 6px; + font-size: 14px; + padding: 4px 8px; + border-radius: 4px; + color: #ffffff; + transition: + background-color 0.2s, + color 0.2s, + border-color 0.2s; } #spacer { @@ -151,14 +150,8 @@ button { } .button:hover { - background-color: #111111; -} - -.flat-button { - background-color: #333333; - color: #ffffff; - padding: 2px 4px; - border-radius: 10px; + background-color: rgba(255, 255, 255, 0.1); + box-shadow: none; } .workspace-pill { diff --git a/src/bar/bar.cpp b/src/bar/bar.cpp index a4027b0..b5748fc 100644 --- a/src/bar/bar.cpp +++ b/src/bar/bar.cpp @@ -5,6 +5,7 @@ #include #include +#include "components/button/textButton.hpp" #include "helpers/system.hpp" #include "widgets/date.hpp" #include "widgets/spacer.hpp" diff --git a/src/components/base/button.cpp b/src/components/base/button.cpp deleted file mode 100644 index a16f834..0000000 --- a/src/components/base/button.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "components/base/button.hpp" - -#include "sigc++/functors/mem_fun.h" - -Button::Button(const std::string label) : Gtk::Button(label) { - signal_clicked().connect(sigc::mem_fun(*this, &Button::on_clicked)); - this->add_css_class("button"); -} - -Button::Button(Gtk::Image &image) : Gtk::Button() { - set_child(image); - signal_clicked().connect(sigc::mem_fun(*this, &Button::on_clicked)); - this->add_css_class("button"); -} \ No newline at end of file diff --git a/src/components/button/iconButton.cpp b/src/components/button/iconButton.cpp new file mode 100644 index 0000000..0b7ac5b --- /dev/null +++ b/src/components/button/iconButton.cpp @@ -0,0 +1,10 @@ +#include "components/button/iconButton.hpp" + +IconButton::IconButton(Icon::Type icon, std::string fontFamilyCss) : TextButton(Icon::toString(icon)) { + this->get_style_context()->add_class(fontFamilyCss); + this->add_css_class("icon-button"); +} + +void IconButton::setIcon(Icon::Type icon) { + this->set_label(Icon::toString(icon)); +} \ No newline at end of file diff --git a/src/components/button/tabButton.cpp b/src/components/button/tabButton.cpp new file mode 100644 index 0000000..b4af55f --- /dev/null +++ b/src/components/button/tabButton.cpp @@ -0,0 +1,13 @@ +#include "components/button/tabButton.hpp" + +TabButton::TabButton(Icon::Type icon) : IconButton(icon) { + add_css_class("tab-icon"); +} + +void TabButton::setActive(bool active) { + if (active) { + this->add_css_class("active-button"); + } else { + this->remove_css_class("active-button"); + } +} \ No newline at end of file diff --git a/src/components/button/textButton.cpp b/src/components/button/textButton.cpp new file mode 100644 index 0000000..a63e6d9 --- /dev/null +++ b/src/components/button/textButton.cpp @@ -0,0 +1,9 @@ +#include "components/button/textButton.hpp" + +TextButton::TextButton(const std::string &label) : Gtk::Button(label) { + add_css_class("button"); +} + +void TextButton::setText(const std::string &text) { + this->set_label(text); +} \ No newline at end of file diff --git a/src/components/popover.cpp b/src/components/popover.cpp index f21ae3a..dffcdd7 100644 --- a/src/components/popover.cpp +++ b/src/components/popover.cpp @@ -1,6 +1,7 @@ #include "components/popover.hpp" +#include "components/button/iconButton.hpp" -Popover::Popover(const std::string icon, std::string name): Button(icon) { +Popover::Popover(Icon::Type icon, std::string name): IconButton(icon) { signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window)); set_name(name); diff --git a/src/widgets/controlCenter/controlCenter.cpp b/src/widgets/controlCenter/controlCenter.cpp index 31f0f26..646fa2d 100644 --- a/src/widgets/controlCenter/controlCenter.cpp +++ b/src/widgets/controlCenter/controlCenter.cpp @@ -1,32 +1,40 @@ #include "widgets/controlCenter/controlCenter.hpp" +#include "components/button/iconButton.hpp" +#include "components/button/tabButton.hpp" -ControlCenter::ControlCenter(std::string icon, std::string name) +ControlCenter::ControlCenter(Icon::Type icon, std::string name) : Popover(icon, name) { this->popover->add_css_class("control-center-popover"); this->container.set_orientation(Gtk::Orientation::VERTICAL); this->container.set_spacing(10); - this->popover->set_hexpand(false); - this->popover->set_size_request(240, -1); + + this->scrollview.set_child(this->container); + this->scrollview.set_min_content_width(220); + this->scrollview.set_max_content_width(220); + this->scrollview.set_size_request(220, -1); + this->scrollview.set_policy( + Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC); + this->scrollview.set_hexpand(false); + this->scrollview.set_vexpand(true); + this->scrollview.set_propagate_natural_height(true); - set_popover_child(this->container); + set_popover_child(this->scrollview); this->tabRow.set_orientation(Gtk::Orientation::HORIZONTAL); this->tabRow.set_spacing(4); this->tabRow.set_margin_bottom(4); this->tabRow.add_css_class("control-center-tab-row"); - this->mediaControl.set_label("\uf5d3"); // control icon - this->mediaControl.add_css_class("tab-icon"); - this->testTabButton.set_label("\uE5CA"); // test icon - this->testTabButton.add_css_class("tab-icon"); + this->mediaControl = std::make_unique(Icon::PLAY_CIRCLE); + this->testTabButton = std::make_unique(Icon::EMPTY_DASHBOARD); - this->tabRow.append(this->mediaControl); - this->tabRow.append(this->testTabButton); + this->tabRow.append(*this->mediaControl); + this->tabRow.append(*this->testTabButton); this->container.append(this->tabRow); - this->contentStack.set_hhomogeneous(false); + this->contentStack.set_hhomogeneous(true); this->contentStack.set_vhomogeneous(false); this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE); this->contentStack.set_transition_duration(150); @@ -41,11 +49,11 @@ ControlCenter::ControlCenter(std::string icon, std::string name) this->container.append(this->contentStack); - this->mediaControl.signal_clicked().connect([this]() { + this->mediaControl->signal_clicked().connect([this]() { this->setActiveTab("controls"); }); - this->testTabButton.signal_clicked().connect([this]() { + this->testTabButton->signal_clicked().connect([this]() { this->setActiveTab("test"); }); @@ -68,13 +76,13 @@ ControlCenter::ControlCenter(std::string icon, std::string name) void ControlCenter::setActiveTab(const std::string &tab_name) { this->contentStack.set_visible_child(tab_name); - this->mediaControl.remove_css_class("active-button"); - this->testTabButton.remove_css_class("active-button"); + this->mediaControl->setActive(false); + this->testTabButton->setActive(false); if (tab_name == "controls") { - this->mediaControl.add_css_class("active-button"); + this->mediaControl->setActive(true); } else if (tab_name == "test") { - this->testTabButton.add_css_class("active-button"); + this->testTabButton->setActive(true); } } diff --git a/src/widgets/controlCenter/mediaControl.cpp b/src/widgets/controlCenter/mediaControl.cpp index 5c2dd2f..6b54442 100644 --- a/src/widgets/controlCenter/mediaControl.cpp +++ b/src/widgets/controlCenter/mediaControl.cpp @@ -1,15 +1,34 @@ #include "widgets/controlCenter/mediaControl.hpp" +#include "components/button/iconButton.hpp" #include "helpers/string.hpp" #include "services/textureCache.hpp" +namespace { +std::string formatTimeUs(int64_t time_us) { + if (time_us < 0) { + time_us = 0; + } + int64_t totalSeconds = time_us / 1000000; + int64_t hours = totalSeconds / 3600; + int64_t minutes = (totalSeconds / 60) % 60; + int64_t seconds = totalSeconds % 60; + + if (hours > 0) { + return std::to_string(hours) + ":" + + (minutes < 10 ? "0" : "") + std::to_string(minutes) + ":" + + (seconds < 10 ? "0" : "") + std::to_string(seconds); + } + return std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds); +} +} // namespace + MediaControlWidget::MediaControlWidget(std::shared_ptr controller) : Gtk::Box(Gtk::Orientation::VERTICAL) { this->mprisController = std::move(controller); this->set_orientation(Gtk::Orientation::VERTICAL); - this->set_size_request(200, -1); this->set_hexpand(false); this->set_vexpand(false); this->add_css_class("control-center-player-container"); @@ -88,6 +107,10 @@ MediaControlWidget::MediaControlWidget(std::shared_ptr controll } }); + this->previousButton = std::make_unique(Icon::SKIP_PREVIOUS); + this->playPauseButton = std::make_unique(Icon::PLAY_ARROW); + this->nextButton = std::make_unique(Icon::SKIP_NEXT); + this->bottomContainer.set_orientation(Gtk::Orientation::HORIZONTAL); this->bottomContainer.set_vexpand(false); this->bottomContainer.set_hexpand(false); @@ -95,26 +118,17 @@ MediaControlWidget::MediaControlWidget(std::shared_ptr controll this->bottomContainer.set_homogeneous(true); this->topContainer.set_vexpand(false); this->topContainer.set_hexpand(true); - this->bottomContainer.append(this->previousButton); - this->bottomContainer.append(this->playPauseButton); - this->bottomContainer.append(this->nextButton); + this->bottomContainer.append(*this->previousButton); + this->bottomContainer.append(*this->playPauseButton); + this->bottomContainer.append(*this->nextButton); - this->previousButton.set_label("\u23EE"); // Previous track symbol - this->previousButton.add_css_class("button"); - this->previousButton.add_css_class("material-icons"); - this->playPauseButton.set_label("\u23EF"); // Play/Pause symbol - this->playPauseButton.add_css_class("button"); - this->playPauseButton.add_css_class("material-icons"); - this->nextButton.set_label("\u23ED"); // Next track symbol - this->nextButton.add_css_class("button"); - this->nextButton.add_css_class("material-icons"); - this->previousButton.signal_clicked().connect([this]() { + this->previousButton->signal_clicked().connect([this]() { this->mprisController->previous_song(); }); - this->playPauseButton.signal_clicked().connect([this]() { + this->playPauseButton->signal_clicked().connect([this]() { this->mprisController->toggle_play(); }); - this->nextButton.signal_clicked().connect([this]() { + this->nextButton->signal_clicked().connect([this]() { this->mprisController->next_song(); }); @@ -179,10 +193,7 @@ void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &messag void MediaControlWidget::setCurrentPosition(int64_t position_us) { this->currentPositionUs = position_us; - int64_t seconds = (position_us / 1000000) % 60; - int64_t minutes = (position_us / (1000000 * 60)) % 60; - this->currentTimeLabel.set_text( - std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds)); + this->currentTimeLabel.set_text(formatTimeUs(position_us)); if (totalLengthUs > 0) { double fraction = static_cast(currentPositionUs) / static_cast(totalLengthUs); this->suppressSeekSignal = true; @@ -193,10 +204,7 @@ void MediaControlWidget::setCurrentPosition(int64_t position_us) { void MediaControlWidget::setTotalLength(int64_t length_us) { this->totalLengthUs = length_us; - int64_t seconds = (length_us / 1000000) % 60; - int64_t minutes = (length_us / (1000000 * 60)) % 60; - this->totalTimeLabel.set_text( - std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds)); + this->totalTimeLabel.set_text(formatTimeUs(length_us)); } void MediaControlWidget::resetSeekTimer(int64_t start_position_us) { @@ -248,20 +256,21 @@ void MediaControlWidget::onRunningStateChanged(MprisController::PlaybackStatus s } void MediaControlWidget::onPlay() { - this->playPauseButton.set_label("\u23F8"); // Pause symbol - // strart seek timer if not already running + this->playPauseButton->setIcon(Icon::PAUSE); this->resetSeekTimer(currentPositionUs); } void MediaControlWidget::onPause() { - this->playPauseButton.set_label("\u23F5"); // Play symbol + this->playPauseButton->setIcon(Icon::PLAY_ARROW); + if (seekTimerConnection.connected()) { seekTimerConnection.disconnect(); } } void MediaControlWidget::onStop() { - this->playPauseButton.set_label("\u23F9"); // stop symbol + this->playPauseButton->setIcon(Icon::PLAY_ARROW); + if (seekTimerConnection.connected()) { seekTimerConnection.disconnect(); } diff --git a/src/widgets/notification/baseNotification.cpp b/src/widgets/notification/baseNotification.cpp index 4b772c5..3cd129c 100644 --- a/src/widgets/notification/baseNotification.cpp +++ b/src/widgets/notification/baseNotification.cpp @@ -8,7 +8,6 @@ #include "gdkmm/monitor.h" #include "glibmm/main.h" -#include "glibmm/object.h" #include "gtk4-layer-shell.h" #include "gtkmm/button.h" #include "gtkmm/cssprovider.h" diff --git a/src/widgets/notification/copyNotification.cpp b/src/widgets/notification/copyNotification.cpp index 452dcc1..8b14a4b 100644 --- a/src/widgets/notification/copyNotification.cpp +++ b/src/widgets/notification/copyNotification.cpp @@ -2,6 +2,7 @@ #include #include +#include "components/button/iconButton.hpp" #include "glibmm/datetime.h" #include "glibmm/fileutils.h" @@ -85,12 +86,8 @@ void CopyNotification::createImageNotification(NotifyMessage notify) { auto buttonBox = Gtk::make_managed(); buttonBox->set_spacing(10); - // material icons unicode - auto saveToClipboardLabel = Gtk::make_managed("\uF0EA"); // content copy icon - auto saveToFileLabel = Gtk::make_managed("\uF1C5"); // save icon - auto saveToClipboardButton = Gtk::make_managed(); - saveToClipboardButton->set_child(*saveToClipboardLabel); + auto saveToClipboardButton = Gtk::make_managed(Icon::CONTENT_COPY); saveToClipboardButton->signal_clicked().connect([this]() { copyToClipboard(this->copiedImage); spdlog::info("Copied image to clipboard"); @@ -101,8 +98,7 @@ void CopyNotification::createImageNotification(NotifyMessage notify) { saveToClipboardButton->add_css_class("notification-button"); saveToClipboardButton->add_css_class("notification-icon-button"); - auto saveToFileButton = Gtk::make_managed(); - saveToFileButton->set_child(*saveToFileLabel); + auto saveToFileButton = Gtk::make_managed(Icon::SAVE); saveToFileButton->signal_clicked().connect([this]() { // xdg-pic/screenshot // use env auto xdgPicturesDir = Glib::get_user_special_dir(Glib::UserDirectory::PICTURES); @@ -136,9 +132,7 @@ void CopyNotification::createTextNotification(NotifyMessage notify) { textLabel->set_margin_bottom(10); contentBox->append(*textLabel); - auto copyToClipboardButton = Gtk::make_managed(); - auto copyToClipboardLabel = Gtk::make_managed("\uF0EA"); // content copy icon - copyToClipboardButton->set_child(*copyToClipboardLabel); + auto copyToClipboardButton = Gtk::make_managed(Icon::CONTENT_COPY); copyToClipboardButton->signal_clicked().connect([this]() { copyToClipboard(this->copiedText); this->signal_close.emit(this->notificationId); diff --git a/src/widgets/notification/notificationWindow.cpp b/src/widgets/notification/notificationWindow.cpp index 99e8c08..c8ebacc 100644 --- a/src/widgets/notification/notificationWindow.cpp +++ b/src/widgets/notification/notificationWindow.cpp @@ -1,11 +1,12 @@ #include "widgets/notification/notificationWindow.hpp" #include #include +#include "components/button/iconButton.hpp" +#include "components/button/textButton.hpp" #include "helpers/string.hpp" #include "gtkmm/box.h" #include "gtkmm/button.h" -#include "gtkmm/gestureclick.h" #include "gtkmm/image.h" #include "gtkmm/label.h" @@ -71,8 +72,7 @@ NotificationWindow::NotificationWindow(uint64_t notificationId, std::shared_ptr< std::string action_id = notify.actions[i]; std::string action_label = notify.actions[i + 1]; - auto btn = Gtk::make_managed(); - btn->set_label(action_label); + auto btn = Gtk::make_managed(action_label); btn->add_css_class("notification-button"); diff --git a/src/widgets/notification/spotifyNotification.cpp b/src/widgets/notification/spotifyNotification.cpp index 9bd4de7..2751073 100644 --- a/src/widgets/notification/spotifyNotification.cpp +++ b/src/widgets/notification/spotifyNotification.cpp @@ -1,6 +1,7 @@ #include "widgets/notification/spotifyNotification.hpp" #include +#include "components/button/iconButton.hpp" #include "helpers/string.hpp" #include "services/textureCache.hpp" @@ -58,7 +59,7 @@ std::unique_ptr SpotifyNotification::createButtonBox(MprisPlayer buttonBox->set_hexpand(true); buttonBox->set_halign(Gtk::Align::CENTER); - auto backButton = Gtk::make_managed("\ue045"); + auto backButton = Gtk::make_managed(Icon::SKIP_PREVIOUS); backButton->add_css_class("notification-icon-button"); backButton->add_css_class("notification-button"); backButton->signal_clicked().connect([this, mpris]() { @@ -68,7 +69,7 @@ std::unique_ptr SpotifyNotification::createButtonBox(MprisPlayer } }); - auto playPauseButton = Gtk::make_managed("\ue037"); + auto playPauseButton = Gtk::make_managed(Icon::PLAY_ARROW); playPauseButton->add_css_class("notification-icon-button"); playPauseButton->add_css_class("notification-button"); playPauseButton->signal_clicked().connect([playPauseButton, mpris]() { @@ -77,15 +78,15 @@ std::unique_ptr SpotifyNotification::createButtonBox(MprisPlayer static bool isPlaying = false; if (isPlaying) { - playPauseButton->set_label("\ue037"); + playPauseButton->setIcon(Icon::PLAY_ARROW); } else { - playPauseButton->set_label("\ue034"); + playPauseButton->setIcon(Icon::PAUSE); } isPlaying = !isPlaying; } }); - auto nextButton = Gtk::make_managed("\ue044"); + auto nextButton = Gtk::make_managed(Icon::SKIP_NEXT); nextButton->add_css_class("notification-icon-button"); nextButton->add_css_class("notification-button"); nextButton->signal_clicked().connect([this, mpris]() { diff --git a/src/widgets/tray.cpp b/src/widgets/tray.cpp index eb45df5..9a49780 100644 --- a/src/widgets/tray.cpp +++ b/src/widgets/tray.cpp @@ -7,7 +7,6 @@ #include #include #include -#include "components/base/button.hpp" namespace { bool is_wayland_display(GtkWidget *widget) { @@ -182,8 +181,7 @@ void log_menu_tree(const std::vector &nodes, } } // namespace -TrayIconWidget::TrayIconWidget( std::string id) - : Button(id), id(std::move(id)), +TrayIconWidget::TrayIconWidget(Icon::Type icon, std::string id) : IconButton(icon), id(std::move(id)), container(Gtk::Orientation::HORIZONTAL) { aliveFlag = std::make_shared(true); set_has_frame(false); @@ -592,7 +590,7 @@ void TrayWidget::on_item_added(const TrayService::Item &item) { return; } - auto icon = std::make_unique(item.id); + auto icon = std::make_unique(Icon::Type::CONTENT_COPY, item.id); icon->update(item); auto *raw = icon.get(); append(*raw); diff --git a/src/widgets/webWidget.cpp b/src/widgets/webWidget.cpp index d2ab3b3..c160921 100644 --- a/src/widgets/webWidget.cpp +++ b/src/widgets/webWidget.cpp @@ -2,8 +2,9 @@ #include #include +#include "components/button/iconButton.hpp" -WebWidget::WebWidget(std::string icon, std::string name, std::string url) : Popover(icon, name) { +WebWidget::WebWidget(Icon::Type icon, std::string name, std::string url) : Popover(icon, name) { auto webview = webkit_web_view_new(); gtk_widget_set_hexpand(webview, true); gtk_widget_set_vexpand(webview, true);