mirror of
https://github.com/esjeon/krohnkite.git
synced 2024-10-04 07:18:09 +03:00
split LayoutStorage
into a separate file
This commit is contained in:
parent
3e7bdc3f7a
commit
b1ca95c3f6
@ -18,67 +18,6 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class LayoutStorage {
|
||||
private store: { [key: string]: ILayout[] };
|
||||
|
||||
constructor() {
|
||||
this.store = {};
|
||||
}
|
||||
|
||||
public getCurrentLayout(screen: number, activity: string, desktop: number): ILayout {
|
||||
const key = this.keygen(screen, activity, desktop);
|
||||
|
||||
if (!this.store[key])
|
||||
this.initEntry(key);
|
||||
|
||||
// TODO: if no layout, return floating layout, which is a static object.
|
||||
return this.store[key][0];
|
||||
}
|
||||
|
||||
public cycleLayout(screen: number, activity: string, desktop: number) {
|
||||
const key = this.keygen(screen, activity, desktop);
|
||||
|
||||
const entry = this.store[key];
|
||||
if (!entry) {
|
||||
this.initEntry(key);
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
const layout = entry.shift();
|
||||
if (!layout)
|
||||
return;
|
||||
|
||||
entry.push(layout);
|
||||
|
||||
if (entry[0].isEnabled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private keygen(screen: number, activity: string, desktop: number): string {
|
||||
let key = String(screen);
|
||||
|
||||
if (Config.layoutPerActivity)
|
||||
key += "@" + activity;
|
||||
if (Config.layoutPerDesktop)
|
||||
key += "#" + desktop;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
private initEntry(key: string) {
|
||||
const entry = [];
|
||||
// TODO: user config
|
||||
entry.push(new TileLayout());
|
||||
entry.push(new MonocleLayout());
|
||||
entry.push(new SpreadLayout());
|
||||
entry.push(new StairLayout());
|
||||
|
||||
this.store[key] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
class TilingEngine {
|
||||
public jiggle: boolean;
|
||||
|
||||
|
80
src/layoutstorage.ts
Normal file
80
src/layoutstorage.ts
Normal file
@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2018 Eon S. Jeon <esjeon@hyunmu.am>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class LayoutStorage {
|
||||
private store: { [key: string]: ILayout[] };
|
||||
|
||||
constructor() {
|
||||
this.store = {};
|
||||
}
|
||||
|
||||
public getCurrentLayout(screen: number, activity: string, desktop: number): ILayout {
|
||||
const key = this.keygen(screen, activity, desktop);
|
||||
|
||||
if (!this.store[key])
|
||||
this.initEntry(key);
|
||||
|
||||
// TODO: if no layout, return floating layout, which is a static object.
|
||||
return this.store[key][0];
|
||||
}
|
||||
|
||||
public cycleLayout(screen: number, activity: string, desktop: number) {
|
||||
const key = this.keygen(screen, activity, desktop);
|
||||
|
||||
const entry = this.store[key];
|
||||
if (!entry) {
|
||||
this.initEntry(key);
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
const layout = entry.shift();
|
||||
if (!layout)
|
||||
return;
|
||||
|
||||
entry.push(layout);
|
||||
|
||||
if (entry[0].isEnabled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private keygen(screen: number, activity: string, desktop: number): string {
|
||||
let key = String(screen);
|
||||
|
||||
if (Config.layoutPerActivity)
|
||||
key += "@" + activity;
|
||||
if (Config.layoutPerDesktop)
|
||||
key += "#" + desktop;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
private initEntry(key: string) {
|
||||
const entry = [];
|
||||
// TODO: user config
|
||||
entry.push(new TileLayout());
|
||||
entry.push(new MonocleLayout());
|
||||
entry.push(new SpreadLayout());
|
||||
entry.push(new StairLayout());
|
||||
|
||||
this.store[key] = entry;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user