#include "ui.h"
#include "config.h"
-struct XConf X;
+XConf X;
static Bool Has_Error = False;
static XErrorEvent Error = {0};
return 0;
}
-int X11_Init(XConf* x)
+static void xkeypress(XEvent* e)
+{}
+
+static void xmousebtn(XEvent* e)
+{}
+
+static void xbtnmotion(XEvent* e)
+{}
+
+static void xclientmsg(XEvent* e)
+{}
+
+static void xresize(XEvent* e)
+{}
+
+static void xmapnotify(XEvent* e)
+{}
+
+static void xenternotify(XEvent* e)
+{}
+
+int X11_Init(void)
{
int ret = -1;
-// signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
-// setlocale(LC_CTYPE, "");
-// XSetLocaleModifiers("");
+ signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
+ setlocale(LC_CTYPE, "");
+ XSetLocaleModifiers("");
/* open the X display and get basic attributes */
- if ( (x->display = XOpenDisplay(0)) )
+ if ( (X.display = XOpenDisplay(0)) )
{
- x->root = DefaultRootWindow(x->display);
+ X.root = DefaultRootWindow(X.display);
XWindowAttributes wa;
- XGetWindowAttributes(x->display, x->root, &wa);
- x->visual = wa.visual;
- x->colormap = wa.colormap;
- x->screen = DefaultScreen(x->display);
- x->depth = DefaultDepth(x->display, x->screen);
- x->state = RUNNING;
+ XGetWindowAttributes(X.display, X.root, &wa);
+ X.visual = wa.visual;
+ X.colormap = wa.colormap;
+ X.screen = DefaultScreen(X.display);
+ X.depth = DefaultDepth(X.display, X.screen);
+ X.state = RUNNING;
XSetErrorHandler(onerror);
+
+ /* register event handlers */
+ X.eventfns[KeyPress] = xkeypress;
+ X.eventfns[ButtonPress] = xmousebtn;
+ X.eventfns[ButtonRelease] = xmousebtn;
+ X.eventfns[MotionNotify] = xbtnmotion;
+ X.eventfns[ClientMessage] = xclientmsg;
+ X.eventfns[ConfigureNotify] = xresize;
+ X.eventfns[MapNotify] = xmapnotify;
+ X.eventfns[EnterNotify] = xenternotify;
ret = 0;
}
+
return ret;
}
return (Has_Error ? &Error : NULL);
}
-void X11_MakeWindow(XConf* x, XWindow* win, int width, int height)
+void X11_MakeWindow(XWindow* win, int width, int height)
{
/* create the main window */
XSetWindowAttributes attr;
win->width = width;
win->height = height;
win->winid = XCreateWindow(
- x->display, x->root, 0, 0, width, height, 0, x->depth, InputOutput, x->visual,
+ X.display, X.root, 0, 0, width, height, 0, X.depth, InputOutput, X.visual,
CWBackPixel | CWBitGravity | CWBackingStore | CWEventMask,
&attr);
/* register interest in the delete window message */
- Atom wmDeleteMessage = XInternAtom(x->display, "WM_DELETE_WINDOW", False);
- XSetWMProtocols(x->display, win->winid, &wmDeleteMessage, 1);
-
-// /* set input methods */
-// if ((x->xim = XOpenIM(x->display, 0, 0, 0)))
-// x->xic = XCreateIC(x->xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, x->self, XNFocusWindow, x->self, NULL);
-// /* initialize pixmap and drawing context */
-// x->pixmap = XCreatePixmap(x->display, x->self, x->width, x->height, x->depth);
-// x->xft = XftDrawCreate(x->display, x->pixmap, x->visual, x->colormap);
-// /* initialize the graphics context */
-// XGCValues gcv;
-// gcv.foreground = WhitePixel(x->display, x->screen);
-// gcv.graphics_exposures = False;
-// x->gc = XCreateGC(x->display, x->self, GCGraphicsExposures, &gcv);
-// x->eventfns[ConfigureNotify] = x11_resize;
-// x->eventfns[MapNotify] = x11_mapnotify;
-// x->eventfns[EnterNotify] = x11_enternotify;
+ Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols(X.display, win->winid, &wmDeleteMessage, 1);
+ /* set input methods */
+ if ((win->xim = XOpenIM(X.display, 0, 0, 0)))
+ {
+ win->xic = XCreateIC(
+ win->xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, win->winid, XNFocusWindow, win->winid, NULL);
+ }
+ /* initialize pixmap and drawing context */
+ win->pixmap = XCreatePixmap(X.display, win->winid, win->width, win->height, X.depth);
+ win->xft = XftDrawCreate(X.display, win->pixmap, X.visual, X.colormap);
+ /* initialize the graphics context */
+ XGCValues gcv;
+ gcv.foreground = WhitePixel(X.display, X.screen);
+ gcv.graphics_exposures = False;
+ win->gc = XCreateGC(X.display, win->winid, GCGraphicsExposures, &gcv);
}
-void X11_MakeDialog(XConf* x, XWindow* win, int width, int height)
+void X11_MakeDialog(XWindow* win, int width, int height)
{
- X11_MakeWindow(x, win, width, height);
- Atom WindowType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE", False);
- Atom DialogType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
- XChangeProperty(x->display, win->winid, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1);
+ X11_MakeWindow(win, width, height);
+ Atom WindowType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE", False);
+ Atom DialogType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+ XChangeProperty(X.display, win->winid, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1);
}
-void X11_ShowWindow(XConf* x, XWindow* w)
+void X11_ShowWindow(XWindow* w)
{
/* simulate an initial resize and map the window */
XConfigureEvent ce;
ce.type = ConfigureNotify;
ce.width = w->width;
ce.height = w->height;
- XSendEvent(x->display, w->winid, False, StructureNotifyMask, (XEvent *)&ce);
- XMapWindow(x->display, w->winid);
- XSync(x->display, False);
+ XSendEvent(X.display, w->winid, False, StructureNotifyMask, (XEvent *)&ce);
+ XMapWindow(X.display, w->winid);
+ XSync(X.display, False);
/* Waiting for window mapping */
XEvent ev;
do
{
- XNextEvent(x->display, &ev);
+ XNextEvent(X.display, &ev);
if (XFilterEvent(&ev, None))
{
continue;
}
if (ev.type == ConfigureNotify)
{
-// x11_resize(x, &ev);
+ xresize(&ev);
}
}
while (ev.type != MapNotify);
}
-void X11_HideWindow(XConf* x, XWindow* w)
+void X11_HideWindow(XWindow* w)
{
/* TODO: implement window hiding */
}