add move window to hyprland service

This commit is contained in:
2026-02-02 12:23:44 +01:00
parent 9404321249
commit da9f167747
12 changed files with 264 additions and 102 deletions

View File

@@ -0,0 +1,20 @@
#include "widgets/controlCenter/controlCenter.hpp"
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);
set_popover_child(this->container);
this->container.append(this->mediaControlWidget);
}

View File

@@ -1,37 +1,28 @@
#include "widgets/controlCenter.hpp"
#include "widgets/controlCenter/mediaControl.hpp"
#include "services/textureCache.hpp"
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.append(this->spotifyContainer);
MediaControlWidget::MediaControlWidget()
: Gtk::Box(Gtk::Orientation::VERTICAL) {
set_popover_child(this->container);
this->set_orientation(Gtk::Orientation::VERTICAL);
this->set_size_request(200, 240);
this->set_hexpand(false);
this->set_vexpand(false);
this->add_css_class("control-center-spotify-container");
this->spotifyContainer.set_orientation(Gtk::Orientation::VERTICAL);
this->spotifyContainer.set_size_request(200, 240);
this->spotifyContainer.set_hexpand(false); // Important: Don't let the main box expand freely
this->spotifyContainer.set_vexpand(false);
this->spotifyContainer.add_css_class("control-center-spotify-container");
this->spotifyContainer.append(this->topContainer);
this->spotifyContainer.append(this->seekBarContainer);
this->spotifyContainer.append(this->bottomContainer);
this->append(this->topContainer);
this->append(this->seekBarContainer);
this->append(this->bottomContainer);
this->backgroundImage.set_content_fit(Gtk::ContentFit::COVER);
this->backgroundImage.set_can_shrink(true);
this->imageWrapper.set_policy(Gtk::PolicyType::NEVER, Gtk::PolicyType::NEVER);
this->imageWrapper.set_child(this->backgroundImage);
this->topContainer.set_child(this->imageWrapper);
this->topContainer.set_child(this->imageWrapper);
this->topContainer.set_size_request(200, 100);
this->topContainer.set_vexpand(false);
this->topContainer.set_hexpand(true);
@@ -44,8 +35,7 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
this->topContainer.add_overlay(this->infoContainer);
this->artistLabel.set_halign(Gtk::Align::START);
this->titleLabel.set_halign(Gtk::Align::START);
this->titleLabel.set_halign(Gtk::Align::START);
this->seekBarContainer.set_orientation(Gtk::Orientation::HORIZONTAL);
this->seekBarContainer.set_vexpand(false);
@@ -68,6 +58,13 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
this->seekBar.set_halign(Gtk::Align::CENTER);
this->seekBar.add_css_class("control-center-seek-bar");
this->seekBar.signal_value_changed().connect([this]() {
double fraction = this->seekBar.get_value() / 100.0;
int64_t new_position_us =
static_cast<int64_t>(fraction * static_cast<double>(this->totalLengthUs));
this->mprisController->emit_seeked(new_position_us); // in ms
this->resetSeekTimer(new_position_us);
});
this->bottomContainer.set_orientation(Gtk::Orientation::HORIZONTAL);
this->bottomContainer.set_vexpand(false);
@@ -101,20 +98,70 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
});
this->mprisController->signal_mpris_updated().connect(
sigc::mem_fun(*this, &ControlCenter::onSpotifyMprisUpdated)
);
sigc::mem_fun(*this, &MediaControlWidget::onSpotifyMprisUpdated));
this->artistLabel.set_text("Artist Name");
this->artistLabel.add_css_class("control-center-spotify-artist-label");
this->titleLabel.set_text("Song Title");
this->titleLabel.add_css_class("control-center-spotify-title-label");
this->resetSeekTimer(0);
}
void ControlCenter::onSpotifyMprisUpdated(const MprisPlayer2Message &message) {
void MediaControlWidget::onSpotifyMprisUpdated(const MprisPlayer2Message &message) {
this->artistLabel.set_text(message.artist);
this->titleLabel.set_text(message.title);
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
this->backgroundImage.set_paintable(texture);
}
this->setTotalLength(message.length_ms);
this->setCurrentPosition(0);
this->resetSeekTimer(0);
}
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));
if (totalLengthUs > 0) {
double fraction = static_cast<double>(currentPositionUs) / static_cast<double>(totalLengthUs);
this->seekBar.set_value(fraction * 100);
}
}
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));
}
void MediaControlWidget::resetSeekTimer(int64_t start_position_us) {
if (seekTimerConnection.connected()) {
seekTimerConnection.disconnect();
}
setCurrentPosition(start_position_us);
seekTimerConnection = Glib::signal_timeout().connect(
sigc::mem_fun(*this, &MediaControlWidget::onSeekTick),
1000);
}
bool MediaControlWidget::onSeekTick() {
if (totalLengthUs <= 0) {
return true;
}
int64_t nextPosition = currentPositionUs + 1000000;
if (nextPosition > totalLengthUs) {
nextPosition = totalLengthUs;
}
setCurrentPosition(nextPosition);
return true;
}