Compare commits
1 Commits
f3b250759e
...
laptop
| Author | SHA1 | Date | |
|---|---|---|---|
| e3bb3fdf31 |
@@ -5,20 +5,17 @@ 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_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic -Werror")
|
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
||||||
pkg_check_modules(LAYERSHELL REQUIRED gtk4-layer-shell-0)
|
pkg_check_modules(LAYERSHELL REQUIRED gtk4-layer-shell-0)
|
||||||
pkg_check_modules(WEBKIT REQUIRED webkitgtk-6.0)
|
pkg_check_modules(WEBKIT REQUIRED webkitgtk-6.0)
|
||||||
pkg_check_modules(CURL REQUIRED libcurl)
|
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
|
||||||
|
|
||||||
find_package(nlohmann_json 3.2.0 REQUIRED)
|
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS} ${SQLITE3_INCLUDE_DIRS})
|
||||||
|
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS} ${SQLITE3_LIBRARY_DIRS})
|
||||||
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${nlohmann_json_INCLUDE_DIRS})
|
|
||||||
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS} ${CURL_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_library(bar_lib)
|
add_library(bar_lib)
|
||||||
target_sources(bar_lib
|
target_sources(bar_lib
|
||||||
@@ -28,17 +25,25 @@ target_sources(bar_lib
|
|||||||
|
|
||||||
src/widgets/clock.cpp
|
src/widgets/clock.cpp
|
||||||
src/widgets/date.cpp
|
src/widgets/date.cpp
|
||||||
|
src/widgets/workspaceIndicator.cpp
|
||||||
src/widgets/volumeWidget.cpp
|
src/widgets/volumeWidget.cpp
|
||||||
src/widgets/webWidget.cpp
|
src/widgets/webWidget.cpp
|
||||||
|
src/widgets/battery.cpp
|
||||||
|
|
||||||
|
src/services/todo.cpp
|
||||||
|
src/services/sqliteTodoAdapter.cpp
|
||||||
src/services/hyprland.cpp
|
src/services/hyprland.cpp
|
||||||
src/services/tray.cpp
|
src/services/tray.cpp
|
||||||
|
src/services/notifications.cpp
|
||||||
|
src/services/bluetooth.cpp
|
||||||
|
|
||||||
src/widgets/tray.cpp
|
src/widgets/tray.cpp
|
||||||
|
src/widgets/todo.cpp
|
||||||
|
src/widgets/bluetooth.cpp
|
||||||
src/widgets/controlCenter.cpp
|
src/widgets/controlCenter.cpp
|
||||||
|
|
||||||
src/components/popover.cpp
|
src/components/popover.cpp
|
||||||
src/components/workspaceIndicator.cpp
|
src/components/todoEntry.cpp
|
||||||
src/components/base/button.cpp
|
src/components/base/button.cpp
|
||||||
)
|
)
|
||||||
include_directories(bar_lib PRIVATE
|
include_directories(bar_lib PRIVATE
|
||||||
@@ -47,7 +52,7 @@ include_directories(bar_lib PRIVATE
|
|||||||
|
|
||||||
add_executable(bar main.cpp)
|
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} ${SQLITE3_LIBRARIES})
|
||||||
|
|
||||||
# Copy `resources/bar.css` into the build directory when it changes
|
# Copy `resources/bar.css` into the build directory when it changes
|
||||||
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "bar/bar.hpp"
|
#include "bar/bar.hpp"
|
||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
|
#include "services/notifications.hpp"
|
||||||
|
#include "services/tray.hpp"
|
||||||
|
|
||||||
#include "glibmm/refptr.h"
|
#include "glibmm/refptr.h"
|
||||||
#include "gtkmm/application.h"
|
#include "gtkmm/application.h"
|
||||||
@@ -16,8 +18,9 @@ class App {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Glib::RefPtr<Gtk::Application> app;
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
std::vector<std::shared_ptr<Bar>> bars;
|
std::vector<Bar *> bars;
|
||||||
HyprlandService *hyprlandService = nullptr;
|
HyprlandService *hyprlandService = HyprlandService::getInstance();
|
||||||
|
NotificationService notificationService;
|
||||||
TrayService *trayService = TrayService::getInstance();
|
TrayService *trayService = TrayService::getInstance();
|
||||||
|
|
||||||
void setupServices();
|
void setupServices();
|
||||||
|
|||||||
@@ -2,24 +2,24 @@
|
|||||||
|
|
||||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
#include "icons.hpp"
|
||||||
|
#include "widgets/battery.hpp"
|
||||||
#include "widgets/clock.hpp"
|
#include "widgets/clock.hpp"
|
||||||
|
#include "widgets/controlCenter.hpp"
|
||||||
#include "widgets/date.hpp"
|
#include "widgets/date.hpp"
|
||||||
#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/workspaceIndicator.hpp"
|
||||||
|
|
||||||
class Bar : public Gtk::Window {
|
class Bar : public Gtk::Window {
|
||||||
public:
|
public:
|
||||||
Bar(GdkMonitor *monitor);
|
Bar(GdkMonitor *monitor, int monitorId);
|
||||||
|
|
||||||
void addLeftWidget(std::shared_ptr<Gtk::Widget> widget) { left_box.append(*widget); }
|
|
||||||
void addCenterWidget(std::shared_ptr<Gtk::Widget> widget) { center_box.append(*widget); }
|
|
||||||
void addRightWidget(std::shared_ptr<Gtk::Widget> widget) { right_box.append(*widget); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int monitorId;
|
||||||
|
|
||||||
Gtk::CenterBox main_box{};
|
Gtk::CenterBox main_box{};
|
||||||
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
|
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
|
||||||
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
|
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
|
||||||
@@ -27,11 +27,13 @@ class Bar : public Gtk::Window {
|
|||||||
|
|
||||||
Clock clock;
|
Clock clock;
|
||||||
Date date;
|
Date date;
|
||||||
WebWidget homeAssistant{"\ue88a", "Home Assistant", "https://home.rivercry.com"};
|
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
|
||||||
ControlCenter controlCenter{"\ue88a", "Control Center"};
|
ControlCenter controlCenter{"\ue8bb", "Control Center"};
|
||||||
|
|
||||||
std::shared_ptr<TrayWidget> trayWidget = nullptr;
|
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||||
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
|
TrayWidget *trayWidget = nullptr;
|
||||||
|
VolumeWidget *volumeWidget = nullptr;
|
||||||
|
BatteryWidget *batteryWidget = nullptr;
|
||||||
|
|
||||||
|
|
||||||
void setup_ui();
|
void setup_ui();
|
||||||
|
|||||||
21
include/components/todoEntry.hpp
Normal file
21
include/components/todoEntry.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
|
||||||
|
class TodoEntry : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited);
|
||||||
|
|
||||||
|
int get_id() const { return id; }
|
||||||
|
std::string get_text() const { return text; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int id;
|
||||||
|
std::string text;
|
||||||
|
sigc::signal<void(int)> signal_dismissed;
|
||||||
|
sigc::signal<void(int, std::string)> signal_edited;
|
||||||
|
|
||||||
|
void on_dismiss_clicked();
|
||||||
|
};
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "gtkmm/box.h"
|
|
||||||
#include "gtkmm/button.h"
|
|
||||||
#include "gtkmm/overlay.h"
|
|
||||||
|
|
||||||
class WorkspaceIndicator : public Gtk::Box {
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum InidicatorState {
|
|
||||||
EMPTY,
|
|
||||||
ALIVE,
|
|
||||||
FOCUSED,
|
|
||||||
PRESENTING,
|
|
||||||
URGENT,
|
|
||||||
};
|
|
||||||
|
|
||||||
// meh, Maybe try WorkspaceState struct later
|
|
||||||
WorkspaceIndicator(int id, std::string label, sigc::slot<void(int)> onClick);
|
|
||||||
void setIndicatorState(InidicatorState state);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void clearCssClass();
|
|
||||||
InidicatorState currentState = EMPTY;
|
|
||||||
std::shared_ptr<Gtk::Overlay> overlay;
|
|
||||||
std::map<InidicatorState, std::string> stateToCssClass = {
|
|
||||||
{FOCUSED, "workspace-pill-focused"},
|
|
||||||
{URGENT, "workspace-pill-urgent"},
|
|
||||||
{ALIVE, "workspace-pill-alive"},
|
|
||||||
{PRESENTING, "workspace-pill-presenting"},
|
|
||||||
{EMPTY, "workspace-pill-empty"}, // Default class
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
class CommandHelper {
|
|
||||||
public:
|
|
||||||
static std::string exec(const char *cmd) {
|
|
||||||
std::array<char, 128> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::unique_ptr<FILE, int(*)(FILE*)> pipe(popen(cmd, "r"), pclose);
|
|
||||||
if (!pipe) {
|
|
||||||
throw std::runtime_error("popen() failed!");
|
|
||||||
}
|
|
||||||
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr) {
|
|
||||||
result += buffer.data();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void execNoOutput(std::string cmd) {
|
|
||||||
std::string command = cmd + " > /dev/null 2>&1";
|
|
||||||
int ret = std::system(command.c_str());
|
|
||||||
if (ret != 0) {
|
|
||||||
throw std::runtime_error("Command failed with return code: " + std::to_string(ret));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#include "helpers/command.hpp"
|
|
||||||
|
|
||||||
class HyprctlHelper {
|
|
||||||
public:
|
|
||||||
static nlohmann::json getMonitorData() {
|
|
||||||
std::string result = CommandHelper::exec("hyprctl -j monitors");
|
|
||||||
assert(!result.empty() && "Failed to get monitor data from hyprctl");
|
|
||||||
|
|
||||||
auto json = nlohmann::json::parse(result);
|
|
||||||
|
|
||||||
assert(json.is_array());
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nlohmann::json getWorkspaceData() {
|
|
||||||
std::string result = CommandHelper::exec("hyprctl -j workspaces");
|
|
||||||
assert(!result.empty() && "Failed to get workspace data from hyprctl");
|
|
||||||
|
|
||||||
auto json = nlohmann::json::parse(result);
|
|
||||||
|
|
||||||
assert(json.is_array());
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nlohmann::json getClientData() {
|
|
||||||
std::string result = CommandHelper::exec("hyprctl -j clients");
|
|
||||||
assert(!result.empty() && "Failed to get client data from hyprctl");
|
|
||||||
|
|
||||||
auto json = nlohmann::json::parse(result);
|
|
||||||
|
|
||||||
assert(json.is_array());
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dispatchWorkspace(int workspaceNumber) {
|
|
||||||
std::string out = "hyprctl dispatch workspace " + std::to_string(workspaceNumber);
|
|
||||||
CommandHelper::execNoOutput(out.c_str());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class HyprSocketHelper {
|
|
||||||
public:
|
|
||||||
static std::string getHyprlandSocketPath() {
|
|
||||||
const char *hyprlandInstanceSignature = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
|
||||||
const char *xdgRuntimeDir = std::getenv("XDG_RUNTIME_DIR");
|
|
||||||
|
|
||||||
if (!xdgRuntimeDir || !hyprlandInstanceSignature) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string basePath = std::string(xdgRuntimeDir) + "/hypr/" + std::string(hyprlandInstanceSignature) + "/";
|
|
||||||
std::string sock1 = basePath + ".socket2.sock";
|
|
||||||
if (access(sock1.c_str(), F_OK) == 0) {
|
|
||||||
return sock1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "helpers/string.hpp"
|
|
||||||
|
|
||||||
class SocketHelper {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef struct SocketMessage {
|
|
||||||
std::string eventType;
|
|
||||||
std::string eventData;
|
|
||||||
} SocketMessage;
|
|
||||||
|
|
||||||
static std::vector<SocketMessage> parseSocketMessage(int socketFd, const std::string &delimiter) {
|
|
||||||
char buffer[4096];
|
|
||||||
std::string data;
|
|
||||||
|
|
||||||
ssize_t bytesRead = recv(socketFd, buffer, sizeof(buffer) - 1, 0);
|
|
||||||
if (bytesRead > 0) {
|
|
||||||
buffer[bytesRead] = '\0';
|
|
||||||
data = std::string(buffer);
|
|
||||||
} else if (bytesRead == 0) {
|
|
||||||
std::cerr << "Socket closed by peer" << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cerr << "Error reading from socket" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto delimiterPos = data.find(delimiter);
|
|
||||||
|
|
||||||
if (delimiterPos == std::string::npos) {
|
|
||||||
assert(false && "Delimiter not found in socket message");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto splitMessages = StringHelper::split(data, '\n');
|
|
||||||
auto splitMessagesFinal = std::vector<SocketMessage>();
|
|
||||||
for (auto splitMessage : splitMessages) {
|
|
||||||
SocketMessage message;
|
|
||||||
auto messageCommandVector = StringHelper::split(splitMessage, delimiter);
|
|
||||||
|
|
||||||
message.eventType = messageCommandVector[0];
|
|
||||||
message.eventData = messageCommandVector.size() > 1 ? messageCommandVector[1] : "";
|
|
||||||
splitMessagesFinal.push_back(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return splitMessagesFinal;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
class StringHelper {
|
|
||||||
public:
|
|
||||||
static std::vector<std::string> split(const std::string &input, char delimiter) {
|
|
||||||
std::vector<std::string> tokens;
|
|
||||||
std::string token;
|
|
||||||
for (char ch : input) {
|
|
||||||
if (ch == delimiter) {
|
|
||||||
if (!token.empty()) {
|
|
||||||
tokens.push_back(token);
|
|
||||||
token.clear();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
token += ch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!token.empty()) {
|
|
||||||
tokens.push_back(token);
|
|
||||||
}
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::vector<std::string> split(const std::string &input, std::string delimiter) {
|
|
||||||
std::vector<std::string> tokens;
|
|
||||||
size_t start = 0;
|
|
||||||
size_t end = input.find(delimiter);
|
|
||||||
while (end != std::string::npos) {
|
|
||||||
tokens.push_back(input.substr(start, end - start));
|
|
||||||
start = end + delimiter.length();
|
|
||||||
end = input.find(delimiter, start);
|
|
||||||
}
|
|
||||||
tokens.push_back(input.substr(start));
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
class SystemHelper {
|
|
||||||
public:
|
|
||||||
static std::string read_file_to_string(const std::string &filePath) {
|
|
||||||
std::ifstream file(filePath);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
throw std::runtime_error("Could not open file: " + filePath);
|
|
||||||
}
|
|
||||||
std::string content((std::istreambuf_iterator<char>(file)),
|
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
file.close();
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
39
include/helpers/systemHelper.hpp
Normal file
39
include/helpers/systemHelper.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class SystemHelper {
|
||||||
|
public:
|
||||||
|
static std::string get_command_output(const char *cmd) {
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, int (*)(FILE *)> pipe(popen(cmd, "r"), pclose);
|
||||||
|
|
||||||
|
if (!pipe) {
|
||||||
|
throw std::runtime_error("popen() failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the output a chunk at a time until the stream ends
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read an entire file into a string. Throws std::runtime_error on failure.
|
||||||
|
static std::string read_file_to_string(const std::string &path) {
|
||||||
|
std::ifstream in(path, std::ios::in | std::ios::binary);
|
||||||
|
if (!in) {
|
||||||
|
throw std::runtime_error("Failed to open file: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << in.rdbuf();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
3
include/icons.hpp
Normal file
3
include/icons.hpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define ICON_HOME "\ue88a"
|
||||||
@@ -1,112 +1,82 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <set>
|
|
||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <vector>
|
||||||
#include "bar/bar.hpp"
|
|
||||||
#include "components/workspaceIndicator.hpp"
|
|
||||||
#include "helpers/socket.hpp"
|
|
||||||
|
|
||||||
#include "gtkmm/box.h"
|
|
||||||
|
|
||||||
#define NUM_WORKSPACES 7
|
|
||||||
|
|
||||||
class HyprlandService {
|
class HyprlandService {
|
||||||
inline static HyprlandService *instance = nullptr;
|
inline static HyprlandService *instance = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Client {
|
static constexpr int kWorkspaceSlotCount = 7;
|
||||||
std::string address;
|
const char *kMonitorCommand = "hyprctl monitors -j";
|
||||||
int workspaceId;
|
const char *kWorkspaceCommand = "hyprctl workspaces -j";
|
||||||
std::string title;
|
const char *kClientsCommand = "hyprctl clients -j";
|
||||||
|
|
||||||
|
struct WindowState {
|
||||||
|
int hyprId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WorkspaceData {
|
struct WorkspaceState {
|
||||||
int id;
|
int hyprId = -1;
|
||||||
std::string monitorName;
|
int monitorId = -1;
|
||||||
|
bool active = false;
|
||||||
|
bool focused = false;
|
||||||
|
std::vector<std::string> urgentWindows;
|
||||||
std::string label;
|
std::string label;
|
||||||
|
|
||||||
std::map<std::string, std::shared_ptr<Client>> clients;
|
|
||||||
std::set<std::string> urgentClients;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Workspace {
|
|
||||||
std::shared_ptr<WorkspaceData> state;
|
|
||||||
std::shared_ptr<WorkspaceIndicator> view;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Monitor {
|
struct Monitor {
|
||||||
int id;
|
std::map<int, WorkspaceState *> workspaceStates;
|
||||||
int activeWorkspaceId;
|
|
||||||
bool focused;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::map<int, std::shared_ptr<Workspace>> monitorWorkspaces;
|
int x = 0;
|
||||||
std::shared_ptr<Bar> bar;
|
int y = 0;
|
||||||
|
int id = -1;
|
||||||
|
int focusedWorkspaceId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void on_hyprland_event(std::string event, std::string data);
|
||||||
|
void printMonitor(const Monitor &mon) const;
|
||||||
|
|
||||||
|
sigc::signal<void(std::string, std::string)> socketEventSignal;
|
||||||
|
sigc::signal<void()> workspaceStateChanged;
|
||||||
|
sigc::signal<void()> monitorStateChanged;
|
||||||
|
|
||||||
|
Monitor *getMonitorById(int id);
|
||||||
|
Monitor *getMonitorByIndex(std::size_t index);
|
||||||
|
void switchToWorkspace(int workspaceId);
|
||||||
|
|
||||||
|
std::map<int, WorkspaceState *> getAllWorkspaces() const {
|
||||||
|
return this->workspaces;
|
||||||
|
}
|
||||||
|
|
||||||
static HyprlandService *getInstance() {
|
static HyprlandService *getInstance() {
|
||||||
if (!instance) {
|
if (HyprlandService::instance == nullptr) {
|
||||||
instance = new HyprlandService();
|
HyprlandService::instance = new HyprlandService();
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Gtk::Box> getWorkspaceIndicatorsForMonitor(std::string monitorName);
|
return HyprlandService::instance;
|
||||||
|
}
|
||||||
void addBar(std::shared_ptr<Bar> bar, std::string monitorName);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum SocketEventType {
|
|
||||||
WORKSPACE_CHANGED,
|
|
||||||
|
|
||||||
ACTIVE_WINDOW,
|
|
||||||
OPEN_WINDOW,
|
|
||||||
CLOSE_WINDOW,
|
|
||||||
URGENT,
|
|
||||||
|
|
||||||
FOCUSED_MONITOR,
|
|
||||||
MONITOR_REMOVED,
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map<std::string, SocketEventType> socketEventTypeMap = {
|
|
||||||
{"workspace", WORKSPACE_CHANGED},
|
|
||||||
{"activewindowv2", ACTIVE_WINDOW},
|
|
||||||
{"openwindow", OPEN_WINDOW},
|
|
||||||
{"closewindow", CLOSE_WINDOW},
|
|
||||||
{"urgent", URGENT},
|
|
||||||
{"focusedmon", FOCUSED_MONITOR},
|
|
||||||
{"monitorremoved", MONITOR_REMOVED},
|
|
||||||
};
|
|
||||||
void onWorkspaceChanged(int workspaceId);
|
|
||||||
void onFocusedMonitorChanged(std::string monitorData);
|
|
||||||
void onOpenWindow(std::string windowData);
|
|
||||||
void onCloseWindow(std::string windowData);
|
|
||||||
void onUrgent(std::string windowAddress);
|
|
||||||
void onActiveWindowChanged(std::string windowAddress);
|
|
||||||
void onMonitorRemoved(std::string monitorName);
|
|
||||||
// void onMonitorAdded(std::string monitorName);
|
|
||||||
|
|
||||||
HyprlandService();
|
HyprlandService();
|
||||||
std::map<std::string, std::shared_ptr<Monitor>> monitors;
|
~HyprlandService();
|
||||||
std::map<int, std::shared_ptr<Workspace>> workspaces;
|
|
||||||
std::map<std::string, std::shared_ptr<Client>> clients;
|
|
||||||
|
|
||||||
/// maybe refactor into reusable class
|
int fd = -1;
|
||||||
std::string socketBuffer;
|
std::map<int, Monitor> monitors;
|
||||||
int socketFd;
|
std::map<int, WorkspaceState *> workspaces;
|
||||||
///
|
std::string socket_buffer;
|
||||||
|
|
||||||
void bindSocket();
|
std::string get_socket_path();
|
||||||
|
bool on_socket_read(Glib::IOCondition condition);
|
||||||
void init();
|
void parse_message(const std::string &line);
|
||||||
|
void refresh_monitors();
|
||||||
void switchToWorkspace(int workspaceId);
|
void refresh_workspaces();
|
||||||
void refreshIndicator(std::shared_ptr<Workspace> workspace);
|
void onUrgentEvent(std::string windowAddress);
|
||||||
|
void onActiveWindowEvent(std::string windowAddress);
|
||||||
void handleSocketMessage(SocketHelper::SocketMessage message);
|
|
||||||
};
|
};
|
||||||
|
|||||||
20
include/services/notifications.hpp
Normal file
20
include/services/notifications.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
public:
|
||||||
|
void intialize();
|
||||||
|
|
||||||
|
NotificationService() = default;
|
||||||
|
~NotificationService();
|
||||||
|
|
||||||
|
guint32 allocateNotificationId(guint32 replacesId);
|
||||||
|
GDBusConnection *getConnection() const { return connection; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
GDBusConnection *connection = nullptr;
|
||||||
|
guint registrationId = 0;
|
||||||
|
GDBusNodeInfo *nodeInfo = nullptr;
|
||||||
|
guint32 nextNotificationId = 1;
|
||||||
|
};
|
||||||
28
include/services/todo.hpp
Normal file
28
include/services/todo.hpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "components/todoEntry.hpp"
|
||||||
|
#include "services/todoAdapter.hpp"
|
||||||
|
|
||||||
|
class TodoService {
|
||||||
|
public:
|
||||||
|
TodoService(sigc::signal<void()> refreshSignal);
|
||||||
|
~TodoService();
|
||||||
|
|
||||||
|
std::map<int, TodoEntry *> getTodos();
|
||||||
|
void init();
|
||||||
|
void removeTodo(int id);
|
||||||
|
TodoEntry *addTodo(std::string text, bool emitSignal = true, bool persist = true);
|
||||||
|
void updateTodo(int id, std::string text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void load();
|
||||||
|
|
||||||
|
int nextId = 1;
|
||||||
|
std::map<int, TodoEntry *> todos;
|
||||||
|
sigc::signal<void()> refreshSignal;
|
||||||
|
|
||||||
|
std::unique_ptr<ITodoAdapter> adapter;
|
||||||
|
};
|
||||||
21
include/services/todoAdapter.hpp
Normal file
21
include/services/todoAdapter.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct TodoRecord {
|
||||||
|
int id;
|
||||||
|
std::string text;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ITodoAdapter {
|
||||||
|
public:
|
||||||
|
virtual ~ITodoAdapter() = default;
|
||||||
|
|
||||||
|
virtual bool init() = 0;
|
||||||
|
virtual std::vector<TodoRecord> listTodos() = 0;
|
||||||
|
|
||||||
|
virtual int addTodo(const std::string &text) = 0;
|
||||||
|
virtual bool removeTodo(int id) = 0;
|
||||||
|
virtual bool updateTodo(int id, const std::string &text) = 0;
|
||||||
|
};
|
||||||
26
include/widgets/battery.hpp
Normal file
26
include/widgets/battery.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
|
class BatteryWidget : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
BatteryWidget();
|
||||||
|
~BatteryWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gtk::Label iconLabel;
|
||||||
|
Gtk::Label label;
|
||||||
|
sigc::connection timeoutConn;
|
||||||
|
std::filesystem::path batteryPath;
|
||||||
|
std::string currentStateClass;
|
||||||
|
|
||||||
|
void update();
|
||||||
|
bool on_timeout();
|
||||||
|
void find_battery_path();
|
||||||
|
void set_state_class(const std::string &stateClass);
|
||||||
|
std::string build_icon(int capacity, bool hasBattery, bool charging, bool full) const;
|
||||||
|
std::string build_text(int capacity, const std::string &status, bool hasBattery, bool charging, bool full) const;
|
||||||
|
};
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "components/popover.hpp"
|
#include "components/popover.hpp"
|
||||||
|
#include "services/bluetooth.hpp"
|
||||||
|
#include "widgets/bluetooth.hpp"
|
||||||
#include "gtkmm/box.h"
|
#include "gtkmm/box.h"
|
||||||
|
|
||||||
class ControlCenter : public Popover {
|
class ControlCenter : public Popover {
|
||||||
@@ -9,4 +11,7 @@ class ControlCenter : public Popover {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Gtk::Box container;
|
Gtk::Box container;
|
||||||
|
|
||||||
|
BluetoothWidget *bluetoothWidget = nullptr;
|
||||||
|
BluetoothService *bluetoothService = BluetoothService::getInstance();
|
||||||
};
|
};
|
||||||
21
include/widgets/todo.hpp
Normal file
21
include/widgets/todo.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "components/popover.hpp"
|
||||||
|
#include "services/todo.hpp"
|
||||||
|
|
||||||
|
class TodoPopover : public Popover {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TodoPopover(std::string icon, std::string title);
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
TodoService *todoService = nullptr;
|
||||||
|
Gtk::Box container;
|
||||||
|
Gtk::Box inputArea;
|
||||||
|
Gtk::Box *todoList = nullptr;
|
||||||
|
};
|
||||||
28
include/widgets/workspaceIndicator.hpp
Normal file
28
include/widgets/workspaceIndicator.hpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/gestureclick.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
|
#include "services/hyprland.hpp"
|
||||||
|
#include "gtkmm/overlay.h"
|
||||||
|
|
||||||
|
class WorkspaceIndicator : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
WorkspaceIndicator(int monitorId);
|
||||||
|
~WorkspaceIndicator() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
HyprlandService *service = HyprlandService::getInstance();
|
||||||
|
int monitorId;
|
||||||
|
sigc::connection workspaceConnection;
|
||||||
|
sigc::connection monitorConnection;
|
||||||
|
std::map<int, Gtk::Overlay *> workspaceIndicators;
|
||||||
|
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
|
||||||
|
|
||||||
|
void rebuild();
|
||||||
|
void on_workspace_update();
|
||||||
|
void on_monitor_update();
|
||||||
|
void refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state);
|
||||||
|
};
|
||||||
2
main.cpp
2
main.cpp
@@ -1,6 +1,6 @@
|
|||||||
#include "app.hpp"
|
#include "app.hpp"
|
||||||
|
|
||||||
int main()
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
App app;
|
App app;
|
||||||
|
|
||||||
|
|||||||
@@ -74,14 +74,8 @@ button {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-alive {
|
.workspace-pill-active {
|
||||||
background-color: rgba(255, 255, 255, 0.153);
|
|
||||||
}
|
|
||||||
|
|
||||||
.workspace-pill-presenting {
|
|
||||||
background-color: #666666;
|
background-color: #666666;
|
||||||
color: #ffffff;
|
|
||||||
/* animation: workspace-updown 1.2s ease-in-out infinite; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspace-pill-focused {
|
.workspace-pill-focused {
|
||||||
@@ -142,3 +136,93 @@ button {
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.battery-widget {
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: rgba(255, 255, 255, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-icon {
|
||||||
|
min-width: 7ch;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.08ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-text {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-normal {
|
||||||
|
background-color: rgba(120, 120, 120, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-full {
|
||||||
|
background-color: rgba(76, 129, 76, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-full .battery-widget-icon {
|
||||||
|
color: #bdf5bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-charging {
|
||||||
|
background-color: rgba(76, 129, 76, 0.28);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-charging .battery-widget-icon {
|
||||||
|
color: #9df19d;
|
||||||
|
animation: battery-charge-glow 1.4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-low {
|
||||||
|
background-color: rgba(148, 61, 61, 0.28);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-low .battery-widget-icon {
|
||||||
|
color: #ff8585;
|
||||||
|
animation: battery-low-blink 1s steps(2, start) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-external {
|
||||||
|
background-color: rgba(100, 100, 100, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.battery-widget-external .battery-widget-icon {
|
||||||
|
color: #d7d7d7;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes battery-charge-glow {
|
||||||
|
0% {
|
||||||
|
opacity: 0.7;
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateX(1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0.7;
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes battery-low-blink {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
49% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
35
src/app.cpp
35
src/app.cpp
@@ -5,9 +5,10 @@
|
|||||||
#include <sigc++/sigc++.h>
|
#include <sigc++/sigc++.h>
|
||||||
|
|
||||||
App::App() {
|
App::App() {
|
||||||
this->app = Gtk::Application::create("org.example.mybar");
|
|
||||||
this->setupServices();
|
this->setupServices();
|
||||||
this->hyprlandService = HyprlandService::getInstance();
|
this->notificationService.intialize();
|
||||||
|
|
||||||
|
this->app = Gtk::Application::create("org.example.mybar");
|
||||||
|
|
||||||
app->signal_activate().connect([&]() {
|
app->signal_activate().connect([&]() {
|
||||||
auto display = Gdk::Display::get_default();
|
auto display = Gdk::Display::get_default();
|
||||||
@@ -15,19 +16,23 @@ App::App() {
|
|||||||
|
|
||||||
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
||||||
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());
|
HyprlandService::Monitor *hyprlandMonitor = nullptr;
|
||||||
|
|
||||||
|
try {
|
||||||
|
hyprlandMonitor =
|
||||||
|
this->hyprlandService->getMonitorByIndex(i);
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
|
std::cerr << "[App] Failed to fetch Hyprland monitor: "
|
||||||
|
<< ex.what() << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto bar = new Bar(monitor->gobj(), hyprlandMonitor->id);
|
||||||
|
|
||||||
bar->set_application(app);
|
bar->set_application(app);
|
||||||
bar->show();
|
bar->show();
|
||||||
|
|
||||||
std::string monitorName = monitor->get_connector();
|
|
||||||
bar->addLeftWidget(hyprlandService->getWorkspaceIndicatorsForMonitor(monitorName));
|
|
||||||
hyprlandService->addBar(bar, monitorName);
|
|
||||||
|
|
||||||
bars.push_back(bar);
|
bars.push_back(bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,12 +40,20 @@ App::App() {
|
|||||||
|
|
||||||
|
|
||||||
app->signal_shutdown().connect([&]() {
|
app->signal_shutdown().connect([&]() {
|
||||||
|
for (auto bar : bars) {
|
||||||
|
delete bar;
|
||||||
|
}
|
||||||
|
bars.clear();
|
||||||
|
|
||||||
this->trayService->stop();
|
this->trayService->stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::setupServices() {
|
void App::setupServices() {
|
||||||
|
this->hyprlandService->socketEventSignal.connect(sigc::mem_fun(
|
||||||
|
*this->hyprlandService, &HyprlandService::on_hyprland_event));
|
||||||
|
|
||||||
|
this->hyprlandService->start();
|
||||||
this->trayService->start();
|
this->trayService->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,19 @@
|
|||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
|
|
||||||
#include "helpers/system.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
#include "widgets/date.hpp"
|
#include "widgets/date.hpp"
|
||||||
#include "widgets/spacer.hpp"
|
#include "widgets/spacer.hpp"
|
||||||
|
#include "widgets/todo.hpp"
|
||||||
#include "widgets/volumeWidget.hpp"
|
#include "widgets/volumeWidget.hpp"
|
||||||
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
|
|
||||||
#include "glibmm/main.h"
|
#include "glibmm/main.h"
|
||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
#include "sigc++/functors/mem_fun.h"
|
#include "sigc++/functors/mem_fun.h"
|
||||||
|
|
||||||
Bar::Bar(GdkMonitor *monitor) {
|
Bar::Bar(GdkMonitor *monitor, int monitorId)
|
||||||
|
: monitorId(monitorId) {
|
||||||
set_name("bar-window");
|
set_name("bar-window");
|
||||||
|
|
||||||
gtk_layer_init_for_window(this->gobj());
|
gtk_layer_init_for_window(this->gobj());
|
||||||
@@ -32,8 +35,10 @@ Bar::Bar(GdkMonitor *monitor) {
|
|||||||
|
|
||||||
set_child(main_box);
|
set_child(main_box);
|
||||||
|
|
||||||
this->volumeWidget = std::make_shared<VolumeWidget>();
|
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||||
this->trayWidget = std::make_shared<TrayWidget>();
|
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(monitorId);
|
||||||
|
this->trayWidget = Gtk::make_managed<TrayWidget>();
|
||||||
|
this->batteryWidget = Gtk::make_managed<BatteryWidget>();
|
||||||
|
|
||||||
load_css();
|
load_css();
|
||||||
setup_ui();
|
setup_ui();
|
||||||
@@ -56,12 +61,14 @@ void Bar::setup_ui() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Bar::setup_left_box() {
|
void Bar::setup_left_box() {
|
||||||
// left_box.append(*workspaceIndicator);
|
left_box.append(*workspaceIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bar::setup_center_box() {
|
void Bar::setup_center_box() {
|
||||||
center_box.set_hexpand(false);
|
center_box.set_hexpand(false);
|
||||||
|
|
||||||
|
center_box.append(*(new TodoPopover("\uf23a", "To-Do")));
|
||||||
|
center_box.append(*(new Spacer()));
|
||||||
center_box.append(this->date);
|
center_box.append(this->date);
|
||||||
center_box.append(*(new Spacer()));
|
center_box.append(*(new Spacer()));
|
||||||
center_box.append(this->clock);
|
center_box.append(this->clock);
|
||||||
@@ -71,6 +78,7 @@ void Bar::setup_center_box() {
|
|||||||
|
|
||||||
void Bar::setup_right_box() {
|
void Bar::setup_right_box() {
|
||||||
right_box.append(*this->trayWidget);
|
right_box.append(*this->trayWidget);
|
||||||
|
right_box.append(*this->batteryWidget);
|
||||||
right_box.append(this->homeAssistant);
|
right_box.append(this->homeAssistant);
|
||||||
right_box.append(this->controlCenter);
|
right_box.append(this->controlCenter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,18 @@
|
|||||||
|
|
||||||
#include "sigc++/functors/mem_fun.h"
|
#include "sigc++/functors/mem_fun.h"
|
||||||
|
|
||||||
Button::Button(const std::string label) : Gtk::Button(label) {
|
|
||||||
signal_clicked().connect(sigc::mem_fun(*this, &Button::on_clicked));
|
Button::Button(const std::string label)
|
||||||
|
: Gtk::Button(label) {
|
||||||
|
signal_clicked().connect(
|
||||||
|
sigc::mem_fun(*this, &Button::on_clicked));
|
||||||
this->add_css_class("button");
|
this->add_css_class("button");
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(Gtk::Image &image) : Gtk::Button() {
|
Button::Button(Gtk::Image &image)
|
||||||
|
: Gtk::Button() {
|
||||||
set_child(image);
|
set_child(image);
|
||||||
signal_clicked().connect(sigc::mem_fun(*this, &Button::on_clicked));
|
signal_clicked().connect(
|
||||||
|
sigc::mem_fun(*this, &Button::on_clicked));
|
||||||
this->add_css_class("button");
|
this->add_css_class("button");
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
#include "components/popover.hpp"
|
#include "components/popover.hpp"
|
||||||
|
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
#include "gtkmm/object.h"
|
||||||
|
|
||||||
Popover::Popover(const std::string icon, std::string name): Button(icon) {
|
Popover::Popover(const std::string icon, std::string name): Button(icon) {
|
||||||
signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window));
|
signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window));
|
||||||
|
|
||||||
set_name(name);
|
|
||||||
|
|
||||||
popover = new Gtk::Popover();
|
popover = new Gtk::Popover();
|
||||||
popover->set_parent(*this);
|
popover->set_parent(*this);
|
||||||
popover->set_autohide(true);
|
popover->set_autohide(true);
|
||||||
|
|||||||
47
src/components/todoEntry.cpp
Normal file
47
src/components/todoEntry.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include "components/todoEntry.hpp"
|
||||||
|
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
#include <string>
|
||||||
|
#include "components/base/button.hpp"
|
||||||
|
|
||||||
|
TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited)
|
||||||
|
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||||
|
this->id = id;
|
||||||
|
this->text = text;
|
||||||
|
this->signal_dismissed = signal_dismissed;
|
||||||
|
this->signal_edited = signal_edited;
|
||||||
|
|
||||||
|
auto box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||||
|
box->set_hexpand(true);
|
||||||
|
box->set_halign(Gtk::Align::START);
|
||||||
|
box->set_valign(Gtk::Align::CENTER);
|
||||||
|
box->set_name("todo-entry-box");
|
||||||
|
box->add_css_class("todo-entry-box");
|
||||||
|
append(*box);
|
||||||
|
|
||||||
|
auto label = Gtk::make_managed<Gtk::Label>(text);
|
||||||
|
label->set_halign(Gtk::Align::START);
|
||||||
|
label->set_valign(Gtk::Align::CENTER);
|
||||||
|
box->append(*label);
|
||||||
|
|
||||||
|
auto buttonBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||||
|
buttonBox->set_halign(Gtk::Align::END);
|
||||||
|
buttonBox->set_valign(Gtk::Align::CENTER);
|
||||||
|
append(*buttonBox);
|
||||||
|
|
||||||
|
auto dismissButton = Gtk::make_managed<Button>("\uf00d");
|
||||||
|
dismissButton->set_valign(Gtk::Align::CENTER);
|
||||||
|
dismissButton->set_tooltip_text("Dismiss");
|
||||||
|
|
||||||
|
dismissButton->signal_clicked().connect(sigc::mem_fun(*this, &TodoEntry::on_dismiss_clicked));
|
||||||
|
|
||||||
|
auto editButton = Gtk::make_managed<Button>("\uf044");
|
||||||
|
editButton->set_valign(Gtk::Align::CENTER);
|
||||||
|
|
||||||
|
buttonBox->append(*editButton);
|
||||||
|
buttonBox->append(*dismissButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoEntry::on_dismiss_clicked() {
|
||||||
|
this->signal_dismissed.emit(this->id);
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include "components/workspaceIndicator.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "gtkmm/gestureclick.h"
|
|
||||||
#include "gtkmm/label.h"
|
|
||||||
#include "gtkmm/overlay.h"
|
|
||||||
|
|
||||||
WorkspaceIndicator::WorkspaceIndicator(int id, std::string label, sigc::slot<void(int)> onClick)
|
|
||||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
|
||||||
|
|
||||||
overlay = std::make_shared<Gtk::Overlay>();
|
|
||||||
auto numLabel = Gtk::make_managed<Gtk::Label>(label);
|
|
||||||
auto pillContainer = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
|
||||||
|
|
||||||
auto gesture = Gtk::GestureClick::create();
|
|
||||||
gesture->set_button(GDK_BUTTON_PRIMARY);
|
|
||||||
gesture->signal_released().connect([this, id, onClick](int, double, double) {
|
|
||||||
onClick(
|
|
||||||
id);
|
|
||||||
});
|
|
||||||
|
|
||||||
overlay->add_controller(gesture);
|
|
||||||
overlay->add_css_class("workspace-pill");
|
|
||||||
|
|
||||||
if (id == 6 || id == 7) {
|
|
||||||
auto indicator = Gtk::make_managed<Gtk::Label>(id == 6 ? "🫱🏻" : "🫲🏻");
|
|
||||||
indicator->add_css_class(id == 6 ? "workspace-pill-six" : "workspace-pill-seven");
|
|
||||||
indicator->set_valign(Gtk::Align::END);
|
|
||||||
overlay->set_child(*indicator);
|
|
||||||
overlay->add_overlay(*numLabel);
|
|
||||||
pillContainer->append(*overlay);
|
|
||||||
} else {
|
|
||||||
overlay->set_child(*numLabel);
|
|
||||||
pillContainer->append(*overlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
append(*pillContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkspaceIndicator::setIndicatorState(InidicatorState state) {
|
|
||||||
this->clearCssClass();
|
|
||||||
this->currentState = state;
|
|
||||||
auto cssClass = this->stateToCssClass[state];
|
|
||||||
|
|
||||||
this->overlay->add_css_class(cssClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkspaceIndicator::clearCssClass() {
|
|
||||||
for (const auto &[_, cssClass] : stateToCssClass) {
|
|
||||||
this->overlay->remove_css_class(cssClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
237
src/services/bluetooth.cpp
Normal file
237
src/services/bluetooth.cpp
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
#include "services/bluetooth.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
|
||||||
|
BluetoothService::BluetoothService() {
|
||||||
|
GError *error = nullptr;
|
||||||
|
|
||||||
|
this->adapter_proxy = g_dbus_proxy_new_for_bus_sync(
|
||||||
|
G_BUS_TYPE_SYSTEM,
|
||||||
|
G_DBUS_PROXY_FLAGS_NONE,
|
||||||
|
nullptr,
|
||||||
|
"org.bluez",
|
||||||
|
"/org/bluez/hci0",
|
||||||
|
"org.bluez.Adapter1",
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cerr << "Error creating Bluetooth adapter proxy: "
|
||||||
|
<< error->message << std::endl;
|
||||||
|
g_error_free(error);
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->powerState = this->getPowerState();
|
||||||
|
this->isDiscovering = this->getIsDiscovering();
|
||||||
|
|
||||||
|
g_signal_connect(
|
||||||
|
this->adapter_proxy,
|
||||||
|
"g-properties-changed",
|
||||||
|
G_CALLBACK(BluetoothService::onPropertyChangedStatic),
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BluetoothService::getPowerState() {
|
||||||
|
GVariant *result = g_dbus_proxy_get_cached_property(
|
||||||
|
this->adapter_proxy,
|
||||||
|
"Powered");
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
std::cerr << "Error getting Powered property." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean powered;
|
||||||
|
g_variant_get(result, "b", &powered);
|
||||||
|
g_variant_unref(result);
|
||||||
|
|
||||||
|
return powered;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BluetoothService::getIsDiscovering() {
|
||||||
|
GVariant *result = g_dbus_proxy_get_cached_property(
|
||||||
|
this->adapter_proxy,
|
||||||
|
"Discovering");
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
std::cerr << "Error getting Discovering property." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean discovering;
|
||||||
|
g_variant_get(result, "b", &discovering);
|
||||||
|
g_variant_unref(result);
|
||||||
|
|
||||||
|
return discovering;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothService::togglePowerState() {
|
||||||
|
GError *error = nullptr;
|
||||||
|
bool state = !this->powerState;
|
||||||
|
|
||||||
|
GDBusConnection *connection = g_dbus_proxy_get_connection(this->adapter_proxy);
|
||||||
|
GVariant *reply = g_dbus_connection_call_sync(
|
||||||
|
connection,
|
||||||
|
"org.bluez",
|
||||||
|
"/org/bluez/hci0",
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
"Set",
|
||||||
|
g_variant_new(
|
||||||
|
"(ssv)",
|
||||||
|
"org.bluez.Adapter1",
|
||||||
|
"Powered",
|
||||||
|
g_variant_new_boolean(state)),
|
||||||
|
nullptr,
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cerr << "Error setting Powered property: "
|
||||||
|
<< error->message << std::endl;
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reply) {
|
||||||
|
g_variant_unref(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
this->powerState = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothService::toggleIsDiscovering() {
|
||||||
|
bool newState = !this->isDiscovering;
|
||||||
|
GError *error = nullptr;
|
||||||
|
|
||||||
|
const char *method = newState ? "StartDiscovery" : "StopDiscovery";
|
||||||
|
GVariant *reply = g_dbus_proxy_call_sync(
|
||||||
|
this->adapter_proxy,
|
||||||
|
method,
|
||||||
|
nullptr,
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cerr << "Error calling " << method << ": "
|
||||||
|
<< error->message << std::endl;
|
||||||
|
g_error_free(error);
|
||||||
|
|
||||||
|
if (reply) {
|
||||||
|
g_variant_unref(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->isDiscovering = newState;
|
||||||
|
|
||||||
|
if (reply) {
|
||||||
|
g_variant_unref(reply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothService::onPropertyChanged(GDBusProxy *proxy,
|
||||||
|
GVariant *changed_properties,
|
||||||
|
const gchar *const *invalidated_properties,
|
||||||
|
gpointer user_data) {
|
||||||
|
|
||||||
|
gboolean is_powered = FALSE;
|
||||||
|
gboolean is_discovering = FALSE;
|
||||||
|
|
||||||
|
if (g_variant_lookup(changed_properties, "Powered", "b", &is_powered)) {
|
||||||
|
|
||||||
|
if (!is_powered) {
|
||||||
|
this->isDiscovering = is_discovering;
|
||||||
|
isDiscoveringChangedSignal.emit(isDiscovering);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->powerState = is_powered;
|
||||||
|
powerStateChangedSignal.emit(powerState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_variant_lookup(changed_properties, "Discovering", "b", &is_discovering)) {
|
||||||
|
this->isDiscovering = is_discovering;
|
||||||
|
isDiscoveringChangedSignal.emit(isDiscovering);
|
||||||
|
getDeviceObjectPaths();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothService::onPropertyChangedStatic(GDBusProxy *proxy,
|
||||||
|
GVariant *changed_properties,
|
||||||
|
const gchar *const *invalidated_properties,
|
||||||
|
gpointer user_data) {
|
||||||
|
BluetoothService *service = static_cast<BluetoothService *>(user_data);
|
||||||
|
|
||||||
|
if (service) {
|
||||||
|
service->onPropertyChanged(proxy, changed_properties, invalidated_properties, user_data);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error: BluetoothService instance is null in static callback." << std::endl;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> BluetoothService::getDeviceObjectPaths() {
|
||||||
|
std::vector<std::string> device_paths;
|
||||||
|
|
||||||
|
GError *error = nullptr;
|
||||||
|
GDBusConnection *connection = g_dbus_proxy_get_connection(this->adapter_proxy);
|
||||||
|
GVariant *reply = g_dbus_connection_call_sync(
|
||||||
|
connection,
|
||||||
|
"org.bluez",
|
||||||
|
"/",
|
||||||
|
"org.freedesktop.DBus.ObjectManager",
|
||||||
|
"GetManagedObjects",
|
||||||
|
nullptr,
|
||||||
|
G_VARIANT_TYPE("(a{oa{sa{sv}}})"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
std::cerr << "Error calling GetManagedObjects: " << error->message << std::endl;
|
||||||
|
g_error_free(error);
|
||||||
|
return device_paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reply) {
|
||||||
|
return device_paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariant *objects = g_variant_get_child_value(reply, 0);
|
||||||
|
g_variant_unref(reply);
|
||||||
|
|
||||||
|
if (!objects) {
|
||||||
|
return device_paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariantIter iter;
|
||||||
|
g_variant_iter_init(&iter, objects);
|
||||||
|
|
||||||
|
const gchar *object_path = nullptr;
|
||||||
|
GVariant *interfaces = nullptr;
|
||||||
|
while (g_variant_iter_next(&iter, "{&o@a{sa{sv}}}", &object_path, &interfaces)) {
|
||||||
|
GVariant *device_props = nullptr;
|
||||||
|
if (g_variant_lookup(interfaces, "org.bluez.Device1", "@a{sv}", &device_props)) {
|
||||||
|
device_paths.emplace_back(object_path);
|
||||||
|
g_variant_unref(device_props);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_variant_unref(interfaces);
|
||||||
|
interfaces = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_variant_unref(objects);
|
||||||
|
return device_paths;
|
||||||
|
}
|
||||||
@@ -1,94 +1,63 @@
|
|||||||
#include "services/hyprland.hpp"
|
#include "services/hyprland.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <glib-unix.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <iterator>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
#include <unordered_set>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "helpers/hypr.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
#include "helpers/string.hpp"
|
|
||||||
|
|
||||||
#include "gtkmm/box.h"
|
HyprlandService::HyprlandService() = default;
|
||||||
|
|
||||||
HyprlandService::HyprlandService() {
|
HyprlandService::~HyprlandService() {
|
||||||
init();
|
if (fd != -1) {
|
||||||
bindSocket();
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// free allocated workspace pointers
|
||||||
|
for (auto &p : this->workspaces) {
|
||||||
|
delete p.second;
|
||||||
|
}
|
||||||
|
this->workspaces.clear();
|
||||||
|
this->monitors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::init() {
|
void HyprlandService::on_hyprland_event(std::string event, std::string data) {
|
||||||
auto monitorDataJson = HyprctlHelper::getMonitorData();
|
|
||||||
auto onClick = sigc::mem_fun(*this, &HyprlandService::switchToWorkspace);
|
|
||||||
|
|
||||||
for (const auto &item : monitorDataJson) {
|
if (event == "urgent") {
|
||||||
auto monitorPtr = std::make_shared<Monitor>();
|
onUrgentEvent(data);
|
||||||
|
|
||||||
std::string monitorName = item["name"].get<std::string>();
|
|
||||||
int monitorId = item["id"].get<int>();
|
|
||||||
|
|
||||||
monitorPtr->id = monitorId;
|
|
||||||
monitorPtr->name = monitorName;
|
|
||||||
monitorPtr->activeWorkspaceId = item["activeWorkspace"]["id"].get<int>();
|
|
||||||
monitorPtr->focused = item["focused"].get<bool>();
|
|
||||||
this->monitors[monitorPtr->name] = monitorPtr;
|
|
||||||
|
|
||||||
for (int i = 1; i <= NUM_WORKSPACES; i++) {
|
|
||||||
std::shared_ptr<WorkspaceData> state = std::make_shared<WorkspaceData>();
|
|
||||||
int workspaceId = i + (NUM_WORKSPACES * monitorId);
|
|
||||||
|
|
||||||
state->id = workspaceId;
|
|
||||||
state->monitorName = monitorName;
|
|
||||||
auto view = std::make_shared<WorkspaceIndicator>(workspaceId, std::to_string(i), onClick);
|
|
||||||
auto workSpace = std::make_shared<Workspace>();
|
|
||||||
workSpace->state = state;
|
|
||||||
workSpace->view = view;
|
|
||||||
|
|
||||||
monitorPtr->monitorWorkspaces[workspaceId] = workSpace;
|
|
||||||
this->workspaces[workspaceId] = workSpace;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clientsDataJson = HyprctlHelper::getClientData();
|
if (event == "activewindowv2") {
|
||||||
|
onActiveWindowEvent(data);
|
||||||
for (const auto &client : clientsDataJson) {
|
|
||||||
auto clientPtr = std::make_shared<Client>();
|
|
||||||
clientPtr->address = client["address"].get<std::string>();
|
|
||||||
clientPtr->workspaceId = client["workspace"]["id"].get<int>();
|
|
||||||
clientPtr->title = client["title"].get<std::string>();
|
|
||||||
this->clients[clientPtr->address] = clientPtr;
|
|
||||||
|
|
||||||
auto workspacePtr = workspaces[clientPtr->workspaceId];
|
|
||||||
workspacePtr->state->clients[clientPtr->address] = clientPtr;
|
|
||||||
|
|
||||||
if (client.contains("urgent") && client["urgent"].get<bool>()) {
|
|
||||||
workspacePtr->state->urgentClients.insert(clientPtr->address);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto workspaceDataJson = HyprctlHelper::getWorkspaceData();
|
if (event == "workspace" || event == "movewindow") {
|
||||||
|
refresh_workspaces();
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &workspace : workspaceDataJson) {
|
if (event == "monitoradded" || event == "monitorremoved") {
|
||||||
auto workspacePtr = workspaces[workspace["id"].get<int>()];
|
refresh_monitors();
|
||||||
auto state = workspacePtr->state;
|
|
||||||
|
|
||||||
state->id = workspace["id"].get<int>();
|
|
||||||
state->monitorName = workspace["monitor"].get<std::string>();
|
|
||||||
|
|
||||||
refreshIndicator(workspacePtr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::bindSocket() {
|
void HyprlandService::start() {
|
||||||
std::string socketPath = HyprSocketHelper::getHyprlandSocketPath();
|
const std::string socket_path = get_socket_path();
|
||||||
|
if (socket_path.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (socketFd == -1) {
|
if (fd == -1) {
|
||||||
std::cerr << "[Hyprland] Failed to create socket" << std::endl;
|
std::cerr << "[Hyprland] Failed to create socket" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,232 +65,282 @@ void HyprlandService::bindSocket() {
|
|||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
std::strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
std::strncpy(addr.sun_path, socket_path.c_str(), sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
if (connect(socketFd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) == -1) {
|
|
||||||
std::cerr << "[Hyprland] Failed to connect to " << socketPath << std::endl;
|
|
||||||
close(socketFd);
|
|
||||||
socketFd = -1;
|
|
||||||
|
|
||||||
|
if (connect(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) ==
|
||||||
|
-1) {
|
||||||
|
std::cerr << "[Hyprland] Failed to connect to " << socket_path
|
||||||
|
<< std::endl;
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSource *source = g_unix_fd_source_new(socketFd, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR));
|
Glib::signal_io().connect(
|
||||||
|
sigc::mem_fun(*this, &HyprlandService::on_socket_read), fd,
|
||||||
|
Glib::IOCondition::IO_IN | Glib::IOCondition::IO_HUP |
|
||||||
|
Glib::IOCondition::IO_ERR);
|
||||||
|
|
||||||
auto onSocketEvent = [](gint fd, GIOCondition , gpointer user_data) -> gboolean {
|
refresh_monitors();
|
||||||
HyprlandService *self = static_cast<HyprlandService *>(user_data);
|
}
|
||||||
auto messages = SocketHelper::parseSocketMessage(fd, ">>");
|
|
||||||
|
|
||||||
for (const auto &message : messages) {
|
bool HyprlandService::on_socket_read(Glib::IOCondition condition) {
|
||||||
self->handleSocketMessage(message);
|
const auto error_mask = Glib::IOCondition::IO_HUP | Glib::IOCondition::IO_ERR;
|
||||||
|
|
||||||
|
if (static_cast<int>(condition & error_mask) != 0) {
|
||||||
|
std::cerr << "[Hyprland] Socket disconnected." << std::endl;
|
||||||
|
if (fd != -1) {
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return G_SOURCE_CONTINUE;
|
char temp_buffer[4096];
|
||||||
};
|
const ssize_t bytes_read = read(fd, temp_buffer, sizeof(temp_buffer));
|
||||||
|
|
||||||
g_source_set_callback(source, reinterpret_cast<GSourceFunc>(reinterpret_cast<void*>(+onSocketEvent)), this, nullptr);
|
if (bytes_read <= 0) {
|
||||||
g_source_attach(source, g_main_context_default());
|
// peer closed or error
|
||||||
g_source_unref(source);
|
std::cerr << "[Hyprland] Socket read returned " << bytes_read << std::endl;
|
||||||
|
if (fd != -1) {
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append exactly bytes_read bytes (may contain embedded nulls)
|
||||||
|
this->socket_buffer.append(temp_buffer, static_cast<size_t>(bytes_read));
|
||||||
|
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = this->socket_buffer.find('\n')) != std::string::npos) {
|
||||||
|
const std::string line = this->socket_buffer.substr(0, pos);
|
||||||
|
parse_message(line);
|
||||||
|
this->socket_buffer.erase(0, pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::onWorkspaceChanged(int workspaceId) {
|
void HyprlandService::parse_message(const std::string &line) {
|
||||||
auto newActive = workspaces[workspaceId];
|
const size_t split = line.find(">>");
|
||||||
auto state = newActive->state;
|
if (split != std::string::npos) {
|
||||||
auto monitorPtr = monitors[state->monitorName];
|
const std::string event_name = line.substr(0, split);
|
||||||
|
const std::string event_data = line.substr(split + 2);
|
||||||
|
|
||||||
int oldActiveWorkspaceId = monitorPtr->activeWorkspaceId;
|
socketEventSignal.emit(event_name, event_data);
|
||||||
auto oldActive = workspaces[oldActiveWorkspaceId];
|
}
|
||||||
|
|
||||||
monitorPtr->activeWorkspaceId = workspaceId;
|
|
||||||
|
|
||||||
refreshIndicator(newActive);
|
|
||||||
refreshIndicator(oldActive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::onFocusedMonitorChanged(std::string monitorData) {
|
std::string HyprlandService::get_socket_path() {
|
||||||
std::string monitorName = StringHelper::split(monitorData, ',')[0];
|
const char *sig = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
const char *runtime = std::getenv("XDG_RUNTIME_DIR");
|
||||||
|
|
||||||
for (const auto &[_, monitorPtr] : monitors) {
|
if (!sig || !runtime) {
|
||||||
std::string itMonitorName = monitorPtr->name;
|
std::cerr << "[Hyprland] Environment variables missing!" << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (itMonitorName == monitorName) {
|
return std::string(runtime) + "/hypr/" + sig + "/.socket2.sock";
|
||||||
monitorPtr->focused = true;
|
}
|
||||||
|
|
||||||
int activeWorkspaceId = monitorPtr->activeWorkspaceId;
|
void HyprlandService::refresh_monitors() {
|
||||||
auto activeWorkspace = workspaces[activeWorkspaceId];
|
// free any previously allocated WorkspaceState objects before rebuilding
|
||||||
refreshIndicator(activeWorkspace);
|
for (auto &p : this->workspaces) {
|
||||||
|
delete p.second;
|
||||||
|
}
|
||||||
|
this->workspaces.clear();
|
||||||
|
this->monitors.clear();
|
||||||
|
|
||||||
|
std::string output = SystemHelper::get_command_output(kMonitorCommand);
|
||||||
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
|
Monitor monitor;
|
||||||
|
monitor.id = monitorJson.value("id", -1);
|
||||||
|
monitor.name = monitorJson.value("name", "");
|
||||||
|
monitor.x = monitorJson.value("x", 0);
|
||||||
|
monitor.y = monitorJson.value("y", 0);
|
||||||
|
|
||||||
|
monitor.focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||||
|
|
||||||
|
if (monitor.id >= 0) {
|
||||||
|
this->monitors[monitor.id] = monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount; ++slot) {
|
||||||
|
WorkspaceState wsState;
|
||||||
|
wsState.focused = false;
|
||||||
|
wsState.active = false;
|
||||||
|
wsState.label = std::to_string(slot);
|
||||||
|
wsState.monitorId = monitor.id;
|
||||||
|
|
||||||
|
int id = slot + monitor.id * HyprlandService::kWorkspaceSlotCount;
|
||||||
|
wsState.hyprId = id;
|
||||||
|
this->workspaces[id] = new WorkspaceState(wsState);
|
||||||
|
if (monitor.id >= 0) {
|
||||||
|
this->monitors[monitor.id].workspaceStates[slot] = this->workspaces[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->refresh_workspaces();
|
||||||
|
monitorStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called every time when workspace changes have been detected.
|
||||||
|
* Used to Update the internal state for the Workspaces,
|
||||||
|
*/
|
||||||
|
void HyprlandService::refresh_workspaces() {
|
||||||
|
std::string output = SystemHelper::get_command_output(kWorkspaceCommand);
|
||||||
|
auto workspacesJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (auto &[id, ws] : this->workspaces) {
|
||||||
|
ws->focused = false;
|
||||||
|
ws->active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
output = SystemHelper::get_command_output(kMonitorCommand);
|
||||||
|
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (const auto &monitorJson : monitorsJson) {
|
||||||
|
const int monitorId = monitorJson.value("id", -1);
|
||||||
|
const int focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||||
|
|
||||||
|
// write into the stored monitor (use reference)
|
||||||
|
auto it = this->monitors.find(monitorId);
|
||||||
|
if (it != this->monitors.end()) {
|
||||||
|
it->second.focusedWorkspaceId = focusedWorkspaceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string clientsOutput = SystemHelper::get_command_output(kClientsCommand);
|
||||||
|
auto clientsJson = nlohmann::json::parse(clientsOutput, nullptr, false);
|
||||||
|
std::unordered_set<std::string> liveClientAddresses;
|
||||||
|
for (const auto &clientJson : clientsJson) {
|
||||||
|
const std::string addr = clientJson.value("address", "");
|
||||||
|
if (addr.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr.rfind("0x", 0) == 0) {
|
||||||
|
liveClientAddresses.insert(addr.substr(2));
|
||||||
} else {
|
} else {
|
||||||
monitorPtr->focused = false;
|
liveClientAddresses.insert(addr);
|
||||||
|
|
||||||
int activeWorkspaceId = monitorPtr->activeWorkspaceId;
|
|
||||||
auto activeWorkspace = workspaces[activeWorkspaceId];
|
|
||||||
refreshIndicator(activeWorkspace);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void HyprlandService::onMonitorRemoved(std::string monitorName) {
|
for (const auto &workspaceJson : workspacesJson) {
|
||||||
auto monitorPtr = this->monitors[monitorName];
|
const int workspaceId = workspaceJson.value("id", -1);
|
||||||
|
auto workspaceStateIt = this->workspaces.find(workspaceId);
|
||||||
for (const auto &[wsId, wsPtr] : monitorPtr->monitorWorkspaces) {
|
if (workspaceStateIt == this->workspaces.end()) {
|
||||||
this->workspaces.erase(wsId);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorPtr->monitorWorkspaces.clear();
|
WorkspaceState *workspaceState = workspaceStateIt->second;
|
||||||
monitorPtr->bar->close();
|
auto mit = this->monitors.find(workspaceState->monitorId);
|
||||||
|
if (mit != this->monitors.end()) {
|
||||||
this->monitors.erase(monitorName);
|
workspaceState->focused = mit->second.focusedWorkspaceId == workspaceId;
|
||||||
}
|
} else {
|
||||||
|
workspaceState->focused = false;
|
||||||
// void HyprlandService::onMonitorAdded(std::string monitorName) {
|
}
|
||||||
// // this->signalMonitorAdded.emit();
|
workspaceState->active = true;
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
void HyprlandService::onOpenWindow(std::string windowData) {
|
|
||||||
auto parts = StringHelper::split(windowData, ',');
|
|
||||||
std::string addr = "0x" + parts[0];
|
|
||||||
int workspaceId = std::stoi(parts[1]);
|
|
||||||
std::string title = parts[2];
|
|
||||||
|
|
||||||
auto clientPtr = std::make_shared<Client>();
|
|
||||||
clientPtr->address = addr;
|
|
||||||
clientPtr->workspaceId = workspaceId;
|
|
||||||
clientPtr->title = title;
|
|
||||||
this->clients[clientPtr->address] = clientPtr;
|
|
||||||
auto workspacePtr = workspaces[clientPtr->workspaceId];
|
|
||||||
workspacePtr->state->clients[clientPtr->address] = clientPtr;
|
|
||||||
|
|
||||||
refreshIndicator(workspacePtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HyprlandService::onCloseWindow(std::string windowData) {
|
|
||||||
auto parts = StringHelper::split(windowData, ',');
|
|
||||||
std::string addr = "0x" + parts[0];
|
|
||||||
|
|
||||||
if (this->clients.find(addr) == this->clients.end()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clientPtr = this->clients[addr];
|
// drop urgent flags for windows no longer reported by hyprctl clients
|
||||||
int workspaceId = clientPtr->workspaceId;
|
for (auto &[id, ws] : this->workspaces) {
|
||||||
|
auto &urgent = ws->urgentWindows;
|
||||||
auto workspacePtr = workspaces[workspaceId];
|
auto newEnd = std::remove_if(urgent.begin(), urgent.end(), [&](const std::string &addr) {
|
||||||
workspacePtr->state->clients.erase(addr);
|
return liveClientAddresses.find(addr) == liveClientAddresses.end();
|
||||||
this->clients.erase(addr);
|
});
|
||||||
|
if (newEnd != urgent.end()) {
|
||||||
refreshIndicator(workspacePtr);
|
urgent.erase(newEnd, urgent.end());
|
||||||
}
|
|
||||||
|
|
||||||
void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
|
|
||||||
if (socketEventTypeMap.find(message.eventType) == socketEventTypeMap.end()) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SocketEventType eventType = socketEventTypeMap[message.eventType];
|
|
||||||
std::string eventData = message.eventData;
|
|
||||||
|
|
||||||
switch (eventType) {
|
|
||||||
case FOCUSED_MONITOR: {
|
|
||||||
onFocusedMonitorChanged(eventData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WORKSPACE_CHANGED: {
|
|
||||||
this->onWorkspaceChanged(std::stoi(eventData));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OPEN_WINDOW: {
|
|
||||||
this->onOpenWindow(eventData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLOSE_WINDOW: {
|
|
||||||
this->onCloseWindow(eventData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case URGENT: {
|
|
||||||
this->onUrgent(eventData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTIVE_WINDOW: {
|
|
||||||
this->onActiveWindowChanged(eventData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MONITOR_REMOVED: {
|
|
||||||
this->onMonitorRemoved(eventData);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void HyprlandService::onUrgent(std::string windowAddress) {
|
|
||||||
std::string addr = "0x" + windowAddress;
|
|
||||||
if (this->clients.find(addr) == this->clients.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto clientPtr = this->clients[addr];
|
workspaceStateChanged.emit();
|
||||||
int workspaceId = clientPtr->workspaceId;
|
|
||||||
|
|
||||||
auto workspacePtr = workspaces[workspaceId];
|
|
||||||
workspacePtr->state->urgentClients.insert(addr);
|
|
||||||
|
|
||||||
refreshIndicator(workspacePtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HyprlandService::onActiveWindowChanged(std::string windowAddress) {
|
|
||||||
std::string addr = "0x" + windowAddress;
|
|
||||||
if (this->clients.find(addr) == this->clients.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto clientPtr = this->clients[addr];
|
|
||||||
int workspaceId = clientPtr->workspaceId;
|
|
||||||
|
|
||||||
auto workspacePtr = workspaces[workspaceId];
|
|
||||||
workspacePtr->state->urgentClients.erase(addr);
|
|
||||||
|
|
||||||
refreshIndicator(workspacePtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Gtk::Box> HyprlandService::getWorkspaceIndicatorsForMonitor(std::string monitorName) {
|
|
||||||
auto box = std::make_shared<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
|
||||||
auto monitor = monitors[monitorName];
|
|
||||||
|
|
||||||
for (const auto &[wsId, wsPair] : monitor->monitorWorkspaces) {
|
|
||||||
box->append((Gtk::Box &)*wsPair->view);
|
|
||||||
}
|
|
||||||
|
|
||||||
return box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::switchToWorkspace(int workspaceId) {
|
void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||||
HyprctlHelper::dispatchWorkspace(workspaceId);
|
std::string cmd =
|
||||||
}
|
"hyprctl dispatch workspace " + std::to_string(workspaceId);
|
||||||
|
|
||||||
void HyprlandService::refreshIndicator(std::shared_ptr<Workspace> workspace) {
|
try {
|
||||||
auto view = workspace->view;
|
(void)SystemHelper::get_command_output(cmd.c_str());
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
auto state = workspace->state;
|
std::cerr << "[Hyprland] Failed to dispatch workspace command: "
|
||||||
auto monitorsPtr = monitors[state->monitorName];
|
<< ex.what() << " cmd=" << cmd << std::endl;
|
||||||
|
|
||||||
bool isUrgent = !state->urgentClients.empty();
|
|
||||||
bool isEmpty = state->clients.empty();
|
|
||||||
bool isPreseneting = state->id == monitorsPtr->activeWorkspaceId;
|
|
||||||
bool isFocused = monitorsPtr->focused && isPreseneting;
|
|
||||||
|
|
||||||
if (isUrgent) {
|
|
||||||
view->setIndicatorState(WorkspaceIndicator::URGENT);
|
|
||||||
} else if (isFocused) {
|
|
||||||
view->setIndicatorState(WorkspaceIndicator::FOCUSED);
|
|
||||||
} else if (isPreseneting) {
|
|
||||||
view->setIndicatorState(WorkspaceIndicator::PRESENTING);
|
|
||||||
} else if (!isEmpty) {
|
|
||||||
view->setIndicatorState(WorkspaceIndicator::ALIVE);
|
|
||||||
} else {
|
|
||||||
view->setIndicatorState(WorkspaceIndicator::EMPTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprlandService::addBar(std::shared_ptr<Bar> bar, std::string monitorName) {
|
void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||||
this->monitors[monitorName]->bar = bar;
|
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||||
|
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (const auto &clientJson : clientsJson) {
|
||||||
|
const std::string addr = clientJson.value("address", "");
|
||||||
|
|
||||||
|
if (addr == "0x" + windowAddress) {
|
||||||
|
int workspaceId = clientJson["workspace"].value("id", -1);
|
||||||
|
|
||||||
|
auto it = this->workspaces.find(workspaceId);
|
||||||
|
if (it != this->workspaces.end() && it->second) {
|
||||||
|
|
||||||
|
WorkspaceState *ws = it->second;
|
||||||
|
auto uit = std::find(ws->urgentWindows.begin(), ws->urgentWindows.end(), windowAddress);
|
||||||
|
if (uit == ws->urgentWindows.end()) {
|
||||||
|
ws->urgentWindows.push_back(windowAddress);
|
||||||
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
|
||||||
|
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||||
|
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||||
|
|
||||||
|
for (const auto &clientJson : clientsJson) {
|
||||||
|
const std::string addr = clientJson.value("address", "");
|
||||||
|
|
||||||
|
if (addr == "0x" + windowAddress) {
|
||||||
|
int workspaceId = clientJson["workspace"]["id"];
|
||||||
|
auto it = this->workspaces.find(workspaceId);
|
||||||
|
if (it != this->workspaces.end() && it->second) {
|
||||||
|
WorkspaceState *ws = it->second;
|
||||||
|
auto uit = std::find(ws->urgentWindows.begin(), ws->urgentWindows.end(), windowAddress);
|
||||||
|
if (uit != ws->urgentWindows.end()) {
|
||||||
|
ws->urgentWindows.erase(uit);
|
||||||
|
workspaceStateChanged.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HyprlandService::Monitor *HyprlandService::getMonitorById(int id) {
|
||||||
|
auto it = monitors.find(id);
|
||||||
|
if (it == monitors.end()) {
|
||||||
|
throw std::runtime_error("Monitor with ID " + std::to_string(id) +
|
||||||
|
" not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
HyprlandService::Monitor *HyprlandService::getMonitorByIndex(std::size_t index) {
|
||||||
|
if (index >= monitors.size()) {
|
||||||
|
throw std::runtime_error("Monitor index out of bounds: " + std::to_string(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = monitors.begin();
|
||||||
|
std::advance(it, static_cast<long>(index));
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
}
|
}
|
||||||
305
src/services/notifications.cpp
Normal file
305
src/services/notifications.cpp
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
#include "services/notifications.hpp"
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static constexpr const char *kNotificationsObjectPath = "/org/freedesktop/Notifications";
|
||||||
|
static constexpr const char *kNotificationsInterface = "org.freedesktop.Notifications";
|
||||||
|
|
||||||
|
static const char *kNotificationsIntrospectionXml = R"XML(
|
||||||
|
<node>
|
||||||
|
<interface name="org.freedesktop.Notifications">
|
||||||
|
<method name="Notify">
|
||||||
|
<arg type="s" direction="in"/>
|
||||||
|
<arg type="u" direction="in"/>
|
||||||
|
<arg type="s" direction="in"/>
|
||||||
|
<arg type="s" direction="in"/>
|
||||||
|
<arg type="s" direction="in"/>
|
||||||
|
<arg type="as" direction="in"/>
|
||||||
|
<arg type="a{sv}" direction="in"/>
|
||||||
|
<arg type="i" direction="in"/>
|
||||||
|
<arg type="u" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="CloseNotification">
|
||||||
|
<arg type="u" direction="in"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetCapabilities">
|
||||||
|
<arg type="as" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetServerInformation">
|
||||||
|
<arg type="s" direction="out"/>
|
||||||
|
<arg type="s" direction="out"/>
|
||||||
|
<arg type="s" direction="out"/>
|
||||||
|
<arg type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<signal name="NotificationClosed">
|
||||||
|
<arg type="u"/>
|
||||||
|
<arg type="u"/>
|
||||||
|
</signal>
|
||||||
|
<signal name="ActionInvoked">
|
||||||
|
<arg type="u"/>
|
||||||
|
<arg type="s"/>
|
||||||
|
</signal>
|
||||||
|
<signal name="ActivationToken">
|
||||||
|
<arg type="u"/>
|
||||||
|
<arg type="s"/>
|
||||||
|
</signal>
|
||||||
|
</interface>
|
||||||
|
</node>)XML";
|
||||||
|
|
||||||
|
static void on_method_call(GDBusConnection * /*connection*/,
|
||||||
|
const gchar * /*sender*/,
|
||||||
|
const gchar * /*object_path*/,
|
||||||
|
const gchar *interface_name,
|
||||||
|
const gchar *method_name,
|
||||||
|
GVariant *parameters,
|
||||||
|
GDBusMethodInvocation *invocation,
|
||||||
|
gpointer user_data) {
|
||||||
|
auto *self = static_cast<NotificationService *>(user_data);
|
||||||
|
|
||||||
|
if (g_strcmp0(interface_name, kNotificationsInterface) != 0) {
|
||||||
|
g_dbus_method_invocation_return_dbus_error(
|
||||||
|
invocation,
|
||||||
|
"org.freedesktop.DBus.Error.UnknownInterface",
|
||||||
|
"Unknown interface");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(method_name, "Notify") == 0) {
|
||||||
|
const gchar *app_name = "";
|
||||||
|
guint32 replaces_id = 0;
|
||||||
|
const gchar *app_icon = "";
|
||||||
|
const gchar *summary = "";
|
||||||
|
const gchar *body = "";
|
||||||
|
GVariant *actions = nullptr;
|
||||||
|
GVariant *hints = nullptr;
|
||||||
|
gint32 expire_timeout = -1;
|
||||||
|
|
||||||
|
g_variant_get(parameters, "(&su&s&s&s@as@a{sv}i)",
|
||||||
|
&app_name,
|
||||||
|
&replaces_id,
|
||||||
|
&app_icon,
|
||||||
|
&summary,
|
||||||
|
&body,
|
||||||
|
&actions,
|
||||||
|
&hints,
|
||||||
|
&expire_timeout);
|
||||||
|
|
||||||
|
std::cout << "--- Notification ---" << std::endl;
|
||||||
|
std::cout << "App: " << (app_name ? app_name : "") << std::endl;
|
||||||
|
std::cout << "Title: " << (summary ? summary : "") << std::endl;
|
||||||
|
std::cout << "Body: " << (body ? body : "") << std::endl;
|
||||||
|
|
||||||
|
if (actions)
|
||||||
|
g_variant_unref(actions);
|
||||||
|
if (hints)
|
||||||
|
g_variant_unref(hints);
|
||||||
|
|
||||||
|
guint32 id = self->allocateNotificationId(replaces_id);
|
||||||
|
g_dbus_method_invocation_return_value(invocation, g_variant_new("(u)", id));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(method_name, "GetCapabilities") == 0) {
|
||||||
|
// Advertise common capabilities so clients don't disable notifications.
|
||||||
|
// (Many apps probe this first and may skip Notify if it's empty.)
|
||||||
|
const gchar *caps[] = {
|
||||||
|
"body",
|
||||||
|
"actions",
|
||||||
|
"body-markup",
|
||||||
|
"icon-static",
|
||||||
|
"persistence",
|
||||||
|
nullptr};
|
||||||
|
GVariant *capsV = g_variant_new_strv(caps, -1);
|
||||||
|
g_dbus_method_invocation_return_value(invocation, g_variant_new("(@as)", capsV));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(method_name, "GetServerInformation") == 0) {
|
||||||
|
g_dbus_method_invocation_return_value(
|
||||||
|
invocation,
|
||||||
|
g_variant_new("(ssss)", "bar", "bar", "0.1", "1.2"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(method_name, "CloseNotification") == 0) {
|
||||||
|
guint32 id = 0;
|
||||||
|
g_variant_get(parameters, "(u)", &id);
|
||||||
|
|
||||||
|
// reason: 3 = closed by call to CloseNotification
|
||||||
|
if (self && self->getConnection()) {
|
||||||
|
g_dbus_connection_emit_signal(
|
||||||
|
self->getConnection(),
|
||||||
|
nullptr,
|
||||||
|
kNotificationsObjectPath,
|
||||||
|
kNotificationsInterface,
|
||||||
|
"NotificationClosed",
|
||||||
|
g_variant_new("(uu)", id, 3u),
|
||||||
|
nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_dbus_method_invocation_return_value(invocation, nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_dbus_method_invocation_return_dbus_error(
|
||||||
|
invocation,
|
||||||
|
"org.freedesktop.DBus.Error.UnknownMethod",
|
||||||
|
"Unknown method");
|
||||||
|
}
|
||||||
|
|
||||||
|
guint32 NotificationService::allocateNotificationId(guint32 replacesId) {
|
||||||
|
if (replacesId != 0)
|
||||||
|
return replacesId;
|
||||||
|
return this->nextNotificationId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const GDBusInterfaceVTable kVTable = {
|
||||||
|
.method_call = on_method_call,
|
||||||
|
.get_property = nullptr,
|
||||||
|
.set_property = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationService::~NotificationService() {
|
||||||
|
if (this->connection) {
|
||||||
|
// Best-effort release of the well-known name.
|
||||||
|
{
|
||||||
|
GError *error = nullptr;
|
||||||
|
GVariant *releaseResult = g_dbus_connection_call_sync(
|
||||||
|
this->connection,
|
||||||
|
"org.freedesktop.DBus",
|
||||||
|
"/org/freedesktop/DBus",
|
||||||
|
"org.freedesktop.DBus",
|
||||||
|
"ReleaseName",
|
||||||
|
g_variant_new("(s)", "org.freedesktop.Notifications"),
|
||||||
|
G_VARIANT_TYPE("(u)"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
if (releaseResult)
|
||||||
|
g_variant_unref(releaseResult);
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->registrationId != 0) {
|
||||||
|
g_dbus_connection_unregister_object(this->connection, this->registrationId);
|
||||||
|
this->registrationId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref(this->connection);
|
||||||
|
this->connection = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->nodeInfo) {
|
||||||
|
g_dbus_node_info_unref(this->nodeInfo);
|
||||||
|
this->nodeInfo = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationService::intialize() {
|
||||||
|
GError *error = nullptr;
|
||||||
|
|
||||||
|
if (this->connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, nullptr, &error);
|
||||||
|
if (!address) {
|
||||||
|
std::cerr << "Failed to get session bus address: " << (error ? error->message : "unknown error") << std::endl;
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
g_error_free(error);
|
||||||
|
error = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->connection = g_dbus_connection_new_for_address_sync(
|
||||||
|
address,
|
||||||
|
static_cast<GDBusConnectionFlags>(
|
||||||
|
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
|
||||||
|
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
g_free(address);
|
||||||
|
|
||||||
|
if (!this->connection) {
|
||||||
|
std::cerr << "Failed to connect to session bus: " << (error ? error->message : "unknown error") << std::endl;
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
g_error_free(error);
|
||||||
|
error = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->nodeInfo = g_dbus_node_info_new_for_xml(kNotificationsIntrospectionXml, &error);
|
||||||
|
if (!this->nodeInfo) {
|
||||||
|
std::cerr << "Failed to create introspection data: " << (error ? error->message : "unknown error") << std::endl;
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GDBusInterfaceInfo *iface = g_dbus_node_info_lookup_interface(this->nodeInfo, kNotificationsInterface);
|
||||||
|
if (!iface) {
|
||||||
|
std::cerr << "Missing interface info for org.freedesktop.Notifications" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->registrationId = g_dbus_connection_register_object(
|
||||||
|
this->connection,
|
||||||
|
kNotificationsObjectPath,
|
||||||
|
iface,
|
||||||
|
&kVTable,
|
||||||
|
this,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (this->registrationId == 0) {
|
||||||
|
std::cerr << "Failed to register notifications object: " << (error ? error->message : "unknown error") << std::endl;
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request the well-known name synchronously so we can detect conflicts.
|
||||||
|
// Reply codes: 1=PRIMARY_OWNER, 2=IN_QUEUE, 3=EXISTS, 4=ALREADY_OWNER
|
||||||
|
GVariant *requestResult = g_dbus_connection_call_sync(
|
||||||
|
this->connection,
|
||||||
|
"org.freedesktop.DBus",
|
||||||
|
"/org/freedesktop/DBus",
|
||||||
|
"org.freedesktop.DBus",
|
||||||
|
"RequestName",
|
||||||
|
g_variant_new("(su)", "org.freedesktop.Notifications", 0u),
|
||||||
|
G_VARIANT_TYPE("(u)"),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (!requestResult) {
|
||||||
|
std::cerr << "Failed to RequestName(org.freedesktop.Notifications): "
|
||||||
|
<< (error ? error->message : "unknown error") << std::endl;
|
||||||
|
if (error)
|
||||||
|
g_error_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
guint32 reply = 0;
|
||||||
|
g_variant_get(requestResult, "(u)", &reply);
|
||||||
|
g_variant_unref(requestResult);
|
||||||
|
|
||||||
|
if (reply != 1u && reply != 4u) {
|
||||||
|
std::cerr << "org.freedesktop.Notifications is already owned (RequestName reply=" << reply
|
||||||
|
<< "). Stop your existing notification daemon (e.g. dunst/mako/swaync) or allow replacement." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
164
src/services/sqliteTodoAdapter.cpp
Normal file
164
src/services/sqliteTodoAdapter.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
#include "services/todoAdapter.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string getDbPath() {
|
||||||
|
const char *homeDir = getenv("HOME");
|
||||||
|
if (!homeDir) {
|
||||||
|
return "todos.db";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string path = std::string(homeDir) + "/.config/bar";
|
||||||
|
if (!std::filesystem::exists(path)) {
|
||||||
|
std::filesystem::create_directories(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path + "/todos.db";
|
||||||
|
}
|
||||||
|
|
||||||
|
class SqliteTodoAdapter final : public ITodoAdapter {
|
||||||
|
public:
|
||||||
|
~SqliteTodoAdapter() override {
|
||||||
|
if (db_) {
|
||||||
|
sqlite3_close(db_);
|
||||||
|
db_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool init() override {
|
||||||
|
std::string dbPath = getDbPath();
|
||||||
|
|
||||||
|
int rc = sqlite3_open(dbPath.c_str(), &db_);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "Can't open database: " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *sql = "CREATE TABLE IF NOT EXISTS todos ("
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||||
|
"text TEXT NOT NULL);";
|
||||||
|
char *zErrMsg = nullptr;
|
||||||
|
rc = sqlite3_exec(db_, sql, nullptr, nullptr, &zErrMsg);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "SQL error (create table): " << (zErrMsg ? zErrMsg : "") << std::endl;
|
||||||
|
sqlite3_free(zErrMsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<TodoRecord> listTodos() override {
|
||||||
|
std::vector<TodoRecord> results;
|
||||||
|
if (!db_) {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_stmt *stmt = nullptr;
|
||||||
|
const char *sql = "SELECT id, text FROM todos";
|
||||||
|
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "Failed to fetch data: " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
|
||||||
|
int id = sqlite3_column_int(stmt, 0);
|
||||||
|
const unsigned char *txt = sqlite3_column_text(stmt, 1);
|
||||||
|
results.push_back({id, txt ? reinterpret_cast<const char *>(txt) : ""});
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addTodo(const std::string &text) override {
|
||||||
|
if (!db_) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_stmt *stmt = nullptr;
|
||||||
|
const char *sql = "INSERT INTO todos (text) VALUES (?1);";
|
||||||
|
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "SQL prepare error (insert): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_text(stmt, 1, text.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
rc = sqlite3_step(stmt);
|
||||||
|
if (rc != SQLITE_DONE) {
|
||||||
|
std::cerr << "SQL step error (insert): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return static_cast<int>(sqlite3_last_insert_rowid(db_));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool removeTodo(int id) override {
|
||||||
|
if (!db_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_stmt *stmt = nullptr;
|
||||||
|
const char *sql = "DELETE FROM todos WHERE id = ?1;";
|
||||||
|
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "SQL prepare error (delete): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_int(stmt, 1, id);
|
||||||
|
rc = sqlite3_step(stmt);
|
||||||
|
if (rc != SQLITE_DONE) {
|
||||||
|
std::cerr << "SQL step error (delete): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool updateTodo(int id, const std::string &text) override {
|
||||||
|
if (!db_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_stmt *stmt = nullptr;
|
||||||
|
const char *sql = "UPDATE todos SET text = ?1 WHERE id = ?2;";
|
||||||
|
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
std::cerr << "SQL prepare error (update): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_text(stmt, 1, text.c_str(), -1, SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_int(stmt, 2, id);
|
||||||
|
rc = sqlite3_step(stmt);
|
||||||
|
if (rc != SQLITE_DONE) {
|
||||||
|
std::cerr << "SQL step error (update): " << sqlite3_errmsg(db_) << std::endl;
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
sqlite3 *db_ = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Factory kept local to this TU for now; TodoService uses it.
|
||||||
|
std::unique_ptr<ITodoAdapter> makeSqliteTodoAdapter() {
|
||||||
|
return std::make_unique<SqliteTodoAdapter>();
|
||||||
|
}
|
||||||
128
src/services/todo.cpp
Normal file
128
src/services/todo.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#include "services/todo.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <gtkmm/object.h>
|
||||||
|
|
||||||
|
#include "components/todoEntry.hpp"
|
||||||
|
|
||||||
|
std::unique_ptr<ITodoAdapter> makeSqliteTodoAdapter();
|
||||||
|
|
||||||
|
TodoService::TodoService(sigc::signal<void()> refreshSignal) {
|
||||||
|
this->refreshSignal = refreshSignal;
|
||||||
|
this->adapter = makeSqliteTodoAdapter();
|
||||||
|
this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
TodoService::~TodoService() {
|
||||||
|
this->adapter.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, TodoEntry *> TodoService::getTodos() {
|
||||||
|
return this->todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoService::init() {
|
||||||
|
if (!this->adapter) {
|
||||||
|
std::cerr << "Todo adapter not set" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->adapter->init()) {
|
||||||
|
std::cerr << "Todo adapter init failed" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoService::removeTodo(int id) {
|
||||||
|
if (todos.find(id) == todos.end()) {
|
||||||
|
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->adapter) {
|
||||||
|
this->adapter->removeTodo(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
todos.erase(id);
|
||||||
|
this->refreshSignal.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
TodoEntry *TodoService::addTodo(std::string text, bool emitSignal, bool persist) {
|
||||||
|
int id = nextId;
|
||||||
|
|
||||||
|
if (persist) {
|
||||||
|
if (!this->adapter) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
int newId = this->adapter->addTodo(text);
|
||||||
|
if (newId < 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
id = newId;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dismissSignal = sigc::signal<void(int)>();
|
||||||
|
dismissSignal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||||
|
|
||||||
|
auto editSignal = sigc::signal<void(int, std::string)>();
|
||||||
|
editSignal.connect(sigc::mem_fun(*this, &TodoService::updateTodo));
|
||||||
|
|
||||||
|
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, dismissSignal, editSignal);
|
||||||
|
|
||||||
|
todos[id] = todo;
|
||||||
|
|
||||||
|
if (id >= nextId) {
|
||||||
|
nextId = id + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emitSignal) {
|
||||||
|
this->refreshSignal.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return todo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoService::updateTodo(int id, std::string text) {
|
||||||
|
if (todos.find(id) == todos.end()) {
|
||||||
|
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->adapter) {
|
||||||
|
this->adapter->updateTodo(id, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->refreshSignal.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoService::load() {
|
||||||
|
if (!this->adapter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rows = this->adapter->listTodos();
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (const auto &row : rows) {
|
||||||
|
count++;
|
||||||
|
int id = row.id;
|
||||||
|
std::string text = row.text;
|
||||||
|
|
||||||
|
auto dismissSignal = sigc::signal<void(int)>();
|
||||||
|
dismissSignal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||||
|
|
||||||
|
auto editSignal = sigc::signal<void(int, std::string)>();
|
||||||
|
editSignal.connect(sigc::mem_fun(*this, &TodoService::updateTodo));
|
||||||
|
|
||||||
|
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, dismissSignal, editSignal);
|
||||||
|
|
||||||
|
todos[id] = todo;
|
||||||
|
if (id >= nextId) {
|
||||||
|
nextId = id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
219
src/widgets/battery.cpp
Normal file
219
src/widgets/battery.cpp
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
#include "widgets/battery.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <glibmm/main.h>
|
||||||
|
#include <sigc++/functors/mem_fun.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string trim(const std::string &value) {
|
||||||
|
const auto start = value.find_first_not_of(" \t\n\r");
|
||||||
|
if (start == std::string::npos) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto end = value.find_last_not_of(" \t\n\r");
|
||||||
|
return value.substr(start, end - start + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BatteryWidget::BatteryWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||||
|
set_valign(Gtk::Align::CENTER);
|
||||||
|
set_halign(Gtk::Align::CENTER);
|
||||||
|
set_spacing(6);
|
||||||
|
add_css_class("battery-widget");
|
||||||
|
|
||||||
|
iconLabel.set_halign(Gtk::Align::CENTER);
|
||||||
|
iconLabel.set_valign(Gtk::Align::CENTER);
|
||||||
|
iconLabel.set_width_chars(7);
|
||||||
|
iconLabel.set_text("[ ]");
|
||||||
|
iconLabel.add_css_class("battery-widget-icon");
|
||||||
|
|
||||||
|
append(iconLabel);
|
||||||
|
|
||||||
|
label.set_halign(Gtk::Align::CENTER);
|
||||||
|
label.set_valign(Gtk::Align::CENTER);
|
||||||
|
label.set_width_chars(5);
|
||||||
|
label.set_text("--%");
|
||||||
|
label.add_css_class("battery-widget-text");
|
||||||
|
|
||||||
|
append(label);
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
timeoutConn = Glib::signal_timeout().connect(
|
||||||
|
sigc::mem_fun(*this, &BatteryWidget::on_timeout), 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
BatteryWidget::~BatteryWidget() {
|
||||||
|
if (timeoutConn.connected()) {
|
||||||
|
timeoutConn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryWidget::find_battery_path() {
|
||||||
|
constexpr auto base = "/sys/class/power_supply";
|
||||||
|
|
||||||
|
batteryPath.clear();
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(base)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &entry : std::filesystem::directory_iterator(base)) {
|
||||||
|
if (!entry.is_directory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream typeFile(entry.path() / "type");
|
||||||
|
if (!typeFile) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string type;
|
||||||
|
std::getline(typeFile, type);
|
||||||
|
type = trim(type);
|
||||||
|
std::transform(type.begin(), type.end(), type.begin(), [](unsigned char ch) {
|
||||||
|
return static_cast<char>(std::toupper(ch));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (type == "BATTERY") {
|
||||||
|
batteryPath = entry.path();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryWidget::update() {
|
||||||
|
try {
|
||||||
|
if (batteryPath.empty() || !std::filesystem::exists(batteryPath)) {
|
||||||
|
find_battery_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool hasBattery = !batteryPath.empty();
|
||||||
|
|
||||||
|
int capacity = -1;
|
||||||
|
std::string status;
|
||||||
|
if (hasBattery) {
|
||||||
|
std::ifstream capacityFile(batteryPath / "capacity");
|
||||||
|
if (capacityFile) {
|
||||||
|
capacityFile >> capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream statusFile(batteryPath / "status");
|
||||||
|
if (statusFile) {
|
||||||
|
std::getline(statusFile, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status = trim(status);
|
||||||
|
|
||||||
|
const bool charging = status == "Charging";
|
||||||
|
const bool full = hasBattery && (status == "Full" || (capacity >= 95));
|
||||||
|
const bool low = (capacity >= 0 && capacity < 20 && !charging);
|
||||||
|
|
||||||
|
std::string stateClass;
|
||||||
|
if (!hasBattery) {
|
||||||
|
stateClass = "battery-widget-external";
|
||||||
|
} else if (charging) {
|
||||||
|
stateClass = "battery-widget-charging";
|
||||||
|
} else if (low) {
|
||||||
|
stateClass = "battery-widget-low";
|
||||||
|
} else if (full) {
|
||||||
|
stateClass = "battery-widget-full";
|
||||||
|
} else {
|
||||||
|
stateClass = "battery-widget-normal";
|
||||||
|
}
|
||||||
|
|
||||||
|
set_state_class(stateClass);
|
||||||
|
|
||||||
|
iconLabel.set_text(build_icon(capacity, hasBattery, charging, full));
|
||||||
|
label.set_text(build_text(capacity, status, hasBattery, charging, full));
|
||||||
|
} catch (...) {
|
||||||
|
set_state_class("battery-widget-normal");
|
||||||
|
iconLabel.set_text("[???]");
|
||||||
|
label.set_text("??%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BatteryWidget::on_timeout() {
|
||||||
|
update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryWidget::set_state_class(const std::string &stateClass) {
|
||||||
|
if (currentStateClass == stateClass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentStateClass.empty()) {
|
||||||
|
remove_css_class(currentStateClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentStateClass = stateClass;
|
||||||
|
|
||||||
|
if (!currentStateClass.empty()) {
|
||||||
|
add_css_class(currentStateClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BatteryWidget::build_icon(int capacity, bool hasBattery, bool charging, bool full) const {
|
||||||
|
if (!hasBattery) {
|
||||||
|
return "<AC>";
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr int segments = 5;
|
||||||
|
const int clampedCapacity = std::clamp(capacity, 0, 100);
|
||||||
|
int filledSegments = (clampedCapacity * segments + 99) / 100;
|
||||||
|
|
||||||
|
if (full) {
|
||||||
|
filledSegments = segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string icon = "[";
|
||||||
|
for (int i = 0; i < segments; ++i) {
|
||||||
|
icon += (i < filledSegments) ? '=' : ' ';
|
||||||
|
}
|
||||||
|
icon += ']';
|
||||||
|
|
||||||
|
if (charging) {
|
||||||
|
icon += '>';
|
||||||
|
} else if (clampedCapacity <= 5) {
|
||||||
|
icon += '!';
|
||||||
|
} else {
|
||||||
|
icon += ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BatteryWidget::build_text(int capacity, const std::string &status, bool hasBattery, bool charging, bool full) const {
|
||||||
|
if (!hasBattery) {
|
||||||
|
return "AC";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capacity >= 0) {
|
||||||
|
std::string text;
|
||||||
|
if (full && capacity >= 99) {
|
||||||
|
text = "100%";
|
||||||
|
} else {
|
||||||
|
text = std::to_string(std::clamp(capacity, 0, 100)) + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (charging && capacity < 100) {
|
||||||
|
text.insert(text.begin(), '+');
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!status.empty()) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "?%";
|
||||||
|
}
|
||||||
72
src/widgets/bluetooth.cpp
Normal file
72
src/widgets/bluetooth.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include "widgets/bluetooth.hpp"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
|
|
||||||
|
BluetoothWidget::BluetoothWidget() : Gtk::Box() {
|
||||||
|
this->set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
this->add_css_class("bluetooth-popover-container");
|
||||||
|
|
||||||
|
this->statusArea.add_css_class("bluetooth-status-area");
|
||||||
|
this->statusArea.set_hexpand(true);
|
||||||
|
this->statusArea.set_halign(Gtk::Align::FILL);
|
||||||
|
this->append(this->statusArea);
|
||||||
|
|
||||||
|
this->powerButton = Gtk::make_managed<Button>("\ue1a8");
|
||||||
|
this->powerButton->set_tooltip_text("Turn Bluetooth Off");
|
||||||
|
this->powerButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onPowerButtonClicked));
|
||||||
|
this->powerButton->add_css_class("toggle-button");
|
||||||
|
|
||||||
|
this->scanButton = Gtk::make_managed<Button>("\ue1aa");
|
||||||
|
this->scanButton->set_tooltip_text("Scan for Devices");
|
||||||
|
this->scanButton->add_css_class("toggle-button");
|
||||||
|
this->scanButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onScanButtonClicked));
|
||||||
|
|
||||||
|
this->statusArea.append(*this->powerButton);
|
||||||
|
this->statusArea.append(*this->scanButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::onPowerButtonClicked() {
|
||||||
|
onPowerStateButtonClickedSignal.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::onScanButtonClicked() {
|
||||||
|
onIsDiscoveringButtonClickedSignal.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::toggleButton(Button *button, bool state) {
|
||||||
|
if (state) {
|
||||||
|
button->add_css_class("toggle-button-on");
|
||||||
|
button->remove_css_class("toggle-button-off");
|
||||||
|
} else {
|
||||||
|
button->add_css_class("toggle-button-off");
|
||||||
|
button->remove_css_class("toggle-button-on");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::setPowerState(bool state) {
|
||||||
|
this->isPowered = state;
|
||||||
|
|
||||||
|
this->scanButton->set_sensitive(state);
|
||||||
|
|
||||||
|
if (!state) {
|
||||||
|
this->scanButton->add_css_class("toggle-button-disabled");
|
||||||
|
// this->add_css_class("disabled-popover-icon");
|
||||||
|
this->setIsDiscovering(false);
|
||||||
|
} else {
|
||||||
|
this->scanButton->remove_css_class("toggle-button-disabled");
|
||||||
|
// this->remove_css_class("disabled-popover-icon");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->toggleButton(this->powerButton, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::setIsDiscovering(bool state) {
|
||||||
|
this->isDiscovering = state;
|
||||||
|
|
||||||
|
this->toggleButton(this->scanButton, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothWidget::update() {
|
||||||
|
setPowerState(isPowered);
|
||||||
|
setIsDiscovering(isDiscovering);
|
||||||
|
}
|
||||||
@@ -5,4 +5,20 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
|
|||||||
this->popover->set_size_request(200, -1);
|
this->popover->set_size_request(200, -1);
|
||||||
set_popover_child(this->container);
|
set_popover_child(this->container);
|
||||||
|
|
||||||
}
|
this->bluetoothWidget = Gtk::make_managed<BluetoothWidget>();
|
||||||
|
this->container.append(*this->bluetoothWidget);
|
||||||
|
|
||||||
|
bluetoothService->powerStateChangedSignal.connect(
|
||||||
|
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setPowerState));
|
||||||
|
|
||||||
|
bluetoothWidget->onPowerStateButtonClickedSignal.connect(
|
||||||
|
sigc::mem_fun(*this->bluetoothService, &BluetoothService::togglePowerState));
|
||||||
|
|
||||||
|
bluetoothWidget->setPowerState(bluetoothService->getPowerState());
|
||||||
|
|
||||||
|
bluetoothService->isDiscoveringChangedSignal.connect(
|
||||||
|
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setIsDiscovering));
|
||||||
|
bluetoothWidget->onIsDiscoveringButtonClickedSignal.connect(
|
||||||
|
sigc::mem_fun(*this->bluetoothService, &BluetoothService::toggleIsDiscovering));
|
||||||
|
bluetoothWidget->setIsDiscovering(bluetoothService->getIsDiscovering());
|
||||||
|
}
|
||||||
|
|||||||
78
src/widgets/todo.cpp
Normal file
78
src/widgets/todo.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include "widgets/todo.hpp"
|
||||||
|
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/entry.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, title) {
|
||||||
|
this->name = title;
|
||||||
|
this->popover->set_size_request(300, -1);
|
||||||
|
|
||||||
|
container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||||
|
container.add_css_class("todo-popover-container");
|
||||||
|
|
||||||
|
auto entry = Gtk::make_managed<Gtk::Entry>();
|
||||||
|
entry->set_placeholder_text("Enter your to-do item...");
|
||||||
|
entry->add_css_class("todo-input");
|
||||||
|
entry->set_hexpand(true);
|
||||||
|
entry->set_halign(Gtk::Align::FILL);
|
||||||
|
entry->set_valign(Gtk::Align::START);
|
||||||
|
|
||||||
|
inputArea.append(*entry);
|
||||||
|
inputArea.add_css_class("todo-input-area");
|
||||||
|
inputArea.set_hexpand(true);
|
||||||
|
inputArea.set_halign(Gtk::Align::FILL);
|
||||||
|
|
||||||
|
entry->signal_activate().connect([this, entry]() {
|
||||||
|
std::string text = entry->get_text();
|
||||||
|
if (!text.empty()) {
|
||||||
|
this->todoService->addTodo(text);
|
||||||
|
|
||||||
|
entry->set_text("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
container.append(inputArea);
|
||||||
|
|
||||||
|
this->todoList = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
|
||||||
|
container.append(*todoList);
|
||||||
|
todoList->add_css_class("todo-list");
|
||||||
|
|
||||||
|
auto signal = sigc::signal<void()>();
|
||||||
|
this->todoService = new TodoService(signal);
|
||||||
|
|
||||||
|
signal.connect(sigc::mem_fun(*this, &TodoPopover::update));
|
||||||
|
|
||||||
|
this->set_popover_child(this->container);
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TodoPopover::update() {
|
||||||
|
auto todos = this->todoService->getTodos();
|
||||||
|
|
||||||
|
Gtk::Widget *child = todoList->get_first_child();
|
||||||
|
|
||||||
|
while (child) {
|
||||||
|
Gtk::Widget *next = child->get_next_sibling();
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
for (auto &[id, todo] : todos) {
|
||||||
|
if (child == todo) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
todoList->remove(*child);
|
||||||
|
}
|
||||||
|
|
||||||
|
child = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &[id, todo] : todos) {
|
||||||
|
if (todo->get_parent() == nullptr) {
|
||||||
|
todoList->append(*todo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sigc++/functors/mem_fun.h>
|
#include <sigc++/functors/mem_fun.h>
|
||||||
|
|
||||||
#include "helpers/command.hpp"
|
#include "helpers/systemHelper.hpp"
|
||||||
|
|
||||||
#include "giomm/applicationcommandline.h"
|
|
||||||
|
|
||||||
VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||||
set_valign(Gtk::Align::CENTER);
|
set_valign(Gtk::Align::CENTER);
|
||||||
@@ -23,7 +21,7 @@ VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
|||||||
click->set_button(GDK_BUTTON_PRIMARY);
|
click->set_button(GDK_BUTTON_PRIMARY);
|
||||||
click->signal_released().connect([this](int, double, double) {
|
click->signal_released().connect([this](int, double, double) {
|
||||||
try {
|
try {
|
||||||
(void)CommandHelper::exec(
|
(void)SystemHelper::get_command_output(
|
||||||
"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()
|
std::cerr << "[VolumeWidget] failed to toggle mute: " << ex.what()
|
||||||
@@ -46,7 +44,8 @@ VolumeWidget::~VolumeWidget() {
|
|||||||
|
|
||||||
void VolumeWidget::update() {
|
void VolumeWidget::update() {
|
||||||
try {
|
try {
|
||||||
const std::string out = CommandHelper::exec("wpctl get-volume @DEFAULT_SINK@");
|
const std::string out =
|
||||||
|
SystemHelper::get_command_output("wpctl get-volume @DEFAULT_SINK@");
|
||||||
|
|
||||||
std::smatch m;
|
std::smatch m;
|
||||||
std::regex r_percent(R"((\d+(?:\.\d+)?)%)");
|
std::regex r_percent(R"((\d+(?:\.\d+)?)%)");
|
||||||
|
|||||||
104
src/widgets/workspaceIndicator.cpp
Normal file
104
src/widgets/workspaceIndicator.cpp
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#include "widgets/workspaceIndicator.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
#include <gtkmm/gestureclick.h>
|
||||||
|
#include <gtkmm/overlay.h>
|
||||||
|
#include <gtkmm/widget.h>
|
||||||
|
#include <sigc++/functors/mem_fun.h>
|
||||||
|
|
||||||
|
#include "services/hyprland.hpp"
|
||||||
|
|
||||||
|
#include "gtkmm/box.h"
|
||||||
|
#include "gtkmm/label.h"
|
||||||
|
|
||||||
|
WorkspaceIndicator::WorkspaceIndicator(int monitorId)
|
||||||
|
: Gtk::Box(Gtk::Orientation::HORIZONTAL),
|
||||||
|
monitorId(monitorId) {
|
||||||
|
set_margin_top(2);
|
||||||
|
set_margin_bottom(2);
|
||||||
|
|
||||||
|
workspaceConnection = service->workspaceStateChanged.connect(
|
||||||
|
sigc::mem_fun(*this, &WorkspaceIndicator::on_workspace_update));
|
||||||
|
monitorConnection = service->monitorStateChanged.connect(
|
||||||
|
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
|
||||||
|
|
||||||
|
for (int i = 1; i <= HyprlandService::kWorkspaceSlotCount; ++i) {
|
||||||
|
auto overlay = Gtk::make_managed<Gtk::Overlay>();
|
||||||
|
auto numLabel = Gtk::make_managed<Gtk::Label>(std::to_string(i));
|
||||||
|
auto pillContainer = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||||
|
|
||||||
|
auto gesture = Gtk::GestureClick::create();
|
||||||
|
gesture->set_button(GDK_BUTTON_PRIMARY);
|
||||||
|
gesture->signal_released().connect([this, i](int, double, double) {
|
||||||
|
this->service->switchToWorkspace(
|
||||||
|
i + this->monitorId * HyprlandService::kWorkspaceSlotCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
workspaceGestures[i] = gesture;
|
||||||
|
workspaceIndicators[i] = overlay;
|
||||||
|
|
||||||
|
overlay->add_controller(gesture);
|
||||||
|
overlay->add_css_class("workspace-pill");
|
||||||
|
|
||||||
|
if (i == 6 || i == 7) {
|
||||||
|
auto indicator = Gtk::make_managed<Gtk::Label>(i == 6 ? "🫱🏻" : "🫲🏻");
|
||||||
|
indicator->add_css_class(i == 6 ? "workspace-pill-six" : "workspace-pill-seven");
|
||||||
|
indicator->set_valign(Gtk::Align::END);
|
||||||
|
overlay->set_child(*indicator);
|
||||||
|
overlay->add_overlay(*numLabel);
|
||||||
|
pillContainer->append(*overlay);
|
||||||
|
} else {
|
||||||
|
overlay->set_child(*numLabel);
|
||||||
|
pillContainer->append(*overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
append(*pillContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkspaceIndicator::~WorkspaceIndicator() {
|
||||||
|
if (workspaceConnection.connected()) {
|
||||||
|
workspaceConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (monitorConnection.connected()) {
|
||||||
|
monitorConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkspaceIndicator::on_workspace_update() {
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkspaceIndicator::on_monitor_update() {
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkspaceIndicator::refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state) {
|
||||||
|
overlay->remove_css_class("workspace-pill-active");
|
||||||
|
overlay->remove_css_class("workspace-pill-focused");
|
||||||
|
overlay->remove_css_class("workspace-pill-urgent");
|
||||||
|
|
||||||
|
// controller created once in constructor and reused
|
||||||
|
if (state.urgentWindows.size() > 0) {
|
||||||
|
overlay->add_css_class("workspace-pill-urgent");
|
||||||
|
} else {
|
||||||
|
if (state.focused) {
|
||||||
|
overlay->add_css_class("workspace-pill-focused");
|
||||||
|
} else if (state.active) {
|
||||||
|
overlay->add_css_class("workspace-pill-active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkspaceIndicator::rebuild() {
|
||||||
|
HyprlandService::Monitor *mon = service->getMonitorById(this->monitorId);
|
||||||
|
|
||||||
|
for (auto [id, workspaceState] : mon->workspaceStates) {
|
||||||
|
Gtk::Overlay *overlay = workspaceIndicators[id];
|
||||||
|
this->refreshLabel(overlay, *workspaceState);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user