refactor notifications
This commit is contained in:
33
include/services/dbus/messages.hpp
Normal file
33
include/services/dbus/messages.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "glibmm/variant.h"
|
||||
|
||||
|
||||
|
||||
struct MprisPlayer2Message {
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string artwork_url;
|
||||
|
||||
std::function<void()> play_pause;
|
||||
std::function<void()> next;
|
||||
std::function<void()> previous;
|
||||
};
|
||||
|
||||
struct NotifyMessage {
|
||||
std::string app_name;
|
||||
uint32_t replaces_id;
|
||||
std::string app_icon;
|
||||
std::string summary;
|
||||
std::string body;
|
||||
std::vector<std::string> actions;
|
||||
std::map<std::string, Glib::VariantBase> hints;
|
||||
int32_t expire_timeout;
|
||||
// Callback to invoke when an action is triggered
|
||||
std::function<void(const std::string& action_id)> on_action;
|
||||
};
|
||||
@@ -1,20 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <giomm.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class MprisController {
|
||||
public:
|
||||
struct MprisPlayer2Message {
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string artwork_url;
|
||||
|
||||
std::function<void()> play_pause;
|
||||
std::function<void()> next;
|
||||
std::function<void()> previous;
|
||||
};
|
||||
|
||||
MprisController();
|
||||
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <giomm.h>
|
||||
#include <gtkmm.h>
|
||||
#include <memory>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <vector>
|
||||
|
||||
#include "gdkmm/monitor.h"
|
||||
#include "giomm/dbusconnection.h"
|
||||
#include "giomm/dbusownname.h"
|
||||
#include "glib.h"
|
||||
@@ -43,7 +40,6 @@ const Glib::ustring introspection_xml = R"(
|
||||
)";
|
||||
|
||||
class NotificationService {
|
||||
|
||||
public:
|
||||
NotificationService() : notificationIdCounter(1) {
|
||||
Gio::DBus::own_name(
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "services/dbus/mpris.hpp"
|
||||
#include "services/dbus/messages.hpp"
|
||||
|
||||
#include "gdkmm/monitor.h"
|
||||
#include "gtkmm/window.h"
|
||||
|
||||
class NotificationController {
|
||||
static std::shared_ptr<NotificationController> instance;
|
||||
|
||||
@@ -17,11 +17,10 @@ class NotificationController {
|
||||
return NotificationController::instance;
|
||||
}
|
||||
|
||||
void showSpotifyNotification(MprisController::MprisPlayer2Message mpris);
|
||||
void showNotificationOnAllMonitors(const std::string &title, const std::string &message);
|
||||
void showSpotifyNotification(MprisPlayer2Message mpris);
|
||||
void showNotificationOnAllMonitors(NotifyMessage notify);
|
||||
|
||||
private:
|
||||
NotificationController();
|
||||
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
||||
|
||||
void baseWindowSetup(std::shared_ptr<Gtk::Window> win, std::shared_ptr<Gdk::Monitor> monitor);
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <giomm.h>
|
||||
#include <gtkmm.h>
|
||||
#include <memory>
|
||||
#include "gdkmm/monitor.h"
|
||||
class NotificationWidget {
|
||||
public:
|
||||
NotificationWidget(std::shared_ptr<Gdk::Monitor> monitor, const Glib::ustring &title, const Glib::ustring &message);
|
||||
};
|
||||
24
include/widgets/notification/baseNotification.hpp
Normal file
24
include/widgets/notification/baseNotification.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "helpers/system.hpp"
|
||||
|
||||
#include "gdkmm/monitor.h"
|
||||
#include "gtk4-layer-shell.h"
|
||||
#include "gtkmm/cssprovider.h"
|
||||
#include "gtkmm/window.h"
|
||||
|
||||
|
||||
#define DEFAULT_NOTIFICATION_TIMEOUT 4000
|
||||
|
||||
class BaseNotification : public Gtk::Window {
|
||||
public:
|
||||
BaseNotification(std::shared_ptr<Gdk::Monitor> monitor);
|
||||
|
||||
virtual ~BaseNotification() = default;
|
||||
|
||||
private:
|
||||
void ensure_notification_css_loaded();
|
||||
};
|
||||
11
include/widgets/notification/notification.hpp
Normal file
11
include/widgets/notification/notification.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "services/dbus/messages.hpp"
|
||||
#include "widgets/notification/baseNotification.hpp"
|
||||
|
||||
class NotificationWindow : public BaseNotification {
|
||||
public:
|
||||
NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage message);
|
||||
virtual ~NotificationWindow() = default;
|
||||
};
|
||||
16
include/widgets/notification/spotifyNotification.hpp
Normal file
16
include/widgets/notification/spotifyNotification.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include "services/dbus/messages.hpp"
|
||||
#include "widgets/notification/baseNotification.hpp"
|
||||
#include "gtkmm/box.h"
|
||||
#include "gtkmm/centerbox.h"
|
||||
|
||||
class SpotifyNotification : public BaseNotification {
|
||||
public:
|
||||
SpotifyNotification(std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message message);
|
||||
virtual ~SpotifyNotification() = default;
|
||||
private:
|
||||
std::unique_ptr<Gtk::CenterBox> createButtonBox(MprisPlayer2Message mpris);
|
||||
};
|
||||
Reference in New Issue
Block a user