Verbessert das Toolbox-Tray-Verhalten
Diese Änderungen verbessern das Verhalten des Toolbox-Trays. - Fügt eine Callback-Funktion für Linksklicks hinzu, um die Aktion zu handhaben. - Aktualisiert die Tray-Initialisierung, um das Icon korrekt zu laden und zu teilen. - Behebt ein Problem, bei dem das Fenster nicht automatisch ausgeblendet wurde, wenn es den Fokus verliert. - Fügt Logik hinzu, um sicherzustellen, dass das Fenster beim Anzeigen in den Vordergrund gebracht und fokussiert wird. - Vergrößert die Fenstergröße.
This commit is contained in:
+23
-10
@@ -5,30 +5,36 @@
|
|||||||
|
|
||||||
class toolboxTray : public tray {
|
class toolboxTray : public tray {
|
||||||
public:
|
public:
|
||||||
// Konstruktor mit optionalen Parametern für Icon und Tooltip
|
// Konstruktor mit optionalen Parametern fuer Icon und Tooltip
|
||||||
explicit toolboxTray(const char* icon = nullptr, const char* tooltip = nullptr) : tray() {
|
explicit toolboxTray(const char* icon = nullptr, const char* tooltip = nullptr) : tray() {
|
||||||
this->icon = icon;
|
this->icon = icon;
|
||||||
this->tooltip = const_cast<char*>(tooltip);
|
this->tooltip = const_cast<char*>(tooltip);
|
||||||
this->menu = nullptr; // Initialisiere ohne Menü (kann später gesetzt werden)
|
this->menu = nullptr; // Initialisiere ohne Menue (kann spaeter gesetzt werden)
|
||||||
|
this->icon_handle = nullptr;
|
||||||
|
this->icon_is_shared = 0;
|
||||||
|
this->left_click_cb = nullptr;
|
||||||
|
this->left_click_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion, um die gewünschte Aktion für den Linksklick zu setzen
|
// Funktion, um die gewuenschte Aktion fuer den Linksklick zu setzen
|
||||||
void setLeftClickAction(const std::function<void()>& action) {
|
void setLeftClickAction(const std::function<void()>& action) {
|
||||||
leftClickAction = action;
|
leftClickAction = action;
|
||||||
|
this->left_click_cb = &toolboxTray::leftClickThunk;
|
||||||
|
this->left_click_context = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion zum Setzen des Tray-Menüs
|
// Funktion zum Setzen des Tray-Menues
|
||||||
void setTrayMenu(tray_menu* menu) {
|
void setTrayMenu(tray_menu* menu) {
|
||||||
this->menu = menu;
|
this->menu = menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ereignis-Handler für Mausklicks
|
// Ereignis-Handler fuer Mausklicks
|
||||||
void handleMouseClick(int button) {
|
void handleMouseClick(int button) {
|
||||||
if (button == LEFT_CLICK && leftClickAction) {
|
if (button == LEFT_CLICK && leftClickAction) {
|
||||||
// Führt die Linksklick-Aktion aus
|
// Fuehrt die Linksklick-Aktion aus
|
||||||
leftClickAction();
|
leftClickAction();
|
||||||
} else if (button == RIGHT_CLICK) {
|
} else if (button == RIGHT_CLICK) {
|
||||||
// Zeigt das Menü
|
// Zeigt das Menue
|
||||||
showMenu();
|
showMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,12 +44,19 @@ public:
|
|||||||
RIGHT_CLICK = 1
|
RIGHT_CLICK = 1
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::function<void()> leftClickAction; // Aktion für Linksklick
|
std::function<void()> leftClickAction; // Aktion fuer Linksklick
|
||||||
|
|
||||||
// Zeigt das Menü an (Rechtsklick)
|
static void leftClickThunk(void* context) {
|
||||||
|
auto* self = static_cast<toolboxTray*>(context);
|
||||||
|
if (self && self->leftClickAction) {
|
||||||
|
self->leftClickAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeigt das Menue an (Rechtsklick)
|
||||||
void showMenu() {
|
void showMenu() {
|
||||||
if (this->menu) {
|
if (this->menu) {
|
||||||
tray_update(this); // Update des Trays mit dem Menü
|
tray_update(this); // Update des Trays mit dem Menue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <saucer/webview.hpp>
|
#include <saucer/webview.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <chrono>
|
||||||
#include "optionWindow.h"
|
#include "optionWindow.h"
|
||||||
#include "toolConfig.h"
|
#include "toolConfig.h"
|
||||||
|
|
||||||
@@ -54,6 +55,8 @@ private:
|
|||||||
std::unique_ptr<optionWindow> m_optionWindow;
|
std::unique_ptr<optionWindow> m_optionWindow;
|
||||||
std::thread m_threadMonitor;
|
std::thread m_threadMonitor;
|
||||||
std::atomic<bool> m_runningMonitor = true;
|
std::atomic<bool> m_runningMonitor = true;
|
||||||
|
std::chrono::steady_clock::time_point m_lastShowTime{};
|
||||||
|
bool m_seenFocusSinceShow = false;
|
||||||
|
|
||||||
std::string jsonString;
|
std::string jsonString;
|
||||||
|
|
||||||
|
|||||||
+1
-1
Submodule lib/c_tray updated: 7387d66ca4...fa1e862259
@@ -1,22 +1,24 @@
|
|||||||
#include <saucer/app.hpp>
|
#include <saucer/app.hpp>
|
||||||
|
#include <Windows.h>
|
||||||
#include "toolboxWindow.h"
|
#include "toolboxWindow.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "tray.h"
|
#include "tray.h"
|
||||||
|
|
||||||
import toolboxTray;
|
import toolboxTray;
|
||||||
|
|
||||||
ToolboxWindow* g_toolboxWindow = nullptr;
|
ToolboxWindow* g_toolboxWindow = nullptr;
|
||||||
|
|
||||||
void on_quit(struct tray_menu *item) {
|
void on_quit(struct tray_menu *item) {
|
||||||
tray_exit();
|
tray_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_click(struct tray_menu *item = nullptr) {
|
void on_open(struct tray_menu *item = nullptr) {
|
||||||
if (g_toolboxWindow) {
|
if (g_toolboxWindow) {
|
||||||
if (g_toolboxWindow->m_bShow)
|
if (g_toolboxWindow->m_bShow) {
|
||||||
g_toolboxWindow->hide();
|
g_toolboxWindow->hide();
|
||||||
else
|
} else {
|
||||||
g_toolboxWindow->show();
|
g_toolboxWindow->show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,25 +30,34 @@ coco::stray start(saucer::application *app){
|
|||||||
|
|
||||||
g_toolboxWindow = toolboxWindow.get();
|
g_toolboxWindow = toolboxWindow.get();
|
||||||
|
|
||||||
HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
|
HICON hIcon = static_cast<HICON>(LoadImage(
|
||||||
|
GetModuleHandle(NULL),
|
||||||
|
MAKEINTRESOURCE(IDI_ICON1),
|
||||||
|
IMAGE_ICON,
|
||||||
|
GetSystemMetrics(SM_CXSMICON),
|
||||||
|
GetSystemMetrics(SM_CYSMICON),
|
||||||
|
LR_SHARED
|
||||||
|
));
|
||||||
|
|
||||||
// Tray-Menü definieren
|
// Tray-Menue definieren
|
||||||
tray_menu tray_menu_items[] = {
|
tray_menu tray_menu_items[] = {
|
||||||
{"Oeffnen", 0, 0, 0, on_click, nullptr},
|
{"Oeffnen", 0, 0, 0, on_open, nullptr},
|
||||||
{"-", 0, 0, 0, nullptr, nullptr}, // Separator
|
{"-", 0, 0, 0, nullptr, nullptr}, // Separator
|
||||||
{"Beenden", 0, 0, 0, on_quit, nullptr},
|
{"Beenden", 0, 0, 0, on_quit, nullptr},
|
||||||
{nullptr, 0, 0, 0, nullptr, nullptr} // Ende des Menüs
|
{nullptr, 0, 0, 0, nullptr, nullptr} // Ende des Menues
|
||||||
};
|
};
|
||||||
|
|
||||||
// ToolboxTray erstellen
|
// ToolboxTray erstellen
|
||||||
toolboxTray tray("toolbox.ico", "Toolbox Application Tray");
|
toolboxTray tray("toolbox.ico", "Toolbox");
|
||||||
|
tray.icon_handle = hIcon;
|
||||||
|
tray.icon_is_shared = (hIcon != nullptr) ? 1 : 0;
|
||||||
|
|
||||||
// Linksklick-Aktion registrieren
|
// Linksklick-Aktion registrieren
|
||||||
tray.setLeftClickAction([&]() {
|
tray.setLeftClickAction([&]() {
|
||||||
on_click(nullptr); // Ruft die Funktion ohne Menüeintrag auf
|
on_open(nullptr); // Ruft die Funktion ohne Menueeintrag auf
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tray-Menü registrieren
|
// Tray-Menue registrieren
|
||||||
tray.setTrayMenu(tray_menu_items);
|
tray.setTrayMenu(tray_menu_items);
|
||||||
|
|
||||||
if (tray_init(&tray) != 0) {
|
if (tray_init(&tray) != 0) {
|
||||||
|
|||||||
+23
-11
@@ -5,34 +5,39 @@ module;
|
|||||||
|
|
||||||
export module toolboxTray;
|
export module toolboxTray;
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
class toolboxTray : public tray {
|
class toolboxTray : public tray {
|
||||||
public:
|
public:
|
||||||
// Konstruktor mit optionalen Parametern für Icon und Tooltip
|
// Konstruktor mit optionalen Parametern fuer Icon und Tooltip
|
||||||
toolboxTray(const char* icon = nullptr, const char* tooltip = nullptr) {
|
toolboxTray(const char* icon = nullptr, const char* tooltip = nullptr) {
|
||||||
this->icon = icon;
|
this->icon = icon;
|
||||||
this->tooltip = const_cast<char*>(tooltip);
|
this->tooltip = const_cast<char*>(tooltip);
|
||||||
this->menu = nullptr; // Initialisiere ohne Menü (kann später gesetzt werden)
|
this->menu = nullptr; // Initialisiere ohne Menue (kann spaeter gesetzt werden)
|
||||||
|
this->icon_handle = nullptr;
|
||||||
|
this->icon_is_shared = 0;
|
||||||
|
this->left_click_cb = nullptr;
|
||||||
|
this->left_click_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion, um die gewünschte Aktion für den Linksklick zu setzen
|
// Funktion, um die gewuenschte Aktion fuer den Linksklick zu setzen
|
||||||
void setLeftClickAction(const std::function<void()>& action) {
|
void setLeftClickAction(const std::function<void()>& action) {
|
||||||
leftClickAction = action;
|
leftClickAction = action;
|
||||||
|
this->left_click_cb = &toolboxTray::leftClickThunk;
|
||||||
|
this->left_click_context = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion zum Setzen des Tray-Menüs
|
// Funktion zum Setzen des Tray-Menues
|
||||||
void setTrayMenu(tray_menu* menu) {
|
void setTrayMenu(tray_menu* menu) {
|
||||||
this->menu = menu;
|
this->menu = menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ereignis-Handler für Mausklicks
|
// Ereignis-Handler fuer Mausklicks
|
||||||
void handleMouseClick(int button) {
|
void handleMouseClick(int button) {
|
||||||
if (button == LEFT_CLICK && leftClickAction) {
|
if (button == LEFT_CLICK && leftClickAction) {
|
||||||
// Führt die Linksklick-Aktion aus
|
// Fuehrt die Linksklick-Aktion aus
|
||||||
leftClickAction();
|
leftClickAction();
|
||||||
} else if (button == RIGHT_CLICK) {
|
} else if (button == RIGHT_CLICK) {
|
||||||
// Zeigt das Menü
|
// Zeigt das Menue
|
||||||
showMenu();
|
showMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,12 +48,19 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void()> leftClickAction; // Aktion für Linksklick
|
std::function<void()> leftClickAction; // Aktion fuer Linksklick
|
||||||
|
|
||||||
// Zeigt das Menü an (Rechtsklick)
|
static void leftClickThunk(void* context) {
|
||||||
|
auto* self = static_cast<toolboxTray*>(context);
|
||||||
|
if (self && self->leftClickAction) {
|
||||||
|
self->leftClickAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeigt das Menue an (Rechtsklick)
|
||||||
void showMenu() {
|
void showMenu() {
|
||||||
if (this->menu) {
|
if (this->menu) {
|
||||||
tray_update(this); // Update des Trays mit dem Menü
|
tray_update(this); // Update des Trays mit dem Menue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-4
@@ -155,8 +155,8 @@ void ToolboxWindow::configureWindow() {
|
|||||||
const int logicalScreenWidth = static_cast<int>(screenWidth / scaleX);
|
const int logicalScreenWidth = static_cast<int>(screenWidth / scaleX);
|
||||||
const int logicalScreenHeight = static_cast<int>(screenHeight / scaleY);
|
const int logicalScreenHeight = static_cast<int>(screenHeight / scaleY);
|
||||||
|
|
||||||
const int windowWidth = 350;
|
const int windowWidth = 420;
|
||||||
const int windowHeight = 600;
|
const int windowHeight = 720;
|
||||||
|
|
||||||
m_webview.parent().set_size({windowWidth, windowHeight});
|
m_webview.parent().set_size({windowWidth, windowHeight});
|
||||||
const saucer::color bg{0x1e, 0x1e, 0x2e, 0xFF};
|
const saucer::color bg{0x1e, 0x1e, 0x2e, 0xFF};
|
||||||
@@ -232,6 +232,8 @@ void ToolboxWindow::runLuaScript() {
|
|||||||
void ToolboxWindow::show() {
|
void ToolboxWindow::show() {
|
||||||
m_webview.parent().show();
|
m_webview.parent().show();
|
||||||
m_bShow = true;
|
m_bShow = true;
|
||||||
|
m_lastShowTime = std::chrono::steady_clock::now();
|
||||||
|
m_seenFocusSinceShow = false;
|
||||||
|
|
||||||
// In some cases the HWND/frame metrics are finalized only after showing.
|
// In some cases the HWND/frame metrics are finalized only after showing.
|
||||||
// Re-acquire HWND and reposition now, plus schedule a short delayed reposition.
|
// Re-acquire HWND and reposition now, plus schedule a short delayed reposition.
|
||||||
@@ -241,6 +243,12 @@ void ToolboxWindow::show() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_hwnd) {
|
||||||
|
SetForegroundWindow(m_hwnd);
|
||||||
|
SetActiveWindow(m_hwnd);
|
||||||
|
SetFocus(m_hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
// Immediate reposition after showing
|
// Immediate reposition after showing
|
||||||
configureWindow();
|
configureWindow();
|
||||||
|
|
||||||
@@ -548,8 +556,13 @@ ToolboxWindow::~ToolboxWindow() {
|
|||||||
|
|
||||||
void ToolboxWindow::monitor_focus() {
|
void ToolboxWindow::monitor_focus() {
|
||||||
while (m_runningMonitor) {
|
while (m_runningMonitor) {
|
||||||
if (m_bShow && !m_webview.parent().focused() && isIndex) {
|
if (m_bShow && isIndex) {
|
||||||
this->hide();
|
const bool focused = m_webview.parent().focused();
|
||||||
|
if (focused) {
|
||||||
|
m_seenFocusSinceShow = true;
|
||||||
|
} else if (m_seenFocusSinceShow) {
|
||||||
|
this->hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schlafpause hinzufügen, um die CPU-Last zu reduzieren
|
// Schlafpause hinzufügen, um die CPU-Last zu reduzieren
|
||||||
|
|||||||
Reference in New Issue
Block a user