зеркало из https://github.com/electron/electron.git
feat: add middle click event to tray (#39926)
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Родитель
480f48b2fc
Коммит
689d1b76de
|
@ -111,6 +111,15 @@ Returns:
|
||||||
|
|
||||||
Emitted when the tray icon is double clicked.
|
Emitted when the tray icon is double clicked.
|
||||||
|
|
||||||
|
#### Event: 'middle-click' _Windows_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `event` [KeyboardEvent](structures/keyboard-event.md)
|
||||||
|
* `bounds` [Rectangle](structures/rectangle.md) - The bounds of tray icon.
|
||||||
|
|
||||||
|
Emitted when the tray icon is middle clicked.
|
||||||
|
|
||||||
#### Event: 'balloon-show' _Windows_
|
#### Event: 'balloon-show' _Windows_
|
||||||
|
|
||||||
Emitted when the tray balloon shows.
|
Emitted when the tray balloon shows.
|
||||||
|
|
|
@ -102,6 +102,12 @@ void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
EmitWithoutEvent("right-click", CreateEventFromFlags(modifiers), bounds);
|
EmitWithoutEvent("right-click", CreateEventFromFlags(modifiers), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tray::OnMiddleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
|
EmitWithoutEvent("middle-click", CreateEventFromFlags(modifiers), bounds);
|
||||||
|
}
|
||||||
|
|
||||||
void Tray::OnBalloonShow() {
|
void Tray::OnBalloonShow() {
|
||||||
Emit("balloon-show");
|
Emit("balloon-show");
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ class Tray : public gin::Wrappable<Tray>,
|
||||||
int modifiers) override;
|
int modifiers) override;
|
||||||
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
|
void OnMiddleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||||
void OnBalloonShow() override;
|
void OnBalloonShow() override;
|
||||||
void OnBalloonClicked() override;
|
void OnBalloonClicked() override;
|
||||||
void OnBalloonClosed() override;
|
void OnBalloonClosed() override;
|
||||||
|
|
|
@ -41,6 +41,11 @@ void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
observer.OnDoubleClicked(bounds, modifiers);
|
observer.OnDoubleClicked(bounds, modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIcon::NotifyMiddleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||||
|
for (TrayIconObserver& observer : observers_)
|
||||||
|
observer.OnMiddleClicked(bounds, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
void TrayIcon::NotifyBalloonShow() {
|
void TrayIcon::NotifyBalloonShow() {
|
||||||
for (TrayIconObserver& observer : observers_)
|
for (TrayIconObserver& observer : observers_)
|
||||||
observer.OnBalloonShow();
|
observer.OnBalloonShow();
|
||||||
|
|
|
@ -106,6 +106,7 @@ class TrayIcon {
|
||||||
const gfx::Point& location = gfx::Point(),
|
const gfx::Point& location = gfx::Point(),
|
||||||
int modifiers = 0);
|
int modifiers = 0);
|
||||||
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||||
|
void NotifyMiddleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||||
void NotifyBalloonShow();
|
void NotifyBalloonShow();
|
||||||
void NotifyBalloonClicked();
|
void NotifyBalloonClicked();
|
||||||
void NotifyBalloonClosed();
|
void NotifyBalloonClosed();
|
||||||
|
|
|
@ -23,6 +23,7 @@ class TrayIconObserver : public base::CheckedObserver {
|
||||||
const gfx::Point& location,
|
const gfx::Point& location,
|
||||||
int modifiers) {}
|
int modifiers) {}
|
||||||
virtual void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {}
|
virtual void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||||
|
virtual void OnMiddleClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||||
virtual void OnBalloonShow() {}
|
virtual void OnBalloonShow() {}
|
||||||
virtual void OnBalloonClicked() {}
|
virtual void OnBalloonClicked() {}
|
||||||
virtual void OnBalloonClosed() {}
|
virtual void OnBalloonClosed() {}
|
||||||
|
|
|
@ -73,7 +73,8 @@ NotifyIcon::~NotifyIcon() {
|
||||||
|
|
||||||
void NotifyIcon::HandleClickEvent(int modifiers,
|
void NotifyIcon::HandleClickEvent(int modifiers,
|
||||||
bool left_mouse_click,
|
bool left_mouse_click,
|
||||||
bool double_button_click) {
|
bool double_button_click,
|
||||||
|
bool middle_button_click) {
|
||||||
gfx::Rect bounds = GetBounds();
|
gfx::Rect bounds = GetBounds();
|
||||||
|
|
||||||
if (left_mouse_click) {
|
if (left_mouse_click) {
|
||||||
|
@ -84,6 +85,8 @@ void NotifyIcon::HandleClickEvent(int modifiers,
|
||||||
display::Screen::GetScreen()->GetCursorScreenPoint(),
|
display::Screen::GetScreen()->GetCursorScreenPoint(),
|
||||||
modifiers);
|
modifiers);
|
||||||
return;
|
return;
|
||||||
|
} else if (middle_button_click) { // single middle click
|
||||||
|
NotifyMiddleClicked(bounds, modifiers);
|
||||||
} else if (!double_button_click) { // single right click
|
} else if (!double_button_click) { // single right click
|
||||||
if (menu_model_)
|
if (menu_model_)
|
||||||
PopUpContextMenu(gfx::Point(), menu_model_->GetWeakPtr());
|
PopUpContextMenu(gfx::Point(), menu_model_->GetWeakPtr());
|
||||||
|
|
|
@ -45,7 +45,8 @@ class NotifyIcon : public TrayIcon {
|
||||||
// otherwise displays the context menu if there is one.
|
// otherwise displays the context menu if there is one.
|
||||||
void HandleClickEvent(int modifiers,
|
void HandleClickEvent(int modifiers,
|
||||||
bool left_button_click,
|
bool left_button_click,
|
||||||
bool double_button_click);
|
bool double_button_click,
|
||||||
|
bool middle_button_click);
|
||||||
|
|
||||||
// Handles a mouse move event from the user.
|
// Handles a mouse move event from the user.
|
||||||
void HandleMouseMoveEvent(int modifiers);
|
void HandleMouseMoveEvent(int modifiers);
|
||||||
|
|
|
@ -189,8 +189,10 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
|
||||||
|
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
case WM_LBUTTONDBLCLK:
|
case WM_LBUTTONDBLCLK:
|
||||||
case WM_RBUTTONDBLCLK:
|
case WM_RBUTTONDBLCLK:
|
||||||
|
case WM_MBUTTONDBLCLK:
|
||||||
case WM_CONTEXTMENU:
|
case WM_CONTEXTMENU:
|
||||||
// Walk our icons, find which one was clicked on, and invoke its
|
// Walk our icons, find which one was clicked on, and invoke its
|
||||||
// HandleClickEvent() method.
|
// HandleClickEvent() method.
|
||||||
|
@ -200,7 +202,8 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
|
||||||
&NotifyIcon::HandleClickEvent, win_icon_weak,
|
&NotifyIcon::HandleClickEvent, win_icon_weak,
|
||||||
GetKeyboardModifiers(),
|
GetKeyboardModifiers(),
|
||||||
(lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
|
(lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
|
||||||
(lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK)));
|
(lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK),
|
||||||
|
(lparam == WM_MBUTTONDOWN || lparam == WM_MBUTTONDBLCLK)));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче