mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-12 23:03:37 +00:00
tray: removed double click handling
This commit is contained in:
committed by
Sam Lantinga
parent
bc16157c9d
commit
cb0c7b01e4
@@ -167,9 +167,6 @@ extern SDL_DECLSPEC SDL_Tray * SDLCALL SDL_CreateTray(SDL_Surface *icon, const c
|
||||
* - `SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER`: an
|
||||
* SDL_TrayClickCallback to be invoked when the tray icon is middle-clicked.
|
||||
* Not supported on all platforms. May be NULL.
|
||||
* - `SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER`: an
|
||||
* SDL_TrayClickCallback to be invoked when the tray icon is double-clicked.
|
||||
* Not supported on all platforms. May be NULL.
|
||||
*
|
||||
* \param props the properties to use.
|
||||
* \returns The newly created system tray icon.
|
||||
@@ -191,7 +188,6 @@ extern SDL_DECLSPEC SDL_Tray * SDLCALL SDL_CreateTrayWithProperties(SDL_Properti
|
||||
#define SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER "SDL.tray.create.leftclick_callback"
|
||||
#define SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER "SDL.tray.create.rightclick_callback"
|
||||
#define SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER "SDL.tray.create.middleclick_callback"
|
||||
#define SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER "SDL.tray.create.doubleclick_callback"
|
||||
|
||||
/**
|
||||
* Updates the system tray icon's icon.
|
||||
|
||||
@@ -34,7 +34,6 @@ struct SDL_Tray;
|
||||
/* Objective-C helper class to handle status item button clicks */
|
||||
@interface SDLTrayClickHandler : NSObject
|
||||
@property (nonatomic, assign) struct SDL_Tray *tray;
|
||||
@property (nonatomic, assign) NSTimeInterval lastLeftClickTime;
|
||||
@property (nonatomic, strong) id middleClickMonitor;
|
||||
- (void)handleClick:(id)sender;
|
||||
- (void)startMonitoringMiddleClicks;
|
||||
@@ -73,7 +72,6 @@ struct SDL_Tray {
|
||||
SDL_TrayClickCallback left_click_callback;
|
||||
SDL_TrayClickCallback right_click_callback;
|
||||
SDL_TrayClickCallback middle_click_callback;
|
||||
SDL_TrayClickCallback double_click_callback;
|
||||
};
|
||||
|
||||
@implementation SDLTrayClickHandler
|
||||
@@ -90,22 +88,11 @@ struct SDL_Tray {
|
||||
bool show_menu = false;
|
||||
|
||||
if (buttonNumber == 0) {
|
||||
/* Left click - check for double-click ourselves */
|
||||
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
|
||||
NSTimeInterval doubleClickInterval = [NSEvent doubleClickInterval];
|
||||
|
||||
if (self.tray->double_click_callback && (now - self.lastLeftClickTime) <= doubleClickInterval) {
|
||||
/* Double-click */
|
||||
self.tray->double_click_callback(self.tray->userdata, self.tray);
|
||||
self.lastLeftClickTime = 0; /* Reset to prevent triple-click from triggering another double */
|
||||
/* Left click */
|
||||
if (self.tray->left_click_callback) {
|
||||
show_menu = self.tray->left_click_callback(self.tray->userdata, self.tray);
|
||||
} else {
|
||||
/* Single left click */
|
||||
self.lastLeftClickTime = now;
|
||||
if (self.tray->left_click_callback) {
|
||||
show_menu = self.tray->left_click_callback(self.tray->userdata, self.tray);
|
||||
} else {
|
||||
show_menu = true;
|
||||
}
|
||||
show_menu = true;
|
||||
}
|
||||
} else if (buttonNumber == 1) {
|
||||
/* Right click */
|
||||
@@ -217,7 +204,6 @@ SDL_Tray *SDL_CreateTrayWithProperties(SDL_PropertiesID props)
|
||||
tray->left_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, NULL);
|
||||
tray->right_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, NULL);
|
||||
tray->middle_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, NULL);
|
||||
tray->double_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER, NULL);
|
||||
|
||||
tray->statusItem = nil;
|
||||
tray->statusBar = [NSStatusBar systemStatusBar];
|
||||
|
||||
@@ -67,8 +67,6 @@ struct SDL_Tray {
|
||||
SDL_TrayClickCallback left_click_callback;
|
||||
SDL_TrayClickCallback right_click_callback;
|
||||
SDL_TrayClickCallback middle_click_callback;
|
||||
SDL_TrayClickCallback double_click_callback;
|
||||
bool ignore_next_left_up;
|
||||
};
|
||||
|
||||
static UINT_PTR get_next_id(void)
|
||||
@@ -131,9 +129,7 @@ LRESULT CALLBACK TrayWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||
|
||||
switch (LOWORD(lParam)) {
|
||||
case WM_LBUTTONUP:
|
||||
if (tray->ignore_next_left_up) {
|
||||
tray->ignore_next_left_up = false;
|
||||
} else if (tray->left_click_callback) {
|
||||
if (tray->left_click_callback) {
|
||||
show_menu = tray->left_click_callback(tray->userdata, tray);
|
||||
} else {
|
||||
show_menu = true;
|
||||
@@ -153,16 +149,6 @@ LRESULT CALLBACK TrayWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||
tray->middle_click_callback(tray->userdata, tray);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDBLCLK:
|
||||
if (tray->double_click_callback) {
|
||||
tray->double_click_callback(tray->userdata, tray);
|
||||
/* Suppress the WM_LBUTTONUP that follows a double-click, so we
|
||||
don't fire both double-click and left-click callbacks. This
|
||||
matches the behavior on other platforms. */
|
||||
tray->ignore_next_left_up = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (show_menu && tray->menu) {
|
||||
@@ -331,7 +317,6 @@ SDL_Tray *SDL_CreateTrayWithProperties(SDL_PropertiesID props)
|
||||
tray->left_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, NULL);
|
||||
tray->right_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, NULL);
|
||||
tray->middle_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, NULL);
|
||||
tray->double_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER, NULL);
|
||||
|
||||
tray->menu = NULL;
|
||||
if (!SDL_RegisterTrayClass(TEXT("SDL_TRAY"))) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* SDL_CreateTrayWithProperties to demonstrate click callbacks:
|
||||
* - Left click: Logs a message and shows the menu (returns true)
|
||||
* - Right click: Logs a message and suppresses the menu (returns false)
|
||||
* - Middle click: Logs a message (menu never shows for middle click)
|
||||
*
|
||||
* Window behavior:
|
||||
* - Closing the window (X button) hides it to the tray rather than exiting
|
||||
@@ -51,6 +52,12 @@ static bool SDLCALL tray2_rightclick(void *userdata, SDL_Tray *tray)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool SDLCALL tray2_middleclick(void *userdata, SDL_Tray *tray)
|
||||
{
|
||||
SDL_Log("Middle click on example tray - menu doesn't show for middle click");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool trays_destroyed = false;
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_TrayEntry *entry_toggle = NULL;
|
||||
@@ -607,6 +614,7 @@ int main(int argc, char **argv)
|
||||
SDL_SetStringProperty(tray2_props, SDL_PROP_TRAY_CREATE_TOOLTIP_STRING, "SDL Tray example");
|
||||
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, tray2_leftclick);
|
||||
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, tray2_rightclick);
|
||||
SDL_SetPointerProperty(tray2_props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, tray2_middleclick);
|
||||
SDL_Tray *tray2 = SDL_CreateTrayWithProperties(tray2_props);
|
||||
SDL_DestroyProperties(tray2_props);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user