2020-06-03 00:00:20 +00:00
|
|
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_GTK_APP_INDICATOR_ICON_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_GTK_APP_INDICATOR_ICON_H_
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "base/nix/xdg_util.h"
|
2022-03-25 01:39:03 +00:00
|
|
|
#include "third_party/skia/include/core/SkImage.h"
|
2020-06-03 00:00:20 +00:00
|
|
|
#include "ui/base/glib/glib_signal.h"
|
2022-07-20 11:03:34 +00:00
|
|
|
#include "ui/linux/status_icon_linux.h"
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
typedef struct _AppIndicator AppIndicator;
|
|
|
|
typedef struct _GtkWidget GtkWidget;
|
|
|
|
|
|
|
|
class SkBitmap;
|
|
|
|
|
|
|
|
namespace gfx {
|
|
|
|
class ImageSkia;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
class MenuModel;
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::gtkui {
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
class AppIndicatorIconMenu;
|
|
|
|
|
|
|
|
// Status icon implementation which uses libappindicator.
|
2022-07-20 11:03:34 +00:00
|
|
|
class AppIndicatorIcon : public ui::StatusIconLinux {
|
2020-06-03 00:00:20 +00:00
|
|
|
public:
|
|
|
|
// The id uniquely identifies the new status icon from other chrome status
|
|
|
|
// icons.
|
|
|
|
AppIndicatorIcon(std::string id,
|
|
|
|
const gfx::ImageSkia& image,
|
2021-03-16 16:18:45 +00:00
|
|
|
const std::u16string& tool_tip);
|
2020-06-03 00:00:20 +00:00
|
|
|
~AppIndicatorIcon() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
AppIndicatorIcon(const AppIndicatorIcon&) = delete;
|
|
|
|
AppIndicatorIcon& operator=(const AppIndicatorIcon&) = delete;
|
|
|
|
|
2020-06-03 00:00:20 +00:00
|
|
|
// Indicates whether libappindicator so could be opened.
|
|
|
|
static bool CouldOpen();
|
|
|
|
|
2022-07-20 11:03:34 +00:00
|
|
|
// Overridden from ui::StatusIconLinux:
|
2020-06-03 00:00:20 +00:00
|
|
|
void SetIcon(const gfx::ImageSkia& image) override;
|
2021-03-16 16:18:45 +00:00
|
|
|
void SetToolTip(const std::u16string& tool_tip) override;
|
2020-06-03 00:00:20 +00:00
|
|
|
void UpdatePlatformContextMenu(ui::MenuModel* menu) override;
|
|
|
|
void RefreshPlatformContextMenu() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct SetImageFromFileParams {
|
|
|
|
// The temporary directory in which the icon(s) were written.
|
|
|
|
base::FilePath parent_temp_dir;
|
|
|
|
|
|
|
|
// The icon theme path to pass to libappindicator.
|
|
|
|
std::string icon_theme_path;
|
|
|
|
|
|
|
|
// The icon name to pass to libappindicator.
|
|
|
|
std::string icon_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Writes |bitmap| to a temporary directory on a worker thread. The temporary
|
|
|
|
// directory is selected based on KDE's quirks.
|
|
|
|
static SetImageFromFileParams WriteKDE4TempImageOnWorkerThread(
|
|
|
|
const SkBitmap& bitmap,
|
|
|
|
const base::FilePath& existing_temp_dir);
|
|
|
|
|
|
|
|
// Writes |bitmap| to a temporary directory on a worker thread. The temporary
|
|
|
|
// directory is selected based on Unity's quirks.
|
|
|
|
static SetImageFromFileParams WriteUnityTempImageOnWorkerThread(
|
|
|
|
const SkBitmap& bitmap,
|
|
|
|
int icon_change_count,
|
|
|
|
const std::string& id);
|
|
|
|
|
|
|
|
void SetImageFromFile(const SetImageFromFileParams& params);
|
|
|
|
void SetMenu();
|
|
|
|
|
|
|
|
// Sets a menu item at the top of the menu as a replacement for the status
|
|
|
|
// icon click action. Clicking on this menu item should simulate a status icon
|
|
|
|
// click by despatching a click event.
|
|
|
|
void UpdateClickActionReplacementMenuItem();
|
|
|
|
|
|
|
|
// Callback for when the status icon click replacement menu item is activated.
|
|
|
|
void OnClickActionReplacementMenuItemActivated();
|
|
|
|
|
|
|
|
std::string id_;
|
|
|
|
std::string tool_tip_;
|
|
|
|
|
|
|
|
// Used to select KDE or Unity for image setting.
|
|
|
|
base::nix::DesktopEnvironment desktop_env_;
|
|
|
|
|
|
|
|
// Gtk status icon wrapper
|
2021-01-26 18:16:21 +00:00
|
|
|
AppIndicator* icon_ = nullptr;
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
std::unique_ptr<AppIndicatorIconMenu> menu_;
|
2021-01-26 18:16:21 +00:00
|
|
|
ui::MenuModel* menu_model_ = nullptr;
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
base::FilePath temp_dir_;
|
2021-01-26 18:16:21 +00:00
|
|
|
int icon_change_count_ = 0;
|
2020-06-03 00:00:20 +00:00
|
|
|
|
|
|
|
base::WeakPtrFactory<AppIndicatorIcon> weak_factory_{this};
|
|
|
|
};
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::gtkui
|
2020-06-03 00:00:20 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_GTK_APP_INDICATOR_ICON_H_
|