diff --git a/Rsconscript b/Rsconscript index 0999d1c..2758a02 100644 --- a/Rsconscript +++ b/Rsconscript @@ -4,6 +4,7 @@ end build do main_env = Rscons::Environment.new do |env| + env["LIBS"] += %w[X11 GLX] env["sources"] = glob("src/**/*.{c,d}") env["D_IMPORT_PATH"] += glob("src/**") env.Program("jes", "${sources}") diff --git a/src/gui/jtk.d b/src/gui/jtk.d deleted file mode 100644 index ef537f4..0000000 --- a/src/gui/jtk.d +++ /dev/null @@ -1,53 +0,0 @@ -struct Event -{ - enum Type : ubyte - { - WINDOW_CLOSE, - WINDOW_EXPOSE, - KEY_PRESS, - KEY_RELEASE, - BUTTON_PRESS, - BUTTON_RELEASE, - TIMER, - WINDOW_RESIZE, - }; - - struct KeyEvent - { - bool repeat; - uint key; - uint x_keycode; - }; - - struct ButtonEvent - { - uint mods; - ubyte button; - }; - - struct TimerEvent - { - uint timer_id; - void * user1; - void * user2; - }; - - struct WindowResizeEvent - { - uint width; - uint height; - }; - - Type type; - union - { - KeyEvent key; - ButtonEvent button; - TimerEvent timer; - WindowResizeEvent resize; - }; -} - -class Window -{ -} diff --git a/src/jes/gui/jtk.c b/src/jes/gui/jtk.c new file mode 100644 index 0000000..8d0930f --- /dev/null +++ b/src/jes/gui/jtk.c @@ -0,0 +1,54 @@ +#include +#include +#include + +static Display * g_display; +static XVisualInfo * g_vi; +static XSetWindowAttributes g_swa; +static GLXContext g_context; + +/** + * Initialize the Jtk subsystem. + * + * @return true on success, false on failure + */ +bool jtk_init() +{ + static int glx_attribute_list[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER, + None, + }; + + g_display = XOpenDisplay(NULL); + if (g_display == NULL) + { + fprintf(stderr, "XOpenDisplay() failure\n"); + return false; + } + + g_vi = glXChooseVisual(g_display, DefaultScreen(g_display), + glx_attribute_list); + if (g_vi == NULL) + { + fprintf(stderr, "glXChooseVisual() failure\n"); + return false; + } + + g_context = glXCreateContext(g_display, g_vi, NULL, True); + if (g_context == NULL) + { + fprintf(stderr, "glXCreateContext() failure\n"); + return false; + } + + Colormap colormap = XCreateColormap(g_display, + RootWindow(g_display, g_vi->screen), g_vi->visual, AllocNone); + g_swa.colormap = colormap; + g_swa.border_pixel = 0; + g_swa.event_mask = StructureNotifyMask | + KeyPressMask | KeyReleaseMask | + ButtonPressMask | ButtonReleaseMask; + + return true; +} diff --git a/src/jes/gui/jtk.d b/src/jes/gui/jtk.d new file mode 100644 index 0000000..81f6d51 --- /dev/null +++ b/src/jes/gui/jtk.d @@ -0,0 +1,68 @@ +private extern(C) bool jtk_init(); + +struct Jtk +{ + struct Event + { + enum Type : ubyte + { + WINDOW_CLOSE, + WINDOW_EXPOSE, + KEY_PRESS, + KEY_RELEASE, + BUTTON_PRESS, + BUTTON_RELEASE, + TIMER, + WINDOW_RESIZE, + }; + + struct KeyEvent + { + bool repeat; + uint key; + uint x_keycode; + }; + + struct ButtonEvent + { + uint mods; + ubyte button; + }; + + struct TimerEvent + { + uint timer_id; + void * user1; + void * user2; + }; + + struct WindowResizeEvent + { + uint width; + uint height; + }; + + Type type; + union + { + KeyEvent key; + ButtonEvent button; + TimerEvent timer; + WindowResizeEvent resize; + }; + } + + class Window + { + } + + static bool init() + { + if (!jtk_init()) + { + return false; + } + + return true; + } +} diff --git a/src/main.d b/src/main.d index 5f69c53..b59782f 100644 --- a/src/main.d +++ b/src/main.d @@ -1,4 +1,7 @@ +import jes.gui.jtk; + int main(string[] args) { + Jtk.init(); return 0; }