Cost for associating the the given metaWindow to the msWindow. * * windowInfo are the matching details for the meta window, for example its window title. * * A higher returned cost means the match is less desirable.
(
windowInfo: MsWindowMatchingInfo,
metaWindow: Meta.Window,
msWindow: MsWindow
)
| 80 | * A higher returned cost means the match is less desirable. |
| 81 | */ |
| 82 | function windowMatchingCost( |
| 83 | windowInfo: MsWindowMatchingInfo, |
| 84 | metaWindow: Meta.Window, |
| 85 | msWindow: MsWindow |
| 86 | ) { |
| 87 | const state = msWindow.lifecycleState; |
| 88 | assert( |
| 89 | state.type === 'window' || state.type === 'app-placeholder', |
| 90 | 'MsWindow has no matching info' |
| 91 | ); |
| 92 | const matchingInfo = state.matchingInfo; |
| 93 | |
| 94 | let cost = 0; |
| 95 | // The wmClass *must* match if specified |
| 96 | cost += matchingCost(matchingInfo.wmClass, windowInfo.wmClass, INF_COST, 1); |
| 97 | cost += matchingCost(matchingInfo.pid, windowInfo.pid, 100, 1); |
| 98 | cost += matchingCost(matchingInfo.title, windowInfo.title, 50, 1); |
| 99 | cost += matchingCost(matchingInfo.stableSeq, windowInfo.stableSeq, 1, 1); |
| 100 | |
| 101 | const msWindowMeta = |
| 102 | state.type === 'window' ? state.metaWindow ?? undefined : undefined; |
| 103 | // Prefer to keep existing matchings |
| 104 | cost += msWindowMeta === metaWindow ? 0 : 5; |
| 105 | |
| 106 | const waiting = |
| 107 | state.type === 'app-placeholder' |
| 108 | ? state.waitingForAppSince !== undefined |
| 109 | : state.matchedWhileWaiting; |
| 110 | // Prefer matching to MsWindows which are waiting for an app to open |
| 111 | cost += waiting ? 0 : 200; |
| 112 | |
| 113 | return cost; |
| 114 | } |
| 115 | |
| 116 | export type MsWindowManagerType = InstanceType<typeof MsWindowManager>; |
| 117 | export class MsWindowManager extends MsManager { |
no test coverage detected