mirror of https://github.com/buggins/dlangui.git
XCB OpenGL support
This commit is contained in:
parent
6d180a7a1b
commit
1e39e2fdf6
|
@ -18,7 +18,7 @@ const int XlibSpecificationRelease=6;
|
|||
version = X_HAVE_UTF8_STRING;
|
||||
|
||||
alias XPointer = void*;
|
||||
typedef int Status ;
|
||||
alias Status = int;
|
||||
enum Bool:int{False,True}; //xlib boolean is int type, D bool is only byte
|
||||
enum QueueMode{QueuedAlready,QueuedAfterReading,QueuedAfterFlush};
|
||||
|
||||
|
@ -143,7 +143,7 @@ struct XGCValues
|
|||
byte dashes;
|
||||
};
|
||||
|
||||
typedef void* GC;
|
||||
alias GC = void*;
|
||||
|
||||
/*
|
||||
* Visual structure; contains information about colormapping possible.
|
||||
|
@ -462,7 +462,7 @@ struct Display
|
|||
/* there is more to this structure, but it is private to Xlib */
|
||||
}
|
||||
|
||||
typedef Display *_XPrivDisplay;
|
||||
alias _XPrivDisplay = Display *;
|
||||
struct XrmHashBucketRec{};
|
||||
|
||||
|
||||
|
@ -485,8 +485,8 @@ struct XKeyEvent
|
|||
uint keycode; /* detail */
|
||||
Bool same_screen; /* same screen flag */
|
||||
};
|
||||
typedef XKeyEvent XKeyPressedEvent;
|
||||
typedef XKeyEvent XKeyReleasedEvent;
|
||||
alias XKeyPressedEvent = XKeyEvent;
|
||||
alias XKeyReleasedEvent = XKeyEvent;
|
||||
|
||||
struct XButtonEvent
|
||||
{
|
||||
|
@ -504,8 +504,8 @@ struct XButtonEvent
|
|||
uint button; /* detail */
|
||||
Bool same_screen; /* same screen flag */
|
||||
};
|
||||
typedef XButtonEvent XButtonPressedEvent;
|
||||
typedef XButtonEvent XButtonReleasedEvent;
|
||||
alias XButtonPressedEvent = XButtonEvent;
|
||||
alias XButtonReleasedEvent = XButtonEvent;
|
||||
|
||||
struct XMotionEvent{
|
||||
int type; /* of event */
|
||||
|
@ -522,7 +522,7 @@ struct XMotionEvent{
|
|||
byte is_hint; /* detail */
|
||||
Bool same_screen; /* same screen flag */
|
||||
};
|
||||
typedef XMotionEvent XPointerMovedEvent;
|
||||
alias XPointerMovedEvent = XMotionEvent;
|
||||
|
||||
struct XCrossingEvent{
|
||||
int type; /* of event */
|
||||
|
@ -545,8 +545,8 @@ struct XCrossingEvent{
|
|||
Bool focus; /* Boolean focus */
|
||||
KeyOrButtonMask state; /* key or button mask */
|
||||
};
|
||||
typedef XCrossingEvent XEnterWindowEvent;
|
||||
typedef XCrossingEvent XLeaveWindowEvent;
|
||||
alias XEnterWindowEvent = XCrossingEvent ;
|
||||
alias XLeaveWindowEvent = XCrossingEvent ;
|
||||
|
||||
struct XFocusChangeEvent{
|
||||
int type; /* FocusIn or FocusOut */
|
||||
|
@ -563,8 +563,8 @@ struct XFocusChangeEvent{
|
|||
* NotifyPointerRoot, NotifyDetailNone
|
||||
*/
|
||||
};
|
||||
typedef XFocusChangeEvent XFocusInEvent;
|
||||
typedef XFocusChangeEvent XFocusOutEvent;
|
||||
alias XFocusInEvent = XFocusChangeEvent;
|
||||
alias XFocusOutEvent = XFocusChangeEvent;
|
||||
|
||||
/* generated on EnterWindow and FocusIn when KeyMapState selected */
|
||||
struct XKeymapEvent
|
||||
|
@ -1008,9 +1008,9 @@ typedef void (*XOMProc)();
|
|||
|
||||
struct _XOM{}
|
||||
struct _XOC{}
|
||||
typedef _XOM *XOM;
|
||||
typedef _XOC *XOC;
|
||||
typedef _XOC *XFontSet;
|
||||
alias XOM = _XOM *;
|
||||
alias XOC = _XOC *;
|
||||
alias XFontSet = _XOC *;
|
||||
struct XmbTextItem{
|
||||
byte *chars;
|
||||
int nchars;
|
||||
|
@ -1066,27 +1066,27 @@ struct XOMFontInfo{
|
|||
|
||||
struct _XIM{}
|
||||
struct _XIC{}
|
||||
typedef _XIM *XIM;
|
||||
typedef _XIC *XIC;
|
||||
alias XIM = _XIM *;
|
||||
alias XIC = _XIC *;
|
||||
|
||||
|
||||
typedef void function(
|
||||
alias XIMProc = void function(
|
||||
XIM,
|
||||
XPointer,
|
||||
XPointer
|
||||
) XIMProc;
|
||||
) ;
|
||||
|
||||
typedef Bool function(
|
||||
alias XICProc = Bool function(
|
||||
XIC,
|
||||
XPointer,
|
||||
XPointer
|
||||
)XICProc;
|
||||
);
|
||||
|
||||
typedef void function(
|
||||
alias XIDProc = void function(
|
||||
Display*,
|
||||
XPointer,
|
||||
XPointer
|
||||
)XIDProc;
|
||||
);
|
||||
|
||||
enum XIMStyle:ulong
|
||||
{
|
||||
|
@ -1157,7 +1157,7 @@ const int XLookupKeySym= 3;
|
|||
const int XLookupBoth = 4;
|
||||
|
||||
|
||||
typedef void *XVaNestedList;
|
||||
alias XVaNestedList = void *;
|
||||
|
||||
struct XIMCallback{
|
||||
XPointer client_data;
|
||||
|
@ -1232,7 +1232,7 @@ struct XIMStringConversionText {
|
|||
};
|
||||
};
|
||||
|
||||
typedef ushort XIMStringConversionPosition;
|
||||
alias XIMStringConversionPosition = ushort ;
|
||||
|
||||
enum XIMStringConversionType:ushort
|
||||
{
|
||||
|
@ -1753,19 +1753,19 @@ extern int XScreenNumberOfScreen(
|
|||
Screen* /* screen */
|
||||
);
|
||||
|
||||
typedef int function ( /* WARNING, this type not in Xlib spec */
|
||||
alias XErrorHandler = int function ( /* WARNING, this type not in Xlib spec */
|
||||
Display* /* display */,
|
||||
XErrorEvent* /* error_event */
|
||||
) XErrorHandler;
|
||||
);
|
||||
|
||||
extern XErrorHandler XSetErrorHandler (
|
||||
XErrorHandler /* handler */
|
||||
);
|
||||
|
||||
|
||||
typedef int function ( /* WARNING, this type not in Xlib spec */
|
||||
alias XIOErrorHandler = int function ( /* WARNING, this type not in Xlib spec */
|
||||
Display* /* display */
|
||||
) XIOErrorHandler;
|
||||
);
|
||||
|
||||
extern XIOErrorHandler XSetIOErrorHandler (
|
||||
XIOErrorHandler /* handler */
|
||||
|
@ -3876,13 +3876,13 @@ extern Bool XUnregisterIMInstantiateCallback(
|
|||
XPointer /* client_data */
|
||||
);
|
||||
|
||||
typedef void function(
|
||||
alias XConnectionWatchProc = void function(
|
||||
Display* /* dpy */,
|
||||
XPointer /* client_data */,
|
||||
int /* fd */,
|
||||
Bool /* opening */, /* open or close flag */
|
||||
XPointer* /* watch_data */ /* open sets, close uses */
|
||||
)XConnectionWatchProc;
|
||||
);
|
||||
|
||||
|
||||
extern Status XInternalConnectionNumbers(
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
<ObjectsDirectory>obj/Debug</ObjectsDirectory>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
<Target>StaticLibrary</Target>
|
||||
<ExtraCompilerArguments>-version=USE_OPENGL
|
||||
</ExtraCompilerArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
|
@ -171,6 +173,8 @@
|
|||
<Compile Include="..\DerelictFI\source\derelict\freeimage\types.d">
|
||||
<Link>3rdparty\DerelictFI\types.d</Link>
|
||||
</Compile>
|
||||
<Compile Include="3rdparty\X11\X.d" />
|
||||
<Compile Include="3rdparty\X11\Xlib.d" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="src\dlangui\platforms\x11\" />
|
||||
|
|
|
@ -8,6 +8,7 @@ version (linux) {
|
|||
pragma(lib, "xcb");
|
||||
pragma(lib, "xcb-shm");
|
||||
pragma(lib, "xcb-image");
|
||||
pragma(lib, "X11-xcb");
|
||||
pragma(lib, "X11");
|
||||
pragma(lib, "dl");
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,7 +20,20 @@ version(linux) {
|
|||
import dlangui.graphics.images;
|
||||
import dlangui.widgets.styles;
|
||||
import dlangui.platforms.common.platform;
|
||||
|
||||
|
||||
version (USE_OPENGL) {
|
||||
import dlangui.graphics.glsupport;
|
||||
}
|
||||
|
||||
import derelict.opengl3.gl3;
|
||||
import derelict.opengl3.glx;
|
||||
|
||||
extern (System)
|
||||
xcb_connection_t *XGetXCBConnection(std.c.linux.X11.Xlib.Display *dpy);
|
||||
enum XEventQueueOwner { XlibOwnsEventQueue = 0, XCBOwnsEventQueue };
|
||||
extern (System)
|
||||
void XSetEventQueueOwner(std.c.linux.X11.Xlib.Display *dpy, XEventQueueOwner owner);
|
||||
|
||||
class XCBWindow : Window {
|
||||
xcb_window_t _w;
|
||||
xcb_gcontext_t _g;
|
||||
|
@ -298,9 +311,12 @@ version(linux) {
|
|||
private __gshared xcb_connection_t * _xcbconnection;
|
||||
private __gshared xcb_screen_t * _xcbscreen;
|
||||
private __gshared ubyte _xcbscreendepth;
|
||||
private __gshared bool _enableOpengl;
|
||||
private __gshared std.c.linux.X11.Xlib.Display * _display;
|
||||
|
||||
class XCBPlatform : Platform {
|
||||
this() {
|
||||
|
||||
}
|
||||
~this() {
|
||||
foreach(ref XCBWindow wnd; _windowMap) {
|
||||
|
@ -311,15 +327,62 @@ version(linux) {
|
|||
disconnect();
|
||||
}
|
||||
void disconnect() {
|
||||
if (_xcbconnection) {
|
||||
/* Cleanup */
|
||||
if (_display) {
|
||||
Log.d("Closing X display");
|
||||
std.c.linux.X11.Xlib.XCloseDisplay(_display);
|
||||
_display = null;
|
||||
} else if (_xcbconnection) {
|
||||
Log.d("Closing XCB connection");
|
||||
/* close connection to server */
|
||||
xcb_disconnect(_xcbconnection);
|
||||
_xcbconnection = null;
|
||||
}
|
||||
}
|
||||
bool connect() {
|
||||
Log.d("Opening connection");
|
||||
/* open connection with the server */
|
||||
_xcbconnection = xcb_connect(null,null);
|
||||
|
||||
try {
|
||||
DerelictGL3.load();
|
||||
_enableOpengl = true;
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot load opengl library", e);
|
||||
}
|
||||
// X
|
||||
import std.c.linux.X11.Xlib;
|
||||
int default_screen;
|
||||
|
||||
if (_enableOpengl) {
|
||||
Log.d("Opening display via XLib");
|
||||
/* Open Xlib Display */
|
||||
_display = XOpenDisplay(null);
|
||||
if (!_display)
|
||||
{
|
||||
Log.e("Failed to open display using Xlib");
|
||||
_enableOpengl = false;
|
||||
} else {
|
||||
// display is opened
|
||||
default_screen = DefaultScreen(_display);
|
||||
Log.d("Opened display =");
|
||||
/* Get the XCB connection from the display */
|
||||
_xcbconnection = XGetXCBConnection(_display);
|
||||
if (!_xcbconnection)
|
||||
{
|
||||
XCloseDisplay(_display);
|
||||
_display = null;
|
||||
Log.e("Failed to get XCB connection from Xlib display");
|
||||
_enableOpengl = false;
|
||||
} else {
|
||||
/* Acquire event queue ownership */
|
||||
XSetEventQueueOwner(_display, XEventQueueOwner.XCBOwnsEventQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_xcbconnection is null) {
|
||||
Log.d("Opening XCB connection");
|
||||
/* open connection with the server */
|
||||
_xcbconnection = xcb_connect(null,null);
|
||||
}
|
||||
if (xcb_connection_has_error(_xcbconnection)) {
|
||||
Log.e("Cannot open display");
|
||||
_xcbconnection = null;
|
||||
|
@ -328,9 +391,21 @@ version(linux) {
|
|||
//XSetEventQueueOwner(display, XCBOwnsEventQueue);
|
||||
Log.d("Getting first screen");
|
||||
/* get the first screen */
|
||||
_xcbscreen = xcb_setup_roots_iterator( xcb_get_setup(_xcbconnection) ).data;
|
||||
_xcbscreendepth = xcb_aux_get_depth(_xcbconnection, _xcbscreen);
|
||||
|
||||
|
||||
if (_enableOpengl) {
|
||||
/* Find XCB screen */
|
||||
//xcb_screen_t *screen = null;
|
||||
xcb_screen_iterator_t screen_iter =
|
||||
xcb_setup_roots_iterator(xcb_get_setup(_xcbconnection));
|
||||
for(int screen_num = default_screen;
|
||||
screen_iter.rem && screen_num > 0;
|
||||
--screen_num, xcb_screen_next(&screen_iter)) {
|
||||
}
|
||||
_xcbscreen = screen_iter.data;
|
||||
} else {
|
||||
_xcbscreen = xcb_setup_roots_iterator( xcb_get_setup(_xcbconnection) ).data;
|
||||
}
|
||||
_xcbscreendepth = xcb_aux_get_depth(_xcbconnection, _xcbscreen);
|
||||
return true;
|
||||
}
|
||||
XCBWindow getWindow(xcb_window_t w) {
|
||||
|
|
Loading…
Reference in New Issue