diff --git a/GNUmakefile b/GNUmakefile index f543f4f..bdd7791 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -27,11 +27,14 @@ L_OBJS += src/x11.o L_LIBS += -lX11 endif -.PHONY: all clean +.PHONY: all format clean .SUFFIXES: .c .o all: $(LIB)milsko$(SO) +format: + clang-format --verbose -i $(shell find src include -name "*.c" -or -name "*.h") + $(LIB)milsko$(SO): $(L_OBJS) $(CC) $(LDFLAGS) -shared -o $@ $(L_OBJS) $(L_LIBS) diff --git a/include/Milsko/LowLevel.h b/include/Milsko/LowLevel.h index 75033d1..2dbbaf1 100644 --- a/include/Milsko/LowLevel.h +++ b/include/Milsko/LowLevel.h @@ -20,11 +20,11 @@ typedef void* HMILSKO; typedef void* HMILSKOCOLOR; #endif -HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height); -void MilskoLLDestroy(HMILSKO handle); -void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color); +HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height); +void MilskoLLDestroy(HMILSKO handle); +void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color); HMILSKOCOLOR MilskoLLAllocColor(HMILSKO handle, int r, int g, int b); -void MilskoLLGetXYWH(HMILSKO handle, int* x, int* y, unsigned int* w, unsigned int* h); -int MilskoLLPending(HMILSKO handle); +void MilskoLLGetXYWH(HMILSKO handle, int* x, int* y, unsigned int* w, unsigned int* h); +int MilskoLLPending(HMILSKO handle); #endif diff --git a/include/Milsko/X11.h b/include/Milsko/X11.h index 7354ff4..07c60c7 100644 --- a/include/Milsko/X11.h +++ b/include/Milsko/X11.h @@ -6,12 +6,12 @@ #include typedef struct __Milsko { - Display* display; - Window window; - GC gc; - Colormap colormap; - int x; - int y; + Display* display; + Window window; + GC gc; + Colormap colormap; + int x; + int y; unsigned int width; unsigned int height; }* HMILSKO; diff --git a/src/x11.c b/src/x11.c index 6ea5d76..f579765 100644 --- a/src/x11.c +++ b/src/x11.c @@ -5,26 +5,26 @@ static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask; -HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height){ +HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height) { HMILSKO r; - Window p; + Window p; - r = malloc(sizeof(*r)); - r->x = x; - r->y = y; - r->width = width; + r = malloc(sizeof(*r)); + r->x = x; + r->y = y; + r->width = width; r->height = height; - if(parent == NULL){ + if(parent == NULL) { r->display = XOpenDisplay(NULL); - p = XRootWindow(r->display, XDefaultScreen(r->display)); - }else{ + p = XRootWindow(r->display, XDefaultScreen(r->display)); + } else { r->display = parent->display; - p = parent->window; + p = parent->window; } - r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display))); + r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display))); r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display)); - r->gc = XCreateGC(r->display, r->window, 0, 0); + r->gc = XCreateGC(r->display, r->window, 0, 0); XSelectInput(r->display, r->window, mask); XMapWindow(r->display, r->window); @@ -32,19 +32,19 @@ HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height){ return r; } -void MilskoLLDestroy(HMILSKO handle){ +void MilskoLLDestroy(HMILSKO handle) { XFreeGC(handle->display, handle->gc); XDestroyWindow(handle->display, handle->window); free(handle); } -void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color){ - int i; +void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color) { + int i; XPoint* p = malloc(sizeof(*p) * points_count); XSetForeground(handle->display, handle->gc, color->pixel); - for(i = 0; i < points_count; i++){ + for(i = 0; i < points_count; i++) { p[i].x = points[i].x; p[i].y = points[i].y; } @@ -53,32 +53,32 @@ void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMIL free(p); } -HMILSKOCOLOR MilskoLLAllocColor(HMILSKO handle, int r, int g, int b){ +HMILSKOCOLOR MilskoLLAllocColor(HMILSKO handle, int r, int g, int b) { HMILSKOCOLOR c = malloc(sizeof(*c)); - XColor xc; - xc.red = 256 * r; + XColor xc; + xc.red = 256 * r; xc.green = 256 * g; - xc.blue = 256 * b; + xc.blue = 256 * b; XAllocColor(handle->display, handle->colormap, &xc); c->pixel = xc.pixel; return c; } -void MilskoLLGetXYWH(HMILSKO handle, int* x, int* y, unsigned int* w, unsigned int* h){ +void MilskoLLGetXYWH(HMILSKO handle, int* x, int* y, unsigned int* w, unsigned int* h) { *x = handle->x; *y = handle->y; *w = handle->width; *h = handle->height; } -void MilskoLLFreeColor(HMILSKOCOLOR color){ +void MilskoLLFreeColor(HMILSKOCOLOR color) { free(color); } -int MilskoLLPending(HMILSKO handle){ +int MilskoLLPending(HMILSKO handle) { XEvent ev; - if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)){ + if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { XPutBackEvent(handle->display, &ev); return 1; }