nice spotify notification
This commit is contained in:
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic -Werror")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic")
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ target_sources(bar_lib
|
|||||||
src/services/textureCache.cpp
|
src/services/textureCache.cpp
|
||||||
src/services/tray.cpp
|
src/services/tray.cpp
|
||||||
src/services/dbus/notification.cpp
|
src/services/dbus/notification.cpp
|
||||||
|
src/services/dbus/mpris.cpp
|
||||||
|
|
||||||
src/widgets/tray.cpp
|
src/widgets/tray.cpp
|
||||||
src/widgets/controlCenter.cpp
|
src/widgets/controlCenter.cpp
|
||||||
|
|||||||
@@ -37,4 +37,11 @@ public:
|
|||||||
tokens.push_back(input.substr(start));
|
tokens.push_back(input.substr(start));
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string trimToSize(const std::string &input, size_t maxSize) {
|
||||||
|
if (input.length() <= maxSize) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
return input.substr(0, maxSize) + "...";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -1,136 +1,35 @@
|
|||||||
#include <gtkmm.h>
|
#pragma once
|
||||||
|
|
||||||
#include <giomm.h>
|
#include <giomm.h>
|
||||||
#include <iostream>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "services/notificationController.hpp"
|
|
||||||
#include "giomm/dbusconnection.h"
|
|
||||||
#include "giomm/dbusproxy.h"
|
|
||||||
|
|
||||||
class MprisController {
|
class MprisController {
|
||||||
public:
|
public:
|
||||||
MprisController() {
|
struct MprisPlayer2Message {
|
||||||
// 1. Connect to the Session Bus
|
std::string title;
|
||||||
Gio::DBus::Connection::get(
|
std::string artist;
|
||||||
Gio::DBus::BusType::SESSION,
|
std::string artwork_url;
|
||||||
sigc::mem_fun(*this, &MprisController::on_bus_connected)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
std::function<void()> play_pause;
|
||||||
|
std::function<void()> next;
|
||||||
|
std::function<void()> previous;
|
||||||
|
};
|
||||||
|
|
||||||
|
MprisController();
|
||||||
|
|
||||||
|
void toggle_play();
|
||||||
|
void next_song();
|
||||||
|
void previous_song();
|
||||||
|
|
||||||
|
private:
|
||||||
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
||||||
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
||||||
|
|
||||||
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult>& result) {
|
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
|
||||||
if (!result) {
|
void launchNotification();
|
||||||
std::cerr << "DBus Connection Error: null async result" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
m_connection = Gio::DBus::Connection::get_finish(result);
|
|
||||||
|
|
||||||
// 2. Create a Proxy to the media player
|
|
||||||
// NOTE: In a real app, you must find the name dynamically (see Step 2 below).
|
|
||||||
// For now, ensure a player like Spotify or VLC is running.
|
|
||||||
// Try "org.mpris.MediaPlayer2.spotify" or "org.mpris.MediaPlayer2.vlc"
|
|
||||||
std::string player_bus_name = "org.mpris.MediaPlayer2.spotify";
|
|
||||||
|
|
||||||
m_proxy = Gio::DBus::Proxy::create_sync(
|
|
||||||
m_connection,
|
|
||||||
player_bus_name, // The Bus Name
|
|
||||||
"/org/mpris/MediaPlayer2", // The Object Path
|
|
||||||
"org.mpris.MediaPlayer2.Player" // The Interface
|
|
||||||
);
|
|
||||||
|
|
||||||
if (m_proxy) {
|
|
||||||
std::cout << "Connected to: " << player_bus_name << std::endl;
|
|
||||||
|
|
||||||
// Get initial state
|
|
||||||
print_metadata();
|
|
||||||
|
|
||||||
// 3. Listen for changes (Song change, Pause/Play)
|
|
||||||
m_proxy->signal_properties_changed().connect(
|
|
||||||
sigc::mem_fun(*this, &MprisController::on_properties_changed)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (const Glib::Error& ex) {
|
|
||||||
std::cerr << "DBus Connection Error: " << ex.what() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_metadata() {
|
|
||||||
// Retrieve the cached property "Metadata"
|
|
||||||
Glib::VariantBase metadata_var;
|
|
||||||
m_proxy->get_cached_property(metadata_var, "Metadata");
|
|
||||||
|
|
||||||
if (!metadata_var) {
|
|
||||||
std::cout << "No metadata available." << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Unpack Metadata (Type: a{sv})
|
|
||||||
// This is a dictionary of string -> variant
|
|
||||||
using MetadataMap = std::map<Glib::ustring, Glib::VariantBase>;
|
|
||||||
MetadataMap metadata_map;
|
|
||||||
|
|
||||||
// Cast the variant to a container and iterate
|
|
||||||
Glib::Variant<MetadataMap> variant_dict =
|
|
||||||
Glib::VariantBase::cast_dynamic<Glib::Variant<MetadataMap>>(metadata_var);
|
|
||||||
|
|
||||||
metadata_map = variant_dict.get();
|
|
||||||
|
|
||||||
std::string title, artist, artwork_url;
|
|
||||||
|
|
||||||
if (metadata_map.count("xesam:title")) {
|
|
||||||
auto title_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["xesam:title"]);
|
|
||||||
title = title_var.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (metadata_map.count("xesam:artist")) {
|
|
||||||
auto artist_var = metadata_map["xesam:artist"];
|
|
||||||
|
|
||||||
if (artist_var.is_of_type(Glib::VariantType("as"))) {
|
|
||||||
auto artists = Glib::VariantBase::cast_dynamic<Glib::Variant<std::vector<Glib::ustring>>>(artist_var).get();
|
|
||||||
if (!artists.empty()) {
|
|
||||||
artist = artists[0]; // Take the first artist
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (metadata_map.count("mpris:artUrl")) {
|
|
||||||
auto art_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["mpris:artUrl"]);
|
|
||||||
artwork_url = art_var.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto notifactionController = NotificationController::getInstance();
|
|
||||||
notifactionController->showSpotifyNotification(title, artist, artwork_url);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the song changes
|
// Called when the song changes
|
||||||
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties& changed_properties,
|
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
||||||
const std::vector<Glib::ustring>& invalidated_properties) {
|
const std::vector<Glib::ustring> &invalidated_properties);
|
||||||
(void)invalidated_properties;
|
|
||||||
|
|
||||||
// Only refresh when Metadata is updated
|
|
||||||
if (changed_properties.find("Metadata") != changed_properties.end()) {
|
|
||||||
// You could parse 'changed_properties' directly, but it's easier to just pull the new cache
|
|
||||||
print_metadata();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Call this to toggle play/pause
|
|
||||||
void toggle_play() {
|
|
||||||
if(m_proxy) {
|
|
||||||
m_proxy->call("PlayPause");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call this to skip
|
|
||||||
void next_song() {
|
|
||||||
if(m_proxy) {
|
|
||||||
m_proxy->call("Next");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "services/dbus/mpris.hpp"
|
||||||
|
|
||||||
#include "gdkmm/monitor.h"
|
#include "gdkmm/monitor.h"
|
||||||
|
#include "gtkmm/window.h"
|
||||||
class NotificationController {
|
class NotificationController {
|
||||||
static std::shared_ptr<NotificationController> instance;
|
static std::shared_ptr<NotificationController> instance;
|
||||||
|
|
||||||
@@ -15,9 +17,11 @@ class NotificationController {
|
|||||||
return NotificationController::instance;
|
return NotificationController::instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSpotifyNotification(const std::string &title, const std::string &message, const std::string &artwork_url);
|
void showSpotifyNotification(MprisController::MprisPlayer2Message mpris);
|
||||||
void showNotificationOnAllMonitors(const std::string &title, const std::string &message);
|
void showNotificationOnAllMonitors(const std::string &title, const std::string &message);
|
||||||
private:
|
private:
|
||||||
NotificationController();
|
NotificationController();
|
||||||
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
||||||
|
|
||||||
|
void baseWindowSetup(std::shared_ptr<Gtk::Window> win, std::shared_ptr<Gdk::Monitor> monitor);
|
||||||
};
|
};
|
||||||
@@ -58,6 +58,13 @@ button {
|
|||||||
background-color: #111111;
|
background-color: #111111;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flat-button {
|
||||||
|
background-color: #333333;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.workspace-pill {
|
.workspace-pill {
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
margin-right: 6px;
|
margin-right: 6px;
|
||||||
@@ -151,3 +158,6 @@ button {
|
|||||||
border: 1px solid rgba(80, 80, 80, 0.8);
|
border: 1px solid rgba(80, 80, 80, 0.8);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification-button-box {
|
||||||
|
}
|
||||||
|
|||||||
132
src/services/dbus/mpris.cpp
Normal file
132
src/services/dbus/mpris.cpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#include "services/dbus/mpris.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
#include "services/notificationController.hpp"
|
||||||
|
|
||||||
|
#include "giomm/dbusconnection.h"
|
||||||
|
#include "giomm/dbusproxy.h"
|
||||||
|
|
||||||
|
MprisController::MprisController() {
|
||||||
|
// 1. Connect to the Session Bus
|
||||||
|
Gio::DBus::Connection::get(
|
||||||
|
Gio::DBus::BusType::SESSION,
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_bus_connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
if (!result) {
|
||||||
|
std::cerr << "DBus Connection Error: null async result" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
m_connection = Gio::DBus::Connection::get_finish(result);
|
||||||
|
|
||||||
|
std::string player_bus_name = "org.mpris.MediaPlayer2.spotify";
|
||||||
|
|
||||||
|
m_proxy = Gio::DBus::Proxy::create_sync(
|
||||||
|
m_connection,
|
||||||
|
player_bus_name, // The Bus Name
|
||||||
|
"/org/mpris/MediaPlayer2", // The Object Path
|
||||||
|
"org.mpris.MediaPlayer2.Player" // The Interface
|
||||||
|
);
|
||||||
|
|
||||||
|
if (m_proxy) {
|
||||||
|
std::cout << "Connected to: " << player_bus_name << std::endl;
|
||||||
|
|
||||||
|
// uncomment if launch notification on start
|
||||||
|
launchNotification();
|
||||||
|
|
||||||
|
m_proxy->signal_properties_changed().connect(
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_properties_changed));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
std::cerr << "DBus Connection Error: " << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::launchNotification() {
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::VariantBase metadata_var;
|
||||||
|
m_proxy->get_cached_property(metadata_var, "Metadata");
|
||||||
|
|
||||||
|
if (!metadata_var) {
|
||||||
|
std::cout << "No metadata available." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using MetadataMap = std::map<Glib::ustring, Glib::VariantBase>;
|
||||||
|
MetadataMap metadata_map;
|
||||||
|
|
||||||
|
Glib::Variant<MetadataMap> variant_dict =
|
||||||
|
Glib::VariantBase::cast_dynamic<Glib::Variant<MetadataMap>>(metadata_var);
|
||||||
|
|
||||||
|
metadata_map = variant_dict.get();
|
||||||
|
|
||||||
|
std::string title, artist, artwork_url;
|
||||||
|
|
||||||
|
if (metadata_map.count("xesam:title")) {
|
||||||
|
auto title_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["xesam:title"]);
|
||||||
|
title = title_var.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata_map.count("xesam:artist")) {
|
||||||
|
auto artist_var = metadata_map["xesam:artist"];
|
||||||
|
|
||||||
|
if (artist_var.is_of_type(Glib::VariantType("as"))) {
|
||||||
|
auto artists = Glib::VariantBase::cast_dynamic<Glib::Variant<std::vector<Glib::ustring>>>(artist_var).get();
|
||||||
|
if (!artists.empty()) {
|
||||||
|
artist = artists[0]; // Take the first artist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata_map.count("mpris:artUrl")) {
|
||||||
|
auto art_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(metadata_map["mpris:artUrl"]);
|
||||||
|
artwork_url = art_var.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto notifactionController = NotificationController::getInstance();
|
||||||
|
|
||||||
|
MprisController::MprisPlayer2Message mpris;
|
||||||
|
mpris.title = StringHelper::trimToSize(title, 30);
|
||||||
|
mpris.artist = StringHelper::trimToSize(artist, 30);
|
||||||
|
mpris.artwork_url = artwork_url;
|
||||||
|
mpris.play_pause = [this]() { this->toggle_play(); };
|
||||||
|
mpris.next = [this]() { this->next_song(); };
|
||||||
|
mpris.previous = [this]() { this->previous_song(); };
|
||||||
|
notifactionController->showSpotifyNotification(mpris);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
||||||
|
const std::vector<Glib::ustring> &) {
|
||||||
|
|
||||||
|
if (changed_properties.find("Metadata") != changed_properties.end()) {
|
||||||
|
launchNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::previous_song() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("Previous");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MprisController::toggle_play() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("PlayPause");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::next_song() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("Next");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,19 +2,27 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "services/dbus/mpris.hpp"
|
||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
#include "gdkmm/display.h"
|
#include "gdkmm/display.h"
|
||||||
#include "giomm/listmodel.h"
|
#include "giomm/listmodel.h"
|
||||||
#include "glibmm/main.h"
|
#include "glibmm/main.h"
|
||||||
#include "gtk4-layer-shell.h"
|
#include "gtk4-layer-shell.h"
|
||||||
#include "gtkmm/box.h"
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/centerbox.h"
|
||||||
#include "gtkmm/image.h"
|
#include "gtkmm/image.h"
|
||||||
#include "gtkmm/label.h"
|
#include "gtkmm/label.h"
|
||||||
#include "gtkmm/window.h"
|
#include "gtkmm/window.h"
|
||||||
#include "services/textureCache.hpp"
|
|
||||||
|
|
||||||
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
|
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
|
||||||
|
|
||||||
NotificationController::NotificationController() {
|
NotificationController::NotificationController() {
|
||||||
|
if (NotificationController::instance) {
|
||||||
|
throw std::runtime_error("use getInstance()!");
|
||||||
|
}
|
||||||
|
|
||||||
auto display = Gdk::Display::get_default();
|
auto display = Gdk::Display::get_default();
|
||||||
if (!display) {
|
if (!display) {
|
||||||
return;
|
return;
|
||||||
@@ -33,82 +41,110 @@ NotificationController::NotificationController() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationController::showSpotifyNotification(const std::string &title, const std::string &message, const std::string &artwork_url) {
|
void NotificationController::showSpotifyNotification(MprisController::MprisPlayer2Message mpris) {
|
||||||
for (const auto &monitor : this->activeMonitors) {
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
|
|
||||||
auto win = new Gtk::Window();
|
auto win = std::make_shared<Gtk::Window>();
|
||||||
win->set_title(title);
|
win->set_title(mpris.title);
|
||||||
win->set_default_size(300, 100);
|
this->baseWindowSetup(win, monitor);
|
||||||
|
|
||||||
gtk_layer_init_for_window(win->gobj());
|
|
||||||
gtk_layer_set_monitor(win->gobj(), monitor->gobj());
|
|
||||||
gtk_layer_set_layer(win->gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
|
||||||
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
|
|
||||||
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
|
|
||||||
gtk_layer_set_margin(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
|
||||||
|
|
||||||
win->add_css_class("notification-popup");
|
|
||||||
|
|
||||||
auto container = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
|
auto container = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
|
||||||
|
|
||||||
if (auto texture = TextureCacheService::getInstance()->getTexture(artwork_url)) {
|
if (auto texture = TextureCacheService::getInstance()->getTexture(mpris.artwork_url)) {
|
||||||
auto img = Gtk::make_managed<Gtk::Image>(texture);
|
auto img = Gtk::make_managed<Gtk::Image>(texture);
|
||||||
// make it larger
|
|
||||||
img->set_pixel_size(64);
|
img->set_pixel_size(64);
|
||||||
container->append(*img);
|
container->append(*img);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto text_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 5);
|
auto rightArea = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 5);
|
||||||
text_box->set_halign(Gtk::Align::CENTER);
|
rightArea->set_halign(Gtk::Align::CENTER);
|
||||||
text_box->set_valign(Gtk::Align::CENTER);
|
rightArea->set_valign(Gtk::Align::CENTER);
|
||||||
|
// make sure rigfht area takes the remaining space
|
||||||
|
rightArea->set_hexpand(true);
|
||||||
|
// also set a max width
|
||||||
|
|
||||||
auto title_label = Gtk::make_managed<Gtk::Label>("<b>" + title + "</b>");
|
auto title_label = Gtk::make_managed<Gtk::Label>("<b>" + mpris.title + "</b>");
|
||||||
title_label->set_use_markup(true);
|
title_label->set_use_markup(true);
|
||||||
title_label->set_halign(Gtk::Align::START);
|
title_label->set_halign(Gtk::Align::START);
|
||||||
text_box->append(*title_label);
|
rightArea->append(*title_label);
|
||||||
|
|
||||||
|
auto artistLabel = Gtk::make_managed<Gtk::Label>(mpris.artist);
|
||||||
|
artistLabel->set_halign(Gtk::Align::CENTER);
|
||||||
|
rightArea->append(*artistLabel);
|
||||||
|
|
||||||
auto message_label = Gtk::make_managed<Gtk::Label>(message);
|
auto buttonBox = Gtk::make_managed<Gtk::CenterBox>();
|
||||||
message_label->set_halign(Gtk::Align::START);
|
buttonBox->add_css_class("notification-button-box");
|
||||||
text_box->append(*message_label);
|
buttonBox->set_hexpand(true);
|
||||||
|
|
||||||
container->append(*text_box);
|
auto backButton = Gtk::make_managed<Gtk::Button>("<");
|
||||||
|
backButton->add_css_class("flat-button");
|
||||||
|
auto playPauseButton = Gtk::make_managed<Gtk::Button>("=<");
|
||||||
|
playPauseButton->add_css_class("flat-button");
|
||||||
|
auto nextButton = Gtk::make_managed<Gtk::Button>(">");
|
||||||
|
nextButton->add_css_class("flat-button");
|
||||||
|
|
||||||
|
backButton->signal_clicked().connect([mpris]() {
|
||||||
|
if (mpris.previous) {
|
||||||
|
mpris.previous();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
playPauseButton->signal_clicked().connect([mpris]() {
|
||||||
|
if (mpris.play_pause) {
|
||||||
|
mpris.play_pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
nextButton->signal_clicked().connect([mpris]() {
|
||||||
|
if (mpris.next) {
|
||||||
|
mpris.next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonBox->set_start_widget(*backButton);
|
||||||
|
buttonBox->set_center_widget(*playPauseButton);
|
||||||
|
buttonBox->set_end_widget(*nextButton);
|
||||||
|
|
||||||
|
// rightArea->append(*buttonBox);
|
||||||
|
|
||||||
|
container->append(*rightArea);
|
||||||
|
|
||||||
win->set_child(*container);
|
win->set_child(*container);
|
||||||
win->show();
|
win->show();
|
||||||
|
|
||||||
// Auto close after 3 seconds for demo purposes
|
|
||||||
Glib::signal_timeout().connect([win]() {
|
Glib::signal_timeout().connect([win]() {
|
||||||
win->close();
|
win->close();
|
||||||
delete win;
|
|
||||||
return false; // Don't repeat
|
return false; // Don't repeat
|
||||||
},
|
},
|
||||||
3000);
|
3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationController::showNotificationOnAllMonitors(const std::string &title, const std::string &message) {
|
void NotificationController::baseWindowSetup(std::shared_ptr<Gtk::Window> win, std::shared_ptr<Gdk::Monitor> monitor) {
|
||||||
for (const auto &monitor : this->activeMonitors) {
|
|
||||||
auto win = new Gtk::Window();
|
|
||||||
win->set_title(title);
|
|
||||||
win->set_default_size(300, 100);
|
win->set_default_size(300, 100);
|
||||||
|
|
||||||
gtk_layer_init_for_window(win->gobj());
|
gtk_layer_init_for_window(win->gobj());
|
||||||
gtk_layer_set_monitor(win->gobj(), monitor->gobj());
|
gtk_layer_set_monitor(win->gobj(), monitor->gobj());
|
||||||
gtk_layer_set_layer(win->gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
gtk_layer_set_layer(win->gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
||||||
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
|
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
|
||||||
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
|
gtk_layer_set_anchor(win->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
|
||||||
gtk_layer_set_margin(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
gtk_layer_set_margin(win->gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
||||||
|
|
||||||
win->add_css_class("notification-popup");
|
win->add_css_class("notification-popup");
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationController::showNotificationOnAllMonitors(const std::string &title, const std::string &message) {
|
||||||
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
|
auto win = std::make_shared<Gtk::Window>();
|
||||||
|
win->set_title(title);
|
||||||
|
|
||||||
|
this->baseWindowSetup(win, monitor);
|
||||||
|
|
||||||
auto label = Gtk::make_managed<Gtk::Label>(message);
|
auto label = Gtk::make_managed<Gtk::Label>(message);
|
||||||
label->set_use_markup(true);
|
label->set_use_markup(true);
|
||||||
win->set_child(*label);
|
win->set_child(*label);
|
||||||
|
|
||||||
win->show();
|
win->show();
|
||||||
|
|
||||||
Glib::signal_timeout().connect([win]() {
|
Glib::signal_timeout().connect([win]() {
|
||||||
win->close();
|
win->close();
|
||||||
delete win;
|
|
||||||
return false; // Don't repeat
|
return false; // Don't repeat
|
||||||
},
|
},
|
||||||
3000);
|
3000);
|
||||||
|
|||||||
Reference in New Issue
Block a user