From be1e77186e887a980716ed39a04433050cfeb30a Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Wed, 29 Mar 2023 15:28:17 +0100 Subject: [PATCH] Wayland: Set app_id for icon in kde (#718) --- src/gui/CMakeLists.txt | 2 ++ src/gui/CemuApp.cpp | 9 +++++++++ src/gui/MainWindow.cpp | 10 ++++++++++ src/gui/helpers/wxWayland.cpp | 24 ++++++++++++++++++++++++ src/gui/helpers/wxWayland.h | 9 ++++++--- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/gui/helpers/wxWayland.cpp diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 23d8bb5e..30fb492a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -69,6 +69,8 @@ add_library(CemuGui helpers/wxHelpers.cpp helpers/wxHelpers.h helpers/wxLogEvent.h + helpers/wxWayland.cpp + helpers/wxWayland.h input/InputAPIAddWindow.cpp input/InputAPIAddWindow.h input/InputSettings2.cpp diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index a19981b0..92ba9436 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -12,6 +12,10 @@ #include "gui/helpers/wxHelpers.h" #include "Cemu/ncrypto/ncrypto.h" +#if BOOST_OS_LINUX && HAS_WAYLAND +#include "gui/helpers/wxWayland.h" +#endif + #include #include #include @@ -176,6 +180,11 @@ bool CemuApp::OnInit() SetTopWindow(m_mainFrame); m_mainFrame->Show(); +#if BOOST_OS_LINUX && HAS_WAYLAND + if (wxWlIsWaylandWindow(m_mainFrame)) + wxWlSetAppId(m_mainFrame, "info.cemu.Cemu"); +#endif + // show warning on macOS about state of builds #if BOOST_OS_MACOS if (!GetConfig().did_show_macos_disclaimer) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 40830547..1a87af0a 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -57,6 +57,10 @@ #include "resource/embedded/resources.h" #endif +#if BOOST_OS_LINUX && HAS_WAYLAND +#include "gui/helpers/wxWayland.h" +#endif + #include "Cafe/TitleList/TitleInfo.h" #include "Cafe/TitleList/TitleList.h" #include "wxHelper.h" @@ -753,6 +757,12 @@ void MainWindow::TogglePadView() m_padView->Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnPadClose, this); m_padView->Show(true); + +#if BOOST_OS_LINUX && HAS_WAYLAND + if (wxWlIsWaylandWindow(m_padView)) + wxWlSetAppId(m_padView, "info.cemu.Cemu"); +#endif + m_padView->Initialize(); if (m_game_launched) m_padView->InitializeRenderCanvas(); diff --git a/src/gui/helpers/wxWayland.cpp b/src/gui/helpers/wxWayland.cpp new file mode 100644 index 00000000..c677451c --- /dev/null +++ b/src/gui/helpers/wxWayland.cpp @@ -0,0 +1,24 @@ +#include "gui/helpers/wxWayland.h" + +#if BOOST_OS_LINUX && HAS_WAYLAND + +#include + +bool wxWlIsWaylandWindow(wxWindow* window) +{ + GtkWidget* gtkWindow = static_cast(window->GetHandle()); + GdkWindow* gdkWindow = gtk_widget_get_window(gtkWindow); + return GDK_IS_WAYLAND_WINDOW(gdkWindow); +} + +void wxWlSetAppId(wxFrame* frame, const char* applicationId) +{ + GtkWidget* gtkWindow = static_cast(frame->GetHandle()); + gtk_widget_realize(gtkWindow); + GdkWindow* gdkWindow = gtk_widget_get_window(gtkWindow); + static auto gdk_wl_set_app_id = reinterpret_cast(dlsym(nullptr, "gdk_wayland_window_set_application_id")); + if (gdk_wl_set_app_id) + gdk_wl_set_app_id(gdkWindow, applicationId); +} + +#endif // BOOST_OS_LINUX && HAS_WAYLAND diff --git a/src/gui/helpers/wxWayland.h b/src/gui/helpers/wxWayland.h index 7aa075db..f921783b 100644 --- a/src/gui/helpers/wxWayland.h +++ b/src/gui/helpers/wxWayland.h @@ -1,6 +1,6 @@ #pragma once -#if BOOST_OS_LINUX +#if BOOST_OS_LINUX && HAS_WAYLAND #include #include @@ -27,7 +27,7 @@ class wxWlSubsurface int32_t m_xPos = 0; int32_t m_yPos = 0; - public: +public: wxWlSubsurface(wxWindow* window) { GtkWidget* widget = static_cast(window->GetHandle()); @@ -72,4 +72,7 @@ class wxWlSubsurface } }; -#endif // BOOST_OS_LINUX +bool wxWlIsWaylandWindow(wxWindow* window); +void wxWlSetAppId(wxFrame* frame, const char* application_id); + +#endif // BOOST_OS_LINUX && HAS_WAYLAND