quick commit
This commit is contained in:
@@ -5,10 +5,9 @@
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
#include "helpers/system.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.hpp"
|
||||
#include "widgets/todo.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
@@ -66,8 +65,6 @@ void Bar::setup_left_box() {
|
||||
void Bar::setup_center_box() {
|
||||
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(*(new Spacer()));
|
||||
center_box.append(this->clock);
|
||||
|
||||
@@ -2,18 +2,13 @@
|
||||
|
||||
#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");
|
||||
}
|
||||
|
||||
Button::Button(Gtk::Image &image)
|
||||
: Gtk::Button() {
|
||||
Button::Button(Gtk::Image &image) : Gtk::Button() {
|
||||
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");
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "components/popover.hpp"
|
||||
|
||||
#include "gtkmm/label.h"
|
||||
#include "gtkmm/object.h"
|
||||
|
||||
Popover::Popover(const std::string icon, std::string name): Button(icon) {
|
||||
signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window));
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <unordered_set>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
#include "helpers/command.hpp"
|
||||
#include "helpers/hypr.hpp"
|
||||
|
||||
HyprlandService::HyprlandService() = default;
|
||||
|
||||
@@ -23,10 +24,10 @@ HyprlandService::~HyprlandService() {
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
// free allocated workspace pointers
|
||||
for (auto &p : this->workspaces) {
|
||||
delete p.second;
|
||||
}
|
||||
|
||||
this->workspaces.clear();
|
||||
this->monitors.clear();
|
||||
}
|
||||
@@ -67,8 +68,7 @@ void HyprlandService::start() {
|
||||
addr.sun_family = AF_UNIX;
|
||||
std::strncpy(addr.sun_path, socket_path.c_str(), sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (connect(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) ==
|
||||
-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);
|
||||
@@ -145,15 +145,13 @@ std::string HyprlandService::get_socket_path() {
|
||||
}
|
||||
|
||||
void HyprlandService::refresh_monitors() {
|
||||
// free any previously allocated WorkspaceState objects before rebuilding
|
||||
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);
|
||||
auto monitorsJson = HyprctlHelper::getMonitorData();
|
||||
|
||||
for (const auto &monitorJson : monitorsJson) {
|
||||
Monitor monitor;
|
||||
@@ -188,35 +186,27 @@ void HyprlandService::refresh_monitors() {
|
||||
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);
|
||||
auto workspacesJson = HyprctlHelper::getWorkspaceData();
|
||||
|
||||
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);
|
||||
auto monitorsJson = HyprctlHelper::getMonitorData();
|
||||
|
||||
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);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
std::unordered_set<std::string> liveClientAddresses;
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
@@ -234,21 +224,23 @@ void HyprlandService::refresh_workspaces() {
|
||||
for (const auto &workspaceJson : workspacesJson) {
|
||||
const int workspaceId = workspaceJson.value("id", -1);
|
||||
auto workspaceStateIt = this->workspaces.find(workspaceId);
|
||||
|
||||
if (workspaceStateIt == this->workspaces.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
WorkspaceState *workspaceState = workspaceStateIt->second;
|
||||
auto mit = this->monitors.find(workspaceState->monitorId);
|
||||
|
||||
if (mit != this->monitors.end()) {
|
||||
workspaceState->focused = mit->second.focusedWorkspaceId == workspaceId;
|
||||
} else {
|
||||
workspaceState->focused = false;
|
||||
}
|
||||
|
||||
workspaceState->active = true;
|
||||
}
|
||||
|
||||
// drop urgent flags for windows no longer reported by hyprctl clients
|
||||
for (auto &[id, ws] : this->workspaces) {
|
||||
auto &urgent = ws->urgentWindows;
|
||||
auto newEnd = std::remove_if(urgent.begin(), urgent.end(), [&](const std::string &addr) {
|
||||
@@ -267,7 +259,7 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||
"hyprctl dispatch workspace " + std::to_string(workspaceId);
|
||||
|
||||
try {
|
||||
(void)SystemHelper::get_command_output(cmd.c_str());
|
||||
(void)CommandHelper::execNoOutput(cmd.c_str());
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "[Hyprland] Failed to dispatch workspace command: "
|
||||
<< ex.what() << " cmd=" << cmd << std::endl;
|
||||
@@ -275,8 +267,7 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||
}
|
||||
|
||||
void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
@@ -301,8 +292,7 @@ void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||
}
|
||||
|
||||
void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
|
||||
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
#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>();
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,23 @@
|
||||
|
||||
ControlCenter::ControlCenter(std::string icon, std::string name)
|
||||
: Popover(icon, name) {
|
||||
this->popover->set_size_request(200, -1);
|
||||
set_popover_child(this->container);
|
||||
this->popover->set_size_request(200, -1);
|
||||
set_popover_child(this->container);
|
||||
|
||||
this->bluetoothWidget = Gtk::make_managed<BluetoothWidget>();
|
||||
this->container.append(*this->bluetoothWidget);
|
||||
this->bluetoothWidget = Gtk::make_managed<BluetoothWidget>();
|
||||
this->container.append(*this->bluetoothWidget);
|
||||
|
||||
bluetoothService->powerStateChangedSignal.connect(
|
||||
bluetoothService->powerStateChangedSignal.connect(
|
||||
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setPowerState));
|
||||
|
||||
bluetoothWidget->onPowerStateButtonClickedSignal.connect(
|
||||
|
||||
bluetoothWidget->onPowerStateButtonClickedSignal.connect(
|
||||
sigc::mem_fun(*this->bluetoothService, &BluetoothService::togglePowerState));
|
||||
|
||||
bluetoothWidget->setPowerState(bluetoothService->getPowerState());
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#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,7 +5,9 @@
|
||||
#include <regex>
|
||||
#include <sigc++/functors/mem_fun.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
#include "helpers/command.hpp"
|
||||
|
||||
#include "giomm/applicationcommandline.h"
|
||||
|
||||
VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||
set_valign(Gtk::Align::CENTER);
|
||||
@@ -21,7 +23,7 @@ VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||
click->set_button(GDK_BUTTON_PRIMARY);
|
||||
click->signal_released().connect([this](int, double, double) {
|
||||
try {
|
||||
(void)SystemHelper::get_command_output(
|
||||
(void)CommandHelper::exec(
|
||||
"wpctl set-mute @DEFAULT_SINK@ toggle");
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "[VolumeWidget] failed to toggle mute: " << ex.what()
|
||||
@@ -44,8 +46,7 @@ VolumeWidget::~VolumeWidget() {
|
||||
|
||||
void VolumeWidget::update() {
|
||||
try {
|
||||
const std::string out =
|
||||
SystemHelper::get_command_output("wpctl get-volume @DEFAULT_SINK@");
|
||||
const std::string out = CommandHelper::exec("wpctl get-volume @DEFAULT_SINK@");
|
||||
|
||||
std::smatch m;
|
||||
std::regex r_percent(R"((\d+(?:\.\d+)?)%)");
|
||||
|
||||
Reference in New Issue
Block a user