提交 7fa03813 编写于 作者: B Benjamin Pasero

window - have a getter for window being focused or not

上级 b368859a
......@@ -183,8 +183,10 @@ export interface IWindowService {
_serviceBrand: any;
onDidChangeFocus: Event<boolean>;
onDidChangeMaximize: Event<boolean>;
readonly onDidChangeFocus: Event<boolean>;
readonly onDidChangeMaximize: Event<boolean>;
readonly hasFocus: boolean;
getConfiguration(): IWindowConfiguration;
getCurrentWindowId(): number;
......
......@@ -11,25 +11,35 @@ import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
import { IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { URI } from 'vs/base/common/uri';
import { Disposable } from 'vs/base/common/lifecycle';
export class WindowService implements IWindowService {
export class WindowService extends Disposable implements IWindowService {
readonly onDidChangeFocus: Event<boolean>;
readonly onDidChangeMaximize: Event<boolean>;
_serviceBrand: any;
private _hasFocus: boolean;
get hasFocus(): boolean { return this._hasFocus; }
constructor(
private windowId: number,
private configuration: IWindowConfiguration,
@IWindowsService private windowsService: IWindowsService
) {
super();
const onThisWindowFocus = mapEvent(filterEvent(windowsService.onWindowFocus, id => id === windowId), _ => true);
const onThisWindowBlur = mapEvent(filterEvent(windowsService.onWindowBlur, id => id === windowId), _ => false);
const onThisWindowMaximize = mapEvent(filterEvent(windowsService.onWindowMaximize, id => id === windowId), _ => true);
const onThisWindowUnmaximize = mapEvent(filterEvent(windowsService.onWindowUnmaximize, id => id === windowId), _ => false);
this.onDidChangeFocus = anyEvent(onThisWindowFocus, onThisWindowBlur);
this.onDidChangeMaximize = anyEvent(onThisWindowMaximize, onThisWindowUnmaximize);
this._hasFocus = document.hasFocus();
this.isFocused().then(focused => this._hasFocus = focused);
this._register(this.onDidChangeFocus(focus => this._hasFocus = focus));
}
getCurrentWindowId(): number {
......
......@@ -54,7 +54,6 @@ export class NotificationsToasts extends Themable {
private notificationsToastsContainer: HTMLElement;
private workbenchDimensions: Dimension;
private windowHasFocus: boolean;
private isNotificationsCenterVisible: boolean;
private mapNotificationToToast: Map<INotificationViewItem, INotificationToast>;
private notificationsToastsVisibleContextKey: IContextKey<boolean>;
......@@ -75,8 +74,6 @@ export class NotificationsToasts extends Themable {
this.mapNotificationToToast = new Map<INotificationViewItem, INotificationToast>();
this.notificationsToastsVisibleContextKey = NotificationsToastsVisibleContext.bindTo(contextKeyService);
this.windowService.isFocused().then(isFocused => this.windowHasFocus = isFocused);
this.registerListeners();
}
......@@ -91,9 +88,6 @@ export class NotificationsToasts extends Themable {
// Update toasts on notification changes
this._register(this.model.onDidNotificationChange(e => this.onDidNotificationChange(e)));
});
// Track window focus
this.windowService.onDidChangeFocus(hasFocus => this.windowHasFocus = hasFocus);
}
private onCanShowNotifications(): Thenable<void> {
......@@ -241,7 +235,7 @@ export class NotificationsToasts extends Themable {
// the timeout again. This prevents an issue where focussing the window
// could immediately hide the notification because the timeout was triggered
// again.
if ((item.sticky || item.hasPrompt()) && !this.windowHasFocus) {
if ((item.sticky || item.hasPrompt()) && !this.windowService.hasFocus) {
if (!listener) {
listener = this.windowService.onDidChangeFocus(focus => {
if (focus) {
......
......@@ -37,6 +37,7 @@ import { CachedKeyboardMapper, IKeyboardMapper } from 'vs/workbench/services/key
import { MacLinuxFallbackKeyboardMapper } from 'vs/workbench/services/keybinding/common/macLinuxFallbackKeyboardMapper';
import { IMacLinuxKeyboardMapping, MacLinuxKeyboardMapper, macLinuxKeyboardMappingEquals } from 'vs/workbench/services/keybinding/common/macLinuxKeyboardMapper';
import { IWindowsKeyboardMapping, WindowsKeyboardMapper, windowsKeyboardMappingEquals } from 'vs/workbench/services/keybinding/common/windowsKeyboardMapper';
import { IWindowService } from 'vs/platform/windows/common/windows';
export class KeyboardMapperFactory {
public static readonly INSTANCE = new KeyboardMapperFactory();
......@@ -266,7 +267,8 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
@INotificationService notificationService: INotificationService,
@IEnvironmentService environmentService: IEnvironmentService,
@IStatusbarService statusBarService: IStatusbarService,
@IConfigurationService configurationService: IConfigurationService
@IConfigurationService configurationService: IConfigurationService,
@IWindowService private windowService: IWindowService
) {
super(contextKeyService, commandService, telemetryService, notificationService, statusBarService);
......@@ -367,7 +369,10 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
}
protected _documentHasFocus(): boolean {
return document.hasFocus();
// it is possible that the document has lost focus, but the
// window is still focused, e.g. when a <webview> element
// has focus
return this.windowService.hasFocus;
}
private _resolveKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
......
......@@ -1002,6 +1002,8 @@ export class TestWindowService implements IWindowService {
onDidChangeFocus: Event<boolean> = new Emitter<boolean>().event;
onDidChangeMaximize: Event<boolean>;
hasFocus = true;
isFocused(): TPromise<boolean> {
return TPromise.as(false);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册