Re: [PATCH v2] ui/cocoa: Use NSWindow's ability to resize

2021-06-29 Thread BALATON Zoltan

On Tue, 29 Jun 2021, Akihiko Odaki wrote:

2021年6月29日(火) 6:19 BALATON Zoltan :


On Mon, 28 Jun 2021, Akihiko Odaki wrote:

2021年6月28日(月) 17:57 BALATON Zoltan :


On Mon, 28 Jun 2021, Akihiko Odaki wrote:

This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
 provided by the platform. (The left-top green button.)


While this is better for consistency with other apps is it a potential
usability issue that a window bar may appear when you move the mouse to
the top of the full screen window (where guests often have a menu bar that
this could make harder to use)? (Haven't tested it so don't know how it
actually works.)


The window bar is completely hidden with NSApplicationPresentationHideMenuBar.


I've missed that but now you pointed to it I have a comment about that.


Signed-off-by: Akihiko Odaki 
---
ui/cocoa.m | 542 -
1 file changed, 249 insertions(+), 293 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9f72844b079..091d9721f4d 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -93,12 +93,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
static DisplayChangeListener dcl = {
.ops = _ops,
};
-static int last_buttons;
static int cursor_hide = 1;

static int gArgc;
static char **gArgv;
-static bool stretch_video;
static NSTextField *pauseLabel;
static NSArray * supportedImageFileTypes;

@@ -301,19 +299,16 @@ static void handleAnyDeviceErrors(Error * err)
*/
@interface QemuCocoaView : NSView
{
+NSTrackingArea *trackingArea;
QEMUScreen screen;
-NSWindow *fullScreenWindow;
-float cx,cy,cw,ch,cdx,cdy;
pixman_image_t *pixman_image;
QKbdState *kbd;
BOOL isMouseGrabbed;
-BOOL isFullscreen;
BOOL isAbsoluteEnabled;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
- (void) ungrabMouse;
-- (void) toggleFullScreen:(id)sender;
- (void) handleMonitorInput:(NSEvent *)event;
- (bool) handleEvent:(NSEvent *)event;
- (bool) handleEventLocked:(NSEvent *)event;
@@ -328,8 +323,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 */
- (BOOL) isMouseGrabbed;
- (BOOL) isAbsoluteEnabled;
-- (float) cdx;
-- (float) cdy;
- (QEMUScreen) gscreen;
- (void) raiseAllKeys;
@end
@@ -369,46 +362,43 @@ - (BOOL) isOpaque
return YES;
}

-- (BOOL) screenContainsPoint:(NSPoint) p
+- (void) removeTrackingRect
{
-return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
+if (trackingArea) {
+[self removeTrackingArea:trackingArea];
+[trackingArea release];
+trackingArea = nil;
+}
}


You could override removeTrackingArea here then you would not have
addTrackingArea vs. removeTrackingRect and that's the way NSTrackingArea
docs also suggest.


https://developer.apple.com/documentation/appkit/nstrackingarea?language=objc

Other NSView methods related to NSTrackingArea objects
(in addition to addTrackingArea:) include removeTrackingArea: and
updateTrackingAreas. Views can override the latter method to recompute and
replace their NSTrackingArea objects in certain situations, such as a change in
the size of the visibleRect.


It says updateTrackingAreas can be overridden, but  decided to hook
the code to modify the guest display state instead because it should
be synchronized with trackingArea.


Indeed it means updateTrackingAreas but I don't think it says you can't
override removeTrackingArea so you could still do that as long as you call
the original method then do whatever else is needed. Doing it in another
method works but breaks the symmetry of add and remove so you have to
remember to use another method to remove the tracking area than what you'd
normally use. That's why I thought overriding the remove method could be
cleaner.


removeTrackingArea: receives a tracking area to be removed, but we are
removing a particular tracking area in this case. See the use of the
method in frameUpdated. The symmetry of add and remove is in
frameUpdated; it sends addTrackingArea: and removeTrackingArea:.




