mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
ui/cocoa: Use qemu_add_mouse_change_notifier
This eliminates the polling in cocoa_refresh and implements the propagation of the mouse mode change from absolute to relative. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Reviewed-by: Phil Dennis-Jordan <phil@philjordan.eu> Tested-by: Phil Dennis-Jordan <phil@philjordan.eu> Message-ID: <20240322-mouse-v1-1-0b7d4d9bdfbf@daynix.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
3476103689
commit
e7b53d160f
1 changed files with 38 additions and 24 deletions
62
ui/cocoa.m
62
ui/cocoa.m
|
@ -296,6 +296,14 @@ static void handleAnyDeviceErrors(Error * err)
|
||||||
{
|
{
|
||||||
QEMUScreen screen;
|
QEMUScreen screen;
|
||||||
pixman_image_t *pixman_image;
|
pixman_image_t *pixman_image;
|
||||||
|
/* The state surrounding mouse grabbing is potentially confusing.
|
||||||
|
* isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated
|
||||||
|
* pointing device an absolute-position one?"], but is only updated on
|
||||||
|
* next refresh.
|
||||||
|
* isMouseGrabbed tracks whether GUI events are directed to the guest;
|
||||||
|
* it controls whether special keys like Cmd get sent to the guest,
|
||||||
|
* and whether we capture the mouse when in non-absolute mode.
|
||||||
|
*/
|
||||||
BOOL isMouseGrabbed;
|
BOOL isMouseGrabbed;
|
||||||
BOOL isAbsoluteEnabled;
|
BOOL isAbsoluteEnabled;
|
||||||
CFMachPortRef eventsTap;
|
CFMachPortRef eventsTap;
|
||||||
|
@ -307,17 +315,8 @@ static void handleAnyDeviceErrors(Error * err)
|
||||||
- (void) handleMonitorInput:(NSEvent *)event;
|
- (void) handleMonitorInput:(NSEvent *)event;
|
||||||
- (bool) handleEvent:(NSEvent *)event;
|
- (bool) handleEvent:(NSEvent *)event;
|
||||||
- (bool) handleEventLocked:(NSEvent *)event;
|
- (bool) handleEventLocked:(NSEvent *)event;
|
||||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
|
- (void) notifyMouseModeChange;
|
||||||
/* The state surrounding mouse grabbing is potentially confusing.
|
|
||||||
* isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated
|
|
||||||
* pointing device an absolute-position one?"], but is only updated on
|
|
||||||
* next refresh.
|
|
||||||
* isMouseGrabbed tracks whether GUI events are directed to the guest;
|
|
||||||
* it controls whether special keys like Cmd get sent to the guest,
|
|
||||||
* and whether we capture the mouse when in non-absolute mode.
|
|
||||||
*/
|
|
||||||
- (BOOL) isMouseGrabbed;
|
- (BOOL) isMouseGrabbed;
|
||||||
- (BOOL) isAbsoluteEnabled;
|
|
||||||
- (QEMUScreen) gscreen;
|
- (QEMUScreen) gscreen;
|
||||||
- (void) raiseAllKeys;
|
- (void) raiseAllKeys;
|
||||||
@end
|
@end
|
||||||
|
@ -404,6 +403,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
|
||||||
qkbd_state_switch_console(kbd, con);
|
qkbd_state_switch_console(kbd, con);
|
||||||
dcl.con = con;
|
dcl.con = con;
|
||||||
register_displaychangelistener(&dcl);
|
register_displaychangelistener(&dcl);
|
||||||
|
[self notifyMouseModeChange];
|
||||||
[self updateUIInfo];
|
[self updateUIInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1109,14 +1109,26 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
|
||||||
[self raiseAllButtons];
|
[self raiseAllButtons];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled {
|
- (void) notifyMouseModeChange {
|
||||||
|
bool tIsAbsoluteEnabled = bool_with_bql(^{
|
||||||
|
return qemu_input_is_absolute(dcl.con);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tIsAbsoluteEnabled == isAbsoluteEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
isAbsoluteEnabled = tIsAbsoluteEnabled;
|
isAbsoluteEnabled = tIsAbsoluteEnabled;
|
||||||
|
|
||||||
if (isMouseGrabbed) {
|
if (isMouseGrabbed) {
|
||||||
CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled);
|
if (isAbsoluteEnabled) {
|
||||||
|
[self ungrabMouse];
|
||||||
|
} else {
|
||||||
|
CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
|
- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
|
||||||
- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;}
|
|
||||||
- (QEMUScreen) gscreen {return screen;}
|
- (QEMUScreen) gscreen {return screen;}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1791,6 +1803,17 @@ static void addRemovableDevicesMenuItems(void)
|
||||||
qapi_free_BlockInfoList(pointerToFree);
|
qapi_free_BlockInfoList(pointerToFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cocoa_mouse_mode_change_notify(Notifier *notifier, void *data)
|
||||||
|
{
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[cocoaView notifyMouseModeChange];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Notifier mouse_mode_change_notifier = {
|
||||||
|
.notify = cocoa_mouse_mode_change_notify
|
||||||
|
};
|
||||||
|
|
||||||
@interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
|
@interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -1975,17 +1998,6 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
|
||||||
COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
|
COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
|
||||||
graphic_hw_update(dcl->con);
|
graphic_hw_update(dcl->con);
|
||||||
|
|
||||||
if (qemu_input_is_absolute(dcl->con)) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
if (![cocoaView isAbsoluteEnabled]) {
|
|
||||||
if ([cocoaView isMouseGrabbed]) {
|
|
||||||
[cocoaView ungrabMouse];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[cocoaView setAbsoluteEnabled:YES];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cbchangecount != [[NSPasteboard generalPasteboard] changeCount]) {
|
if (cbchangecount != [[NSPasteboard generalPasteboard] changeCount]) {
|
||||||
qemu_clipboard_info_unref(cbinfo);
|
qemu_clipboard_info_unref(cbinfo);
|
||||||
cbinfo = qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD);
|
cbinfo = qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD);
|
||||||
|
@ -2062,6 +2074,8 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
|
||||||
|
|
||||||
// register vga output callbacks
|
// register vga output callbacks
|
||||||
register_displaychangelistener(&dcl);
|
register_displaychangelistener(&dcl);
|
||||||
|
qemu_add_mouse_mode_change_notifier(&mouse_mode_change_notifier);
|
||||||
|
[cocoaView notifyMouseModeChange];
|
||||||
[cocoaView updateUIInfo];
|
[cocoaView updateUIInfo];
|
||||||
|
|
||||||
qemu_event_init(&cbevent, false);
|
qemu_event_init(&cbevent, false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue