tray_icon_gtk.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  19. TrayIconGtk::~TrayIconGtk() {
  20. }
  21. void TrayIconGtk::SetImage(const gfx::Image& image) {
  22. if (icon_) {
  23. icon_->SetImage(image.AsImageSkia());
  24. return;
  25. }
  26. const auto toolTip = base::UTF8ToUTF16(brightray::GetApplicationName());
  27. if (libgtkui::AppIndicatorIcon::CouldOpen()) {
  28. ++indicators_count;
  29. icon_.reset(new libgtkui::AppIndicatorIcon(
  30. base::StringPrintf(
  31. "%s%d", Browser::Get()->GetName().c_str(), indicators_count),
  32. image.AsImageSkia(),
  33. toolTip));
  34. } else {
  35. icon_.reset(new libgtkui::Gtk2StatusIcon(image.AsImageSkia(), toolTip));
  36. }
  37. icon_->set_delegate(this);
  38. }
  39. void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
  40. icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
  41. }
  42. void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
  43. icon_->UpdatePlatformContextMenu(menu_model);
  44. }
  45. void TrayIconGtk::OnClick() {
  46. NotifyClicked();
  47. }
  48. bool TrayIconGtk::HasClickAction() {
  49. return false;
  50. }
  51. // static
  52. TrayIcon* TrayIcon::Create() {
  53. return new TrayIconGtk;
  54. }
  55. } // namespace atom