Skip to content

Commit

Permalink
Big commit, Key Binds WORKS
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Printzell <[email protected]>
  • Loading branch information
Vild committed Jan 14, 2016
1 parent 382991e commit cbe6933
Show file tree
Hide file tree
Showing 14 changed files with 2,783 additions and 2,556 deletions.
5 changes: 4 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"description": "A dynamic window manager written in D",
"copyright": "Copyright © 2015, Dan Printzell",
"libs": [
"xcb-ewmh",
"xcb-icccm",
"xcb-keysyms",
"xcb-xinerama"
],
"authors": [
"Dan Printzell"
],
"dependencies": {
"xcb-d": "~>2.0.0"
"xcb-d": "~>2.1.0"
}
}
24 changes: 18 additions & 6 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,37 @@ int main(string[] args) {
}

string title = "DWin - D always win!";
string size = "1280x720";
string size = "1920x1080";

auto Xephyr = spawnProcess([`Xephyr`, `-name`, title, `-ac`, `-br`, `-noreset`, `-screen`, size, `:8`]);
/*
rules: evdev
model: pc105
layout: se
options: terminate:ctrl_alt_bksp
-keybd ephyr,,,xkbmodel=pc105,xkblayout=se,xkbrules=evdev,xkboption=terminate:ctrl_alt_bksp
*/

auto Xephyr = spawnProcess([`Xephyr`, `-keybd`, `ephyr,,,xkbmodel=pc105,xkblayout=se,xkbrules=evdev,xkboption=`,
`-name`, title, `-ac`, `-br`, `-noreset`, `-screen`, size, `:8`]);
scope (exit)
kill(Xephyr);

import core.thread : Thread;
import core.time : seconds;

auto childEnv = environment.toAA;
childEnv["DISPLAY"] = ":8";

Thread.sleep(1.seconds);
spawnProcess(["feh", "--bg-scale", "http://wild.tk/DWinBG.png"], childEnv);

auto dwin = new DWin();
scope (exit)
dwin.destroy;

auto childEnv = environment.toAA;
childEnv["DISPLAY"] = ":8";

Pid xeyes;
Pid xterm;

