Skip to content

Commit

Permalink
Much in the works.
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Printzell <[email protected]>
  • Loading branch information
Vild committed Oct 30, 2015
1 parent 686ab80 commit 6dd4be2
Show file tree
Hide file tree
Showing 15 changed files with 906 additions and 223 deletions.
57 changes: 57 additions & 0 deletions d-linter.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; Configurue which static analysis checks are enabled
[analysis.config.StaticAnalysisConfig]
; Check variable, class, struct, interface, union, and function names against t
; he Phobos style guide
style_check="false"
; Check for array literals that cause unnecessary allocation
enum_array_literal_check="true"
; Check for poor exception handling practices
exception_check="true"
; Check for use of the deprecated 'delete' keyword
delete_check="true"
; Check for use of the deprecated floating point operators
float_operator_check="true"
; Check number literals for readability
number_style_check="true"
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable
; , or inout.
object_const_check="true"
; Checks for .. expressions where the left side is larger than the right.
backwards_range_check="true"
; Checks for if statements whose 'then' block is the same as the 'else' block
if_else_same_check="true"
; Checks for some problems with constructors
constructor_check="true"
; Checks for unused variables and function parameters
unused_variable_check="true"
; Checks for unused labels
unused_label_check="true"
; Checks for duplicate attributes
duplicate_attribute="true"
; Checks that opEquals and toHash are both defined or neither are defined
opequals_tohash_check="true"
; Checks for subtraction from .length properties
length_subtraction_check="true"
; Checks for methods or properties whose names conflict with built-in propertie
; s
builtin_property_names_check="true"
; Checks for confusing code in inline asm statements
asm_style_check="true"
; Checks for confusing logical operator precedence
logical_precedence_check="true"
; Checks for undocumented public declarations
undocumented_declaration_check="true"
; Checks for poor placement of function attributes
function_attribute_check="true"
; Checks for use of the comma operator
comma_expression_check="true"
; Checks for local imports that are too broad
local_import_check="true"
; Checks for variables that could be declared immutable
could_be_immutable_check="true"
; Checks for redundant expressions in if statements
redundant_if_check="true"
; Checks for redundant parenthesis
redundant_parens_check="true"
; Checks for labels with the same name as variables
label_var_same_name_check="true"
4 changes: 2 additions & 2 deletions debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ sleep 1
DISPLAY=$XPORT

feh --bg-max ~/Pictures/Wallpaper.arch/archwall_dark_purple.png
xterm &
xterm &
#xterm &
#xterm &
#lxterminal &
xeyes &

Expand Down
207 changes: 4 additions & 203 deletions source/app.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import std.getopt;
import dwin.dwin;

int main(string[] args) {
import std.stdio : writeln, writefln;
Expand All @@ -10,209 +11,9 @@ int main(string[] args) {
return 0;
}

MainLoop();
auto dwin = new DWin();
dwin.Run();
dwin.destroy;

return 0;
}

enum HandlingEvent {
NONE,
MOVE,
RESIZE
}

