refacor media widget, apply clang format rule

This commit is contained in:
2026-02-07 14:14:50 +01:00
parent 64b3babd3d
commit d9ac353a0d
54 changed files with 642 additions and 878 deletions

View File

@@ -3,9 +3,9 @@
#include <vector>
#include "bar/bar.hpp"
#include "services/hyprland.hpp"
#include "connection/dbus/notification.hpp"
#include "connection/dbus/tray.hpp"
#include "services/hyprland.hpp"
#include "glibmm/refptr.h"
#include "gtkmm/application.h"
@@ -22,8 +22,8 @@ class App {
Glib::RefPtr<Gtk::Application> app;
std::vector<std::shared_ptr<Bar>> bars;
std::shared_ptr<NotificationService> notificationService = nullptr;
std::shared_ptr<MprisController> mprisController = nullptr;
HyprlandService *hyprlandService = nullptr;
std::shared_ptr<MprisController> mprisController = nullptr;
HyprlandService *hyprlandService = nullptr;
TrayService *trayService = TrayService::getInstance();
void setupServices();

View File

@@ -6,11 +6,11 @@
#include "components/button/iconButton.hpp"
#include "widgets/clock.hpp"
#include "widgets/controlCenter/controlCenter.hpp"
#include "widgets/date.hpp"
#include "widgets/tray.hpp"
#include "widgets/volumeWidget.hpp"
#include "widgets/webWidget.hpp"
#include "widgets/controlCenter/controlCenter.hpp"
class Bar : public Gtk::Window {
public:
@@ -29,11 +29,10 @@ class Bar : public Gtk::Window {
Clock clock;
Date date;
WebWidget homeAssistant{Icon::HOME_ASSISTANT, "Home Assistant", "https://home.rivercry.com"};
ControlCenter controlCenter{Icon::CONTROL_CENTER, "Control Center"};
std::shared_ptr<TrayWidget> trayWidget = nullptr;
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
ControlCenter controlCenter{Icon::MENU, "Control Center"};
std::shared_ptr<TrayWidget> trayWidget = nullptr;
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
void setup_ui();
void setup_left_box();

View File

@@ -6,7 +6,7 @@
#include "components/types/icon.hpp"
class IconButton : public TextButton {
public:
IconButton(Icon::Type icon, std::string fontFamilyCss = "materia-icons");
void setIcon(Icon::Type icon);
public:
IconButton(Icon::Type icon, std::string fontFamilyCss = "materia-icons");
void setIcon(Icon::Type icon);
};

View File

@@ -3,7 +3,7 @@
#include "components/button/iconButton.hpp"
class TabButton : public IconButton {
public:
TabButton(Icon::Type icon);
void setActive(bool active);
public:
TabButton(Icon::Type icon);
void setActive(bool active);
};

View File

@@ -1,7 +1,5 @@
#pragma once
#include <string>
#include "gtkmm/button.h"

View File

@@ -1,18 +1,17 @@
#pragma once
#include "components/button/iconButton.hpp"
#include "connection/dbus/mpris.hpp"
#include "gtkmm/box.h"
#include "gtkmm/button.h"
#include "gtkmm/label.h"
#include "gtkmm/overlay.h"
#include "gtkmm/picture.h"
#include "gtkmm/scale.h"
#include "gtkmm/scrolledwindow.h"
#include "components/button/iconButton.hpp"
#include "connection/dbus/mpris.hpp"
class MediaControlWidget : public Gtk::Box {
public:
explicit MediaControlWidget(std::shared_ptr<MprisController> controller);
class MediaPlayer : public Gtk::Box {
public:
explicit MediaPlayer(std::shared_ptr<MprisController> controller);
private:
std::shared_ptr<MprisController> mprisController;
@@ -23,7 +22,7 @@ class MediaControlWidget : public Gtk::Box {
bool suppressSeekSignal = false;
std::string currentTrackId;
MprisController::PlaybackStatus playbackStatus = MprisController::PlaybackStatus::Stopped;
bool canSeek = true;
bool canSeek = true;
void setCurrentPosition(int64_t position_us);
void setTotalLength(int64_t length_us);
@@ -32,8 +31,6 @@ class MediaControlWidget : public Gtk::Box {
void schedulePauseAfterSeek();
void setCanSeek(bool can_seek);
Gtk::Box spotifyContainer;
// image as background, artist, title
Gtk::Overlay topContainer;
Gtk::Picture backgroundImage;

View File

@@ -3,6 +3,7 @@
#include <gtkmm/button.h>
#include <gtkmm/popover.h>
#include <string>
#include "components/button/iconButton.hpp"
#include "components/button/textButton.hpp"

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -4,12 +4,10 @@
#include <string>
class Icon {
public:
public:
enum Type {
HOME_ASSISTANT,
CONTROL_CENTER,
MENU,
SKIP_PREVIOUS,
SKIP_NEXT,
@@ -22,6 +20,8 @@ class Icon {
SAVE,
CONTENT_COPY,
TOKEN,
};
static const std::string toString(Type type) {
@@ -31,7 +31,7 @@ class Icon {
private:
static inline std::map<Type, const std::string> typeToString = {
{HOME_ASSISTANT, "\uf024"},
{CONTROL_CENTER, "\ue062"},
{MENU, "\ue5d2"},
{SKIP_PREVIOUS, "\ue045"},
{SKIP_NEXT, "\ue044"},
@@ -44,5 +44,7 @@ class Icon {
{SAVE, "\ue161"},
{CONTENT_COPY, "\ue14d"},
{TOKEN, "\uea25"},
};
};

View File

@@ -8,7 +8,6 @@
class WorkspaceIndicator : public Gtk::Box {
public:
enum InidicatorState {
EMPTY,
ALIVE,

View File

@@ -5,20 +5,20 @@
class DbusConnection {
public:
virtual ~DbusConnection() = default;
virtual ~DbusConnection() = default;
protected:
Glib::RefPtr<Gio::DBus::Connection> connection;
Glib::RefPtr<Gio::DBus::Connection> connection;
void connect_session_async(const sigc::slot<void(const Glib::RefPtr<Gio::AsyncResult> &)> &callback) {
Gio::DBus::Connection::get(Gio::DBus::BusType::SESSION, callback);
}
void connect_session_async(const sigc::slot<void(const Glib::RefPtr<Gio::AsyncResult> &)> &callback) {
Gio::DBus::Connection::get(Gio::DBus::BusType::SESSION, callback);
}
static void ensure_gio_init() {
try {
Gio::init();
} catch (const Glib::Error &) {
// Already initialized.
}
}
static void ensure_gio_init() {
try {
Gio::init();
} catch (const Glib::Error &) {
// Already initialized.
}
}
};

View File

@@ -7,6 +7,7 @@
#include <string>
#include <sys/types.h>
#include <vector>
#include "gdkmm/pixbuf.h"
#include "glibmm/variant.h"
@@ -23,8 +24,8 @@ struct MprisPlayer2Message {
};
enum NotificationUrgency {
LOW = 0,
NORMAL = 1,
LOW = 0,
NORMAL = 1,
CRITICAL = 2
};
@@ -38,7 +39,7 @@ struct NotifyMessage {
NotificationUrgency urgency = NORMAL;
int32_t expire_timeout;
// Callback to invoke when an action is triggered
std::function<void(const std::string& action_id)> on_action;
std::function<void(const std::string &action_id)> on_action;
// Guard to prevent multiple action invocations across mirrors
std::shared_ptr<bool> actionInvoked;
// image data (if any) from dbus

View File

@@ -2,9 +2,10 @@
#include <cstdint>
#include <giomm.h>
#include <sigc++/sigc++.h>
#include <set>
#include <sigc++/sigc++.h>
#include <vector>
#include "connection/dbus/dbus.hpp"
#include "connection/dbus/messages.hpp"
@@ -56,7 +57,7 @@ class MprisController : public DbusConnection {
Glib::RefPtr<Gio::DBus::Proxy> m_dbus_proxy;
std::string m_player_bus_name = "org.mpris.MediaPlayer2.spotify";
std::set<std::string> registeredPlayers;
sigc::signal<void(const MprisPlayer2Message &)> mprisUpdatedSignal;
sigc::signal<void(PlaybackStatus)> playbackStatusChangedSignal;
sigc::signal<void(int64_t)> playbackPositionChangedSignal;
@@ -70,8 +71,8 @@ class MprisController : public DbusConnection {
void emit_cached_position();
void emit_cached_can_seek();
void on_dbus_signal(const Glib::ustring &sender_name,
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters);
const Glib::ustring &signal_name,
const Glib::VariantContainerBase &parameters);
void handle_player_registered(const std::string &bus_name);
void handle_player_deregistered(const std::string &bus_name);

View File

@@ -6,6 +6,7 @@
#include <sigc++/sigc++.h>
#include "connection/dbus/dbus.hpp"
#include "giomm/dbusconnection.h"
#include "giomm/dbusownname.h"
#include "glib.h"

View File

@@ -19,6 +19,7 @@
class TrayService : public DbusConnection {
inline static TrayService *instance = nullptr;
public:
struct Item {
std::string id;
@@ -66,7 +67,7 @@ class TrayService : public DbusConnection {
if (TrayService::instance == nullptr) {
TrayService::instance = new TrayService();
}
return TrayService::instance;
}
@@ -137,7 +138,7 @@ class TrayService : public DbusConnection {
void begin_refresh(const std::string &id);
static gboolean refresh_timeout_cb(gpointer user_data);
static void on_refresh_finished_static(GObject *source, GAsyncResult *res,
gpointer user_data);
gpointer user_data);
void emit_registered_items_changed();
Glib::Variant<std::vector<Glib::ustring>>

View File

@@ -1,17 +1,17 @@
#pragma once
#include <array>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>
#include <cstdio>
class CommandHelper {
public:
static std::string exec(const char *cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, int(*)(FILE*)> pipe(popen(cmd, "r"), pclose);
std::unique_ptr<FILE, int (*)(FILE *)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
@@ -23,7 +23,7 @@ class CommandHelper {
static void execNoOutput(std::string cmd) {
std::string command = cmd + " > /dev/null 2>&1";
int ret = std::system(command.c_str());
int ret = std::system(command.c_str());
if (ret != 0) {
throw std::runtime_error("Command failed with return code: " + std::to_string(ret));
}

View File

@@ -52,14 +52,14 @@ class HyprSocketHelper {
public:
static std::string getHyprlandSocketPath() {
const char *hyprlandInstanceSignature = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
const char *xdgRuntimeDir = std::getenv("XDG_RUNTIME_DIR");
const char *xdgRuntimeDir = std::getenv("XDG_RUNTIME_DIR");
if (!xdgRuntimeDir || !hyprlandInstanceSignature) {
return std::string();
}
std::string basePath = std::string(xdgRuntimeDir) + "/hypr/" + std::string(hyprlandInstanceSignature) + "/";
std::string sock1 = basePath + ".socket2.sock";
std::string sock1 = basePath + ".socket2.sock";
if (access(sock1.c_str(), F_OK) == 0) {
return sock1;
}

View File

@@ -3,9 +3,8 @@
#include <string>
#include <vector>
class StringHelper {
public:
public:
static std::vector<std::string> split(const std::string &input, char delimiter) {
std::vector<std::string> tokens;
std::string token;
@@ -25,14 +24,14 @@ public:
return tokens;
}
static std::vector<std::string> split(const std::string &input, std::string delimiter) {
static std::vector<std::string> split(const std::string &input, std::string delimiter) {
std::vector<std::string> tokens;
size_t start = 0;
size_t end = input.find(delimiter);
size_t end = input.find(delimiter);
while (end != std::string::npos) {
tokens.push_back(input.substr(start, end - start));
start = end + delimiter.length();
end = input.find(delimiter, start);
end = input.find(delimiter, start);
}
tokens.push_back(input.substr(start));
return tokens;

View File

@@ -10,7 +10,7 @@ class SystemHelper {
throw std::runtime_error("Could not open file: " + filePath);
}
std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
std::istreambuf_iterator<char>());
file.close();
return content;
}

View File

@@ -8,8 +8,8 @@
#include "sigc++/signal.h"
class BluetoothService {
inline static BluetoothService *instance = nullptr;
inline static BluetoothService *instance = nullptr;
public:
sigc::signal<void(bool)> powerStateChangedSignal;
sigc::signal<void(bool)> isDiscoveringChangedSignal;

View File

View File

@@ -6,8 +6,6 @@
#include "components/base/button.hpp"
class BluetoothEntry : Gtk::Box {
public:
BluetoothEntry(std::string name, std::string address) {
@@ -38,7 +36,6 @@ class BluetoothEntry : Gtk::Box {
sigc::signal<void(std::string)> connect_clicked;
};
class BluetoothWidget : public Gtk::Box {
public:
BluetoothWidget();

View File

@@ -1,35 +1,36 @@
#pragma once
#include <memory>
#include "components/button/iconButton.hpp"
#include "components/button/tabButton.hpp"
#include "components/popover.hpp"
#include "widgets/controlCenter/mediaWidget.hpp"
#include "widgets/weather.hpp"
#include "gtkmm/box.h"
#include "gtkmm/scrolledwindow.h"
#include "gtkmm/stack.h"
#include "widgets/controlCenter/mediaControl.hpp"
#include "widgets/weather.hpp"
#include <memory>
#include <unordered_map>
class ControlCenter : public Popover {
public:
ControlCenter(Icon::Type icon, std::string name);
private:
Gtk::ScrolledWindow scrollview;
Gtk::Box container;
Gtk::Box tabRow;
Gtk::Stack contentStack;
Gtk::Box controlCenterContainer;
WeatherWidget weatherWidget;
std::unique_ptr<TabButton> mediaControl;
std::unique_ptr<TabButton> testTabButton;
std::shared_ptr<MprisController> mprisController = MprisController::getInstance();
std::unordered_map<std::string, MediaControlWidget*> mediaWidgets;
public:
ControlCenter(Icon::Type icon, std::string name);
void addPlayerWidget(const std::string &bus_name);
void removePlayerWidget(const std::string &bus_name);
void setActiveTab(const std::string &tab_name);
private:
Gtk::ScrolledWindow scrollview;
Gtk::Box container;
Gtk::Box tabRow;
Gtk::Stack contentStack;
std::unique_ptr<TabButton> mediaTabButton;
std::unique_ptr<TabButton> infoTabButton;
std::unique_ptr<TabButton> timerButton;
std::unique_ptr<WeatherWidget> weatherWidget;
std::unique_ptr<MediaWidget> mediaControlWidget;
void addPlayerWidget(const std::string &bus_name);
void removePlayerWidget(const std::string &bus_name);
void setActiveTab(const std::string &tab_name);
};

View File

@@ -0,0 +1,24 @@
#pragma once
#include "components/mediaPlayer.hpp"
#include <map>
#include <memory>
#include <string>
#include "connection/dbus/mpris.hpp"
#include "gtkmm/box.h"
class MediaWidget : public Gtk::Box {
public:
MediaWidget();
private:
Gtk::Box container;
std::shared_ptr<MprisController> mprisController = MprisController::getInstance();
void addPlayerWidget(const std::string &bus_name);
void removePlayerWidget(const std::string &bus_name);
std::map<std::string, std::unique_ptr<MediaPlayer>> mediaWidgets;
};

View File

@@ -1,12 +1,10 @@
#pragma once
#include <chrono>
#include <csignal>
#include <cstdint>
#include <sigc++/connection.h>
#include "gdkmm/monitor.h"
#include "gtkmm/scrolledwindow.h"
#include "gtkmm/window.h"
#define DEFAULT_NOTIFICATION_TIMEOUT 6700
@@ -19,11 +17,9 @@ class BaseNotification : public Gtk::Window {
void resumeAutoClose();
void startAutoClose(int timeoutMs);
sigc::signal<void(int)> signal_close;
sigc::signal<void(uint64_t)> signal_close;
sigc::signal<void(bool)> signal_hover_changed;
virtual ~BaseNotification() = default;
uint64_t getNotificationId() const {
return this->notificationId;
}

View File

@@ -4,6 +4,7 @@
#include "connection/dbus/messages.hpp"
#include "widgets/notification/baseNotification.hpp"
#include "gtkmm/box.h"
class CopyNotification : public BaseNotification {

View File

@@ -2,6 +2,7 @@
#pragma once
#include <cstdint>
#include "connection/dbus/messages.hpp"
#include "widgets/notification/baseNotification.hpp"
@@ -9,5 +10,4 @@ class NotificationWindow : public BaseNotification {
public:
NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage message);
virtual ~NotificationWindow() = default;
};

View File

@@ -39,12 +39,12 @@ class TrayIconWidget : public IconButton {
Glib::RefPtr<Gtk::PopoverMenu> menuPopover;
Glib::RefPtr<Gio::SimpleActionGroup> menuActions;
Glib::RefPtr<Gio::MenuModel> menuModel;
bool menuPopupPending = false;
bool menuPopupPending = false;
bool menuRequestInFlight = false;
bool hasRemoteMenu = false;
bool hasRemoteMenu = false;
std::shared_ptr<bool> aliveFlag;
double pendingX = 0.0;
double pendingY = 0.0;
double pendingX = 0.0;
double pendingY = 0.0;
void on_primary_released(int n_press, double x, double y);
void on_middle_released(int n_press, double x, double y);