-/* Get location of event and convert to virtual screen coordinate */
-- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+- (void) frameUpdated
{
-NSWindow *eventWindow = [ev window];
-// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
-CGRect r = CGRectZero;
-r.origin = [ev locationInWindow];
-if (!eventWindow) {
-if (!isFullscreen) {
-return [[self window] convertRectFromScreen:r].origin;
-} else {
-CGPoint locationInSelfWindow = [[self window] 
convertRectFromScreen:r].origin;
-CGPoint loc = [self convertPoint:locationInSelfWindow 
fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else if ([[self window] isEqual:eventWindow]) {
-if 

Re: [PATCH v2] ui/cocoa: Use NSWindow's ability to resize

2021-06-28 Thread Akihiko Odaki
2021年6月29日(火) 6:19 BALATON Zoltan :
>
> On Mon, 28 Jun 2021, Akihiko Odaki wrote:
> > 2021年6月28日(月) 17:57 BALATON Zoltan :
> >>
> >> On Mon, 28 Jun 2021, Akihiko Odaki wrote:
> >>> This change brings two new features:
> >>> - The window will be resizable if "Zoom To Fit" is eanbled
> >>> - The window can be made full screen by clicking full screen button
> >>>  provided by the platform. (The left-top green button.)
> >>
> >> While this is better for consistency with other apps is it a potential
> >> usability issue that a window bar may appear when you move the mouse to
> >> the top of the full screen window (where guests often have a menu bar that
> >> this could make harder to use)? (Haven't tested it so don't know how it
> >> actually works.)
> >
> > The window bar is completely hidden with 
> > NSApplicationPresentationHideMenuBar.
>
> I've missed that but now you pointed to it I have a comment about that.
>
> >>> Signed-off-by: Akihiko Odaki 
> >>> ---
> >>> ui/cocoa.m | 542 -
> >>> 1 file changed, 249 insertions(+), 293 deletions(-)
> >>>
> >>> diff --git a/ui/cocoa.m b/ui/cocoa.m
> >>> index 9f72844b079..091d9721f4d 100644
> >>> --- a/ui/cocoa.m
> >>> +++ b/ui/cocoa.m
> >>> @@ -93,12 +93,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
> >>> static DisplayChangeListener dcl = {
> >>> .ops = _ops,
> >>> };
> >>> -static int last_buttons;
> >>> static int cursor_hide = 1;
> >>>
> >>> static int gArgc;
> >>> static char **gArgv;
> >>> -static bool stretch_video;
> >>> static NSTextField *pauseLabel;
> >>> static NSArray * supportedImageFileTypes;
> >>>
> >>> @@ -301,19 +299,16 @@ static void handleAnyDeviceErrors(Error * err)
> >>> */
> >>> @interface QemuCocoaView : NSView
> >>> {
> >>> +NSTrackingArea *trackingArea;
> >>> QEMUScreen screen;
> >>> -NSWindow *fullScreenWindow;
> >>> -float cx,cy,cw,ch,cdx,cdy;
> >>> pixman_image_t *pixman_image;
> >>> QKbdState *kbd;
> >>> BOOL isMouseGrabbed;
> >>> -BOOL isFullscreen;
> >>> BOOL isAbsoluteEnabled;
> >>> }
> >>> - (void) switchSurface:(pixman_image_t *)image;
> >>> - (void) grabMouse;
> >>> - (void) ungrabMouse;
> >>> -- (void) toggleFullScreen:(id)sender;
> >>> - (void) handleMonitorInput:(NSEvent *)event;
> >>> - (bool) handleEvent:(NSEvent *)event;
> >>> - (bool) handleEventLocked:(NSEvent *)event;
> >>> @@ -328,8 +323,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
> >>>  */
> >>> - (BOOL) isMouseGrabbed;
> >>> - (BOOL) isAbsoluteEnabled;
> >>> -- (float) cdx;
> >>> -- (float) cdy;
> >>> - (QEMUScreen) gscreen;
> >>> - (void) raiseAllKeys;
> >>> @end
> >>> @@ -369,46 +362,43 @@ - (BOOL) isOpaque
> >>> return YES;
> >>> }
> >>>
> >>> -- (BOOL) screenContainsPoint:(NSPoint) p
> >>> +- (void) removeTrackingRect
> >>> {
> >>> -return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < 
> >>> screen.height);
> >>> +if (trackingArea) {
> >>> +[self removeTrackingArea:trackingArea];
> >>> +[trackingArea release];
> >>> +trackingArea = nil;
> >>> +}
> >>> }
> >>
> >> You could override removeTrackingArea here then you would not have
> >> addTrackingArea vs. removeTrackingRect and that's the way NSTrackingArea
> >> docs also suggest.
> >
> > https://developer.apple.com/documentation/appkit/nstrackingarea?language=objc
> >> Other NSView methods related to NSTrackingArea objects
> >> (in addition to addTrackingArea:) include removeTrackingArea: and
> >> updateTrackingAreas. Views can override the latter method to recompute and
> >> replace their NSTrackingArea objects in certain situations, such as a 
> >> change in
> >> the size of the visibleRect.
> >
> > It says updateTrackingAreas can be overridden, but  decided to hook
> > the code to modify the guest display state instead because it should
> > be synchronized with trackingArea.
>
> Indeed it means updateTrackingAreas but I don't think it says you can't
> override removeTrackingArea so you could still do that as long as you call
> the original method then do whatever else is needed. Doing it in another
> method works but breaks the symmetry of add and remove so you have to
> remember to use another method to remove the tracking area than what you'd
> normally use. That's why I thought overriding the remove method could be
> cleaner.

removeTrackingArea: receives a tracking area to be removed, but we are
removing a particular tracking area in this case. See the use of the
method in frameUpdated. The symmetry of add and remove is in
frameUpdated; it sends addTrackingArea: and removeTrackingArea:.

>
> >>> -/* Get location of event and convert to virtual screen coordinate */
> >>> -- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
> >>> +- (void) frameUpdated
> >>> {
> >>> -NSWindow *eventWindow = [ev window];
> >>> -// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
> >>> -CGRect r = CGRectZero;
> >>> -r.origin = [ev 

Re: [PATCH v2] ui/cocoa: Use NSWindow's ability to resize

2021-06-28 Thread BALATON Zoltan

On Mon, 28 Jun 2021, Akihiko Odaki wrote:

2021年6月28日(月) 17:57 BALATON Zoltan :


On Mon, 28 Jun 2021, Akihiko Odaki wrote:

This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
 provided by the platform. (The left-top green button.)


While this is better for consistency with other apps is it a potential
usability issue that a window bar may appear when you move the mouse to
the top of the full screen window (where guests often have a menu bar that
this could make harder to use)? (Haven't tested it so don't know how it
actually works.)


The window bar is completely hidden with NSApplicationPresentationHideMenuBar.


I've missed that but now you pointed to it I have a comment about that.


Signed-off-by: Akihiko Odaki 
---
ui/cocoa.m | 542 -
1 file changed, 249 insertions(+), 293 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9f72844b079..091d9721f4d 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -93,12 +93,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
static DisplayChangeListener dcl = {
.ops = _ops,
};
-static int last_buttons;
static int cursor_hide = 1;

static int gArgc;
static char **gArgv;
-static bool stretch_video;
static NSTextField *pauseLabel;
static NSArray * supportedImageFileTypes;

@@ -301,19 +299,16 @@ static void handleAnyDeviceErrors(Error * err)
*/
@interface QemuCocoaView : NSView
{
+NSTrackingArea *trackingArea;
QEMUScreen screen;
-NSWindow *fullScreenWindow;
-float cx,cy,cw,ch,cdx,cdy;
pixman_image_t *pixman_image;
QKbdState *kbd;
BOOL isMouseGrabbed;
-BOOL isFullscreen;
BOOL isAbsoluteEnabled;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
- (void) ungrabMouse;
-- (void) toggleFullScreen:(id)sender;
- (void) handleMonitorInput:(NSEvent *)event;
- (bool) handleEvent:(NSEvent *)event;
- (bool) handleEventLocked:(NSEvent *)event;
@@ -328,8 +323,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 */
- (BOOL) isMouseGrabbed;
- (BOOL) isAbsoluteEnabled;
-- (float) cdx;
-- (float) cdy;
- (QEMUScreen) gscreen;
- (void) raiseAllKeys;
@end
@@ -369,46 +362,43 @@ - (BOOL) isOpaque
return YES;
}

-- (BOOL) screenContainsPoint:(NSPoint) p
+- (void) removeTrackingRect
{
-return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
+if (trackingArea) {
+[self removeTrackingArea:trackingArea];
+[trackingArea release];
+trackingArea = nil;
+}
}


You could override removeTrackingArea here then you would not have
addTrackingArea vs. removeTrackingRect and that's the way NSTrackingArea
docs also suggest.


https://developer.apple.com/documentation/appkit/nstrackingarea?language=objc

Other NSView methods related to NSTrackingArea objects
(in addition to addTrackingArea:) include removeTrackingArea: and
updateTrackingAreas. Views can override the latter method to recompute and
replace their NSTrackingArea objects in certain situations, such as a change in
the size of the visibleRect.


It says updateTrackingAreas can be overridden, but  decided to hook
the code to modify the guest display state instead because it should
be synchronized with trackingArea.


Indeed it means updateTrackingAreas but I don't think it says you can't 
override removeTrackingArea so you could still do that as long as you call 
the original method then do whatever else is needed. Doing it in another 
method works but breaks the symmetry of add and remove so you have to 
remember to use another method to remove the tracking area than what you'd 
normally use. That's why I thought overriding the remove method could be 
cleaner.



-/* Get location of event and convert to virtual screen coordinate */
-- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+- (void) frameUpdated
{
-NSWindow *eventWindow = [ev window];
-// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
-CGRect r = CGRectZero;
-r.origin = [ev locationInWindow];
-if (!eventWindow) {
-if (!isFullscreen) {
-return [[self window] convertRectFromScreen:r].origin;
-} else {
-CGPoint locationInSelfWindow = [[self window] 
convertRectFromScreen:r].origin;
-CGPoint loc = [self convertPoint:locationInSelfWindow 
fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else if ([[self window] isEqual:eventWindow]) {
-if (!isFullscreen) {
-return r.origin;
-} else {
-CGPoint loc = [self convertPoint:r.origin fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else {
-return [[self window] 

Re: [PATCH v2] ui/cocoa: Use NSWindow's ability to resize

2021-06-28 Thread Akihiko Odaki
2021年6月28日(月) 17:57 BALATON Zoltan :
>
> On Mon, 28 Jun 2021, Akihiko Odaki wrote:
> > This change brings two new features:
> > - The window will be resizable if "Zoom To Fit" is eanbled
> > - The window can be made full screen by clicking full screen button
> >  provided by the platform. (The left-top green button.)
>
> While this is better for consistency with other apps is it a potential
> usability issue that a window bar may appear when you move the mouse to
> the top of the full screen window (where guests often have a menu bar that
> this could make harder to use)? (Haven't tested it so don't know how it
> actually works.)

The window bar is completely hidden with NSApplicationPresentationHideMenuBar.

>
> > Signed-off-by: Akihiko Odaki 
> > ---
> > ui/cocoa.m | 542 -
> > 1 file changed, 249 insertions(+), 293 deletions(-)
> >
> > diff --git a/ui/cocoa.m b/ui/cocoa.m
> > index 9f72844b079..091d9721f4d 100644
> > --- a/ui/cocoa.m
> > +++ b/ui/cocoa.m
> > @@ -93,12 +93,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
> > static DisplayChangeListener dcl = {
> > .ops = _ops,
> > };
> > -static int last_buttons;
> > static int cursor_hide = 1;
> >
> > static int gArgc;
> > static char **gArgv;
> > -static bool stretch_video;
> > static NSTextField *pauseLabel;
> > static NSArray * supportedImageFileTypes;
> >
> > @@ -301,19 +299,16 @@ static void handleAnyDeviceErrors(Error * err)
> > */
> > @interface QemuCocoaView : NSView
> > {
> > +NSTrackingArea *trackingArea;
> > QEMUScreen screen;
> > -NSWindow *fullScreenWindow;
> > -float cx,cy,cw,ch,cdx,cdy;
> > pixman_image_t *pixman_image;
> > QKbdState *kbd;
> > BOOL isMouseGrabbed;
> > -BOOL isFullscreen;
> > BOOL isAbsoluteEnabled;
> > }
> > - (void) switchSurface:(pixman_image_t *)image;
> > - (void) grabMouse;
> > - (void) ungrabMouse;
> > -- (void) toggleFullScreen:(id)sender;
> > - (void) handleMonitorInput:(NSEvent *)event;
> > - (bool) handleEvent:(NSEvent *)event;
> > - (bool) handleEventLocked:(NSEvent *)event;
> > @@ -328,8 +323,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
> >  */
> > - (BOOL) isMouseGrabbed;
> > - (BOOL) isAbsoluteEnabled;
> > -- (float) cdx;
> > -- (float) cdy;
> > - (QEMUScreen) gscreen;
> > - (void) raiseAllKeys;
> > @end
> > @@ -369,46 +362,43 @@ - (BOOL) isOpaque
> > return YES;
> > }
> >
> > -- (BOOL) screenContainsPoint:(NSPoint) p
> > +- (void) removeTrackingRect
> > {
> > -return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < 
> > screen.height);
> > +if (trackingArea) {
> > +[self removeTrackingArea:trackingArea];
> > +[trackingArea release];
> > +trackingArea = nil;
> > +}
> > }
>
> You could override removeTrackingArea here then you would not have
> addTrackingArea vs. removeTrackingRect and that's the way NSTrackingArea
> docs also suggest.

https://developer.apple.com/documentation/appkit/nstrackingarea?language=objc
> Other NSView methods related to NSTrackingArea objects
> (in addition to addTrackingArea:) include removeTrackingArea: and
> updateTrackingAreas. Views can override the latter method to recompute and
> replace their NSTrackingArea objects in certain situations, such as a change 
> in
> the size of the visibleRect.

It says updateTrackingAreas can be overridden, but  decided to hook
the code to modify the guest display state instead because it should
be synchronized with trackingArea.

>
> >
> > -/* Get location of event and convert to virtual screen coordinate */
> > -- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
> > +- (void) frameUpdated
> > {
> > -NSWindow *eventWindow = [ev window];
> > -// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
> > -CGRect r = CGRectZero;
> > -r.origin = [ev locationInWindow];
> > -if (!eventWindow) {
> > -if (!isFullscreen) {
> > -return [[self window] convertRectFromScreen:r].origin;
> > -} else {
> > -CGPoint locationInSelfWindow = [[self window] 
> > convertRectFromScreen:r].origin;
> > -CGPoint loc = [self convertPoint:locationInSelfWindow 
> > fromView:nil];
> > -if (stretch_video) {
> > -loc.x /= cdx;
> > -loc.y /= cdy;
> > -}
> > -return loc;
> > -}
> > -} else if ([[self window] isEqual:eventWindow]) {
> > -if (!isFullscreen) {
> > -return r.origin;
> > -} else {
> > -CGPoint loc = [self convertPoint:r.origin fromView:nil];
> > -if (stretch_video) {
> > -loc.x /= cdx;
> > -loc.y /= cdy;
> > -}
> > -return loc;
> > -}
> > -} else {
> > -return [[self window] convertRectFromScreen:[eventWindow 
> > convertRectToScreen:r]].origin;
> > +[self removeTrackingRect];
> > +
> > +if ([self window]) {
> > +   

Re: [PATCH v2] ui/cocoa: Use NSWindow's ability to resize

2021-06-28 Thread BALATON Zoltan

On Mon, 28 Jun 2021, Akihiko Odaki wrote:

This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
 provided by the platform. (The left-top green button.)


While this is better for consistency with other apps is it a potential 
usability issue that a window bar may appear when you move the mouse to 
the top of the full screen window (where guests often have a menu bar that 
this could make harder to use)? (Haven't tested it so don't know how it 
actually works.)



Signed-off-by: Akihiko Odaki 
---
ui/cocoa.m | 542 -
1 file changed, 249 insertions(+), 293 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9f72844b079..091d9721f4d 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -93,12 +93,10 @@ static void cocoa_switch(DisplayChangeListener *dcl,
static DisplayChangeListener dcl = {
.ops = _ops,
};
-static int last_buttons;
static int cursor_hide = 1;

static int gArgc;
static char **gArgv;
-static bool stretch_video;
static NSTextField *pauseLabel;
static NSArray * supportedImageFileTypes;

@@ -301,19 +299,16 @@ static void handleAnyDeviceErrors(Error * err)
*/
@interface QemuCocoaView : NSView
{
+NSTrackingArea *trackingArea;
QEMUScreen screen;
-NSWindow *fullScreenWindow;
-float cx,cy,cw,ch,cdx,cdy;
pixman_image_t *pixman_image;
QKbdState *kbd;
BOOL isMouseGrabbed;
-BOOL isFullscreen;
BOOL isAbsoluteEnabled;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
- (void) ungrabMouse;
-- (void) toggleFullScreen:(id)sender;
- (void) handleMonitorInput:(NSEvent *)event;
- (bool) handleEvent:(NSEvent *)event;
- (bool) handleEventLocked:(NSEvent *)event;
@@ -328,8 +323,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 */
- (BOOL) isMouseGrabbed;
- (BOOL) isAbsoluteEnabled;
-- (float) cdx;
-- (float) cdy;
- (QEMUScreen) gscreen;
- (void) raiseAllKeys;
@end
@@ -369,46 +362,43 @@ - (BOOL) isOpaque
return YES;
}

-- (BOOL) screenContainsPoint:(NSPoint) p
+- (void) removeTrackingRect
{
-return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
+if (trackingArea) {
+[self removeTrackingArea:trackingArea];
+[trackingArea release];
+trackingArea = nil;
+}
}


You could override removeTrackingArea here then you would not have 
addTrackingArea vs. removeTrackingRect and that's the way NSTrackingArea 
docs also suggest.




-/* Get location of event and convert to virtual screen coordinate */
-- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+- (void) frameUpdated
{
-NSWindow *eventWindow = [ev window];
-// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
-CGRect r = CGRectZero;
-r.origin = [ev locationInWindow];
-if (!eventWindow) {
-if (!isFullscreen) {
-return [[self window] convertRectFromScreen:r].origin;
-} else {
-CGPoint locationInSelfWindow = [[self window] 
convertRectFromScreen:r].origin;
-CGPoint loc = [self convertPoint:locationInSelfWindow 
fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else if ([[self window] isEqual:eventWindow]) {
-if (!isFullscreen) {
-return r.origin;
-} else {
-CGPoint loc = [self convertPoint:r.origin fromView:nil];
-if (stretch_video) {
-loc.x /= cdx;
-loc.y /= cdy;
-}
-return loc;
-}
-} else {
-return [[self window] convertRectFromScreen:[eventWindow 
convertRectToScreen:r]].origin;
+[self removeTrackingRect];
+
+if ([self window]) {
+NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow |
+NSTrackingMouseEnteredAndExited |
+NSTrackingMouseMoved;
+trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame]
+options:options
+  owner:self
+   userInfo:nil];
+[self addTrackingArea:trackingArea];
+[self updateUIInfo];
}
}

+- (void) viewDidMoveToWindow
+{
+[self resizeWindow];
+[self frameUpdated];
+}
+
+- (void) viewWillMoveToWindow:(NSWindow *)newWindow
+{
+[self removeTrackingRect];
+}
+
- (void) hideCursor
{
if (!cursor_hide) {
@@ -471,13 +461,14 @@ - (void) drawRect:(NSRect) rect
int i;
CGImageRef clipImageRef;
CGRect clipRect;
+CGFloat d = (CGFloat)h / [self frame].size.height;

[self getRectsBeingDrawn: count:];
for (i = 0; i < rectCount; i++) {
-clipRect.origin.x = rectList[i].origin.x / cdx;
-