From 09ae765d0a9245e261e2078df3122d0c72f28c92 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 09:04:35 +0000 Subject: [PATCH] thing git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@15 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Milsko/Core.h | 4 +++- include/Milsko/LowLevel.h | 3 ++- include/Milsko/Milsko.h | 2 ++ include/Milsko/StringDefs.h | 10 ++++++++++ src/core.c | 25 +++++++++++++++++++++++-- src/x11.c | 30 +++++++++++++++++++++--------- 6 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 include/Milsko/StringDefs.h diff --git a/include/Milsko/Core.h b/include/Milsko/Core.h index 498e07f..560b29e 100644 --- a/include/Milsko/Core.h +++ b/include/Milsko/Core.h @@ -10,6 +10,8 @@ MILSKODECL void MilskoDestroyWidget(HMILSKO handle); MILSKODECL void MilskoLoop(HMILSKO handle); MILSKODECL void MilskoStep(HMILSKO handle); MILSKODECL int MilskoPending(HMILSKO handle); -MILSKODECL void MilskoApply(HMILSKO handle, ...); + +MILSKODECL void MilskoSetInteger(HMILSKO handle, const char* key, int n); +MILSKODECL void MilskoApply(HMILSKO handle, ...); #endif diff --git a/include/Milsko/LowLevel.h b/include/Milsko/LowLevel.h index c47e344..8e437ab 100644 --- a/include/Milsko/LowLevel.h +++ b/include/Milsko/LowLevel.h @@ -22,7 +22,8 @@ MILSKODECL void MilskoLLDestroy(HMILSKOLL handle); MILSKODECL void MilskoLLPolygon(HMILSKOLL handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color); MILSKODECL HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b); MILSKODECL void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned int* h); -MILSKODECL void MilskoLLSetXYWH(HMILSKOLL handle, int x, int y, unsigned int w, unsigned int h); +MILSKODECL void MilskoLLSetXY(HMILSKOLL handle, int x, int y); +MILSKODECL void MilskoLLSetWH(HMILSKOLL handle, int w, int h); MILSKODECL int MilskoLLPending(HMILSKOLL handle); MILSKODECL void MilskoLLNextEvent(HMILSKOLL handle); MILSKODECL void MilskoLLSleep(int ms); diff --git a/include/Milsko/Milsko.h b/include/Milsko/Milsko.h index deb16d0..c123572 100644 --- a/include/Milsko/Milsko.h +++ b/include/Milsko/Milsko.h @@ -4,6 +4,8 @@ #include #include +#include +#include #include #include diff --git a/include/Milsko/StringDefs.h b/include/Milsko/StringDefs.h new file mode 100644 index 0000000..2c47c31 --- /dev/null +++ b/include/Milsko/StringDefs.h @@ -0,0 +1,10 @@ +/* $Id$ */ +#ifndef __MILSKO_STRINGDEFS_H__ +#define __MILSKO_STRINGDEFS_H__ + +#define MilskoNx "Ix" +#define MilskoNy "Iy" +#define MilskoNwidth "Iwidth" +#define MilskoNheight "Iheight" + +#endif diff --git a/src/core.c b/src/core.c index d9ad812..d2579d1 100644 --- a/src/core.c +++ b/src/core.c @@ -60,12 +60,33 @@ MILSKODECL void MilskoLoop(HMILSKO handle) { } } +void MilskoSetInteger(HMILSKO handle, const char* key, int n) { + int xy = 0; + int wh = 0; + if((xy = (strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0)) || (wh = (strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0))) { + int x, y; + unsigned int w, h; + + MilskoLLGetXYWH(handle->lowlevel, &x, &y, &w, &h); + if(strcmp(key, MilskoNx) == 0) x = n; + if(strcmp(key, MilskoNy) == 0) y = n; + if(strcmp(key, MilskoNwidth) == 0) w = n; + if(strcmp(key, MilskoNheight) == 0) h = n; + if(xy) MilskoLLSetXY(handle->lowlevel, x, y); + if(wh) MilskoLLSetWH(handle->lowlevel, w, h); + } +} + void MilskoApply(HMILSKO handle, ...) { va_list va; - char* key; + char* key; va_start(va, handle); - while((key = va_arg(va, char*)) != NULL){ + while((key = va_arg(va, char*)) != NULL) { + if(key[0] == 'I') { + int n = va_arg(va, int); + MilskoSetInteger(handle, key, n); + } } va_end(va); } diff --git a/src/x11.c b/src/x11.c index 900153a..7cdbe10 100644 --- a/src/x11.c +++ b/src/x11.c @@ -4,8 +4,10 @@ static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask; HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height) { - HMILSKOLL r; - Window p; + HMILSKOLL r; + Window p; + Window root; + unsigned int border, depth; r = malloc(sizeof(*r)); r->x = x; @@ -22,7 +24,8 @@ HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height) } 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); @@ -64,14 +67,23 @@ HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b) { } void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned int* h) { - *x = handle->x; - *y = handle->y; - *w = handle->width; - *h = handle->height; + Window root; + unsigned int border, depth; + + XGetGeometry(handle->display, handle->window, &root, x, y, w, h, &border, &depth); + + handle->x = *x; + handle->y = *y; + handle->width = *w; + handle->height = *h; } -void MilskoLLSetXYWH(HMILSKOLL handle, int x, int y, unsigned int w, unsigned int h) { - XMoveResizeWindow(handle->display, handle->window, x, y, w, h); +void MilskoLLSetXY(HMILSKOLL handle, int x, int y) { + XMoveWindow(handle->display, handle->window, x, y); +} + +void MilskoLLSetWH(HMILSKOLL handle, int w, int h) { + XResizeWindow(handle->display, handle->window, w, h); } void MilskoLLFreeColor(HMILSKOCOLOR color) {