fixes and refactoring - XCB app

This commit is contained in:
Vadim Lopatin 2014-03-14 13:54:35 +04:00
parent 5135e9ec30
commit cb500d42e4
3 changed files with 167 additions and 7 deletions

2
3rdparty/X11/Xlib.d vendored
View File

@ -17,7 +17,7 @@ public import std.c.linux.X11.X;
const int XlibSpecificationRelease=6;
version = X_HAVE_UTF8_STRING;
typedef void* XPointer;
alias XPointer = void*;
typedef int Status ;
enum Bool:int{False,True}; //xlib boolean is int type, D bool is only byte
enum QueueMode{QueuedAlready,QueuedAfterReading,QueuedAfterFlush};

View File

@ -99,6 +99,79 @@ struct xcb_colormap_iterator_t {
alias uint xcb_atom_t;
enum : uint {
XCB_ATOM_NONE = 0,
XCB_ATOM_ANY = 0,
XCB_ATOM_PRIMARY,
XCB_ATOM_SECONDARY,
XCB_ATOM_ARC,
XCB_ATOM_ATOM,
XCB_ATOM_BITMAP,
XCB_ATOM_CARDINAL,
XCB_ATOM_COLORMAP,
XCB_ATOM_CURSOR,
XCB_ATOM_CUT_BUFFER0,
XCB_ATOM_CUT_BUFFER1,
XCB_ATOM_CUT_BUFFER2,
XCB_ATOM_CUT_BUFFER3,
XCB_ATOM_CUT_BUFFER4,
XCB_ATOM_CUT_BUFFER5,
XCB_ATOM_CUT_BUFFER6,
XCB_ATOM_CUT_BUFFER7,
XCB_ATOM_DRAWABLE,
XCB_ATOM_FONT,
XCB_ATOM_INTEGER,
XCB_ATOM_PIXMAP,
XCB_ATOM_POINT,
XCB_ATOM_RECTANGLE,
XCB_ATOM_RESOURCE_MANAGER,
XCB_ATOM_RGB_COLOR_MAP,
XCB_ATOM_RGB_BEST_MAP,
XCB_ATOM_RGB_BLUE_MAP,
XCB_ATOM_RGB_DEFAULT_MAP,
XCB_ATOM_RGB_GRAY_MAP,
XCB_ATOM_RGB_GREEN_MAP,
XCB_ATOM_RGB_RED_MAP,
XCB_ATOM_STRING,
XCB_ATOM_VISUALID,
XCB_ATOM_WINDOW,
XCB_ATOM_WM_COMMAND,
XCB_ATOM_WM_HINTS,
XCB_ATOM_WM_CLIENT_MACHINE,
XCB_ATOM_WM_ICON_NAME,
XCB_ATOM_WM_ICON_SIZE,
XCB_ATOM_WM_NAME,
XCB_ATOM_WM_NORMAL_HINTS,
XCB_ATOM_WM_SIZE_HINTS,
XCB_ATOM_WM_ZOOM_HINTS,
XCB_ATOM_MIN_SPACE,
XCB_ATOM_NORM_SPACE,
XCB_ATOM_MAX_SPACE,
XCB_ATOM_END_SPACE,
XCB_ATOM_SUPERSCRIPT_X,
XCB_ATOM_SUPERSCRIPT_Y,
XCB_ATOM_SUBSCRIPT_X,
XCB_ATOM_SUBSCRIPT_Y,
XCB_ATOM_UNDERLINE_POSITION,
XCB_ATOM_UNDERLINE_THICKNESS,
XCB_ATOM_STRIKEOUT_ASCENT,
XCB_ATOM_STRIKEOUT_DESCENT,
XCB_ATOM_ITALIC_ANGLE,
XCB_ATOM_X_HEIGHT,
XCB_ATOM_QUAD_WIDTH,
XCB_ATOM_WEIGHT,
XCB_ATOM_POINT_SIZE,
XCB_ATOM_RESOLUTION,
XCB_ATOM_COPYRIGHT,
XCB_ATOM_NOTICE,
XCB_ATOM_FONT_NAME,
XCB_ATOM_FAMILY_NAME,
XCB_ATOM_FULL_NAME,
XCB_ATOM_CAP_HEIGHT,
XCB_ATOM_WM_CLASS,
XCB_ATOM_WM_TRANSIENT_FOR
};
/**
* @brief xcb_atom_iterator_t
**/

View File

@ -1,6 +1,8 @@
module src.dlangui.platforms.x11.x11app;
import std.stdio;
version(linux) {
import std.string;
import std.c.linux.X11.xcb.xcb;
import std.c.linux.X11.xcb.xproto;
import std.c.linux.X11.keysymdef;
@ -43,12 +45,14 @@ class XCBWindow : Window {
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_MOTION
| XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE;
| XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE
| XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE;
xcb_create_window(_xcbconnection, _xcbscreen.root_depth, _w, _xcbscreen.root,
10, 10, 100, 100, 1,
50, 50, 500, 400, 1,
XCB_WINDOW_CLASS_INPUT_OUTPUT, _xcbscreen.root_visual,
mask, &values[0]);
xcb_flush(_xcbconnection);
windowCaption = _caption;
return true;
}
override void show() {
@ -63,6 +67,15 @@ class XCBWindow : Window {
}
override @property void windowCaption(string caption) {
_caption = caption;
const char * title = _caption.toStringz;
xcb_change_property (_xcbconnection,
XCB_PROP_MODE_REPLACE,
_w,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
cast(uint)_caption.length,
cast(void*)title);
}
void processExpose(xcb_expose_event_t * event) {
static xcb_rectangle_t r = { 20, 20, 60, 60 };
@ -95,7 +108,7 @@ class XCBPlatform : Platform {
_xcbconnection = null;
return false;
}
//XSetEventQueueOwner(display, XCBOwnsEventQueue);
Log.d("Getting first screen");
/* get the first screen */
_xcbscreen = xcb_setup_roots_iterator( xcb_get_setup(_xcbconnection) ).data;
@ -118,16 +131,87 @@ class XCBPlatform : Platform {
xcb_generic_event_t *e;
/* event loop */
do {
Log.v("waiting for event");
e = xcb_wait_for_event(_xcbconnection);
if (e is null) {
Log.w("NULL event received. Exiting message loop");
break;
}
switch (e.response_type & ~0x80) {
case XCB_CREATE_NOTIFY: {
xcb_create_notify_event_t *event = cast(xcb_create_notify_event_t *)e;
Log.i("XCB_CREATE_NOTIFY");
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_DESTROY_NOTIFY: {
xcb_destroy_notify_event_t *event = cast(xcb_destroy_notify_event_t *)e;
Log.i("XCB_DESTROY_NOTIFY");
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_MAP_NOTIFY: {
xcb_map_notify_event_t *event = cast(xcb_map_notify_event_t *)e;
Log.i("XCB_MAP_NOTIFY");
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_UNMAP_NOTIFY: {
xcb_unmap_notify_event_t *event = cast(xcb_unmap_notify_event_t *)e;
Log.i("XCB_UNMAP_NOTIFY");
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_VISIBILITY_NOTIFY: {
xcb_visibility_notify_event_t *event = cast(xcb_visibility_notify_event_t *)e;
Log.i("XCB_VISIBILITY_NOTIFY ", event.state);
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_REPARENT_NOTIFY: {
xcb_reparent_notify_event_t *event = cast(xcb_reparent_notify_event_t *)e;
Log.i("XCB_REPARENT_NOTIFY");
break;
}
case XCB_CONFIGURE_NOTIFY: {
xcb_configure_notify_event_t *event = cast(xcb_configure_notify_event_t *)e;
Log.i("XCB_CONFIGURE_NOTIFY ", event.width, "x", event.height);
XCBWindow window = getWindow(event.window);
if (window !is null) {
//
window.onResize(event.width, event.height);
} else {
Log.w("Received message for unknown window", event.window);
}
break;
}
case XCB_EXPOSE: { /* draw or redraw the window */
xcb_expose_event_t *expose = cast(xcb_expose_event_t *)e;
Log.i("expose event");
Log.i("XCB_EXPOSE");
XCBWindow window = getWindow(expose.window);
if (window !is null) {
window.processExpose(expose);
@ -177,6 +261,7 @@ class XCBPlatform : Platform {
break;
}
default:
Log.v("unknown event: ", e.response_type & ~0x80);
break;
}
free(e);
@ -210,3 +295,5 @@ int main(string[] args)
return res;
}
}