2782b2872b
Rather than depend on the Cocoa event system we intercept the events in our main loop and send them to the appropriate sk_app::Window. A hashmap that maps from Cocoa windowNumbers to an sk_app::Window is added to make this possible. We continue to send the event on through the Cocoa system to catch system level events -- e.g., window close and drag events. We also continue to catch key events in an NSView to keep the app from beeping annoyingly because it thinks it's capturing events outside its focus. Finally we ensure that move events are always enabled for the window so that imgui knows that the cursor is over it. Bug: skia:8737 Change-Id: Id49df51f68942fbf51634d6484291df862074864 Reviewed-on: https://skia-review.googlesource.com/c/191574 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
68 lines
1.3 KiB
Objective-C
68 lines
1.3 KiB
Objective-C
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef Window_mac_DEFINED
|
|
#define Window_mac_DEFINED
|
|
|
|
#include "../Window.h"
|
|
#include "SkTDynamicHash.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
namespace sk_app {
|
|
|
|
class Window_mac : public Window {
|
|
public:
|
|
Window_mac()
|
|
: INHERITED()
|
|
, fWindow(nil)
|
|
, fMSAASampleCount(1) {}
|
|
~Window_mac() override {
|
|
this->closeWindow();
|
|
}
|
|
|
|
bool initWindow();
|
|
|
|
void setTitle(const char*) override;
|
|
void show() override;
|
|
|
|
bool attach(BackendType) override;
|
|
|
|
void onInval() override {}
|
|
|
|
static void PaintWindows();
|
|
static void HandleWindowEvent(const NSEvent* event);
|
|
|
|
static const NSInteger& GetKey(const Window_mac& w) {
|
|
return w.fWindowNumber;
|
|
}
|
|
|
|
static uint32_t Hash(const NSInteger& windowNumber) {
|
|
return windowNumber;
|
|
}
|
|
|
|
bool needsPaint() { return this->fIsContentInvalidated; }
|
|
|
|
NSWindow* window() { return fWindow; }
|
|
void closeWindow();
|
|
|
|
private:
|
|
void handleEvent(const NSEvent* event);
|
|
|
|
NSWindow* fWindow;
|
|
NSInteger fWindowNumber;
|
|
int fMSAASampleCount;
|
|
|
|
static SkTDynamicHash<Window_mac, NSInteger> gWindowMap;
|
|
|
|
typedef Window INHERITED;
|
|
};
|
|
|
|
} // namespace sk_app
|
|
|
|
#endif
|