feat(bar): control center button

This commit is contained in:
Lemmy
2026-04-27 02:08:40 -04:00
parent 803eefafef
commit f50a5d9bb1
6 changed files with 79 additions and 2 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ capsule = false
start = ["launcher", "wallpaper", "workspaces"]
center = ["clock"]
end = ["media", "tray", "notifications", "network", "bluetooth", "volume", "brightness", "battery", "session"]
end = ["media", "tray", "notifications", "network", "bluetooth", "volume", "brightness", "battery", "control-center", "session"]
# Per-monitor override example — only the fields you list are overridden:
# [bar.main.monitor.dp1]
+1
View File
@@ -449,6 +449,7 @@ _noctalia_sources = files(
'src/shell/bar/widgets/audio_visualizer_widget.cpp',
'src/shell/bar/widgets/battery_widget.cpp',
'src/shell/bar/widgets/bluetooth_widget.cpp',
'src/shell/bar/widgets/control_center_widget.cpp',
'src/shell/bar/widgets/clock_widget.cpp',
'src/shell/bar/widgets/idle_inhibitor_widget.cpp',
'src/shell/bar/widgets/keyboard_layout_widget.cpp',
+1 -1
View File
@@ -78,7 +78,7 @@ struct BarConfig {
std::vector<std::string> startWidgets = {"launcher", "wallpaper", "workspaces"};
std::vector<std::string> centerWidgets = {"clock"};
std::vector<std::string> endWidgets = {"media", "tray", "notifications", "network", "bluetooth",
"volume", "brightness", "battery", "session"};
"volume", "brightness", "battery", "control-center", "session"};
// When true, widgets on this bar use a capsule unless `[widget.*] capsule = false`.
bool widgetCapsuleDefault = false;
ThemeColor widgetCapsuleFill = roleColor(ColorRole::SurfaceVariant);
+12
View File
@@ -15,6 +15,7 @@
#include "shell/bar/widgets/bluetooth_widget.h"
#include "shell/bar/widgets/brightness_widget.h"
#include "shell/bar/widgets/clock_widget.h"
#include "shell/bar/widgets/control_center_widget.h"
#include "shell/bar/widgets/idle_inhibitor_widget.h"
#include "shell/bar/widgets/keyboard_layout_widget.h"
#include "shell/bar/widgets/launcher_widget.h"
@@ -124,6 +125,17 @@ std::unique_ptr<Widget> WidgetFactory::create(const std::string& name, wl_output
return widget;
}
if (type == "control-center") {
auto barGlyph = wc != nullptr ? wc->getString("glyph", "noctalia") : std::string{"noctalia"};
if (barGlyph.empty()) {
barGlyph = "search";
}
auto widget = std::make_unique<ControlCenterWidget>(output, std::move(barGlyph));
widget->setContentScale(contentScale);
return widget;
}
if (type == "idle_inhibitor") {
auto widget = std::make_unique<IdleInhibitorWidget>(m_idleInhibitor);
widget->setContentScale(contentScale);
@@ -0,0 +1,42 @@
#include "shell/bar/widgets/control_center_widget.h"
#include "render/scene/input_area.h"
#include "render/scene/node.h"
#include "shell/panel/panel_manager.h"
#include "ui/controls/glyph.h"
#include "ui/palette.h"
#include "ui/style.h"
#include <memory>
ControlCenterWidget::ControlCenterWidget(wl_output* output, std::string barGlyphId)
: m_output(output), m_barGlyphId(std::move(barGlyphId)) {}
void ControlCenterWidget::create() {
auto area = std::make_unique<InputArea>();
area->setOnClick([this](const InputArea::PointerData& /*data*/) {
PanelManager::instance().togglePanel("control-center", m_output, 0.0f, 0.0f, "overview");
});
auto glyph = std::make_unique<Glyph>();
glyph->setGlyph(m_barGlyphId.empty() ? "search" : m_barGlyphId);
glyph->setGlyphSize(Style::fontSizeBody * m_contentScale);
glyph->setColor(widgetForegroundOr(roleColor(ColorRole::OnSurface)));
m_glyph = glyph.get();
area->addChild(std::move(glyph));
setRoot(std::move(area));
}
void ControlCenterWidget::doLayout(Renderer& renderer, float /*containerWidth*/, float /*containerHeight*/) {
if (m_glyph == nullptr) {
return;
}
m_glyph->setGlyphSize(Style::fontSizeBody * m_contentScale);
m_glyph->setColor(widgetForegroundOr(roleColor(ColorRole::OnSurface)));
m_glyph->measure(renderer);
auto* node = root();
if (node != nullptr) {
node->setSize(m_glyph->width(), m_glyph->height());
}
}
@@ -0,0 +1,22 @@
#pragma once
#include "shell/bar/widget.h"
#include <cstdint>
#include <string>
class Glyph;
struct wl_output;
class ControlCenterWidget : public Widget {
public:
ControlCenterWidget(wl_output* output, std::string barGlyphId);
void create() override;
private:
void doLayout(Renderer& renderer, float containerWidth, float containerHeight) override;
wl_output* m_output;
std::string m_barGlyphId;
Glyph* m_glyph = nullptr;
};