void MainLoop() {
import dwin.log;
import dwin.backend.xcb.xcb;
import xcb.xcb;
import xcb.xproto;
Log log = Log.MainLogger();
XCB x = new XCB();

x.GrabKey(0, XCB_MOD_MASK_ANY, 9, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);

x.GrabButton(1, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, 1, XCB_MOD_MASK_ANY);

x.GrabButton(1, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, 3, XCB_MOD_MASK_ANY);
x.Flush();

HandlingEvent handlingEvent = HandlingEvent.NONE;
xcb_drawable_t win;
xcb_get_geometry_reply_t * geom;
bool quit = false;
enum Loc {
FIRST,
SECOND,
THIRD
}

xcb_get_geometry_reply_t oldGeom;
int pointerDiffX, pointerDiffY;

Loc row, column;

while (!quit) {
xcb_generic_event_t * e = xcb_wait_for_event(x.Display);
switch (e.response_type & ~0x80) {
case XCB_KEY_PRESS:
xcb_key_press_event_t * key = cast(xcb_key_press_event_t *)e;
quit = key.detail == 9/* Escape */;
break;
case XCB_BUTTON_PRESS:
xcb_button_press_event_t * be = cast(xcb_button_press_event_t *)e;

if (!(be.state&XCB_MOD_MASK_CONTROL))
break;

win = be.child;
if (!win)
break;
// Move the window that was clicked on, to the front.
xcb_configure_window(x.Display, win, XCB_CONFIG_WINDOW_STACK_MODE, [cast(uint)XCB_STACK_MODE_ABOVE].ptr);

// Get window size
geom = xcb_get_geometry_reply(x.Display, xcb_get_geometry(x.Display, win), null);
xcb_query_pointer_reply_t *pointer = xcb_query_pointer_reply(x.Display, xcb_query_pointer(x.Display, x.Root), null);

if (be.detail == 1) { //Left click
handlingEvent = HandlingEvent.MOVE;
pointerDiffX = pointer.root_x - geom.x;
pointerDiffY = pointer.root_y - geom.y;
oldGeom = *geom;
} else {
handlingEvent = HandlingEvent.RESIZE;
pointerDiffX = pointer.root_x - (geom.x + geom.width/2);
pointerDiffY = pointer.root_y - (geom.y + geom.height/2);
oldGeom = *geom;

int pointX = (pointer.root_x - geom.x) / (geom.width / 4)+1;
int pointY = (pointer.root_y - geom.y) / (geom.height / 4)+1;

log.Info("PointX: %d, PointY: %d", pointX, pointY);

if (pointX & 0b100)
column = Loc.THIRD;
else if (pointX & 0b10)
column = Loc.SECOND;
else if (pointX & 0b1)
column = Loc.FIRST;
else
assert(0);

if (pointY & 0b100)
row = Loc.THIRD;
else if (pointY & 0b10)
row = Loc.SECOND;
else if (pointY & 0b1)
row = Loc.FIRST;
else
assert(0);

log.Info("Row: %s, Column: %s", row, column);
}
x.GrabPointer(0, XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_CURRENT_TIME);
x.Flush();
break;

case XCB_MOTION_NOTIFY:
if (handlingEvent == HandlingEvent.NONE)
break;
xcb_query_pointer_reply_t *pointer = xcb_query_pointer_reply(x.Display, xcb_query_pointer(x.Display, x.Root), null);
if (handlingEvent == HandlingEvent.MOVE) {
geom = xcb_get_geometry_reply(x.Display, xcb_get_geometry(x.Display, win), null);

uint px = pointer.root_x - pointerDiffX;
uint py = pointer.root_y - pointerDiffY;

xcb_configure_window(x.Display, win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, [px, py].ptr);
x.Flush();
} else if (handlingEvent == HandlingEvent.RESIZE) {
geom = xcb_get_geometry_reply(x.Display, xcb_get_geometry(x.Display, win), null);


int px = geom.x;
int py = geom.y;
int pw = geom.width; // pointer.root_x - geom.x + pointerDiffX;
int ph = geom.height; // pointer.root_y - geom.y + pointerDiffY;


if (row == Loc.FIRST) {
if (column == Loc.FIRST) {
uint oldPx = px;
px = (pointer.root_x) - (pointerDiffX + oldGeom.width / 2);
pw += oldPx - px;

uint oldPy = py;
py = (pointer.root_y) - (pointerDiffY + oldGeom.height / 2);
ph += oldPy - py;

} else if (column == Loc.SECOND) {
uint oldPy = py;
py = (pointer.root_y) - (pointerDiffY + oldGeom.height / 2);
ph += oldPy - py;
} else /*if (column == Loc.THIRD) */ {
pw = (pointer.root_x - oldGeom.x) - (pointerDiffX - oldGeom.width / 2);

uint oldPy = py;
py = (pointer.root_y) - (pointerDiffY + oldGeom.height / 2);
ph += oldPy - py;
}
} else if (row == Loc.SECOND) {
if (column == Loc.FIRST) {
uint oldPx = px;
px = (pointer.root_x) - (pointerDiffX + oldGeom.width / 2);
pw += oldPx - px;

} else if (column == Loc.SECOND) {

} else /*if (column == Loc.THIRD) */ {
pw = (pointer.root_x - oldGeom.x) - (pointerDiffX - oldGeom.width / 2);
}
} else /*if (row == Loc.THIRD) */ {
if (column == Loc.FIRST) {
uint oldPx = px;
px = (pointer.root_x) - (pointerDiffX + oldGeom.width / 2);
pw += oldPx - px;

ph = (pointer.root_y - oldGeom.y) - (pointerDiffY - oldGeom.height/2);
} else if (column == Loc.SECOND) {


ph = (pointer.root_y - oldGeom.y) - (pointerDiffY - oldGeom.height/2);
} else /*if (column == Loc.THIRD) */ {
pw = (pointer.root_x - oldGeom.x) - (pointerDiffX - oldGeom.width / 2);
ph = (pointer.root_y - oldGeom.y) - (pointerDiffY - oldGeom.height / 2);
}
}

{
import std.algorithm.comparison : max;
px = max(px, 0);
py = max(py, 0);
pw = max(pw, 16);
ph = max(ph, 16);
}

xcb_configure_window(x.Display, win,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
[cast(uint)px, cast(uint)py, cast(uint)pw, cast(uint)ph].ptr);
x.Flush();
}
break;

case XCB_BUTTON_RELEASE:
handlingEvent = HandlingEvent.NONE;
x.UngrabPointer(XCB_CURRENT_TIME);
x.Flush();
break;
default:

break;
}

}
}
5 changes: 5 additions & 0 deletions source/dwin/backend/hotkeymanager.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module dwin.backend.hotkeymanager;

