mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(bar): control center button
This commit is contained in:
+1
-1
@@ -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]
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user