Skip to content

Commit

Permalink
fix: Fetch window names upfront; ignore unknown windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Feb 26, 2020
1 parent 396815a commit 8fb6a4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
25 changes: 20 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ export class Ext extends Ecs.World {

/// Fetches the window component from the entity associated with the metacity window metadata.
get_window(meta: any): Window.ShellWindow | null {
// TODO: Deprecate this
let entity = this.window(meta);
let entity = this.window_entity(meta);
return entity ? this.windows.get(entity) : null;
}

Expand Down Expand Up @@ -711,22 +710,38 @@ export class Ext extends Ecs.World {
}

/// Fetches the window entity which is associated with the metacity window metadata.
window(meta: any) {
window_entity(meta: any): Entity | null {
if (!meta) return null;

let id = meta.get_stable_sequence();
let id: number;

try {
id = meta.get_stable_sequence();
} catch (e) {
return null;
}

// Locate the window entity with the matching ID
let entity = this.ids.find((comp) => comp == id).next().value;

// If not found, create a new entity with a ShellWindow component.
if (!entity) {
let window_app: any, name: string;

try {
window_app = Window.window_tracker.get_window_app(meta);
name = window_app.get_name().replace(/&/g, "&");
} catch (e) {
return null;
}

entity = this.create_entity();

let win = new Window.ShellWindow(entity, meta, this);
let win = new Window.ShellWindow(entity, meta, window_app, this);

this.windows.insert(entity, win);
this.ids.insert(entity, id);
this.names.insert(entity, name);
this.monitors.insert(entity, [win.meta.get_monitor(), win.meta.get_workspace().index()]);

Log.debug(`created window (${win.entity}): ${win.name()}: ${id}`);
Expand Down
29 changes: 6 additions & 23 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const MOTIF_HINTS: string = '_MOTIF_WM_HINTS';
const HIDE_FLAGS: string[] = ['0x2', '0x0', '0x2', '0x0', '0x0'];
const SHOW_FLAGS: string[] = ['0x2', '0x0', '0x1', '0x0', '0x0'];

const window_tracker = Shell.WindowTracker.get_default();
export var window_tracker = Shell.WindowTracker.get_default();

export class ShellWindow {
entity: Entity;
meta: any;

private _window_app: any;
private window_app: any;
private ext: Ext;

constructor(entity: Entity, window: any, ext: Ext) {
this._window_app = null;
constructor(entity: Entity, window: any, window_app: any, ext: Ext) {
this.window_app = window_app;
this.ext = ext;

this.entity = entity;
Expand Down Expand Up @@ -55,10 +55,7 @@ export class ShellWindow {

icon(size: number) {
return this.ext.icons.get_or(this.entity, () => {
let app = this.window_app();
if (!app) return null;

let icon = app.create_icon_texture(size);
let icon = this.window_app.create_icon_texture(size);

if (!icon) {
icon = new St.Icon({
Expand Down Expand Up @@ -100,13 +97,7 @@ export class ShellWindow {
}

name(): string {
return this.ext.names.get_or(this.entity, () => {
try {
return this.window_app().get_name().replace(/&/g, "&");
} catch (e) {
return "unknown";
}
});
return this.ext.names.get_or(this.entity, () => "unknown");
}

rect(): Rectangle {
Expand All @@ -122,14 +113,6 @@ export class ShellWindow {
place_pointer_on(this.meta);
}

window_app() {
if (!this._window_app) {
this._window_app = window_tracker.get_window_app(this.meta)
}

return this._window_app;
}

xid() {
const desc = this.meta.get_description();
const match = desc && desc.match(/0x[0-9a-f]+/);
Expand Down

0 comments on commit 8fb6a4d

Please sign in to comment.