WindowRuleEnforcer: refactor function -> private static
This commit is contained in:
@@ -4,7 +4,7 @@ class WindowRuleEnforcer {
|
||||
private readonly followCaption: Set<string>;
|
||||
|
||||
constructor(windowRules: WindowRule[]) {
|
||||
const [mapFloat, mapTile] = createWindowRuleMaps(windowRules);
|
||||
const [mapFloat, mapTile] = WindowRuleEnforcer.createWindowRuleMaps(windowRules);
|
||||
this.preferFloating = new ClientMatcher(mapFloat);
|
||||
this.preferTiling = new ClientMatcher(mapTile);
|
||||
this.followCaption = new Set([...mapFloat.keys(), ...mapTile.keys()]);
|
||||
@@ -36,50 +36,50 @@ class WindowRuleEnforcer {
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
|
||||
function createWindowRuleMaps(windowRules: WindowRule[]) {
|
||||
const mapFloat = new Map<string, string[]>();
|
||||
const mapTile = new Map<string, string[]>();
|
||||
for (const windowRule of windowRules) {
|
||||
const map = windowRule.tile ? mapTile : mapFloat;
|
||||
let captions = map.get(windowRule.class);
|
||||
if (captions === undefined) {
|
||||
captions = [];
|
||||
map.set(windowRule.class, captions);
|
||||
private static createWindowRuleMaps(windowRules: WindowRule[]) {
|
||||
const mapFloat = new Map<string, string[]>();
|
||||
const mapTile = new Map<string, string[]>();
|
||||
for (const windowRule of windowRules) {
|
||||
const map = windowRule.tile ? mapTile : mapFloat;
|
||||
let captions = map.get(windowRule.class);
|
||||
if (captions === undefined) {
|
||||
captions = [];
|
||||
map.set(windowRule.class, captions);
|
||||
}
|
||||
if (windowRule.caption !== undefined) {
|
||||
captions.push(windowRule.caption);
|
||||
}
|
||||
}
|
||||
if (windowRule.caption !== undefined) {
|
||||
captions.push(windowRule.caption);
|
||||
|
||||
return [
|
||||
WindowRuleEnforcer.createWindowRuleRegexMap(mapFloat),
|
||||
WindowRuleEnforcer.createWindowRuleRegexMap(mapTile),
|
||||
];
|
||||
}
|
||||
|
||||
private static createWindowRuleRegexMap(windowRuleMap: Map<string, string[]>) {
|
||||
const regexMap = new Map<string, RegExp>;
|
||||
for (const [k, v] of windowRuleMap) {
|
||||
regexMap.set(k, WindowRuleEnforcer.joinRegexes(v));
|
||||
}
|
||||
return regexMap;
|
||||
}
|
||||
|
||||
return [
|
||||
createWindowRuleRegexMap(mapFloat),
|
||||
createWindowRuleRegexMap(mapTile),
|
||||
];
|
||||
}
|
||||
private static joinRegexes(regexes: string[]) {
|
||||
if (regexes.length == 0) {
|
||||
return new RegExp("");
|
||||
}
|
||||
|
||||
function createWindowRuleRegexMap(windowRuleMap: Map<string, string[]>) {
|
||||
const regexMap = new Map<string, RegExp>;
|
||||
for (const [k, v] of windowRuleMap) {
|
||||
regexMap.set(k, joinRegexes(v));
|
||||
}
|
||||
return regexMap;
|
||||
}
|
||||
if (regexes.length == 1) {
|
||||
return new RegExp("^" + regexes[0] + "$");
|
||||
}
|
||||
|
||||
function joinRegexes(regexes: string[]) {
|
||||
if (regexes.length == 0) {
|
||||
return new RegExp("");
|
||||
const joinedRegexes = regexes.map(WindowRuleEnforcer.wrapParens).join("|");
|
||||
return new RegExp("^" + joinedRegexes + "$");
|
||||
}
|
||||
|
||||
if (regexes.length == 1) {
|
||||
return new RegExp("^" + regexes[0] + "$");
|
||||
private static wrapParens(str: string) {
|
||||
return "(" + str + ")";
|
||||
}
|
||||
|
||||
const joinedRegexes = regexes.map(wrapParens).join("|");
|
||||
return new RegExp("^" + joinedRegexes + "$");
|
||||
}
|
||||
|
||||
function wrapParens(str: string) {
|
||||
return "(" + str + ")";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user