fix cursor thing for x11/gdi, also format
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-24 04:26:26 +09:00
commit 6d7fe3271f
Signed by: nishi
GPG key ID: 27EF69B208EB9343
8 changed files with 231 additions and 228 deletions

View file

@ -12,78 +12,82 @@
static double deg = 0;
static void draw(void) {
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(deg, 1, 0, 0);
glRotatef(deg, 0, 1, 0);
glRotatef(deg, 0, 0, 1);
glPushMatrix();
glRotatef(deg, 1, 0, 0);
glRotatef(deg, 0, 1, 0);
glRotatef(deg, 0, 0, 1);
for (i = 0; i < 6; i++) {
if (i == 0)
glColor3f(1, 0, 0);
if (i == 1)
glColor3f(0, 1, 0);
if (i == 2)
glColor3f(1, 1, 0);
if (i == 3)
glColor3f(0, 0, 1);
if (i == 4)
glColor3f(1, 0, 1);
if (i == 5)
glColor3f(0, 1, 1);
for(i = 0; i < 6; i++) {
if(i == 0)
glColor3f(1, 0, 0);
if(i == 1)
glColor3f(0, 1, 0);
if(i == 2)
glColor3f(1, 1, 0);
if(i == 3)
glColor3f(0, 0, 1);
if(i == 4)
glColor3f(1, 0, 1);
if(i == 5)
glColor3f(0, 1, 1);
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 1, -1);
glVertex3f(-1, 1, 1);
glVertex3f(1, 1, 1);
glVertex3f(1, 1, -1);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0, 1, 0);
glVertex3f(-1, 1, -1);
glVertex3f(-1, 1, 1);
glVertex3f(1, 1, 1);
glVertex3f(1, 1, -1);
glEnd();
if (i < 3)
glRotatef(90, 0, 0, 1);
if (i == 3)
glRotatef(90, 1, 0, 0);
if (i == 4)
glRotatef(180, 0, 0, 1);
}
glPopMatrix();
if(i < 3)
glRotatef(90, 0, 0, 1);
if(i == 3)
glRotatef(90, 1, 0, 0);
if(i == 4)
glRotatef(180, 0, 0, 1);
}
glPopMatrix();
}
static void idle(void) { deg += 1.0; }
static void idle(void) {
deg += 1.0;
}
static void reshape(int width, int height) {
GLfloat lpos[4];
GLfloat lpos[4];
lpos[0] = 1;
lpos[1] = 1;
lpos[2] = 1;
lpos[3] = 0;
lpos[0] = 1;
lpos[1] = 1;
lpos[2] = 1;
lpos[3] = 0;
glViewport(0, 0, width, height);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)width / height, 1, 100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)width / height, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
}
static void init(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
}
static void key(int k) { (void)k; }
static void key(int k) {
(void)k;
}

View file

