kiran-menu/1011-feat-applet-icon-The-plugin-button-loads-the-icon-fr.patch
2024-04-09 18:20:17 +08:00

93 lines
3.7 KiB
Diff

From e5403df890ccfc0ea8790c6596714a643a6ea573 Mon Sep 17 00:00:00 2001
From: yangfeng <yangfeng@kylinsec.com.cn>
Date: Wed, 20 Mar 2024 10:18:12 +0800
Subject: [PATCH 1011/1014] feat(applet-icon):The plugin button loads the icon
from the system theme
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 插件按钮从系统主题中载入图标
---
src/common/kiran-applet-button.cpp | 12 +++++-------
src/common/kiran-applet-button.h | 4 ++--
src/menu/menu-applet-button.cpp | 2 +-
src/workspace/workspace-applet-button.cpp | 2 +-
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/common/kiran-applet-button.cpp b/src/common/kiran-applet-button.cpp
index 7600e37..fe3952f 100644
--- a/src/common/kiran-applet-button.cpp
+++ b/src/common/kiran-applet-button.cpp
@@ -123,16 +123,14 @@ void KiranAppletButton::generate_pixbuf()
{
int scale = get_scale_factor();
- KLOG_INFO("generate pixbuf for button, resource %s\n",
- icon_resource.c_str());
- icon_pixbuf = Gdk::Pixbuf::create_from_resource(icon_resource,
- icon_size * scale,
- icon_size * scale);
+ KLOG_INFO("generate pixbuf for button, theme icon %s\n",
+ icon_name.c_str());
+ icon_pixbuf = Gtk::IconTheme::get_default()->load_icon(icon_name, icon_size, scale, Gtk::ICON_LOOKUP_USE_BUILTIN);
}
-void KiranAppletButton::set_icon_from_resource(const std::string &resource)
+void KiranAppletButton::set_icon_from_theme(const std::string &name)
{
- icon_resource = resource;
+ icon_name = name;
icon_pixbuf.clear();
if (get_realized())
diff --git a/src/common/kiran-applet-button.h b/src/common/kiran-applet-button.h
index 8049630..0355b3c 100644
--- a/src/common/kiran-applet-button.h
+++ b/src/common/kiran-applet-button.h
@@ -31,13 +31,13 @@ protected:
virtual void get_preferred_height_vfunc(int &minimum_height, int &natural_height) const override;
virtual void on_size_allocate(Gtk::Allocation &allocation) override;
virtual bool on_draw(const ::Cairo::RefPtr<Cairo::Context> &cr) override;
- virtual void set_icon_from_resource(const std::string &resource);
+ virtual void set_icon_from_theme(const std::string &name);
void generate_pixbuf();
private:
MatePanelApplet *applet;
- std::string icon_resource;
+ std::string icon_name;
Glib::RefPtr<Gdk::Pixbuf> icon_pixbuf; //图标
int icon_size; //图标显示尺寸
};
diff --git a/src/menu/menu-applet-button.cpp b/src/menu/menu-applet-button.cpp
index 7b1b013..61d83ce 100644
--- a/src/menu/menu-applet-button.cpp
+++ b/src/menu/menu-applet-button.cpp
@@ -23,7 +23,7 @@
MenuAppletButton::MenuAppletButton(MatePanelApplet *panel_applet) : KiranAppletButton(panel_applet)
{
set_tooltip_text(_("Kiran Start Menu"));
- set_icon_from_resource("/kiran-menu/icon/logo");
+ set_icon_from_theme("kiran-menu");
get_style_context()->add_class("menu-applet-button");
window.signal_size_changed().connect(
diff --git a/src/workspace/workspace-applet-button.cpp b/src/workspace/workspace-applet-button.cpp
index ddeb6b0..b959151 100644
--- a/src/workspace/workspace-applet-button.cpp
+++ b/src/workspace/workspace-applet-button.cpp
@@ -16,7 +16,7 @@
WorkspaceAppletButton::WorkspaceAppletButton(MatePanelApplet *applet_) : KiranAppletButton(applet_)
{
- set_icon_from_resource("/kiran-workspace/icon/button");
+ set_icon_from_theme("kiran-workspace-switcher");
applet_window.signal_unmap_event().connect(
[this](GdkEventAny *event) -> bool
--
2.27.0