Implement SysColorChangeListener directly on Windows
This commit is contained in:
parent
25bcc2dd0d
commit
38281f3364
3 changed files with 17 additions and 26 deletions
|
@ -14,7 +14,11 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
|
||||
SystemPreferences::SystemPreferences(v8::Isolate* isolate)
|
||||
#if defined(OS_WIN)
|
||||
: color_change_listener_(this)
|
||||
#endif
|
||||
{
|
||||
Init(isolate);
|
||||
#if defined(OS_WIN)
|
||||
InitializeWindow();
|
||||
|
|
|
@ -24,7 +24,11 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
||||
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||
#if defined(OS_WIN)
|
||||
, public gfx::SysColorChangeListener
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
static mate::Handle<SystemPreferences> Create(v8::Isolate* isolate);
|
||||
|
||||
|
@ -43,8 +47,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
|
||||
void InitializeWindow();
|
||||
|
||||
void OnColorChanged();
|
||||
|
||||
// gfx::SysColorChangeListener:
|
||||
void OnSysColorChange() override;
|
||||
|
||||
#elif defined(OS_MACOSX)
|
||||
using NotificationCallback = base::Callback<
|
||||
|
@ -101,9 +105,9 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
|
||||
std::string current_color_;
|
||||
|
||||
bool invertered_color_scheme_ = false;
|
||||
bool invertered_color_scheme_;
|
||||
|
||||
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
||||
gfx::ScopedSysColorChangeListener color_change_listener_;
|
||||
#endif
|
||||
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
||||
};
|
||||
|
|
|
@ -19,21 +19,6 @@ const wchar_t kSystemPreferencesWindowClass[] =
|
|||
|
||||
namespace api {
|
||||
|
||||
class SystemPreferencesColorChangeListener
|
||||
: public gfx::SysColorChangeListener {
|
||||
public:
|
||||
explicit SystemPreferencesColorChangeListener(SystemPreferences* prefs)
|
||||
: prefs_(prefs) {
|
||||
}
|
||||
|
||||
void OnSysColorChange() {
|
||||
prefs_->OnColorChanged();
|
||||
}
|
||||
|
||||
private:
|
||||
SystemPreferences* prefs_;
|
||||
};
|
||||
|
||||
bool SystemPreferences::IsAeroGlassEnabled() {
|
||||
return ui::win::IsAeroGlassEnabled();
|
||||
}
|
||||
|
@ -57,6 +42,8 @@ std::string SystemPreferences::GetAccentColor() {
|
|||
}
|
||||
|
||||
void SystemPreferences::InitializeWindow() {
|
||||
invertered_color_scheme_ = IsInvertedColorScheme();
|
||||
|
||||
WNDCLASSEX window_class;
|
||||
base::win::InitializeWindowClass(
|
||||
kSystemPreferencesWindowClass,
|
||||
|
@ -74,10 +61,6 @@ void SystemPreferences::InitializeWindow() {
|
|||
0, WS_POPUP, 0, 0, 0, 0, 0, 0, instance_, 0);
|
||||
gfx::CheckWindowCreated(window_);
|
||||
gfx::SetWindowUserData(window_, this);
|
||||
|
||||
color_change_listener_.reset(
|
||||
new gfx::ScopedSysColorChangeListener(
|
||||
new SystemPreferencesColorChangeListener(this)));
|
||||
}
|
||||
|
||||
LRESULT CALLBACK SystemPreferences::WndProcStatic(HWND hwnd,
|
||||
|
@ -107,7 +90,7 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd,
|
|||
return ::DefWindowProc(hwnd, message, wparam, lparam);
|
||||
}
|
||||
|
||||
void SystemPreferences::OnColorChanged() {
|
||||
void SystemPreferences::OnSysColorChange() {
|
||||
bool new_invertered_color_scheme = IsInvertedColorScheme();
|
||||
if (new_invertered_color_scheme != invertered_color_scheme_) {
|
||||
invertered_color_scheme_ = new_invertered_color_scheme;
|
||||
|
|
Loading…
Reference in a new issue