Compare commits
4 Commits
47f052f913
...
5a429a3b8b
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a429a3b8b | |||
| 0101ea1ec0 | |||
| 22a1b7e369 | |||
| 36f8b6d8b2 |
@@ -1,3 +1,12 @@
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 0
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveAssignments: true
|
||||
|
||||
IncludeCategories:
|
||||
- Regex: '^(<.+>)$'
|
||||
Priority: 1
|
||||
- Regex: '^"(.+\.hpp)"$'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeBlocks: Regroup
|
||||
@@ -12,25 +12,36 @@ find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)
|
||||
pkg_check_modules(LAYERSHELL REQUIRED gtk4-layer-shell-0)
|
||||
pkg_check_modules(WEBKIT REQUIRED webkitgtk-6.0)
|
||||
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
|
||||
|
||||
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS})
|
||||
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS})
|
||||
include_directories(${GTKMM_INCLUDE_DIRS} ${LAYERSHELL_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS} ${SQLITE3_INCLUDE_DIRS})
|
||||
link_directories(${GTKMM_LIBRARY_DIRS} ${LAYERSHELL_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS} ${SQLITE3_LIBRARY_DIRS})
|
||||
|
||||
add_library(bar_lib)
|
||||
target_sources(bar_lib
|
||||
PUBLIC
|
||||
src/app.cpp
|
||||
src/bar/bar.cpp
|
||||
|
||||
src/widgets/clock.cpp
|
||||
src/widgets/date.cpp
|
||||
src/widgets/workspaceIndicator.cpp
|
||||
src/widgets/volumeWidget.cpp
|
||||
src/widgets/webWidget.cpp
|
||||
|
||||
src/services/todo.cpp
|
||||
src/services/sqliteTodoAdapter.cpp
|
||||
src/services/hyprland.cpp
|
||||
src/services/tray.cpp
|
||||
src/services/notifications.cpp
|
||||
src/services/bluetooth.cpp
|
||||
|
||||
src/widgets/tray.cpp
|
||||
src/widgets/todo.cpp
|
||||
src/widgets/bluetooth.cpp
|
||||
|
||||
src/components/popover.cpp
|
||||
src/components/todoEntry.cpp
|
||||
)
|
||||
include_directories(bar_lib PRIVATE
|
||||
include
|
||||
@@ -38,7 +49,7 @@ include_directories(bar_lib PRIVATE
|
||||
|
||||
add_executable(bar main.cpp)
|
||||
|
||||
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${WEBKIT_LIBRARIES})
|
||||
target_link_libraries(bar bar_lib ${GTKMM_LIBRARIES} ${LAYERSHELL_LIBRARIES} ${WEBKIT_LIBRARIES} ${SQLITE3_LIBRARIES})
|
||||
|
||||
# Copy `resources/bar.css` into the build directory when it changes
|
||||
set(RES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/bar.css")
|
||||
|
||||
@@ -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,19 +2,22 @@
|
||||
|
||||
#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"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
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{};
|
||||
@@ -23,17 +26,24 @@ class Bar : public Gtk::Window {
|
||||
Gtk::Box right_box{Gtk::Orientation::HORIZONTAL};
|
||||
|
||||
private:
|
||||
int monitorId;
|
||||
|
||||
Clock clock;
|
||||
Date date;
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant",
|
||||
"https://home.rivercry.com"};
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
|
||||
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
VolumeWidget *volumeWidget = nullptr;
|
||||
BluetoothWidget *bluetoothWidget = nullptr;
|
||||
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
int monitorId;
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
class VolumeWidget *volumeWidget = nullptr;
|
||||
BluetoothService &bluetoothService;
|
||||
|
||||
void setup_ui();
|
||||
void setup_left_box();
|
||||
void setup_center_box();
|
||||
void setup_right_box();
|
||||
void load_css();
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
};
|
||||
22
include/components/todoEntry.hpp
Normal file
22
include/components/todoEntry.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "gtkmm/box.h"
|
||||
|
||||
class TodoEntry : public Gtk::Box {
|
||||
public:
|
||||
TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited);
|
||||
~TodoEntry() override;
|
||||
|
||||
int get_id() const { return id; }
|
||||
std::string get_text() const { return text; }
|
||||
|
||||
private:
|
||||
int id;
|
||||
std::string text;
|
||||
sigc::signal<void(int)> signal_dismissed;
|
||||
sigc::signal<void(int, std::string)> signal_edited;
|
||||
|
||||
void on_dismiss_clicked();
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
class IUpdatable {
|
||||
public:
|
||||
virtual ~IUpdatable() = default;
|
||||
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;
|
||||
guint registrationId = 0;
|
||||
GDBusNodeInfo* nodeInfo = nullptr;
|
||||
guint32 nextNotificationId = 1;
|
||||
private:
|
||||
GDBusConnection *connection = nullptr;
|
||||
guint registrationId = 0;
|
||||
GDBusNodeInfo *nodeInfo = nullptr;
|
||||
guint32 nextNotificationId = 1;
|
||||
};
|
||||
|
||||
28
include/services/todo.hpp
Normal file
28
include/services/todo.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "services/todoAdapter.hpp"
|
||||
|
||||
class TodoService {
|
||||
public:
|
||||
TodoService(sigc::signal<void()> refreshSignal);
|
||||
~TodoService();
|
||||
|
||||
std::map<int, TodoEntry *> getTodos();
|
||||
void init();
|
||||
void removeTodo(int id);
|
||||
TodoEntry *addTodo(std::string text, bool emitSignal = true, bool persist = true);
|
||||
void updateTodo(int id, std::string text);
|
||||
|
||||
private:
|
||||
void load();
|
||||
|
||||
int nextId = 1;
|
||||
std::map<int, TodoEntry *> todos;
|
||||
sigc::signal<void()> refreshSignal;
|
||||
|
||||
std::unique_ptr<ITodoAdapter> adapter;
|
||||
};
|
||||
21
include/services/todoAdapter.hpp
Normal file
21
include/services/todoAdapter.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct TodoRecord {
|
||||
int id;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class ITodoAdapter {
|
||||
public:
|
||||
virtual ~ITodoAdapter() = default;
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual std::vector<TodoRecord> listTodos() = 0;
|
||||
|
||||
virtual int addTodo(const std::string &text) = 0;
|
||||
virtual bool removeTodo(int id) = 0;
|
||||
virtual bool updateTodo(int id, const std::string &text) = 0;
|
||||
};
|
||||
@@ -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>
|
||||
|
||||
@@ -49,8 +48,8 @@ class TrayService {
|
||||
struct MenuNode {
|
||||
int id = 0;
|
||||
std::string label;
|
||||
bool enabled = true;
|
||||
bool visible = true;
|
||||
bool enabled = true;
|
||||
bool visible = true;
|
||||
bool separator = false;
|
||||
std::vector<MenuNode> children;
|
||||
};
|
||||
@@ -65,7 +64,7 @@ class TrayService {
|
||||
struct TrackedItem {
|
||||
Item publicData;
|
||||
guint signalSubscriptionId = 0;
|
||||
guint ownerWatchId = 0;
|
||||
guint ownerWatchId = 0;
|
||||
Glib::RefPtr<Gio::MenuModel> menuModel;
|
||||
Glib::RefPtr<Gio::ActionGroup> menuActions;
|
||||
};
|
||||
@@ -74,9 +73,9 @@ class TrayService {
|
||||
Glib::RefPtr<Gio::DBus::NodeInfo> nodeInfo;
|
||||
Gio::DBus::InterfaceVTable vtable;
|
||||
|
||||
guint nameOwnerId = 0;
|
||||
guint nameOwnerId = 0;
|
||||
guint registrationId = 0;
|
||||
bool hostRegistered = false;
|
||||
bool hostRegistered = false;
|
||||
|
||||
std::map<std::string, std::unique_ptr<TrackedItem>> items;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
21
include/widgets/todo.hpp
Normal file
21
include/widgets/todo.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "components/popover.hpp"
|
||||
#include "services/todo.hpp"
|
||||
|
||||
class TodoPopover : public Popover {
|
||||
|
||||
public:
|
||||
TodoPopover(std::string icon, std::string title);
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
TodoService *todoService = nullptr;
|
||||
Gtk::Box container;
|
||||
Gtk::Box inputArea;
|
||||
Gtk::Box *todoList = nullptr;
|
||||
};
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <gtkmm/image.h>
|
||||
#include <gtkmm/picture.h>
|
||||
#include <gtkmm/popovermenu.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -37,8 +36,8 @@ class TrayIconWidget : public Gtk::Button {
|
||||
Glib::RefPtr<Gio::MenuModel> menuModel;
|
||||
sigc::connection menuChangedConnection;
|
||||
bool menuPopupPending = false;
|
||||
double pendingX = 0.0;
|
||||
double pendingY = 0.0;
|
||||
double pendingX = 0.0;
|
||||
double pendingY = 0.0;
|
||||
|
||||
void on_primary_released(int n_press, double x, double y);
|
||||
void on_secondary_released(int n_press, double x, double y);
|
||||
|
||||
@@ -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"
|
||||
@@ -18,7 +18,7 @@ class WorkspaceIndicator : public Gtk::Box {
|
||||
sigc::connection workspaceConnection;
|
||||
sigc::connection monitorConnection;
|
||||
std::map<int, Gtk::Label *> workspaceLabels;
|
||||
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
|
||||
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
|
||||
|
||||
void rebuild();
|
||||
void on_workspace_update();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
all: unset;
|
||||
}
|
||||
|
||||
|
||||
window {
|
||||
background-color: rgba(30, 30, 30, 0.8);
|
||||
color: #ffffff;
|
||||
@@ -66,14 +65,6 @@ window {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.minimized {
|
||||
background-color: rgba(50, 50, 50, 0.5);
|
||||
}
|
||||
|
||||
.restored {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 2px 5px;
|
||||
margin: 0 2px;
|
||||
@@ -81,6 +72,7 @@ button {
|
||||
background-color: transparent;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
@@ -96,6 +88,10 @@ 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;
|
||||
}
|
||||
|
||||
tooltip {
|
||||
@@ -108,4 +104,35 @@ tooltip {
|
||||
.icon-label {
|
||||
font-family: "Material Icons, Font Awesome 7 Brands, Hack Nerd Font Mono";
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
.todo-popover-container {
|
||||
background-color: #1e1e1e;
|
||||
}
|
||||
|
||||
.todo-input-area {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.todo-input {
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #555555;
|
||||
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,25 +1,24 @@
|
||||
#include "bar/bar.hpp"
|
||||
|
||||
#include "gtk/gtk.h"
|
||||
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.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");
|
||||
|
||||
@@ -38,51 +37,63 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
|
||||
set_child(main_box);
|
||||
|
||||
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||
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);
|
||||
}
|
||||
|
||||
void Bar::setup_ui() {
|
||||
main_box.set_hexpand(true);
|
||||
|
||||
main_box.set_start_widget(left_box);
|
||||
main_box.set_center_widget(center_box);
|
||||
main_box.set_end_widget(right_box);
|
||||
main_box.set_valign(Gtk::Align::CENTER);
|
||||
|
||||
left_box.set_valign(Gtk::Align::CENTER);
|
||||
|
||||
center_box.set_hexpand(false);
|
||||
center_box.set_valign(Gtk::Align::CENTER);
|
||||
center_box.set_halign(Gtk::Align::CENTER);
|
||||
|
||||
right_box.set_valign(Gtk::Align::CENTER);
|
||||
|
||||
workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
setup_left_box();
|
||||
setup_center_box();
|
||||
setup_right_box();
|
||||
}
|
||||
|
||||
void Bar::setup_left_box() {
|
||||
left_box.append(*workspaceIndicator);
|
||||
}
|
||||
|
||||
clock.set_name("clock-label");
|
||||
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);
|
||||
center_box.append(*(new Spacer()));
|
||||
center_box.append(*this->volumeWidget);
|
||||
}
|
||||
|
||||
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
right_box.append(*trayWidget);
|
||||
right_box.append(homeAssistant);
|
||||
void Bar::setup_right_box() {
|
||||
right_box.append(*this->trayWidget);
|
||||
right_box.append(this->homeAssistant);
|
||||
right_box.append(*this->bluetoothWidget);
|
||||
}
|
||||
|
||||
void Bar::load_css() {
|
||||
|
||||
@@ -13,11 +13,6 @@ Popover::Popover(std::string icon, std::string name) {
|
||||
popover = new Gtk::Popover();
|
||||
popover->set_parent(*this);
|
||||
popover->set_autohide(true);
|
||||
|
||||
popover->signal_closed().connect([this]() {
|
||||
this->add_css_class("minimized");
|
||||
this->remove_css_class("restored");
|
||||
});
|
||||
}
|
||||
|
||||
Popover::~Popover() {
|
||||
@@ -28,8 +23,6 @@ void Popover::on_toggle_window() {
|
||||
if (popover->get_visible()) {
|
||||
popover->popdown();
|
||||
} else {
|
||||
this->remove_css_class("minimized");
|
||||
this->add_css_class("restored");
|
||||
popover->popup();
|
||||
}
|
||||
}
|
||||
|
||||
51
src/components/todoEntry.cpp
Normal file
51
src/components/todoEntry.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#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, 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<Gtk::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");
|
||||
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);
|
||||
}
|
||||
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;
|
||||
|
||||
164
src/services/sqliteTodoAdapter.cpp
Normal file
164
src/services/sqliteTodoAdapter.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "services/todoAdapter.hpp"
|
||||
|
||||
namespace {
|
||||
std::string getDbPath() {
|
||||
const char *homeDir = getenv("HOME");
|
||||
if (!homeDir) {
|
||||
return "todos.db";
|
||||
}
|
||||
|
||||
std::string path = std::string(homeDir) + "/.config/bar";
|
||||
if (!std::filesystem::exists(path)) {
|
||||
std::filesystem::create_directories(path);
|
||||
}
|
||||
|
||||
return path + "/todos.db";
|
||||
}
|
||||
|
||||
class SqliteTodoAdapter final : public ITodoAdapter {
|
||||
public:
|
||||
~SqliteTodoAdapter() override {
|
||||
if (db_) {
|
||||
sqlite3_close(db_);
|
||||
db_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool init() override {
|
||||
std::string dbPath = getDbPath();
|
||||
|
||||
int rc = sqlite3_open(dbPath.c_str(), &db_);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Can't open database: " << sqlite3_errmsg(db_) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *sql = "CREATE TABLE IF NOT EXISTS todos ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"text TEXT NOT NULL);";
|
||||
char *zErrMsg = nullptr;
|
||||
rc = sqlite3_exec(db_, sql, nullptr, nullptr, &zErrMsg);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "SQL error (create table): " << (zErrMsg ? zErrMsg : "") << std::endl;
|
||||
sqlite3_free(zErrMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<TodoRecord> listTodos() override {
|
||||
std::vector<TodoRecord> results;
|
||||
if (!db_) {
|
||||
return results;
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
const char *sql = "SELECT id, text FROM todos";
|
||||
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "Failed to fetch data: " << sqlite3_errmsg(db_) << std::endl;
|
||||
return results;
|
||||
}
|
||||
|
||||
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
|
||||
int id = sqlite3_column_int(stmt, 0);
|
||||
const unsigned char *txt = sqlite3_column_text(stmt, 1);
|
||||
results.push_back({id, txt ? reinterpret_cast<const char *>(txt) : ""});
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return results;
|
||||
}
|
||||
|
||||
int addTodo(const std::string &text) override {
|
||||
if (!db_) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
const char *sql = "INSERT INTO todos (text) VALUES (?1);";
|
||||
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "SQL prepare error (insert): " << sqlite3_errmsg(db_) << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, text.c_str(), -1, SQLITE_TRANSIENT);
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
std::cerr << "SQL step error (insert): " << sqlite3_errmsg(db_) << std::endl;
|
||||
sqlite3_finalize(stmt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return static_cast<int>(sqlite3_last_insert_rowid(db_));
|
||||
}
|
||||
|
||||
bool removeTodo(int id) override {
|
||||
if (!db_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
const char *sql = "DELETE FROM todos WHERE id = ?1;";
|
||||
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "SQL prepare error (delete): " << sqlite3_errmsg(db_) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_bind_int(stmt, 1, id);
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
std::cerr << "SQL step error (delete): " << sqlite3_errmsg(db_) << std::endl;
|
||||
sqlite3_finalize(stmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool updateTodo(int id, const std::string &text) override {
|
||||
if (!db_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
const char *sql = "UPDATE todos SET text = ?1 WHERE id = ?2;";
|
||||
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "SQL prepare error (update): " << sqlite3_errmsg(db_) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_bind_text(stmt, 1, text.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, 2, id);
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
std::cerr << "SQL step error (update): " << sqlite3_errmsg(db_) << std::endl;
|
||||
sqlite3_finalize(stmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3 *db_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Factory kept local to this TU for now; TodoService uses it.
|
||||
std::unique_ptr<ITodoAdapter> makeSqliteTodoAdapter() {
|
||||
return std::make_unique<SqliteTodoAdapter>();
|
||||
}
|
||||
128
src/services/todo.cpp
Normal file
128
src/services/todo.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "services/todo.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <gtkmm/object.h>
|
||||
|
||||
#include "components/todoEntry.hpp"
|
||||
|
||||
std::unique_ptr<ITodoAdapter> makeSqliteTodoAdapter();
|
||||
|
||||
TodoService::TodoService(sigc::signal<void()> refreshSignal) {
|
||||
this->refreshSignal = refreshSignal;
|
||||
this->adapter = makeSqliteTodoAdapter();
|
||||
this->init();
|
||||
}
|
||||
|
||||
TodoService::~TodoService() {
|
||||
this->adapter.reset();
|
||||
}
|
||||
|
||||
std::map<int, TodoEntry *> TodoService::getTodos() {
|
||||
return this->todos;
|
||||
}
|
||||
|
||||
void TodoService::init() {
|
||||
if (!this->adapter) {
|
||||
std::cerr << "Todo adapter not set" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->adapter->init()) {
|
||||
std::cerr << "Todo adapter init failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
this->load();
|
||||
}
|
||||
|
||||
void TodoService::removeTodo(int id) {
|
||||
if (todos.find(id) == todos.end()) {
|
||||
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (this->adapter) {
|
||||
this->adapter->removeTodo(id);
|
||||
}
|
||||
|
||||
todos.erase(id);
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
|
||||
TodoEntry *TodoService::addTodo(std::string text, bool emitSignal, bool persist) {
|
||||
int id = nextId;
|
||||
|
||||
if (persist) {
|
||||
if (!this->adapter) {
|
||||
return nullptr;
|
||||
}
|
||||
int newId = this->adapter->addTodo(text);
|
||||
if (newId < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
id = newId;
|
||||
}
|
||||
|
||||
auto dismissSignal = sigc::signal<void(int)>();
|
||||
dismissSignal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
|
||||
auto editSignal = sigc::signal<void(int, std::string)>();
|
||||
editSignal.connect(sigc::mem_fun(*this, &TodoService::updateTodo));
|
||||
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, dismissSignal, editSignal);
|
||||
|
||||
todos[id] = todo;
|
||||
|
||||
if (id >= nextId) {
|
||||
nextId = id + 1;
|
||||
}
|
||||
|
||||
if (emitSignal) {
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
|
||||
return todo;
|
||||
}
|
||||
|
||||
void TodoService::updateTodo(int id, std::string text) {
|
||||
if (todos.find(id) == todos.end()) {
|
||||
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (this->adapter) {
|
||||
this->adapter->updateTodo(id, text);
|
||||
}
|
||||
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
|
||||
void TodoService::load() {
|
||||
if (!this->adapter) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto rows = this->adapter->listTodos();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (const auto &row : rows) {
|
||||
count++;
|
||||
int id = row.id;
|
||||
std::string text = row.text;
|
||||
|
||||
auto dismissSignal = sigc::signal<void(int)>();
|
||||
dismissSignal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
|
||||
auto editSignal = sigc::signal<void(int, std::string)>();
|
||||
editSignal.connect(sigc::mem_fun(*this, &TodoService::updateTodo));
|
||||
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(id, text, dismissSignal, editSignal);
|
||||
|
||||
todos[id] = todo;
|
||||
if (id >= nextId) {
|
||||
nextId = id + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
79
src/widgets/todo.cpp
Normal file
79
src/widgets/todo.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#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.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");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,5 +1,5 @@
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include <gtkmm/box.h>
|
||||
|
||||
#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