some refactore
This commit is contained in:
@@ -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<TabButton>(Icon::PLAY_CIRCLE);
|
||||
this->testTabButton = std::make_unique<TabButton>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MprisController> 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<MprisController> controll
|
||||
}
|
||||
});
|
||||
|
||||
this->previousButton = std::make_unique<IconButton>(Icon::SKIP_PREVIOUS);
|
||||
this->playPauseButton = std::make_unique<IconButton>(Icon::PLAY_ARROW);
|
||||
this->nextButton = std::make_unique<IconButton>(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<MprisController> 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<double>(currentPositionUs) / static_cast<double>(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();
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <spdlog/spdlog.h>
|
||||
#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<Gtk::Box>();
|
||||
buttonBox->set_spacing(10);
|
||||
|
||||
// material icons unicode
|
||||
auto saveToClipboardLabel = Gtk::make_managed<Gtk::Label>("\uF0EA"); // content copy icon
|
||||
auto saveToFileLabel = Gtk::make_managed<Gtk::Label>("\uF1C5"); // save icon
|
||||
|
||||
auto saveToClipboardButton = Gtk::make_managed<Gtk::Button>();
|
||||
saveToClipboardButton->set_child(*saveToClipboardLabel);
|
||||
auto saveToClipboardButton = Gtk::make_managed<IconButton>(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<Gtk::Button>();
|
||||
saveToFileButton->set_child(*saveToFileLabel);
|
||||
auto saveToFileButton = Gtk::make_managed<IconButton>(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<Gtk::Button>();
|
||||
auto copyToClipboardLabel = Gtk::make_managed<Gtk::Label>("\uF0EA"); // content copy icon
|
||||
copyToClipboardButton->set_child(*copyToClipboardLabel);
|
||||
auto copyToClipboardButton = Gtk::make_managed<IconButton>(Icon::CONTENT_COPY);
|
||||
copyToClipboardButton->signal_clicked().connect([this]() {
|
||||
copyToClipboard(this->copiedText);
|
||||
this->signal_close.emit(this->notificationId);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "widgets/notification/notificationWindow.hpp"
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
#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<Gtk::Button>();
|
||||
btn->set_label(action_label);
|
||||
auto btn = Gtk::make_managed<TextButton>(action_label);
|
||||
|
||||
btn->add_css_class("notification-button");
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "widgets/notification/spotifyNotification.hpp"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "components/button/iconButton.hpp"
|
||||
#include "helpers/string.hpp"
|
||||
#include "services/textureCache.hpp"
|
||||
|
||||
@@ -58,7 +59,7 @@ std::unique_ptr<Gtk::CenterBox> SpotifyNotification::createButtonBox(MprisPlayer
|
||||
buttonBox->set_hexpand(true);
|
||||
buttonBox->set_halign(Gtk::Align::CENTER);
|
||||
|
||||
auto backButton = Gtk::make_managed<Gtk::Button>("\ue045");
|
||||
auto backButton = Gtk::make_managed<IconButton>(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<Gtk::CenterBox> SpotifyNotification::createButtonBox(MprisPlayer
|
||||
}
|
||||
});
|
||||
|
||||
auto playPauseButton = Gtk::make_managed<Gtk::Button>("\ue037");
|
||||
auto playPauseButton = Gtk::make_managed<IconButton>(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<Gtk::CenterBox> 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<Gtk::Button>("\ue044");
|
||||
auto nextButton = Gtk::make_managed<IconButton>(Icon::SKIP_NEXT);
|
||||
nextButton->add_css_class("notification-icon-button");
|
||||
nextButton->add_css_class("notification-button");
|
||||
nextButton->signal_clicked().connect([this, mpris]() {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <graphene.h>
|
||||
#include <utility>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "components/base/button.hpp"
|
||||
|
||||
namespace {
|
||||
bool is_wayland_display(GtkWidget *widget) {
|
||||
@@ -182,8 +181,7 @@ void log_menu_tree(const std::vector<TrayService::MenuNode> &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<bool>(true);
|
||||
set_has_frame(false);
|
||||
@@ -592,7 +590,7 @@ void TrayWidget::on_item_added(const TrayService::Item &item) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto icon = std::make_unique<TrayIconWidget>(item.id);
|
||||
auto icon = std::make_unique<TrayIconWidget>(Icon::Type::CONTENT_COPY, item.id);
|
||||
icon->update(item);
|
||||
auto *raw = icon.get();
|
||||
append(*raw);
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
#include <webkit/webkit.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user