@ -23,9 +23,9 @@
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject {
NSApplication *appl;
NSApplication* appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)appl;
@end
@interface MilskoCocoaWindow : NSWindow {
@ -34,9 +34,9 @@
// Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject {
MilskoCocoaWindow *w;
MilskoCocoaWindow* w;
}
- (MilskoCocoaWindowDelegate *)initWithWin:(MilskoCocoaWindow *)win;
- (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win;
@end
/*
@ -52,139 +52,138 @@
retrieved appropriately.
*/
@interface MilskoFakePointer : NSView {
void *ptr;
void* ptr;
}
- (void)setPointer:(void *)ptr;
- (void *)pointer;
- (void)setPointer:(void*)ptr;
- (void*)pointer;
@end
@interface MilskoCocoaPixmap : NSObject {
MwBool valid;
int width;
int height;
unsigned char *buf;
NSImage *image;
NSBitmapImageRep *rep;
MwBool valid;
int width;
int height;
unsigned char* buf;
NSImage* image;
NSBitmapImageRep* rep;
}
+ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char *)data;
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char*)data;
- (void)destroy;
/* using @property to create instance variables fucks up 10.4 gcc for some
* reason? */
- (NSImage *)image;
- (NSImage*)image;
@end
@interface MilskoCocoaView : NSView {
NSBitmapImageRep *rep;
NSGraphicsContext *context;
MwBool valid;
CGColorSpaceRef space;
CGDataProviderRef provider;
float width;
float height;
NSBitmapImageRep* rep;
NSGraphicsContext* context;
MwBool valid;
CGColorSpaceRef space;
CGDataProviderRef provider;
float width;
float height;
}
- (void)initRepAndContextWithWidth:(float)w Height:(float)h;
- (NSGraphicsContext *)context;
- (NSGraphicsContext*)context;
- (void)destroy;
- (NSBitmapImageRep *)getRep;
- (NSBitmapImageRep*)getRep;
@end
@interface MilskoCocoa : NSObject {
NSApplication *application;
MwBool _forceRender;
MilskoCocoaWindow *window;
NSRect rect;
MilskoCocoaView *view;
MwLL parent;
MilskoFakePointer *handle;
unsigned int strHash;
NSEvent *lastEvent;
NSApplication* application;
MwBool _forceRender;
MilskoCocoaWindow* window;
NSRect rect;
MilskoCocoaView* view;
MwLL parent;
MilskoFakePointer* handle;
unsigned int strHash;
NSEvent* lastEvent;
MilskoCocoaPixmap *cursorPixmap;
NSCursor *cursor;
NSModalSession modalSession;
MwBool pointerLocked;
MwBool mouseMoved;
MilskoCocoaPixmap* cursorPixmap;
NSCursor* cursor;
NSModalSession modalSession;
MwBool pointerLocked;
MwBool mouseMoved;
}
+ (MilskoCocoa *)newWithParent:(MwLL)parent
x:(int)x
y:(int)y
width:(int)width
height:(int)height
handle:(MwLL)handle;
- (void)polygonWithPoints:(MwPoint *)points
points_count:(int)points_count
color:(MwLLColor)color;
- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color;
- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h;
+ (MilskoCocoa*)newWithParent:(MwLL)parent
x:(int)x
y:(int)y
width:(int)width
height:(int)height
handle:(MwLL)handle;
- (void)polygonWithPoints:(MwPoint*)points
points_count:(int)points_count
color:(MwLLColor)color;
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color;
- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h;
- (void)setX:(int)x Y:(int)y;
- (void)setW:(int)w H:(int)h;
- (int)pending;
- (void)eventProcess:(NSEvent *)ev;
- (void)handleKeyEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)eventProcess:(NSEvent*)ev;
- (void)handleKeyEvent:(NSEvent*)ev ll:(MwLL)ll;
- (void)handleMouseEvent:(NSEvent*)ev ll:(MwLL)ll;
- (void)getNextEvent;
- (void)setTitle:(const char *)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect;
- (void)setTitle:(const char*)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect;
- (void)setIcon:(MwLLPixmap)pixmap;
- (void)forceRender;
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask;
- (void)detachWithPoint:(MwPoint *)point;
- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask;
- (void)detachWithPoint:(MwPoint*)point;
- (void)show:(int)show;
- (void)makePopupWithParent:(MwLL)parent;
- (void)setSizeHintsWithMinX:(int)minx
MinY:(int)miny
MaxX:(int)maxx
MaxY:(int)maxy;
MinY:(int)miny
MaxX:(int)maxx
MaxY:(int)maxy;
- (void)makeBorderless:(int)toggle;
- (void)focus;
- (void)grabPointer:(int)toggle;
- (void)setClipboard:(const char *)text;
- (void)setClipboard:(const char*)text;
- (void)makeToolWindow;
- (void)getCursorCoord:(MwPoint *)point;
- (void)getScreenSize:(MwRect *)rect;
- (void)getCursorCoord:(MwPoint*)point;
- (void)getScreenSize:(MwRect*)rect;
- (void)destroy;
- (void)sendClipboardEvent;
- (MwLL)getParent;
- (NSView *)getView;
- (MilskoCocoaWindow *)getWindow;
- (NSView*)getView;
- (MilskoCocoaWindow*)getWindow;
- (MilskoFakePointer *)getHandle;
+ (void)eventCanceller:(MilskoCocoa *)this;
- (MilskoFakePointer*)getHandle;
+ (void)eventCanceller:(MilskoCocoa*)this;
@end
#define OBJC(x) x
#else
#define OBJC(x) void *
#define OBJC(x) void*
#endif
MWDECL int MwLLCocoaCallInit(void);
struct _MwLLCocoa {
struct _MwLLCommon common;
OBJC(MilskoCocoa *)
real;
struct _MwLLCommon common;
OBJC(MilskoCocoa*)
real;
};
struct _MwLLCocoaColor {
struct _MwLLCommonColor common;
struct _MwLLCommonColor common;
};
struct _MwLLCocoaPixmap {
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap *)
real;
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap*)
real;
};
#endif

