Compare commits
38 Commits
f3b250759e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 178a4451d4 | |||
| 17aef717b7 | |||
| dc325834c7 | |||
| caca94bc6a | |||
| 13278d518a | |||
| 8283531748 |
@@ -9,4 +9,7 @@ IncludeCategories:
|
|||||||
Priority: 2
|
Priority: 2
|
||||||
- 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,12 +1,24 @@
|
|||||||
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)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic -Werror")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic")
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -28,14 +40,22 @@ target_sources(bar_lib
|
|||||||
|
|
||||||
src/widgets/clock.cpp
|
src/widgets/clock.cpp
|
||||||
src/widgets/date.cpp
|
src/widgets/date.cpp
|
||||||
|
src/widgets/notification/baseNotification.cpp
|
||||||
|
src/widgets/notification/notificationWindow.cpp
|
||||||
|
src/widgets/notification/spotifyNotification.cpp
|
||||||
src/widgets/volumeWidget.cpp
|
src/widgets/volumeWidget.cpp
|
||||||
src/widgets/webWidget.cpp
|
src/widgets/webWidget.cpp
|
||||||
|
|
||||||
src/services/hyprland.cpp
|
src/services/hyprland.cpp
|
||||||
|
src/services/notificationController.cpp
|
||||||
|
src/services/textureCache.cpp
|
||||||
src/services/tray.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
|
||||||
@@ -49,28 +69,57 @@ 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)
|
||||||
|
|
||||||
# Copy `resources/bar.css` into the build directory when it changes
|
|
||||||
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
|
||||||
set(RES_DST "${CMAKE_CURRENT_BINARY_DIR}/resources/bar.css")
|
|
||||||
set(USER_CONFIG_CSS "$ENV{HOME}/.config/bar/bar.css")
|
|
||||||
|
|
||||||
add_custom_command(
|
# add spdlog
|
||||||
OUTPUT ${RES_DST}
|
find_package(spdlog REQUIRED)
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/resources"
|
target_link_libraries(bar_lib PRIVATE spdlog::spdlog)
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RES_SRC}" "${RES_DST}"
|
|
||||||
DEPENDS "${RES_SRC}"
|
|
||||||
COMMENT "Copy resources/bar.css to build directory"
|
# ---- Testing shit
|
||||||
VERBATIM
|
find_package(Catch2 3 REQUIRED)
|
||||||
|
|
||||||
|
add_executable(bar_tests
|
||||||
|
tests/string_helper_tests.cpp
|
||||||
)
|
)
|
||||||
|
target_include_directories(bar_tests PRIVATE
|
||||||
add_custom_command(
|
include
|
||||||
OUTPUT ${USER_CONFIG_CSS}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "$ENV{HOME}/.config/bar"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RES_SRC}" "${USER_CONFIG_CSS}"
|
|
||||||
DEPENDS "${RES_SRC}"
|
|
||||||
COMMENT "Copy resources/bar.css to ~/.config/bar/bar.css"
|
|
||||||
VERBATIM
|
|
||||||
)
|
)
|
||||||
|
target_link_libraries(bar_tests PRIVATE Catch2::Catch2WithMain)
|
||||||
|
|
||||||
add_custom_target(copy_resources ALL DEPENDS ${RES_DST} ${USER_CONFIG_CSS})
|
# 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
|
||||||
|
file(GLOB RES_CSS_FILES CONFIGURE_DEPENDS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/resources/*.css"
|
||||||
|
)
|
||||||
|
set(RES_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/resources")
|
||||||
|
set(RES_USER_DIR "$ENV{HOME}/.config/bar")
|
||||||
|
|
||||||
|
set(RES_DST_FILES "")
|
||||||
|
set(USER_DST_FILES "")
|
||||||
|
|
||||||
|
foreach(RES_FILE IN LISTS RES_CSS_FILES)
|
||||||
|
get_filename_component(RES_NAME "${RES_FILE}" NAME)
|
||||||
|
set(RES_DST "${RES_BUILD_DIR}/${RES_NAME}")
|
||||||
|
set(USER_DST "${RES_USER_DIR}/${RES_NAME}")
|
||||||
|
|
||||||
|
list(APPEND RES_DST_FILES "${RES_DST}")
|
||||||
|
list(APPEND USER_DST_FILES "${USER_DST}")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${RES_DST}" "${USER_DST}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${RES_BUILD_DIR}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${RES_USER_DIR}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RES_FILE}" "${RES_DST}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RES_FILE}" "${USER_DST}"
|
||||||
|
DEPENDS "${RES_FILE}"
|
||||||
|
COMMENT "Copy ${RES_NAME} to build and config directories"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_custom_target(copy_resources ALL DEPENDS ${RES_DST_FILES} ${USER_DST_FILES})
|
||||||
add_dependencies(bar copy_resources)
|
add_dependencies(bar copy_resources)
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
#include "bar/bar.hpp"
|
#include "bar/bar.hpp"
|
||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
|
#include "services/dbus/notification.hpp"
|
||||||
|
|
||||||
#include "glibmm/refptr.h"
|
#include "glibmm/refptr.h"
|
||||||
#include "gtkmm/application.h"
|
#include "gtkmm/application.h"
|
||||||
|
|
||||||
|
class MprisController;
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
public:
|
public:
|
||||||
App();
|
App();
|
||||||
@@ -17,8 +20,10 @@ class App {
|
|||||||
private:
|
private:
|
||||||
Glib::RefPtr<Gtk::Application> app;
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
std::vector<std::shared_ptr<Bar>> bars;
|
std::vector<std::shared_ptr<Bar>> bars;
|
||||||
|
std::shared_ptr<NotificationService> notificationService = nullptr;
|
||||||
|
std::shared_ptr<MprisController> mprisController = nullptr;
|
||||||
HyprlandService *hyprlandService = nullptr;
|
HyprlandService *hyprlandService = nullptr;
|
||||||
TrayService *trayService = TrayService::getInstance();
|
|
||||||
|
|
||||||
|
TrayService *trayService = TrayService::getInstance();
|
||||||
void setupServices();
|
void setupServices();
|
||||||
};
|
};
|
||||||
@@ -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:
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -37,4 +37,11 @@ public:
|
|||||||
tokens.push_back(input.substr(start));
|
tokens.push_back(input.substr(start));
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string trimToSize(const std::string &input, size_t maxSize) {
|
||||||
|
if (input.length() <= maxSize) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
return input.substr(0, maxSize) + "...";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
47
include/services/dbus/messages.hpp
Normal file
47
include/services/dbus/messages.hpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
#include "gdkmm/pixbuf.h"
|
||||||
|
#include "glibmm/variant.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct MprisPlayer2Message {
|
||||||
|
std::string title;
|
||||||
|
std::vector<std::string> artist;
|
||||||
|
std::string artwork_url;
|
||||||
|
int64_t length_ms;
|
||||||
|
|
||||||
|
std::function<void()> play_pause;
|
||||||
|
std::function<void()> next;
|
||||||
|
std::function<void()> previous;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum NotificationUrgency {
|
||||||
|
LOW = 0,
|
||||||
|
NORMAL = 1,
|
||||||
|
CRITICAL = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NotifyMessage {
|
||||||
|
std::string app_name;
|
||||||
|
uint32_t replaces_id;
|
||||||
|
std::string app_icon;
|
||||||
|
std::string summary;
|
||||||
|
std::string body;
|
||||||
|
std::vector<std::string> actions;
|
||||||
|
NotificationUrgency urgency = NORMAL;
|
||||||
|
int32_t expire_timeout;
|
||||||
|
// Callback to invoke when an action is triggered
|
||||||
|
std::function<void(const std::string& action_id)> on_action;
|
||||||
|
// 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;
|
||||||
|
};
|
||||||
57
include/services/dbus/mpris.hpp
Normal file
57
include/services/dbus/mpris.hpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <giomm.h>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
#include <vector>
|
||||||
|
#include "services/dbus/messages.hpp"
|
||||||
|
|
||||||
|
class MprisController {
|
||||||
|
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();
|
||||||
|
|
||||||
|
void toggle_play();
|
||||||
|
void next_song();
|
||||||
|
void previous_song();
|
||||||
|
void emit_seeked(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();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MprisController();
|
||||||
|
std::map<std::string, PlaybackStatus> playbackStatusMap = {
|
||||||
|
{"Playing", PlaybackStatus::Playing},
|
||||||
|
{"Paused", PlaybackStatus::Paused},
|
||||||
|
{"Stopped", PlaybackStatus::Stopped},
|
||||||
|
};
|
||||||
|
|
||||||
|
PlaybackStatus currentPlaybackStatus = PlaybackStatus::Stopped;
|
||||||
|
|
||||||
|
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
||||||
|
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
||||||
|
|
||||||
|
sigc::signal<void(const MprisPlayer2Message &)> mprisUpdatedSignal;
|
||||||
|
sigc::signal<void(PlaybackStatus)> playbackStatusChangedSignal;
|
||||||
|
sigc::signal<void(int64_t)> playbackPositionChangedSignal;
|
||||||
|
|
||||||
|
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
|
||||||
|
void signalNotification();
|
||||||
|
|
||||||
|
// Called when the song changes
|
||||||
|
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
||||||
|
const std::vector<Glib::ustring> &invalidated_properties);
|
||||||
|
};
|
||||||
70
include/services/dbus/notification.hpp
Normal file
70
include/services/dbus/notification.hpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <giomm.h>
|
||||||
|
#include <gtkmm.h>
|
||||||
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
|
#include "giomm/dbusconnection.h"
|
||||||
|
#include "giomm/dbusownname.h"
|
||||||
|
#include "glib.h"
|
||||||
|
|
||||||
|
const Glib::ustring introspection_xml = R"(
|
||||||
|
<node>
|
||||||
|
<interface name="org.freedesktop.Notifications">
|
||||||
|
<method name="GetCapabilities">
|
||||||
|
<arg name="capabilities" type="as" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Notify">
|
||||||
|
<arg name="app_name" type="s" direction="in"/>
|
||||||
|
<arg name="replaces_id" type="u" direction="in"/>
|
||||||
|
<arg name="app_icon" type="s" direction="in"/>
|
||||||
|
<arg name="summary" type="s" direction="in"/>
|
||||||
|
<arg name="body" type="s" direction="in"/>
|
||||||
|
<arg name="actions" type="as" direction="in"/>
|
||||||
|
<arg name="hints" type="a{sv}" direction="in"/>
|
||||||
|
<arg name="expire_timeout" type="i" direction="in"/>
|
||||||
|
<arg name="id" type="u" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="CloseNotification">
|
||||||
|
<arg name="id" type="u" direction="in"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetServerInformation">
|
||||||
|
<arg name="name" type="s" direction="out"/>
|
||||||
|
<arg name="vendor" type="s" direction="out"/>
|
||||||
|
<arg name="version" type="s" direction="out"/>
|
||||||
|
<arg name="spec_version" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
|
)";
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
public:
|
||||||
|
NotificationService() : notificationIdCounter(1) {
|
||||||
|
Gio::DBus::own_name(
|
||||||
|
Gio::DBus::BusType::SESSION,
|
||||||
|
"org.freedesktop.Notifications",
|
||||||
|
sigc::mem_fun(*this, &NotificationService::onBusAcquired),
|
||||||
|
{}, // Name acquired slot (optional)
|
||||||
|
{}, // Name lost slot (optional)
|
||||||
|
Gio::DBus::BusNameOwnerFlags::REPLACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onBusAcquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
guint notificationIdCounter;
|
||||||
|
const Gio::DBus::InterfaceVTable &getMessageInterfaceVTable();
|
||||||
|
void on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
|
const Glib::ustring &sender,
|
||||||
|
const Glib::ustring &object_path,
|
||||||
|
const Glib::ustring &interface_name,
|
||||||
|
const Glib::ustring &method_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters,
|
||||||
|
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation);
|
||||||
|
|
||||||
|
void handle_notify(const Glib::VariantContainerBase ¶meters,
|
||||||
|
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation);
|
||||||
|
void createNotificationPopup(const Glib::ustring &title, const Glib::ustring &message);
|
||||||
|
};
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
36
include/services/notificationController.hpp
Normal file
36
include/services/notificationController.hpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "services/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
|
#include "gdkmm/monitor.h"
|
||||||
|
|
||||||
|
class NotificationController {
|
||||||
|
static std::shared_ptr<NotificationController> instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::shared_ptr<NotificationController> getInstance() {
|
||||||
|
if (!NotificationController::instance) {
|
||||||
|
NotificationController::instance = std::shared_ptr<NotificationController>(new NotificationController());
|
||||||
|
}
|
||||||
|
return NotificationController::instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showSpotifyNotification(MprisPlayer2Message mpris);
|
||||||
|
void showNotificationOnAllMonitors(NotifyMessage notify);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint64_t globalNotificationId = 1;
|
||||||
|
std::map<uint64_t, std::vector<std::shared_ptr<BaseNotification>>> activeNotifications;
|
||||||
|
std::map<uint64_t, int> hoverCounts;
|
||||||
|
NotificationController();
|
||||||
|
std::vector<std::shared_ptr<Gdk::Monitor>> activeMonitors;
|
||||||
|
void updateHoverState(uint64_t notificationId, bool isHovered);
|
||||||
|
void closeNotification(uint64_t notificationId);
|
||||||
|
};
|
||||||
20
include/services/textureCache.hpp
Normal file
20
include/services/textureCache.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "gdkmm/texture.h"
|
||||||
|
#include "glibmm/refptr.h"
|
||||||
|
|
||||||
|
class TextureCacheService {
|
||||||
|
public:
|
||||||
|
static TextureCacheService *getInstance();
|
||||||
|
|
||||||
|
Glib::RefPtr<Gdk::Texture> getTexture(const std::string &url);
|
||||||
|
void pruneCache();
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextureCacheService() = default;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, Glib::RefPtr<Gdk::Texture>> cache;
|
||||||
|
};
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "components/popover.hpp"
|
#include "components/popover.hpp"
|
||||||
#include "gtkmm/box.h"
|
#include "gtkmm/box.h"
|
||||||
|
#include "widgets/controlCenter/mediaControl.hpp"
|
||||||
|
|
||||||
class ControlCenter : public Popover {
|
class ControlCenter : public Popover {
|
||||||
public:
|
public:
|
||||||
@@ -9,4 +10,6 @@ class ControlCenter : public Popover {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Gtk::Box container;
|
Gtk::Box container;
|
||||||
|
MediaControlWidget mediaControlWidget;
|
||||||
|
|
||||||
};
|
};
|
||||||
57
include/widgets/controlCenter/mediaControl.hpp
Normal file
57
include/widgets/controlCenter/mediaControl.hpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#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 "services/dbus/mpris.hpp"
|
||||||
|
|
||||||
|
class MediaControlWidget : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
MediaControlWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<MprisController> mprisController = MprisController::getInstance();
|
||||||
|
|
||||||
|
int64_t currentPositionUs = 0;
|
||||||
|
int64_t totalLengthUs = 0;
|
||||||
|
sigc::connection seekTimerConnection;
|
||||||
|
|
||||||
|
void setCurrentPosition(int64_t position_us);
|
||||||
|
void setTotalLength(int64_t length_us);
|
||||||
|
void resetSeekTimer(int64_t start_position_us);
|
||||||
|
bool onSeekTick();
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
45
include/widgets/notification/baseNotification.hpp
Normal file
45
include/widgets/notification/baseNotification.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
|
#include "gdkmm/monitor.h"
|
||||||
|
#include "gtkmm/window.h"
|
||||||
|
|
||||||
|
#define DEFAULT_NOTIFICATION_TIMEOUT 5000
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNotification : public Gtk::Window {
|
||||||
|
public:
|
||||||
|
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;
|
||||||
|
|
||||||
|
uint64_t getNotificationId() const {
|
||||||
|
return this->notificationId;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
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;
|
||||||
|
};
|
||||||
13
include/widgets/notification/notificationWindow.hpp
Normal file
13
include/widgets/notification/notificationWindow.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "services/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
|
class NotificationWindow : public BaseNotification {
|
||||||
|
public:
|
||||||
|
NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage message);
|
||||||
|
virtual ~NotificationWindow() = default;
|
||||||
|
|
||||||
|
};
|
||||||
18
include/widgets/notification/spotifyNotification.hpp
Normal file
18
include/widgets/notification/spotifyNotification.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "services/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
|
#include "gtkmm/centerbox.h"
|
||||||
|
|
||||||
|
class SpotifyNotification : public BaseNotification {
|
||||||
|
public:
|
||||||
|
SpotifyNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, MprisPlayer2Message message);
|
||||||
|
virtual ~SpotifyNotification() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Gtk::CenterBox> createButtonBox(MprisPlayer2Message mpris);
|
||||||
|
};
|
||||||
@@ -3,23 +3,27 @@
|
|||||||
all: unset;
|
all: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* variable */
|
||||||
|
:root {
|
||||||
|
--icon-font-material: "Material Icons", sans-serif;
|
||||||
|
--icon-font-awesome: "Font Awesome 7 Free", sans-serif;
|
||||||
|
--text-font: "Hack Nerd Font Mono", sans-serif;
|
||||||
|
--text-font-mono: "Hack Nerd Font Mono", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
window {
|
window {
|
||||||
background-color: #191919c6;
|
background-color: #191919c6;
|
||||||
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:
|
font-family: var(--text-font);
|
||||||
"Hack Nerd Font Mono", "Font Awesome 7 Brands", "Font Awesome 7 Free",
|
|
||||||
sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
popover {
|
popover {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
font-family:
|
font-family: var(--text-font);
|
||||||
"Hack Nerd Font Mono", "Material Icons", "Font Awesome 7 Free", sans-serif;
|
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
|
||||||
@@ -29,6 +33,63 @@ popover {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.control-center-popover {
|
||||||
|
padding: 12px;
|
||||||
|
background-color: rgba(25, 25, 25, 0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-spotify-container {
|
||||||
|
border: 1px solid rgba(80, 80, 80, 0.8);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(30, 30, 30, 0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-center-spotify-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-spotify-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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
@@ -38,26 +99,28 @@ tooltip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
font-family: "Material Icons", sans-serif;
|
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
padding: 3px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#spacer {
|
#spacer {
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
text-shadow: 0 0 5px #ffffffaa;
|
text-shadow: 0 0 5px #ffffffaa;
|
||||||
}
|
|
||||||
|
|
||||||
.button {
|
|
||||||
padding: 4px 8px;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-family: "Material Icons", sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover {
|
.button:hover {
|
||||||
background-color: #111111;
|
background-color: #111111;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flat-button {
|
||||||
|
background-color: #333333;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.workspace-pill {
|
.workspace-pill {
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
margin-right: 6px;
|
margin-right: 6px;
|
||||||
@@ -76,12 +139,12 @@ button {
|
|||||||
|
|
||||||
.workspace-pill-alive {
|
.workspace-pill-alive {
|
||||||
background-color: rgba(255, 255, 255, 0.153);
|
background-color: rgba(255, 255, 255, 0.153);
|
||||||
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-presenting {
|
.workspace-pill-presenting {
|
||||||
background-color: #666666;
|
background-color: #666666;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
/* animation: workspace-updown 1.2s ease-in-out infinite; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-focused {
|
.workspace-pill-focused {
|
||||||
@@ -104,7 +167,6 @@ button {
|
|||||||
animation: workspace-updown 1.2s ease-in-out infinite;
|
animation: workspace-updown 1.2s ease-in-out infinite;
|
||||||
margin-left: -4px;
|
margin-left: -4px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
font-size: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-seven {
|
.workspace-pill-seven {
|
||||||
@@ -112,7 +174,6 @@ button {
|
|||||||
animation-delay: 0.6s;
|
animation-delay: 0.6s;
|
||||||
margin-right: -4px;
|
margin-right: -4px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
font-size: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes workspace-updown {
|
@keyframes workspace-updown {
|
||||||
|
|||||||
93
resources/notification.css
Normal file
93
resources/notification.css
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
:root {
|
||||||
|
--icon-font-material: "Material Icons", sans-serif;
|
||||||
|
--icon-font-awesome: "Font Awesome 7 Free", sans-serif;
|
||||||
|
--text-font: "Hack Nerd Font Mono", sans-serif;
|
||||||
|
--text-font-mono: "Hack Nerd Font Mono", monospace;
|
||||||
|
|
||||||
|
--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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-popup {
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: var(--color-notification-bg);
|
||||||
|
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
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 {
|
||||||
|
border-top: 1px solid var(--color-border);
|
||||||
|
padding-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-button {
|
||||||
|
background-color: #333333;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 4px 8px;
|
||||||
|
margin-right: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-icon-button {
|
||||||
|
font-family: var(--icon-font-material);
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-button:hover {
|
||||||
|
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);
|
||||||
|
}
|
||||||
18
src/app.cpp
18
src/app.cpp
@@ -1,13 +1,24 @@
|
|||||||
#include "app.hpp"
|
#include "app.hpp"
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
|
#include <vector>
|
||||||
|
#include "services/dbus/notification.hpp"
|
||||||
|
#include "services/dbus/mpris.hpp"
|
||||||
|
#include "services/notificationController.hpp"
|
||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
App::App() {
|
App::App() {
|
||||||
this->app = Gtk::Application::create("org.example.mybar");
|
this->app = Gtk::Application::create("org.example.mybar");
|
||||||
this->setupServices();
|
this->setupServices();
|
||||||
this->hyprlandService = HyprlandService::getInstance();
|
this->hyprlandService = HyprlandService::getInstance();
|
||||||
|
this->notificationService = std::make_shared<NotificationService>();
|
||||||
|
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();
|
||||||
@@ -17,7 +28,7 @@ App::App() {
|
|||||||
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(
|
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(
|
||||||
monitors->get_object(i)
|
monitors->get_object(i)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
auto bar = std::make_shared<Bar>(monitor->gobj());
|
auto bar = std::make_shared<Bar>(monitor->gobj());
|
||||||
|
|
||||||
@@ -40,6 +51,7 @@ App::App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void App::setupServices() {
|
void App::setupServices() {
|
||||||
|
TextureCacheService::getInstance()->pruneCache();
|
||||||
|
|
||||||
this->trayService->start();
|
this->trayService->start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "components/workspaceIndicator.hpp"
|
#include "components/workspaceIndicator.hpp"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "gtkmm/gestureclick.h"
|
#include "gtkmm/gestureclick.h"
|
||||||
#include "gtkmm/label.h"
|
#include "gtkmm/label.h"
|
||||||
@@ -14,7 +13,7 @@ WorkspaceIndicator::WorkspaceIndicator(int id, std::string label, sigc::slot<voi
|
|||||||
|
|
||||||
auto gesture = Gtk::GestureClick::create();
|
auto gesture = Gtk::GestureClick::create();
|
||||||
gesture->set_button(GDK_BUTTON_PRIMARY);
|
gesture->set_button(GDK_BUTTON_PRIMARY);
|
||||||
gesture->signal_released().connect([this, id, onClick](int, double, double) {
|
gesture->signal_released().connect([id, onClick](int, double, double) {
|
||||||
onClick(
|
onClick(
|
||||||
id);
|
id);
|
||||||
});
|
});
|
||||||
@@ -22,9 +21,11 @@ WorkspaceIndicator::WorkspaceIndicator(int id, std::string label, sigc::slot<voi
|
|||||||
overlay->add_controller(gesture);
|
overlay->add_controller(gesture);
|
||||||
overlay->add_css_class("workspace-pill");
|
overlay->add_css_class("workspace-pill");
|
||||||
|
|
||||||
if (id == 6 || id == 7) {
|
int sixSevenCheck = std::stoi(label);
|
||||||
auto indicator = Gtk::make_managed<Gtk::Label>(id == 6 ? "🫱🏻" : "🫲🏻");
|
|
||||||
indicator->add_css_class(id == 6 ? "workspace-pill-six" : "workspace-pill-seven");
|
if (sixSevenCheck == 6 || sixSevenCheck == 7) {
|
||||||
|
auto indicator = Gtk::make_managed<Gtk::Label>(sixSevenCheck == 6 ? "🫱🏻" : "🫲🏻");
|
||||||
|
indicator->add_css_class(sixSevenCheck == 6 ? "workspace-pill-six" : "workspace-pill-seven");
|
||||||
indicator->set_valign(Gtk::Align::END);
|
indicator->set_valign(Gtk::Align::END);
|
||||||
overlay->set_child(*indicator);
|
overlay->set_child(*indicator);
|
||||||
overlay->add_overlay(*numLabel);
|
overlay->add_overlay(*numLabel);
|
||||||
|
|||||||
214
src/services/dbus/mpris.cpp
Normal file
214
src/services/dbus/mpris.cpp
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
#include "services/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;
|
||||||
|
}
|
||||||
|
|
||||||
|
MprisController::MprisController() {
|
||||||
|
Gio::DBus::Connection::get(
|
||||||
|
Gio::DBus::BusType::SESSION,
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_bus_connected));
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
if (!result) {
|
||||||
|
spdlog::error("DBus Connection Error: null async result");
|
||||||
|
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) {
|
||||||
|
spdlog::info("Connected to: {}", player_bus_name);
|
||||||
|
|
||||||
|
signalNotification();
|
||||||
|
|
||||||
|
m_proxy->signal_properties_changed().connect(
|
||||||
|
sigc::mem_fun(*this, &MprisController::on_properties_changed));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (const Glib::Error &ex) {
|
||||||
|
spdlog::error("DBus Connection Error: {}", ex.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.play_pause = [this]() { this->toggle_play(); };
|
||||||
|
mpris.next = [this]() { this->next_song(); };
|
||||||
|
mpris.previous = [this]() { this->previous_song(); };
|
||||||
|
mpris.length_ms = length_us; // Convert microseconds to milliseconds
|
||||||
|
mprisUpdatedSignal.emit(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()) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MprisController::emit_seeked(int64_t 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
172
src/services/dbus/notification.cpp
Normal file
172
src/services/dbus/notification.cpp
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#include "services/dbus/notification.hpp"
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
#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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notify.expire_timeout = expire_timeout;
|
||||||
|
|
||||||
|
if (app_name == "Thunderbird") {
|
||||||
|
notify.expire_timeout = 10000; // 10 seconds for email notifications
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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,10 +1,8 @@
|
|||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#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>
|
||||||
@@ -17,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() {
|
||||||
@@ -30,24 +30,24 @@ void HyprlandService::init() {
|
|||||||
auto monitorPtr = std::make_shared<Monitor>();
|
auto monitorPtr = std::make_shared<Monitor>();
|
||||||
|
|
||||||
std::string monitorName = item["name"].get<std::string>();
|
std::string monitorName = item["name"].get<std::string>();
|
||||||
int monitorId = item["id"].get<int>();
|
int monitorId = item["id"].get<int>();
|
||||||
|
|
||||||
monitorPtr->id = monitorId;
|
monitorPtr->id = monitorId;
|
||||||
monitorPtr->name = monitorName;
|
monitorPtr->name = monitorName;
|
||||||
monitorPtr->activeWorkspaceId = item["activeWorkspace"]["id"].get<int>();
|
monitorPtr->activeWorkspaceId = item["activeWorkspace"]["id"].get<int>();
|
||||||
monitorPtr->focused = item["focused"].get<bool>();
|
monitorPtr->focused = item["focused"].get<bool>();
|
||||||
this->monitors[monitorPtr->name] = monitorPtr;
|
this->monitors[monitorPtr->name] = monitorPtr;
|
||||||
|
|
||||||
for (int i = 1; i <= NUM_WORKSPACES; i++) {
|
for (int i = 1; i <= NUM_WORKSPACES; i++) {
|
||||||
std::shared_ptr<WorkspaceData> state = std::make_shared<WorkspaceData>();
|
std::shared_ptr<WorkspaceData> state = std::make_shared<WorkspaceData>();
|
||||||
int workspaceId = i + (NUM_WORKSPACES * monitorId);
|
int workspaceId = i + (NUM_WORKSPACES * monitorId);
|
||||||
|
|
||||||
state->id = workspaceId;
|
state->id = workspaceId;
|
||||||
state->monitorName = monitorName;
|
state->monitorName = monitorName;
|
||||||
auto view = std::make_shared<WorkspaceIndicator>(workspaceId, std::to_string(i), onClick);
|
auto view = std::make_shared<WorkspaceIndicator>(workspaceId, std::to_string(i), onClick);
|
||||||
auto workSpace = std::make_shared<Workspace>();
|
auto workSpace = std::make_shared<Workspace>();
|
||||||
workSpace->state = state;
|
workSpace->state = state;
|
||||||
workSpace->view = view;
|
workSpace->view = view;
|
||||||
|
|
||||||
monitorPtr->monitorWorkspaces[workspaceId] = workSpace;
|
monitorPtr->monitorWorkspaces[workspaceId] = workSpace;
|
||||||
this->workspaces[workspaceId] = workSpace;
|
this->workspaces[workspaceId] = workSpace;
|
||||||
@@ -77,19 +77,19 @@ void HyprlandService::init() {
|
|||||||
auto workspacePtr = workspaces[workspace["id"].get<int>()];
|
auto workspacePtr = workspaces[workspace["id"].get<int>()];
|
||||||
auto state = workspacePtr->state;
|
auto state = workspacePtr->state;
|
||||||
|
|
||||||
state->id = workspace["id"].get<int>();
|
state->id = workspace["id"].get<int>();
|
||||||
state->monitorName = workspace["monitor"].get<std::string>();
|
state->monitorName = workspace["monitor"].get<std::string>();
|
||||||
|
|
||||||
refreshIndicator(workspacePtr);
|
refreshIndicator(workspacePtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,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, ">>");
|
||||||
|
|
||||||
@@ -119,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);
|
||||||
}
|
}
|
||||||
@@ -169,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, ',');
|
||||||
@@ -215,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,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) {
|
||||||
|
|||||||
139
src/services/notificationController.cpp
Normal file
139
src/services/notificationController.cpp
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
#include "services/notificationController.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "services/dbus/messages.hpp"
|
||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
#include "widgets/notification/notificationWindow.hpp"
|
||||||
|
#include "widgets/notification/spotifyNotification.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "gdkmm/display.h"
|
||||||
|
#include "sigc++/adaptors/bind.h"
|
||||||
|
|
||||||
|
std::shared_ptr<NotificationController> NotificationController::instance = nullptr;
|
||||||
|
|
||||||
|
NotificationController::NotificationController() {
|
||||||
|
if (NotificationController::instance) {
|
||||||
|
throw std::runtime_error("use getInstance()!");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto display = Gdk::Display::get_default();
|
||||||
|
if (!display) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto monitors = display->get_monitors();
|
||||||
|
if (!monitors) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
||||||
|
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(
|
||||||
|
monitors->get_object(i));
|
||||||
|
|
||||||
|
this->activeMonitors.push_back(monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NotificationController::showNotificationOnAllMonitors(NotifyMessage notify) {
|
||||||
|
uint64_t id = this->globalNotificationId++;
|
||||||
|
std::vector<std::shared_ptr<BaseNotification>> notifications;
|
||||||
|
|
||||||
|
for (const auto &monitor : this->activeMonitors) {
|
||||||
|
auto notification = std::make_shared<NotificationWindow>(id, monitor, notify);
|
||||||
|
notifications.push_back(notification);
|
||||||
|
|
||||||
|
auto timeout = notify.expire_timeout;
|
||||||
|
notification->show();
|
||||||
|
// -1 means use default timeout, 0 means never expire
|
||||||
|
if (timeout < 0) {
|
||||||
|
timeout = DEFAULT_NOTIFICATION_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (timeout == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
notification->startAutoClose(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);
|
||||||
|
}
|
||||||
223
src/services/textureCache.cpp
Normal file
223
src/services/textureCache.cpp
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "giomm/file.h"
|
||||||
|
#include "glibmm/bytes.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
#define CACHE_SIZE 128
|
||||||
|
#define CACHE_AGE 168
|
||||||
|
|
||||||
|
constexpr std::uint64_t kFnvOffsetBasis = 14695981039346656037ull;
|
||||||
|
constexpr std::uint64_t kFnvPrime = 1099511628211ull;
|
||||||
|
|
||||||
|
std::string to_hex(std::uint64_t value) {
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << std::hex << std::setw(16) << std::setfill('0') << value;
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string hash_url(const std::string &url) {
|
||||||
|
std::uint64_t hash = kFnvOffsetBasis;
|
||||||
|
for (unsigned char c : url) {
|
||||||
|
hash ^= c;
|
||||||
|
hash *= kFnvPrime;
|
||||||
|
}
|
||||||
|
return to_hex(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path get_cache_dir() {
|
||||||
|
const char *xdg_cache = std::getenv("XDG_CACHE_HOME");
|
||||||
|
if (xdg_cache && *xdg_cache) {
|
||||||
|
return std::filesystem::path(xdg_cache) / "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *home = std::getenv("HOME");
|
||||||
|
if (home && *home) {
|
||||||
|
return std::filesystem::path(home) / ".cache" / "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::filesystem::temp_directory_path() / "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path get_cache_path_for_url(const std::string &url) {
|
||||||
|
auto filename = hash_url(url);
|
||||||
|
|
||||||
|
auto last_slash = url.find_last_of('/');
|
||||||
|
auto last_dot = url.find_last_of('.');
|
||||||
|
if (last_dot != std::string::npos && (last_slash == std::string::npos || last_dot > last_slash)) {
|
||||||
|
auto ext = url.substr(last_dot);
|
||||||
|
if (ext.size() <= 10) {
|
||||||
|
filename += ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return get_cache_dir() / filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::system_clock::time_point to_system_clock(std::filesystem::file_time_type time) {
|
||||||
|
return std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||||
|
time - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t write_to_buffer(void *contents, size_t size, size_t nmemb, void *userp) {
|
||||||
|
auto *buffer = static_cast<std::vector<unsigned char> *>(userp);
|
||||||
|
auto total = size * nmemb;
|
||||||
|
auto *bytes = static_cast<unsigned char *>(contents);
|
||||||
|
buffer->insert(buffer->end(), bytes, bytes + total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::RefPtr<Gdk::Texture> load_texture_from_file(const std::filesystem::path &path) {
|
||||||
|
if (!std::filesystem::exists(path)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto file = Gio::File::create_for_path(path.string());
|
||||||
|
try {
|
||||||
|
return Gdk::Texture::create_from_file(file);
|
||||||
|
} catch (...) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::RefPtr<Gdk::Texture> download_texture_from_url(const std::string &url, const std::filesystem::path &path) {
|
||||||
|
if (url.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if (!curl) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> buffer;
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
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()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::error_code error;
|
||||||
|
std::filesystem::create_directories(path.parent_path(), error);
|
||||||
|
|
||||||
|
std::ofstream output(path, std::ios::binary | std::ios::trunc);
|
||||||
|
if (output) {
|
||||||
|
output.write(reinterpret_cast<const char *>(buffer.data()), static_cast<std::streamsize>(buffer.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto bytes = Glib::Bytes::create(buffer.data(), buffer.size());
|
||||||
|
return Gdk::Texture::create_from_bytes(bytes);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TextureCacheService *TextureCacheService::getInstance() {
|
||||||
|
static TextureCacheService instance;
|
||||||
|
return &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::RefPtr<Gdk::Texture> TextureCacheService::getTexture(const std::string &url) {
|
||||||
|
if (url.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = cache.find(url);
|
||||||
|
if (it != cache.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cache_path = get_cache_path_for_url(url);
|
||||||
|
auto texture = load_texture_from_file(cache_path);
|
||||||
|
if (!texture) {
|
||||||
|
texture = download_texture_from_url(url, cache_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture) {
|
||||||
|
cache.emplace(url, texture);
|
||||||
|
std::error_code error;
|
||||||
|
std::filesystem::last_write_time(cache_path, std::filesystem::file_time_type::clock::now(), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCacheService::pruneCache() {
|
||||||
|
std::error_code error;
|
||||||
|
auto cache_dir = get_cache_dir();
|
||||||
|
std::filesystem::create_directories(cache_dir, error);
|
||||||
|
|
||||||
|
std::vector<std::pair<std::filesystem::path, std::uintmax_t>> files;
|
||||||
|
std::uintmax_t total_size = 0;
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto max_age = std::chrono::hours(CACHE_AGE);
|
||||||
|
|
||||||
|
for (const auto &entry : std::filesystem::directory_iterator(cache_dir, error)) {
|
||||||
|
if (error || !entry.is_regular_file()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto path = entry.path();
|
||||||
|
auto last_write = entry.last_write_time(error);
|
||||||
|
if (!error) {
|
||||||
|
auto age = now - to_system_clock(last_write);
|
||||||
|
if (age > max_age) {
|
||||||
|
std::filesystem::remove(path, error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto size = entry.file_size(error);
|
||||||
|
if (!error) {
|
||||||
|
total_size += size;
|
||||||
|
files.emplace_back(path, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto max_size = static_cast<std::uintmax_t>(CACHE_SIZE) * 1024ull * 1024ull;
|
||||||
|
if (total_size <= max_size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(files.begin(), files.end(), [&](const auto &left, const auto &right) {
|
||||||
|
std::error_code left_error;
|
||||||
|
std::error_code right_error;
|
||||||
|
auto left_time = std::filesystem::last_write_time(left.first, left_error);
|
||||||
|
auto right_time = std::filesystem::last_write_time(right.first, right_error);
|
||||||
|
if (left_error || right_error) {
|
||||||
|
return left.first.string() < right.first.string();
|
||||||
|
}
|
||||||
|
return left_time < right_time;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto &item : files) {
|
||||||
|
if (total_size <= max_size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::filesystem::remove(item.first, error);
|
||||||
|
if (!error) {
|
||||||
|
if (total_size >= item.second) {
|
||||||
|
total_size -= item.second;
|
||||||
|
} else {
|
||||||
|
total_size = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -288,8 +288,9 @@ void TrayService::start() {
|
|||||||
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 +578,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 +638,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 +646,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 +748,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 +846,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 +1242,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 {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
20
src/widgets/controlCenter/controlCenter.cpp
Normal file
20
src/widgets/controlCenter/controlCenter.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "widgets/controlCenter/controlCenter.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
ControlCenter::ControlCenter(std::string icon, std::string name)
|
||||||
|
: Popover(icon, name) {
|
||||||
|
this->popover->add_css_class("control-center-popover");
|
||||||
|
this->container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
this->container.set_spacing(0);
|
||||||
|
this->container.set_margin_top(0);
|
||||||
|
this->container.set_margin_bottom(0);
|
||||||
|
this->container.set_margin_start(0);
|
||||||
|
this->container.set_margin_end(0);
|
||||||
|
|
||||||
|
set_popover_child(this->container);
|
||||||
|
|
||||||
|
|
||||||
|
this->container.append(this->mediaControlWidget);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
217
src/widgets/controlCenter/mediaControl.cpp
Normal file
217
src/widgets/controlCenter/mediaControl.cpp
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
#include "widgets/controlCenter/mediaControl.hpp"
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
|
MediaControlWidget::MediaControlWidget()
|
||||||
|
: Gtk::Box(Gtk::Orientation::VERTICAL) {
|
||||||
|
|
||||||
|
this->set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
this->set_size_request(200, 240);
|
||||||
|
this->set_hexpand(false);
|
||||||
|
this->set_vexpand(false);
|
||||||
|
this->add_css_class("control-center-spotify-container");
|
||||||
|
|
||||||
|
this->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(200, 100);
|
||||||
|
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->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_size_request(120, -1);
|
||||||
|
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]() {
|
||||||
|
double fraction = this->seekBar.get_value() / 100.0;
|
||||||
|
int64_t new_position_us =
|
||||||
|
static_cast<int64_t>(fraction * static_cast<double>(this->totalLengthUs));
|
||||||
|
this->mprisController->emit_seeked(new_position_us - this->currentPositionUs); // in us
|
||||||
|
this->resetSeekTimer(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("notification-button");
|
||||||
|
this->previousButton.add_css_class("notification-icon-button");
|
||||||
|
this->playPauseButton.set_label("\u23EF"); // Play/Pause symbol
|
||||||
|
this->playPauseButton.add_css_class("notification-button");
|
||||||
|
this->playPauseButton.add_css_class("notification-icon-button");
|
||||||
|
this->nextButton.set_label("\u23ED"); // Next track symbol
|
||||||
|
this->nextButton.add_css_class("notification-button");
|
||||||
|
this->nextButton.add_css_class("notification-icon-button");
|
||||||
|
|
||||||
|
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->artistLabel.set_text("Artist Name");
|
||||||
|
this->artistLabel.add_css_class("control-center-spotify-artist-label");
|
||||||
|
this->titleLabel.set_text("Song Title");
|
||||||
|
this->titleLabel.add_css_class("control-center-spotify-title-label");
|
||||||
|
|
||||||
|
this->resetSeekTimer(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void 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);
|
||||||
|
|
||||||
|
if (auto texture = TextureCacheService::getInstance()->getTexture(message.artwork_url)) {
|
||||||
|
this->backgroundImage.set_paintable(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setTotalLength(message.length_ms);
|
||||||
|
this->setCurrentPosition(0);
|
||||||
|
this->resetSeekTimer(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::setCurrentPosition(int64_t position_us) {
|
||||||
|
this->currentPositionUs = position_us;
|
||||||
|
int64_t seconds = (position_us / 1000000) % 60;
|
||||||
|
int64_t minutes = (position_us / (1000000 * 60)) % 60;
|
||||||
|
this->currentTimeLabel.set_text(
|
||||||
|
std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds));
|
||||||
|
if (totalLengthUs > 0) {
|
||||||
|
double fraction = static_cast<double>(currentPositionUs) / static_cast<double>(totalLengthUs);
|
||||||
|
this->seekBar.set_value(fraction * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::setTotalLength(int64_t length_us) {
|
||||||
|
this->totalLengthUs = length_us;
|
||||||
|
int64_t seconds = (length_us / 1000000) % 60;
|
||||||
|
int64_t minutes = (length_us / (1000000 * 60)) % 60;
|
||||||
|
this->totalTimeLabel.set_text(
|
||||||
|
std::to_string(minutes) + ":" + (seconds < 10 ? "0" : "") + std::to_string(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::resetSeekTimer(int64_t start_position_us) {
|
||||||
|
if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentPosition(start_position_us);
|
||||||
|
|
||||||
|
seekTimerConnection = Glib::signal_timeout().connect(
|
||||||
|
sigc::mem_fun(*this, &MediaControlWidget::onSeekTick),
|
||||||
|
1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MediaControlWidget::onSeekTick() {
|
||||||
|
if (totalLengthUs <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t nextPosition = currentPositionUs + 1000000;
|
||||||
|
if (nextPosition > totalLengthUs) {
|
||||||
|
nextPosition = totalLengthUs;
|
||||||
|
}
|
||||||
|
setCurrentPosition(nextPosition);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onRunningStateChanged(MprisController::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("\u23EF"); // Play symbol
|
||||||
|
if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaControlWidget::onStop() {
|
||||||
|
this->playPauseButton.set_label("\u23EF"); // Play symbol
|
||||||
|
if (seekTimerConnection.connected()) {
|
||||||
|
seekTimerConnection.disconnect();
|
||||||
|
}
|
||||||
|
this->setCurrentPosition(0);
|
||||||
|
}
|
||||||
148
src/widgets/notification/baseNotification.cpp
Normal file
148
src/widgets/notification/baseNotification.cpp
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
#include "widgets/notification/baseNotification.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "helpers/system.hpp"
|
||||||
|
|
||||||
|
#include "gdkmm/monitor.h"
|
||||||
|
#include "glibmm/main.h"
|
||||||
|
#include "glibmm/object.h"
|
||||||
|
#include "gtk4-layer-shell.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/cssprovider.h"
|
||||||
|
#include "gtkmm/eventcontrollermotion.h"
|
||||||
|
#include "gtkmm/gestureclick.h"
|
||||||
|
|
||||||
|
BaseNotification::BaseNotification(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor) {
|
||||||
|
ensure_notification_css_loaded();
|
||||||
|
set_default_size(350, -1);
|
||||||
|
gtk_layer_init_for_window(gobj());
|
||||||
|
gtk_layer_set_monitor(gobj(), monitor->gobj());
|
||||||
|
gtk_layer_set_layer(gobj(), GTK_LAYER_SHELL_LAYER_OVERLAY);
|
||||||
|
gtk_layer_set_anchor(gobj(), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
|
||||||
|
gtk_layer_set_anchor(gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
|
||||||
|
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_TOP, 2);
|
||||||
|
gtk_layer_set_margin(gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, 2);
|
||||||
|
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() {
|
||||||
|
static bool loaded = false;
|
||||||
|
if (loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto css_provider = Gtk::CssProvider::create();
|
||||||
|
|
||||||
|
std::string css_path = "resources/notification.css";
|
||||||
|
const char *home = std::getenv("HOME");
|
||||||
|
if (home) {
|
||||||
|
std::filesystem::path config_path =
|
||||||
|
std::filesystem::path(home) / ".config/bar/notification.css";
|
||||||
|
if (std::filesystem::exists(config_path)) {
|
||||||
|
css_path = config_path.string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string css = SystemHelper::read_file_to_string(css_path);
|
||||||
|
css_provider->load_from_data(css);
|
||||||
|
|
||||||
|
Gtk::StyleContext::add_provider_for_display(
|
||||||
|
Gdk::Display::get_default(), css_provider,
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_USER + 2);
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
98
src/widgets/notification/spotifyNotification.cpp
Normal file
98
src/widgets/notification/spotifyNotification.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "widgets/notification/spotifyNotification.hpp"
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "helpers/string.hpp"
|
||||||
|
#include "services/textureCache.hpp"
|
||||||
|
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/button.h"
|
||||||
|
#include "gtkmm/centerbox.h"
|
||||||
|
#include "gtkmm/image.h"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
container->set_hexpand(true);
|
||||||
|
|
||||||
|
if (auto texture = TextureCacheService::getInstance()->getTexture(mpris.artwork_url)) {
|
||||||
|
auto img = Gtk::make_managed<Gtk::Image>(texture);
|
||||||
|
img->set_pixel_size(64);
|
||||||
|
container->append(*img);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rightArea = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 5);
|
||||||
|
rightArea->set_halign(Gtk::Align::FILL);
|
||||||
|
rightArea->set_valign(Gtk::Align::CENTER);
|
||||||
|
rightArea->set_hexpand(true);
|
||||||
|
rightArea->set_size_request(220, -1);
|
||||||
|
|
||||||
|
auto title_label = Gtk::make_managed<Gtk::Label>("<b>" + mpris.title + "</b>");
|
||||||
|
title_label->set_use_markup(true);
|
||||||
|
title_label->set_hexpand(true);
|
||||||
|
title_label->set_halign(Gtk::Align::CENTER);
|
||||||
|
title_label->set_ellipsize(Pango::EllipsizeMode::END);
|
||||||
|
|
||||||
|
auto artistLabel = Gtk::make_managed<Gtk::Label>();
|
||||||
|
artistLabel->set_text(StringHelper::trimToSize(mpris.artist[0], 30));
|
||||||
|
artistLabel->set_hexpand(true);
|
||||||
|
artistLabel->set_halign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
|
auto buttonBox = createButtonBox(mpris);
|
||||||
|
|
||||||
|
rightArea->append(*artistLabel);
|
||||||
|
rightArea->append(*title_label);
|
||||||
|
rightArea->append(*buttonBox);
|
||||||
|
|
||||||
|
container->append(*rightArea);
|
||||||
|
|
||||||
|
set_child(*container);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Gtk::CenterBox> SpotifyNotification::createButtonBox(MprisPlayer2Message mpris) {
|
||||||
|
auto buttonBox = std::make_unique<Gtk::CenterBox>();
|
||||||
|
buttonBox->add_css_class("notification-button-box");
|
||||||
|
buttonBox->set_hexpand(true);
|
||||||
|
buttonBox->set_halign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
|
auto backButton = Gtk::make_managed<Gtk::Button>("\ue045");
|
||||||
|
backButton->add_css_class("notification-icon-button");
|
||||||
|
backButton->add_css_class("notification-button");
|
||||||
|
backButton->signal_clicked().connect([this, mpris]() {
|
||||||
|
if (mpris.previous) {
|
||||||
|
mpris.previous();
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto playPauseButton = Gtk::make_managed<Gtk::Button>("\ue037");
|
||||||
|
playPauseButton->add_css_class("notification-icon-button");
|
||||||
|
playPauseButton->add_css_class("notification-button");
|
||||||
|
playPauseButton->signal_clicked().connect([playPauseButton, mpris]() {
|
||||||
|
if (mpris.play_pause) {
|
||||||
|
mpris.play_pause();
|
||||||
|
|
||||||
|
static bool isPlaying = false;
|
||||||
|
if (isPlaying) {
|
||||||
|
playPauseButton->set_label("\ue037");
|
||||||
|
} else {
|
||||||
|
playPauseButton->set_label("\ue034");
|
||||||
|
}
|
||||||
|
isPlaying = !isPlaying;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
auto nextButton = Gtk::make_managed<Gtk::Button>("\ue044");
|
||||||
|
nextButton->add_css_class("notification-icon-button");
|
||||||
|
nextButton->add_css_class("notification-button");
|
||||||
|
nextButton->signal_clicked().connect([this, mpris]() {
|
||||||
|
if (mpris.next) {
|
||||||
|
mpris.next();
|
||||||
|
this->signal_close.emit(this->notificationId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonBox->set_start_widget(*backButton);
|
||||||
|
buttonBox->set_center_widget(*playPauseButton);
|
||||||
|
buttonBox->set_end_widget(*nextButton);
|
||||||
|
|
||||||
|
return buttonBox;
|
||||||
|
}
|
||||||
@@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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...");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user