dein bruder
This commit is contained in:
47
src/app.cpp
Normal file
47
src/app.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "app.hpp"
|
||||
|
||||
#include <sigc++/sigc++.h>
|
||||
|
||||
App::App() {
|
||||
this->setupServices();
|
||||
|
||||
this->app = Gtk::Application::create("org.example.mybar");
|
||||
|
||||
app->signal_activate().connect([&]() {
|
||||
auto display = Gdk::Display::get_default();
|
||||
auto monitors = display->get_monitors();
|
||||
|
||||
for (guint i = 0; i < monitors->get_n_items(); ++i) {
|
||||
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(
|
||||
monitors->get_object(i));
|
||||
if (monitor) {
|
||||
auto hyprlanMonitor = this->hyprlandService.getMonitorById(i);
|
||||
|
||||
auto bar = new Bar(monitor->gobj(), hyprlanMonitor);
|
||||
this->hyprlandService.printMonitor(*hyprlanMonitor); // Debugging output
|
||||
|
||||
bar->set_application(app);
|
||||
bar->show();
|
||||
bars.push_back(bar);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app->signal_shutdown().connect([&]() {
|
||||
for (auto bar : bars) {
|
||||
delete bar;
|
||||
}
|
||||
bars.clear();
|
||||
});
|
||||
}
|
||||
|
||||
void App::setupServices() {
|
||||
this->hyprlandService.socketEventSignal.connect(sigc::mem_fun(
|
||||
this->hyprlandService, &HyprlandService::on_hyprland_event));
|
||||
|
||||
this->hyprlandService.start();
|
||||
}
|
||||
|
||||
int App::run() {
|
||||
return this->app->run();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "bar.hpp"
|
||||
#include "bar/bar.hpp"
|
||||
|
||||
#include <gtkmm/enums.h>
|
||||
#include <gtkmm/label.h>
|
||||
@@ -9,10 +9,14 @@
|
||||
#include "glibmm/main.h"
|
||||
#include "sigc++/functors/mem_fun.h"
|
||||
|
||||
Bar::Bar()
|
||||
Bar::Bar(GdkMonitor* monitor, HyprlandService::Monitor* hyprlandMonitor)
|
||||
{
|
||||
gtk_layer_init_for_window(this->gobj());
|
||||
|
||||
if (monitor) {
|
||||
gtk_layer_set_monitor(this->gobj(), monitor);
|
||||
}
|
||||
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_TOP, true);
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_LEFT, true);
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, true);
|
||||
@@ -31,11 +35,6 @@ Bar::Bar()
|
||||
this->clock,
|
||||
&Clock::onUpdate),
|
||||
1000);
|
||||
|
||||
hyprland.socketEventSignal.connect(
|
||||
sigc::mem_fun(this->hyprland, &HyprlandService::on_hyprland_event));
|
||||
|
||||
hyprland.start();
|
||||
}
|
||||
|
||||
void Bar::setup_ui()
|
||||
@@ -24,7 +24,6 @@ HyprlandService::~HyprlandService()
|
||||
|
||||
void HyprlandService::on_hyprland_event(std::string event, std::string data)
|
||||
{
|
||||
|
||||
if (event == "workspacev2")
|
||||
{
|
||||
std::cout << event << " " << data << std::endl;
|
||||
@@ -75,15 +74,15 @@ void HyprlandService::start()
|
||||
{
|
||||
for (auto &monitorJson : monitorsJson)
|
||||
{
|
||||
Monitor monitor;
|
||||
Monitor* monitor = new Monitor();
|
||||
|
||||
monitor.id = monitorJson["id"];
|
||||
monitor.name = monitorJson["name"];
|
||||
monitor.x = monitorJson["x"];
|
||||
monitor.y = monitorJson["y"];
|
||||
monitor.focusedWorkspaceId = monitorJson["activeWorkspace"]["id"];
|
||||
monitor->id = monitorJson["id"];
|
||||
monitor->name = monitorJson["name"];
|
||||
monitor->x = monitorJson["x"];
|
||||
monitor->y = monitorJson["y"];
|
||||
monitor->focusedWorkspaceId = monitorJson["activeWorkspace"]["id"];
|
||||
|
||||
this->monitors.insert({monitor.id, monitor});
|
||||
this->monitors.insert({monitor->id, monitor});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ void HyprlandService::start()
|
||||
tempState.urgent = false;
|
||||
tempState.id = i;
|
||||
|
||||
this->monitors[i / numWorkspaces].workspaceStates.insert({i % numWorkspaces, tempState});
|
||||
this->monitors[i / numWorkspaces]->workspaceStates.insert({i % numWorkspaces, tempState});
|
||||
}
|
||||
|
||||
std::string hyprctlWorkspacesOutput = SystemHelper::get_command_output("hyprctl workspaces -j");
|
||||
@@ -111,9 +110,10 @@ void HyprlandService::start()
|
||||
{
|
||||
int currentId = workspaceJson["id"];
|
||||
int monitorId = workspaceJson["monitorID"];
|
||||
WorkspaceState &workspaceState = this->monitors[monitorId].workspaceStates.at((currentId - 1) % numWorkspaces);
|
||||
Monitor* monitor = this->monitors[monitorId];
|
||||
WorkspaceState &workspaceState = monitor->workspaceStates.at((currentId - 1) % numWorkspaces);
|
||||
|
||||
int focusedWorkspaceId = this->monitors[monitorId].focusedWorkspaceId;
|
||||
int focusedWorkspaceId = monitor[monitorId].focusedWorkspaceId;
|
||||
workspaceState.focused = currentId == focusedWorkspaceId;
|
||||
workspaceState.active = true;
|
||||
}
|
||||
@@ -178,3 +178,16 @@ std::string HyprlandService::get_socket_path()
|
||||
|
||||
return std::string(runtime) + "/hypr/" + sig + "/.socket2.sock";
|
||||
}
|
||||
|
||||
|
||||
HyprlandService::Monitor* HyprlandService::getMonitorById(const int &id)
|
||||
{
|
||||
if (this->monitors.find(id) != this->monitors.end())
|
||||
{
|
||||
return this->monitors.at(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Monitor with ID " + std::to_string(id) + " not found.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user