bar can now toggle bluetooth power and discovery
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 0
|
||||
AlignConsecutiveAssignments: true
|
||||
|
||||
IncludeCategories:
|
||||
- Regex: '^(<.+>)$'
|
||||
Priority: 1
|
||||
- Regex: '^"(.+\.hpp)"$'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeBlocks: Regroup
|
||||
@@ -34,9 +34,11 @@ target_sources(bar_lib
|
||||
src/services/hyprland.cpp
|
||||
src/services/tray.cpp
|
||||
src/services/notifications.cpp
|
||||
src/services/bluetooth.cpp
|
||||
|
||||
src/widgets/tray.cpp
|
||||
src/widgets/todoPopover.cpp
|
||||
src/widgets/todo.cpp
|
||||
src/widgets/bluetooth.cpp
|
||||
|
||||
src/components/popover.cpp
|
||||
src/components/todoEntry.cpp
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "bar/bar.hpp"
|
||||
#include "glibmm/refptr.h"
|
||||
#include "gtkmm/application.h"
|
||||
#include "services/bluetooth.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/notifications.hpp"
|
||||
#include "services/tray.hpp"
|
||||
|
||||
#include "glibmm/refptr.h"
|
||||
#include "gtkmm/application.h"
|
||||
|
||||
class App {
|
||||
public:
|
||||
App();
|
||||
@@ -21,6 +23,7 @@ class App {
|
||||
HyprlandService hyprlandService;
|
||||
NotificationService notificationService;
|
||||
TrayService trayService;
|
||||
BluetoothService bluetoothService;
|
||||
|
||||
void setupServices();
|
||||
};
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "icons.hpp"
|
||||
#include "services/bluetooth.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/tray.hpp"
|
||||
#include "widgets/bluetooth.hpp"
|
||||
#include "widgets/clock.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/tray.hpp"
|
||||
@@ -14,7 +17,7 @@
|
||||
|
||||
class Bar : public Gtk::Window {
|
||||
public:
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, int monitorId);
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, BluetoothService &bluetoothService, int monitorId);
|
||||
|
||||
protected:
|
||||
Gtk::CenterBox main_box{};
|
||||
@@ -32,9 +35,11 @@ class Bar : public Gtk::Window {
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
VolumeWidget *volumeWidget = nullptr;
|
||||
BluetoothWidget *bluetoothWidget = nullptr;
|
||||
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
BluetoothService &bluetoothService;
|
||||
|
||||
void setup_ui();
|
||||
void setup_left_box();
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/popover.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class Popover: public Gtk::Button {
|
||||
public:
|
||||
class Popover : public Gtk::Button {
|
||||
public:
|
||||
Popover(std::string icon, std::string name);
|
||||
~Popover() override;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void on_toggle_window();
|
||||
Gtk::Popover* popover = nullptr;
|
||||
void set_popover_child(Gtk::Widget& child) {
|
||||
Gtk::Popover *popover = nullptr;
|
||||
void set_popover_child(Gtk::Widget &child) {
|
||||
gtk_popover_set_child(popover->gobj(), child.gobj());
|
||||
}
|
||||
};
|
||||
@@ -1,20 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "gtkmm/box.h"
|
||||
#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);
|
||||
public:
|
||||
TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited);
|
||||
~TodoEntry() override;
|
||||
|
||||
int get_id() const { return id; }
|
||||
std::string get_text() const { return text; }
|
||||
private:
|
||||
|
||||
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,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
class IUpdatable {
|
||||
public:
|
||||
public:
|
||||
virtual ~IUpdatable() = default;
|
||||
virtual bool onUpdate() = 0;
|
||||
};
|
||||
35
include/services/bluetooth.hpp
Normal file
35
include/services/bluetooth.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "sigc++/signal.h"
|
||||
|
||||
class BluetoothService {
|
||||
public:
|
||||
BluetoothService();
|
||||
|
||||
sigc::signal<void(bool)> powerStateChangedSignal;
|
||||
sigc::signal<void(bool)> isDiscoveringChangedSignal;
|
||||
|
||||
bool getPowerState();
|
||||
void setPowerState(bool state);
|
||||
|
||||
bool getIsDiscovering();
|
||||
void setIsDiscovering(bool state);
|
||||
|
||||
private:
|
||||
GDBusProxy *adapter_proxy = nullptr;
|
||||
bool powerState = false;
|
||||
bool isDiscovering = false;
|
||||
|
||||
void onPropertyChanged(GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
const gchar *const *invalidated_properties,
|
||||
gpointer user_data);
|
||||
|
||||
static void onPropertyChangedStatic(GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
const gchar *const *invalidated_properties,
|
||||
gpointer user_data);
|
||||
};
|
||||
@@ -3,18 +3,18 @@
|
||||
#include <gio/gio.h>
|
||||
|
||||
class NotificationService {
|
||||
public:
|
||||
public:
|
||||
void intialize();
|
||||
|
||||
NotificationService() = default;
|
||||
~NotificationService();
|
||||
|
||||
guint32 allocateNotificationId(guint32 replacesId);
|
||||
GDBusConnection* getConnection() const { return connection; }
|
||||
GDBusConnection *getConnection() const { return connection; }
|
||||
|
||||
private:
|
||||
GDBusConnection* connection = nullptr;
|
||||
private:
|
||||
GDBusConnection *connection = nullptr;
|
||||
guint registrationId = 0;
|
||||
GDBusNodeInfo* nodeInfo = nullptr;
|
||||
GDBusNodeInfo *nodeInfo = nullptr;
|
||||
guint32 nextNotificationId = 1;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "services/todoAdapter.hpp"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class TodoService {
|
||||
public:
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <gdkmm/memorytexture.h>
|
||||
#include <gio/gio.h>
|
||||
#include <giomm/actiongroup.h>
|
||||
#include <giomm/dbusconnection.h>
|
||||
#include <giomm/init.h>
|
||||
#include <giomm/menumodel.h>
|
||||
#include <glibmm/bytes.h>
|
||||
#include <glibmm/refptr.h>
|
||||
#include <sigc++/sigc++.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
31
include/widgets/bluetooth.hpp
Normal file
31
include/widgets/bluetooth.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
|
||||
#include "components/popover.hpp"
|
||||
|
||||
#include "gtkmm/button.h"
|
||||
|
||||
class BluetoothWidget : public Popover {
|
||||
public:
|
||||
BluetoothWidget(std::string icon, std::string title);
|
||||
|
||||
void setPowerState(bool state);
|
||||
void setIsDiscovering(bool state);
|
||||
|
||||
sigc::signal<void(bool)> powerStateChangedSignal;
|
||||
sigc::signal<void(bool)> isDiscoveringChangedSignal;
|
||||
|
||||
void update();
|
||||
private:
|
||||
bool isPowered = false;
|
||||
bool isDiscovering = false;
|
||||
|
||||
Gtk::Box container;
|
||||
Gtk::Box statusArea;
|
||||
|
||||
Gtk::Box *deviceList = nullptr;
|
||||
|
||||
Gtk::Button *scanButton = nullptr;
|
||||
Gtk::Button *toggleButton = nullptr;
|
||||
};
|
||||
@@ -1,19 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "components/popover.hpp"
|
||||
#include "services/todo.hpp"
|
||||
#include <string>
|
||||
|
||||
class TodoPopover : public Popover {
|
||||
|
||||
public:
|
||||
public:
|
||||
TodoPopover(std::string icon, std::string title);
|
||||
|
||||
void update();
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
TodoService* todoService = nullptr;
|
||||
TodoService *todoService = nullptr;
|
||||
Gtk::Box container;
|
||||
Gtk::Box inputArea;
|
||||
Gtk::Box* todoList = nullptr;
|
||||
Gtk::Box *todoList = nullptr;
|
||||
};
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <gtkmm/image.h>
|
||||
#include <gtkmm/picture.h>
|
||||
#include <gtkmm/popovermenu.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/popover.hpp"
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/popover.h>
|
||||
|
||||
#include "components/popover.hpp"
|
||||
|
||||
class WebWidget : public Popover {
|
||||
public:
|
||||
public:
|
||||
WebWidget(std::string icon, std::string title, std::string url);
|
||||
private:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/gestureclick.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <sigc++/connection.h>
|
||||
|
||||
#include "services/hyprland.hpp"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
all: unset;
|
||||
}
|
||||
|
||||
|
||||
window {
|
||||
background-color: rgba(30, 30, 30, 0.8);
|
||||
color: #ffffff;
|
||||
@@ -73,6 +72,7 @@ button {
|
||||
background-color: transparent;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
@@ -88,9 +88,10 @@ popover {
|
||||
background-color: rgb(30, 30, 30);
|
||||
color: #ffffff;
|
||||
font-family: "IBMPlexSans-Regular", sans-serif;
|
||||
padding: 10px;
|
||||
padding: 5px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #444444;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
tooltip {
|
||||
@@ -120,3 +121,18 @@ tooltip {
|
||||
background-color: #222222;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* use background to highlight using same dark colors as in file */
|
||||
.toggle-button-on {
|
||||
background-color: rgba(0, 150, 136, 0.2);
|
||||
border: 1px solid #009688;
|
||||
}
|
||||
|
||||
.toggle-button-off {
|
||||
background-color: rgba(244, 67, 54, 0.2);
|
||||
border: 1px solid #f44336;
|
||||
}
|
||||
@@ -29,8 +29,10 @@ App::App() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
auto bar = new Bar(monitor->gobj(), this->hyprlandService,
|
||||
this->trayService, hyprlandMonitor->id);
|
||||
this->trayService, this->bluetoothService, hyprlandMonitor->id);
|
||||
|
||||
bar->set_application(app);
|
||||
bar->show();
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
#include "bar/bar.hpp"
|
||||
|
||||
#include "gtk/gtk.h"
|
||||
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.hpp"
|
||||
#include "widgets/todoPopover.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <gtkmm/enums.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.hpp"
|
||||
#include "widgets/todo.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
#include "glibmm/main.h"
|
||||
#include "gtk/gtk.h"
|
||||
#include "sigc++/functors/mem_fun.h"
|
||||
|
||||
Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
TrayService &trayService, int monitorId)
|
||||
: hyprlandService(hyprlandService), trayService(trayService),
|
||||
TrayService &trayService, BluetoothService &bluetoothService, int monitorId)
|
||||
: hyprlandService(hyprlandService), trayService(trayService), bluetoothService(bluetoothService),
|
||||
monitorId(monitorId) {
|
||||
set_name("bar-window");
|
||||
|
||||
@@ -42,17 +40,27 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
this->trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
this->bluetoothWidget = Gtk::make_managed<BluetoothWidget>("\ue8bb", "Bluetooth");
|
||||
|
||||
bluetoothService.powerStateChangedSignal.connect(
|
||||
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setPowerState));
|
||||
bluetoothWidget->powerStateChangedSignal.connect(
|
||||
sigc::mem_fun(bluetoothService, &BluetoothService::setPowerState));
|
||||
bluetoothWidget->setPowerState(bluetoothService.getPowerState());
|
||||
|
||||
bluetoothService.isDiscoveringChangedSignal.connect(
|
||||
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setIsDiscovering));
|
||||
bluetoothWidget->isDiscoveringChangedSignal.connect(
|
||||
sigc::mem_fun(bluetoothService, &BluetoothService::setIsDiscovering));
|
||||
bluetoothWidget->setIsDiscovering(bluetoothService.getIsDiscovering());
|
||||
|
||||
load_css();
|
||||
setup_ui();
|
||||
|
||||
clock.onUpdate();
|
||||
|
||||
Glib::signal_timeout().connect(sigc::mem_fun(clock, &Clock::onUpdate),
|
||||
1000);
|
||||
|
||||
date.onUpdate();
|
||||
|
||||
Glib::signal_timeout().connect(sigc::mem_fun(clock, &Clock::onUpdate), 1000);
|
||||
Glib::signal_timeout().connect(sigc::mem_fun(date, &Date::onUpdate), 1000);
|
||||
}
|
||||
|
||||
@@ -83,8 +91,9 @@ void Bar::setup_center_box() {
|
||||
}
|
||||
|
||||
void Bar::setup_right_box() {
|
||||
right_box.append(*trayWidget);
|
||||
right_box.append(homeAssistant);
|
||||
right_box.append(*this->trayWidget);
|
||||
right_box.append(this->homeAssistant);
|
||||
right_box.append(*this->bluetoothWidget);
|
||||
}
|
||||
|
||||
void Bar::load_css() {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#include "components/todoEntry.hpp"
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
#include <string>
|
||||
|
||||
#include "gtkmm/button.h"
|
||||
|
||||
TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed)
|
||||
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);
|
||||
@@ -35,6 +36,10 @@ TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_di
|
||||
|
||||
dismissButton->signal_clicked().connect(sigc::mem_fun(*this, &TodoEntry::on_dismiss_clicked));
|
||||
|
||||
auto editButton = Gtk::make_managed<Gtk::Button>("\uf044");
|
||||
editButton->set_valign(Gtk::Align::CENTER);
|
||||
|
||||
buttonBox->append(*editButton);
|
||||
buttonBox->append(*dismissButton);
|
||||
}
|
||||
|
||||
|
||||
185
src/services/bluetooth.cpp
Normal file
185
src/services/bluetooth.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
#include "services/bluetooth.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "glib.h"
|
||||
#include "sigc++/signal.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);
|
||||
} else {
|
||||
std::cout << "Bluetooth adapter proxy created successfully." << std::endl;
|
||||
}
|
||||
|
||||
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::setPowerState(bool state) {
|
||||
GError *error = nullptr;
|
||||
|
||||
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::setIsDiscovering(bool state) {
|
||||
const bool currently_discovering = this->getIsDiscovering();
|
||||
this->isDiscovering = currently_discovering;
|
||||
|
||||
if (currently_discovering == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
GError *error = nullptr;
|
||||
|
||||
const char *method = state ? "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 = state;
|
||||
|
||||
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)) {
|
||||
|
||||
this->setIsDiscovering(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <stdexcept>
|
||||
@@ -10,8 +11,6 @@
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
|
||||
HyprlandService::HyprlandService() = default;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "services/todoAdapter.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "services/todoAdapter.hpp"
|
||||
|
||||
namespace {
|
||||
std::string getDbPath() {
|
||||
const char *homeDir = getenv("HOME");
|
||||
@@ -31,7 +31,6 @@ class SqliteTodoAdapter final : public ITodoAdapter {
|
||||
|
||||
bool init() override {
|
||||
std::string dbPath = getDbPath();
|
||||
std::cout << "Opening database at: " << dbPath << std::endl;
|
||||
|
||||
int rc = sqlite3_open(dbPath.c_str(), &db_);
|
||||
if (rc != SQLITE_OK) {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "services/todo.hpp"
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "gtkmm/object.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <gtkmm/object.h>
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
|
||||
std::unique_ptr<ITodoAdapter> makeSqliteTodoAdapter();
|
||||
|
||||
@@ -62,9 +64,13 @@ TodoEntry *TodoService::addTodo(std::string text, bool emitSignal, bool persist)
|
||||
id = newId;
|
||||
}
|
||||
|
||||
auto signal = sigc::signal<void(int)>();
|
||||
signal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, signal);
|
||||
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;
|
||||
|
||||
@@ -79,14 +85,24 @@ TodoEntry *TodoService::addTodo(std::string text, bool emitSignal, bool persist)
|
||||
return todo;
|
||||
}
|
||||
|
||||
void TodoService::updateTodo(int id, std::string text) {}
|
||||
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;
|
||||
}
|
||||
|
||||
std::cout << "Loading todos from database..." << std::endl;
|
||||
auto rows = this->adapter->listTodos();
|
||||
|
||||
int count = 0;
|
||||
@@ -96,14 +112,17 @@ void TodoService::load() {
|
||||
int id = row.id;
|
||||
std::string text = row.text;
|
||||
|
||||
auto signal = sigc::signal<void(int)>();
|
||||
signal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, signal);
|
||||
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;
|
||||
}
|
||||
}
|
||||
std::cout << "Loaded " << count << " todos." << std::endl;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "services/tray.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <gdkmm/pixbuf.h>
|
||||
#include <gdkmm/texture.h>
|
||||
#include <gio/gdbusmenumodel.h>
|
||||
@@ -7,9 +9,6 @@
|
||||
#include <giomm/dbusactiongroup.h>
|
||||
#include <giomm/dbusownname.h>
|
||||
#include <giomm/menumodel.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
70
src/widgets/bluetooth.cpp
Normal file
70
src/widgets/bluetooth.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "widgets/bluetooth.hpp"
|
||||
|
||||
BluetoothWidget::BluetoothWidget(std::string icon, std::string title) : Popover(icon, title) {
|
||||
this->popover->set_size_request(100, -1);
|
||||
set_popover_child(this->container);
|
||||
|
||||
this->container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->container.set_spacing(10);
|
||||
this->container.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->container.append(this->statusArea);
|
||||
|
||||
this->toggleButton = Gtk::make_managed<Gtk::Button>("\ue1a8");
|
||||
this->toggleButton->add_css_class("bluetooth-toggle-button");
|
||||
this->toggleButton->set_tooltip_text("Turn Bluetooth Off");
|
||||
this->toggleButton->signal_clicked().connect([this]() {
|
||||
const bool newState = !isPowered;
|
||||
setPowerState(newState);
|
||||
powerStateChangedSignal.emit(newState);
|
||||
});
|
||||
this->toggleButton->add_css_class("toggle-button");
|
||||
|
||||
this->scanButton = Gtk::make_managed<Gtk::Button>("\ue1aa");
|
||||
this->scanButton->set_tooltip_text("Scan for Devices");
|
||||
this->scanButton->add_css_class("bluetooth-scan-button");
|
||||
this->scanButton->signal_clicked().connect([this]() {
|
||||
const bool newState = !isDiscovering;
|
||||
setIsDiscovering(newState);
|
||||
isDiscoveringChangedSignal.emit(newState);
|
||||
});
|
||||
|
||||
this->statusArea.append(*this->toggleButton);
|
||||
this->statusArea.append(*this->scanButton);
|
||||
}
|
||||
|
||||
void BluetoothWidget::setPowerState(bool state) {
|
||||
this->isPowered = state;
|
||||
|
||||
if (state) {
|
||||
this->toggleButton->set_label("\ue1a8");
|
||||
this->toggleButton->add_css_class("toggle-button-on");
|
||||
this->toggleButton->remove_css_class("toggle-button-off");
|
||||
} else {
|
||||
this->toggleButton->set_label("\ue1a9");
|
||||
this->toggleButton->add_css_class("toggle-button-off");
|
||||
this->toggleButton->remove_css_class("toggle-button-on");
|
||||
}
|
||||
|
||||
this->setIsDiscovering(false);
|
||||
}
|
||||
|
||||
void BluetoothWidget::setIsDiscovering(bool state) {
|
||||
this->isDiscovering = state;
|
||||
|
||||
if (state) {
|
||||
this->scanButton->add_css_class("toggle-button-on");
|
||||
this->scanButton->remove_css_class("toggle-button-off");
|
||||
} else {
|
||||
this->scanButton->add_css_class("toggle-button-off");
|
||||
this->scanButton->remove_css_class("toggle-button-on");
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothWidget::update() {
|
||||
setPowerState(isPowered);
|
||||
setIsDiscovering(isDiscovering);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "widgets/todoPopover.hpp"
|
||||
#include "widgets/todo.hpp"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/entry.h>
|
||||
@@ -12,7 +12,6 @@ TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, ti
|
||||
container.set_spacing(10);
|
||||
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");
|
||||
@@ -52,13 +51,13 @@ TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, ti
|
||||
void TodoPopover::update() {
|
||||
auto todos = this->todoService->getTodos();
|
||||
|
||||
Gtk::Widget* child = todoList->get_first_child();
|
||||
Gtk::Widget *child = todoList->get_first_child();
|
||||
|
||||
while (child) {
|
||||
Gtk::Widget* next = child->get_next_sibling();
|
||||
Gtk::Widget *next = child->get_next_sibling();
|
||||
|
||||
bool found = false;
|
||||
for (auto& [id, todo] : todos) {
|
||||
for (auto &[id, todo] : todos) {
|
||||
if (child == todo) {
|
||||
found = true;
|
||||
break;
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <sigc++/functors/mem_fun.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
|
||||
VolumeWidget::VolumeWidget() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||
set_valign(Gtk::Align::CENTER);
|
||||
set_halign(Gtk::Align::CENTER);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "widgets/webWidget.hpp"
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
#include <webkit/webkit.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <gdk/gdk.h>
|
||||
@@ -7,6 +6,8 @@
|
||||
#include <gtkmm/widget.h>
|
||||
#include <sigc++/functors/mem_fun.h>
|
||||
|
||||
#include "services/hyprland.hpp"
|
||||
|
||||
WorkspaceIndicator::WorkspaceIndicator(HyprlandService &service, int monitorId)
|
||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service),
|
||||
monitorId(monitorId) {
|
||||
|
||||
Reference in New Issue
Block a user