about summary refs log tree commit diff stats
path: root/util.h
blob: be296e8ad42d06d85d23396536fe9a99b165a0cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <X11/Xlib.h>
#include <X11/Xlocale.h>

typedef struct Brush Brush;
typedef struct Color Color;
typedef struct Fnt Fnt;

struct Color {
	unsigned long bg;
	unsigned long fg;
	unsigned long border;
};

struct Fnt {
	XFontStruct *xfont;
	XFontSet set;
	int ascent;
	int descent;
};

struct Brush {
	GC gc;
	Drawable drawable;
	XRectangle rect;
	Bool border;
	Fnt *font;
	Color color;
	const char *text;
};

extern void draw(Display *dpy, Brush *b);
extern void loadcolor(Display *dpy, int screen, Color *c,
		const char *bg, const char *fg, const char *bo);
extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
extern unsigned int textwidth(Fnt *font, char *text);
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
EnterCriticalSection".} ## Acquires the lock `L`. proc ReleaseSys(L: var TSysLock) {.stdcall, noSideEffect, dynlib: "kernel32", importc: "LeaveCriticalSection".} ## Releases the lock `L`. proc DeinitSys(L: var TSysLock) {.stdcall, noSideEffect, dynlib: "kernel32", importc: "DeleteCriticalSection".} proc CreateEvent(lpEventAttributes: pointer, bManualReset, bInitialState: int32, lpName: cstring): TSysCond {.stdcall, noSideEffect, dynlib: "kernel32", importc: "CreateEventA".} proc CloseHandle(hObject: THandle) {.stdcall, noSideEffect, dynlib: "kernel32", importc: "CloseHandle".} proc WaitForSingleObject(hHandle: THandle, dwMilliseconds: int32): int32 {. stdcall, dynlib: "kernel32", importc: "WaitForSingleObject".} proc SignalSysCond(hEvent: TSysCond) {.stdcall, noSideEffect, dynlib: "kernel32", importc: "SetEvent".} proc InitSysCond(cond: var TSysCond) {.inline.} = cond = CreateEvent(nil, 0'i32, 0'i32, nil) proc DeinitSysCond(cond: var TSysCond) {.inline.} = CloseHandle(cond) proc WaitSysCond(cond: var TSysCond, lock: var TSysLock) = releaseSys(lock) discard WaitForSingleObject(cond, -1'i32) acquireSys(lock) else: type TSysLock {.importc: "pthread_mutex_t", pure, final, header: "<sys/types.h>".} = object TSysCond {.importc: "pthread_cond_t", pure, final, header: "<sys/types.h>".} = object proc InitSysLock(L: var TSysLock, attr: pointer = nil) {. importc: "pthread_mutex_init", header: "<pthread.h>", noSideEffect.} proc AcquireSys(L: var TSysLock) {.noSideEffect, importc: "pthread_mutex_lock", header: "<pthread.h>".} proc TryAcquireSysAux(L: var TSysLock): cint {.noSideEffect, importc: "pthread_mutex_trylock", header: "<pthread.h>".} proc TryAcquireSys(L: var TSysLock): bool {.inline.} = result = TryAcquireSysAux(L) == 0'i32 proc ReleaseSys(L: var TSysLock) {.noSideEffect, importc: "pthread_mutex_unlock", header: "<pthread.h>".} proc DeinitSys(L: var TSysLock) {. importc: "pthread_mutex_destroy", header: "<pthread.h>".} proc InitSysCond(cond: var TSysCond, cond_attr: pointer = nil) {. importc: "pthread_cond_init", header: "<pthread.h>".} proc WaitSysCond(cond: var TSysCond, lock: var TSysLock) {. importc: "pthread_cond_wait", header: "<pthread.h>".} proc SignalSysCond(cond: var TSysCond) {. importc: "pthread_cond_signal", header: "<pthread.h>".} proc DeinitSysCond(cond: var TSysCond) {. importc: "pthread_cond_destroy", header: "<pthread.h>".}