Compare commits
37 Commits
178a4451d4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ce0643b6ac | |||
| 0463c37543 | |||
| cddcc96aa9 | |||
| a048d7ae7a | |||
| b9f5eea4af | |||
| 9c70065bf6 | |||
| 9898c48c67 | |||
| 6d9f016350 | |||
| ed1a9a8605 | |||
| 49ac6cec90 | |||
| da9f167747 | |||
| 9404321249 | |||
| c742ca6d18 | |||
| bfc9369a5e | |||
| 8de6b2c0ef | |||
| 8873c4eb3c | |||
| 88e3c7a825 | |||
| eb6d5ba499 | |||
| 5320831c15 | |||
| 82769019f5 | |||
| 54eed7e7e1 | |||
| fc47a52a15 | |||
| 6e9301ac59 | |||
| e654683d4c | |||
| 66124fae8b | |||
| 7121b945d7 | |||
| 3a44910961 | |||
| 183b138658 | |||
| 2f2e476d74 | |||
| b447abca42 | |||
| a90db8588c | |||
| 4d4115012c | |||
| 03e0ce53d5 | |||
| dd312b9ec5 | |||
| f4a1dca281 | |||
| 49ab07cd6f | |||
| 817b9dd394 |
@@ -10,3 +10,6 @@ IncludeCategories:
|
|||||||
- Regex: '.*'
|
- Regex: '.*'
|
||||||
Priority: 3
|
Priority: 3
|
||||||
IncludeBlocks: Regroup
|
IncludeBlocks: Regroup
|
||||||
|
|
||||||
|
# remove unused includes
|
||||||
|
SortIncludes: true
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -55,4 +55,5 @@ test/test_runner
|
|||||||
|
|
||||||
cmake-build-debug/**/*
|
cmake-build-debug/**/*
|
||||||
.idea
|
.idea
|
||||||
|
.cache/
|
||||||
|
Testing/
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 4.2.0)
|
cmake_minimum_required(VERSION 4.2.0)
|
||||||
project(bar)
|
project(bar)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
option(ENABLE_COVERAGE "Enable coverage flags" OFF)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
@@ -8,6 +13,13 @@ 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")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic")
|
||||||
|
|
||||||
|
if(ENABLE_COVERAGE)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g --coverage")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g --coverage")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
|
||||||
|
set(CTEST_COVERAGE_COMMAND "gcov")
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
||||||
@@ -26,23 +38,28 @@ target_sources(bar_lib
|
|||||||
src/app.cpp
|
src/app.cpp
|
||||||
src/bar/bar.cpp
|
src/bar/bar.cpp
|
||||||
|
|
||||||
|
src/connection/httpConnection.cpp
|
||||||
|
src/connection/dbus/notification.cpp
|
||||||
|
src/connection/dbus/mpris.cpp
|
||||||
|
src/connection/dbus/tray.cpp
|
||||||
|
|
||||||
src/widgets/clock.cpp
|
src/widgets/clock.cpp
|
||||||
src/widgets/date.cpp
|
src/widgets/date.cpp
|
||||||
src/widgets/notification/baseNotification.cpp
|
src/widgets/notification/baseNotification.cpp
|
||||||
src/widgets/notification/notification.cpp
|
src/widgets/notification/copyNotification.cpp
|
||||||
|
src/widgets/notification/notificationWindow.cpp
|
||||||
src/widgets/notification/spotifyNotification.cpp
|
src/widgets/notification/spotifyNotification.cpp
|
||||||
src/widgets/volumeWidget.cpp
|
src/widgets/volumeWidget.cpp
|
||||||
|
src/widgets/weather.cpp
|
||||||
src/widgets/webWidget.cpp
|
src/widgets/webWidget.cpp
|
||||||
|
|
||||||
src/services/hyprland.cpp
|
src/services/hyprland.cpp
|
||||||
src/services/notificationController.cpp
|
src/services/notificationController.cpp
|
||||||
src/services/textureCache.cpp
|
src/services/textureCache.cpp
|
||||||
src/services/tray.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/controlCenter.cpp
|
||||||
|
src/widgets/controlCenter/mediaControl.cpp
|
||||||
|
|
||||||
src/components/popover.cpp
|
src/components/popover.cpp
|
||||||
src/components/workspaceIndicator.cpp
|
src/components/workspaceIndicator.cpp
|
||||||
@@ -56,6 +73,28 @@ add_executable(bar main.cpp)
|
|||||||
|
|
||||||
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${WEBKIT_LIBRARIES} ${CURL_LIBRARIES} nlohmann_json::nlohmann_json)
|
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${WEBKIT_LIBRARIES} ${CURL_LIBRARIES} nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
|
|
||||||
|
# add spdlog
|
||||||
|
find_package(spdlog REQUIRED)
|
||||||
|
target_link_libraries(bar_lib PRIVATE spdlog::spdlog)
|
||||||
|
|
||||||
|
|
||||||
|
# ---- Testing shit
|
||||||
|
find_package(Catch2 3 REQUIRED)
|
||||||
|
|
||||||
|
add_executable(bar_tests
|
||||||
|
tests/string_helper_tests.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(bar_tests PRIVATE
|
||||||
|
include
|
||||||
|
)
|
||||||
|
target_link_libraries(bar_tests PRIVATE Catch2::Catch2WithMain)
|
||||||
|
|
||||||
|
# Coverage flags are set globally when ENABLE_COVERAGE is ON.
|
||||||
|
|
||||||
|
include(Catch)
|
||||||
|
catch_discover_tests(bar_tests)
|
||||||
|
|
||||||
# Copy all CSS files in resources/ into build and user config directories
|
# Copy all CSS files in resources/ into build and user config directories
|
||||||
file(GLOB RES_CSS_FILES CONFIGURE_DEPENDS
|
file(GLOB RES_CSS_FILES CONFIGURE_DEPENDS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/resources/*.css"
|
"${CMAKE_CURRENT_SOURCE_DIR}/resources/*.css"
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include "bar/bar.hpp"
|
#include "bar/bar.hpp"
|
||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
#include "services/dbus/notification.hpp"
|
#include "connection/dbus/notification.hpp"
|
||||||
|
#include "connection/dbus/tray.hpp"
|
||||||
|
|
||||||
#include "glibmm/refptr.h"
|
#include "glibmm/refptr.h"
|
||||||
#include "gtkmm/application.h"
|
#include "gtkmm/application.h"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "widgets/tray.hpp"
|
#include "widgets/tray.hpp"
|
||||||
#include "widgets/volumeWidget.hpp"
|
#include "widgets/volumeWidget.hpp"
|
||||||
#include "widgets/webWidget.hpp"
|
#include "widgets/webWidget.hpp"
|
||||||
#include "widgets/controlCenter.hpp"
|
#include "widgets/controlCenter/controlCenter.hpp"
|
||||||
|
|
||||||
class Bar : public Gtk::Window {
|
class Bar : public Gtk::Window {
|
||||||
public:
|
public:
|
||||||
@@ -27,8 +27,8 @@ class Bar : public Gtk::Window {
|
|||||||
|
|
||||||
Clock clock;
|
Clock clock;
|
||||||
Date date;
|
Date date;
|
||||||
WebWidget homeAssistant{"\ue88a", "Home Assistant", "https://home.rivercry.com"};
|
WebWidget homeAssistant{"\uf024", "Home Assistant", "https://home.rivercry.com"};
|
||||||
ControlCenter controlCenter{"\ue88a", "Control Center"};
|
ControlCenter controlCenter{"\ue062", "Control Center"};
|
||||||
|
|
||||||
std::shared_ptr<TrayWidget> trayWidget = nullptr;
|
std::shared_ptr<TrayWidget> trayWidget = nullptr;
|
||||||
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
|
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Popover : public Button {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_toggle_window();
|
void on_toggle_window();
|
||||||
Gtk::Popover *popover = nullptr;
|
std::unique_ptr<Gtk::Popover> popover;
|
||||||
void set_popover_child(Gtk::Widget &child) {
|
void set_popover_child(Gtk::Widget &child) {
|
||||||
gtk_popover_set_child(popover->gobj(), child.gobj());
|
gtk_popover_set_child(popover->gobj(), child.gobj());
|
||||||
}
|
}
|
||||||
|
|||||||
24
include/connection/dbus/dbus.hpp
Normal file
24
include/connection/dbus/dbus.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <giomm.h>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
|
class DbusConnection {
|
||||||
|
public:
|
||||||
|
virtual ~DbusConnection() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ensure_gio_init() {
|
||||||
|
try {
|
||||||
|
Gio::init();
|
||||||
|
} catch (const Glib::Error &) {
|
||||||
|
// Already initialized.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -2,23 +2,32 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "gdkmm/pixbuf.h"
|
||||||
#include "glibmm/variant.h"
|
#include "glibmm/variant.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct MprisPlayer2Message {
|
struct MprisPlayer2Message {
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string artist;
|
std::vector<std::string> artist;
|
||||||
std::string artwork_url;
|
std::string artwork_url;
|
||||||
|
std::string track_id;
|
||||||
|
int64_t length_ms;
|
||||||
|
|
||||||
std::function<void()> play_pause;
|
std::function<void()> play_pause;
|
||||||
std::function<void()> next;
|
std::function<void()> next;
|
||||||
std::function<void()> previous;
|
std::function<void()> previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum NotificationUrgency {
|
||||||
|
LOW = 0,
|
||||||
|
NORMAL = 1,
|
||||||
|
CRITICAL = 2
|
||||||
|
};
|
||||||
|
|
||||||
struct NotifyMessage {
|
struct NotifyMessage {
|
||||||
std::string app_name;
|
std::string app_name;
|
||||||
uint32_t replaces_id;
|
uint32_t replaces_id;
|
||||||
@@ -26,8 +35,12 @@ struct NotifyMessage {
|
|||||||
std::string summary;
|
std::string summary;
|
||||||
std::string body;
|
std::string body;
|
||||||
std::vector<std::string> actions;
|
std::vector<std::string> actions;
|
||||||
std::map<std::string, Glib::VariantBase> hints;
|
NotificationUrgency urgency = NORMAL;
|
||||||
int32_t expire_timeout;
|
int32_t expire_timeout;
|
||||||
// Callback to invoke when an action is triggered
|
// 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
|
||||||
|
std::optional<Glib::RefPtr<Gdk::Pixbuf>> imageData;
|
||||||
};
|
};
|
||||||
81
include/connection/dbus/mpris.hpp
Normal file
81
include/connection/dbus/mpris.hpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <giomm.h>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include "connection/dbus/dbus.hpp"
|
||||||
|
#include "connection/dbus/messages.hpp"
|
||||||
|
|
||||||
|
class MprisController : public DbusConnection {
|
||||||
|
public:
|
||||||
|
struct PlayerState {
|
||||||
|
std::string title;
|
||||||
|
std::vector<std::string> artist;
|
||||||
|
std::string artwork_url;
|
||||||
|
int64_t length_ms;
|
||||||
|
};
|
||||||
|
enum class PlaybackStatus {
|
||||||
|
Playing,
|
||||||
|
Paused,
|
||||||
|
Stopped,
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::shared_ptr<MprisController> getInstance();
|
||||||
|
static std::shared_ptr<MprisController> createForPlayer(const std::string &bus_name);
|
||||||
|
|
||||||
|
std::vector<std::string> get_registered_players() const;
|
||||||
|
|
||||||
|
void toggle_play();
|
||||||
|
void pause();
|
||||||
|
void next_song();
|
||||||
|
void previous_song();
|
||||||
|
void emit_seeked(int64_t position_us);
|
||||||
|
void set_position(const std::string &track_id, int64_t position_us);
|
||||||
|
|
||||||
|
sigc::signal<void(const MprisPlayer2Message &)> &signal_mpris_updated();
|
||||||
|
sigc::signal<void(PlaybackStatus)> &signal_playback_status_changed();
|
||||||
|
sigc::signal<void(int64_t)> &signal_playback_position_changed();
|
||||||
|
sigc::signal<void(bool)> &signal_can_seek_changed();
|
||||||
|
sigc::signal<void(const std::string &)> &signal_player_registered();
|
||||||
|
sigc::signal<void(const std::string &)> &signal_player_deregistered();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MprisController();
|
||||||
|
explicit MprisController(const std::string &bus_name);
|
||||||
|
std::map<std::string, PlaybackStatus> playbackStatusMap = {
|
||||||
|
{"Playing", PlaybackStatus::Playing},
|
||||||
|
{"Paused", PlaybackStatus::Paused},
|
||||||
|
{"Stopped", PlaybackStatus::Stopped},
|
||||||
|
};
|
||||||
|
|
||||||
|
PlaybackStatus currentPlaybackStatus = PlaybackStatus::Stopped;
|
||||||
|
|
||||||
|
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
||||||
|
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;
|
||||||
|
sigc::signal<void(bool)> canSeekChangedSignal;
|
||||||
|
sigc::signal<void(const std::string &)> playerRegisteredSignal;
|
||||||
|
sigc::signal<void(const std::string &)> playerDeregisteredSignal;
|
||||||
|
|
||||||
|
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
|
||||||
|
void signalNotification();
|
||||||
|
void emit_cached_playback_status();
|
||||||
|
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 ¶meters);
|
||||||
|
void handle_player_registered(const std::string &bus_name);
|
||||||
|
void handle_player_deregistered(const std::string &bus_name);
|
||||||
|
|
||||||
|
// Called when the song changes
|
||||||
|
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
||||||
|
const std::vector<Glib::ustring> &invalidated_properties);
|
||||||
|
};
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
|
#include "connection/dbus/dbus.hpp"
|
||||||
#include "giomm/dbusconnection.h"
|
#include "giomm/dbusconnection.h"
|
||||||
#include "giomm/dbusownname.h"
|
#include "giomm/dbusownname.h"
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
@@ -39,7 +40,7 @@ const Glib::ustring introspection_xml = R"(
|
|||||||
</node>
|
</node>
|
||||||
)";
|
)";
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService : public DbusConnection {
|
||||||
public:
|
public:
|
||||||
NotificationService() : notificationIdCounter(1) {
|
NotificationService() : notificationIdCounter(1) {
|
||||||
Gio::DBus::own_name(
|
Gio::DBus::own_name(
|
||||||
@@ -15,7 +15,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class TrayService {
|
#include "connection/dbus/dbus.hpp"
|
||||||
|
|
||||||
|
class TrayService : public DbusConnection {
|
||||||
inline static TrayService *instance = nullptr;
|
inline static TrayService *instance = nullptr;
|
||||||
public:
|
public:
|
||||||
struct Item {
|
struct Item {
|
||||||
@@ -85,7 +87,6 @@ class TrayService {
|
|||||||
bool addSignalPending = false;
|
bool addSignalPending = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Glib::RefPtr<Gio::DBus::Connection> connection;
|
|
||||||
Glib::RefPtr<Gio::DBus::NodeInfo> nodeInfo;
|
Glib::RefPtr<Gio::DBus::NodeInfo> nodeInfo;
|
||||||
Gio::DBus::InterfaceVTable vtable;
|
Gio::DBus::InterfaceVTable vtable;
|
||||||
|
|
||||||
36
include/connection/httpConnection.hpp
Normal file
36
include/connection/httpConnection.hpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct HttpResponse {
|
||||||
|
long status_code = 0;
|
||||||
|
std::string body;
|
||||||
|
std::map<std::string, std::string> headers;
|
||||||
|
std::string error;
|
||||||
|
|
||||||
|
bool ok() const {
|
||||||
|
return error.empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class HttpConnection {
|
||||||
|
public:
|
||||||
|
static HttpResponse get(const std::string &url,
|
||||||
|
const std::map<std::string, std::string> &headers = {},
|
||||||
|
long timeout_ms = 0);
|
||||||
|
|
||||||
|
static HttpResponse post(const std::string &url,
|
||||||
|
const std::string &body,
|
||||||
|
const std::map<std::string, std::string> &headers = {},
|
||||||
|
const std::string &content_type = "application/json",
|
||||||
|
long timeout_ms = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static HttpResponse performRequest(const std::string &method,
|
||||||
|
const std::string &url,
|
||||||
|
const std::string &body,
|
||||||
|
const std::map<std::string, std::string> &headers,
|
||||||
|
const std::string &content_type,
|
||||||
|
long timeout_ms);
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <spdlog/spdlog.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -25,9 +25,9 @@ class SocketHelper {
|
|||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
data = std::string(buffer);
|
data = std::string(buffer);
|
||||||
} else if (bytesRead == 0) {
|
} else if (bytesRead == 0) {
|
||||||
std::cerr << "Socket closed by peer" << std::endl;
|
spdlog::warn("Socket closed by peer");
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Error reading from socket" << std::endl;
|
spdlog::error("Error reading from socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto delimiterPos = data.find(delimiter);
|
auto delimiterPos = data.find(delimiter);
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <giomm.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class MprisController {
|
|
||||||
public:
|
|
||||||
|
|
||||||
MprisController();
|
|
||||||
|
|
||||||
void toggle_play();
|
|
||||||
void next_song();
|
|
||||||
void previous_song();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
|
||||||
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
|
||||||
|
|
||||||
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
|
|
||||||
void launchNotification();
|
|
||||||
|
|
||||||
// Called when the song changes
|
|
||||||
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
|
||||||
const std::vector<Glib::ustring> &invalidated_properties);
|
|
||||||
};
|
|
||||||
@@ -67,6 +67,7 @@ class HyprlandService {
|
|||||||
ACTIVE_WINDOW,
|
ACTIVE_WINDOW,
|
||||||
OPEN_WINDOW,
|
OPEN_WINDOW,
|
||||||
CLOSE_WINDOW,
|
CLOSE_WINDOW,
|
||||||
|
MOVE_WINDOW,
|
||||||
URGENT,
|
URGENT,
|
||||||
|
|
||||||
FOCUSED_MONITOR,
|
FOCUSED_MONITOR,
|
||||||
@@ -78,6 +79,7 @@ class HyprlandService {
|
|||||||
{"activewindowv2", ACTIVE_WINDOW},
|
{"activewindowv2", ACTIVE_WINDOW},
|
||||||
{"openwindow", OPEN_WINDOW},
|
{"openwindow", OPEN_WINDOW},
|
||||||
{"closewindow", CLOSE_WINDOW},
|
{"closewindow", CLOSE_WINDOW},
|
||||||
|
{"movewindowv2", MOVE_WINDOW},
|
||||||
{"urgent", URGENT},
|
{"urgent", URGENT},
|
||||||
{"focusedmon", FOCUSED_MONITOR},
|
{"focusedmon", FOCUSED_MONITOR},
|
||||||
{"monitorremoved", MONITOR_REMOVED},
|
{"monitorremoved", MONITOR_REMOVED},
|
||||||
@@ -86,6 +88,7 @@ class HyprlandService {
|
|||||||
void onFocusedMonitorChanged(std::string monitorData);
|
void onFocusedMonitorChanged(std::string monitorData);
|
||||||
void onOpenWindow(std::string windowData);
|
void onOpenWindow(std::string windowData);
|
||||||
void onCloseWindow(std::string windowData);
|
void onCloseWindow(std::string windowData);
|
||||||
|
void onMoveWindow(std::string windowData);
|
||||||
void onUrgent(std::string windowAddress);
|
void onUrgent(std::string windowAddress);
|
||||||
void onActiveWindowChanged(std::string windowAddress);
|
void onActiveWindowChanged(std::string windowAddress);
|
||||||
void onMonitorRemoved(std::string monitorName);
|
void onMonitorRemoved(std::string monitorName);
|
||||||
@@ -101,7 +104,7 @@ class HyprlandService {
|
|||||||
int socketFd;
|
int socketFd;
|
||||||
///
|
///
|
||||||
|
|
||||||
void bindSocket();
|
void bindHyprlandSocket();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "services/dbus/messages.hpp"
|
|
||||||
|
#include "connection/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
#include "gdkmm/monitor.h"
|
#include "gdkmm/monitor.h"
|
||||||
|
|
||||||
@@ -19,8 +24,14 @@ class NotificationController {
|
|||||||
|
|
||||||
void showSpotifyNotification(MprisPlayer2Message mpris);
|
void showSpotifyNotification(MprisPlayer2Message mpris);
|
||||||
void showNotificationOnAllMonitors(NotifyMessage notify);
|
void showNotificationOnAllMonitors(NotifyMessage notify);
|
||||||
|
void showCopyNotification(NotifyMessage notify);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint64_t globalNotificationId = 1;
|
||||||
|
std::map<uint64_t, std::vector<std::shared_ptr<BaseNotification>>> activeNotifications;
|
||||||
|
std::map<uint64_t, int> hoverCounts;
|
||||||
NotificationController();
|
NotificationController();
|
||||||
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
||||||
|
void updateHoverState(uint64_t notificationId, bool isHovered);
|
||||||
|
void closeNotification(uint64_t notificationId);
|
||||||
};
|
};
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "components/popover.hpp"
|
|
||||||
#include "gtkmm/box.h"
|
|
||||||
|
|
||||||
class ControlCenter : public Popover {
|
|
||||||
public:
|
|
||||||
ControlCenter(std::string icon, std::string name);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Gtk::Box container;
|
|
||||||
};
|
|
||||||
32
include/widgets/controlCenter/controlCenter.hpp
Normal file
32
include/widgets/controlCenter/controlCenter.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "components/popover.hpp"
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
#include "gtkmm/stack.h"
|
||||||
|
#include "widgets/controlCenter/mediaControl.hpp"
|
||||||
|
#include "widgets/weather.hpp"
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class ControlCenter : public Popover {
|
||||||
|
public:
|
||||||
|
ControlCenter(std::string icon, std::string name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gtk::Box container;
|
||||||
|
Gtk::Box tabRow;
|
||||||
|
Gtk::Stack contentStack;
|
||||||
|
Gtk::Box controlCenterContainer;
|
||||||
|
WeatherWidget weatherWidget;
|
||||||
|
Gtk::Button mediaControl;
|
||||||
|
Gtk::Button testTabButton;
|
||||||
|
std::shared_ptr<MprisController> mprisController = MprisController::getInstance();
|
||||||
|
std::unordered_map<std::string, MediaControlWidget*> mediaWidgets;
|
||||||
|
|
||||||
|
void addPlayerWidget(const std::string &bus_name);
|
||||||
|
void removePlayerWidget(const std::string &bus_name);
|
||||||
|
void setActiveTab(const std::string &tab_name);
|
||||||
|
|
||||||
|
};
|
||||||
63
include/widgets/controlCenter/mediaControl.hpp
Normal file
63
include/widgets/controlCenter/mediaControl.hpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
#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 "connection/dbus/mpris.hpp"
|
||||||
|
|
||||||
|
class MediaControlWidget : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
explicit MediaControlWidget(std::shared_ptr<MprisController> controller);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<MprisController> mprisController;
|
||||||
|
|
||||||
|
int64_t currentPositionUs = 0;
|
||||||
|
int64_t totalLengthUs = 0;
|
||||||
|
sigc::connection seekTimerConnection;
|
||||||
|
bool suppressSeekSignal = false;
|
||||||
|
std::string currentTrackId;
|
||||||
|
MprisController::PlaybackStatus playbackStatus = MprisController::PlaybackStatus::Stopped;
|
||||||
|
bool canSeek = true;
|
||||||
|
|
||||||
|
void setCurrentPosition(int64_t position_us);
|
||||||
|
void setTotalLength(int64_t length_us);
|
||||||
|
void resetSeekTimer(int64_t start_position_us);
|
||||||
|
bool onSeekTick();
|
||||||
|
void schedulePauseAfterSeek();
|
||||||
|
void setCanSeek(bool can_seek);
|
||||||
|
|
||||||
|
Gtk::Box spotifyContainer;
|
||||||
|
|
||||||
|
// image as background, artist, title
|
||||||
|
Gtk::Overlay topContainer;
|
||||||
|
Gtk::Picture backgroundImage;
|
||||||
|
Gtk::Box infoContainer;
|
||||||
|
Gtk::Label artistLabel;
|
||||||
|
Gtk::Label titleLabel;
|
||||||
|
|
||||||
|
//
|
||||||
|
Gtk::Box seekBarContainer;
|
||||||
|
Gtk::Label currentTimeLabel;
|
||||||
|
Gtk::Scale seekBar;
|
||||||
|
Gtk::Label totalTimeLabel;
|
||||||
|
|
||||||
|
// playback controls
|
||||||
|
Gtk::Box bottomContainer;
|
||||||
|
Gtk::Button previousButton;
|
||||||
|
Gtk::Button playPauseButton;
|
||||||
|
Gtk::Button nextButton;
|
||||||
|
|
||||||
|
Gtk::ScrolledWindow imageWrapper;
|
||||||
|
|
||||||
|
void onSpotifyMprisUpdated(const MprisPlayer2Message &message);
|
||||||
|
|
||||||
|
void onRunningStateChanged(MprisController::PlaybackStatus status);
|
||||||
|
void onPlay();
|
||||||
|
void onPause();
|
||||||
|
void onStop();
|
||||||
|
};
|
||||||
@@ -1,24 +1,45 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <chrono>
|
||||||
#include <string>
|
#include <csignal>
|
||||||
|
#include <cstdint>
|
||||||
#include "helpers/system.hpp"
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
#include "gdkmm/monitor.h"
|
#include "gdkmm/monitor.h"
|
||||||
#include "gtk4-layer-shell.h"
|
#include "gtkmm/scrolledwindow.h"
|
||||||
#include "gtkmm/cssprovider.h"
|
|
||||||
#include "gtkmm/window.h"
|
#include "gtkmm/window.h"
|
||||||
|
|
||||||
|
#define DEFAULT_NOTIFICATION_TIMEOUT 6700
|
||||||
#define DEFAULT_NOTIFICATION_TIMEOUT 4000
|
|
||||||
|
|
||||||
class BaseNotification : public Gtk::Window {
|
class BaseNotification : public Gtk::Window {
|
||||||
public:
|
public:
|
||||||
BaseNotification(std::shared_ptr<Gdk::Monitor> monitor);
|
BaseNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor);
|
||||||
|
|
||||||
|
void pauseAutoClose();
|
||||||
|
void resumeAutoClose();
|
||||||
|
void startAutoClose(int timeoutMs);
|
||||||
|
|
||||||
|
sigc::signal<void(int)> signal_close;
|
||||||
|
sigc::signal<void(bool)> signal_hover_changed;
|
||||||
|
|
||||||
virtual ~BaseNotification() = default;
|
virtual ~BaseNotification() = default;
|
||||||
|
|
||||||
|
uint64_t getNotificationId() const {
|
||||||
|
return this->notificationId;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ensure_notification_css_loaded();
|
void ensure_notification_css_loaded();
|
||||||
|
|
||||||
|
void start_auto_close_timeout(int timeoutMs);
|
||||||
|
void pause_auto_close();
|
||||||
|
void resume_auto_close();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint64_t notificationId;
|
||||||
|
|
||||||
|
bool autoClosePaused = false;
|
||||||
|
int autoCloseRemainingMs = 0;
|
||||||
|
std::chrono::steady_clock::time_point autoCloseDeadline;
|
||||||
|
sigc::connection autoCloseConnection;
|
||||||
};
|
};
|
||||||
34
include/widgets/notification/copyNotification.hpp
Normal file
34
include/widgets/notification/copyNotification.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include "connection/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
|
||||||
|
class CopyNotification : public BaseNotification {
|
||||||
|
enum class CopyType {
|
||||||
|
TEXT,
|
||||||
|
IMAGE
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
CopyNotification(uint64_t id,
|
||||||
|
std::shared_ptr<Gdk::Monitor> monitor,
|
||||||
|
NotifyMessage notify);
|
||||||
|
virtual ~CopyNotification() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
CopyType type;
|
||||||
|
std::string copiedText;
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> copiedImage;
|
||||||
|
Gtk::Box mainBox;
|
||||||
|
|
||||||
|
std::string title;
|
||||||
|
|
||||||
|
void createImageNotification(NotifyMessage notify);
|
||||||
|
void createTextNotification(NotifyMessage notify);
|
||||||
|
|
||||||
|
void setupTitle(std::string title);
|
||||||
|
};
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "services/dbus/messages.hpp"
|
#include <cstdint>
|
||||||
|
#include "connection/dbus/messages.hpp"
|
||||||
#include "widgets/notification/baseNotification.hpp"
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
class NotificationWindow : public BaseNotification {
|
class NotificationWindow : public BaseNotification {
|
||||||
public:
|
public:
|
||||||
NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage message);
|
NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage message);
|
||||||
virtual ~NotificationWindow() = default;
|
virtual ~NotificationWindow() = default;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
|
||||||
#include "services/dbus/messages.hpp"
|
#include "connection/dbus/messages.hpp"
|
||||||
#include "widgets/notification/baseNotification.hpp"
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
#include "gtkmm/box.h"
|
|
||||||
#include "gtkmm/centerbox.h"
|
#include "gtkmm/centerbox.h"
|
||||||
|
|
||||||
class SpotifyNotification : public BaseNotification {
|
class SpotifyNotification : public BaseNotification {
|
||||||
public:
|
public:
|
||||||
SpotifyNotification(std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message message);
|
SpotifyNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message message);
|
||||||
virtual ~SpotifyNotification() = default;
|
virtual ~SpotifyNotification() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Gtk::CenterBox> createButtonBox(MprisPlayer2Message mpris);
|
std::unique_ptr<Gtk::CenterBox> createButtonBox(MprisPlayer2Message mpris);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "services/tray.hpp"
|
#include "connection/dbus/tray.hpp"
|
||||||
#include "components/base/button.hpp"
|
#include "components/base/button.hpp"
|
||||||
|
|
||||||
class TrayIconWidget : public Button {
|
class TrayIconWidget : public Button {
|
||||||
|
|||||||
20
include/widgets/weather.hpp
Normal file
20
include/widgets/weather.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
|
class WeatherWidget : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
WeatherWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gtk::Label titleLabel;
|
||||||
|
Gtk::Label currentLabel;
|
||||||
|
Gtk::Label todayLabel;
|
||||||
|
|
||||||
|
bool onRefreshTick();
|
||||||
|
void fetchWeather();
|
||||||
|
void applyWeatherText(const std::string ¤t_text,
|
||||||
|
const std::string &today_text);
|
||||||
|
};
|
||||||
@@ -16,16 +16,49 @@ window {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
padding-top: 2px;
|
|
||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-family: var(--text-font);
|
font-family: var(--text-font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.material-icons {
|
||||||
|
font-family: var(--icon-font-material);
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-icon {
|
||||||
|
font-family: var(--icon-font-material);
|
||||||
|
font-size: 20px;
|
||||||
|
margin-right: 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 2px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-icon:hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-tab-row {
|
||||||
|
/* mordern and sleek */
|
||||||
|
background-color: rgba(50, 50, 50, 0.8);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 2px 4px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active-button {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #1e1e1e;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
popover {
|
popover {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
font-family: var(--text-font);
|
font-family: var(--text-font);
|
||||||
padding: 6px;
|
/* padding: 6px; TODO: create better padding*/
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
|
||||||
background: rgba(25, 25, 25, 0.8);
|
background: rgba(25, 25, 25, 0.8);
|
||||||
@@ -34,6 +67,69 @@ popover {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.control-center-popover {
|
||||||
|
background-color: rgba(35, 35, 35, 0.95);
|
||||||
|
padding: 12px;
|
||||||
|
padding-top : 6px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
|
||||||
|
border: 1px solid rgba(57, 57, 57, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-player-container {
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(35, 35, 35, 0.95);
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.control-center-player-artist-label {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: rgba(0, 0, 0, 0.45);
|
||||||
|
/* bold text shadow */
|
||||||
|
text-shadow: 0 0 5px #000000aa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-player-title-label {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #cccccc;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: rgba(0, 0, 0, 0.35);
|
||||||
|
/* bold text shadow */
|
||||||
|
text-shadow: 0 0 5px #000000aa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-seek-bar {
|
||||||
|
min-height: 6px;
|
||||||
|
min-width: 120px;
|
||||||
|
margin: 0 6px;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-seek-bar trough {
|
||||||
|
background-color: rgba(255, 255, 255, 0.18);
|
||||||
|
border-radius: 999px;
|
||||||
|
min-height: 6px;
|
||||||
|
min-width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-seek-bar highlight {
|
||||||
|
background-color: rgba(255, 255, 255, 0.65);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-seek-bar slider {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 999px;
|
||||||
|
min-width: 10px;
|
||||||
|
min-height: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
tooltip {
|
tooltip {
|
||||||
background-color: #222222;
|
background-color: #222222;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
--text-font-mono: "Hack Nerd Font Mono", monospace;
|
--text-font-mono: "Hack Nerd Font Mono", monospace;
|
||||||
|
|
||||||
--color-notification-bg: rgba(30, 30, 30, 0.95);
|
--color-notification-bg: rgba(30, 30, 30, 0.95);
|
||||||
|
--color-notification-critical-bg: rgba(50, 20, 20, 0.95);
|
||||||
--color-border: rgba(80, 80, 80, 0.8);
|
--color-border: rgba(80, 80, 80, 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,24 +13,57 @@
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
background: var(--color-notification-bg);
|
background: var(--color-notification-bg);
|
||||||
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
|
||||||
border: 1px solid var(--color-border);
|
border: 1px solid var(--color-border);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification-critical {
|
||||||
|
background: linear-gradient(145deg, #321010, #1e1e1e);
|
||||||
|
border: 1px solid rgba(255, 75, 75, 0.5);
|
||||||
|
border-left: 3px solid #ff4b4b;
|
||||||
|
box-shadow:
|
||||||
|
0 4px 30px rgba(0, 0, 0, 0.8),
|
||||||
|
0 0 15px rgba(255, 75, 75, 0.2),
|
||||||
|
inset 0 0 10px rgba(255, 75, 75, 0.1);
|
||||||
|
|
||||||
|
color: #ffffff;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-normal {
|
||||||
|
background: linear-gradient(90deg, #0c1f3a 0%, #1e1e1e 100%);
|
||||||
|
border: 1px solid rgba(60, 160, 255, 0.3);
|
||||||
|
border-left: 3px solid #3c9aff;
|
||||||
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5),
|
||||||
|
0 0 10px rgba(60, 160, 255, 0.1);
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-low {
|
||||||
|
background: linear-gradient(145deg, #2a2a2a, #1e1e1e);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
border-left: 3px solid #888888;
|
||||||
|
color: rgba(255, 255, 255, 0.95);
|
||||||
|
/* white box shadow */
|
||||||
|
box-shadow: 0 4px 20px rgba(255, 255, 255, 0.05);
|
||||||
|
font-size: 13px;
|
||||||
|
|
||||||
|
}
|
||||||
.notification-button-box {
|
.notification-button-box {
|
||||||
border-top: 1px solid var(--color-border);
|
border-top: 1px solid var(--color-border);
|
||||||
padding-top: 6px;
|
padding-top: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification-button {
|
.notification-button {
|
||||||
background-color: #444444;
|
background-color: #333333;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
border-radius: 6px;
|
|
||||||
margin-right: 6px;
|
margin-right: 6px;
|
||||||
font-family: var(--text-font-mono);
|
font-size: 12px;
|
||||||
font-size: 13px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification-icon-button {
|
.notification-icon-button {
|
||||||
@@ -40,3 +74,20 @@
|
|||||||
.notification-button:hover {
|
.notification-button:hover {
|
||||||
background-color: #555555;
|
background-color: #555555;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification-app-icon {
|
||||||
|
padding-right: 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-app-name {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-header {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
13
src/app.cpp
13
src/app.cpp
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "services/dbus/notification.hpp"
|
#include "connection/dbus/notification.hpp"
|
||||||
#include "services/dbus/mpris.hpp"
|
#include "connection/dbus/mpris.hpp"
|
||||||
|
#include "services/notificationController.hpp"
|
||||||
#include "services/textureCache.hpp"
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
App::App() {
|
App::App() {
|
||||||
@@ -11,7 +12,13 @@ App::App() {
|
|||||||
this->setupServices();
|
this->setupServices();
|
||||||
this->hyprlandService = HyprlandService::getInstance();
|
this->hyprlandService = HyprlandService::getInstance();
|
||||||
this->notificationService = std::make_shared<NotificationService>();
|
this->notificationService = std::make_shared<NotificationService>();
|
||||||
this->mprisController = std::make_shared<MprisController>();
|
this->mprisController = MprisController::getInstance();
|
||||||
|
|
||||||
|
auto notificationController = NotificationController::getInstance();
|
||||||
|
this->mprisController->signal_mpris_updated().connect(
|
||||||
|
[notificationController](const MprisPlayer2Message &msg) {
|
||||||
|
notificationController->showSpotifyNotification(msg);
|
||||||
|
});
|
||||||
|
|
||||||
app->signal_activate().connect([&]() {
|
app->signal_activate().connect([&]() {
|
||||||
auto display = Gdk::Display::get_default();
|
auto display = Gdk::Display::get_default();
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ Popover::Popover(const std::string icon, std::string name): Button(icon) {
|
|||||||
|
|
||||||
set_name(name);
|
set_name(name);
|
||||||
|
|
||||||
popover = new Gtk::Popover();
|
this->add_css_class("material-icons");
|
||||||
|
|
||||||
|
popover = std::make_unique<Gtk::Popover>();
|
||||||
popover->set_parent(*this);
|
popover->set_parent(*this);
|
||||||
popover->set_autohide(true);
|
popover->set_autohide(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Popover::~Popover() {
|
Popover::~Popover() = default;
|
||||||
delete popover;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Popover::on_toggle_window() {
|
void Popover::on_toggle_window() {
|
||||||
if (popover->get_visible()) {
|
if (popover->get_visible()) {
|
||||||
|
|||||||
0
src/connection/dbus/dbus.cpp
Normal file
0
src/connection/dbus/dbus.cpp
Normal file
410
src/connection/dbus/mpris.cpp
Normal file
410
src/connection/dbus/mpris.cpp
Normal file
@@ -0,0 +1,410 @@
|
|||||||
|
#include "connection/dbus/mpris.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
|
||||||
|
#include "giomm/dbusconnection.h"
|
||||||
|
#include "giomm/dbusproxy.h"
|
||||||
|
|
||||||
|
std::shared_ptr<MprisController> MprisController::getInstance() {
|
||||||
|
static std::shared_ptr<MprisController> instance = std::shared_ptr<MprisController>(new MprisController());
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<MprisController> MprisController::createForPlayer(const std::string &bus_name) {
|
||||||
|
return std::shared_ptr<MprisController>(new MprisController(bus_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
MprisController::MprisController() {
|
||||||
|
connect_session_async(sigc::mem_fun(*this, &MprisController::on_bus_connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
MprisController::MprisController(const std::string &bus_name)
|
||||||
|
: m_player_bus_name(bus_name) {
|
||||||
|
connect_session_async(sigc::mem_fun(*this, &MprisController::on_bus_connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> MprisController::get_registered_players() const {
|
||||||
|
return std::vector<std::string>(registeredPlayers.begin(), registeredPlayers.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(const MprisPlayer2Message &)> &MprisController::signal_mpris_updated() {
|
||||||
|
return mprisUpdatedSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(MprisController::PlaybackStatus)> &MprisController::signal_playback_status_changed() {
|
||||||
|
return playbackStatusChangedSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(int64_t)> &MprisController::signal_playback_position_changed() {
|
||||||
|
return playbackPositionChangedSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(bool)> &MprisController::signal_can_seek_changed() {
|
||||||
|
return canSeekChangedSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(const std::string &)> &MprisController::signal_player_registered() {
|
||||||
|
return playerRegisteredSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigc::signal<void(const std::string &)> &MprisController::signal_player_deregistered() {
|
||||||
|
return playerDeregisteredSignal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
if (!result) {
|
||||||
|
spdlog::error("DBus Connection Error: null async result");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
connection = Gio::DBus::Connection::get_finish(result);
|
||||||
|
|
||||||
|
if (!m_dbus_proxy) {
|
||||||
|
m_dbus_proxy = Gio::DBus::Proxy::create_sync(
|
||||||
|
connection,
|
||||||
|
"org.freedesktop.DBus",
|
||||||
|
"/org/freedesktop/DBus",
|
||||||
|
"org.freedesktop.DBus");
|
||||||
|
|
||||||
|
if (m_dbus_proxy) {
|
||||||
|
m_dbus_proxy->signal_signal().connect(
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_dbus_signal));
|
||||||
|
|
||||||
|
try {
|
||||||
|
auto list_names_result = m_dbus_proxy->call_sync("ListNames");
|
||||||
|
auto names_variant = Glib::VariantBase::cast_dynamic<
|
||||||
|
Glib::Variant<std::vector<Glib::ustring>>>(list_names_result.get_child(0));
|
||||||
|
|
||||||
|
for (const auto &name : names_variant.get()) {
|
||||||
|
const std::string bus_name = name;
|
||||||
|
if (bus_name.rfind("org.mpris.MediaPlayer2.", 0) == 0) {
|
||||||
|
handle_player_registered(bus_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("DBus ListNames Error: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("DBus Connection Error: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::on_dbus_signal(const Glib::ustring &,
|
||||||
|
const Glib::ustring &signal_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
|
if (signal_name != "NameOwnerChanged") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto name_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(parameters.get_child(0));
|
||||||
|
auto old_owner_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(parameters.get_child(1));
|
||||||
|
auto new_owner_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(parameters.get_child(2));
|
||||||
|
|
||||||
|
const std::string bus_name = name_var.get();
|
||||||
|
if (bus_name.rfind("org.mpris.MediaPlayer2.", 0) != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool had_owner = !old_owner_var.get().empty();
|
||||||
|
const bool has_owner = !new_owner_var.get().empty();
|
||||||
|
|
||||||
|
if (!had_owner && has_owner) {
|
||||||
|
handle_player_registered(bus_name);
|
||||||
|
} else if (had_owner && !has_owner) {
|
||||||
|
handle_player_deregistered(bus_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::handle_player_registered(const std::string &bus_name) {
|
||||||
|
spdlog::info("MPRIS player registered: {}", bus_name);
|
||||||
|
|
||||||
|
registeredPlayers.insert(bus_name);
|
||||||
|
|
||||||
|
if (bus_name == m_player_bus_name && !m_proxy && connection) {
|
||||||
|
try {
|
||||||
|
m_proxy = Gio::DBus::Proxy::create_sync(
|
||||||
|
connection,
|
||||||
|
m_player_bus_name,
|
||||||
|
"/org/mpris/MediaPlayer2",
|
||||||
|
"org.mpris.MediaPlayer2.Player");
|
||||||
|
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->signal_properties_changed().connect(
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_properties_changed));
|
||||||
|
signalNotification();
|
||||||
|
emit_cached_playback_status();
|
||||||
|
emit_cached_position();
|
||||||
|
emit_cached_can_seek();
|
||||||
|
}
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("DBus Connection Error: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerRegisteredSignal.emit(bus_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::handle_player_deregistered(const std::string &bus_name) {
|
||||||
|
spdlog::info("MPRIS player deregistered: {}", bus_name);
|
||||||
|
|
||||||
|
registeredPlayers.erase(bus_name);
|
||||||
|
|
||||||
|
if (bus_name == m_player_bus_name) {
|
||||||
|
m_proxy.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
playerDeregisteredSignal.emit(bus_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::signalNotification() {
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::VariantBase metadata_var;
|
||||||
|
m_proxy->get_cached_property(metadata_var, "Metadata");
|
||||||
|
|
||||||
|
if (!metadata_var) {
|
||||||
|
spdlog::info("No metadata available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!metadata_var.is_of_type(Glib::VariantType("a{sv}"))) {
|
||||||
|
spdlog::error("Unexpected metadata type.");
|
||||||
|
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, artwork_url, track_id;
|
||||||
|
std::vector<std::string> artist;
|
||||||
|
|
||||||
|
if (metadata_map.count("xesam:title")) {
|
||||||
|
const auto &title_base = metadata_map["xesam:title"];
|
||||||
|
if (title_base.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
auto title_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(title_base);
|
||||||
|
title = title_var.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata_map.count("xesam:artist")) {
|
||||||
|
const 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()) {
|
||||||
|
for (const auto &a : artists) {
|
||||||
|
artist.push_back(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (artist_var.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
auto artist_str = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(artist_var);
|
||||||
|
artist.push_back(artist_str.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata_map.count("mpris:artUrl")) {
|
||||||
|
const auto &art_base = metadata_map["mpris:artUrl"];
|
||||||
|
if (art_base.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
auto art_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(art_base);
|
||||||
|
artwork_url = art_var.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata_map.count("mpris:trackid")) {
|
||||||
|
const auto &track_base = metadata_map["mpris:trackid"];
|
||||||
|
if (track_base.is_of_type(Glib::VariantType("o"))) {
|
||||||
|
auto track_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(track_base);
|
||||||
|
track_id = track_var.get();
|
||||||
|
} else if (track_base.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
auto track_var = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(track_base);
|
||||||
|
track_id = track_var.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t length_us = 0;
|
||||||
|
if (metadata_map.count("mpris:length")) {
|
||||||
|
const auto &length_base = metadata_map["mpris:length"];
|
||||||
|
if (length_base.is_of_type(Glib::VariantType("x"))) {
|
||||||
|
auto length_var = Glib::VariantBase::cast_dynamic<Glib::Variant<gint64>>(length_base);
|
||||||
|
length_us = static_cast<int64_t>(length_var.get());
|
||||||
|
} else if (length_base.is_of_type(Glib::VariantType("t"))) {
|
||||||
|
auto length_var = Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(length_base);
|
||||||
|
length_us = static_cast<int64_t>(length_var.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MprisPlayer2Message mpris;
|
||||||
|
mpris.title = StringHelper::trimToSize(title, 30);
|
||||||
|
mpris.artist = artist;
|
||||||
|
mpris.artwork_url = artwork_url;
|
||||||
|
mpris.track_id = track_id;
|
||||||
|
mpris.play_pause = [this]() { this->toggle_play(); };
|
||||||
|
mpris.next = [this]() { this->next_song(); };
|
||||||
|
mpris.previous = [this]() { this->previous_song(); };
|
||||||
|
mpris.length_ms = length_us / 1000; // Convert microseconds to milliseconds
|
||||||
|
mprisUpdatedSignal.emit(mpris);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::emit_cached_playback_status() {
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::VariantBase status_var;
|
||||||
|
m_proxy->get_cached_property(status_var, "PlaybackStatus");
|
||||||
|
if (!status_var || !status_var.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto status = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(status_var).get();
|
||||||
|
auto parsedStatusIt = playbackStatusMap.find(static_cast<std::string>(status));
|
||||||
|
if (parsedStatusIt != playbackStatusMap.end()) {
|
||||||
|
currentPlaybackStatus = parsedStatusIt->second;
|
||||||
|
playbackStatusChangedSignal.emit(currentPlaybackStatus);
|
||||||
|
} else {
|
||||||
|
spdlog::error("Unknown playback status: {}", status.raw());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::emit_cached_position() {
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::VariantBase position_var;
|
||||||
|
m_proxy->get_cached_property(position_var, "Position");
|
||||||
|
if (!position_var || !position_var.is_of_type(Glib::VariantType("x"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto position = Glib::VariantBase::cast_dynamic<Glib::Variant<gint64>>(position_var).get();
|
||||||
|
playbackPositionChangedSignal.emit(static_cast<int64_t>(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::emit_cached_can_seek() {
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::VariantBase can_seek_var;
|
||||||
|
m_proxy->get_cached_property(can_seek_var, "CanSeek");
|
||||||
|
if (!can_seek_var || !can_seek_var.is_of_type(Glib::VariantType("b"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto can_seek = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(can_seek_var).get();
|
||||||
|
canSeekChangedSignal.emit(can_seek);
|
||||||
|
}
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
signalNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed_properties.find("PlaybackStatus") != changed_properties.end()) {
|
||||||
|
auto status_var = changed_properties.at("PlaybackStatus");
|
||||||
|
if (status_var.is_of_type(Glib::VariantType("s"))) {
|
||||||
|
auto status = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(status_var).get();
|
||||||
|
spdlog::info("Playback Status changed to: {}", status.raw());
|
||||||
|
auto parsedStatusIt = playbackStatusMap.find(static_cast<std::string>(status));
|
||||||
|
|
||||||
|
if (parsedStatusIt != playbackStatusMap.end()) {
|
||||||
|
currentPlaybackStatus = parsedStatusIt->second;
|
||||||
|
playbackStatusChangedSignal.emit(currentPlaybackStatus);
|
||||||
|
} else {
|
||||||
|
spdlog::error("Unknown playback status: {}", status.raw());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed_properties.find("Position") != changed_properties.end()) {
|
||||||
|
auto position_var = changed_properties.at("Position");
|
||||||
|
if (position_var.is_of_type(Glib::VariantType("x"))) {
|
||||||
|
auto position = Glib::VariantBase::cast_dynamic<Glib::Variant<gint64>>(position_var).get();
|
||||||
|
spdlog::info("Position changed to: {}", position);
|
||||||
|
playbackPositionChangedSignal.emit(static_cast<int64_t>(position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed_properties.find("CanSeek") != changed_properties.end()) {
|
||||||
|
auto can_seek_var = changed_properties.at("CanSeek");
|
||||||
|
if (can_seek_var.is_of_type(Glib::VariantType("b"))) {
|
||||||
|
auto can_seek = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(can_seek_var).get();
|
||||||
|
canSeekChangedSignal.emit(can_seek);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::previous_song() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("Previous");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::toggle_play() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("PlayPause");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::pause() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("Pause");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::next_song() {
|
||||||
|
if (m_proxy) {
|
||||||
|
m_proxy->call("Next");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::emit_seeked(int64_t position_us) {
|
||||||
|
spdlog::debug("Seeking to position: {}", position_us);
|
||||||
|
|
||||||
|
if (!m_proxy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Glib::VariantContainerBase params = Glib::VariantContainerBase::create_tuple(
|
||||||
|
Glib::Variant<gint64>::create(position_us));
|
||||||
|
|
||||||
|
m_proxy->call("Seek", params);
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("Error seeking: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::set_position(const std::string &track_id, int64_t position_us) {
|
||||||
|
if (!m_proxy || track_id.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Glib::VariantContainerBase params = Glib::VariantContainerBase::create_tuple({
|
||||||
|
Glib::Variant<Glib::DBusObjectPathString>::create(track_id),
|
||||||
|
Glib::Variant<gint64>::create(position_us)
|
||||||
|
});
|
||||||
|
|
||||||
|
m_proxy->call("SetPosition", params);
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("Error setting position: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
200
src/connection/dbus/notification.cpp
Normal file
200
src/connection/dbus/notification.cpp
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
#include "connection/dbus/notification.hpp"
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "services/notificationController.hpp"
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
#include "glibconfig.h"
|
||||||
|
|
||||||
|
void NotificationService::onBusAcquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name) {
|
||||||
|
spdlog::info("Acquired bus name: {}", name.raw());
|
||||||
|
|
||||||
|
auto introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml);
|
||||||
|
|
||||||
|
// Register the object at the standard path
|
||||||
|
connection->register_object(
|
||||||
|
"/org/freedesktop/Notifications",
|
||||||
|
introspection_data->lookup_interface("org.freedesktop.Notifications"),
|
||||||
|
getMessageInterfaceVTable());
|
||||||
|
}
|
||||||
|
|
||||||
|
const Gio::DBus::InterfaceVTable &NotificationService::getMessageInterfaceVTable() {
|
||||||
|
static Gio::DBus::InterfaceVTable vtable(
|
||||||
|
sigc::mem_fun(*this, &NotificationService::on_method_call));
|
||||||
|
return vtable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
|
||||||
|
const Glib::ustring &,
|
||||||
|
const Glib::ustring &,
|
||||||
|
const Glib::ustring &,
|
||||||
|
const Glib::ustring &method_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters,
|
||||||
|
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
|
||||||
|
|
||||||
|
if (method_name == "Notify") {
|
||||||
|
handle_notify(parameters, invocation);
|
||||||
|
} else if (method_name == "GetCapabilities") {
|
||||||
|
auto caps = std::vector<Glib::ustring>{
|
||||||
|
"body", "actions", "actions-icons", "persistence", "icon-static"};
|
||||||
|
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
||||||
|
Glib::Variant<std::vector<Glib::ustring>>::create(caps)));
|
||||||
|
} else if (method_name == "GetServerInformation") {
|
||||||
|
invocation->return_value(Glib::VariantContainerBase::create_tuple({Glib::Variant<Glib::ustring>::create("MyGtkmmNotifier"),
|
||||||
|
Glib::Variant<Glib::ustring>::create("Custom"),
|
||||||
|
Glib::Variant<Glib::ustring>::create("1.0"),
|
||||||
|
Glib::Variant<Glib::ustring>::create("1.2")}));
|
||||||
|
} else {
|
||||||
|
// Handle other methods or return error
|
||||||
|
invocation->return_value(Glib::VariantContainerBase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::handle_notify(const Glib::VariantContainerBase ¶meters,
|
||||||
|
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
|
||||||
|
|
||||||
|
Glib::VariantBase app_name_var, replaces_id_var, app_icon_var, summary_var, body_var, actions_var, hints_var, timeout_var;
|
||||||
|
parameters.get_child(app_name_var, 0);
|
||||||
|
parameters.get_child(replaces_id_var, 1);
|
||||||
|
parameters.get_child(app_icon_var, 2);
|
||||||
|
parameters.get_child(summary_var, 3);
|
||||||
|
parameters.get_child(body_var, 4);
|
||||||
|
parameters.get_child(actions_var, 5);
|
||||||
|
parameters.get_child(hints_var, 6);
|
||||||
|
parameters.get_child(timeout_var, 7);
|
||||||
|
|
||||||
|
Glib::ustring app_name = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(app_name_var).get();
|
||||||
|
guint32 replaces_id = Glib::VariantBase::cast_dynamic<Glib::Variant<guint32>>(replaces_id_var).get();
|
||||||
|
Glib::ustring app_icon = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(app_icon_var).get();
|
||||||
|
Glib::ustring summary = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(summary_var).get();
|
||||||
|
Glib::ustring body = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(body_var).get();
|
||||||
|
std::vector<Glib::ustring> actions = Glib::VariantBase::cast_dynamic<Glib::Variant<std::vector<Glib::ustring>>>(actions_var).get();
|
||||||
|
std::map<Glib::ustring, Glib::VariantBase> hints = Glib::VariantBase::cast_dynamic<Glib::Variant<std::map<Glib::ustring, Glib::VariantBase>>>(hints_var).get();
|
||||||
|
gint32 expire_timeout = Glib::VariantBase::cast_dynamic<Glib::Variant<gint32>>(timeout_var).get();
|
||||||
|
|
||||||
|
spdlog::info("Notification Received: {} - {}", summary.raw(), body.raw());
|
||||||
|
|
||||||
|
NotifyMessage notify;
|
||||||
|
notify.app_name = app_name;
|
||||||
|
notify.replaces_id = replaces_id;
|
||||||
|
notify.app_icon = app_icon;
|
||||||
|
notify.summary = static_cast<std::string>(summary);
|
||||||
|
notify.body = static_cast<std::string>(body);
|
||||||
|
notify.actionInvoked = std::make_shared<bool>(false);
|
||||||
|
|
||||||
|
std::vector<std::string> actions_converted;
|
||||||
|
actions_converted.reserve(actions.size());
|
||||||
|
for (ulong i = 0; i < actions.size(); i += 2) {
|
||||||
|
auto name = static_cast<std::string>(actions[i]);
|
||||||
|
auto label = static_cast<std::string>(actions[i + 1]);
|
||||||
|
|
||||||
|
if (name == "default") {
|
||||||
|
label = "Open";
|
||||||
|
}
|
||||||
|
|
||||||
|
actions_converted.push_back(name);
|
||||||
|
actions_converted.push_back(label);
|
||||||
|
}
|
||||||
|
notify.actions = actions_converted;
|
||||||
|
|
||||||
|
for (const auto &[key, value] : hints) {
|
||||||
|
if (key == "urgency") {
|
||||||
|
if (value.is_of_type(Glib::VariantType("y"))) {
|
||||||
|
auto urgency = Glib::VariantBase::cast_dynamic<Glib::Variant<guint8>>(value).get();
|
||||||
|
notify.urgency = static_cast<NotificationUrgency>(urgency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == "image-data") {
|
||||||
|
Glib::VariantBase image_value = value;
|
||||||
|
if (image_value.is_of_type(Glib::VariantType("v"))) {
|
||||||
|
try {
|
||||||
|
image_value = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::VariantBase>>(image_value).get();
|
||||||
|
} catch (const std::bad_cast &) {
|
||||||
|
spdlog::warn("Failed to unwrap image-data variant");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image_value.is_of_type(Glib::VariantType("(iiibiiay)"))) {
|
||||||
|
// This is a raw data image format which describes width, height, rowstride, has alpha,
|
||||||
|
// bits per sample, channels and image data respectively.
|
||||||
|
try {
|
||||||
|
auto image_data_variant = Glib::VariantBase::cast_dynamic<
|
||||||
|
Glib::Variant<std::tuple<gint32, gint32, gint32, bool, gint32, gint32, std::vector<guint8>>>>(image_value);
|
||||||
|
auto [width, height, rowstride, has_alpha, bits_per_sample, channels, data] = image_data_variant.get();
|
||||||
|
(void)channels;
|
||||||
|
auto pixbuf = Gdk::Pixbuf::create_from_data(
|
||||||
|
data.data(),
|
||||||
|
Gdk::Colorspace::RGB,
|
||||||
|
has_alpha,
|
||||||
|
bits_per_sample,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
rowstride);
|
||||||
|
notify.imageData = pixbuf;
|
||||||
|
} catch (const std::bad_cast &e) {
|
||||||
|
spdlog::warn("Failed to decode image-data hint: {}", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == "image-path") {
|
||||||
|
try {
|
||||||
|
auto image_path_variant = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(value);
|
||||||
|
auto image_path = static_cast<std::string>(image_path_variant.get());
|
||||||
|
|
||||||
|
try {
|
||||||
|
auto pixbuf = Gdk::Pixbuf::create_from_file(image_path);
|
||||||
|
notify.imageData = pixbuf;
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
spdlog::warn("Failed to load image from path {}: {}", image_path, e.what());
|
||||||
|
}
|
||||||
|
} catch (const std::bad_cast &e) {
|
||||||
|
spdlog::warn("Failed to decode image-path hint: {}", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notify.expire_timeout = expire_timeout;
|
||||||
|
|
||||||
|
guint id = notificationIdCounter++;
|
||||||
|
if (app_name == "image-copy" ) {
|
||||||
|
NotificationController::getInstance()->showCopyNotification(notify);
|
||||||
|
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
||||||
|
Glib::Variant<guint>::create(id)));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_name == "ocr-copy") {
|
||||||
|
NotificationController::getInstance()->showCopyNotification(notify);
|
||||||
|
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
||||||
|
Glib::Variant<guint>::create(id)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_name == "Thunderbird") {
|
||||||
|
notify.expire_timeout = 10000; // 10 seconds for email notifications
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the callback to emit ActionInvoked on D-Bus
|
||||||
|
Glib::RefPtr<Gio::DBus::Connection> dbus_conn = invocation->get_connection();
|
||||||
|
notify.on_action = [dbus_conn, id](const std::string &action_id) {
|
||||||
|
try {
|
||||||
|
dbus_conn->emit_signal(
|
||||||
|
"/org/freedesktop/Notifications",
|
||||||
|
"org.freedesktop.Notifications",
|
||||||
|
"ActionInvoked",
|
||||||
|
"", // destination bus name (empty for broadcast)
|
||||||
|
Glib::VariantContainerBase::create_tuple({Glib::Variant<guint>::create(id),
|
||||||
|
Glib::Variant<Glib::ustring>::create(action_id)}));
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
spdlog::error("Failed to emit ActionInvoked: {}", e.what());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
NotificationController::getInstance()->showNotificationOnAllMonitors(notify);
|
||||||
|
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
||||||
|
Glib::Variant<guint>::create(id)));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "services/tray.hpp"
|
#include "connection/dbus/tray.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <giomm/dbusactiongroup.h>
|
#include <giomm/dbusactiongroup.h>
|
||||||
#include <giomm/dbusownname.h>
|
#include <giomm/dbusownname.h>
|
||||||
#include <giomm/menumodel.h>
|
#include <giomm/menumodel.h>
|
||||||
#include <iostream>
|
#include <spdlog/spdlog.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -143,9 +143,9 @@ void on_simple_call_finished(GObject *source, GAsyncResult *res,
|
|||||||
const bool isUnknownMethod =
|
const bool isUnknownMethod =
|
||||||
(error->domain == G_DBUS_ERROR && error->code == G_DBUS_ERROR_UNKNOWN_METHOD);
|
(error->domain == G_DBUS_ERROR && error->code == G_DBUS_ERROR_UNKNOWN_METHOD);
|
||||||
if (!(data && data->ignoreUnknownMethod && isUnknownMethod)) {
|
if (!(data && data->ignoreUnknownMethod && isUnknownMethod)) {
|
||||||
std::cerr << "[TrayService] "
|
spdlog::error("[TrayService] {} failed: {}",
|
||||||
<< (data ? data->debugLabel : std::string("D-Bus call"))
|
(data ? data->debugLabel : std::string("D-Bus call")),
|
||||||
<< " failed: " << error->message << std::endl;
|
error->message);
|
||||||
}
|
}
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
}
|
}
|
||||||
@@ -277,19 +277,16 @@ void TrayService::start() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
ensure_gio_init();
|
||||||
Gio::init();
|
|
||||||
} catch (const Glib::Error &) {
|
|
||||||
// Already initialised; ignore.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nodeInfo) {
|
if (!nodeInfo) {
|
||||||
try {
|
try {
|
||||||
nodeInfo =
|
nodeInfo =
|
||||||
Gio::DBus::NodeInfo::create_for_xml(kWatcherIntrospection);
|
Gio::DBus::NodeInfo::create_for_xml(kWatcherIntrospection);
|
||||||
} catch (const Glib::Error &err) {
|
} catch (const Glib::Error &err) {
|
||||||
std::cerr << "[TrayService] Failed to parse introspection data: "
|
spdlog::error(
|
||||||
<< err.what() << std::endl;
|
"[TrayService] Failed to parse introspection data: {}",
|
||||||
|
err.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,9 +574,9 @@ bool TrayService::activate_menu_item(const std::string &id, int itemId,
|
|||||||
const guint32 nowMs = static_cast<guint32>(g_get_real_time() / 1000);
|
const guint32 nowMs = static_cast<guint32>(g_get_real_time() / 1000);
|
||||||
const guint32 ts = timestampMs ? timestampMs : nowMs;
|
const guint32 ts = timestampMs ? timestampMs : nowMs;
|
||||||
|
|
||||||
std::cerr << "[TrayService] MenuEvent id=" << id << " item=" << itemId
|
spdlog::debug(
|
||||||
<< " x=" << x << " y=" << y << " button=" << button
|
"[TrayService] MenuEvent id={} item={} x={} y={} button={} tsMs={}",
|
||||||
<< " tsMs=" << ts << std::endl;
|
id, itemId, x, y, button, ts);
|
||||||
|
|
||||||
// dbusmenu Event signature: (i s v u)
|
// dbusmenu Event signature: (i s v u)
|
||||||
// Some handlers (e.g., media players) look for both "timestamp" and
|
// Some handlers (e.g., media players) look for both "timestamp" and
|
||||||
@@ -637,8 +634,7 @@ void TrayService::on_bus_acquired(
|
|||||||
|
|
||||||
auto interface_info = nodeInfo->lookup_interface(kWatcherInterface);
|
auto interface_info = nodeInfo->lookup_interface(kWatcherInterface);
|
||||||
if (!interface_info) {
|
if (!interface_info) {
|
||||||
std::cerr << "[TrayService] Missing interface info for watcher."
|
spdlog::error("[TrayService] Missing interface info for watcher.");
|
||||||
<< std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,8 +642,9 @@ void TrayService::on_bus_acquired(
|
|||||||
registrationId = connection->register_object(kWatcherObjectPath,
|
registrationId = connection->register_object(kWatcherObjectPath,
|
||||||
interface_info, vtable);
|
interface_info, vtable);
|
||||||
} catch (const Glib::Error &err) {
|
} catch (const Glib::Error &err) {
|
||||||
std::cerr << "[TrayService] Failed to register watcher object: "
|
spdlog::error(
|
||||||
<< err.what() << std::endl;
|
"[TrayService] Failed to register watcher object: {}",
|
||||||
|
err.what());
|
||||||
registrationId = 0;
|
registrationId = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -747,8 +744,8 @@ void TrayService::register_item(const Glib::ustring &sender,
|
|||||||
|
|
||||||
ParsedService parsed = parse_service_identifier(sender, service);
|
ParsedService parsed = parse_service_identifier(sender, service);
|
||||||
if (parsed.busName.empty() || parsed.objectPath.empty()) {
|
if (parsed.busName.empty() || parsed.objectPath.empty()) {
|
||||||
std::cerr << "[TrayService] Invalid service registration: " << service
|
spdlog::warn("[TrayService] Invalid service registration: {}",
|
||||||
<< std::endl;
|
service);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -845,8 +842,9 @@ void TrayService::on_refresh_finished_static(GObject *source, GAsyncResult *res,
|
|||||||
g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
|
g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
if (error) {
|
if (error) {
|
||||||
std::cerr << "[TrayService] Failed to query properties for "
|
spdlog::error(
|
||||||
<< data->id << ": " << error->message << std::endl;
|
"[TrayService] Failed to query properties for {}: {}",
|
||||||
|
data->id, error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1240,8 +1238,8 @@ Glib::RefPtr<Gdk::Paintable> TrayService::parse_icon_pixmap(GVariant *variant) {
|
|||||||
try {
|
try {
|
||||||
return Gdk::Texture::create_for_pixbuf(pixbuf);
|
return Gdk::Texture::create_for_pixbuf(pixbuf);
|
||||||
} catch (const Glib::Error &err) {
|
} catch (const Glib::Error &err) {
|
||||||
std::cerr << "[TrayService] Failed to create texture: " << err.what()
|
spdlog::error("[TrayService] Failed to create texture: {}",
|
||||||
<< std::endl;
|
err.what());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
119
src/connection/httpConnection.cpp
Normal file
119
src/connection/httpConnection.cpp
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include "connection/httpConnection.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
size_t write_to_string(void *contents, size_t size, size_t nmemb, void *userp) {
|
||||||
|
size_t total = size * nmemb;
|
||||||
|
auto *buffer = static_cast<std::string *>(userp);
|
||||||
|
buffer->append(static_cast<char *>(contents), total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string trim(std::string value) {
|
||||||
|
auto not_space = [](unsigned char c) { return std::isspace(c) == 0; };
|
||||||
|
value.erase(value.begin(),
|
||||||
|
std::find_if(value.begin(), value.end(), not_space));
|
||||||
|
value.erase(std::find_if(value.rbegin(), value.rend(), not_space).base(),
|
||||||
|
value.end());
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t header_to_map(char *buffer, size_t size, size_t nitems, void *userdata) {
|
||||||
|
size_t total = size * nitems;
|
||||||
|
auto *header_map = static_cast<std::map<std::string, std::string> *>(userdata);
|
||||||
|
|
||||||
|
std::string line(buffer, total);
|
||||||
|
auto colon = line.find(':');
|
||||||
|
if (colon != std::string::npos) {
|
||||||
|
auto key = trim(line.substr(0, colon));
|
||||||
|
auto value = trim(line.substr(colon + 1));
|
||||||
|
if (!key.empty()) {
|
||||||
|
header_map->insert_or_assign(std::move(key), std::move(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse HttpConnection::get(const std::string &url,
|
||||||
|
const std::map<std::string, std::string> &headers,
|
||||||
|
long timeout_ms) {
|
||||||
|
return performRequest("GET", url, std::string(), headers, std::string(), timeout_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse HttpConnection::post(const std::string &url,
|
||||||
|
const std::string &body,
|
||||||
|
const std::map<std::string, std::string> &headers,
|
||||||
|
const std::string &content_type,
|
||||||
|
long timeout_ms) {
|
||||||
|
return performRequest("POST", url, body, headers, content_type, timeout_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse HttpConnection::performRequest(const std::string &method,
|
||||||
|
const std::string &url,
|
||||||
|
const std::string &body,
|
||||||
|
const std::map<std::string, std::string> &headers,
|
||||||
|
const std::string &content_type,
|
||||||
|
long timeout_ms) {
|
||||||
|
HttpResponse response;
|
||||||
|
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if (!curl) {
|
||||||
|
response.error = "curl_easy_init failed";
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response.body);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_to_map);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &response.headers);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "bar/1.0");
|
||||||
|
|
||||||
|
if (timeout_ms > 0) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "POST") {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(body.size()));
|
||||||
|
} else {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct curl_slist *header_list = nullptr;
|
||||||
|
for (const auto &pair : headers) {
|
||||||
|
std::string header = pair.first + ": " + pair.second;
|
||||||
|
header_list = curl_slist_append(header_list, header.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "POST" && !content_type.empty()) {
|
||||||
|
std::string content_header = "Content-Type: " + content_type;
|
||||||
|
header_list = curl_slist_append(header_list, content_header.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header_list) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = curl_easy_perform(curl);
|
||||||
|
if (result != CURLE_OK) {
|
||||||
|
response.error = curl_easy_strerror(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response.status_code);
|
||||||
|
|
||||||
|
if (header_list) {
|
||||||
|
curl_slist_free_all(header_list);
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
#include "services/dbus/mpris.hpp"
|
|
||||||
#include "services/dbus/messages.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();
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
#include "services/dbus/notification.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "services/notificationController.hpp"
|
|
||||||
|
|
||||||
#include "glib.h"
|
|
||||||
#include "glibconfig.h"
|
|
||||||
|
|
||||||
void NotificationService::onBusAcquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name) {
|
|
||||||
std::cout << "Acquired bus name: " << name << std::endl;
|
|
||||||
|
|
||||||
auto introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml);
|
|
||||||
|
|
||||||
// Register the object at the standard path
|
|
||||||
connection->register_object(
|
|
||||||
"/org/freedesktop/Notifications",
|
|
||||||
introspection_data->lookup_interface("org.freedesktop.Notifications"),
|
|
||||||
getMessageInterfaceVTable());
|
|
||||||
}
|
|
||||||
|
|
||||||
const Gio::DBus::InterfaceVTable &NotificationService::getMessageInterfaceVTable() {
|
|
||||||
static Gio::DBus::InterfaceVTable vtable(
|
|
||||||
sigc::mem_fun(*this, &NotificationService::on_method_call));
|
|
||||||
return vtable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationService::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
|
|
||||||
const Glib::ustring &,
|
|
||||||
const Glib::ustring &,
|
|
||||||
const Glib::ustring &,
|
|
||||||
const Glib::ustring &method_name,
|
|
||||||
const Glib::VariantContainerBase ¶meters,
|
|
||||||
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
|
|
||||||
|
|
||||||
if (method_name == "Notify") {
|
|
||||||
handle_notify(parameters, invocation);
|
|
||||||
} else if (method_name == "GetCapabilities") {
|
|
||||||
auto caps = std::vector<Glib::ustring>{"body"};
|
|
||||||
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
|
||||||
Glib::Variant<std::vector<Glib::ustring>>::create(caps)));
|
|
||||||
} else if (method_name == "GetServerInformation") {
|
|
||||||
invocation->return_value(Glib::VariantContainerBase::create_tuple({Glib::Variant<Glib::ustring>::create("MyGtkmmNotifier"),
|
|
||||||
Glib::Variant<Glib::ustring>::create("Custom"),
|
|
||||||
Glib::Variant<Glib::ustring>::create("1.0"),
|
|
||||||
Glib::Variant<Glib::ustring>::create("1.2")}));
|
|
||||||
} else {
|
|
||||||
// Handle other methods or return error
|
|
||||||
invocation->return_value(Glib::VariantContainerBase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationService::handle_notify(const Glib::VariantContainerBase ¶meters,
|
|
||||||
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation) {
|
|
||||||
|
|
||||||
Glib::VariantBase app_name_var, replaces_id_var, app_icon_var, summary_var, body_var, actions_var, hints_var, timeout_var;
|
|
||||||
parameters.get_child(app_name_var, 0);
|
|
||||||
parameters.get_child(replaces_id_var, 1);
|
|
||||||
parameters.get_child(app_icon_var, 2);
|
|
||||||
parameters.get_child(summary_var, 3);
|
|
||||||
parameters.get_child(body_var, 4);
|
|
||||||
parameters.get_child(actions_var, 5);
|
|
||||||
parameters.get_child(hints_var, 6);
|
|
||||||
parameters.get_child(timeout_var, 7);
|
|
||||||
|
|
||||||
Glib::ustring app_name = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(app_name_var).get();
|
|
||||||
guint32 replaces_id = Glib::VariantBase::cast_dynamic<Glib::Variant<guint32>>(replaces_id_var).get();
|
|
||||||
Glib::ustring app_icon = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(app_icon_var).get();
|
|
||||||
Glib::ustring summary = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(summary_var).get();
|
|
||||||
Glib::ustring body = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(body_var).get();
|
|
||||||
std::vector<Glib::ustring> actions = Glib::VariantBase::cast_dynamic<Glib::Variant<std::vector<Glib::ustring>>>(actions_var).get();
|
|
||||||
// std::map<Glib::ustring, Glib::VariantBase> hints = Glib::VariantBase::cast_dynamic<Glib::Variant<std::map<Glib::ustring, Glib::VariantBase>>>(hints_var).get();
|
|
||||||
gint32 expire_timeout = Glib::VariantBase::cast_dynamic<Glib::Variant<gint32>>(timeout_var).get();
|
|
||||||
|
|
||||||
std::cout << "Notification Received: " << summary << " - " << body << std::endl;
|
|
||||||
|
|
||||||
NotifyMessage notify;
|
|
||||||
notify.app_name = app_name;
|
|
||||||
notify.replaces_id = replaces_id;
|
|
||||||
notify.app_icon = app_icon;
|
|
||||||
notify.summary = summary;
|
|
||||||
notify.body = body;
|
|
||||||
|
|
||||||
std::vector<std::string> actions_converted;
|
|
||||||
actions_converted.reserve(actions.size());
|
|
||||||
for (const auto &a : actions) {
|
|
||||||
actions_converted.emplace_back(static_cast<std::string>(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
notify.actions = actions_converted;
|
|
||||||
|
|
||||||
// notify.hints = hints;
|
|
||||||
|
|
||||||
notify.expire_timeout = expire_timeout;
|
|
||||||
|
|
||||||
guint id = notificationIdCounter++;
|
|
||||||
// Set up the callback to emit ActionInvoked on D-Bus
|
|
||||||
Glib::RefPtr<Gio::DBus::Connection> dbus_conn = invocation->get_connection();
|
|
||||||
notify.on_action = [dbus_conn, id](const std::string &action_id) {
|
|
||||||
try {
|
|
||||||
dbus_conn->emit_signal(
|
|
||||||
"/org/freedesktop/Notifications",
|
|
||||||
"org.freedesktop.Notifications",
|
|
||||||
"ActionInvoked",
|
|
||||||
"", // destination bus name (empty for broadcast)
|
|
||||||
Glib::VariantContainerBase::create_tuple({Glib::Variant<guint>::create(id),
|
|
||||||
Glib::Variant<Glib::ustring>::create(action_id)}));
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
std::cerr << "Failed to emit ActionInvoked: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
NotificationController::getInstance()->showNotificationOnAllMonitors(notify);
|
|
||||||
invocation->return_value(Glib::VariantContainerBase::create_tuple(
|
|
||||||
Glib::Variant<guint>::create(id)));
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <glib-unix.h>
|
#include <glib-unix.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -16,9 +15,11 @@
|
|||||||
|
|
||||||
#include "gtkmm/box.h"
|
#include "gtkmm/box.h"
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
HyprlandService::HyprlandService() {
|
HyprlandService::HyprlandService() {
|
||||||
init();
|
init();
|
||||||
bindSocket();
|
this->bindHyprlandSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::init() {
|
void HyprlandService::init() {
|
||||||
@@ -83,12 +84,12 @@ void HyprlandService::init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::bindSocket() {
|
void HyprlandService::bindHyprlandSocket() {
|
||||||
std::string socketPath = HyprSocketHelper::getHyprlandSocketPath();
|
std::string socketPath = HyprSocketHelper::getHyprlandSocketPath();
|
||||||
|
|
||||||
socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (socketFd == -1) {
|
if (socketFd == -1) {
|
||||||
std::cerr << "[Hyprland] Failed to create socket" << std::endl;
|
spdlog::error("[Hyprland] Failed to create socket");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,16 +99,17 @@ void HyprlandService::bindSocket() {
|
|||||||
std::strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
std::strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
if (connect(socketFd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) == -1) {
|
if (connect(socketFd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) == -1) {
|
||||||
std::cerr << "[Hyprland] Failed to connect to " << socketPath << std::endl;
|
spdlog::error("[Hyprland] Failed to connect to {}", socketPath);
|
||||||
close(socketFd);
|
close(socketFd);
|
||||||
socketFd = -1;
|
socketFd = -1;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSource *source = g_unix_fd_source_new(socketFd, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR));
|
auto socket_conditions = static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||||
|
GSource *source = g_unix_fd_source_new(socketFd, socket_conditions);
|
||||||
|
|
||||||
auto onSocketEvent = [](gint fd, GIOCondition , gpointer user_data) -> gboolean {
|
auto onSocketEvent = [](gint fd, GIOCondition, gpointer user_data) -> gboolean {
|
||||||
HyprlandService *self = static_cast<HyprlandService *>(user_data);
|
HyprlandService *self = static_cast<HyprlandService *>(user_data);
|
||||||
auto messages = SocketHelper::parseSocketMessage(fd, ">>");
|
auto messages = SocketHelper::parseSocketMessage(fd, ">>");
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ void HyprlandService::bindSocket() {
|
|||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
};
|
};
|
||||||
|
|
||||||
g_source_set_callback(source, reinterpret_cast<GSourceFunc>(reinterpret_cast<void*>(+onSocketEvent)), this, nullptr);
|
g_source_set_callback(source, reinterpret_cast<GSourceFunc>(reinterpret_cast<void *>(+onSocketEvent)), this, nullptr);
|
||||||
g_source_attach(source, g_main_context_default());
|
g_source_attach(source, g_main_context_default());
|
||||||
g_source_unref(source);
|
g_source_unref(source);
|
||||||
}
|
}
|
||||||
@@ -168,14 +170,38 @@ void HyprlandService::onMonitorRemoved(std::string monitorName) {
|
|||||||
|
|
||||||
monitorPtr->monitorWorkspaces.clear();
|
monitorPtr->monitorWorkspaces.clear();
|
||||||
monitorPtr->bar->close();
|
monitorPtr->bar->close();
|
||||||
|
monitorPtr->bar = nullptr;
|
||||||
|
|
||||||
this->monitors.erase(monitorName);
|
this->monitors.erase(monitorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void HyprlandService::onMonitorAdded(std::string monitorName) {
|
void HyprlandService::onMoveWindow(std::string windowData) {
|
||||||
// // this->signalMonitorAdded.emit();
|
auto parts = StringHelper::split(windowData, ',');
|
||||||
// }
|
std::string addr = "0x" + parts[0];
|
||||||
|
int newWorkspaceId = std::stoi(parts[1]);
|
||||||
|
|
||||||
|
if (this->clients.find(addr) == this->clients.end()) {
|
||||||
|
spdlog::warn("[Hyprland] onMoveWindow: Client {} not found", addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto clientPtr = this->clients[addr];
|
||||||
|
int oldWorkspaceId = clientPtr->workspaceId;
|
||||||
|
|
||||||
|
auto oldWorkspacePtr = workspaces[oldWorkspaceId];
|
||||||
|
oldWorkspacePtr->state->clients.erase(addr);
|
||||||
|
bool wasUrgent = oldWorkspacePtr->state->urgentClients.erase(addr) > 0;
|
||||||
|
refreshIndicator(oldWorkspacePtr);
|
||||||
|
|
||||||
|
clientPtr->workspaceId = newWorkspaceId;
|
||||||
|
|
||||||
|
auto newWorkspacePtr = workspaces[newWorkspaceId];
|
||||||
|
newWorkspacePtr->state->clients[addr] = clientPtr;
|
||||||
|
if (wasUrgent) {
|
||||||
|
newWorkspacePtr->state->urgentClients.insert(addr);
|
||||||
|
}
|
||||||
|
refreshIndicator(newWorkspacePtr);
|
||||||
|
}
|
||||||
|
|
||||||
void HyprlandService::onOpenWindow(std::string windowData) {
|
void HyprlandService::onOpenWindow(std::string windowData) {
|
||||||
auto parts = StringHelper::split(windowData, ',');
|
auto parts = StringHelper::split(windowData, ',');
|
||||||
@@ -214,7 +240,6 @@ void HyprlandService::onCloseWindow(std::string windowData) {
|
|||||||
|
|
||||||
void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
|
void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
|
||||||
if (socketEventTypeMap.find(message.eventType) == socketEventTypeMap.end()) {
|
if (socketEventTypeMap.find(message.eventType) == socketEventTypeMap.end()) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,6 +275,10 @@ void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
|
|||||||
this->onMonitorRemoved(eventData);
|
this->onMonitorRemoved(eventData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MOVE_WINDOW: {
|
||||||
|
this->onMoveWindow(eventData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HyprlandService::onUrgent(std::string windowAddress) {
|
void HyprlandService::onUrgent(std::string windowAddress) {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "services/notificationController.hpp"
|
#include "services/notificationController.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "services/dbus/messages.hpp"
|
#include "connection/dbus/messages.hpp"
|
||||||
#include "widgets/notification/notification.hpp"
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
#include "widgets/notification/copyNotification.hpp"
|
||||||
|
#include "widgets/notification/notificationWindow.hpp"
|
||||||
#include "widgets/notification/spotifyNotification.hpp"
|
#include "widgets/notification/spotifyNotification.hpp"
|
||||||
|
|
||||||
#include "gdkmm/display.h"
|
#include "gdkmm/display.h"
|
||||||
#include "glibmm/main.h"
|
#include "sigc++/adaptors/bind.h"
|
||||||
|
|
||||||
|
|
||||||
#define DEFAULT_NOTIFICATION_TIMEOUT 4000
|
|
||||||
|
|
||||||
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
|
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
|
||||||
|
|
||||||
@@ -37,34 +37,120 @@ NotificationController::NotificationController() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris) {
|
|
||||||
for (const auto &monitor : this->activeMonitors) {
|
|
||||||
auto notification = std::make_shared<SpotifyNotification>(monitor, mpris);
|
|
||||||
notification->show();
|
|
||||||
|
|
||||||
Glib::signal_timeout().connect([notification]() {
|
|
||||||
notification->close();
|
|
||||||
return false; // Don't repeat
|
|
||||||
},
|
|
||||||
DEFAULT_NOTIFICATION_TIMEOUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify) {
|
void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify) {
|
||||||
|
uint64_t id = this->globalNotificationId++;
|
||||||
|
std::vector<std::shared_ptr<BaseNotification>> notifications;
|
||||||
|
|
||||||
for (const auto &monitor : this->activeMonitors) {
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
auto notification = std::make_shared<NotificationWindow>(monitor, notify);
|
auto notification = std::make_shared<NotificationWindow>(id, monitor, notify);
|
||||||
|
notifications.push_back(notification);
|
||||||
|
|
||||||
auto timeout = notify.expire_timeout;
|
auto timeout = notify.expire_timeout;
|
||||||
notification->show();
|
notification->show();
|
||||||
// -1 means use default timeout, 0 means never expire
|
// -1 means use default timeout, 0 means never expire
|
||||||
if (timeout <= 0) {
|
if (timeout < 0) {
|
||||||
timeout = DEFAULT_NOTIFICATION_TIMEOUT; // default to 3 seconds
|
timeout = DEFAULT_NOTIFICATION_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::signal_timeout().connect([notification]() {
|
notification->signal_close.connect([this, id = notification->getNotificationId()](int) {
|
||||||
notification->close();
|
closeNotification(id);
|
||||||
return false; // Don't repeat
|
});
|
||||||
},
|
|
||||||
timeout);
|
notification->signal_hover_changed.connect([this, id = notification->getNotificationId()](bool hovered) {
|
||||||
|
updateHoverState(id, hovered);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (timeout == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
notification->startAutoClose(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->activeNotifications[id] = notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationController::showCopyNotification(NotifyMessage notify) {
|
||||||
|
std::vector<std::shared_ptr<BaseNotification>> notifications;
|
||||||
|
uint64_t id = this->globalNotificationId++;
|
||||||
|
|
||||||
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
|
auto notification = std::make_shared<CopyNotification>(id, monitor, notify);
|
||||||
|
|
||||||
|
notification->show();
|
||||||
|
notifications.push_back(notification);
|
||||||
|
|
||||||
|
notification->signal_close.connect([this, id = notification->getNotificationId()](int) {
|
||||||
|
closeNotification(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
notification->signal_hover_changed.connect([this, id = notification->getNotificationId()](bool hovered) {
|
||||||
|
updateHoverState(id, hovered);
|
||||||
|
});
|
||||||
|
notification->startAutoClose(DEFAULT_NOTIFICATION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->activeNotifications[id] = notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris) {
|
||||||
|
std::vector<std::shared_ptr<BaseNotification>> notifications;
|
||||||
|
uint64_t id = this->globalNotificationId++;
|
||||||
|
|
||||||
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
|
auto notification = std::make_shared<SpotifyNotification>(id, monitor, mpris);
|
||||||
|
|
||||||
|
notification->show();
|
||||||
|
notifications.push_back(notification);
|
||||||
|
|
||||||
|
notification->signal_close.connect([this, id = notification->getNotificationId()](int) {
|
||||||
|
closeNotification(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
notification->signal_hover_changed.connect([this, id = notification->getNotificationId()](bool hovered) {
|
||||||
|
updateHoverState(id, hovered);
|
||||||
|
});
|
||||||
|
|
||||||
|
notification->startAutoClose(DEFAULT_NOTIFICATION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->activeNotifications[id] = notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationController::updateHoverState(uint64_t notificationId, bool isHovered) {
|
||||||
|
if (this->activeNotifications.find(notificationId) == this->activeNotifications.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int &count = this->hoverCounts[notificationId];
|
||||||
|
if (isHovered) {
|
||||||
|
count += 1;
|
||||||
|
} else {
|
||||||
|
count = std::max(0, count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ¬ifications = this->activeNotifications[notificationId];
|
||||||
|
if (count > 0) {
|
||||||
|
for (const auto ¬ification : notifications) {
|
||||||
|
notification->pauseAutoClose();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const auto ¬ification : notifications) {
|
||||||
|
notification->resumeAutoClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationController::closeNotification(uint64_t notificationId) {
|
||||||
|
if (this->activeNotifications.find(notificationId) == this->activeNotifications.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto notifications = this->activeNotifications[notificationId];
|
||||||
|
for (const auto ¬ification : notifications) {
|
||||||
|
notification->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->activeNotifications.erase(notificationId);
|
||||||
|
this->hoverCounts.erase(notificationId);
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include "widgets/controlCenter.hpp"
|
|
||||||
|
|
||||||
ControlCenter::ControlCenter(std::string icon, std::string name)
|
|
||||||
: Popover(icon, name) {
|
|
||||||
this->popover->set_size_request(200, -1);
|
|
||||||
set_popover_child(this->container);
|
|
||||||
|
|
||||||
}
|
|
||||||
101
src/widgets/controlCenter/controlCenter.cpp
Normal file
101
src/widgets/controlCenter/controlCenter.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#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(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->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->contentStack.add(this->controlCenterContainer, "controls", "Controls");
|
||||||
|
this->contentStack.add(this->weatherWidget, "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);
|
||||||
|
}
|
||||||
|
|
||||||
269
src/widgets/controlCenter/mediaControl.cpp
Normal file
269
src/widgets/controlCenter/mediaControl.cpp
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
#include "widgets/controlCenter/mediaControl.hpp"
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
|
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, -1);
|
||||||
|
this->set_hexpand(false);
|
||||||
|
this->set_vexpand(false);
|
||||||
|
this->add_css_class("control-center-player-container");
|
||||||
|
|
||||||
|
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_size_request(-1, 120);
|
||||||
|
this->topContainer.set_vexpand(false);
|
||||||
|
this->topContainer.set_hexpand(true);
|
||||||
|
|
||||||
|
this->infoContainer.set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
this->infoContainer.set_valign(Gtk::Align::END);
|
||||||
|
this->infoContainer.set_halign(Gtk::Align::START);
|
||||||
|
this->infoContainer.append(this->artistLabel);
|
||||||
|
this->infoContainer.append(this->titleLabel);
|
||||||
|
this->topContainer.add_overlay(this->infoContainer);
|
||||||
|
|
||||||
|
this->artistLabel.set_halign(Gtk::Align::START);
|
||||||
|
this->titleLabel.set_halign(Gtk::Align::START);
|
||||||
|
|
||||||
|
this->seekBarContainer.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||||
|
this->seekBarContainer.set_vexpand(false);
|
||||||
|
this->seekBarContainer.set_hexpand(true);
|
||||||
|
this->seekBarContainer.set_halign(Gtk::Align::CENTER);
|
||||||
|
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);
|
||||||
|
this->totalTimeLabel.set_text("0:00");
|
||||||
|
this->totalTimeLabel.set_halign(Gtk::Align::END);
|
||||||
|
this->seekBar.set_range(0, 100);
|
||||||
|
this->seekBar.set_value(0);
|
||||||
|
this->seekBar.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||||
|
this->seekBar.set_draw_value(false);
|
||||||
|
this->seekBar.set_hexpand(true);
|
||||||
|
this->seekBar.set_halign(Gtk::Align::CENTER);
|
||||||
|
this->seekBar.add_css_class("control-center-seek-bar");
|
||||||
|
|
||||||
|
this->seekBar.signal_value_changed().connect([this]() {
|
||||||
|
if (this->suppressSeekSignal || this->totalLengthUs <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double fraction = this->seekBar.get_value() / 100.0;
|
||||||
|
int64_t new_position_us =
|
||||||
|
static_cast<int64_t>(fraction * static_cast<double>(this->totalLengthUs));
|
||||||
|
if (new_position_us == this->currentPositionUs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this->currentTrackId.empty()) {
|
||||||
|
this->mprisController->set_position(this->currentTrackId, new_position_us);
|
||||||
|
if (this->playbackStatus != MprisController::PlaybackStatus::Playing) {
|
||||||
|
this->schedulePauseAfterSeek();
|
||||||
|
}
|
||||||
|
} else if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||||
|
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||||
|
this->resetSeekTimer(new_position_us);
|
||||||
|
} else {
|
||||||
|
this->setCurrentPosition(new_position_us);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this->bottomContainer.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||||
|
this->bottomContainer.set_vexpand(false);
|
||||||
|
this->bottomContainer.set_hexpand(false);
|
||||||
|
this->bottomContainer.set_valign(Gtk::Align::START);
|
||||||
|
this->bottomContainer.set_homogeneous(true);
|
||||||
|
this->topContainer.set_vexpand(false);
|
||||||
|
this->topContainer.set_hexpand(true);
|
||||||
|
this->bottomContainer.append(this->previousButton);
|
||||||
|
this->bottomContainer.append(this->playPauseButton);
|
||||||
|
this->bottomContainer.append(this->nextButton);
|
||||||
|
|
||||||
|
this->previousButton.set_label("\u23EE"); // Previous track symbol
|
||||||
|
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("button");
|
||||||
|
this->playPauseButton.add_css_class("material-icons");
|
||||||
|
this->nextButton.set_label("\u23ED"); // Next track symbol
|
||||||
|
this->nextButton.add_css_class("button");
|
||||||
|
this->nextButton.add_css_class("material-icons");
|
||||||
|
this->previousButton.signal_clicked().connect([this]() {
|
||||||
|
this->mprisController->previous_song();
|
||||||
|
});
|
||||||
|
this->playPauseButton.signal_clicked().connect([this]() {
|
||||||
|
this->mprisController->toggle_play();
|
||||||
|
});
|
||||||
|
this->nextButton.signal_clicked().connect([this]() {
|
||||||
|
this->mprisController->next_song();
|
||||||
|
});
|
||||||
|
|
||||||
|
this->mprisController->signal_mpris_updated().connect(
|
||||||
|
sigc::mem_fun(*this, &MediaControlWidget::onSpotifyMprisUpdated));
|
||||||
|
|
||||||
|
this->mprisController->signal_playback_status_changed().connect(
|
||||||
|
[this](MprisController::PlaybackStatus status) {
|
||||||
|
this->onRunningStateChanged(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
this->mprisController->signal_playback_position_changed().connect(
|
||||||
|
[this](int64_t position_us) {
|
||||||
|
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-player-artist-label");
|
||||||
|
this->titleLabel.set_text("Song Title");
|
||||||
|
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()) {
|
||||||
|
artistText = StringHelper::trimToSize(message.artist[0], 30);
|
||||||
|
}
|
||||||
|
this->artistLabel.set_text(artistText);
|
||||||
|
this->titleLabel.set_text(message.title);
|
||||||
|
const bool trackChanged = !this->currentTrackId.empty() && this->currentTrackId != message.track_id;
|
||||||
|
this->currentTrackId = message.track_id;
|
||||||
|
|
||||||
|
if (trackChanged) {
|
||||||
|
this->currentPositionUs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
|
||||||
|
this->backgroundImage.set_paintable(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setTotalLength(message.length_ms * 1000);
|
||||||
|
this->setCurrentPosition(this->currentPositionUs);
|
||||||
|
|
||||||
|
if (this->playbackStatus == MprisController::PlaybackStatus::Playing) {
|
||||||
|
this->resetSeekTimer(this->currentPositionUs);
|
||||||
|
} else if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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->suppressSeekSignal = true;
|
||||||
|
this->seekBar.set_value(fraction * 100);
|
||||||
|
this->suppressSeekSignal = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::schedulePauseAfterSeek() {
|
||||||
|
Glib::signal_timeout().connect_once([this]() {
|
||||||
|
if (this->playbackStatus != MprisController::PlaybackStatus::Playing) {
|
||||||
|
this->mprisController->pause();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MediaControlWidget::onSeekTick() {
|
||||||
|
if (totalLengthUs <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t nextPosition = currentPositionUs + 1000000;
|
||||||
|
if (nextPosition > totalLengthUs) {
|
||||||
|
nextPosition = totalLengthUs;
|
||||||
|
}
|
||||||
|
setCurrentPosition(nextPosition);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onRunningStateChanged(MprisController::PlaybackStatus status) {
|
||||||
|
this->playbackStatus = status;
|
||||||
|
switch (status) {
|
||||||
|
case MprisController::PlaybackStatus::Playing:
|
||||||
|
this->onPlay();
|
||||||
|
break;
|
||||||
|
case MprisController::PlaybackStatus::Paused:
|
||||||
|
this->onPause();
|
||||||
|
break;
|
||||||
|
case MprisController::PlaybackStatus::Stopped:
|
||||||
|
this->onStop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onPlay() {
|
||||||
|
this->playPauseButton.set_label("\u23F8"); // Pause symbol
|
||||||
|
// strart seek timer if not already running
|
||||||
|
this->resetSeekTimer(currentPositionUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onPause() {
|
||||||
|
this->playPauseButton.set_label("\u23F5"); // Play symbol
|
||||||
|
if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onStop() {
|
||||||
|
this->playPauseButton.set_label("\u23F9"); // stop symbol
|
||||||
|
if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
this->setCurrentPosition(0);
|
||||||
|
}
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
#include "widgets/notification/baseNotification.hpp"
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "helpers/system.hpp"
|
#include "helpers/system.hpp"
|
||||||
|
|
||||||
#include "gdkmm/monitor.h"
|
#include "gdkmm/monitor.h"
|
||||||
|
#include "glibmm/main.h"
|
||||||
|
#include "glibmm/object.h"
|
||||||
#include "gtk4-layer-shell.h"
|
#include "gtk4-layer-shell.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
#include "gtkmm/cssprovider.h"
|
#include "gtkmm/cssprovider.h"
|
||||||
|
#include "gtkmm/eventcontrollermotion.h"
|
||||||
|
#include "gtkmm/gestureclick.h"
|
||||||
|
|
||||||
BaseNotification::BaseNotification(std::shared_ptr<Gdk::Monitor> monitor) {
|
BaseNotification::BaseNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor) {
|
||||||
ensure_notification_css_loaded();
|
ensure_notification_css_loaded();
|
||||||
set_default_size(300, 100);
|
set_default_size(350, 100);
|
||||||
gtk_layer_init_for_window(gobj());
|
gtk_layer_init_for_window(gobj());
|
||||||
gtk_layer_set_monitor(gobj(), monitor->gobj());
|
gtk_layer_set_monitor(gobj(), monitor->gobj());
|
||||||
gtk_layer_set_layer(gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
gtk_layer_set_layer(gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
||||||
@@ -20,6 +26,96 @@ BaseNotification::BaseNotification(std::shared_ptr<Gdk::Monitor> monitor) {
|
|||||||
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
||||||
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, 2);
|
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, 2);
|
||||||
add_css_class("notification-popup");
|
add_css_class("notification-popup");
|
||||||
|
|
||||||
|
this->set_hexpand(false);
|
||||||
|
this->set_vexpand(false);
|
||||||
|
|
||||||
|
this->notificationId = notificationId;
|
||||||
|
|
||||||
|
auto window_click = Gtk::GestureClick::create();
|
||||||
|
window_click->set_button(GDK_BUTTON_PRIMARY);
|
||||||
|
window_click->set_exclusive(false);
|
||||||
|
window_click->signal_released().connect([this](int, double x, double y) {
|
||||||
|
Gtk::Widget *picked = this->pick(x, y, Gtk::PickFlags::DEFAULT);
|
||||||
|
for (auto *w = picked; w != nullptr; w = w->get_parent()) {
|
||||||
|
if (dynamic_cast<Gtk::Button *>(w) != nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
});
|
||||||
|
add_controller(window_click);
|
||||||
|
|
||||||
|
auto window_motion = Gtk::EventControllerMotion::create();
|
||||||
|
window_motion->signal_enter().connect([this](double, double) {
|
||||||
|
signal_hover_changed.emit(true);
|
||||||
|
pause_auto_close();
|
||||||
|
});
|
||||||
|
window_motion->signal_leave().connect([this]() {
|
||||||
|
signal_hover_changed.emit(false);
|
||||||
|
resume_auto_close();
|
||||||
|
});
|
||||||
|
add_controller(window_motion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::pauseAutoClose() {
|
||||||
|
pause_auto_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::resumeAutoClose() {
|
||||||
|
resume_auto_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::startAutoClose(int timeoutMs) {
|
||||||
|
if (timeoutMs <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
autoCloseRemainingMs = timeoutMs;
|
||||||
|
autoClosePaused = false;
|
||||||
|
start_auto_close_timeout(timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::start_auto_close_timeout(int timeoutMs) {
|
||||||
|
if (autoCloseConnection.connected()) {
|
||||||
|
autoCloseConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
autoCloseDeadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs);
|
||||||
|
autoCloseConnection = Glib::signal_timeout().connect([this]() {
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
return false; // Don't repeat
|
||||||
|
},
|
||||||
|
timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::pause_auto_close() {
|
||||||
|
if (autoClosePaused || autoCloseRemainingMs <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (autoCloseConnection.connected()) {
|
||||||
|
autoCloseConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
auto remaining = std::chrono::duration_cast<std::chrono::milliseconds>(autoCloseDeadline - now).count();
|
||||||
|
autoCloseRemainingMs = static_cast<int>(std::max<int64_t>(0, remaining));
|
||||||
|
autoClosePaused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseNotification::resume_auto_close() {
|
||||||
|
if (!autoClosePaused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
autoClosePaused = false;
|
||||||
|
if (autoCloseRemainingMs <= 0) {
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
start_auto_close_timeout(autoCloseRemainingMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseNotification::ensure_notification_css_loaded() {
|
void BaseNotification::ensure_notification_css_loaded() {
|
||||||
|
|||||||
162
src/widgets/notification/copyNotification.cpp
Normal file
162
src/widgets/notification/copyNotification.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
#include "widgets/notification/copyNotification.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include "glibmm/datetime.h"
|
||||||
|
#include "glibmm/fileutils.h"
|
||||||
|
#include "glibmm/miscutils.h"
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/image.h"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
|
// todo refactor out later
|
||||||
|
|
||||||
|
void copyToClipboard(const std::string &text) {
|
||||||
|
auto clipboard = Gdk::Display::get_default()->get_clipboard();
|
||||||
|
clipboard->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void copyToClipboard(const Glib::RefPtr<Gdk::Pixbuf> &image) {
|
||||||
|
auto clipboard = Gdk::Display::get_default()->get_clipboard();
|
||||||
|
|
||||||
|
// Wrap the pixbuf in a Value so GTK knows how to handle it
|
||||||
|
Glib::Value<Glib::RefPtr<Gdk::Pixbuf>> value;
|
||||||
|
value.init(Glib::Value<Glib::RefPtr<Gdk::Pixbuf>>::value_type());
|
||||||
|
value.set(image);
|
||||||
|
|
||||||
|
// Create a content provider from the value
|
||||||
|
auto provider = Gdk::ContentProvider::create(value);
|
||||||
|
|
||||||
|
spdlog::info("Copying image to clipboard with content provider");
|
||||||
|
clipboard->set_content(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createDirectoryIfNotExists(const std::string &dirpath) {
|
||||||
|
if (!Glib::file_test(dirpath, Glib::FileTest::IS_DIR)) {
|
||||||
|
try {
|
||||||
|
g_mkdir_with_parents(dirpath.c_str(), 0755);
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
spdlog::error("Failed to create directory {}: {}", dirpath, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveImageToFile(const Glib::RefPtr<Gdk::Pixbuf> &image, const std::string &filepath, const std::string &filename) {
|
||||||
|
try {
|
||||||
|
createDirectoryIfNotExists(filepath);
|
||||||
|
std::string fullpath = filepath + "/" + filename;
|
||||||
|
image->save(fullpath, "png");
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
spdlog::error("Failed to save image to file {}: {}", filepath, e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyNotification::CopyNotification(uint64_t id,
|
||||||
|
std::shared_ptr<Gdk::Monitor> monitor,
|
||||||
|
NotifyMessage notify)
|
||||||
|
: BaseNotification(id, monitor) {
|
||||||
|
|
||||||
|
this->set_child(this->mainBox);
|
||||||
|
this->mainBox.set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
|
||||||
|
if (notify.imageData) {
|
||||||
|
this->createImageNotification(notify);
|
||||||
|
} else if (!notify.body.empty()) {
|
||||||
|
this->createTextNotification(notify);
|
||||||
|
} else {
|
||||||
|
spdlog::warn("CopyNotification created without valid image or text data.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyNotification::createImageNotification(NotifyMessage notify) {
|
||||||
|
this->setupTitle("image copied");
|
||||||
|
this->type = CopyType::IMAGE;
|
||||||
|
this->copiedImage = notify.imageData.value();
|
||||||
|
|
||||||
|
auto contentBox = Gtk::make_managed<Gtk::Box>();
|
||||||
|
contentBox->set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
contentBox->set_margin(0);
|
||||||
|
auto imageWidget = Gtk::make_managed<Gtk::Image>(this->copiedImage);
|
||||||
|
contentBox->append(*imageWidget);
|
||||||
|
imageWidget->set_pixel_size(300);
|
||||||
|
|
||||||
|
auto buttonBox = Gtk::make_managed<Gtk::Box>();
|
||||||
|
buttonBox->set_spacing(10);
|
||||||
|
|
||||||
|
// material icons unicode
|
||||||
|
auto saveToClipboardLabel = Gtk::make_managed<Gtk::Label>("\uF0EA"); // content copy icon
|
||||||
|
auto saveToFileLabel = Gtk::make_managed<Gtk::Label>("\uF1C5"); // save icon
|
||||||
|
|
||||||
|
auto saveToClipboardButton = Gtk::make_managed<Gtk::Button>();
|
||||||
|
saveToClipboardButton->set_child(*saveToClipboardLabel);
|
||||||
|
saveToClipboardButton->signal_clicked().connect([this]() {
|
||||||
|
copyToClipboard(this->copiedImage);
|
||||||
|
spdlog::info("Copied image to clipboard");
|
||||||
|
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
});
|
||||||
|
saveToClipboardButton->set_tooltip_text("Copy to Clipboard");
|
||||||
|
saveToClipboardButton->add_css_class("notification-button");
|
||||||
|
saveToClipboardButton->add_css_class("notification-icon-button");
|
||||||
|
|
||||||
|
auto saveToFileButton = Gtk::make_managed<Gtk::Button>();
|
||||||
|
saveToFileButton->set_child(*saveToFileLabel);
|
||||||
|
saveToFileButton->signal_clicked().connect([this]() {
|
||||||
|
// xdg-pic/screenshot // use env
|
||||||
|
auto xdgPicturesDir = Glib::get_user_special_dir(Glib::UserDirectory::PICTURES);
|
||||||
|
auto dateStamp = Glib::DateTime::create_now_local().format("%Y%m%d_%H%M%S");
|
||||||
|
auto filepath = xdgPicturesDir + "/screenshot" ;
|
||||||
|
auto filename = dateStamp + ".png";
|
||||||
|
saveImageToFile(this->copiedImage, filepath, filename);
|
||||||
|
spdlog::info("Saved image to {}", filepath.c_str());
|
||||||
|
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
});
|
||||||
|
saveToFileButton->set_tooltip_text("Save to File");
|
||||||
|
saveToFileButton->add_css_class("notification-button");
|
||||||
|
saveToFileButton->add_css_class("notification-icon-button");
|
||||||
|
|
||||||
|
buttonBox->append(*saveToClipboardButton);
|
||||||
|
buttonBox->append(*saveToFileButton);
|
||||||
|
contentBox->append(*buttonBox);
|
||||||
|
|
||||||
|
this->mainBox.append(*contentBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyNotification::createTextNotification(NotifyMessage notify) {
|
||||||
|
this->setupTitle("text copied");
|
||||||
|
this->type = CopyType::TEXT;
|
||||||
|
this->copiedText = notify.body;
|
||||||
|
auto contentBox = Gtk::make_managed<Gtk::Box>();
|
||||||
|
contentBox->set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
auto textLabel = Gtk::make_managed<Gtk::Label>(this->copiedText);
|
||||||
|
textLabel->set_margin_bottom(10);
|
||||||
|
contentBox->append(*textLabel);
|
||||||
|
|
||||||
|
auto copyToClipboardButton = Gtk::make_managed<Gtk::Button>();
|
||||||
|
auto copyToClipboardLabel = Gtk::make_managed<Gtk::Label>("\uF0EA"); // content copy icon
|
||||||
|
copyToClipboardButton->set_child(*copyToClipboardLabel);
|
||||||
|
copyToClipboardButton->signal_clicked().connect([this]() {
|
||||||
|
copyToClipboard(this->copiedText);
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
});
|
||||||
|
copyToClipboardButton->set_tooltip_text("Copy to Clipboard");
|
||||||
|
copyToClipboardButton->add_css_class("notification-icon-button");
|
||||||
|
copyToClipboardButton->add_css_class("notification-button");
|
||||||
|
copyToClipboardButton->set_hexpand(false);
|
||||||
|
copyToClipboardButton->set_halign(Gtk::Align::START);
|
||||||
|
contentBox->append(*copyToClipboardButton);
|
||||||
|
|
||||||
|
this->mainBox.append(*contentBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyNotification::setupTitle(std::string title) {
|
||||||
|
this->title = title;
|
||||||
|
|
||||||
|
auto titleLabel = Gtk::make_managed<Gtk::Label>(this->title);
|
||||||
|
titleLabel->set_margin_bottom(8);
|
||||||
|
this->mainBox.append(*titleLabel);
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#include "widgets/notification/notification.hpp"
|
|
||||||
|
|
||||||
#include "gtkmm/box.h"
|
|
||||||
#include "gtkmm/button.h"
|
|
||||||
#include "gtkmm/label.h"
|
|
||||||
|
|
||||||
NotificationWindow::NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage notify) : BaseNotification(monitor) {
|
|
||||||
set_title(notify.summary);
|
|
||||||
|
|
||||||
// Main vertical box
|
|
||||||
auto vbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 8);
|
|
||||||
|
|
||||||
// Summary label
|
|
||||||
auto summary_label = Gtk::make_managed<Gtk::Label>("<b>" + notify.summary + "</b>");
|
|
||||||
summary_label->set_use_markup(true);
|
|
||||||
summary_label->set_halign(Gtk::Align::START);
|
|
||||||
vbox->append(*summary_label);
|
|
||||||
|
|
||||||
// Body label
|
|
||||||
auto body_label = Gtk::make_managed<Gtk::Label>(notify.body);
|
|
||||||
body_label->set_use_markup(true);
|
|
||||||
body_label->set_halign(Gtk::Align::START);
|
|
||||||
vbox->append(*body_label);
|
|
||||||
|
|
||||||
// If actions exist, add buttons
|
|
||||||
if (!notify.actions.empty()) {
|
|
||||||
auto actions_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 6);
|
|
||||||
for (size_t i = 0; i + 1 < notify.actions.size(); i += 2) {
|
|
||||||
std::string action_id = notify.actions[i];
|
|
||||||
std::string action_label = notify.actions[i + 1];
|
|
||||||
|
|
||||||
auto btn = Gtk::make_managed<Gtk::Button>();
|
|
||||||
btn->set_label(action_label);
|
|
||||||
|
|
||||||
btn->add_css_class("notification-button");
|
|
||||||
btn->signal_clicked().connect([this, action_id, cb = notify.on_action]() {
|
|
||||||
if (cb) {
|
|
||||||
cb(action_id);
|
|
||||||
this->close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
actions_box->append(*btn);
|
|
||||||
}
|
|
||||||
vbox->append(*actions_box);
|
|
||||||
}
|
|
||||||
|
|
||||||
set_child(*vbox);
|
|
||||||
}
|
|
||||||
104
src/widgets/notification/notificationWindow.cpp
Normal file
104
src/widgets/notification/notificationWindow.cpp
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#include "widgets/notification/notificationWindow.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/gestureclick.h"
|
||||||
|
#include "gtkmm/image.h"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
|
NotificationWindow::NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage notify) : BaseNotification(notificationId, monitor) {
|
||||||
|
set_title(notify.summary);
|
||||||
|
|
||||||
|
|
||||||
|
// Main vertical box
|
||||||
|
auto vbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 8);
|
||||||
|
vbox->set_halign(Gtk::Align::FILL);
|
||||||
|
|
||||||
|
switch (notify.urgency) {
|
||||||
|
case NotificationUrgency::CRITICAL:
|
||||||
|
add_css_class("notification-critical");
|
||||||
|
break;
|
||||||
|
case NotificationUrgency::NORMAL:
|
||||||
|
add_css_class("notification-normal");
|
||||||
|
break;
|
||||||
|
case NotificationUrgency::LOW:
|
||||||
|
add_css_class("notification-low");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto header_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||||
|
header_box->set_halign(Gtk::Align::START);
|
||||||
|
header_box->add_css_class("notification-header");
|
||||||
|
header_box->set_hexpand(true);
|
||||||
|
header_box->set_halign(Gtk::Align::FILL);
|
||||||
|
|
||||||
|
if (notify.imageData) {
|
||||||
|
auto img = Gtk::make_managed<Gtk::Image>(*(notify.imageData));
|
||||||
|
img->set_pixel_size(16);
|
||||||
|
img->set_halign(Gtk::Align::START);
|
||||||
|
img->set_valign(Gtk::Align::CENTER);
|
||||||
|
img->add_css_class("notification-app-icon");
|
||||||
|
header_box->append(*img);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto app_label = Gtk::make_managed<Gtk::Label>(StringHelper::trimToSize(notify.app_name, 24));
|
||||||
|
app_label->set_halign(Gtk::Align::START);
|
||||||
|
app_label->set_wrap(false);
|
||||||
|
app_label->add_css_class("notification-app-name");
|
||||||
|
header_box->append(*app_label);
|
||||||
|
vbox->append(*header_box);
|
||||||
|
|
||||||
|
// Summary label
|
||||||
|
auto summary_label = Gtk::make_managed<Gtk::Label>("<b>" + StringHelper::trimToSize(notify.summary, 20) + "</b>");
|
||||||
|
summary_label->set_use_markup(true);
|
||||||
|
summary_label->set_halign(Gtk::Align::START);
|
||||||
|
summary_label->set_wrap(true);
|
||||||
|
vbox->append(*summary_label);
|
||||||
|
|
||||||
|
auto body_label = Gtk::make_managed<Gtk::Label>(StringHelper::trimToSize(notify.body, 100));
|
||||||
|
body_label->set_use_markup(true);
|
||||||
|
body_label->set_halign(Gtk::Align::START);
|
||||||
|
body_label->set_wrap(true);
|
||||||
|
vbox->append(*body_label);
|
||||||
|
|
||||||
|
// If actions exist, add buttons
|
||||||
|
if (!notify.actions.empty()) {
|
||||||
|
auto actions_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 6);
|
||||||
|
for (size_t i = 0; i + 1 < notify.actions.size(); i += 2) {
|
||||||
|
std::string action_id = notify.actions[i];
|
||||||
|
std::string action_label = notify.actions[i + 1];
|
||||||
|
|
||||||
|
auto btn = Gtk::make_managed<Gtk::Button>();
|
||||||
|
btn->set_label(action_label);
|
||||||
|
|
||||||
|
btn->add_css_class("notification-button");
|
||||||
|
|
||||||
|
switch (notify.urgency) {
|
||||||
|
case NotificationUrgency::CRITICAL:
|
||||||
|
btn->add_css_class("notification-critical");
|
||||||
|
break;
|
||||||
|
case NotificationUrgency::NORMAL:
|
||||||
|
btn->add_css_class("notification-normal");
|
||||||
|
break;
|
||||||
|
case NotificationUrgency::LOW:
|
||||||
|
btn->add_css_class("notification-low");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
btn->signal_clicked().connect([this, action_id, cb = notify.on_action, guard = notify.actionInvoked]() {
|
||||||
|
if (cb && guard && !*guard) {
|
||||||
|
*guard = true;
|
||||||
|
cb(action_id);
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
actions_box->append(*btn);
|
||||||
|
}
|
||||||
|
vbox->append(*actions_box);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_child(*vbox);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "widgets/notification/spotifyNotification.hpp"
|
#include "widgets/notification/spotifyNotification.hpp"
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
#include "services/textureCache.hpp"
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
#include "gtkmm/box.h"
|
#include "gtkmm/box.h"
|
||||||
@@ -8,7 +10,7 @@
|
|||||||
#include "gtkmm/image.h"
|
#include "gtkmm/image.h"
|
||||||
#include "gtkmm/label.h"
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
SpotifyNotification::SpotifyNotification(std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message mpris) : BaseNotification(monitor) {
|
SpotifyNotification::SpotifyNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message mpris) : BaseNotification(notificationId, monitor) {
|
||||||
auto container = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
|
auto container = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
|
||||||
container->set_hexpand(true);
|
container->set_hexpand(true);
|
||||||
|
|
||||||
@@ -30,7 +32,12 @@ SpotifyNotification::SpotifyNotification(std::shared_ptr<Gdk::Monitor> monitor,
|
|||||||
title_label->set_halign(Gtk::Align::CENTER);
|
title_label->set_halign(Gtk::Align::CENTER);
|
||||||
title_label->set_ellipsize(Pango::EllipsizeMode::END);
|
title_label->set_ellipsize(Pango::EllipsizeMode::END);
|
||||||
|
|
||||||
auto artistLabel = Gtk::make_managed<Gtk::Label>(mpris.artist);
|
auto artistLabel = Gtk::make_managed<Gtk::Label>();
|
||||||
|
if (!mpris.artist.empty()) {
|
||||||
|
artistLabel->set_text(StringHelper::trimToSize(mpris.artist[0], 30));
|
||||||
|
} else {
|
||||||
|
artistLabel->set_text("Unknown Artist");
|
||||||
|
}
|
||||||
artistLabel->set_hexpand(true);
|
artistLabel->set_hexpand(true);
|
||||||
artistLabel->set_halign(Gtk::Align::CENTER);
|
artistLabel->set_halign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
@@ -57,7 +64,7 @@ std::unique_ptr<Gtk::CenterBox> SpotifyNotification::createButtonBox(MprisPlayer
|
|||||||
backButton->signal_clicked().connect([this, mpris]() {
|
backButton->signal_clicked().connect([this, mpris]() {
|
||||||
if (mpris.previous) {
|
if (mpris.previous) {
|
||||||
mpris.previous();
|
mpris.previous();
|
||||||
this->close();
|
this->signal_close.emit(this->notificationId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -84,7 +91,7 @@ std::unique_ptr<Gtk::CenterBox> SpotifyNotification::createButtonBox(MprisPlayer
|
|||||||
nextButton->signal_clicked().connect([this, mpris]() {
|
nextButton->signal_clicked().connect([this, mpris]() {
|
||||||
if (mpris.next) {
|
if (mpris.next) {
|
||||||
mpris.next();
|
mpris.next();
|
||||||
this->close();
|
this->signal_close.emit(this->notificationId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
buttonBox->set_start_widget(*backButton);
|
buttonBox->set_start_widget(*backButton);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <graphene.h>
|
#include <graphene.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iostream>
|
#include <spdlog/spdlog.h>
|
||||||
#include "components/base/button.hpp"
|
#include "components/base/button.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -168,11 +168,13 @@ void log_menu_tree(const std::vector<TrayService::MenuNode> &nodes,
|
|||||||
if (!node.visible) {
|
if (!node.visible) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::cerr << "[TrayIconWidget] menu node id=" << node.id
|
spdlog::debug(
|
||||||
<< " label='" << node.label << "' enabled="
|
"[TrayIconWidget] menu node id={} label='{}' enabled={} sep={} depth={}",
|
||||||
<< (node.enabled ? "1" : "0") << " sep="
|
node.id,
|
||||||
<< (node.separator ? "1" : "0") << " depth=" << depth
|
node.label,
|
||||||
<< std::endl;
|
node.enabled ? 1 : 0,
|
||||||
|
node.separator ? 1 : 0,
|
||||||
|
depth);
|
||||||
if (!node.children.empty()) {
|
if (!node.children.empty()) {
|
||||||
log_menu_tree(node.children, depth + 1);
|
log_menu_tree(node.children, depth + 1);
|
||||||
}
|
}
|
||||||
@@ -299,8 +301,8 @@ void TrayIconWidget::on_primary_released(int /*n_press*/, double x, double y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "[TrayIconWidget] Activate primary id=" << id << " x="
|
spdlog::debug("[TrayIconWidget] Activate primary id={} x={} y={}", id, sendX,
|
||||||
<< sendX << " y=" << sendY << std::endl;
|
sendY);
|
||||||
service.activate(id, sendX, sendY);
|
service.activate(id, sendX, sendY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,8 +319,9 @@ void TrayIconWidget::on_middle_released(int /*n_press*/, double x, double y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "[TrayIconWidget] SecondaryActivate (middle) id=" << id
|
spdlog::debug(
|
||||||
<< " x=" << sendX << " y=" << sendY << std::endl;
|
"[TrayIconWidget] SecondaryActivate (middle) id={} x={} y={}", id,
|
||||||
|
sendX, sendY);
|
||||||
service.secondaryActivate(id, sendX, sendY);
|
service.secondaryActivate(id, sendX, sendY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,8 +332,9 @@ void TrayIconWidget::on_secondary_released(int /*n_press*/, double x,
|
|||||||
// would crash without a mapped surface.
|
// would crash without a mapped surface.
|
||||||
GtkWidget *selfWidget = GTK_WIDGET(gobj());
|
GtkWidget *selfWidget = GTK_WIDGET(gobj());
|
||||||
if (!gtk_widget_get_mapped(selfWidget) || !has_popup_surface(selfWidget)) {
|
if (!gtk_widget_get_mapped(selfWidget) || !has_popup_surface(selfWidget)) {
|
||||||
std::cerr << "[TrayIconWidget] Secondary fallback ContextMenu (no surface) id="
|
spdlog::debug(
|
||||||
<< id << std::endl;
|
"[TrayIconWidget] Secondary fallback ContextMenu (no surface) id={}",
|
||||||
|
id);
|
||||||
service.contextMenu(id, -1, -1);
|
service.contextMenu(id, -1, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -341,8 +345,7 @@ void TrayIconWidget::on_secondary_released(int /*n_press*/, double x,
|
|||||||
// Use dbusmenu popover when available and we have a mapped surface; else
|
// Use dbusmenu popover when available and we have a mapped surface; else
|
||||||
// fall back to the item's ContextMenu.
|
// fall back to the item's ContextMenu.
|
||||||
if (hasRemoteMenu && has_popup_surface(selfWidget)) {
|
if (hasRemoteMenu && has_popup_surface(selfWidget)) {
|
||||||
std::cerr << "[TrayIconWidget] Requesting dbusmenu for id=" << id
|
spdlog::debug("[TrayIconWidget] Requesting dbusmenu for id={}", id);
|
||||||
<< std::endl;
|
|
||||||
menuPopupPending = true;
|
menuPopupPending = true;
|
||||||
if (menuRequestInFlight) {
|
if (menuRequestInFlight) {
|
||||||
return;
|
return;
|
||||||
@@ -367,12 +370,12 @@ void TrayIconWidget::on_secondary_released(int /*n_press*/, double x,
|
|||||||
(void)try_get_global_pointer_coords(GTK_WIDGET(gobj()), sendX, sendY);
|
(void)try_get_global_pointer_coords(GTK_WIDGET(gobj()), sendX, sendY);
|
||||||
}
|
}
|
||||||
if (is_wayland_display(GTK_WIDGET(gobj()))) {
|
if (is_wayland_display(GTK_WIDGET(gobj()))) {
|
||||||
std::cerr << "[TrayIconWidget] ContextMenu wayland id=" << id
|
spdlog::debug(
|
||||||
<< " x=-1 y=-1" << std::endl;
|
"[TrayIconWidget] ContextMenu wayland id={} x=-1 y=-1", id);
|
||||||
service.contextMenu(id, -1, -1);
|
service.contextMenu(id, -1, -1);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[TrayIconWidget] ContextMenu id=" << id << " x=" << sendX
|
spdlog::debug("[TrayIconWidget] ContextMenu id={} x={} y={}", id,
|
||||||
<< " y=" << sendY << std::endl;
|
sendX, sendY);
|
||||||
service.contextMenu(id, sendX, sendY);
|
service.contextMenu(id, sendX, sendY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,9 +521,8 @@ void TrayIconWidget::on_menu_action(const Glib::VariantBase & /*parameter*/,
|
|||||||
int32_t sendY = -1;
|
int32_t sendY = -1;
|
||||||
(void)try_get_pending_coords(sendX, sendY);
|
(void)try_get_pending_coords(sendX, sendY);
|
||||||
|
|
||||||
std::cerr << "[TrayIconWidget] Menu action id=" << this->id
|
spdlog::debug("[TrayIconWidget] Menu action id={} item={} x={} y={}",
|
||||||
<< " item=" << itemId << " x=" << sendX << " y=" << sendY
|
this->id, itemId, sendX, sendY);
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
const uint32_t nowMs = static_cast<uint32_t>(g_get_monotonic_time() / 1000);
|
const uint32_t nowMs = static_cast<uint32_t>(g_get_monotonic_time() / 1000);
|
||||||
// Use button 1 for menu activation events; some dbusmenu handlers ignore
|
// Use button 1 for menu activation events; some dbusmenu handlers ignore
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "widgets/volumeWidget.hpp"
|
#include "widgets/volumeWidget.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <spdlog/spdlog.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sigc++/functors/mem_fun.h>
|
#include <sigc++/functors/mem_fun.h>
|
||||||
|
|
||||||
@@ -26,8 +26,7 @@ VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
|||||||
(void)CommandHelper::exec(
|
(void)CommandHelper::exec(
|
||||||
"wpctl set-mute @DEFAULT_SINK@ toggle");
|
"wpctl set-mute @DEFAULT_SINK@ toggle");
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
std::cerr << "[VolumeWidget] failed to toggle mute: " << ex.what()
|
spdlog::error("[VolumeWidget] failed to toggle mute: {}", ex.what());
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
this->update();
|
this->update();
|
||||||
});
|
});
|
||||||
@@ -77,8 +76,7 @@ void VolumeWidget::update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
std::cerr << "[VolumeWidget] failed to read volume: " << ex.what()
|
spdlog::error("[VolumeWidget] failed to read volume: {}", ex.what());
|
||||||
<< std::endl;
|
|
||||||
label.set_text("N/A");
|
label.set_text("N/A");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/widgets/weather.cpp
Normal file
112
src/widgets/weather.cpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#include "widgets/weather.hpp"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <glibmm/main.h>
|
||||||
|
#include <ios>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr const char *kWeatherUrl =
|
||||||
|
"https://api.open-meteo.com/v1/forecast?latitude=49.0094&longitude=8.4044&daily=temperature_2m_max,temperature_2m_min,weather_code&hourly=temperature_2m,rain¤t=temperature_2m&timezone=Europe%2FBerlin";
|
||||||
|
|
||||||
|
size_t write_to_buffer(void *contents, size_t size, size_t nmemb, void *userp) {
|
||||||
|
size_t total = size * nmemb;
|
||||||
|
auto *buffer = static_cast<std::string *>(userp);
|
||||||
|
buffer->append(static_cast<char *>(contents), total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string formatTemp(double value) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss.setf(std::ios::fixed);
|
||||||
|
ss.precision(1);
|
||||||
|
ss << value << "°C";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
WeatherWidget::WeatherWidget()
|
||||||
|
: Gtk::Box(Gtk::Orientation::VERTICAL) {
|
||||||
|
this->set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
this->set_spacing(6);
|
||||||
|
this->set_margin_top(4);
|
||||||
|
this->set_margin_bottom(4);
|
||||||
|
this->set_margin_start(4);
|
||||||
|
this->set_margin_end(4);
|
||||||
|
|
||||||
|
this->titleLabel.set_text("Weather");
|
||||||
|
this->currentLabel.set_text("Now: --");
|
||||||
|
this->todayLabel.set_text("Today: -- / --");
|
||||||
|
|
||||||
|
this->append(this->titleLabel);
|
||||||
|
this->append(this->currentLabel);
|
||||||
|
this->append(this->todayLabel);
|
||||||
|
|
||||||
|
this->fetchWeather();
|
||||||
|
Glib::signal_timeout().connect_seconds(
|
||||||
|
sigc::mem_fun(*this, &WeatherWidget::onRefreshTick),
|
||||||
|
3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WeatherWidget::onRefreshTick() {
|
||||||
|
this->fetchWeather();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherWidget::fetchWeather() {
|
||||||
|
std::thread([this]() {
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if (!curl) {
|
||||||
|
Glib::signal_idle().connect_once([this]() {
|
||||||
|
this->applyWeatherText("Now: --", "Today: -- / --");
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, kWeatherUrl);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_buffer);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "bar/1.0");
|
||||||
|
|
||||||
|
auto res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
if (res != CURLE_OK || buffer.empty()) {
|
||||||
|
Glib::signal_idle().connect_once([this]() {
|
||||||
|
this->applyWeatherText("Now: --", "Today: -- / --");
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
auto json = nlohmann::json::parse(buffer);
|
||||||
|
double current = json.at("current").at("temperature_2m").get<double>();
|
||||||
|
double minTemp = json.at("daily").at("temperature_2m_min").at(0).get<double>();
|
||||||
|
double maxTemp = json.at("daily").at("temperature_2m_max").at(0).get<double>();
|
||||||
|
|
||||||
|
std::string currentText = "Now: " + formatTemp(current);
|
||||||
|
std::string todayText = "Today: " + formatTemp(minTemp) + " / " + formatTemp(maxTemp);
|
||||||
|
|
||||||
|
Glib::signal_idle().connect_once([this, currentText, todayText]() {
|
||||||
|
this->applyWeatherText(currentText, todayText);
|
||||||
|
});
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
|
spdlog::error("Weather parse error: {}", ex.what());
|
||||||
|
Glib::signal_idle().connect_once([this]() {
|
||||||
|
this->applyWeatherText("Now: --", "Today: -- / --");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherWidget::applyWeatherText(const std::string ¤t_text,
|
||||||
|
const std::string &today_text) {
|
||||||
|
this->currentLabel.set_text(current_text);
|
||||||
|
this->todayLabel.set_text(today_text);
|
||||||
|
}
|
||||||
24
tests/string_helper_tests.cpp
Normal file
24
tests/string_helper_tests.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("StringHelper::split by char", "[string]") {
|
||||||
|
const auto tokens = StringHelper::split("a,b,,c", ',');
|
||||||
|
REQUIRE(tokens.size() == 3);
|
||||||
|
REQUIRE(tokens[0] == "a");
|
||||||
|
REQUIRE(tokens[1] == "b");
|
||||||
|
REQUIRE(tokens[2] == "c");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("StringHelper::split by string", "[string]") {
|
||||||
|
const auto tokens = StringHelper::split("one::two::three", "::");
|
||||||
|
REQUIRE(tokens.size() == 3);
|
||||||
|
REQUIRE(tokens[0] == "one");
|
||||||
|
REQUIRE(tokens[1] == "two");
|
||||||
|
REQUIRE(tokens[2] == "three");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("StringHelper::trimToSize", "[string]") {
|
||||||
|
REQUIRE(StringHelper::trimToSize("hello", 10) == "hello");
|
||||||
|
REQUIRE(StringHelper::trimToSize("hello world", 5) == "hello...");
|
||||||
|
}
|
||||||
580
weather.json
Normal file
580
weather.json
Normal file
@@ -0,0 +1,580 @@
|
|||||||
|
{
|
||||||
|
"latitude": 49.0,
|
||||||
|
"longitude": 8.4,
|
||||||
|
"generationtime_ms": 0.23317337036132812,
|
||||||
|
"utc_offset_seconds": 3600,
|
||||||
|
"timezone": "Europe/Berlin",
|
||||||
|
"timezone_abbreviation": "GMT+1",
|
||||||
|
"elevation": 122.0,
|
||||||
|
"current_units": {
|
||||||
|
"time": "iso8601",
|
||||||
|
"interval": "seconds",
|
||||||
|
"temperature_2m": "°C"
|
||||||
|
},
|
||||||
|
"current": {
|
||||||
|
"time": "2026-02-03T23:00",
|
||||||
|
"interval": 900,
|
||||||
|
"temperature_2m": -0.7
|
||||||
|
},
|
||||||
|
"hourly_units": {
|
||||||
|
"time": "iso8601",
|
||||||
|
"temperature_2m": "°C",
|
||||||
|
"rain": "mm"
|
||||||
|
},
|
||||||
|
"hourly": {
|
||||||
|
"time": [
|
||||||
|
"2026-02-03T00:00",
|
||||||
|
"2026-02-03T01:00",
|
||||||
|
"2026-02-03T02:00",
|
||||||
|
"2026-02-03T03:00",
|
||||||
|
"2026-02-03T04:00",
|
||||||
|
"2026-02-03T05:00",
|
||||||
|
"2026-02-03T06:00",
|
||||||
|
"2026-02-03T07:00",
|
||||||
|
"2026-02-03T08:00",
|
||||||
|
"2026-02-03T09:00",
|
||||||
|
"2026-02-03T10:00",
|
||||||
|
"2026-02-03T11:00",
|
||||||
|
"2026-02-03T12:00",
|
||||||
|
"2026-02-03T13:00",
|
||||||
|
"2026-02-03T14:00",
|
||||||
|
"2026-02-03T15:00",
|
||||||
|
"2026-02-03T16:00",
|
||||||
|
"2026-02-03T17:00",
|
||||||
|
"2026-02-03T18:00",
|
||||||
|
"2026-02-03T19:00",
|
||||||
|
"2026-02-03T20:00",
|
||||||
|
"2026-02-03T21:00",
|
||||||
|
"2026-02-03T22:00",
|
||||||
|
"2026-02-03T23:00",
|
||||||
|
"2026-02-04T00:00",
|
||||||
|
"2026-02-04T01:00",
|
||||||
|
"2026-02-04T02:00",
|
||||||
|
"2026-02-04T03:00",
|
||||||
|
"2026-02-04T04:00",
|
||||||
|
"2026-02-04T05:00",
|
||||||
|
"2026-02-04T06:00",
|
||||||
|
"2026-02-04T07:00",
|
||||||
|
"2026-02-04T08:00",
|
||||||
|
"2026-02-04T09:00",
|
||||||
|
"2026-02-04T10:00",
|
||||||
|
"2026-02-04T11:00",
|
||||||
|
"2026-02-04T12:00",
|
||||||
|
"2026-02-04T13:00",
|
||||||
|
"2026-02-04T14:00",
|
||||||
|
"2026-02-04T15:00",
|
||||||
|
"2026-02-04T16:00",
|
||||||
|
"2026-02-04T17:00",
|
||||||
|
"2026-02-04T18:00",
|
||||||
|
"2026-02-04T19:00",
|
||||||
|
"2026-02-04T20:00",
|
||||||
|
"2026-02-04T21:00",
|
||||||
|
"2026-02-04T22:00",
|
||||||
|
"2026-02-04T23:00",
|
||||||
|
"2026-02-05T00:00",
|
||||||
|
"2026-02-05T01:00",
|
||||||
|
"2026-02-05T02:00",
|
||||||
|
"2026-02-05T03:00",
|
||||||
|
"2026-02-05T04:00",
|
||||||
|
"2026-02-05T05:00",
|
||||||
|
"2026-02-05T06:00",
|
||||||
|
"2026-02-05T07:00",
|
||||||
|
"2026-02-05T08:00",
|
||||||
|
"2026-02-05T09:00",
|
||||||
|
"2026-02-05T10:00",
|
||||||
|
"2026-02-05T11:00",
|
||||||
|
"2026-02-05T12:00",
|
||||||
|
"2026-02-05T13:00",
|
||||||
|
"2026-02-05T14:00",
|
||||||
|
"2026-02-05T15:00",
|
||||||
|
"2026-02-05T16:00",
|
||||||
|
"2026-02-05T17:00",
|
||||||
|
"2026-02-05T18:00",
|
||||||
|
"2026-02-05T19:00",
|
||||||
|
"2026-02-05T20:00",
|
||||||
|
"2026-02-05T21:00",
|
||||||
|
"2026-02-05T22:00",
|
||||||
|
"2026-02-05T23:00",
|
||||||
|
"2026-02-06T00:00",
|
||||||
|
"2026-02-06T01:00",
|
||||||
|
"2026-02-06T02:00",
|
||||||
|
"2026-02-06T03:00",
|
||||||
|
"2026-02-06T04:00",
|
||||||
|
"2026-02-06T05:00",
|
||||||
|
"2026-02-06T06:00",
|
||||||
|
"2026-02-06T07:00",
|
||||||
|
"2026-02-06T08:00",
|
||||||
|
"2026-02-06T09:00",
|
||||||
|
"2026-02-06T10:00",
|
||||||
|
"2026-02-06T11:00",
|
||||||
|
"2026-02-06T12:00",
|
||||||
|
"2026-02-06T13:00",
|
||||||
|
"2026-02-06T14:00",
|
||||||
|
"2026-02-06T15:00",
|
||||||
|
"2026-02-06T16:00",
|
||||||
|
"2026-02-06T17:00",
|
||||||
|
"2026-02-06T18:00",
|
||||||
|
"2026-02-06T19:00",
|
||||||
|
"2026-02-06T20:00",
|
||||||
|
"2026-02-06T21:00",
|
||||||
|
"2026-02-06T22:00",
|
||||||
|
"2026-02-06T23:00",
|
||||||
|
"2026-02-07T00:00",
|
||||||
|
"2026-02-07T01:00",
|
||||||
|
"2026-02-07T02:00",
|
||||||
|
"2026-02-07T03:00",
|
||||||
|
"2026-02-07T04:00",
|
||||||
|
"2026-02-07T05:00",
|
||||||
|
"2026-02-07T06:00",
|
||||||
|
"2026-02-07T07:00",
|
||||||
|
"2026-02-07T08:00",
|
||||||
|
"2026-02-07T09:00",
|
||||||
|
"2026-02-07T10:00",
|
||||||
|
"2026-02-07T11:00",
|
||||||
|
"2026-02-07T12:00",
|
||||||
|
"2026-02-07T13:00",
|
||||||
|
"2026-02-07T14:00",
|
||||||
|
"2026-02-07T15:00",
|
||||||
|
"2026-02-07T16:00",
|
||||||
|
"2026-02-07T17:00",
|
||||||
|
"2026-02-07T18:00",
|
||||||
|
"2026-02-07T19:00",
|
||||||
|
"2026-02-07T20:00",
|
||||||
|
"2026-02-07T21:00",
|
||||||
|
"2026-02-07T22:00",
|
||||||
|
"2026-02-07T23:00",
|
||||||
|
"2026-02-08T00:00",
|
||||||
|
"2026-02-08T01:00",
|
||||||
|
"2026-02-08T02:00",
|
||||||
|
"2026-02-08T03:00",
|
||||||
|
"2026-02-08T04:00",
|
||||||
|
"2026-02-08T05:00",
|
||||||
|
"2026-02-08T06:00",
|
||||||
|
"2026-02-08T07:00",
|
||||||
|
"2026-02-08T08:00",
|
||||||
|
"2026-02-08T09:00",
|
||||||
|
"2026-02-08T10:00",
|
||||||
|
"2026-02-08T11:00",
|
||||||
|
"2026-02-08T12:00",
|
||||||
|
"2026-02-08T13:00",
|
||||||
|
"2026-02-08T14:00",
|
||||||
|
"2026-02-08T15:00",
|
||||||
|
"2026-02-08T16:00",
|
||||||
|
"2026-02-08T17:00",
|
||||||
|
"2026-02-08T18:00",
|
||||||
|
"2026-02-08T19:00",
|
||||||
|
"2026-02-08T20:00",
|
||||||
|
"2026-02-08T21:00",
|
||||||
|
"2026-02-08T22:00",
|
||||||
|
"2026-02-08T23:00",
|
||||||
|
"2026-02-09T00:00",
|
||||||
|
"2026-02-09T01:00",
|
||||||
|
"2026-02-09T02:00",
|
||||||
|
"2026-02-09T03:00",
|
||||||
|
"2026-02-09T04:00",
|
||||||
|
"2026-02-09T05:00",
|
||||||
|
"2026-02-09T06:00",
|
||||||
|
"2026-02-09T07:00",
|
||||||
|
"2026-02-09T08:00",
|
||||||
|
"2026-02-09T09:00",
|
||||||
|
"2026-02-09T10:00",
|
||||||
|
"2026-02-09T11:00",
|
||||||
|
"2026-02-09T12:00",
|
||||||
|
"2026-02-09T13:00",
|
||||||
|
"2026-02-09T14:00",
|
||||||
|
"2026-02-09T15:00",
|
||||||
|
"2026-02-09T16:00",
|
||||||
|
"2026-02-09T17:00",
|
||||||
|
"2026-02-09T18:00",
|
||||||
|
"2026-02-09T19:00",
|
||||||
|
"2026-02-09T20:00",
|
||||||
|
"2026-02-09T21:00",
|
||||||
|
"2026-02-09T22:00",
|
||||||
|
"2026-02-09T23:00"
|
||||||
|
],
|
||||||
|
"temperature_2m": [
|
||||||
|
2.2,
|
||||||
|
2.2,
|
||||||
|
2.2,
|
||||||
|
2.2,
|
||||||
|
2.0,
|
||||||
|
1.9,
|
||||||
|
1.8,
|
||||||
|
1.5,
|
||||||
|
1.2,
|
||||||
|
1.4,
|
||||||
|
1.8,
|
||||||
|
2.2,
|
||||||
|
2.5,
|
||||||
|
1.9,
|
||||||
|
2.6,
|
||||||
|
3.0,
|
||||||
|
2.7,
|
||||||
|
3.0,
|
||||||
|
3.0,
|
||||||
|
2.4,
|
||||||
|
1.7,
|
||||||
|
1.3,
|
||||||
|
0.9,
|
||||||
|
-0.7,
|
||||||
|
-0.2,
|
||||||
|
-0.1,
|
||||||
|
-0.5,
|
||||||
|
-0.7,
|
||||||
|
-1.4,
|
||||||
|
-1.1,
|
||||||
|
-1.0,
|
||||||
|
-1.0,
|
||||||
|
-1.1,
|
||||||
|
-0.9,
|
||||||
|
1.7,
|
||||||
|
3.7,
|
||||||
|
5.0,
|
||||||
|
5.8,
|
||||||
|
6.5,
|
||||||
|
6.9,
|
||||||
|
6.6,
|
||||||
|
5.9,
|
||||||
|
4.8,
|
||||||
|
3.6,
|
||||||
|
2.7,
|
||||||
|
2.0,
|
||||||
|
1.5,
|
||||||
|
1.1,
|
||||||
|
0.5,
|
||||||
|
0.2,
|
||||||
|
0.4,
|
||||||
|
0.9,
|
||||||
|
1.2,
|
||||||
|
1.3,
|
||||||
|
1.5,
|
||||||
|
1.7,
|
||||||
|
1.8,
|
||||||
|
2.0,
|
||||||
|
2.2,
|
||||||
|
2.7,
|
||||||
|
3.4,
|
||||||
|
4.2,
|
||||||
|
5.2,
|
||||||
|
6.1,
|
||||||
|
6.4,
|
||||||
|
5.9,
|
||||||
|
4.5,
|
||||||
|
3.2,
|
||||||
|
2.4,
|
||||||
|
1.9,
|
||||||
|
1.4,
|
||||||
|
1.1,
|
||||||
|
1.0,
|
||||||
|
0.8,
|
||||||
|
0.5,
|
||||||
|
0.3,
|
||||||
|
0.1,
|
||||||
|
-0.1,
|
||||||
|
-0.2,
|
||||||
|
-0.3,
|
||||||
|
-0.3,
|
||||||
|
-0.1,
|
||||||
|
0.7,
|
||||||
|
1.7,
|
||||||
|
2.9,
|
||||||
|
4.1,
|
||||||
|
5.0,
|
||||||
|
5.2,
|
||||||
|
5.1,
|
||||||
|
4.8,
|
||||||
|
4.3,
|
||||||
|
4.1,
|
||||||
|
4.2,
|
||||||
|
4.1,
|
||||||
|
3.8,
|
||||||
|
3.5,
|
||||||
|
3.3,
|
||||||
|
3.4,
|
||||||
|
3.4,
|
||||||
|
3.5,
|
||||||
|
3.5,
|
||||||
|
3.5,
|
||||||
|
3.4,
|
||||||
|
3.4,
|
||||||
|
3.5,
|
||||||
|
3.6,
|
||||||
|
4.1,
|
||||||
|
5.2,
|
||||||
|
6.6,
|
||||||
|
7.8,
|
||||||
|
8.4,
|
||||||
|
8.8,
|
||||||
|
8.8,
|
||||||
|
8.1,
|
||||||
|
6.9,
|
||||||
|
5.9,
|
||||||
|
5.3,
|
||||||
|
4.9,
|
||||||
|
4.6,
|
||||||
|
4.3,
|
||||||
|
4.2,
|
||||||
|
4.0,
|
||||||
|
3.9,
|
||||||
|
3.9,
|
||||||
|
3.8,
|
||||||
|
3.8,
|
||||||
|
3.8,
|
||||||
|
3.9,
|
||||||
|
4.3,
|
||||||
|
4.7,
|
||||||
|
5.3,
|
||||||
|
6.0,
|
||||||
|
6.9,
|
||||||
|
7.5,
|
||||||
|
7.6,
|
||||||
|
7.5,
|
||||||
|
7.2,
|
||||||
|
6.6,
|
||||||
|
5.8,
|
||||||
|
5.0,
|
||||||
|
4.4,
|
||||||
|
3.9,
|
||||||
|
3.5,
|
||||||
|
3.1,
|
||||||
|
2.9,
|
||||||
|
2.8,
|
||||||
|
3.0,
|
||||||
|
3.3,
|
||||||
|
3.6,
|
||||||
|
3.5,
|
||||||
|
3.4,
|
||||||
|
3.4,
|
||||||
|
3.7,
|
||||||
|
4.2,
|
||||||
|
4.7,
|
||||||
|
5.3,
|
||||||
|
6.0,
|
||||||
|
6.5,
|
||||||
|
6.8,
|
||||||
|
6.8,
|
||||||
|
6.6,
|
||||||
|
5.9,
|
||||||
|
4.8,
|
||||||
|
3.9,
|
||||||
|
3.5,
|
||||||
|
3.3,
|
||||||
|
3.1,
|
||||||
|
2.9
|
||||||
|
],
|
||||||
|
"rain": [
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.10,
|
||||||
|
0.40,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.20,
|
||||||
|
0.60,
|
||||||
|
0.30,
|
||||||
|
1.30,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.40,
|
||||||
|
0.10,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.10,
|
||||||
|
0.20,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.10,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00,
|
||||||
|
0.00
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"daily_units": {
|
||||||
|
"time": "iso8601",
|
||||||
|
"temperature_2m_max": "°C",
|
||||||
|
"temperature_2m_min": "°C",
|
||||||
|
"weather_code": "wmo code"
|
||||||
|
},
|
||||||
|
"daily": {
|
||||||
|
"time": [
|
||||||
|
"2026-02-03",
|
||||||
|
"2026-02-04",
|
||||||
|
"2026-02-05",
|
||||||
|
"2026-02-06",
|
||||||
|
"2026-02-07",
|
||||||
|
"2026-02-08",
|
||||||
|
"2026-02-09"
|
||||||
|
],
|
||||||
|
"temperature_2m_max": [
|
||||||
|
3.0,
|
||||||
|
6.9,
|
||||||
|
6.4,
|
||||||
|
5.2,
|
||||||
|
8.8,
|
||||||
|
7.6,
|
||||||
|
6.8
|
||||||
|
],
|
||||||
|
"temperature_2m_min": [
|
||||||
|
-0.7,
|
||||||
|
-1.4,
|
||||||
|
0.2,
|
||||||
|
-0.3,
|
||||||
|
3.3,
|
||||||
|
3.1,
|
||||||
|
2.8
|
||||||
|
],
|
||||||
|
"weather_code": [
|
||||||
|
61,
|
||||||
|
45,
|
||||||
|
45,
|
||||||
|
61,
|
||||||
|
61,
|
||||||
|
3,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user