backend refactor

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@683 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-13 02:27:31 +00:00
parent 7e7e9f776d
commit 295e685f54
14 changed files with 495 additions and 458 deletions

View File

@@ -12,15 +12,34 @@
typedef struct _MwLLHandler* MwLLHandler;
typedef struct _MwLLMouse MwLLMouse;
#ifdef _MILSKO
typedef struct _MwLL* MwLL;
typedef struct _MwLLColor* MwLLColor;
typedef struct _MwLLPixmap* MwLLPixmap;
typedef union _MwLL* MwLL;
typedef union _MwLLColor* MwLLColor;
typedef union _MwLLPixmap* MwLLPixmap;
#else
typedef void* MwLL;
typedef void* MwLLColor;
typedef void* MwLLPixmap;
#endif
struct _MwLLCommon {
void* user;
int copy_buffer;
MwLLHandler handler;
};
struct _MwLLCommonColor {
int red;
int green;
int blue;
};
struct _MwLLCommonPixmap {
int width;
int height;
unsigned char* raw;
};
#ifdef _MILSKO
#ifdef USE_X11
#include "../../src/backend/x11.h"
@@ -28,14 +47,41 @@ typedef void* MwLLPixmap;
#ifdef USE_GDI
#include "../../src/backend/gdi.h"
#endif
#ifdef USE_DARWIN
#include "../../src/backend/mac/mac.h"
union _MwLL {
struct _MwLLCommon common;
#ifdef USE_X11
struct _MwLLX11 x11;
#endif
#ifdef USE_GDI
struct _MwLLGDI gdi;
#endif
};
union _MwLLColor {
struct _MwLLCommonColor common;
#ifdef USE_X11
struct _MwLLX11Color x11;
#endif
#ifdef USE_GDI
struct _MwLLGDIColor gdi;
#endif
};
union _MwLLPixmap {
struct _MwLLCommonPixmap common;
#ifdef USE_X11
struct _MwLLX11Pixmap x11;
#endif
#ifdef USE_GDI
struct _MwLLGDIPixmap gdi;
#endif
};
#endif
#include <Mw/TypeDefs.h>
#define MwLLDispatch(x, y, z) \
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x, z)
if(x->common.handler != NULL && x->common.handler->y != NULL) x->common.handler->y(x, z)
#define MwLLKeyMask (1 << 31)
enum MwLLKeyEnum {

View File

@@ -20,7 +20,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
HBITMAP hbmp;
HDC dc, hbdc;
if(u->ll->copy_buffer) {
if(u->ll->common.copy_buffer) {
GetClientRect(hWnd, &rc);
dc = GetDC(hWnd);
@@ -29,7 +29,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
SelectObject(hbdc, hbmp);
ReleaseDC(hWnd, dc);
u->ll->hDC = hbdc;
u->ll->gdi.hDC = hbdc;
MwLLDispatch(u->ll, draw, NULL);
dc = BeginPaint(hWnd, &ps);
@@ -39,7 +39,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
DeleteDC(hbdc);
DeleteObject(hbmp);
} else {
u->ll->hDC = BeginPaint(hWnd, &ps);
u->ll->gdi.hDC = BeginPaint(hWnd, &ps);
MwLLDispatch(u->ll, draw, NULL);
EndPaint(hWnd, &ps);
}
@@ -91,7 +91,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
p.x = LOWORD(lp);
p.y = HIWORD(lp);
if(u->ll->grabbed) {
if(u->ll->gdi.grabbed) {
RECT rc;
GetClientRect(hWnd, &rc);
@@ -101,7 +101,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, move, &p);
if(u->ll->grabbed && (p.x != 0 || p.y != 0)) {
if(u->ll->gdi.grabbed && (p.x != 0 || p.y != 0)) {
RECT rc;
POINT p;
@@ -200,7 +200,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
}
} else if(msg == WM_SETCURSOR) {
if(LOWORD(lp) != HTCLIENT) return DefWindowProc(hWnd, msg, wp, lp);
if(u->ll->cursor != NULL) SetCursor(u->ll->cursor);
if(u->ll->gdi.cursor != NULL) SetCursor(u->ll->gdi.cursor);
} else if(msg == WM_USER) {
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
@@ -233,16 +233,17 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
RegisterClassEx(&wc);
r->grabbed = 0;
r->copy_buffer = 1;
r->hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
r->hInstance = wc.hInstance;
r->cursor = NULL;
r->common.copy_buffer = 1;
r->gdi.grabbed = 0;
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
r->gdi.hInstance = wc.hInstance;
r->gdi.cursor = NULL;
u->ll = r;
u->min_set = 0;
u->max_set = 0;
SetWindowLongPtr(r->hWnd, GWLP_USERDATA, (LPARAM)u);
SetWindowLongPtr(r->gdi.hWnd, GWLP_USERDATA, (LPARAM)u);
if(parent == NULL) {
RECT rc;
@@ -251,13 +252,13 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
rc.top = 0;
rc.right = width;
rc.bottom = height;
AdjustWindowRect(&rc, GetWindowLongPtr(r->hWnd, GWL_STYLE), FALSE);
SetWindowPos(r->hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE);
AdjustWindowRect(&rc, GetWindowLongPtr(r->gdi.hWnd, GWL_STYLE), FALSE);
SetWindowPos(r->gdi.hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE);
ShowWindow(r->hWnd, SW_NORMAL);
UpdateWindow(r->hWnd);
ShowWindow(r->gdi.hWnd, SW_NORMAL);
UpdateWindow(r->gdi.hWnd);
InvalidateRect(r->hWnd, NULL, FALSE);
InvalidateRect(r->gdi.hWnd, NULL, FALSE);
}
return r;
@@ -267,10 +268,10 @@ static void MwLLDestroyImpl(MwLL handle) {
MwLLDestroyCommon(handle);
/* for safety */
SetWindowLongPtr(handle->hWnd, GWLP_USERDATA, (LPARAM)NULL);
DestroyWindow(handle->hWnd);
SetWindowLongPtr(handle->gdi.hWnd, GWLP_USERDATA, (LPARAM)NULL);
DestroyWindow(handle->gdi.hWnd);
if(handle->cursor != NULL) DestroyCursor(handle->cursor);
if(handle->gdi.cursor != NULL) DestroyCursor(handle->gdi.cursor);
free(handle);
}
@@ -284,10 +285,10 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
p[i].x = points[i].x;
p[i].y = points[i].y;
}
SelectObject(handle->hDC, color->brush);
SelectObject(handle->hDC, pen);
SetPolyFillMode(handle->hDC, ALTERNATE);
Polygon(handle->hDC, p, points_count);
SelectObject(handle->gdi.hDC, color->gdi.brush);
SelectObject(handle->gdi.hDC, pen);
SetPolyFillMode(handle->gdi.hDC, ALTERNATE);
Polygon(handle->gdi.hDC, p, points_count);
DeleteObject(pen);
@@ -295,11 +296,11 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
HPEN pen = CreatePen(PS_SOLID, 1, RGB(color->red, color->green, color->blue));
HPEN pen = CreatePen(PS_SOLID, 1, RGB(color->common.red, color->common.green, color->common.blue));
SelectObject(handle->hDC, pen);
MoveToEx(handle->hDC, points[0].x, points[0].y, NULL);
LineTo(handle->hDC, points[1].x, points[1].y);
SelectObject(handle->gdi.hDC, pen);
MoveToEx(handle->gdi.hDC, points[0].x, points[0].y, NULL);
LineTo(handle->gdi.hDC, points[1].x, points[1].y);
DeleteObject(pen);
}
@@ -307,7 +308,7 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
MwLLColor c = malloc(sizeof(*c));
c->brush = NULL;
c->gdi.brush = NULL;
MwLLColorUpdate(handle, c, r, g, b);
@@ -315,7 +316,7 @@ static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
}
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
HDC dc = GetDC(handle->hWnd);
HDC dc = GetDC(handle->gdi.hWnd);
if(r > 255) r = 255;
if(g > 255) g = 255;
@@ -324,17 +325,17 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
if(g < 0) g = 0;
if(b < 0) b = 0;
if(c->brush != NULL) DeleteObject(c->brush);
c->brush = CreateSolidBrush(GetNearestColor(dc, RGB(r, g, b)));
c->red = r;
c->green = g;
c->blue = b;
if(c->gdi.brush != NULL) DeleteObject(c->gdi.brush);
c->gdi.brush = CreateSolidBrush(GetNearestColor(dc, RGB(r, g, b)));
c->common.red = r;
c->common.green = g;
c->common.blue = b;
ReleaseDC(handle->hWnd, dc);
ReleaseDC(handle->gdi.hWnd, dc);
}
static void MwLLFreeColorImpl(MwLLColor color) {
DeleteObject(color->brush);
DeleteObject(color->gdi.brush);
free(color);
}
@@ -347,8 +348,8 @@ static void MwLLSetBackgroundImpl(MwLL handle, MwLLColor color) {
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
RECT rc;
GetClientRect(handle->hWnd, &rc);
MapWindowPoints(handle->hWnd, GetParent(handle->hWnd), (LPPOINT)&rc, 2);
GetClientRect(handle->gdi.hWnd, &rc);
MapWindowPoints(handle->gdi.hWnd, GetParent(handle->gdi.hWnd), (LPPOINT)&rc, 2);
*x = rc.left;
*y = rc.top;
@@ -357,17 +358,17 @@ static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsign
}
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
SetWindowPos(handle->hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
InvalidateRect(handle->hWnd, NULL, FALSE);
SetWindowPos(handle->gdi.hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
InvalidateRect(handle->gdi.hWnd, NULL, FALSE);
}
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
SetWindowPos(handle->hWnd, NULL, 0, 0, w, h, SWP_NOMOVE);
InvalidateRect(handle->hWnd, NULL, FALSE);
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, w, h, SWP_NOMOVE);
InvalidateRect(handle->gdi.hWnd, NULL, FALSE);
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
SetWindowText(handle->hWnd, title);
SetWindowText(handle->gdi.hWnd, title);
}
static int MwLLPendingImpl(MwLL handle) {
@@ -375,7 +376,7 @@ static int MwLLPendingImpl(MwLL handle) {
(void)handle;
return PeekMessage(&msg, handle->hWnd, 0, 0, PM_NOREMOVE) ? 1 : 0;
return PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE) ? 1 : 0;
}
static void MwLLNextEventImpl(MwLL handle) {
@@ -383,8 +384,8 @@ static void MwLLNextEventImpl(MwLL handle) {
(void)handle;
while(PeekMessage(&msg, handle->hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->hWnd, 0, 0);
while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->gdi.hWnd, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -392,14 +393,14 @@ static void MwLLNextEventImpl(MwLL handle) {
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
HDC dc = GetDC(handle->hWnd);
HDC dc = GetDC(handle->gdi.hWnd);
BITMAPINFOHEADER bmih;
r->raw = malloc(width * height * 4);
memcpy(r->raw, data, 4 * width * height);
r->common.raw = malloc(width * height * 4);
memcpy(r->common.raw, data, 4 * width * height);
r->width = width;
r->height = height;
r->common.width = width;
r->common.height = height;
bmih.biSize = sizeof(bmih);
bmih.biWidth = width;
@@ -413,12 +414,12 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
r->hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&r->quad, NULL, (DWORD)0);
r->gdi.hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&r->gdi.quad, NULL, (DWORD)0);
r->hMask = NULL;
r->hMask2 = NULL;
r->gdi.hMask = NULL;
r->gdi.hMask2 = NULL;
ReleaseDC(handle->hWnd, dc);
ReleaseDC(handle->gdi.hWnd, dc);
MwLLPixmapUpdate(r);
@@ -427,22 +428,22 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
int y, x;
int w = (r->width + (16 - (r->width % 16))) / 8;
int w = (r->common.width + (16 - (r->common.width % 16))) / 8;
WORD* words;
WORD* words2;
if(16 * (r->width / 16) == r->width) w -= 2;
if(16 * (r->common.width / 16) == r->common.width) w -= 2;
words = malloc(w * r->height);
words2 = malloc(w * r->height);
memset(words, 0, w * r->height);
memset(words2, 0, w * r->height);
for(y = 0; y < r->height; y++) {
words = malloc(w * r->common.height);
words2 = malloc(w * r->common.height);
memset(words, 0, w * r->common.height);
memset(words2, 0, w * r->common.height);
for(y = 0; y < r->common.height; y++) {
BYTE* l = (BYTE*)&words[y * (w / 2)];
BYTE* l2 = (BYTE*)&words2[y * (w / 2)];
for(x = 0; x < r->width; x++) {
RGBQUAD* q = &r->quad[y * r->width + x];
unsigned char* px = &r->raw[(y * r->width + x) * 4];
for(x = 0; x < r->common.width; x++) {
RGBQUAD* q = &r->gdi.quad[y * r->common.width + x];
unsigned char* px = &r->common.raw[(y * r->common.width + x) * 4];
q->rgbRed = px[0];
q->rgbGreen = px[1];
@@ -456,27 +457,27 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
}
}
if(r->hMask != NULL) DeleteObject(r->hMask);
if(r->hMask2 != NULL) DeleteObject(r->hMask2);
if(r->gdi.hMask != NULL) DeleteObject(r->gdi.hMask);
if(r->gdi.hMask2 != NULL) DeleteObject(r->gdi.hMask2);
r->hMask = CreateBitmap(r->width, r->height, 1, 1, words);
r->hMask2 = CreateBitmap(r->width, r->height, 1, 1, words2);
r->gdi.hMask = CreateBitmap(r->common.width, r->common.height, 1, 1, words);
r->gdi.hMask2 = CreateBitmap(r->common.width, r->common.height, 1, 1, words2);
free(words);
free(words2);
}
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
free(pixmap->raw);
DeleteObject(pixmap->hMask);
DeleteObject(pixmap->hMask2);
DeleteObject(pixmap->hBitmap);
free(pixmap->common.raw);
DeleteObject(pixmap->gdi.hMask);
DeleteObject(pixmap->gdi.hMask2);
DeleteObject(pixmap->gdi.hBitmap);
free(pixmap);
}
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
HDC hmdc = CreateCompatibleDC(handle->hDC);
HDC hmdc = CreateCompatibleDC(handle->gdi.hDC);
POINT p[3];
p[0].x = rect->x;
@@ -488,10 +489,10 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
p[2].x = rect->x;
p[2].y = rect->y + rect->height;
SelectObject(hmdc, pixmap->hBitmap);
SelectObject(hmdc, pixmap->gdi.hBitmap);
SetStretchBltMode(handle->hDC, HALFTONE);
PlgBlt(handle->hDC, p, hmdc, 0, 0, pixmap->width, pixmap->height, pixmap->hMask, 0, 0);
SetStretchBltMode(handle->gdi.hDC, HALFTONE);
PlgBlt(handle->gdi.hDC, p, hmdc, 0, 0, pixmap->common.width, pixmap->common.height, pixmap->gdi.hMask, 0, 0);
DeleteDC(hmdc);
}
@@ -504,18 +505,18 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
ii.fIcon = TRUE;
ii.xHotspot = 0;
ii.yHotspot = 0;
ii.hbmMask = pixmap->hMask2;
ii.hbmColor = pixmap->hBitmap;
ii.hbmMask = pixmap->gdi.hMask2;
ii.hbmColor = pixmap->gdi.hBitmap;
ico = CreateIconIndirect(&ii);
SetClassLongPtr(handle->hWnd, GCLP_HICON, (LPARAM)ico);
SetClassLongPtr(handle->gdi.hWnd, GCLP_HICON, (LPARAM)ico);
DestroyIcon(ico);
}
static void MwLLForceRenderImpl(MwLL handle) {
PostMessage(handle->hWnd, WM_USER, 0, 0);
PostMessage(handle->gdi.hWnd, WM_USER, 0, 0);
}
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
@@ -559,8 +560,8 @@ static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
if(handle->cursor != NULL) DestroyCursor(handle->cursor);
handle->cursor = cursor;
if(handle->gdi.cursor != NULL) DestroyCursor(handle->gdi.cursor);
handle->gdi.cursor = cursor;
free(dimage);
free(dmask);
@@ -568,16 +569,16 @@ static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
RECT rc, rc2;
LPARAM lp = GetWindowLongPtr(handle->hWnd, GWL_STYLE);
LPARAM lp = GetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE);
lp &= WS_VISIBLE;
GetWindowRect(GetParent(handle->hWnd), &rc);
GetWindowRect(GetParent(handle->gdi.hWnd), &rc);
GetClientRect(handle->hWnd, &rc2);
GetClientRect(handle->gdi.hWnd, &rc2);
SetWindowLongPtr(handle->hWnd, GWL_STYLE, (LPARAM)WS_OVERLAPPEDWINDOW | lp);
SetParent(handle->hWnd, NULL);
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, (LPARAM)WS_OVERLAPPEDWINDOW | lp);
SetParent(handle->gdi.hWnd, NULL);
rc.left += point->x;
rc.top += point->y;
@@ -586,12 +587,12 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
rc2.right -= rc2.left;
rc2.bottom -= rc2.top;
SetWindowPos(handle->hWnd, HWND_TOPMOST, rc.left, rc.top, rc2.right == 0 ? 1 : rc2.right, rc2.bottom == 0 ? 1 : rc2.bottom, SWP_FRAMECHANGED | SWP_NOACTIVATE);
SetWindowPos(handle->gdi.hWnd, HWND_TOPMOST, rc.left, rc.top, rc2.right == 0 ? 1 : rc2.right, rc2.bottom == 0 ? 1 : rc2.bottom, SWP_FRAMECHANGED | SWP_NOACTIVATE);
}
static void MwLLShowImpl(MwLL handle, int show) {
ShowWindow(handle->hWnd, show ? SW_NORMAL : SW_HIDE);
if(show) SetFocus(handle->hWnd);
ShowWindow(handle->gdi.hWnd, show ? SW_NORMAL : SW_HIDE);
if(show) SetFocus(handle->gdi.hWnd);
}
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
@@ -601,7 +602,7 @@ static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
}
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) {
userdata_t* u = (userdata_t*)GetWindowLongPtr(handle->hWnd, GWLP_USERDATA);
userdata_t* u = (userdata_t*)GetWindowLongPtr(handle->gdi.hWnd, GWLP_USERDATA);
u->min_set = u->max_set = 1;
u->min.x = minx;
@@ -611,7 +612,7 @@ static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int
}
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
LPARAM lp = GetWindowLongPtr(handle->hWnd, GWL_STYLE);
LPARAM lp = GetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE);
if(toggle) {
lp &= ~WS_CAPTION;
@@ -619,13 +620,13 @@ static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
lp |= WS_CAPTION;
}
SetWindowLongPtr(handle->hWnd, GWL_STYLE, lp);
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, lp);
SetWindowPos(handle->hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
}
static void MwLLFocusImpl(MwLL handle) {
SetFocus(handle->hWnd);
SetFocus(handle->gdi.hWnd);
}
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
@@ -633,7 +634,7 @@ static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
POINT p;
RECT rc;
GetClientRect(handle->hWnd, &rc);
GetClientRect(handle->gdi.hWnd, &rc);
rc.right -= rc.left;
rc.bottom -= rc.top;
@@ -641,25 +642,25 @@ static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
p.x = (rc.right - rc.left) / 2;
p.y = (rc.bottom - rc.top) / 2;
MapWindowPoints(handle->hWnd, HWND_DESKTOP, &p, 1);
MapWindowPoints(handle->gdi.hWnd, HWND_DESKTOP, &p, 1);
handle->grabbed = 1;
handle->gdi.grabbed = 1;
SetFocus(handle->hWnd);
SetFocus(handle->gdi.hWnd);
GetWindowRect(handle->hWnd, &rc);
GetWindowRect(handle->gdi.hWnd, &rc);
ClipCursor(&rc);
SetCursorPos(p.x, p.y);
} else {
handle->grabbed = 0;
handle->gdi.grabbed = 0;
ClipCursor(NULL);
}
}
static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
HGLOBAL hg;
if(OpenClipboard(handle->hWnd) != 0) {
if(OpenClipboard(handle->gdi.hWnd) != 0) {
char* lock;
EmptyClipboard();
@@ -678,7 +679,7 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
static char* MwLLGetClipboardImpl(MwLL handle) {
HGLOBAL hg;
char* r = NULL;
if(OpenClipboard(handle->hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* lock;
r = malloc(GlobalSize(hg));
@@ -693,15 +694,15 @@ static char* MwLLGetClipboardImpl(MwLL handle) {
}
static void MwLLMakeToolWindowImpl(MwLL handle) {
LPARAM lp = GetWindowLongPtr(handle->hWnd, GWL_STYLE) & WS_VISIBLE;
LPARAM lp = GetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE) & WS_VISIBLE;
RECT rc;
SetWindowLongPtr(handle->hWnd, GWL_STYLE, (LPARAM)lp);
SetWindowLongPtr(handle->hWnd, GWL_EXSTYLE, (LPARAM)WS_EX_TOOLWINDOW);
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, (LPARAM)lp);
SetWindowLongPtr(handle->gdi.hWnd, GWL_EXSTYLE, (LPARAM)WS_EX_TOOLWINDOW);
GetClientRect(handle->hWnd, &rc);
GetClientRect(handle->gdi.hWnd, &rc);
SetWindowPos(handle->hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
static int MwLLGDICallInitImpl(void) {

View File

@@ -22,31 +22,25 @@
#define GET_WHEEL_DELTA_WPARAM(x) ((short)HIWORD(x))
#endif
struct _MwLL {
struct _MwLLGDI {
struct _MwLLCommon common;
HINSTANCE hInstance;
HWND hWnd;
HDC hDC;
void* user;
int copy_buffer;
HCURSOR cursor;
MwLLHandler handler;
int grabbed;
};
struct _MwLLColor {
HBRUSH brush;
struct _MwLLGDIColor {
struct _MwLLCommonColor common;
int red;
int green;
int blue;
HBRUSH brush;
};
struct _MwLLPixmap {
int width;
int height;
unsigned char* raw;
struct _MwLLGDIPixmap {
struct _MwLLCommonPixmap common;
RGBQUAD* quad;
HBITMAP hBitmap;

View File

@@ -31,13 +31,13 @@ static void create_pixmap(MwLL handle) {
MwLLGetXYWH(handle, &x, &y, &w, &h);
XGetWindowAttributes(handle->display, handle->window, &attr);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &attr);
handle->pixmap = XCreatePixmap(handle->display, handle->window, w, h, attr.depth);
handle->x11.pixmap = XCreatePixmap(handle->x11.display, handle->x11.window, w, h, attr.depth);
}
static void destroy_pixmap(MwLL handle) {
XFreePixmap(handle->display, handle->pixmap);
XFreePixmap(handle->x11.display, handle->x11.pixmap);
}
static void wait_map(MwLL handle, int move_back, int nomap) {
@@ -51,15 +51,15 @@ static void wait_map(MwLL handle, int move_back, int nomap) {
if(move_back) MwLLSetXY(handle, x, y);
XGetWindowAttributes(handle->display, handle->window, &xwa);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
if(xwa.map_state != IsViewable) {
if(!nomap) XMapWindow(handle->display, handle->window);
if(!nomap) XMapWindow(handle->x11.display, handle->x11.window);
XSync(handle->display, False);
XSync(handle->x11.display, False);
while(1) {
XNextEvent(handle->display, &ev);
if(ev.type == MapNotify && ev.xmap.window == handle->window) {
XNextEvent(handle->x11.display, &ev);
if(ev.type == MapNotify && ev.xmap.window == handle->x11.window) {
break;
} else {
arrput(queue, ev);
@@ -67,7 +67,7 @@ static void wait_map(MwLL handle, int move_back, int nomap) {
}
while(arrlen(queue) > 0) {
XPutBackEvent(handle->display, &queue[0]);
XPutBackEvent(handle->x11.display, &queue[0]);
arrdel(queue, 0);
}
arrfree(queue);
@@ -80,12 +80,12 @@ static void wait_unmap(MwLL handle) {
XEvent* queue = NULL;
XEvent ev;
XUnmapWindow(handle->display, handle->window);
XSync(handle->display, False);
XUnmapWindow(handle->x11.display, handle->x11.window);
XSync(handle->x11.display, False);
while(1) {
XNextEvent(handle->display, &ev);
if(ev.type == UnmapNotify && ev.xunmap.window == handle->window) {
XNextEvent(handle->x11.display, &ev);
if(ev.type == UnmapNotify && ev.xunmap.window == handle->x11.window) {
break;
} else {
arrput(queue, ev);
@@ -93,7 +93,7 @@ static void wait_unmap(MwLL handle) {
}
while(arrlen(queue) > 0) {
XPutBackEvent(handle->display, &queue[0]);
XPutBackEvent(handle->x11.display, &queue[0]);
arrdel(queue, 0);
}
arrfree(queue);
@@ -102,11 +102,11 @@ static void wait_unmap(MwLL handle) {
static unsigned long generate_color(MwLL handle, unsigned long r, unsigned long g, unsigned long b) {
unsigned long c = 0;
c |= (r * handle->red_max / 255) << handle->red_shift;
c |= (r * handle->x11.red_max / 255) << handle->x11.red_shift;
c |= (g * handle->green_max / 255) << handle->green_shift;
c |= (g * handle->x11.green_max / 255) << handle->x11.green_shift;
c |= (b * handle->blue_max / 255) << handle->blue_shift;
c |= (b * handle->x11.blue_max / 255) << handle->x11.blue_shift;
return c;
}
@@ -140,74 +140,74 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
if(height < 2) height = 2;
if(parent == NULL) {
r->display = XOpenDisplay(NULL);
p = XRootWindow(r->display, XDefaultScreen(r->display));
r->top = 1;
r->x11.display = XOpenDisplay(NULL);
p = XRootWindow(r->x11.display, XDefaultScreen(r->x11.display));
r->x11.top = 1;
} else {
r->display = parent->display;
p = parent->window;
r->top = 0;
r->x11.display = parent->x11.display;
p = parent->x11.window;
r->x11.top = 0;
}
r->window = XCreateSimpleWindow(r->display, p, px, py, width, height, 0, 0, WhitePixel(r->display, DefaultScreen(r->display)));
r->x11.window = XCreateSimpleWindow(r->x11.display, p, px, py, width, height, 0, 0, WhitePixel(r->x11.display, DefaultScreen(r->x11.display)));
sh.flags = PWinGravity;
sh.win_gravity = StaticGravity;
XSetWMNormalHints(r->display, r->window, &sh);
XSetWMNormalHints(r->x11.display, r->x11.window, &sh);
xvi = get_visual_info(r->display);
xvi = get_visual_info(r->x11.display);
if(xvi->red_mask != 0) {
i = 0;
while(!((n << i) & xvi->red_mask)) i++;
r->red_mask = xvi->red_mask;
r->red_max = xvi->red_mask >> i;
r->red_shift = i;
r->x11.red_mask = xvi->red_mask;
r->x11.red_max = xvi->red_mask >> i;
r->x11.red_shift = i;
i = 0;
while(!((n << i) & xvi->green_mask)) i++;
r->green_mask = xvi->green_mask;
r->green_max = xvi->green_mask >> i;
r->green_shift = i;
r->x11.green_mask = xvi->green_mask;
r->x11.green_max = xvi->green_mask >> i;
r->x11.green_shift = i;
i = 0;
while(!((n << i) & xvi->blue_mask)) i++;
r->blue_mask = xvi->blue_mask;
r->blue_max = xvi->blue_mask >> i;
r->blue_shift = i;
r->x11.blue_mask = xvi->blue_mask;
r->x11.blue_max = xvi->blue_mask >> i;
r->x11.blue_shift = i;
}
XFree(xvi);
XSetLocaleModifiers("");
if((r->xim = XOpenIM(r->display, 0, 0, 0)) == NULL) {
if((r->x11.xim = XOpenIM(r->x11.display, 0, 0, 0)) == NULL) {
XSetLocaleModifiers("@im=none");
r->xim = XOpenIM(r->display, 0, 0, 0);
r->x11.xim = XOpenIM(r->x11.display, 0, 0, 0);
}
r->xic = XCreateIC(r->xim,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, r->window,
XNFocusWindow, r->window,
NULL);
XSetICFocus(r->xic);
r->x11.xic = XCreateIC(r->x11.xim,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, r->x11.window,
XNFocusWindow, r->x11.window,
NULL);
XSetICFocus(r->x11.xic);
r->copy_buffer = 1;
r->common.copy_buffer = 1;
r->width = width;
r->height = height;
r->x11.width = width;
r->x11.height = height;
r->grabbed = 0;
r->x11.grabbed = 0;
r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display));
r->wm_delete = XInternAtom(r->display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(r->display, r->window, &r->wm_delete, 1);
r->x11.colormap = DefaultColormap(r->x11.display, XDefaultScreen(r->x11.display));
r->x11.wm_delete = XInternAtom(r->x11.display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(r->x11.display, r->x11.window, &r->x11.wm_delete, 1);
r->gc = XCreateGC(r->display, r->window, 0, NULL);
r->x11.gc = XCreateGC(r->x11.display, r->x11.window, 0, NULL);
create_pixmap(r);
XSetGraphicsExposures(r->display, r->gc, False);
XSetGraphicsExposures(r->x11.display, r->x11.gc, False);
XSelectInput(r->display, r->window, mask);
XSelectInput(r->x11.display, r->x11.window, mask);
if(x != MwDEFAULT || y != MwDEFAULT) {
unsigned int dummy;
@@ -217,7 +217,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
if(y == MwDEFAULT) y = py;
MwLLSetXY(r, x, y);
XSync(r->display, False);
XSync(r->x11.display, False);
}
wait_map(r, 0, 0);
@@ -228,15 +228,15 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
static void MwLLDestroyImpl(MwLL handle) {
MwLLDestroyCommon(handle);
if(handle->xic) XDestroyIC(handle->xic);
if(handle->xim) XCloseIM(handle->xim);
if(handle->x11.xic) XDestroyIC(handle->x11.xic);
if(handle->x11.xim) XCloseIM(handle->x11.xim);
destroy_pixmap(handle);
XFreeGC(handle->display, handle->gc);
XUnmapWindow(handle->display, handle->window);
XDestroyWindow(handle->display, handle->window);
XFreeGC(handle->x11.display, handle->x11.gc);
XUnmapWindow(handle->x11.display, handle->x11.window);
XDestroyWindow(handle->x11.display, handle->x11.window);
XSync(handle->display, False);
XSync(handle->x11.display, False);
free(handle);
}
@@ -245,21 +245,21 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL
int i;
XPoint* p = malloc(sizeof(*p) * points_count);
XSetForeground(handle->display, handle->gc, color->pixel);
XSetForeground(handle->x11.display, handle->x11.gc, color->x11.pixel);
for(i = 0; i < points_count; i++) {
p[i].x = points[i].x;
p[i].y = points[i].y;
}
XFillPolygon(handle->display, handle->pixmap, handle->gc, p, points_count, Nonconvex, CoordModeOrigin);
XFillPolygon(handle->x11.display, handle->x11.pixmap, handle->x11.gc, p, points_count, Nonconvex, CoordModeOrigin);
free(p);
}
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
XSetForeground(handle->display, handle->gc, color->pixel);
XSetForeground(handle->x11.display, handle->x11.gc, color->x11.pixel);
XDrawLine(handle->display, handle->pixmap, handle->gc, points[0].x, points[0].y, points[1].x, points[1].y);
XDrawLine(handle->x11.display, handle->x11.pixmap, handle->x11.gc, points[0].x, points[0].y, points[1].x, points[1].y);
}
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
@@ -271,7 +271,7 @@ static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
XColor xc;
if(handle->red_mask == 0) {
if(handle->x11.red_mask == 0) {
if(r > 255) r = 255;
if(g > 255) g = 255;
if(b > 255) b = 255;
@@ -282,27 +282,27 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
xc.red = 256 * r;
xc.green = 256 * g;
xc.blue = 256 * b;
XAllocColor(handle->display, handle->colormap, &xc);
XAllocColor(handle->x11.display, handle->x11.colormap, &xc);
c->pixel = xc.pixel;
c->x11.pixel = xc.pixel;
} else {
c->pixel = generate_color(handle, r, g, b);
c->x11.pixel = generate_color(handle, r, g, b);
}
c->red = r;
c->green = g;
c->blue = b;
c->common.red = r;
c->common.green = g;
c->common.blue = b;
}
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
Window root;
unsigned int border, depth;
XGetGeometry(handle->display, handle->window, &root, x, y, w, h, &border, &depth);
if(handle->top) {
XGetGeometry(handle->x11.display, handle->x11.window, &root, x, y, w, h, &border, &depth);
if(handle->x11.top) {
int rx, ry;
Window child;
XTranslateCoordinates(handle->display, handle->window, root, 0, 0, &rx, &ry, &child);
XTranslateCoordinates(handle->x11.display, handle->x11.window, root, 0, 0, &rx, &ry, &child);
*x += rx;
*y += ry;
@@ -314,16 +314,16 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) {
long r;
sh.flags = 0;
XGetWMNormalHints(handle->display, handle->window, &sh, &r);
XGetWMNormalHints(handle->x11.display, handle->x11.window, &sh, &r);
sh.flags |= PPosition;
sh.x = x;
sh.y = y;
XMoveWindow(handle->display, handle->window, x, y);
XSetWMNormalHints(handle->display, handle->window, &sh);
XMoveWindow(handle->x11.display, handle->x11.window, x, y);
XSetWMNormalHints(handle->x11.display, handle->x11.window, &sh);
XSync(handle->display, False);
XSync(handle->x11.display, False);
}
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
@@ -331,7 +331,7 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) {
long r;
sh.flags = 0;
XGetWMNormalHints(handle->display, handle->window, &sh, &r);
XGetWMNormalHints(handle->x11.display, handle->x11.window, &sh, &r);
if(w < 2) w = 2;
if(h < 2) h = 2;
@@ -340,16 +340,16 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) {
sh.width = w;
sh.height = h;
XResizeWindow(handle->display, handle->window, w, h);
XSetWMNormalHints(handle->display, handle->window, &sh);
XResizeWindow(handle->x11.display, handle->x11.window, w, h);
XSetWMNormalHints(handle->x11.display, handle->x11.window, &sh);
destroy_pixmap(handle);
create_pixmap(handle);
handle->width = w;
handle->height = h;
handle->x11.width = w;
handle->x11.height = h;
XSync(handle->display, False);
XSync(handle->x11.display, False);
MwLLForceRender(handle);
}
@@ -359,13 +359,13 @@ static void MwLLFreeColorImpl(MwLLColor color) {
}
static void MwLLSetBackgroundImpl(MwLL handle, MwLLColor color) {
XSetWindowBackground(handle->display, handle->window, color->pixel);
XSetWindowBackground(handle->x11.display, handle->x11.window, color->x11.pixel);
}
static int MwLLPendingImpl(MwLL handle) {
XEvent ev;
if(XCheckTypedWindowEvent(handle->display, handle->window, ClientMessage, &ev) || XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
XPutBackEvent(handle->display, &ev);
if(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
XPutBackEvent(handle->x11.display, &ev);
return 1;
}
return 0;
@@ -373,7 +373,7 @@ static int MwLLPendingImpl(MwLL handle) {
static void MwLLNextEventImpl(MwLL handle) {
XEvent ev;
while(XCheckTypedWindowEvent(handle->display, handle->window, ClientMessage, &ev) || XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
while(XCheckTypedWindowEvent(handle->x11.display, handle->x11.window, ClientMessage, &ev) || XCheckWindowEvent(handle->x11.display, handle->x11.window, mask, &ev)) {
int render = 0;
if(ev.type == Expose) {
render = 1;
@@ -393,7 +393,7 @@ static void MwLLNextEventImpl(MwLL handle) {
p.button = MwLLMouseWheelDown;
}
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime);
MwLLDispatch(handle, down, &p);
} else if(ev.type == ButtonRelease) {
@@ -414,16 +414,16 @@ static void MwLLNextEventImpl(MwLL handle) {
MwLLDispatch(handle, up, &p);
} else if(ev.type == ConfigureNotify) {
if(handle->width != (unsigned int)ev.xconfigure.width || handle->height != (unsigned int)ev.xconfigure.height) {
if(handle->x11.width != (unsigned int)ev.xconfigure.width || handle->x11.height != (unsigned int)ev.xconfigure.height) {
MwLLDispatch(handle, resize, NULL);
destroy_pixmap(handle);
create_pixmap(handle);
render = 1;
}
handle->width = ev.xconfigure.width;
handle->height = ev.xconfigure.height;
handle->x11.width = ev.xconfigure.width;
handle->x11.height = ev.xconfigure.height;
} else if(ev.type == ClientMessage) {
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
if(ev.xclient.data.l[0] == (long)handle->x11.wm_delete) {
MwLLDispatch(handle, close, NULL);
}
} else if(ev.type == FocusIn) {
@@ -434,19 +434,19 @@ static void MwLLNextEventImpl(MwLL handle) {
MwPoint p;
XWindowAttributes attr;
XGetWindowAttributes(handle->display, handle->window, &attr);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &attr);
p.x = ev.xmotion.x;
p.y = ev.xmotion.y;
if(handle->grabbed) {
if(handle->x11.grabbed) {
p.x -= attr.width / 2;
p.y -= attr.height / 2;
}
MwLLDispatch(handle, move, &p);
if(handle->grabbed && (p.x != 0 || p.y != 0)) {
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
if(handle->x11.grabbed && (p.x != 0 || p.y != 0)) {
XWarpPointer(handle->x11.display, None, handle->x11.window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
}
} else if(ev.type == KeyPress || ev.type == KeyRelease) {
int n = -1;
@@ -519,16 +519,16 @@ static void MwLLNextEventImpl(MwLL handle) {
MwLLGetXYWH(handle, &x, &y, &w, &h);
MwLLDispatch(handle, draw, NULL);
if(handle->copy_buffer) {
XCopyArea(handle->display, handle->pixmap, handle->window, handle->gc, 0, 0, w, h, 0, 0);
XSetWindowBackgroundPixmap(handle->display, handle->window, handle->pixmap);
if(handle->common.copy_buffer) {
XCopyArea(handle->x11.display, handle->x11.pixmap, handle->x11.window, handle->x11.gc, 0, 0, w, h, 0, 0);
XSetWindowBackgroundPixmap(handle->x11.display, handle->x11.window, handle->x11.pixmap);
}
}
}
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
XSetStandardProperties(handle->display, handle->window, title, title, None, (char**)NULL, 0, NULL);
XSetStandardProperties(handle->x11.display, handle->x11.window, title, title, None, (char**)NULL, 0, NULL);
}
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
@@ -538,24 +538,25 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
int evbase, erbase;
XWindowAttributes attr;
r->raw = malloc(4 * width * height);
memcpy(r->raw, data, 4 * width * height);
r->common.raw = malloc(4 * width * height);
memcpy(r->common.raw, data, 4 * width * height);
XGetWindowAttributes(handle->display, handle->window, &attr);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &attr);
r->depth = attr.depth;
r->width = width;
r->height = height;
r->display = handle->display;
r->data = malloc(sizeof(unsigned long) * width * height);
r->handle = handle;
r->common.width = width;
r->common.height = height;
r->x11.depth = attr.depth;
r->x11.display = handle->x11.display;
r->x11.data = malloc(sizeof(unsigned long) * width * height);
r->x11.handle = handle;
#ifdef USE_XRENDER
r->use_xrender = XRenderQueryExtension(handle->display, &evbase, &erbase) ? 1 : 0;
r->x11.use_xrender = XRenderQueryExtension(handle->x11.display, &evbase, &erbase) ? 1 : 0;
#endif
r->image = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), r->depth, ZPixmap, 0, di, width, height, 32, width * 4);
r->mask = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 1, ZPixmap, 0, dm, width, height, 32, width * 4);
r->x11.image = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), r->x11.depth, ZPixmap, 0, di, width, height, 32, width * 4);
r->x11.mask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, dm, width, height, 32, width * 4);
MwLLPixmapUpdate(r);
return r;
@@ -563,37 +564,37 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
int y, x;
for(y = 0; y < r->height; y++) {
for(x = 0; x < r->width; x++) {
unsigned char* px = &r->raw[(y * r->width + x) * 4];
for(y = 0; y < r->common.height; y++) {
for(x = 0; x < r->common.width; x++) {
unsigned char* px = &r->common.raw[(y * r->common.width + x) * 4];
MwLLColor c = NULL;
unsigned long p;
c = MwLLAllocColor(r->handle, px[0], px[1], px[2]);
p = c->pixel;
c = MwLLAllocColor(r->x11.handle, px[0], px[1], px[2]);
p = c->x11.pixel;
MwLLFreeColor(c);
XPutPixel(r->image, x, y, p);
*(unsigned long*)(&r->data[(y * r->width + x) * sizeof(unsigned long)]) = (px[3] << 24) | p;
XPutPixel(r->x11.image, x, y, p);
*(unsigned long*)(&r->x11.data[(y * r->common.width + x) * sizeof(unsigned long)]) = (px[3] << 24) | p;
}
}
for(y = 0; y < r->height; y++) {
for(x = 0; x < r->width; x++) {
if(r->raw[(y * r->width + x) * 4 + 3]) {
XPutPixel(r->mask, x, y, 1);
for(y = 0; y < r->common.height; y++) {
for(x = 0; x < r->common.width; x++) {
if(r->common.raw[(y * r->common.width + x) * 4 + 3]) {
XPutPixel(r->x11.mask, x, y, 1);
} else {
XPutPixel(r->mask, x, y, 0);
XPutPixel(r->x11.mask, x, y, 0);
}
}
}
}
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
free(pixmap->raw);
XDestroyImage(pixmap->image);
XDestroyImage(pixmap->mask);
free(pixmap->data);
free(pixmap->common.raw);
XDestroyImage(pixmap->x11.image);
XDestroyImage(pixmap->x11.mask);
free(pixmap->x11.data);
free(pixmap);
}
@@ -601,35 +602,35 @@ static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
if(rect->width == 0 || rect->height == 0) return;
#ifdef USE_XRENDER
if(pixmap->image != NULL && pixmap->use_xrender) {
Pixmap px = XCreatePixmap(handle->display, handle->window, pixmap->width, pixmap->height, pixmap->depth);
Pixmap mask = XCreatePixmap(handle->display, handle->window, rect->width, rect->height, 1);
Pixmap pxsrc = XCreatePixmap(handle->display, handle->window, rect->width, rect->height, pixmap->depth);
GC maskgc = XCreateGC(handle->display, mask, 0, NULL);
XRenderPictFormat* format = XRenderFindStandardFormat(handle->display, PictStandardRGB24);
if(pixmap->x11.image != NULL && pixmap->x11.use_xrender) {
Pixmap px = XCreatePixmap(handle->x11.display, handle->x11.window, pixmap->common.width, pixmap->common.height, pixmap->x11.depth);
Pixmap mask = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, 1);
Pixmap pxsrc = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, pixmap->x11.depth);
GC maskgc = XCreateGC(handle->x11.display, mask, 0, NULL);
XRenderPictFormat* format = XRenderFindStandardFormat(handle->x11.display, PictStandardRGB24);
XRenderPictureAttributes attr;
Picture src, dest;
XTransform m;
double xsc = (double)pixmap->width / rect->width;
double ysc = (double)pixmap->height / rect->height;
double xsc = (double)pixmap->common.width / rect->width;
double ysc = (double)pixmap->common.height / rect->height;
char* dm = malloc(rect->width * rect->height * 4);
XImage* destmask;
int y, x;
destmask = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 1, ZPixmap, 0, dm, rect->width, rect->height, 32, rect->width * 4);
destmask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, dm, rect->width, rect->height, 32, rect->width * 4);
for(y = 0; y < (int)rect->height; y++) {
for(x = 0; x < (int)rect->width; x++) {
int sy = y * pixmap->height / rect->height;
int sx = x * pixmap->width / rect->width;
int sy = y * pixmap->common.height / rect->height;
int sx = x * pixmap->common.width / rect->width;
sy = (int)sy;
sx = (int)sx;
XPutPixel(destmask, x, y, XGetPixel(pixmap->mask, sx, sy));
XPutPixel(destmask, x, y, XGetPixel(pixmap->x11.mask, sx, sy));
}
}
XPutImage(handle->display, mask, maskgc, destmask, 0, 0, 0, 0, rect->width, rect->height);
XPutImage(handle->x11.display, mask, maskgc, destmask, 0, 0, 0, 0, rect->width, rect->height);
m.matrix[0][0] = XDoubleToFixed(xsc);
m.matrix[0][1] = XDoubleToFixed(0);
@@ -645,87 +646,87 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
memset(&attr, 0, sizeof(attr));
XPutImage(handle->display, px, handle->gc, pixmap->image, 0, 0, 0, 0, pixmap->width, pixmap->height);
XPutImage(handle->x11.display, px, handle->x11.gc, pixmap->x11.image, 0, 0, 0, 0, pixmap->common.width, pixmap->common.height);
src = XRenderCreatePicture(handle->display, px, format, 0, &attr);
dest = XRenderCreatePicture(handle->display, pxsrc, format, 0, &attr);
src = XRenderCreatePicture(handle->x11.display, px, format, 0, &attr);
dest = XRenderCreatePicture(handle->x11.display, pxsrc, format, 0, &attr);
XRenderSetPictureTransform(handle->display, src, &m);
XRenderComposite(handle->display, PictOpSrc, src, 0, dest, 0, 0, 0, 0, 0, 0, rect->width, rect->height);
XRenderSetPictureTransform(handle->x11.display, src, &m);
XRenderComposite(handle->x11.display, PictOpSrc, src, 0, dest, 0, 0, 0, 0, 0, 0, rect->width, rect->height);
XRenderFreePicture(handle->display, src);
XRenderFreePicture(handle->display, dest);
XRenderFreePicture(handle->x11.display, src);
XRenderFreePicture(handle->x11.display, dest);
XSetClipMask(handle->display, handle->gc, mask);
XSetClipOrigin(handle->display, handle->gc, rect->x, rect->y);
XCopyArea(handle->display, pxsrc, handle->pixmap, handle->gc, 0, 0, rect->width, rect->height, rect->x, rect->y);
XSetClipMask(handle->display, handle->gc, None);
XSetClipMask(handle->x11.display, handle->x11.gc, mask);
XSetClipOrigin(handle->x11.display, handle->x11.gc, rect->x, rect->y);
XCopyArea(handle->x11.display, pxsrc, handle->x11.pixmap, handle->x11.gc, 0, 0, rect->width, rect->height, rect->x, rect->y);
XSetClipMask(handle->x11.display, handle->x11.gc, None);
XDestroyImage(destmask);
XFreeGC(handle->display, maskgc);
XFreePixmap(handle->display, mask);
XFreePixmap(handle->display, px);
XFreePixmap(handle->display, pxsrc);
XFreeGC(handle->x11.display, maskgc);
XFreePixmap(handle->x11.display, mask);
XFreePixmap(handle->x11.display, px);
XFreePixmap(handle->x11.display, pxsrc);
} else
#endif
if(pixmap->image != NULL) {
if(pixmap->x11.image != NULL) {
XImage* dest;
XImage* destmask;
Pixmap mask = XCreatePixmap(handle->display, handle->window, rect->width, rect->height, 1);
GC maskgc = XCreateGC(handle->display, mask, 0, NULL);
Pixmap mask = XCreatePixmap(handle->x11.display, handle->x11.window, rect->width, rect->height, 1);
GC maskgc = XCreateGC(handle->x11.display, mask, 0, NULL);
char* di = malloc(rect->width * rect->height * 4);
char* dm = malloc(rect->width * rect->height * 4);
int y, x;
dest = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), pixmap->depth, ZPixmap, 0, di, rect->width, rect->height, 32, rect->width * 4);
destmask = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 1, ZPixmap, 0, dm, rect->width, rect->height, 32, rect->width * 4);
dest = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), pixmap->x11.depth, ZPixmap, 0, di, rect->width, rect->height, 32, rect->width * 4);
destmask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, dm, rect->width, rect->height, 32, rect->width * 4);
for(y = 0; y < (int)rect->height; y++) {
for(x = 0; x < (int)rect->width; x++) {
int sy = y * pixmap->height / rect->height;
int sx = x * pixmap->width / rect->width;
int sy = y * pixmap->common.height / rect->height;
int sx = x * pixmap->common.width / rect->width;
char* ipx;
char* opx;
sy = (int)sy;
sx = (int)sx;
ipx = &pixmap->image->data[(pixmap->width * sy + sx) * (pixmap->image->bitmap_unit / 8)];
opx = &di[(rect->width * y + x) * (pixmap->image->bitmap_unit / 8)];
memcpy(opx, ipx, pixmap->image->bitmap_unit / 8);
ipx = &pixmap->x11.image->data[(pixmap->common.width * sy + sx) * (pixmap->x11.image->bitmap_unit / 8)];
opx = &di[(rect->width * y + x) * (pixmap->x11.image->bitmap_unit / 8)];
memcpy(opx, ipx, pixmap->x11.image->bitmap_unit / 8);
XPutPixel(destmask, x, y, XGetPixel(pixmap->mask, sx, sy));
XPutPixel(destmask, x, y, XGetPixel(pixmap->x11.mask, sx, sy));
}
}
XPutImage(handle->display, mask, maskgc, destmask, 0, 0, 0, 0, rect->width, rect->height);
XPutImage(handle->x11.display, mask, maskgc, destmask, 0, 0, 0, 0, rect->width, rect->height);
XSetClipMask(handle->display, handle->gc, mask);
XSetClipOrigin(handle->display, handle->gc, rect->x, rect->y);
XPutImage(handle->display, handle->pixmap, handle->gc, dest, 0, 0, rect->x, rect->y, rect->width, rect->height);
XSetClipMask(handle->display, handle->gc, None);
XSetClipMask(handle->x11.display, handle->x11.gc, mask);
XSetClipOrigin(handle->x11.display, handle->x11.gc, rect->x, rect->y);
XPutImage(handle->x11.display, handle->x11.pixmap, handle->x11.gc, dest, 0, 0, rect->x, rect->y, rect->width, rect->height);
XSetClipMask(handle->x11.display, handle->x11.gc, None);
XDestroyImage(dest);
XDestroyImage(destmask);
XFreeGC(handle->display, maskgc);
XFreePixmap(handle->display, mask);
XFreeGC(handle->x11.display, maskgc);
XFreePixmap(handle->x11.display, mask);
}
}
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
unsigned long* icon = malloc((2 + pixmap->width * pixmap->height) * sizeof(*icon));
unsigned long* icon = malloc((2 + pixmap->common.width * pixmap->common.height) * sizeof(*icon));
int i;
Atom atom = XInternAtom(handle->display, "_NET_WM_ICON", False);
Atom atom = XInternAtom(handle->x11.display, "_NET_WM_ICON", False);
icon[0] = pixmap->width;
icon[1] = pixmap->height;
icon[0] = pixmap->common.width;
icon[1] = pixmap->common.height;
for(i = 0; i < pixmap->width * pixmap->height; i++) {
icon[2 + i] = *(unsigned long*)(&pixmap->data[i * sizeof(unsigned long)]);
for(i = 0; i < pixmap->common.width * pixmap->common.height; i++) {
icon[2 + i] = *(unsigned long*)(&pixmap->x11.data[i * sizeof(unsigned long)]);
}
XChangeProperty(handle->display, handle->window, atom, 6, 32, PropModeReplace, (unsigned char*)icon, 2 + pixmap->width * pixmap->height);
XChangeProperty(handle->x11.display, handle->x11.window, atom, 6, 32, PropModeReplace, (unsigned char*)icon, 2 + pixmap->common.width * pixmap->common.height);
free(icon);
}
@@ -735,8 +736,8 @@ static void MwLLForceRenderImpl(MwLL handle) {
memset(&ev, 0, sizeof(ev));
ev.type = Expose;
ev.xexpose.window = handle->window;
XSendEvent(handle->display, handle->window, False, ExposureMask, &ev);
ev.xexpose.window = handle->x11.window;
XSendEvent(handle->x11.display, handle->x11.window, False, ExposureMask, &ev);
}
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
@@ -744,12 +745,12 @@ static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
int y, x, ys, xs;
char* di = malloc(MwCursorDataHeight * MwCursorDataHeight * 4);
char* dm = malloc(MwCursorDataHeight * MwCursorDataHeight * 4);
XImage* cimage = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 1, ZPixmap, 0, di, MwCursorDataHeight, MwCursorDataHeight, 32, MwCursorDataHeight * 4);
XImage* cmask = XCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 1, ZPixmap, 0, dm, MwCursorDataHeight, MwCursorDataHeight, 32, MwCursorDataHeight * 4);
Pixmap pimage = XCreatePixmap(handle->display, handle->window, MwCursorDataHeight, MwCursorDataHeight, 1);
Pixmap pmask = XCreatePixmap(handle->display, handle->window, MwCursorDataHeight, MwCursorDataHeight, 1);
GC imagegc = XCreateGC(handle->display, pimage, 0, NULL);
GC maskgc = XCreateGC(handle->display, pmask, 0, NULL);
XImage* cimage = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, di, MwCursorDataHeight, MwCursorDataHeight, 32, MwCursorDataHeight * 4);
XImage* cmask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, dm, MwCursorDataHeight, MwCursorDataHeight, 32, MwCursorDataHeight * 4);
Pixmap pimage = XCreatePixmap(handle->x11.display, handle->x11.window, MwCursorDataHeight, MwCursorDataHeight, 1);
Pixmap pmask = XCreatePixmap(handle->x11.display, handle->x11.window, MwCursorDataHeight, MwCursorDataHeight, 1);
GC imagegc = XCreateGC(handle->x11.display, pimage, 0, NULL);
GC maskgc = XCreateGC(handle->x11.display, pmask, 0, NULL);
XColor cfg, cbg;
xs = -mask->x + image->x;
@@ -781,22 +782,22 @@ static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
cfg.red = 65535;
cfg.green = 65535;
cfg.blue = 65535;
XAllocColor(handle->display, handle->colormap, &cfg);
XAllocColor(handle->x11.display, handle->x11.colormap, &cfg);
cbg.red = 0;
cbg.green = 0;
cbg.blue = 0;
XAllocColor(handle->display, handle->colormap, &cbg);
XAllocColor(handle->x11.display, handle->x11.colormap, &cbg);
XPutImage(handle->display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(handle->display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(handle->x11.display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(handle->x11.display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
cur = XCreatePixmapCursor(handle->display, pimage, pmask, &cfg, &cbg, xs, ys);
XDefineCursor(handle->display, handle->window, cur);
XFreeCursor(handle->display, cur);
cur = XCreatePixmapCursor(handle->x11.display, pimage, pmask, &cfg, &cbg, xs, ys);
XDefineCursor(handle->x11.display, handle->x11.window, cur);
XFreeCursor(handle->x11.display, cur);
XFreePixmap(handle->display, pimage);
XFreePixmap(handle->display, pmask);
XFreePixmap(handle->x11.display, pimage);
XFreePixmap(handle->x11.display, pmask);
XDestroyImage(cimage);
XDestroyImage(cmask);
@@ -809,18 +810,18 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
unsigned int nchild;
XWindowAttributes xwa;
handle->top = 1;
handle->x11.top = 1;
XQueryTree(handle->display, handle->window, &root, &parent, &children, &nchild);
XQueryTree(handle->x11.display, handle->x11.window, &root, &parent, &children, &nchild);
if(children != NULL) XFree(children);
XTranslateCoordinates(handle->display, parent, RootWindow(handle->display, DefaultScreen(handle->display)), 0, 0, &x, &y, &child);
XTranslateCoordinates(handle->x11.display, parent, RootWindow(handle->x11.display, DefaultScreen(handle->x11.display)), 0, 0, &x, &y, &child);
XGetWindowAttributes(handle->display, handle->window, &xwa);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
if(xwa.map_state == IsViewable) wait_unmap(handle);
XReparentWindow(handle->display, handle->window, RootWindow(handle->display, DefaultScreen(handle->display)), x + point->x, y + point->y);
XReparentWindow(handle->x11.display, handle->x11.window, RootWindow(handle->x11.display, DefaultScreen(handle->x11.display)), x + point->x, y + point->y);
if(xwa.map_state == IsViewable) wait_map(handle, 0, 0);
}
@@ -829,23 +830,23 @@ static void MwLLShowImpl(MwLL handle, int show) {
if(show) {
wait_map(handle, 0, 0);
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime);
} else {
wait_unmap(handle);
}
}
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
Atom wndtype = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE", False);
Atom wnddlg = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
Atom wndstate = XInternAtom(handle->display, "_NET_WM_STATE", False);
Atom wndmodal = XInternAtom(handle->display, "_NET_WM_STATE_MODAL", False);
Atom wndtype = XInternAtom(handle->x11.display, "_NET_WM_WINDOW_TYPE", False);
Atom wnddlg = XInternAtom(handle->x11.display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
Atom wndstate = XInternAtom(handle->x11.display, "_NET_WM_STATE", False);
Atom wndmodal = XInternAtom(handle->x11.display, "_NET_WM_STATE_MODAL", False);
XSetTransientForHint(handle->display, handle->window, parent->window);
XChangeProperty(handle->display, handle->window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wnddlg, 1);
XChangeProperty(handle->display, handle->window, wndstate, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmodal, 1);
XSetTransientForHint(handle->x11.display, handle->x11.window, parent->x11.window);
XChangeProperty(handle->x11.display, handle->x11.window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wnddlg, 1);
XChangeProperty(handle->x11.display, handle->x11.window, wndstate, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmodal, 1);
XUnmapWindow(handle->display, handle->window);
XUnmapWindow(handle->x11.display, handle->x11.window);
wait_map(handle, 1, 0);
}
@@ -854,49 +855,49 @@ static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int
XSizeHints* hints = XAllocSizeHints();
long ret;
XGetWMSizeHints(handle->display, handle->window, hints, &ret, XA_WM_NORMAL_HINTS);
XGetWMSizeHints(handle->x11.display, handle->x11.window, hints, &ret, XA_WM_NORMAL_HINTS);
hints->flags |= PMinSize | PMaxSize;
hints->min_width = minx;
hints->min_height = miny;
hints->max_width = maxx;
hints->max_height = maxy;
XSetWMSizeHints(handle->display, handle->window, hints, XA_WM_NORMAL_HINTS);
XSetWMSizeHints(handle->x11.display, handle->x11.window, hints, XA_WM_NORMAL_HINTS);
XFree(hints);
XUnmapWindow(handle->display, handle->window);
XUnmapWindow(handle->x11.display, handle->x11.window);
wait_map(handle, 1, 0);
}
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
Atom atom = XInternAtom(handle->display, "_MOTIF_WM_HINTS", 0);
Atom atom = XInternAtom(handle->x11.display, "_MOTIF_WM_HINTS", 0);
mwm_hints_t hints;
hints.flags = MWM_HINTS_DECORATIONS;
hints.decorations = toggle ? 0 : 1;
XChangeProperty(handle->display, handle->window, atom, atom, 32, PropModeReplace, (unsigned char*)&hints, 5);
XChangeProperty(handle->x11.display, handle->x11.window, atom, atom, 32, PropModeReplace, (unsigned char*)&hints, 5);
XUnmapWindow(handle->display, handle->window);
XUnmapWindow(handle->x11.display, handle->x11.window);
wait_map(handle, 1, 0);
}
static void MwLLFocusImpl(MwLL handle) {
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime);
}
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
XWindowAttributes attr;
XGetWindowAttributes(handle->display, handle->window, &attr);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &attr);
if(toggle) {
handle->grabbed = 1;
handle->x11.grabbed = 1;
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
XWarpPointer(handle->x11.display, None, handle->x11.window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
} else {
handle->grabbed = 0;
handle->x11.grabbed = 0;
}
}
@@ -913,14 +914,14 @@ static char* MwLLGetClipboardImpl(MwLL handle) {
XEvent* queue = NULL;
char* r = NULL;
clip = XInternAtom(handle->display, "CLIPBOARD", 0);
clip = XInternAtom(handle->x11.display, "CLIPBOARD", 0);
target = XA_STRING;
prop = XInternAtom(handle->display, "XSEL_DATA", 0);
prop = XInternAtom(handle->x11.display, "XSEL_DATA", 0);
XConvertSelection(handle->display, clip, target, prop, handle->window, CurrentTime);
XConvertSelection(handle->x11.display, clip, target, prop, handle->x11.window, CurrentTime);
while(1) {
XNextEvent(handle->display, &ev);
XNextEvent(handle->x11.display, &ev);
if(ev.type == SelectionNotify) {
if(ev.xselection.selection == clip && ev.xselection.property != 0) {
Atom t;
@@ -940,7 +941,7 @@ static char* MwLLGetClipboardImpl(MwLL handle) {
}
while(arrlen(queue) > 0) {
XPutBackEvent(handle->display, &queue[0]);
XPutBackEvent(handle->x11.display, &queue[0]);
arrdel(queue, 0);
}
arrfree(queue);
@@ -950,13 +951,13 @@ static char* MwLLGetClipboardImpl(MwLL handle) {
static void MwLLMakeToolWindowImpl(MwLL handle) {
XSetWindowAttributes xswa;
Atom wndtype = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE", False);
Atom wndmenu = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE_MENU", False);
Atom wndtype = XInternAtom(handle->x11.display, "_NET_WM_WINDOW_TYPE", False);
Atom wndmenu = XInternAtom(handle->x11.display, "_NET_WM_WINDOW_TYPE_MENU", False);
xswa.override_redirect = True;
XChangeWindowAttributes(handle->display, handle->window, CWOverrideRedirect, &xswa);
XChangeProperty(handle->display, handle->window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
XChangeWindowAttributes(handle->x11.display, handle->x11.window, CWOverrideRedirect, &xswa);
XChangeProperty(handle->x11.display, handle->x11.window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
}
static int MwLLX11CallInitImpl(void) {

View File

@@ -13,23 +13,21 @@
#include <X11/extensions/Xrender.h>
#endif
struct _MwLL {
struct _MwLLX11 {
struct _MwLLCommon common;
unsigned int width;
unsigned int height;
Display* display;
Window window;
Pixmap pixmap;
GC gc;
Colormap colormap;
void* user;
Atom wm_delete;
int copy_buffer;
XIM xim;
XIC xic;
unsigned int width;
unsigned int height;
MwLLHandler handler;
int top;
int grabbed;
@@ -46,17 +44,14 @@ struct _MwLL {
unsigned long blue_shift;
};
struct _MwLLColor {
struct _MwLLX11Color {
struct _MwLLCommonColor common;
unsigned long pixel;
int red;
int green;
int blue;
};
struct _MwLLPixmap {
int width;
int height;
unsigned char* raw;
struct _MwLLX11Pixmap {
struct _MwLLCommonPixmap common;
int depth;
unsigned char* data;

View File

@@ -4,7 +4,7 @@
#include "../external/stb_ds.h"
static void lldrawhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
(void)data;
@@ -14,7 +14,7 @@ static void lldrawhandler(MwLL handle, void* data) {
}
static void lluphandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwLLMouse* p = data;
if(p->button == MwLLMouseLeft) h->pressed = 0;
@@ -27,7 +27,7 @@ static void lluphandler(MwLL handle, void* data) {
}
static void lldownhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwLLMouse* p = data;
if(p->button == MwLLMouseLeft) h->pressed = 1;
h->mouse_point.x = p->point.x;
@@ -38,7 +38,7 @@ static void lldownhandler(MwLL handle, void* data) {
}
static void llresizehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
int i;
(void)data;
@@ -50,7 +50,7 @@ static void llresizehandler(MwLL handle, void* data) {
}
static void llclosehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
int n;
(void)data;
@@ -68,7 +68,7 @@ static void llclosehandler(MwLL handle, void* data) {
}
static void llmovehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwPoint* p = data;
h->mouse_point.x = p->x;
h->mouse_point.y = p->y;
@@ -78,7 +78,7 @@ static void llmovehandler(MwLL handle, void* data) {
}
static void llkeyhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
int key = *(int*)data;
MwDispatch3(h, key, key);
@@ -86,19 +86,19 @@ static void llkeyhandler(MwLL handle, void* data) {
}
static void llkeyrelhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwDispatchUserHandler(h, MwNkeyReleaseHandler, data);
}
static void llfocusinhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwDispatchUserHandler(h, MwNfocusInHandler, data);
}
static void llfocusouthandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwWidget h = (MwWidget)handle->common.user;
MwDispatchUserHandler(h, MwNfocusOutHandler, data);
}
@@ -133,17 +133,17 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
if(parent == NULL) arrput(h->tick_list, h);
if(h->lowlevel != NULL) {
h->lowlevel->user = h;
h->lowlevel->handler->draw = lldrawhandler;
h->lowlevel->handler->up = lluphandler;
h->lowlevel->handler->down = lldownhandler;
h->lowlevel->handler->resize = llresizehandler;
h->lowlevel->handler->close = llclosehandler;
h->lowlevel->handler->move = llmovehandler;
h->lowlevel->handler->key = llkeyhandler;
h->lowlevel->handler->key_released = llkeyrelhandler;
h->lowlevel->handler->focus_in = llfocusinhandler;
h->lowlevel->handler->focus_out = llfocusouthandler;
h->lowlevel->common.user = h;
h->lowlevel->common.handler->draw = lldrawhandler;
h->lowlevel->common.handler->up = lluphandler;
h->lowlevel->common.handler->down = lldownhandler;
h->lowlevel->common.handler->resize = llresizehandler;
h->lowlevel->common.handler->close = llclosehandler;
h->lowlevel->common.handler->move = llmovehandler;
h->lowlevel->common.handler->key = llkeyhandler;
h->lowlevel->common.handler->key_released = llkeyrelhandler;
h->lowlevel->common.handler->focus_in = llfocusinhandler;
h->lowlevel->common.handler->focus_out = llfocusouthandler;
}
if(parent != NULL) arrput(parent->children, h);

View File

@@ -246,9 +246,9 @@ static void color_display_text_change(MwWidget handle, void* user,
color = MwParseColor(handle, hexColor);
fr = color->red > 128 ? 0 : 255;
fg = color->green > 128 ? 0 : 255;
fb = color->blue > 128 ? 0 : 255;
fr = color->common.red > 128 ? 0 : 255;
fg = color->common.green > 128 ? 0 : 255;
fb = color->common.blue > 128 ? 0 : 255;
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
MwSetText(picker->color_display, MwNbackground, hexColor);
@@ -257,9 +257,9 @@ static void color_display_text_change(MwWidget handle, void* user,
MwSetText(picker->color_display_text, MwNbackground, hexColor);
MwSetText(picker->color_display_text, MwNtext, hexColor);
picker->chosen_color.red = color->red;
picker->chosen_color.green = color->green;
picker->chosen_color.blue = color->blue;
picker->chosen_color.red = color->common.red;
picker->chosen_color.green = color->common.green;
picker->chosen_color.blue = color->common.blue;
MwLLFreeColor(color);
}

View File

@@ -63,9 +63,9 @@ MwLLColor MwParseColor(MwWidget handle, const char* text) {
}
MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b) {
int cr = color->red + r;
int cg = color->green + g;
int cb = color->blue + b;
int cr = color->common.red + r;
int cg = color->common.green + g;
int cb = color->common.blue + b;
if(cr < 0) cr = 0;
if(cg < 0) cg = 0;
@@ -110,9 +110,9 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken);
for(x = 0; x < rect->width; x++) {
int idx = ((y * rect->width) + x) * 4;
data[idx] = col->red;
data[idx + 1] = col->green;
data[idx + 2] = col->blue;
data[idx] = col->common.red;
data[idx + 1] = col->common.green;
data[idx + 2] = col->common.blue;
data[idx + 3] = 255;
}
MwLLFreeColor(col);
@@ -651,9 +651,9 @@ MwLLPixmap MwLoadRaw(MwWidget handle, unsigned char* rgb, int width, int height)
pout[1] = pin[1] * a;
pout[2] = pin[2] * a;
pout[0] += base->red * (1 - a);
pout[1] += base->green * (1 - a);
pout[2] += base->blue * (1 - a);
pout[0] += base->common.red * (1 - a);
pout[1] += base->common.green * (1 - a);
pout[2] += base->common.blue * (1 - a);
pout[3] = 255;
}
}
@@ -671,10 +671,10 @@ void MwReloadRaw(MwWidget handle, unsigned char* rgb, int width, int height, MwL
int i;
MwLLColor base = handle->bgcolor == NULL ? MwParseColor(handle, MwGetText(handle, MwNbackground)) : handle->bgcolor;
memset(px->raw, 0, width * height * 4);
memset(px->common.raw, 0, width * height * 4);
for(i = 0; i < width * height; i++) {
unsigned char* pin = &rgb[i * 4];
unsigned char* pout = &px->raw[i * 4];
unsigned char* pout = &px->common.raw[i * 4];
double a = pin[3];
a /= 255;
@@ -683,9 +683,9 @@ void MwReloadRaw(MwWidget handle, unsigned char* rgb, int width, int height, MwL
pout[1] = pin[1] * a;
pout[2] = pin[2] * a;
pout[0] += base->red * (1 - a);
pout[1] += base->green * (1 - a);
pout[2] += base->blue * (1 - a);
pout[0] += base->common.red * (1 - a);
pout[1] += base->common.green * (1 - a);
pout[2] += base->common.blue * (1 - a);
pout[3] = 255;
}
}
@@ -696,9 +696,9 @@ void MwReloadRaw(MwWidget handle, unsigned char* rgb, int width, int height, MwL
}
void MwGetColor(MwLLColor color, int* red, int* green, int* blue) {
*red = color->red;
*green = color->green;
*blue = color->blue;
*red = color->common.red;
*green = color->common.green;
*blue = color->common.blue;
}
MwLLPixmap MwLoadIcon(MwWidget handle, unsigned int* data) {
@@ -771,9 +771,9 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
shput(c, k, v);
ind = shgeti(c, k);
c[ind].r = color->red;
c[ind].g = color->green;
c[ind].b = color->blue;
c[ind].r = color->common.red;
c[ind].g = color->common.green;
c[ind].b = color->common.blue;
c[ind].a = 255;
MwLLFreeColor(color);

View File

@@ -48,10 +48,10 @@ char* (*MwLLGetClipboard)(MwLL handle);
void (*MwLLMakeToolWindow)(MwLL handle);
void MwLLCreateCommon(MwLL handle) {
handle->handler = malloc(sizeof(*handle->handler));
memset(handle->handler, 0, sizeof(*handle->handler));
handle->common.handler = malloc(sizeof(*handle->common.handler));
memset(handle->common.handler, 0, sizeof(*handle->common.handler));
}
void MwLLDestroyCommon(MwLL handle) {
free(handle->handler);
free(handle->common.handler);
}

View File

@@ -60,9 +60,9 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
for(x = 0; x < FontWidth; x++) {
unsigned char* ppx = &px[((sy + y) * tw + sx + x) * 4];
if((bold ? MwBoldFontData : MwFontData)[out].data[y] & (1 << ((FontWidth - 1) - x))) {
ppx[0] = color->red;
ppx[1] = color->green;
ppx[2] = color->blue;
ppx[0] = color->common.red;
ppx[1] = color->common.green;
ppx[2] = color->common.blue;
ppx[3] = 255;
} else {
ppx[0] = 0;
@@ -131,9 +131,9 @@ static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
int oy = (ttf->ascent * ttf->scale) + y0 + cy;
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->red;
opx[1] = color->green;
opx[2] = color->blue;
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = out[cy * ow + cx];
}
}
@@ -216,9 +216,9 @@ static int ttf_MwDrawText(MwWidget handle, MwPoint* point, const char* text, int
int oy = th - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * 14 / ttf->face->units_per_EM);
unsigned char* opx = &px[(oy * tw + ox) * 4];
opx[0] = color->red;
opx[1] = color->green;
opx[2] = color->blue;
opx[0] = color->common.red;
opx[1] = color->common.green;
opx[2] = color->common.blue;
opx[3] = bmp->buffer[cy * bmp->pitch + cx];
}
}

View File

@@ -28,15 +28,15 @@ static void draw(MwWidget handle) {
int ow = r.width;
int oh = r.height;
double sw = (double)ow / px->width;
double sh = (double)oh / px->height;
double sw = (double)ow / px->common.width;
double sh = (double)oh / px->common.height;
if(sw < sh) {
r.width = px->width * sw;
r.height = px->height * sw;
r.width = px->common.width * sw;
r.height = px->common.height * sw;
} else {
r.width = px->width * sh;
r.height = px->height * sh;
r.width = px->common.width * sh;
r.height = px->common.height * sh;
}
r.width -= MwDefaultBorderWidth(handle) * 2;
r.height -= MwDefaultBorderWidth(handle) * 2;

View File

@@ -223,10 +223,10 @@ static void frame_draw(MwWidget handle) {
}
if(lb->list[i].pixmap != NULL) {
MwRect r2;
int h = (lb->list[i].pixmap->height > MwTextHeight(handle, "M")) ? MwTextHeight(handle, "M") : lb->list[i].pixmap->height;
int h = (lb->list[i].pixmap->common.height > MwTextHeight(handle, "M")) ? MwTextHeight(handle, "M") : lb->list[i].pixmap->common.height;
r2.x = MwDefaultBorderWidth(handle);
r2.y = p.y + (MwTextHeight(handle, "M") - h) / 2;
r2.width = h * lb->list[i].pixmap->width / lb->list[i].pixmap->height;
r2.width = h * lb->list[i].pixmap->common.width / lb->list[i].pixmap->common.height;
r2.height = h;
MwLLDrawPixmap(handle->lowlevel, &r2, lb->list[i].pixmap);
}

View File

@@ -55,7 +55,7 @@ static int create(MwWidget handle) {
pfd.cDepthBits = 32;
pfd.cColorBits = 32;
o->dc = GetDC(handle->lowlevel->hWnd);
o->dc = GetDC(handle->lowlevel->gdi.hWnd);
pf = ChoosePixelFormat(o->dc, &pfd);
SetPixelFormat(o->dc, pf, &pfd);
@@ -93,11 +93,11 @@ static int create(MwWidget handle) {
o->glXGetProcAddress = (MWglXGetProcAddress)dlsym(o->lib, "glXGetProcAddress");
/* XXX: fix this */
o->visual = o->glXChooseVisual(handle->lowlevel->display, DefaultScreen(handle->lowlevel->display), attribs);
o->gl = o->glXCreateContext(handle->lowlevel->display, o->visual, NULL, GL_TRUE);
o->visual = o->glXChooseVisual(handle->lowlevel->x11.display, DefaultScreen(handle->lowlevel->x11.display), attribs);
o->gl = o->glXCreateContext(handle->lowlevel->x11.display, o->visual, NULL, GL_TRUE);
#endif
handle->internal = o;
handle->lowlevel->copy_buffer = 0;
handle->internal = o;
handle->lowlevel->common.copy_buffer = 0;
MwSetDefault(handle);
@@ -113,8 +113,8 @@ static void destroy(MwWidget handle) {
FreeLibrary(o->lib);
#else
o->glXMakeCurrent(handle->lowlevel->display, None, NULL);
o->glXDestroyContext(handle->lowlevel->display, o->gl);
o->glXMakeCurrent(handle->lowlevel->x11.display, None, NULL);
o->glXDestroyContext(handle->lowlevel->x11.display, o->gl);
dlclose(o->lib);
#endif
@@ -126,7 +126,7 @@ static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
#ifdef _WIN32
o->wglMakeCurrent(o->dc, o->gl);
#else
o->glXMakeCurrent(handle->lowlevel->display, handle->lowlevel->window, o->gl);
o->glXMakeCurrent(handle->lowlevel->x11.display, handle->lowlevel->x11.window, o->gl);
#endif
}
@@ -137,7 +137,7 @@ static void mwOpenGLSwapBufferImpl(MwWidget handle) {
#else
(void)o;
o->glXSwapBuffers(handle->lowlevel->display, handle->lowlevel->window);
o->glXSwapBuffers(handle->lowlevel->x11.display, handle->lowlevel->x11.window);
#endif
}

View File

@@ -136,7 +136,7 @@ static int create(MwWidget handle) {
return 1;
}
handle->lowlevel->copy_buffer = 0;
handle->lowlevel->common.copy_buffer = 0;
handle->internal = o;
MwSetDefault(handle);
@@ -313,8 +313,8 @@ static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
.pNext = NULL,
.flags = 0,
.dpy = handle->lowlevel->display,
.window = handle->lowlevel->window,
.dpy = handle->lowlevel->x11.display,
.window = handle->lowlevel->x11.window,
};
VK_CMD(_vkCreateXlibSurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface));
#endif