fix: ensure tray icon is the proper size on linux (#21904)
* fix: ensure tray icon is the proper size on linux Fixes #21445. * chore: use correct include order * chore: use correct include order * chore: remove use of deprecated casting style * chore: be more explicit about the 22 pixel height * chore: remove now-unneeded #include statements * chore: fix typo and bugs.chromium.org link * refactor: put GetIconFromImage() in anon namespace
This commit is contained in:
parent
55ccca922d
commit
5f307381d2
1 changed files with 27 additions and 1 deletions
|
@ -10,15 +10,41 @@
|
||||||
#include "shell/browser/browser.h"
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/application_info.h"
|
#include "shell/common/application_info.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
#include "ui/gfx/image/image_skia_operations.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
gfx::ImageSkia GetIconFromImage(const gfx::Image& image) {
|
||||||
|
auto icon = image.AsImageSkia();
|
||||||
|
auto size = icon.size();
|
||||||
|
|
||||||
|
// Systray icons are historically 22 pixels tall, e.g. on Ubuntu GNOME,
|
||||||
|
// KDE, and xfce. Taller icons are causing incorrect sizing issues -- e.g.
|
||||||
|
// a 1x1 icon -- so for now, pin the height manually. Similar behavior to
|
||||||
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1042098 ?
|
||||||
|
static constexpr int DESIRED_HEIGHT = 22;
|
||||||
|
if ((size.height() != 0) && (size.height() != DESIRED_HEIGHT)) {
|
||||||
|
const double ratio = DESIRED_HEIGHT / static_cast<double>(size.height());
|
||||||
|
size = gfx::Size(static_cast<int>(ratio * size.width()),
|
||||||
|
static_cast<int>(ratio * size.height()));
|
||||||
|
icon = gfx::ImageSkiaOperations::CreateResizedImage(
|
||||||
|
icon, skia::ImageOperations::RESIZE_BEST, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
TrayIconGtk::TrayIconGtk() = default;
|
TrayIconGtk::TrayIconGtk() = default;
|
||||||
|
|
||||||
TrayIconGtk::~TrayIconGtk() = default;
|
TrayIconGtk::~TrayIconGtk() = default;
|
||||||
|
|
||||||
void TrayIconGtk::SetImage(const gfx::Image& image) {
|
void TrayIconGtk::SetImage(const gfx::Image& image) {
|
||||||
image_ = image.AsImageSkia();
|
image_ = GetIconFromImage(image);
|
||||||
|
|
||||||
if (icon_) {
|
if (icon_) {
|
||||||
icon_->SetIcon(image_);
|
icon_->SetIcon(image_);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue