Fix some possible crash problems caused by sigc::slot. Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
205 lines
7.5 KiB
Diff
205 lines
7.5 KiB
Diff
From ee1e902961b07f16b22916338bc37b98ba9d9060 Mon Sep 17 00:00:00 2001
|
||
From: tangjie02 <tangjie02@kylinsec.com.cn>
|
||
Date: Tue, 9 Aug 2022 09:41:35 +0800
|
||
Subject: [PATCH 1/2] fix(connect): Fix some possible crash problems caused by
|
||
sigc::slot.
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 修复一些可能存在的崩溃问题,这些崩溃问题是因为槽函数绑定的对象已经被释放导致
|
||
|
||
Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
|
||
---
|
||
src/menu/menu-app-item.cpp | 52 ++++++++++++++++++++------------
|
||
src/menu/menu-app-item.h | 5 +++
|
||
src/menu/menu-applet-window.cpp | 3 +-
|
||
src/menu/menu-apps-container.cpp | 12 ++------
|
||
src/menu/menu-apps-container.h | 7 -----
|
||
5 files changed, 40 insertions(+), 39 deletions(-)
|
||
|
||
diff --git a/src/menu/menu-app-item.cpp b/src/menu/menu-app-item.cpp
|
||
index fba3994..fa672c2 100644
|
||
--- a/src/menu/menu-app-item.cpp
|
||
+++ b/src/menu/menu-app-item.cpp
|
||
@@ -68,11 +68,7 @@ void MenuAppItem::init_drag_and_drop()
|
||
targets.push_back(target);
|
||
drag_source_set(targets, Gdk::BUTTON1_MASK, Gdk::ACTION_COPY);
|
||
|
||
- signal_drag_failed().connect(
|
||
- [this](const Glib::RefPtr<Gdk::DragContext> &context, Gtk::DragResult result) -> bool {
|
||
- KLOG_DEBUG("drag failed, result %d\n", (int)result);
|
||
- return true;
|
||
- });
|
||
+ signal_drag_failed().connect(sigc::mem_fun(*this, &MenuAppItem::on_drag_failed));
|
||
}
|
||
|
||
bool MenuAppItem::on_button_press_event(GdkEventButton *button_event)
|
||
@@ -131,14 +127,22 @@ void MenuAppItem::on_drag_end(const Glib::RefPtr<Gdk::DragContext> &context)
|
||
// 如果拖拽被取消,拖拽的ungrab操作可能在drag-end信号之后,所以这里的grab操作放入到后面的事件循环处理。
|
||
if (this->idle_drag_connection_.empty())
|
||
{
|
||
- this->idle_drag_connection_ = Glib::signal_idle().connect([this]() -> bool {
|
||
- Gtk::Container *toplevel = this->get_toplevel();
|
||
- KiranHelper::grab_input(*toplevel);
|
||
- return false;
|
||
- });
|
||
+ this->idle_drag_connection_ = Glib::signal_idle().connect(
|
||
+ [this]() -> bool
|
||
+ {
|
||
+ Gtk::Container *toplevel = this->get_toplevel();
|
||
+ KiranHelper::grab_input(*toplevel);
|
||
+ return false;
|
||
+ });
|
||
}
|
||
}
|
||
|
||
+bool MenuAppItem::on_drag_failed(const Glib::RefPtr<Gdk::DragContext> &context, Gtk::DragResult result)
|
||
+{
|
||
+ KLOG_DEBUG("drag failed, result %d\n", (int)result);
|
||
+ return true;
|
||
+}
|
||
+
|
||
bool MenuAppItem::on_key_press_event(GdkEventKey *key_event)
|
||
{
|
||
if (key_event->keyval == GDK_KEY_Menu)
|
||
@@ -181,20 +185,12 @@ void MenuAppItem::create_context_menu()
|
||
if (!is_in_favorite())
|
||
{
|
||
item = Gtk::make_managed<Gtk::MenuItem>(_("Add to favorites"));
|
||
- item->signal_activate().connect(
|
||
- [this]() -> void {
|
||
- if (!app.expired())
|
||
- Kiran::MenuSkeleton::get_instance()->add_favorite_app(app.lock()->get_desktop_id());
|
||
- });
|
||
+ item->signal_activate().connect(sigc::mem_fun(*this, &MenuAppItem::on_add_favorite_app));
|
||
}
|
||
else
|
||
{
|
||
item = Gtk::make_managed<Gtk::MenuItem>(_("Remove from favorites"));
|
||
- item->signal_activate().connect(
|
||
- [this]() -> void {
|
||
- if (!app.expired())
|
||
- Kiran::MenuSkeleton::get_instance()->del_favorite_app(app.lock()->get_desktop_id());
|
||
- });
|
||
+ item->signal_activate().connect(sigc::mem_fun(*this, &MenuAppItem::on_del_favorite_app));
|
||
}
|
||
context_menu.append(*item);
|
||
|
||
@@ -345,3 +341,19 @@ void MenuAppItem::launch_app()
|
||
signal_launched().emit();
|
||
app.lock()->launch();
|
||
}
|
||
+
|
||
+void MenuAppItem::on_add_favorite_app()
|
||
+{
|
||
+ if (!this->app.expired())
|
||
+ {
|
||
+ Kiran::MenuSkeleton::get_instance()->add_favorite_app(app.lock()->get_desktop_id());
|
||
+ }
|
||
+}
|
||
+
|
||
+void MenuAppItem::on_del_favorite_app()
|
||
+{
|
||
+ if (!app.expired())
|
||
+ {
|
||
+ Kiran::MenuSkeleton::get_instance()->del_favorite_app(app.lock()->get_desktop_id());
|
||
+ }
|
||
+}
|
||
\ No newline at end of file
|
||
diff --git a/src/menu/menu-app-item.h b/src/menu/menu-app-item.h
|
||
index 39f3767..6caadd7 100644
|
||
--- a/src/menu/menu-app-item.h
|
||
+++ b/src/menu/menu-app-item.h
|
||
@@ -37,6 +37,7 @@ protected:
|
||
virtual void on_drag_begin(const Glib::RefPtr<Gdk::DragContext> &context) override;
|
||
virtual void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &context, Gtk::SelectionData &selection, guint info, guint timestamp) override;
|
||
virtual void on_drag_end(const Glib::RefPtr<Gdk::DragContext> &context) override;
|
||
+ bool on_drag_failed(const Glib::RefPtr<Gdk::DragContext> &context, Gtk::DragResult result);
|
||
|
||
virtual void init_drag_and_drop();
|
||
|
||
@@ -46,6 +47,10 @@ protected:
|
||
void create_context_menu();
|
||
bool add_app_to_desktop();
|
||
|
||
+private:
|
||
+ void on_add_favorite_app();
|
||
+ void on_del_favorite_app();
|
||
+
|
||
private:
|
||
KiranOpacityMenu context_menu;
|
||
Gtk::MenuItem *items;
|
||
diff --git a/src/menu/menu-applet-window.cpp b/src/menu/menu-applet-window.cpp
|
||
index 941c2b8..eea61c9 100644
|
||
--- a/src/menu/menu-applet-window.cpp
|
||
+++ b/src/menu/menu-applet-window.cpp
|
||
@@ -63,8 +63,7 @@ MenuAppletWindow::MenuAppletWindow(Gtk::WindowType window_type) : Glib::ObjectBa
|
||
/* 监控工作区域大小变化 */
|
||
auto screen = get_screen();
|
||
monitor = new WorkareaMonitor(screen);
|
||
- monitor->signal_size_changed().connect(
|
||
- sigc::mem_fun(*this, &MenuAppletWindow::on_workarea_size_changed));
|
||
+ monitor->signal_size_changed().connect(sigc::mem_fun(*this, &MenuAppletWindow::on_workarea_size_changed));
|
||
|
||
//加载当前用户信息
|
||
set_display_mode(profile.get_display_mode());
|
||
diff --git a/src/menu/menu-apps-container.cpp b/src/menu/menu-apps-container.cpp
|
||
index 4930e46..b849397 100644
|
||
--- a/src/menu/menu-apps-container.cpp
|
||
+++ b/src/menu/menu-apps-container.cpp
|
||
@@ -32,7 +32,8 @@ MenuAppsContainer::MenuAppsContainer(MenuAppsContainer::AppIconMode mode_,
|
||
apps_box.get_style_context()->add_class("menu-apps-box");
|
||
|
||
category_box.signal_clicked().connect_notify(
|
||
- [this]() -> void {
|
||
+ [this]() -> void
|
||
+ {
|
||
signal_category_clicked().emit(category_box.get_category_name());
|
||
});
|
||
|
||
@@ -142,11 +143,6 @@ bool MenuAppsContainer::get_category_clickable() const
|
||
return category_box.get_clickable();
|
||
}
|
||
|
||
-sigc::signal<void> MenuAppsContainer::signal_app_launched()
|
||
-{
|
||
- return m_signal_app_launched;
|
||
-}
|
||
-
|
||
sigc::signal<void, const Glib::ustring &> MenuAppsContainer::signal_category_clicked()
|
||
{
|
||
return m_signal_category_clicked;
|
||
@@ -157,10 +153,6 @@ MenuAppItem *MenuAppsContainer::create_app_item(std::shared_ptr<Kiran::App> app,
|
||
auto item = new MenuAppItem(app);
|
||
|
||
item->set_orientation(orient);
|
||
- item->signal_launched().connect(
|
||
- [this]() -> void {
|
||
- signal_app_launched().emit();
|
||
- });
|
||
|
||
return item;
|
||
}
|
||
diff --git a/src/menu/menu-apps-container.h b/src/menu/menu-apps-container.h
|
||
index d5bfcfe..85148e3 100644
|
||
--- a/src/menu/menu-apps-container.h
|
||
+++ b/src/menu/menu-apps-container.h
|
||
@@ -83,13 +83,6 @@ public:
|
||
*/
|
||
virtual bool load_applications(const Kiran::AppVec &apps);
|
||
|
||
- /**
|
||
- * @brief signal_app_launched 信号,容器内的应用按钮启动时触发
|
||
- *
|
||
- * @return 返回应用启动信号
|
||
- */
|
||
- sigc::signal<void> signal_app_launched();
|
||
-
|
||
/**
|
||
* @brief siganl_category_clicked 信号,容器内的应用分类标签点击后触发
|
||
*/
|
||
--
|
||
2.33.0
|
||
|