View file

@ -43,7 +43,7 @@ MWDECL MwClass MwOpenGLClass;
* @param handle Widget
*/
MwInline void MwOpenGLMakeCurrent(MwWidget handle) {
MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL);
MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL);
}
/*!
@ -52,10 +52,10 @@ MwInline void MwOpenGLMakeCurrent(MwWidget handle) {
* @param name Name
* @return Procedure
*/
MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) {
void *out;
MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name);
return out;
MwInline void* MwOpenGLGetProcAddress(MwWidget handle, const char* name) {
void* out;
MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name);
return out;
}
/*!
@ -63,7 +63,7 @@ MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) {
* @param handle Widget
*/
MwInline void MwOpenGLSwapBuffer(MwWidget handle) {
MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL);
MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL);
}
#ifdef __cplusplus

View file

@ -37,7 +37,7 @@ if (grep(/^wayland$/, @backends)) {
}
scan_wayland_protocol("stable", "xdg-shell", "");
scan_wayland_protocol("stable", "viewporter", "");
scan_wayland_protocol("stable", "viewporter", "");
scan_wayland_protocol("stable", "tablet", "-v2");
scan_wayland_protocol("staging", "xdg-toplevel-icon", "-v1");
scan_wayland_protocol("staging", "cursor-shape", "-v1");
@ -55,7 +55,7 @@ if (grep(/^cocoa$/, @backends)) {
new_object("src/widget/opengl_cocoa.m");
}
# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this
# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this
add_cflags("-DGL_SILENCE_DEPRECATION");
$gl_libs = "-framework OpenGL";

View file

@ -621,7 +621,7 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) {
}
}
cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
cursor = CreateCursor(GetModuleHandle(NULL), xs - image->x, ys + (MwCursorDataHeight + image->y), MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
free(dimage);
free(dmask);

View file

@ -849,7 +849,7 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) {
XPutImage(display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs, ys);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs - image->x, ys + (MwCursorDataHeight + image->y));
XFreePixmap(display, pimage);
XFreePixmap(display, pmask);

View file

