Skip to content

Commit

Permalink
fix: set Wayland application ID (#34879)
Browse files Browse the repository at this point in the history
  • Loading branch information
trop[bot] committed Jul 12, 2022
1 parent 688780a commit 3ca5708
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions shell/browser/native_window_views.cc
Expand Up @@ -51,6 +51,7 @@
#include "shell/browser/ui/views/client_frame_view_linux.h"
#include "shell/browser/ui/views/frameless_view.h"
#include "shell/browser/ui/views/native_frame_view.h"
#include "shell/common/platform_util.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/window/native_frame_view.h"

Expand Down Expand Up @@ -271,6 +272,8 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
// Set WM_CLASS.
params.wm_class_name = base::ToLowerASCII(name);
params.wm_class_class = name;
// Set Wayland application ID.
params.wayland_app_id = platform_util::GetXdgAppId();

auto* native_widget = new views::DesktopNativeWidgetAura(widget());
params.native_widget = native_widget;
Expand Down
10 changes: 2 additions & 8 deletions shell/browser/notifications/linux/libnotify_notification.cc
Expand Up @@ -9,7 +9,6 @@

#include "base/files/file_enumerator.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/ui/gtk_util.h"
Expand Down Expand Up @@ -138,13 +137,8 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {

// Send the desktop name to identify the application
// The desktop-entry is the part before the .desktop
std::string desktop_id;
if (platform_util::GetDesktopName(&desktop_id)) {
const std::string suffix{".desktop"};
if (base::EndsWith(desktop_id, suffix,
base::CompareCase::INSENSITIVE_ASCII)) {
desktop_id.resize(desktop_id.size() - suffix.size());
}
std::string desktop_id = platform_util::GetXdgAppId();
if (!desktop_id.empty()) {
libnotify_loader_.notify_notification_set_hint_string(
notification_, "desktop-entry", desktop_id.c_str());
}
Expand Down
4 changes: 4 additions & 0 deletions shell/common/platform_util.h
Expand Up @@ -56,6 +56,10 @@ bool SetLoginItemEnabled(bool enabled);
// Returns a success flag.
// Unlike libgtkui, does *not* use "chromium-browser.desktop" as a fallback.
bool GetDesktopName(std::string* setme);

// The XDG application ID must match the name of the desktop entry file without
// the .desktop extension.
std::string GetXdgAppId();
#endif

} // namespace platform_util
Expand Down
15 changes: 15 additions & 0 deletions shell/common/platform_util_linux.cc
Expand Up @@ -20,6 +20,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "components/dbus/thread_linux/dbus_thread_linux.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -403,4 +404,18 @@ bool GetDesktopName(std::string* setme) {
return base::Environment::Create()->GetVar("CHROME_DESKTOP", setme);
}

std::string GetXdgAppId() {
std::string desktop_file_name;
if (GetDesktopName(&desktop_file_name)) {
const std::string kDesktopExtension{".desktop"};
if (base::EndsWith(desktop_file_name, kDesktopExtension,
base::CompareCase::INSENSITIVE_ASCII)) {
desktop_file_name.resize(desktop_file_name.size() -
kDesktopExtension.size());
}
}

return desktop_file_name;
}

} // namespace platform_util

0 comments on commit 3ca5708

Please sign in to comment.