fix code style
This commit is contained in:
@@ -1,130 +1,104 @@
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <gtkmm/widget.h>
|
||||
#include <gtkmm/gestureclick.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtkmm/gestureclick.h>
|
||||
#include <gtkmm/widget.h>
|
||||
#include <sigc++/functors/mem_fun.h>
|
||||
|
||||
WorkspaceIndicator::WorkspaceIndicator(HyprlandService &service, int monitorId)
|
||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL), m_service(service), m_monitorId(monitorId)
|
||||
{
|
||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service),
|
||||
monitorId(monitorId) {
|
||||
set_margin_top(2);
|
||||
set_margin_bottom(2);
|
||||
|
||||
m_workspaceConnection = m_service.workspaceStateChanged.connect(
|
||||
workspaceConnection = service.workspaceStateChanged.connect(
|
||||
sigc::mem_fun(*this, &WorkspaceIndicator::on_workspace_update));
|
||||
m_monitorConnection = m_service.monitorStateChanged.connect(
|
||||
monitorConnection = service.monitorStateChanged.connect(
|
||||
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
WorkspaceIndicator::~WorkspaceIndicator()
|
||||
{
|
||||
if (m_workspaceConnection.connected())
|
||||
{
|
||||
m_workspaceConnection.disconnect();
|
||||
WorkspaceIndicator::~WorkspaceIndicator() {
|
||||
if (workspaceConnection.connected()) {
|
||||
workspaceConnection.disconnect();
|
||||
}
|
||||
|
||||
if (m_monitorConnection.connected())
|
||||
{
|
||||
m_monitorConnection.disconnect();
|
||||
if (monitorConnection.connected()) {
|
||||
monitorConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void WorkspaceIndicator::on_workspace_update(int monitorId)
|
||||
{
|
||||
if (monitorId != m_monitorId && monitorId != -1)
|
||||
{
|
||||
void WorkspaceIndicator::on_workspace_update(int monitorId) {
|
||||
if (monitorId != monitorId && monitorId != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void WorkspaceIndicator::on_monitor_update()
|
||||
{
|
||||
rebuild();
|
||||
}
|
||||
void WorkspaceIndicator::on_monitor_update() { rebuild(); }
|
||||
|
||||
void WorkspaceIndicator::rebuild()
|
||||
{
|
||||
void WorkspaceIndicator::rebuild() {
|
||||
clear_children();
|
||||
|
||||
HyprlandService::Monitor *monitor = nullptr;
|
||||
try
|
||||
{
|
||||
monitor = m_service.getMonitorById(m_monitorId);
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
try {
|
||||
monitor = service.getMonitorById(monitorId);
|
||||
} catch (const std::exception &) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (monitor == nullptr)
|
||||
{
|
||||
if (monitor == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int workspaceId = 1; workspaceId <= HyprlandService::kWorkspaceSlotCount; ++workspaceId)
|
||||
{
|
||||
for (int workspaceId = 1;
|
||||
workspaceId <= HyprlandService::kWorkspaceSlotCount; ++workspaceId) {
|
||||
const HyprlandService::WorkspaceState *state = nullptr;
|
||||
auto it = monitor->workspaceStates.find(workspaceId);
|
||||
if (it != monitor->workspaceStates.end())
|
||||
{
|
||||
|
||||
if (it != monitor->workspaceStates.end()) {
|
||||
state = &it->second;
|
||||
}
|
||||
|
||||
const std::string display = (state && !state->label.empty()) ? state->label : std::to_string(workspaceId);
|
||||
const std::string display = (state && !state->label.empty())
|
||||
? state->label
|
||||
: std::to_string(workspaceId);
|
||||
|
||||
auto label = Gtk::make_managed<Gtk::Label>(display);
|
||||
label->add_css_class("workspace-pill");
|
||||
|
||||
// Make the label clickable using a gesture click (primary button)
|
||||
auto gesture = Gtk::GestureClick::create();
|
||||
gesture->set_button(GDK_BUTTON_PRIMARY);
|
||||
// Use a lambda to capture the workspace slot id
|
||||
gesture->signal_released().connect([this, workspaceId](int /*n_press*/, double /*x*/, double /*y*/)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_service.switchToWorkspace(m_monitorId, workspaceId);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
std::cerr << "[WorkspaceIndicator] switchToWorkspace failed: " << ex.what() << std::endl;
|
||||
}
|
||||
});
|
||||
gesture->signal_released().connect(
|
||||
[this, workspaceId](int /*n_press*/, double /*x*/, double /*y*/) {
|
||||
int realWorkspaceId = workspaceId + 5 * (monitorId);
|
||||
|
||||
service.switchToWorkspace(realWorkspaceId);
|
||||
});
|
||||
label->add_controller(gesture);
|
||||
|
||||
if (state != nullptr)
|
||||
{
|
||||
if (state->focused)
|
||||
{
|
||||
if (state != nullptr) {
|
||||
if (state->focused) {
|
||||
label->add_css_class("workspace-pill-focused");
|
||||
}
|
||||
else if (state->active)
|
||||
{
|
||||
} else if (state->active) {
|
||||
label->add_css_class("workspace-pill-active");
|
||||
}
|
||||
|
||||
if (state->urgent)
|
||||
{
|
||||
if (state->urgent) {
|
||||
label->add_css_class("workspace-pill-urgent");
|
||||
}
|
||||
}
|
||||
|
||||
append(*label);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WorkspaceIndicator::clear_children()
|
||||
{
|
||||
void WorkspaceIndicator::clear_children() {
|
||||
Gtk::Widget *child = get_first_child();
|
||||
while (child != nullptr)
|
||||
{
|
||||
while (child != nullptr) {
|
||||
Gtk::Widget *next = child->get_next_sibling();
|
||||
remove(*child);
|
||||
child = next;
|
||||
|
||||
Reference in New Issue
Block a user