nice control center
This commit is contained in:
@@ -5,16 +5,99 @@ ControlCenter::ControlCenter(std::string 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(0);
|
||||
this->container.set_margin_top(0);
|
||||
this->container.set_margin_bottom(0);
|
||||
this->container.set_margin_start(0);
|
||||
this->container.set_margin_end(0);
|
||||
this->container.set_spacing(10);
|
||||
this->popover->set_hexpand(false);
|
||||
this->popover->set_size_request(240, -1);
|
||||
|
||||
set_popover_child(this->container);
|
||||
|
||||
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->container.append(this->mediaControlWidget);
|
||||
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->tabRow.append(this->mediaControl);
|
||||
this->tabRow.append(this->testTabButton);
|
||||
|
||||
this->container.append(this->tabRow);
|
||||
|
||||
this->contentStack.set_hhomogeneous(false);
|
||||
this->contentStack.set_vhomogeneous(false);
|
||||
this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE);
|
||||
this->contentStack.set_transition_duration(150);
|
||||
|
||||
this->controlCenterContainer.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->controlCenterContainer.set_spacing(4);
|
||||
|
||||
this->testLabel.set_text("Test tab");
|
||||
|
||||
this->contentStack.add(this->controlCenterContainer, "controls", "Controls");
|
||||
this->contentStack.add(this->testLabel, "test", "Test");
|
||||
this->contentStack.set_visible_child("controls");
|
||||
this->setActiveTab("controls");
|
||||
|
||||
this->container.append(this->contentStack);
|
||||
|
||||
this->mediaControl.signal_clicked().connect([this]() {
|
||||
this->setActiveTab("controls");
|
||||
});
|
||||
|
||||
this->testTabButton.signal_clicked().connect([this]() {
|
||||
this->setActiveTab("test");
|
||||
});
|
||||
|
||||
this->mprisController->signal_player_registered().connect(
|
||||
[this](const std::string &bus_name) {
|
||||
this->addPlayerWidget(bus_name);
|
||||
});
|
||||
|
||||
this->mprisController->signal_player_deregistered().connect(
|
||||
[this](const std::string &bus_name) {
|
||||
this->removePlayerWidget(bus_name);
|
||||
});
|
||||
|
||||
for (const auto &bus_name : this->mprisController->get_registered_players()) {
|
||||
this->addPlayerWidget(bus_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");
|
||||
|
||||
if (tab_name == "controls") {
|
||||
this->mediaControl.add_css_class("active-button");
|
||||
} else if (tab_name == "test") {
|
||||
this->testTabButton.add_css_class("active-button");
|
||||
}
|
||||
}
|
||||
|
||||
void ControlCenter::addPlayerWidget(const std::string &bus_name) {
|
||||
if (this->mediaWidgets.find(bus_name) != this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto controller = MprisController::createForPlayer(bus_name);
|
||||
auto widget = Gtk::make_managed<MediaControlWidget>(controller);
|
||||
this->mediaWidgets.emplace(bus_name, widget);
|
||||
this->controlCenterContainer.append(*widget);
|
||||
}
|
||||
|
||||
void ControlCenter::removePlayerWidget(const std::string &bus_name) {
|
||||
auto it = this->mediaWidgets.find(bus_name);
|
||||
if (it == this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->controlCenterContainer.remove(*it->second);
|
||||
this->mediaWidgets.erase(it);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
#include "helpers/string.hpp"
|
||||
#include "services/textureCache.hpp"
|
||||
|
||||
MediaControlWidget::MediaControlWidget()
|
||||
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, 240);
|
||||
this->set_size_request(200, -1);
|
||||
this->set_hexpand(false);
|
||||
this->set_vexpand(false);
|
||||
this->add_css_class("control-center-spotify-container");
|
||||
this->add_css_class("control-center-player-container");
|
||||
|
||||
this->append(this->topContainer);
|
||||
this->append(this->seekBarContainer);
|
||||
@@ -24,7 +26,7 @@ MediaControlWidget::MediaControlWidget()
|
||||
|
||||
this->topContainer.set_child(this->imageWrapper);
|
||||
|
||||
this->topContainer.set_size_request(200, 100);
|
||||
this->topContainer.set_size_request(-1, 120);
|
||||
this->topContainer.set_vexpand(false);
|
||||
this->topContainer.set_hexpand(true);
|
||||
|
||||
@@ -45,6 +47,7 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->seekBarContainer.append(this->currentTimeLabel);
|
||||
this->seekBarContainer.append(this->seekBar);
|
||||
this->seekBarContainer.append(this->totalTimeLabel);
|
||||
this->seekBarContainer.set_visible(true);
|
||||
|
||||
this->currentTimeLabel.set_text("0:00");
|
||||
this->currentTimeLabel.set_halign(Gtk::Align::START);
|
||||
@@ -54,7 +57,6 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->seekBar.set_value(0);
|
||||
this->seekBar.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||
this->seekBar.set_draw_value(false);
|
||||
this->seekBar.set_size_request(120, -1);
|
||||
this->seekBar.set_hexpand(true);
|
||||
this->seekBar.set_halign(Gtk::Align::CENTER);
|
||||
this->seekBar.add_css_class("control-center-seek-bar");
|
||||
@@ -98,15 +100,14 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->bottomContainer.append(this->nextButton);
|
||||
|
||||
this->previousButton.set_label("\u23EE"); // Previous track symbol
|
||||
this->previousButton.add_css_class("notification-button");
|
||||
this->previousButton.add_css_class("notification-icon-button");
|
||||
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("notification-button");
|
||||
this->playPauseButton.add_css_class("notification-icon-button");
|
||||
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("notification-button");
|
||||
this->nextButton.add_css_class("notification-icon-button");
|
||||
|
||||
this->nextButton.add_css_class("button");
|
||||
this->nextButton.add_css_class("material-icons");
|
||||
this->previousButton.signal_clicked().connect([this]() {
|
||||
this->mprisController->previous_song();
|
||||
});
|
||||
@@ -130,14 +131,24 @@ MediaControlWidget::MediaControlWidget()
|
||||
this->setCurrentPosition(position_us);
|
||||
});
|
||||
|
||||
this->mprisController->signal_can_seek_changed().connect(
|
||||
[this](bool can_seek) {
|
||||
this->setCanSeek(can_seek);
|
||||
});
|
||||
|
||||
this->artistLabel.set_text("Artist Name");
|
||||
this->artistLabel.add_css_class("control-center-spotify-artist-label");
|
||||
this->artistLabel.add_css_class("control-center-player-artist-label");
|
||||
this->titleLabel.set_text("Song Title");
|
||||
this->titleLabel.add_css_class("control-center-spotify-title-label");
|
||||
this->titleLabel.add_css_class("control-center-player-title-label");
|
||||
|
||||
this->resetSeekTimer(0);
|
||||
}
|
||||
|
||||
void MediaControlWidget::setCanSeek(bool can_seek) {
|
||||
this->canSeek = can_seek;
|
||||
this->seekBarContainer.set_visible(can_seek);
|
||||
}
|
||||
|
||||
void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &message) {
|
||||
std::string artistText = "Unknown Artist";
|
||||
if (!message.artist.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user