tray_icon_gtk.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/ui/tray_icon_gtk.h"
  5. #include "atom/browser/browser.h"
  6. #include "base/strings/stringprintf.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "brightray/common/application_info.h"
  9. #include "chrome/browser/ui/libgtkui/app_indicator_icon.h"
  10. #include "chrome/browser/ui/libgtkui/gtk_status_icon.h"
  11. #include "ui/gfx/image/image.h"
  12. namespace atom {
  13. namespace {
  14. // Number of app indicators used (used as part of app-indicator id).
  15. int indicators_count;
  16. } // namespace
  17. TrayIconGtk::TrayIconGtk() {}
  18. TrayIconGtk::~TrayIconGtk() {}
  19. void TrayIconGtk::SetImage(const gfx::Image& image) {
  20. if (icon_) {
  21. icon_->SetImage(image.AsImageSkia());
  22. return;
  23. }
  24. const auto toolTip = base::UTF8ToUTF16(brightray::GetApplicationName());
  25. if (libgtkui::AppIndicatorIcon::CouldOpen()) {
  26. ++indicators_count;
  27. icon_.reset(new libgtkui::AppIndicatorIcon(
  28. base::StringPrintf("%s%d", Browser::Get()->GetName().c_str(),
  29. indicators_count),
  30. image.AsImageSkia(), toolTip));
  31. } else {
  32. icon_.reset(new libgtkui::Gtk2StatusIcon(image.AsImageSkia(), toolTip));
  33. }
  34. icon_->set_delegate(this);
  35. }
  36. void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
  37. icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
  38. }
  39. void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
  40. icon_->UpdatePlatformContextMenu(menu_model);
  41. }
  42. void TrayIconGtk::OnClick() {
  43. NotifyClicked();
  44. }
  45. bool TrayIconGtk::HasClickAction() {
  46. return false;
  47. }
  48. // static
  49. TrayIcon* TrayIcon::Create() {
  50. return new TrayIconGtk;
  51. }
  52. } // namespace atom