@ -7,124 +7,125 @@
#import <mach-o/dyld.h>
@interface MacOpenGLWidget : NSObject {
NSOpenGLPixelFormat *pixelFormat;
NSOpenGLContext *glc;
MilskoCocoa *_win;
NSOpenGLPixelFormat* pixelFormat;
NSOpenGLContext* glc;
MilskoCocoa* _win;
}
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w;
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w;
- (void)destroy;
- (void)makeCurrent;
- (void)swapBuffer;
- (void *)getProcAddressWithName:(const char *)name;
- (void*)getProcAddressWithName:(const char*)name;
@end
static int create(MwWidget handle) {
void *r = NULL;
MwWidget w = handle;
void* r = NULL;
MwWidget w = handle;
int x = MwGetInteger(w, MwNx);
int y = MwGetInteger(w, MwNy);
int width = MwGetInteger(w, MwNwidth);
int height = MwGetInteger(w, MwNheight);
int x = MwGetInteger(w, MwNx);
int y = MwGetInteger(w, MwNy);
int width = MwGetInteger(w, MwNwidth);
int height = MwGetInteger(w, MwNheight);
printf("%d %d\n", width, height);
printf("%d %d\n", width, height);
handle->internal =
[[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real];
handle->lowlevel->common.copy_buffer = 0;
handle->internal =
[[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real];
handle->lowlevel->common.copy_buffer = 0;
MwSetDefault(handle);
MwSetDefault(handle);
while (w->parent != NULL)
w = w->parent;
while(w->parent != NULL)
w = w->parent;
w->berserk++;
w->berserk++;
return 0;
return 0;
}
static void destroy(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal destroy];
[(MacOpenGLWidget*)handle->internal destroy];
}
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal makeCurrent];
[(MacOpenGLWidget*)handle->internal makeCurrent];
}
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal swapBuffer];
[(MacOpenGLWidget*)handle->internal swapBuffer];
}
static void *mwOpenGLGetProcAddressImpl(MwWidget handle, const char *name) {
return [(MacOpenGLWidget *)handle->internal getProcAddressWithName:name];
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
return [(MacOpenGLWidget*)handle->internal getProcAddressWithName:name];
}
static void func_handler(MwWidget handle, const char *name, void *out,
va_list va) {
if (strcmp(name, "mwOpenGLMakeCurrent") == 0) {
mwOpenGLMakeCurrentImpl(handle);
}
if (strcmp(name, "mwOpenGLSwapBuffer") == 0) {
mwOpenGLSwapBufferImpl(handle);
}
if (strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char *_name = va_arg(va, const char *);
*(void **)out = mwOpenGLGetProcAddressImpl(handle, _name);
}
static void func_handler(MwWidget handle, const char* name, void* out,
va_list va) {
if(strcmp(name, "mwOpenGLMakeCurrent") == 0) {
mwOpenGLMakeCurrentImpl(handle);
}
if(strcmp(name, "mwOpenGLSwapBuffer") == 0) {
mwOpenGLSwapBufferImpl(handle);
}
if(strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char* _name = va_arg(va, const char*);
*(void**)out = mwOpenGLGetProcAddressImpl(handle, _name);
}
}
@implementation MacOpenGLWidget
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w {
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery, 0};
self->pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
self->glc =
[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
[self->glc setView:[w getView]];
self->_win = w;
return self;
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w {
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery, 0};
self->pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
self->glc =
[[NSOpenGLContext alloc] initWithFormat:pixelFormat
shareContext:nil];
[self->glc setView:[w getView]];
self->_win = w;
return self;
};
- (void)destroy {
};
- (void)makeCurrent {
[self->glc makeCurrentContext];
[self->glc makeCurrentContext];
};
- (void)swapBuffer {
[self->glc flushBuffer];
[self->glc flushBuffer];
};
- (void *)getProcAddressWithName:(const char *)name {
if (NSIsSymbolNameDefined(name)) {
return NSAddressOfSymbol(NSLookupAndBindSymbol(name));
} else {
return NULL;
}
- (void*)getProcAddressWithName:(const char*)name {
if(NSIsSymbolNameDefined(name)) {
return NSAddressOfSymbol(NSLookupAndBindSymbol(name));
} else {
return NULL;
}
};
@end
MwClassRec MwOpenGLClassRec = {create, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL, NULL, NULL, NULL};
MwClass MwOpenGLClass = &MwOpenGLClassRec;
MwClassRec MwOpenGLClassRec = {create, /* create */
destroy, /* destroy */
NULL, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL, /* mouse_down */
NULL, /* key */
func_handler, /* execute */
NULL, /* tick */
NULL, /* resize */
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL, NULL, NULL, NULL};
MwClass MwOpenGLClass = &MwOpenGLClassRec;

View file

@ -58,8 +58,7 @@ l(
l("");
c("Requirements");
l("");
l(
" Milsko requires either");
l(" Milsko requires either");
l(" * A Windows environment with GDI (so anything NT or 9x)");
l(" * A MacOS environment with Cocoa (10.4 or above supported)");
l(" * A Unix-like environment with X11 for runtime.");