final class HotKeyManager {

}
76 changes: 76 additions & 0 deletions source/dwin/backend/xcb/atom.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module dwin.backend.xcb.atom;

import xcb.xcb;
import dwin.backend.xcb.xcb;
import dwin.backend.xcb.window;
import std.string : toStringz;
import std.conv : to;
import std.c.stdlib : free;

struct Atom {
this(XCB xcb, string name, bool createOnMissing = true) {
atom = XCB_ATOM_NONE;
xcb_intern_atom_cookie_t c = xcb_intern_atom_unchecked(xcb.Connection, !createOnMissing, cast(ushort)name.length, name.toStringz);
if (auto reply = xcb_intern_atom_reply(xcb.Connection, c, null)) {
atom = reply.atom;
free(reply);
}
}

this(xcb_atom_t atom) {
this.atom = atom;
}

Atom[] GetPropertyAtom(XCB xcb, Window window) {
Atom[] ret;
xcb_get_property_cookie_t c = xcb_get_property_unchecked(xcb.Connection, 0, window.Window, atom, XCB_ATOM_ATOM, 0, 0);
if (auto reply = xcb_get_property_reply(xcb.Connection, c, null)) {
xcb_atom_t[] tmp = (cast(xcb_atom_t *)xcb_get_property_value(reply))[0 .. xcb_get_property_value_length(reply)];
foreach (atom; tmp)
ret ~= Atom(atom);
free(reply);
}
return ret;
}

Window[] GetPropertyWindow(XCB xcb, Window window) {
Window[] ret;
xcb_get_property_cookie_t c = xcb_get_property_unchecked(xcb.Connection, 0, window.Window, atom, XCB_ATOM_WINDOW, 0, 0);
if (auto reply = xcb_get_property_reply(xcb.Connection, c, null)) {
xcb_window_t[] tmp = (cast(xcb_window_t *)xcb_get_property_value(reply))[0 .. xcb_get_property_value_length(reply)];
foreach (win; tmp)
ret ~= new Window(xcb, win);
free(reply);
}
return ret;
}

string GetPropertyString(XCB xcb, Window window) {
string ret = null;
xcb_get_property_cookie_t c = xcb_get_property_unchecked(xcb.Connection, 0, window.Window, atom, XCB_ATOM_STRING, 0, 0);
if (auto reply = xcb_get_property_reply(xcb.Connection, c, null)) {
char[] tmp = (cast(char *)xcb_get_property_value(reply))[0 .. xcb_get_property_value_length(reply)];
ret = tmp.to!string;
free(reply);
}
return ret;
}

void ChangeProperty(XCB xcb, Window window, Atom atom) {
xcb_change_property(xcb.Connection, XCB_PROP_MODE_REPLACE, window.Window, atom, XCB_ATOM_ATOM, 32, 1, cast(ubyte *)&atom);
}

void ChangeProperty(XCB xcb, Window window, Window value) {
xcb_change_property(xcb.Connection, XCB_PROP_MODE_REPLACE, window.Window, atom, XCB_ATOM_WINDOW, 32, 1, cast(ubyte *)&value);
}

void ChangeProperty(XCB xcb, Window window, string str) {
xcb_change_property(xcb.Connection, XCB_PROP_MODE_REPLACE, window.Window, atom, XCB_ATOM_STRING, 8, cast(uint)str.length, str.toStringz);
}

@property bool IsValid() { return atom != XCB_ATOM_NONE; }


alias atom this;
xcb_atom_t atom;
}
6 changes: 6 additions & 0 deletions source/dwin/backend/xcb/color.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module dwin.backend.xcb.color;

struct Color {
public:
private:
}
Loading

0 comments on commit 6dd4be2

Please sign in to comment.