Expand All @@ -41,7 +54,6 @@ int main(string[] args) {

auto spawnThread = new Thread(() {
Thread.sleep(1.seconds);
spawnProcess(["feh", "--bg-scale", "http://wild.tk/DWinBG.png"], childEnv);
xeyes = spawnProcess("xeyes", childEnv);
xterm = spawnProcess("xterm", childEnv);

Expand Down
88 changes: 9 additions & 79 deletions source/dwin/backend/container.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,17 @@ module dwin.backend.container;
import dwin.backend.layout;
import dwin.backend.window;

class Container {
abstract class Container {
public:
this(LayoutType type, Window window) {
this.type = type;
isLayout = false;
window = window;
}

this(LayoutType type, Layout layout) {
this.type = type;
isLayout = true;
layout = layout;
}

void Add(Container container) {
import dwin.layout.floatinglayout : FloatingLayout;

if (!isLayout) {
Window window = this.window;

if (type == LayoutType.Float)
layout = new FloatingLayout();
else
assert(0); //TODO: Add all the other layouts

layout.Add(new Container(type, window));
layout.Add(container);

isLayout = true;
} else
layout.Add(container);
}

void Remove(Container container) {
assert(isLayout);
layout.Remove(container);
if (layout.Containers.length == 1 && layout.ShouldCollapseOnOne) {
Container con = layout.Containers[0];
layout.destroy;
if (con.isLayout)
this.layout = con.TheLayout;
else
this.window = con.TheWindow;
isLayout = false;
}
}

void Move(short x, short y) {
if (isLayout)
layout.Move(x, y);
else
window.Move(x, y);
}

void Resize(ushort width, ushort height) {
if (isLayout)
layout.Resize(width, height);
else
window.Resize(width, height);
}

@property bool IsLayout() {
return isLayout;
}

@property ref Window TheWindow() {
assert(!isLayout);
return window;
}

@property ref Layout TheLayout() {
assert(isLayout);
return layout;
}
abstract void Add(Container container);
abstract void Remove(Container container);
abstract void Move(short x, short y);
abstract void Resize(ushort width, ushort height);

private:
union {
Window window;
Layout layout;
@property ref Layout Parent() {
return parent;
}

bool isLayout;
LayoutType type;
protected:
Layout parent;
}
18 changes: 6 additions & 12 deletions source/dwin/backend/layout.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,29 @@ enum LayoutType {
Tab
}

abstract class Layout {
abstract class Layout : Container {
public:
abstract void Add(Container container) {
override void Add(Container container) {
containers.insertBack(container);
container.Parent = this;
}

abstract void Remove(Container container) {
override void Remove(Container container) {
auto idx = containers[].countUntil(container);
assert(idx >= 0);
containers.linearRemove(containers[idx .. idx + 1]);
}

abstract void Move(short x, short y) {
override void Move(short x, short y) {
this.x = x;
this.y = y;
}

abstract void Resize(ushort width, ushort height) {
override void Resize(ushort width, ushort height) {
this.width = width;
this.height = height;
}

//void RequestMove();
//void RequestResize();

@property bool ShouldCollapseOnOne() {
return true;
}

@property short X() {
return x;
}
Expand Down
20 changes: 14 additions & 6 deletions source/dwin/backend/screen.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ public:
this.y = y;
this.width = width;
this.height = height;
onTopContainers = new FloatingLayout();
onTop = new FloatingLayout();
this.workspaces = workspaces;
}

void Add(Container container) {
workspaces[currentWorkspace].Add(container);
}

void Remove(Container container) {
workspaces[currentWorkspace].Remove(container);
}

void AddOnTop(Container container) {
onTopContainers.Add(container);
onTop.Add(container);
}

void RemoveOnTop(Container container) {
onTopContainers.Remove(container);
onTop.Remove(container);
}

@property ref string Name() {
Expand Down Expand Up @@ -54,8 +62,8 @@ public:
return workspaces;
}

@property FloatingLayout OnTopContainers() {
return onTopContainers;
@property FloatingLayout OnTop() {
return onTop;
}

protected:
Expand All @@ -68,5 +76,5 @@ protected:
ulong currentWorkspace;

Workspace[] workspaces;
FloatingLayout onTopContainers;
FloatingLayout onTop;
}
28 changes: 20 additions & 8 deletions source/dwin/backend/window.d
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
module dwin.backend.window;

import dwin.backend.layout;
import dwin.backend.container;
import dwin.log;

abstract class Window {
abstract class Window : Container {
public:
override void Add(Container container) {
Log.MainLogger.Error("Trying to add a container to a window, redirecting it to the parent!");
parent.Add(container);
}

override void Remove(Container container) {
Log.MainLogger.Error("Trying to remove a container from a window, redirecting it to the parent!");
parent.Remove(container);
}

abstract void Update();
abstract void Move(short x, short y);
abstract void Resize(ushort width, ushort height);
//abstract void Move(short x, short y);
//abstract void Resize(ushort width, ushort height);
abstract void Show();
abstract void Hide();

@property abstract string Title();

@property ref bool Dead() {
return dead;
}

@property short X() {
return x;
}
Expand Down Expand Up @@ -52,14 +68,10 @@ public:
return this.height;
}

@property ref Layout ParentLayout() {
return parentLayout;
}

protected:
bool dead;
short x;
short y;
ushort width;
ushort height;
Layout parentLayout;
}
32 changes: 13 additions & 19 deletions source/dwin/backend/workspace.d
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
module dwin.backend.workspace;

import dwin.backend.container;
import dwin.backend.layout;
import dwin.layout.floatinglayout;

class Workspace {
public:
this(string name) {
this.name = name;
onTopContainers = new FloatingLayout();
onTop = new FloatingLayout();
root = new FloatingLayout();
}

void Add(Container container) {
if (rootContainer)
rootContainer.Add(container);
else
rootContainer = container;
root.Add(container);
}

void Remove(Container container) {
assert(rootContainer);

if (rootContainer == container)
rootContainer = null;
else
rootContainer.Remove(container);
root.Remove(container);
}

void AddOnTop(Container container) {
onTopContainers.Add(container);
onTop.Add(container);
}

void RemoveOnTop(Container container) {
onTopContainers.Remove(container);
onTop.Remove(container);
}

@property ref string Name() {
return name;
}

@property Container RootContainer() {
return rootContainer;
@property Layout Root() {
return root;
}

@property FloatingLayout OnTopContainers() {
return onTopContainers;
@property FloatingLayout OnTop() {
return onTop;
}

protected:
string name;
Container rootContainer;
FloatingLayout onTopContainers;
Layout root;
FloatingLayout onTop;
}
Loading

0 comments on commit cbe6933

Please sign in to comment.