-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to es6 module syntax, and make Workspace and Window into funct…
…ion collections (instead of classes)
- Loading branch information
Showing
4 changed files
with
118 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
module.exports = class { | ||
constructor(id, parent, screen) { | ||
this.id = id | ||
this.parent = parent | ||
this.screen = screen | ||
} | ||
const create = id => ({ | ||
id, | ||
workspace: null, | ||
shown: false, | ||
focused: false | ||
}) | ||
|
||
show() { | ||
global.X.MapWindow(this.id) | ||
} | ||
|
||
hide() { | ||
global.X.UnmapWindow(this.id) | ||
} | ||
|
||
focus() { | ||
global.X.SetInputFocus(this.id) | ||
} | ||
const show = window => { | ||
global.X.MapWindow(window.id) | ||
window.shown = true | ||
} | ||
|
||
kill() { | ||
global.X.DestroyWindow(this.id) | ||
} | ||
const hide = window => { | ||
global.X.UnmapWindow(window.id) | ||
window.shown = false | ||
} | ||
|
||
exec(callback) { | ||
callback(this) | ||
} | ||
const focus = window => { | ||
global.X.SetInputFocus(window.id) | ||
// todo: how does this get unset | ||
// is it even the job of the window to maintain this? | ||
window.focused = true | ||
} | ||
|
||
export {create, show, hide, focus} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
const Window = require('./window') | ||
import * as Window from './window' | ||
|
||
module.exports = class { | ||
constructor(screen) { | ||
this.screen = screen | ||
this.root = screen.root | ||
this.focused = null | ||
this.windows = [] | ||
} | ||
const create = id => ({ | ||
id, | ||
windows: [], | ||
currentWindow: null | ||
}) | ||
|
||
addWindow(id) { | ||
const window = new Window(id) | ||
this.windows.push(window) | ||
window.show() | ||
// todo: maybe this should always take only ever a window | ||
const addWindow = (workspace, window) => { | ||
if (!window) return | ||
if (typeof window == 'number') { | ||
window = Window.create(window) | ||
} | ||
workspace.windows.push(window) | ||
Window.show(window) | ||
} | ||
|
||
removeWindow(id) { | ||
this.windows = this.windows.filter(window => window.id != id) | ||
} | ||
const removeWindow = (workspace, window) => { | ||
if (!window) return | ||
const {id} = window | ||
workspace.windows = workspace.windows.filter(window => window.id != id) | ||
} | ||
|
||
show() { | ||
if (this.focused) { | ||
this.focused.focus() | ||
} else { | ||
global.X.SetInputFocus(this.root) | ||
} | ||
this.windows.forEach(window => window.show()) | ||
} | ||
// todo: should root be a global? | ||
// todo: should root be a *window*? | ||
// todo: this root argument definitely doesn't belong here | ||
const show = (workspace, root) => { | ||
workspace.currentWindow | ||
? Window.focus(workspace.currentWindow) | ||
: global.X.SetInputFocus(root) | ||
workspace.windows.forEach(Window.show) | ||
} | ||
|
||
hide() { | ||
this.windows.forEach(window => window.hide()) | ||
} | ||
const hide = workspace => { | ||
workspace.windows.forEach(Window.hide) | ||
} | ||
|
||
contains(id) { | ||
return this.windows.some(window => window.id == id) | ||
} | ||
const contains = (workspace, window) => { | ||
const {id} = window | ||
return workspace.windows.some(window => window.id == id) | ||
} | ||
|
||
export {create, addWindow, removeWindow, show, hide, contains} |