X.white = WhitePixel(X.disp, X.screen);
XAllocNamedColor(X.disp, DefaultColormap(X.disp, X.screen), "DimGray", &color, &exact);
X.gray = color.pixel;
- check_for_wm();
- mons_init();
- client_initall();
- keys_init();
/* configure mouse cursors */
Colormap cmap = DefaultColormap(X.disp, X.screen);
XRecolorCursor(X.disp, X.csr_point, &red, &white);
XDefineCursor(X.disp, X.root, X.csr_root);
+ /* load the font */
+ char **miss, *def;
+ int nmiss;
+ X.font = XCreateFontSet(X.disp, FONT_NAME, &miss, &nmiss, &def);
+ if (!X.font)
+ {
+ X.font = XCreateFontSet(X.disp, "fixed", &miss, &nmiss, &def);
+ }
+ check(X.font != NULL, "unable to create font set for title font");
+ X.font_ext = XExtentsOfFontSet(X.font);
+
+ XGCValues gv;
+ /* Set up root (frame) GC's. */
+ gv.foreground = X.black ^ X.white;
+ gv.background = X.white;
+ gv.function = GXxor;
+ gv.line_width = 1;
+ gv.subwindow_mode = IncludeInferiors;
+ gv.line_width = 2;
+ X.graphics = XCreateGC(X.disp, X.root,
+ GCForeground | GCBackground | GCFunction |
+ GCLineWidth | GCSubwindowMode, &gv);
+
+
+ check_for_wm();
+ mons_init();
+ client_initall();
+ keys_init();
+
/* setup event handlers */
X.eventfns[ButtonPress] = xbtnpress;
X.eventfns[ButtonRelease] = xbtnrelease;
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
+#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/extensions/Xinerama.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <assert.h>
#define min(a,b) (a < b ? a : b)
int start_x, start_y;
int reshaping;
Cursor csr_root, csr_point;
+ XFontSet font;
+ XFontSetExtents *font_ext;
+ GC graphics;
void (*eventfns[LASTEvent])(XEvent*);
} XConf;
} Key;
#define BORDER_WIDTH 5
-#define TITLE_HEIGHT 10
+#define TITLE_HEIGHT (X.font_ext->max_logical_extent.height)
+#define FONT_NAME "-*-lucida-bold-r-normal-sans-14-*-*-*-p-*-iso10646-1"
/* anvil.c */
extern XConf X;
mons_addclient(c);
/* get window name */
+ Atom actual_type;
+ int format;
+ unsigned long n, extra;
+ XGetWindowProperty(
+ X.disp, c->win, XA_WM_NAME, 0L, 100L, False, AnyPropertyType, &actual_type, &format, &n, &extra, (unsigned char **)&c->name);
+
/* get normal hints ? */
/* get registered protocols */
/* get transient_for property ? */
XSetWindowBackground(X.disp, c->frame, (Focused == c) ? X.black : X.gray);
XClearWindow(X.disp, c->frame);
XDefineCursor(X.disp, c->frame, X.csr_point);
-
- // int quarter = (border + titleHeight()) / 4;
- // /* Draw window title. */
- // if (c->name != 0) {
- // Xutf8DrawString(dpy, c->parent, font_set,
- // gc, border + 2 + (3 * quarter),
- // 2 + ascent(font_set_ext),
- // c->name, c->namelen);
- // }
+ if (c->name) {
+ int ascent = abs(X.font_ext->max_logical_extent.y);
+ Xutf8DrawString(X.disp, c->frame, X.font,
+ X.graphics, BORDER_WIDTH,
+ 2 + ascent,
+ c->name, strlen(c->name));
+ }
}
}
int (*error_default)(Display* disp, XErrorEvent* ev) = NULL;
-int error_ignore(Display* disp, XErrorEvent* ev)
-{
- (void)disp, (void)ev;
- return 0;
-}
-
int error_init(Display* disp, XErrorEvent* ev)
{
(void)disp, (void)ev;
int error_panic(Display* disp, XErrorEvent* ev)
{
+ if (ev->error_code == BadWindow)
+ {
+ return 0;
+ }
fprintf(stderr, "anvil: fatal error: request code=%d, error code=%d\n", ev->request_code, ev->error_code);
return error_default(disp, ev);
}
KeySym keysym = XkbKeycodeToKeysym(X.disp, ev->keycode, 0, 0);
for (unsigned int i = 0; i < sizeof(keys)/sizeof(keys[0]); i++)
{
- printf("%d: (%d == %d) && (%d == %d)\n",
- (int)i,
- (int)keysym,
- (int)keys[i].keysym,
- (int)keys[i].mod,
- (int)ev->state
- );
if (keysym == keys[i].keysym && keys[i].mod == ev->state && keys[i].func)
{
keys[i].func(&(keys[i].arg));