summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Marchesin <marchesin@icps.u-strasbg.fr>2010-04-23 12:29:46 -0700
committerStephane Marchesin <marchesin@icps.u-strasbg.fr>2010-04-23 12:29:46 -0700
commitf0aafcf5cb1f4aedb9c89ca13705bab4556aebb0 (patch)
tree23f79c3792d32517eb19017a79c3d37e6152cda8
Import Xenon sources.
-rw-r--r--CMakeLists.txt6
-rw-r--r--Makefile262
-rw-r--r--display.c42
-rw-r--r--display.h2
-rw-r--r--drawable.c12
-rw-r--r--init.c15
-rw-r--r--init.h2
-rw-r--r--render.c112
-rw-r--r--render.h11
-rw-r--r--screen.c6
-rw-r--r--screen.h4
-rw-r--r--tests/.rect.c.swpbin0 -> 12288 bytes
-rwxr-xr-xtests/buildall3
-rw-r--r--tests/hello-x.c39
-rw-r--r--tests/mapwin.c19
-rw-r--r--tests/openclosedisplay.c20
-rw-r--r--tests/rect.c42
-rw-r--r--tests/xlib-beginner.c59
-rw-r--r--window.c45
-rw-r--r--window.h4
-rw-r--r--xenon.h7
-rw-r--r--xlib_api.c171
22 files changed, 883 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..530950f
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.4)
+link_libraries(dl)
+set(CMAKE_C_FLAGS "-Wall -march=native -O2")
+add_library (X11 SHARED display.c drawable.c init.c render.c screen.c window.c xlib_api.c)
+
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..43bf3d8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,262 @@
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 2.6
+
+# Default target executed when no arguments are given to make.
+default_target: all
+.PHONY : default_target
+
+#=============================================================================
+# Special targets provided by cmake.
+
+# Disable implicit rules so canoncical targets will work.
+.SUFFIXES:
+
+# Remove some rules from gmake that .SUFFIXES does not remove.
+SUFFIXES =
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+# Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/bin/cmake
+
+# The command to remove a file.
+RM = /usr/bin/cmake -E remove -f
+
+# The program to use to edit the cache.
+CMAKE_EDIT_COMMAND = /usr/bin/ccmake
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /home/steph/boulot/xenon
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /home/steph/boulot/xenon
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
+ /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+.PHONY : edit_cache/fast
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+.PHONY : rebuild_cache/fast
+
+# The main all target
+all: cmake_check_build_system
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/steph/boulot/xenon/CMakeFiles /home/steph/boulot/xenon/CMakeFiles/progress.make
+ $(MAKE) -f CMakeFiles/Makefile2 all
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/steph/boulot/xenon/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ $(MAKE) -f CMakeFiles/Makefile2 clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+#=============================================================================
+# Target rules for targets named X11
+
+# Build rule for target.
+X11: cmake_check_build_system
+ $(MAKE) -f CMakeFiles/Makefile2 X11
+.PHONY : X11
+
+# fast build rule for target.
+X11/fast:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/build
+.PHONY : X11/fast
+
+# target to build an object file
+display.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/display.o
+.PHONY : display.o
+
+# target to preprocess a source file
+display.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/display.i
+.PHONY : display.i
+
+# target to generate assembly for a file
+display.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/display.s
+.PHONY : display.s
+
+# target to build an object file
+drawable.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/drawable.o
+.PHONY : drawable.o
+
+# target to preprocess a source file
+drawable.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/drawable.i
+.PHONY : drawable.i
+
+# target to generate assembly for a file
+drawable.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/drawable.s
+.PHONY : drawable.s
+
+# target to build an object file
+init.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/init.o
+.PHONY : init.o
+
+# target to preprocess a source file
+init.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/init.i
+.PHONY : init.i
+
+# target to generate assembly for a file
+init.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/init.s
+.PHONY : init.s
+
+# target to build an object file
+render.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/render.o
+.PHONY : render.o
+
+# target to preprocess a source file
+render.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/render.i
+.PHONY : render.i
+
+# target to generate assembly for a file
+render.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/render.s
+.PHONY : render.s
+
+# target to build an object file
+screen.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/screen.o
+.PHONY : screen.o
+
+# target to preprocess a source file
+screen.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/screen.i
+.PHONY : screen.i
+
+# target to generate assembly for a file
+screen.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/screen.s
+.PHONY : screen.s
+
+# target to build an object file
+window.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/window.o
+.PHONY : window.o
+
+# target to preprocess a source file
+window.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/window.i
+.PHONY : window.i
+
+# target to generate assembly for a file
+window.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/window.s
+.PHONY : window.s
+
+# target to build an object file
+xlib_api.o:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/xlib_api.o
+.PHONY : xlib_api.o
+
+# target to preprocess a source file
+xlib_api.i:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/xlib_api.i
+.PHONY : xlib_api.i
+
+# target to generate assembly for a file
+xlib_api.s:
+ $(MAKE) -f CMakeFiles/X11.dir/build.make CMakeFiles/X11.dir/xlib_api.s
+.PHONY : xlib_api.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... X11"
+ @echo "... edit_cache"
+ @echo "... rebuild_cache"
+ @echo "... display.o"
+ @echo "... display.i"
+ @echo "... display.s"
+ @echo "... drawable.o"
+ @echo "... drawable.i"
+ @echo "... drawable.s"
+ @echo "... init.o"
+ @echo "... init.i"
+ @echo "... init.s"
+ @echo "... render.o"
+ @echo "... render.i"
+ @echo "... render.s"
+ @echo "... screen.o"
+ @echo "... screen.i"
+ @echo "... screen.s"
+ @echo "... window.o"
+ @echo "... window.i"
+ @echo "... window.s"
+ @echo "... xlib_api.o"
+ @echo "... xlib_api.i"
+ @echo "... xlib_api.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
+
diff --git a/display.c b/display.c
new file mode 100644
index 0000000..f58e42d
--- /dev/null
+++ b/display.c
@@ -0,0 +1,42 @@
+#include "xenon.h"
+#include "screen.h"
+
+typedef struct xenon_display
+{
+ char* name;
+ Display* display;
+ struct xenon_display* next;
+}
+xenon_display;
+
+static xenon_display* display_list = NULL;
+
+xenon_display* display_create()
+{
+ xenon_display* new_display = (xenon_display*) malloc ( sizeof(xenon_display) );
+ Display* new_Display = (Display*) malloc ( sizeof(Display) );
+ new_Display -> nscreens = 1;
+ new_Display -> screens = &screen;
+
+ new_display -> next = display_list;
+ new_display -> display = (Display*)new_Display;
+
+ display_list = new_display;
+
+ return new_display;
+}
+
+Display* display_find(const char* name)
+{
+ xenon_display* d = display_list;
+ if (name)
+ while(d)
+ {
+ if (!strcmp(name,d->name))
+ return d->display;
+ d = d->next;
+ }
+
+ return display_create()->display;
+}
+
diff --git a/display.h b/display.h
new file mode 100644
index 0000000..f02354e
--- /dev/null
+++ b/display.h
@@ -0,0 +1,2 @@
+extern Display* display_find(const char* name);
+
diff --git a/drawable.c b/drawable.c
new file mode 100644
index 0000000..4691ca4
--- /dev/null
+++ b/drawable.c
@@ -0,0 +1,12 @@
+#include <X11/Xlib.h>
+#include <string.h>
+
+typedef struct xenon_window
+{
+ Window window;
+ struct xenon_window* next;
+}
+xenon_window;
+
+
+
diff --git a/init.c b/init.c
new file mode 100644
index 0000000..ad86034
--- /dev/null
+++ b/init.c
@@ -0,0 +1,15 @@
+
+#include "xenon.h"
+#include "screen.h"
+#include "render.h"
+
+int init_done = 0;
+
+void __attribute__ ((constructor)) init()
+{
+ screen.width = 640;
+ screen.height = 480;
+ render_init(screen.width, screen.height);
+ init_done = 1;
+}
+
diff --git a/init.h b/init.h
new file mode 100644
index 0000000..139597f
--- /dev/null
+++ b/init.h
@@ -0,0 +1,2 @@
+
+
diff --git a/render.c b/render.c
new file mode 100644
index 0000000..8388f30
--- /dev/null
+++ b/render.c
@@ -0,0 +1,112 @@
+
+#include <dlfcn.h>
+#include "xenon.h"
+#include "render.h"
+#include <GL/glx.h>
+
+unsigned char* pixels;
+static xenon_rect screen_rect;
+
+typedef struct xenon_libX11
+{
+ void* handle;
+ int (*XFlush)(Display*);
+ Display* (*XOpenDisplay)(const char*);
+ Colormap (*XCreateColormap)(Display*, Window, Visual*, int);
+ Window (*XCreateWindow)(Display*, Window, int, int, unsigned int, unsigned int, unsigned int, int, unsigned int, Visual*, unsigned long, XSetWindowAttributes*);
+ int (*XMapRaised)(Display*, Window);
+}
+xenon_libX11;
+
+static xenon_libX11 libX11;
+
+typedef struct xenon_libGL
+{
+ void* handle;
+ XVisualInfo* (*glXChooseVisual) (Display*, int, int*);
+ GLXContext (*glXCreateContext) (Display*, XVisualInfo*, GLXContext, Bool);
+ Bool (*glXMakeCurrent) (Display*, GLXDrawable, GLXContext );
+ void (*glDrawPixels) (GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
+ void (*glRasterPos2i) (GLint, GLint);
+ void (*glViewport) (GLint, GLint, GLsizei, GLsizei);
+ void (*glMatrixMode) (GLenum);
+ void (*glLoadIdentity) (void);
+ void (*glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
+}
+xenon_libGL;
+
+static xenon_libGL libGL;
+
+static void render_init_libs()
+{
+ libX11.handle = dlopen("/usr/lib64/libX11.so.6", RTLD_LAZY);
+ if (!libX11.handle)
+ libX11.handle = dlopen("/usr/lib/libX11.so.6", RTLD_LAZY);
+ if (!libX11.handle)
+ printf("can't open libX11\n");
+ libX11.XFlush = dlsym(libX11.handle, "XFlush");
+ libX11.XOpenDisplay = dlsym(libX11.handle, "XOpenDisplay");
+ libX11.XCreateColormap = dlsym(libX11.handle, "XCreateColormap");
+ libX11.XCreateWindow = dlsym(libX11.handle, "XCreateWindow");
+ libX11.XMapRaised = dlsym(libX11.handle, "XMapRaised");
+
+ libGL.handle = dlopen("/usr/lib64/libGL.so", RTLD_LAZY);
+ if (!libGL.handle)
+ libGL.handle = dlopen("/usr/lib/libGL.so", RTLD_LAZY);
+ if (!libGL.handle)
+ printf("can't open libGL\n");
+ libGL.glXChooseVisual = dlsym(libGL.handle, "glXChooseVisual");
+ libGL.glXCreateContext = dlsym(libGL.handle, "glXCreateContext");
+ libGL.glXMakeCurrent = dlsym(libGL.handle, "glXMakeCurrent");
+ libGL.glDrawPixels = dlsym(libGL.handle, "glDrawPixels");
+ libGL.glRasterPos2i = dlsym(libGL.handle, "glRasterPos2i");
+ libGL.glViewport = dlsym(libGL.handle, "glViewport");
+ libGL.glMatrixMode = dlsym(libGL.handle, "glMatrixMode");
+ libGL.glLoadIdentity = dlsym(libGL.handle, "glLoadIdentity");
+ libGL.glOrtho = dlsym(libGL.handle, "glOrtho");
+}
+
+void render_init(int w, int h)
+{
+ render_init_libs();
+
+ Display* dpy = libX11.XOpenDisplay(0);
+
+ int screen = DefaultScreen(dpy);
+ GLint glxattr[] = {GLX_RGBA, None};
+ XVisualInfo* vi = libGL.glXChooseVisual(dpy, screen, glxattr);
+
+ GLXContext ctx = libGL.glXCreateContext(dpy, vi, 0, GL_TRUE);
+
+ XSetWindowAttributes attr;
+ attr.colormap = libX11.XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
+ attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask;
+ Window win = libX11.XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, w, h, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &attr);
+
+ libX11.XMapRaised(dpy, win);
+
+ libGL.glXMakeCurrent(dpy, win, ctx);
+
+ libGL.glViewport(0, 0, w, h);
+ libGL.glMatrixMode( GL_PROJECTION );
+ libGL.glLoadIdentity();
+ libGL.glOrtho(0.0, (GLfloat)w, 0.0, (GLfloat)h, 0.0, 2.0);
+ libGL.glMatrixMode( GL_MODELVIEW );
+ libGL.glLoadIdentity();
+
+ screen_rect.x = 0;
+ screen_rect.y = 0;
+ screen_rect.w = w;
+ screen_rect.h = h;
+
+ pixels = (unsigned char*) calloc (1, w * h * 4);
+
+ render_update(screen_rect);
+}
+
+void render_update(xenon_rect r)
+{
+ libGL.glRasterPos2i(r.x, r.y);
+ libGL.glDrawPixels(r.w, r.h, GL_RGBA, GL_UNSIGNED_BYTE, pixels + (r.x + r.y * screen_rect.w) * 4 );
+}
+
diff --git a/render.h b/render.h
new file mode 100644
index 0000000..9a924de
--- /dev/null
+++ b/render.h
@@ -0,0 +1,11 @@
+
+typedef struct xenon_rect
+{
+ int x, y;
+ int w, h;
+}
+xenon_rect;
+
+extern void render_init(int w, int h);
+extern void render_update(xenon_rect r);
+
diff --git a/screen.c b/screen.c
new file mode 100644
index 0000000..339472d
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,6 @@
+#include "xenon.h"
+
+Screen screen;
+
+
+
diff --git a/screen.h b/screen.h
new file mode 100644
index 0000000..779fcbd
--- /dev/null
+++ b/screen.h
@@ -0,0 +1,4 @@
+#include "xenon.h"
+
+extern Screen screen;
+
diff --git a/tests/.rect.c.swp b/tests/.rect.c.swp
new file mode 100644
index 0000000..141eb94
--- /dev/null
+++ b/tests/.rect.c.swp
Binary files differ
diff --git a/tests/buildall b/tests/buildall
new file mode 100755
index 0000000..a6b38f8
--- /dev/null
+++ b/tests/buildall
@@ -0,0 +1,3 @@
+#!/bin/sh
+for i in *.c ; do gcc -O2 -lX11 $i -o ${i%.c} ; done
+
diff --git a/tests/hello-x.c b/tests/hello-x.c
new file mode 100644
index 0000000..3b276a6
--- /dev/null
+++ b/tests/hello-x.c
@@ -0,0 +1,39 @@
+#include <X11/Xlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void) {
+ Display *d;
+ Window w;
+ XEvent e;
+ char *msg = "Hello, World!";
+ int s;
+
+ d = XOpenDisplay(NULL);
+ if (d == NULL) {
+ fprintf(stderr, "Cannot open display\n");
+ exit(1);
+ }
+
+ s = DefaultScreen(d);
+ w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
+ BlackPixel(d, s), WhitePixel(d, s));
+ XSelectInput(d, w, ExposureMask | KeyPressMask);
+ XMapWindow(d, w);
+
+ while (1) {
+ XNextEvent(d, &e);
+ if (e.type == Expose) {
+ XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
+ XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
+ }
+ if (e.type == KeyPress)
+ break;
+ }
+
+ XCloseDisplay(d);
+ return 0;
+}
+
+
diff --git a/tests/mapwin.c b/tests/mapwin.c
new file mode 100644
index 0000000..01c556b
--- /dev/null
+++ b/tests/mapwin.c
@@ -0,0 +1,19 @@
+#include <X11/Xlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+
+int main() {
+ Display* dis = XOpenDisplay(NULL);
+ Window win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, \
+ 0, BlackPixel (dis, 0), BlackPixel(dis, 0));
+ XMapWindow(dis, win);
+ XFlush(dis);
+ /*Sleep 5 seconds before closing.*/
+ sleep(5);
+ return(0);
+}
+
+
diff --git a/tests/openclosedisplay.c b/tests/openclosedisplay.c
new file mode 100644
index 0000000..4b50ce1
--- /dev/null
+++ b/tests/openclosedisplay.c
@@ -0,0 +1,20 @@
+#include <X11/Xlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(void) {
+ Display *d;
+
+ d = XOpenDisplay(NULL);
+ if (d == NULL) {
+ printf("Cannot open display\n");
+ exit(1);
+ }
+
+ XCloseDisplay(d);
+ printf("ok\n");
+ return 0;
+}
+
+
diff --git a/tests/rect.c b/tests/rect.c
new file mode 100644
index 0000000..db66834
--- /dev/null
+++ b/tests/rect.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+/*Linux users will need to add -ldl to the Makefile to compile
+ *this example.
+ */
+Display *dis;
+Window win;
+XEvent report;
+GC green_gc;
+XColor green_col;
+Colormap colormap;
+/*
+Try changing the green[] = below to a different color.
+The color can also be from /usr/X11R6/lib/X11/rgb.txt, such as RoyalBlue4.
+A # (number sign) is only needed when using hexadecimal colors.
+*/
+char green[] = "#00FF00";
+
+int main() {
+ dis = XOpenDisplay(NULL);
+ win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 250, 250, 0, BlackPixel (dis, 0), BlackPixel(dis, 0));
+ XMapWindow(dis, win);
+ colormap = DefaultColormap(dis, 0);
+ green_gc = XCreateGC(dis, win, 0, 0);
+ XParseColor(dis, colormap, green, &green_col);
+ XAllocColor(dis, colormap, &green_col);
+ XSetForeground(dis, green_gc, green_col.pixel);
+
+ XSelectInput(dis, win, ExposureMask | KeyPressMask | ButtonPressMask);
+
+ XDrawRectangle(dis, win, green_gc, 1, 1, 247, 247);
+ XDrawRectangle(dis, win, green_gc, 50, 50, 148, 148);
+ XFlush(dis);
+
+ sleep(5);
+ return 0;
+}
diff --git a/tests/xlib-beginner.c b/tests/xlib-beginner.c
new file mode 100644
index 0000000..b31a148
--- /dev/null
+++ b/tests/xlib-beginner.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+/*Linux users will need to add -ldl to the Makefile to compile
+ *this example.
+ */
+Display *dis;
+Window win;
+XEvent report;
+GC green_gc;
+XColor green_col;
+Colormap colormap;
+/*
+Try changing the green[] = below to a different color.
+The color can also be from /usr/X11R6/lib/X11/rgb.txt, such as RoyalBlue4.
+A # (number sign) is only needed when using hexadecimal colors.
+*/
+char green[] = "#00FF00";
+
+int main() {
+ dis = XOpenDisplay(NULL);
+ win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, 0, BlackPixel (dis, 0), BlackPixel(dis, 0));
+ XMapWindow(dis, win);
+ colormap = DefaultColormap(dis, 0);
+ green_gc = XCreateGC(dis, win, 0, 0);
+ XParseColor(dis, colormap, green, &green_col);
+ XAllocColor(dis, colormap, &green_col);
+ XSetForeground(dis, green_gc, green_col.pixel);
+
+ XSelectInput(dis, win, ExposureMask | KeyPressMask | ButtonPressMask);
+
+ XDrawRectangle(dis, win, green_gc, 1, 1, 497, 497);
+ XDrawRectangle(dis, win, green_gc, 50, 50, 398, 398);
+ XFlush(dis);
+
+ while (1) {
+ XNextEvent(dis, &report);
+ switch (report.type) {
+ case Expose:
+ fprintf(stdout, "I have been exposed.\n");
+ XDrawRectangle(dis, win, green_gc, 1, 1, 497, 497);
+ XDrawRectangle(dis, win, green_gc, 50, 50, 398, 398);
+ XFlush(dis);
+ break;
+ case KeyPress:
+ /*Close the program if q is pressed.*/
+ if (XLookupKeysym(&report.xkey, 0) == XK_q) {
+ exit(0);
+ }
+ break;
+ }
+ }
+
+return 0;
+}
diff --git a/window.c b/window.c
new file mode 100644
index 0000000..a78be77
--- /dev/null
+++ b/window.c
@@ -0,0 +1,45 @@
+#include <X11/Xlib.h>
+#include <string.h>
+
+typedef struct xenon_window
+{
+ Window window;
+ struct xenon_window* next;
+}
+xenon_window;
+
+static xenon_window* window_list = NULL;
+
+Window window_create()
+{
+ xenon_window* new_window = (xenon_window*) malloc ( sizeof(xenon_window) );
+ new_window -> next = window_list;
+ window_list = new_window;
+ return new_window->window;
+}
+
+xenon_window* window_find(Window wid)
+{
+ xenon_window* w = window_list;
+ while(w)
+ {
+ if (w->window == wid)
+ return w;
+ w = w->next;
+ }
+ return NULL;
+}
+
+void window_resize(Window w, int width, int height)
+{
+ xenon_window* xw = window_find(w);
+
+}
+
+void window_move(Window w, int posx, int posy)
+{
+ xenon_window* xw = window_find(w);
+
+}
+
+
diff --git a/window.h b/window.h
new file mode 100644
index 0000000..183bdf3
--- /dev/null
+++ b/window.h
@@ -0,0 +1,4 @@
+extern Window window_create();
+extern void window_resize(Window w, int width, int height);
+extern void window_move(Window w, int posx, int posy);
+
diff --git a/xenon.h b/xenon.h
new file mode 100644
index 0000000..c7d1b11
--- /dev/null
+++ b/xenon.h
@@ -0,0 +1,7 @@
+#define XLIB_ILLEGAL_ACCESS
+#include <X11/Xlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
diff --git a/xlib_api.c b/xlib_api.c
new file mode 100644
index 0000000..990a748
--- /dev/null
+++ b/xlib_api.c
@@ -0,0 +1,171 @@
+#include <dlfcn.h>
+#include "xenon.h"
+#include "window.h"
+#include "display.h"
+
+Status XAllocColor(
+ Display* display,
+ Colormap colormap,
+ XColor* screen_in_out
+)
+{
+}
+
+int XCloseDisplay(
+ Display* display
+)
+{
+ printf("close display ok\n");
+}
+
+
+GC XCreateGC(
+ Display* display,
+ Drawable d,
+ unsigned long valuemask,
+ XGCValues* values
+)
+{
+ // XXX init hack, remove when the renderer is changed to gallium
+ extern int init_done;
+ if (!init_done)
+ {
+ void* handle;
+ handle = dlopen("/usr/lib64/libX11.so.6", RTLD_LAZY);
+ if (!handle)
+ handle = dlopen("/usr/lib/libX11.so.6", RTLD_LAZY);
+ if (!handle)
+ printf("can't open libX11\n");
+ typedef GC (* XCreateGCfunc) (Display*, Drawable,unsigned long, XGCValues*);
+ XCreateGCfunc XCreateGCreal = dlsym(handle, "XCreateGC");
+ return XCreateGCreal(display, d, valuemask, values);
+ }
+
+ printf("create GC ok\n");
+}
+
+Window XCreateSimpleWindow(
+ Display* display,
+ Window parent,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height,
+ unsigned int border_width,
+ unsigned long border,
+ unsigned long background
+)
+{
+ Window wid = window_create();
+ window_resize(wid, width, height);
+ window_move(wid, x, y);
+ printf("simple window ok\n");
+ return wid;
+}
+
+int XDrawRectangle(
+ Display* display,
+ Drawable d,
+ GC gc,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height
+)
+{
+ printf("draw rectangle ok\n");
+}
+
+int XDrawString(
+ Display* display,
+ Drawable d,
+ GC gc,
+ int x,
+ int y,
+ _Xconst char* string,
+ int length
+)
+{
+ printf("draw string ok\n");
+}
+
+int XFillRectangle(
+ Display* display,
+ Drawable d,
+ GC gc,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height
+)
+{
+ printf("fill rectangle ok\n");
+}
+
+int XFlush(
+ Display* display
+)
+{
+ printf("flush ok\n");
+ // XXX here call render_update
+}
+
+void XFlushGC(
+ Display* display,
+ GC gc
+)
+{
+ XFlush(display);
+}
+
+int XMapWindow(
+ Display* display,
+ Window w
+)
+{
+ printf("map window ok\n");
+
+}
+
+int XNextEvent(
+ Display* display,
+ XEvent* event_return
+)
+{
+}
+
+Display *XOpenDisplay(
+ _Xconst char* name /* display_name */
+)
+{
+ Display* r = display_find(name);
+ printf("open display ok\n");
+ return r;
+}
+
+Status XParseColor(
+ Display* display,
+ Colormap colormap,
+ _Xconst char* spec,
+ XColor* exact_def_return
+)
+{
+}
+
+int XSelectInput(
+ Display* display,
+ Window w,
+ long event_mask
+)
+{
+}
+
+int XSetForeground(
+ Display* display,
+ GC gc,
+ unsigned long foreground
+)
+{
+}
+
+