Compare commits

...

4 Commits

Author SHA1 Message Date
2d5b492da8 deine mum 2025-12-30 21:55:11 +01:00
9b5db719cb refactor and shizz 2025-12-25 21:13:00 +01:00
a06c96f648 make bluetooth service singleton 2025-12-23 19:57:52 +01:00
8613024f8d nicer button interactivities 2025-12-22 02:32:18 +01:00
29 changed files with 504 additions and 394 deletions

View File

@@ -39,9 +39,11 @@ target_sources(bar_lib
src/widgets/tray.cpp
src/widgets/todo.cpp
src/widgets/bluetooth.cpp
src/widgets/controlCenter.cpp
src/components/popover.cpp
src/components/todoEntry.cpp
src/components/base/button.cpp
)
include_directories(bar_lib PRIVATE
include

View File

@@ -3,7 +3,6 @@
#include <vector>
#include "bar/bar.hpp"
#include "services/bluetooth.hpp"
#include "services/hyprland.hpp"
#include "services/notifications.hpp"
#include "services/tray.hpp"
@@ -20,10 +19,9 @@ class App {
private:
Glib::RefPtr<Gtk::Application> app;
std::vector<Bar *> bars;
HyprlandService hyprlandService;
HyprlandService *hyprlandService = HyprlandService::getInstance();
NotificationService notificationService;
TrayService trayService;
BluetoothService bluetoothService;
TrayService *trayService = TrayService::getInstance();
void setupServices();
};

View File

@@ -4,42 +4,35 @@
#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"
#include "widgets/volumeWidget.hpp"
#include "widgets/webWidget.hpp"
#include "widgets/workspaceIndicator.hpp"
#include "widgets/controlCenter.hpp"
class Bar : public Gtk::Window {
public:
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, BluetoothService &bluetoothService, int monitorId);
Bar(GdkMonitor *monitor, int monitorId);
private:
int monitorId;
protected:
Gtk::CenterBox main_box{};
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
Gtk::Box right_box{Gtk::Orientation::HORIZONTAL};
private:
int monitorId;
Clock clock;
Date date;
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
ControlCenter controlCenter{"\ue8bb", "Control Center"};
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();

View File

@@ -0,0 +1,18 @@
#pragma once
#include <gtkmm/button.h>
#include "gtkmm/image.h"
#include "sigc++/signal.h"
class Button : public Gtk::Button {
public:
Button(const std::string label);
Button(Gtk::Image &image);
sigc::signal<void()> onClickedSignal;
private:
void on_clicked() {
onClickedSignal.emit();
}
};

View File

@@ -3,10 +3,11 @@
#include <gtkmm/button.h>
#include <gtkmm/popover.h>
#include <string>
#include "components/base/button.hpp"
class Popover : public Gtk::Button {
class Popover : public Button {
public:
Popover(std::string icon, std::string name);
Popover(const std::string icon, std::string name);
~Popover() override;
protected:

View File

@@ -7,7 +7,6 @@
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);
~TodoEntry() override;
int get_id() const { return id; }
std::string get_text() const { return text; }

View File

@@ -2,26 +2,40 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <string>
#include <vector>
#include "sigc++/signal.h"
class BluetoothService {
inline static BluetoothService *instance = nullptr;
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:
void togglePowerState();
void toggleIsDiscovering();
static BluetoothService *getInstance() {
if (BluetoothService::instance == nullptr) {
BluetoothService::instance = new BluetoothService();
}
return BluetoothService::instance;
}
private:
BluetoothService();
GDBusProxy *adapter_proxy = nullptr;
bool powerState = false;
bool isDiscovering = false;
std::vector<std::string> getDeviceObjectPaths();
bool powerState = false;
bool isDiscovering = false;
void onPropertyChanged(GDBusProxy *proxy,
GVariant *changed_properties,

View File

@@ -5,9 +5,12 @@
#include <map>
#include <sigc++/sigc++.h>
#include <string>
#include <sys/stat.h>
#include <vector>
class HyprlandService {
inline static HyprlandService *instance = nullptr;
public:
static constexpr int kWorkspaceSlotCount = 7;
const char *kMonitorCommand = "hyprctl monitors -j";
@@ -36,9 +39,6 @@ class HyprlandService {
int focusedWorkspaceId = -1;
};
HyprlandService();
~HyprlandService();
void start();
void on_hyprland_event(std::string event, std::string data);
void printMonitor(const Monitor &mon) const;
@@ -55,11 +55,21 @@ class HyprlandService {
return this->workspaces;
}
static HyprlandService *getInstance() {
if (HyprlandService::instance == nullptr) {
HyprlandService::instance = new HyprlandService();
}
return HyprlandService::instance;
}
private:
HyprlandService();
~HyprlandService();
int fd = -1;
std::map<int, Monitor> monitors;
std::map<int, WorkspaceState *> workspaces;
// persistent buffer for socket reads to handle partial messages
std::string socket_buffer;
std::string get_socket_path();

View File

@@ -16,6 +16,7 @@
#include <vector>
class TrayService {
inline static TrayService *instance = nullptr;
public:
struct Item {
std::string id;
@@ -29,9 +30,6 @@ class TrayService {
Glib::RefPtr<Gdk::Paintable> iconPaintable;
};
TrayService();
~TrayService();
void start();
void stop();
@@ -44,7 +42,6 @@ class TrayService {
Glib::RefPtr<Gio::MenuModel> get_menu_model(const std::string &id);
Glib::RefPtr<Gio::ActionGroup> get_menu_action_group(const std::string &id);
void debug_dump_menu_layout(const std::string &id);
struct MenuNode {
int id = 0;
std::string label;
@@ -60,7 +57,18 @@ class TrayService {
sigc::signal<void(const std::string &)> &signal_item_removed();
sigc::signal<void(const Item &)> &signal_item_updated();
static TrayService *getInstance() {
if (TrayService::instance == nullptr) {
TrayService::instance = new TrayService();
}
return TrayService::instance;
}
private:
TrayService();
~TrayService();
struct TrackedItem {
Item publicData;
guint signalSubscriptionId = 0;

View File

@@ -1,31 +1,68 @@
#pragma once
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include "components/popover.hpp"
#include "components/base/button.hpp"
#include "gtkmm/button.h"
class BluetoothWidget : public Popover {
class BluetoothEntry : Gtk::Box {
public:
BluetoothWidget(std::string icon, std::string title);
BluetoothEntry(std::string name, std::string address) {
this->set_orientation(Gtk::Orientation::VERTICAL);
this->add_css_class("bluetooth-entry-box");
auto nameLabel = Gtk::make_managed<Gtk::Label>(name);
nameLabel->set_halign(Gtk::Align::START);
nameLabel->add_css_class("bluetooth-entry-name");
this->append(*nameLabel);
auto addressLabel = Gtk::make_managed<Gtk::Label>(address);
addressLabel->set_halign(Gtk::Align::START);
addressLabel->add_css_class("bluetooth-entry-address");
this->append(*addressLabel);
this->add_css_class("bluetooth-entry");
auto connectButton = Gtk::make_managed<Button>("Connect");
connectButton->set_halign(Gtk::Align::END);
connectButton->set_tooltip_text("Connect to Device");
connectButton->onClickedSignal.connect([this, address]() {
this->connect_clicked.emit(address);
});
this->append(*connectButton);
}
sigc::signal<void(std::string)> connect_clicked;
};
class BluetoothWidget : public Gtk::Box {
public:
BluetoothWidget();
void setPowerState(bool state);
void setIsDiscovering(bool state);
sigc::signal<void(bool)> powerStateChangedSignal;
sigc::signal<void(bool)> isDiscoveringChangedSignal;
sigc::signal<void()> onPowerStateButtonClickedSignal;
sigc::signal<void()> onIsDiscoveringButtonClickedSignal;
void update();
private:
bool isPowered = false;
bool isPowered = false;
bool isDiscovering = false;
Gtk::Box container;
Gtk::Box statusArea;
std::map<std::string, BluetoothEntry *> deviceEntries;
Gtk::Box devicesArea;
Button *scanButton = nullptr;
Button *powerButton = nullptr;
Gtk::Box *deviceList = nullptr;
void onPowerButtonClicked();
void onScanButtonClicked();
Gtk::Button *scanButton = nullptr;
Gtk::Button *toggleButton = nullptr;
void toggleButton(Button *button, bool state);
};

View File

@@ -0,0 +1,17 @@
#pragma once
#include "components/popover.hpp"
#include "services/bluetooth.hpp"
#include "widgets/bluetooth.hpp"
#include "gtkmm/box.h"
class ControlCenter : public Popover {
public:
ControlCenter(std::string icon, std::string name);
private:
Gtk::Box container;
BluetoothWidget *bluetoothWidget = nullptr;
BluetoothService *bluetoothService = BluetoothService::getInstance();
};

View File

@@ -16,15 +16,16 @@
#include <string>
#include "services/tray.hpp"
#include "components/base/button.hpp"
class TrayIconWidget : public Gtk::Button {
class TrayIconWidget : public Button {
public:
TrayIconWidget(TrayService &service, std::string id);
TrayIconWidget(std::string id);
void update(const TrayService::Item &item);
private:
TrayService &service;
TrayService &service = *TrayService::getInstance();
std::string id;
Gtk::Box container;
Gtk::Picture picture;
@@ -53,11 +54,11 @@ class TrayIconWidget : public Gtk::Button {
class TrayWidget : public Gtk::Box {
public:
explicit TrayWidget(TrayService &service);
explicit TrayWidget();
~TrayWidget() override;
private:
TrayService &service;
TrayService *service = TrayService::getInstance();
std::map<std::string, std::unique_ptr<TrayIconWidget>> icons;
sigc::connection addConnection;

View File

@@ -8,6 +8,4 @@
class WebWidget : public Popover {
public:
WebWidget(std::string icon, std::string title, std::string url);
private:
};

View File

@@ -6,22 +6,23 @@
#include <sigc++/connection.h>
#include "services/hyprland.hpp"
#include "gtkmm/overlay.h"
class WorkspaceIndicator : public Gtk::Box {
public:
WorkspaceIndicator(HyprlandService &service, int monitorId);
WorkspaceIndicator(int monitorId);
~WorkspaceIndicator() override;
private:
HyprlandService &service;
HyprlandService *service = HyprlandService::getInstance();
int monitorId;
sigc::connection workspaceConnection;
sigc::connection monitorConnection;
std::map<int, Gtk::Label *> workspaceLabels;
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::Label *label, const HyprlandService::WorkspaceState &state);
void refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state);
};

View File

@@ -1,138 +1,138 @@
/** biome-ignore-all lint/correctness/noUnknownTypeSelector: gtk css has more valid identifiers */
* {
all: unset;
all: unset;
}
window {
background-color: rgba(30, 30, 30, 0.8);
color: #ffffff;
font-family: "IBMPlexSans-Regular", sans-serif;
font-size: 14px;
padding: 2px 7px;
}
#clock-label {
font-weight: bold;
font-family: monospace;
}
.workspace-pill {
padding: 2px 5px;
margin-right: 6px;
border-radius: 5px;
}
.workspace-pill:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.workspace-pill-focused {
background-color: #ffffff;
color: #1e1e1e;
font-weight: bold;
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
.workspace-pill-focused:hover {
box-shadow: none;
}
.workspace-pill-active {
background-color: rgba(255, 255, 255, 0.2);
}
.workspace-pill-urgent {
background-color: #ff5555;
color: #fff;
animation: workspace-blink 1s linear infinite;
}
/* blinking animation for urgent workspaces */
@keyframes workspace-blink {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
.workspace-pill:last-child {
margin-right: 0;
}
button {
padding: 2px 5px;
margin: 0 2px;
border-radius: 3px;
background-color: transparent;
color: #ffffff;
border: none;
font-size: 20px;
}
button:hover {
background-color: #111111;
}
#spacer {
color: rgba(255, 255, 255, 0.3);
padding: 0 5px;
background-color: #191919c6;
color: #ffffff;
padding-left: 4px;
padding-right: 4px;
padding-top: 2px;
padding-bottom: 2px;
font-size: 14px;
font-family:
"Hack Nerd Font Mono", "Font Awesome 7 Brands", "Font Awesome 7 Free",
sans-serif;
}
popover {
background-color: rgb(30, 30, 30);
color: #ffffff;
font-family: "IBMPlexSans-Regular", sans-serif;
padding: 5px;
border-radius: 8px;
border: 1px solid #444444;
margin-top: 5px;
margin-top: 4px;
font-family:
"Hack Nerd Font Mono", "Material Icons", "Font Awesome 7 Free", sans-serif;
padding: 6px;
border-radius: 8px;
background: rgba(25, 25, 25, 0.8);
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(57, 57, 57, 0.71);
font-size: 14px;
}
tooltip {
background-color: rgba(50, 50, 50, 0.9);
color: #ffffff;
font-family: "IBMPlexSans-Regular", sans-serif;
padding: 5px 10px;
background-color: #222222;
color: #ffffff;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
}
.icon-label {
font-family: "Material Icons, Font Awesome 7 Brands, Hack Nerd Font Mono";
font-size: 19px;
button {
font-family: "Material Icons", sans-serif;
font-size: 20px;
}
.todo-popover-container {
background-color: #1e1e1e;
#spacer {
font-weight: 900;
padding: 0 5px;
text-shadow: 0 0 5px #ffffffaa;
}
.todo-input-area {
margin-bottom: 10px;
.button {
padding: 4px 8px;
border-radius: 4px;
font-family: "Material Icons", sans-serif;
}
.todo-input {
padding: 5px;
border-radius: 4px;
border: 1px solid #555555;
background-color: #222222;
color: #ffffff;
.button:hover {
background-color: #111111;
}
.toggle-button {
border-radius: 4px;
.workspace-pill {
padding: 2px 5px;
margin-right: 6px;
border-radius: 5px;
text-shadow: 0 0 2px #646464;
transition:
background-color 0.2s,
color 0.2s,
box-shadow 0.2s;
}
/* 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;
.workspace-pill:hover {
background-color: rgba(255, 255, 255, 0.1);
color: #ffffff;
}
.toggle-button-off {
background-color: rgba(244, 67, 54, 0.2);
border: 1px solid #f44336;
}
.workspace-pill-active {
background-color: #666666;
}
.workspace-pill-focused {
background-color: #ffffff;
color: #1e1e1e;
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
.workspace-pill-focused:hover {
box-shadow: none;
}
.workspace-pill-urgent {
background-color: #ff5555;
color: #fff;
animation: workspace-blink 1s linear infinite;
}
.workspace-pill-six {
animation: workspace-updown 1.2s ease-in-out infinite;
margin-left: -4px;
margin-top: 4px;
font-size: 12px;
}
.workspace-pill-seven {
animation: workspace-updown 1.2s ease-in-out infinite;
animation-delay: 0.6s;
margin-right: -4px;
margin-top: 4px;
font-size: 12px;
}
@keyframes workspace-updown {
0% {
transform: translateY(4px);
}
50% {
transform: translateY(0px);
}
100% {
transform: translateY(4px);
}
}
@keyframes workspace-blink {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}

View File

@@ -22,17 +22,14 @@ App::App() {
try {
hyprlandMonitor =
this->hyprlandService.getMonitorByIndex(i);
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(), this->hyprlandService,
this->trayService, this->bluetoothService, hyprlandMonitor->id);
auto bar = new Bar(monitor->gobj(), hyprlandMonitor->id);
bar->set_application(app);
bar->show();
@@ -41,22 +38,23 @@ App::App() {
}
});
app->signal_shutdown().connect([&]() {
for (auto bar : bars) {
delete bar;
}
bars.clear();
this->trayService.stop();
this->trayService->stop();
});
}
void App::setupServices() {
this->hyprlandService.socketEventSignal.connect(sigc::mem_fun(
this->hyprlandService, &HyprlandService::on_hyprland_event));
this->hyprlandService->socketEventSignal.connect(sigc::mem_fun(
*this->hyprlandService, &HyprlandService::on_hyprland_event));
this->hyprlandService.start();
this->trayService.start();
this->hyprlandService->start();
this->trayService->start();
}
int App::run() { return this->app->run(); }

View File

@@ -16,10 +16,8 @@
#include "gtk/gtk.h"
#include "sigc++/functors/mem_fun.h"
Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
TrayService &trayService, BluetoothService &bluetoothService, int monitorId)
: hyprlandService(hyprlandService), trayService(trayService), bluetoothService(bluetoothService),
monitorId(monitorId) {
Bar::Bar(GdkMonitor *monitor, int monitorId)
: monitorId(monitorId) {
set_name("bar-window");
gtk_layer_init_for_window(this->gobj());
@@ -38,22 +36,9 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
set_child(main_box);
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");
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(monitorId);
this->trayWidget = Gtk::make_managed<TrayWidget>();
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();
@@ -93,7 +78,7 @@ void Bar::setup_center_box() {
void Bar::setup_right_box() {
right_box.append(*this->trayWidget);
right_box.append(this->homeAssistant);
right_box.append(*this->bluetoothWidget);
right_box.append(this->controlCenter);
}
void Bar::load_css() {

View File

@@ -0,0 +1,19 @@
#include "components/base/button.hpp"
#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));
this->add_css_class("button");
}
Button::Button(Gtk::Image &image)
: Gtk::Button() {
set_child(image);
signal_clicked().connect(
sigc::mem_fun(*this, &Button::on_clicked));
this->add_css_class("button");
}

View File

@@ -3,12 +3,8 @@
#include "gtkmm/label.h"
#include "gtkmm/object.h"
Popover::Popover(std::string icon, std::string name) {
auto label = Gtk::make_managed<Gtk::Label>(icon);
label->add_css_class("icon-label");
set_child(*label);
signal_clicked().connect(
sigc::mem_fun(*this, &Popover::on_toggle_window));
Popover::Popover(const std::string icon, std::string name): Button(icon) {
signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window));
popover = new Gtk::Popover();
popover->set_parent(*this);

View File

@@ -2,8 +2,7 @@
#include <gtkmm/label.h>
#include <string>
#include "gtkmm/button.h"
#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) {
@@ -30,22 +29,19 @@ TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_di
buttonBox->set_valign(Gtk::Align::CENTER);
append(*buttonBox);
auto dismissButton = Gtk::make_managed<Gtk::Button>("\uf00d");
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<Gtk::Button>("\uf044");
auto editButton = Gtk::make_managed<Button>("\uf044");
editButton->set_valign(Gtk::Align::CENTER);
buttonBox->append(*editButton);
buttonBox->append(*dismissButton);
}
TodoEntry::~TodoEntry() {
}
void TodoEntry::on_dismiss_clicked() {
this->signal_dismissed.emit(this->id);
}

View File

@@ -2,9 +2,10 @@
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include "glib.h"
#include "sigc++/signal.h"
BluetoothService::BluetoothService() {
GError *error = nullptr;
@@ -24,9 +25,7 @@ BluetoothService::BluetoothService() {
<< 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();
@@ -72,8 +71,9 @@ bool BluetoothService::getIsDiscovering() {
return discovering;
}
void BluetoothService::setPowerState(bool state) {
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(
@@ -108,17 +108,11 @@ void BluetoothService::setPowerState(bool state) {
}
}
void BluetoothService::setIsDiscovering(bool state) {
const bool currently_discovering = this->getIsDiscovering();
this->isDiscovering = currently_discovering;
if (currently_discovering == state) {
return;
}
void BluetoothService::toggleIsDiscovering() {
bool newState = !this->isDiscovering;
GError *error = nullptr;
const char *method = state ? "StartDiscovery" : "StopDiscovery";
const char *method = newState ? "StartDiscovery" : "StopDiscovery";
GVariant *reply = g_dbus_proxy_call_sync(
this->adapter_proxy,
method,
@@ -140,7 +134,7 @@ void BluetoothService::setIsDiscovering(bool state) {
return;
}
this->isDiscovering = state;
this->isDiscovering = newState;
if (reply) {
g_variant_unref(reply);
@@ -157,8 +151,10 @@ void BluetoothService::onPropertyChanged(GDBusProxy *proxy,
if (g_variant_lookup(changed_properties, "Powered", "b", &is_powered)) {
this->setIsDiscovering(false);
isDiscoveringChangedSignal.emit(isDiscovering);
if (!is_powered) {
this->isDiscovering = is_discovering;
isDiscoveringChangedSignal.emit(isDiscovering);
}
this->powerState = is_powered;
powerStateChangedSignal.emit(powerState);
@@ -167,6 +163,7 @@ void BluetoothService::onPropertyChanged(GDBusProxy *proxy,
if (g_variant_lookup(changed_properties, "Discovering", "b", &is_discovering)) {
this->isDiscovering = is_discovering;
isDiscoveringChangedSignal.emit(isDiscovering);
getDeviceObjectPaths();
}
}
@@ -182,4 +179,59 @@ void BluetoothService::onPropertyChangedStatic(GDBusProxy *proxy,
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;
}

View File

@@ -43,9 +43,6 @@ void HyprlandService::on_hyprland_event(std::string event, std::string data) {
refresh_workspaces();
}
// use for
// event == "focusedmon"
if (event == "monitoradded" || event == "monitorremoved") {
refresh_monitors();
}
@@ -77,8 +74,6 @@ void HyprlandService::start() {
return;
}
std::cout << "[Hyprland] Connected to event socket." << std::endl;
Glib::signal_io().connect(
sigc::mem_fun(*this, &HyprlandService::on_socket_read), fd,
Glib::IOCondition::IO_IN | Glib::IOCondition::IO_HUP |
@@ -263,10 +258,10 @@ void HyprlandService::onUrgentEvent(std::string windowAddress) {
auto it = this->workspaces.find(workspaceId);
if (it != this->workspaces.end() && it->second) {
if (std::find(it->second->urgentWindows.begin(),
it->second->urgentWindows.end(), windowAddress) ==
it->second->urgentWindows.end()) {
it->second->urgentWindows.push_back(windowAddress);
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();
}
}
@@ -300,45 +295,6 @@ void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
}
}
void HyprlandService::printMonitor(const Monitor &mon) const {
std::cout << "=== Monitor Info ===\n";
std::cout << "Name: " << mon.name << " (ID: " << mon.id << ")\n";
std::cout << "Position: (" << mon.x << ", " << mon.y << ")\n";
std::cout << "Focused Workspace ID: " << mon.focusedWorkspaceId << "\n";
std::cout << "Workspaces:\n";
if (mon.workspaceStates.empty()) {
std::cout << " (None)\n";
return;
}
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount; ++slot) {
const auto it = mon.workspaceStates.find(slot);
if (it == mon.workspaceStates.end()) {
std::cout << " - [Slot: " << slot << " | HyprID: n/a]"
<< " Label: <none> | Active: No | Focused: No | "
"Urgent: No\n";
continue;
}
const WorkspaceState *ws = it->second;
std::cout << " - [HyprID: "
<< (ws->hyprId >= 0 ? std::to_string(ws->hyprId)
: std::string("n/a"))
<< "] "
<< "Label: " << (ws->label.empty() ? "<none>" : ws->label)
<< " | "
<< "Active: " << (ws->active ? "Yes" : "No") << " | "
<< "Focused: " << (ws->focused ? "Yes" : "No") << " | "
<< "Urgent: " << (ws->urgentWindows.size() > 0 ? "Yes" : "No")
<< "\n";
}
std::cout << "====================\n";
}
HyprlandService::Monitor *HyprlandService::getMonitorById(int id) {
auto it = monitors.find(id);
if (it == monitors.end()) {

View File

@@ -302,6 +302,4 @@ void NotificationService::intialize() {
<< "). Stop your existing notification daemon (e.g. dunst/mako/swaync) or allow replacement." << std::endl;
return;
}
std::cout << "Notifications daemon active (org.freedesktop.Notifications)." << std::endl;
}

View File

@@ -485,34 +485,6 @@ TrayService::get_menu_action_group(const std::string &id) {
return item.menuActions;
}
void TrayService::debug_dump_menu_layout(const std::string &id) {
auto it = items.find(id);
if (it == items.end() || !connection) {
return;
}
const auto &item = *it->second;
if (!item.publicData.menuAvailable || item.publicData.menuPath.empty()) {
return;
}
GVariant *result = call_get_layout(connection, item.publicData.busName,
item.publicData.menuPath);
if (!result) {
return;
}
gchar *printed = g_variant_print(result, TRUE);
if (printed) {
std::cout << "[TrayService] GetLayout for " << id << ":\n"
<< printed << std::endl;
g_free(printed);
}
g_variant_unref(result);
}
std::optional<TrayService::MenuNode>
TrayService::get_menu_layout(const std::string &id) {
auto it = items.find(id);

View File

@@ -1,67 +1,69 @@
#include "widgets/bluetooth.hpp"
#include "gtkmm/label.h"
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");
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->container.append(this->statusArea);
this->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->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<Gtk::Button>("\ue1aa");
this->scanButton = Gtk::make_managed<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->scanButton->add_css_class("toggle-button");
this->scanButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onScanButtonClicked));
this->statusArea.append(*this->toggleButton);
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;
if (state) {
this->toggleButton->set_label("\ue1a8");
this->toggleButton->add_css_class("toggle-button-on");
this->toggleButton->remove_css_class("toggle-button-off");
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->toggleButton->set_label("\ue1a9");
this->toggleButton->add_css_class("toggle-button-off");
this->toggleButton->remove_css_class("toggle-button-on");
this->scanButton->remove_css_class("toggle-button-disabled");
// this->remove_css_class("disabled-popover-icon");
}
this->setIsDiscovering(false);
this->toggleButton(this->powerButton, state);
}
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");
}
this->toggleButton(this->scanButton, state);
}
void BluetoothWidget::update() {

View File

@@ -0,0 +1,24 @@
#include "widgets/controlCenter.hpp"
ControlCenter::ControlCenter(std::string icon, std::string name)
: Popover(icon, name) {
this->popover->set_size_request(200, -1);
set_popover_child(this->container);
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());
}

View File

@@ -9,7 +9,6 @@ TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, ti
this->popover->set_size_request(300, -1);
container.set_orientation(Gtk::Orientation::VERTICAL);
container.set_spacing(10);
container.add_css_class("todo-popover-container");
auto entry = Gtk::make_managed<Gtk::Entry>();

View File

@@ -5,9 +5,10 @@
#include <gtk/gtk.h>
#include <iostream>
#include <utility>
#include "components/base/button.hpp"
TrayIconWidget::TrayIconWidget(TrayService &service, std::string id)
: service(service), id(std::move(id)),
TrayIconWidget::TrayIconWidget( std::string id)
: Button(id), id(std::move(id)),
container(Gtk::Orientation::HORIZONTAL) {
set_has_frame(false);
set_focusable(false);
@@ -131,10 +132,8 @@ bool TrayIconWidget::ensure_menu() {
populate_menu_items(layout.children, menu, actions);
const auto itemCount = menu->get_n_items();
std::cout << "[TrayIconWidget] menu update for " << id
<< ", items: " << itemCount << std::endl;
if (itemCount == 0) {
service.debug_dump_menu_layout(id);
return false;
}
@@ -174,9 +173,6 @@ void TrayIconWidget::on_menu_items_changed(guint /*position*/,
return;
}
const auto count = menuModel->get_n_items();
std::cout << "[TrayIconWidget] items changed for " << id << ": " << count
<< " entries" << std::endl;
try_popup();
}
@@ -251,17 +247,17 @@ void TrayIconWidget::on_menu_action(const Glib::VariantBase & /*parameter*/,
}
}
TrayWidget::TrayWidget(TrayService &service)
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service) {
TrayWidget::TrayWidget()
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
set_valign(Gtk::Align::CENTER);
set_halign(Gtk::Align::CENTER);
set_visible(false);
addConnection = service.signal_item_added().connect(
addConnection = service->signal_item_added().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_added));
removeConnection = service.signal_item_removed().connect(
removeConnection = service->signal_item_removed().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_removed));
updateConnection = service.signal_item_updated().connect(
updateConnection = service->signal_item_updated().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_updated));
rebuild_existing();
@@ -280,7 +276,7 @@ TrayWidget::~TrayWidget() {
}
void TrayWidget::rebuild_existing() {
auto items = service.snapshotItems();
auto items = service->snapshotItems();
for (const auto &item : items) {
on_item_added(item);
}
@@ -295,7 +291,7 @@ void TrayWidget::on_item_added(const TrayService::Item &item) {
return;
}
auto icon = std::make_unique<TrayIconWidget>(service, item.id);
auto icon = std::make_unique<TrayIconWidget>(item.id);
icon->update(item);
auto *raw = icon.get();
append(*raw);

View File

@@ -3,39 +3,57 @@
#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"
WorkspaceIndicator::WorkspaceIndicator(HyprlandService &service, int monitorId)
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service),
#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(
workspaceConnection = service->workspaceStateChanged.connect(
sigc::mem_fun(*this, &WorkspaceIndicator::on_workspace_update));
monitorConnection = service.monitorStateChanged.connect(
monitorConnection = service->monitorStateChanged.connect(
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
for (int i = 1; i <= HyprlandService::kWorkspaceSlotCount; ++i) {
auto label = Gtk::make_managed<Gtk::Label>(std::to_string(i));
label->add_css_class("workspace-pill");
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);
// create and store a gesture controller once to avoid duplicate handlers
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);
});
label->add_controller(gesture);
workspaceGestures[i] = gesture;
gesture->signal_released().connect([this, i](int, double, double) {
this->service->switchToWorkspace(
i + this->monitorId * HyprlandService::kWorkspaceSlotCount);
});
workspaceLabels[i] = label;
append(*label);
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();
@@ -55,30 +73,32 @@ void WorkspaceIndicator::on_workspace_update() {
rebuild();
}
void WorkspaceIndicator::on_monitor_update() { rebuild(); }
void WorkspaceIndicator::on_monitor_update() {
rebuild();
}
void WorkspaceIndicator::refreshLabel(Gtk::Label *label, const HyprlandService::WorkspaceState &state) {
label->remove_css_class("workspace-pill-active");
label->remove_css_class("workspace-pill-focused");
label->remove_css_class("workspace-pill-urgent");
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) {
label->add_css_class("workspace-pill-urgent");
overlay->add_css_class("workspace-pill-urgent");
} else {
if (state.focused) {
label->add_css_class("workspace-pill-focused");
overlay->add_css_class("workspace-pill-focused");
} else if (state.active) {
label->add_css_class("workspace-pill-active");
overlay->add_css_class("workspace-pill-active");
}
}
}
void WorkspaceIndicator::rebuild() {
HyprlandService::Monitor *mon = service.getMonitorById(this->monitorId);
HyprlandService::Monitor *mon = service->getMonitorById(this->monitorId);
for (auto [id, workspaceState] : mon->workspaceStates) {
Gtk::Label *label = workspaceLabels[id];
this->refreshLabel(label, *workspaceState);
Gtk::Overlay *overlay = workspaceIndicators[id];
this->refreshLabel(overlay, *workspaceState);
}
}
}