electron/atom/browser/ui/tray_icon_gtk.cc

70 lines
1.7 KiB
C++
Raw Normal View History

// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/ui/tray_icon_gtk.h"
2016-06-20 08:35:45 +00:00
#include "atom/browser/browser.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/common/application_info.h"
2017-01-26 10:55:19 +00:00
#include "chrome/browser/ui/libgtkui/app_indicator_icon.h"
#include "chrome/browser/ui/libgtkui/gtk_status_icon.h"
2015-01-03 03:17:02 +00:00
#include "ui/gfx/image/image.h"
namespace atom {
2016-06-20 08:35:45 +00:00
namespace {
// Number of app indicators used (used as part of app-indicator id).
int indicators_count;
} // namespace
2018-04-18 01:55:30 +00:00
TrayIconGtk::TrayIconGtk() {}
2018-04-18 01:55:30 +00:00
TrayIconGtk::~TrayIconGtk() {}
void TrayIconGtk::SetImage(const gfx::Image& image) {
if (icon_) {
icon_->SetImage(image.AsImageSkia());
return;
}
const auto toolTip = base::UTF8ToUTF16(brightray::GetApplicationName());
2017-01-26 10:55:19 +00:00
if (libgtkui::AppIndicatorIcon::CouldOpen()) {
2016-06-20 08:35:45 +00:00
++indicators_count;
2017-01-26 10:55:19 +00:00
icon_.reset(new libgtkui::AppIndicatorIcon(
2018-04-18 01:55:30 +00:00
base::StringPrintf("%s%d", Browser::Get()->GetName().c_str(),
indicators_count),
image.AsImageSkia(), toolTip));
2016-06-20 08:35:45 +00:00
} else {
icon_.reset(new libgtkui::Gtk2StatusIcon(image.AsImageSkia(), toolTip));
2016-06-20 08:35:45 +00:00
}
icon_->set_delegate(this);
}
void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
}
void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
icon_->UpdatePlatformContextMenu(menu_model);
}
void TrayIconGtk::OnClick() {
2015-05-21 07:22:52 +00:00
NotifyClicked();
}
bool TrayIconGtk::HasClickAction() {
return false;
}
2014-05-30 15:57:54 +00:00
// static
TrayIcon* TrayIcon::Create() {
return new TrayIconGtk;
2014-05-30 15:57:54 +00:00
}
} // namespace atom