From 03255843195d5fe6f270f35baa017e8d172a0f54 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 12 Apr 2026 00:27:04 +0900 Subject: [PATCH 01/21] fix document --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3bdf08e..8c1d005 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,11 @@ pipeline { when { branch "master" } + agent { + label "built-in" + } steps { + sh("rm -rf include/Mw/LowLevel/Wayland") sh("doxygen") sh("rm -rf /var/www/milsko-doxygen") sh("mv doxygen/html /var/www/milsko-doxygen") From 00397f17ea161d3659e8c484aaeab91fcf56414e Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 12 Apr 2026 06:44:35 +0900 Subject: [PATCH 02/21] update milsko.xml --- milsko.xml | 53 ++++++++++++++++--------------------------- src/backend/wayland.c | 2 +- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/milsko.xml b/milsko.xml index 51c065a..18caed3 100644 --- a/milsko.xml +++ b/milsko.xml @@ -40,21 +40,7 @@ - - - - + + + + @@ -80,38 +66,39 @@ - - + + - - - + + + - + - + - - + + + - - - - + + + + - + diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 0bd23a6..801c03f 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -1264,7 +1264,7 @@ static void update_buffer(MwLL self, struct _MwLLWaylandShmBuffer* buffer) { memcpy(buffer->buf, buffer->buf_back, buffer->buf_size); // Yes this is needed every time, it's how we fix weston. wl_surface_attach(buffer->surface, buffer->shm_buffer, 0, 0); - wl_surface_commit(buffer->surface); + wl_surface_commit(buffer->surface); } static void buffer_setup(struct _MwLLWaylandShmBuffer* buffer, MwU32 width, MwU32 height) { From 3852646ce30caf47b74a7be2ed388d2fd6d17ea1 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 12 Apr 2026 07:12:59 +0900 Subject: [PATCH 03/21] fix warning --- src/text/text.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/text/text.c b/src/text/text.c index f550195..fec0bb4 100644 --- a/src/text/text.c +++ b/src/text/text.c @@ -26,6 +26,7 @@ static int is_bold(MwWidget handle, MwFLFont ttf) { return s; } +#ifdef TTF static int is_monospace(MwWidget handle, MwFLFont ttf) { size_t u = (size_t)ttf; int s; @@ -36,6 +37,7 @@ static int is_monospace(MwWidget handle, MwFLFont ttf) { if(s == MwDEFAULT) return 0; return s; } +#endif #ifdef TTF From d1f351a7efb8a3b278e5684b801b07b11a92811f Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 12 Apr 2026 07:27:07 +0900 Subject: [PATCH 04/21] fix cmake --- examples/gldemos/CMakeLists.txt | 2 +- examples/vkdemos/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/gldemos/CMakeLists.txt b/examples/gldemos/CMakeLists.txt index 9afda19..122f62c 100644 --- a/examples/gldemos/CMakeLists.txt +++ b/examples/gldemos/CMakeLists.txt @@ -15,7 +15,7 @@ foreach(PATH IN LISTS EXAMPLES_GL_SOURCES) ${TARGET} PRIVATE Mw - OpenGL::GL + OpenGL::GL OpenGL::GLU ) if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") target_link_libraries( diff --git a/examples/vkdemos/CMakeLists.txt b/examples/vkdemos/CMakeLists.txt index 354bf36..a315bf9 100644 --- a/examples/vkdemos/CMakeLists.txt +++ b/examples/vkdemos/CMakeLists.txt @@ -3,10 +3,16 @@ file( EXAMPLES_VULKAN_SOURCES *.c ) +find_package(Vulkan) foreach(PATH IN LISTS EXAMPLES_VULKAN_SOURCES) get_filename_component(TARGET ${PATH} NAME_WE) add_executable(${TARGET} WIN32 MACOSX_BUNDLE ${PATH}) + target_include_directories( + ${TARGET} + PRIVATE + ${Vulkan_INCLUDE_DIR} + ) target_link_libraries( ${TARGET} PRIVATE From 2a7cf2de83d1fb5051013ccc988ec367564a932f Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Sat, 11 Apr 2026 18:26:15 -0500 Subject: [PATCH 05/21] x11: allow apple. --- src/backend/x11.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/x11.c b/src/backend/x11.c index 72e54f3..755da71 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -1292,7 +1292,11 @@ static int MwLLX11CallInitImpl(void) { return 1; } +#ifdef __APPLE__ + xsymtbl.lib_xlib = MwDynamicOpen("libX11.dylib"); +#else xsymtbl.lib_xlib = MwDynamicOpen("libX11.so"); +#endif if(!xsymtbl.lib_xlib) { return 1; } From c4f6d1eb14c94721fc4e18b76b4557c7def4b3e4 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Sat, 11 Apr 2026 18:30:00 -0500 Subject: [PATCH 06/21] Update src/core.c --- src/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core.c b/src/core.c index c8a5c12..b4b6743 100644 --- a/src/core.c +++ b/src/core.c @@ -856,15 +856,16 @@ MwWidget MwGetParent(MwWidget handle) { typedef int (*call_t)(void); int MwLibraryInit(void) { call_t calls[] = { +/* x11 has higher priority then cocoa until it works */ +#ifdef USE_X11 + MwLLX11CallInit, +#endif #ifdef USE_COCOA MwLLCocoaCallInit, #endif #ifdef USE_WAYLAND MwLLWaylandCallInit, #endif -#ifdef USE_X11 - MwLLX11CallInit, -#endif #ifdef USE_GDI MwLLGDICallInit, #endif From 0ab497ca8869bcc968d3e48ff5e3ea4c15c3c766 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 11:28:54 -0700 Subject: [PATCH 07/21] oops prioritize wayland --- src/backend/wayland.c | 7 +------ src/backend/x11.c | 3 --- src/core.c | 8 ++++---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 801c03f..148ca44 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -2575,7 +2575,6 @@ static int MwLLWaylandCallInitImpl(void) { /* * Order of precedence: * - MILSKO_BACKEND - * - XDG_SESSION_TYPE * - manually checking environment variables */ #ifdef __linux__ @@ -2583,11 +2582,7 @@ static int MwLLWaylandCallInitImpl(void) { if(getenv("MILSKO_BACKEND")) { loadWayland |= (strcmp(getenv("MILSKO_BACKEND"), "wayland") == 0); - } - if(getenv("XDG_SESSION_TYPE")) { - loadWayland |= (strcmp(getenv("XDG_SESSION_TYPE"), "wayland") == 0); - } - if(getenv("WAYLAND_DISPLAY")) { + } else if(getenv("WAYLAND_DISPLAY")) { loadWayland |= (getenv("WAYLAND_DISPLAY") != NULL); } diff --git a/src/backend/x11.c b/src/backend/x11.c index 755da71..4068186 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -1281,9 +1281,6 @@ static int MwLLX11CallInitImpl(void) { loadX11 |= (strcmp(getenv("MILSKO_BACKEND"), "x11") == 0); } - if(getenv("XDG_SESSION_TYPE")) { - loadX11 |= (strcmp(getenv("XDG_SESSION_TYPE"), "x11") == 0); - } if(getenv("DISPLAY")) { loadX11 |= (getenv("DISPLAY") != NULL); } diff --git a/src/core.c b/src/core.c index b4b6743..cdd0723 100644 --- a/src/core.c +++ b/src/core.c @@ -856,16 +856,16 @@ MwWidget MwGetParent(MwWidget handle) { typedef int (*call_t)(void); int MwLibraryInit(void) { call_t calls[] = { -/* x11 has higher priority then cocoa until it works */ +#ifdef USE_WAYLAND + MwLLWaylandCallInit, +#endif +/* x11 has higher priority then cocoa until it works */ #ifdef USE_X11 MwLLX11CallInit, #endif #ifdef USE_COCOA MwLLCocoaCallInit, #endif -#ifdef USE_WAYLAND - MwLLWaylandCallInit, -#endif #ifdef USE_GDI MwLLGDICallInit, #endif From 728983b92ccd4a79925b36f035b0cbdce003221c Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 13:46:25 -0700 Subject: [PATCH 08/21] fix builds on osx 10.4 --- configure | 4 +++- include/Mw/LowLevel/Cocoa.h | 23 +++++++++++------------ include/Mw/MachDep.h | 9 +++++++++ pl/utils.pl | 1 + src/backend/cocoa.m | 8 ++++++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 0371bcd..0c17663 100755 --- a/configure +++ b/configure @@ -38,7 +38,6 @@ require("./pl/utils.pl"); param_set("classic-theme", 0); param_set("stb-image", 1); -param_set("stb-truetype", 0); param_set("xrender", 1); param_set("opengl", 0); param_set("vulkan", 0); @@ -50,6 +49,9 @@ param_set("examples", 1); if($target ne "Darwin") { param_set("freetype2", 1); + param_set("stb-truetype", 0); +} else { + param_set("stb-truetype", 1); } my %features = ( diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index da104f0..6e51c30 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -86,18 +86,17 @@ @end @interface MilskoCocoaView : NSView { - NSBitmapImageRep* rep; - NSGraphicsContext* context; - MwBool valid; - CGColorSpaceRef space; - CGDataProviderRef provider; - NSRect givenRect; - float x; - float y; - float width; - float height; - MwBool _child; - IBOutlet NSViewController* viewController; + NSBitmapImageRep* rep; + NSGraphicsContext* context; + MwBool valid; + CGColorSpaceRef space; + CGDataProviderRef provider; + NSRect givenRect; + float x; + float y; + float width; + float height; + MwBool _child; } - (void)initRepAndContextWithWidth:(float)w Height:(float)h; diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index 61a6f90..50898f6 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -57,17 +57,26 @@ #define M_PI 3.14159265 #endif +/* Windows */ #if defined(_MILSKO) && defined(_WIN32) #define MWDECL extern __declspec(dllexport) #elif defined(_WIN32) #define MWDECL extern __declspec(dllimport) +/* GCC/Clang */ +/* First check if we have __has_attribute and can check for the existence of visibility */ #elif defined(__has_attribute) #if __has_attribute(visibility) #define MWDECL extern __attribute__((visibility("default"))) #else #define MWDECL extern #endif +/* It might be that we're on an old version of GCC (like the one Apple ships with older versions of Mac OS). + * If we're on gcc 3 or above, assume it's there + */ +#elif __GNUC__ >= 3 +#define MWDECL extern __attribute__((visibility("default"))) #else +/* all else fails */ #define MWDECL extern #endif diff --git a/pl/utils.pl b/pl/utils.pl index 70c0b51..9472123 100644 --- a/pl/utils.pl +++ b/pl/utils.pl @@ -55,6 +55,7 @@ sub new_object { my @l = glob($_[0]); foreach my $e (@l) { $e =~ s/\.(c|m)$/$object_suffix/; + print($e."\n"); push(@library_targets, $e); } } diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 04ce17e..195e339 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -665,6 +665,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { NSSize sz = [self->rep size]; MwLL ll = [((MilskoFakePointer*)[[[[self window] contentView] subviews] objectAtIndex:0]) pointer]; + NSRect bounds; + NSArray* subviews = [self subviews]; + int i; [super drawRect:dirtyRect]; if(!self->rep) { @@ -683,8 +686,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [self->rep drawInRect:dirtyRect]; - for(NSView* subview in [self subviews]) { - NSRect bounds = [subview bounds]; + for(i = 0; i < [subviews count]; i++) { + NSView* subview = [subviews objectAtIndex:i]; + bounds = [subview bounds]; [subview drawRect:bounds]; } From 14e908488c3f5ffa7e450e6380a318be97cb4d65 Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 16:09:28 -0700 Subject: [PATCH 09/21] mac --- include/Mw/LowLevel/Cocoa.h | 6 +++ src/backend/cocoa.m | 86 ++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 6e51c30..fc39b07 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -104,7 +104,11 @@ - (void)destroy; - (NSBitmapImageRep*)getRep; - (void)setChild; +- (void)drawRectSub:(NSRect)dirtyRect; +@end +@interface MilskoCocoaSubView : MilskoCocoaView { +} @end @interface MilskoCocoa : NSObject { @@ -125,6 +129,8 @@ MwBool pointerLocked; MwBool mouseMoved; + + MwBool rejectFirstTest; } + (MilskoCocoa*)newWithParent:(MwLL)parent diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 195e339..dc30287 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -116,8 +116,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { - (void)destroy { free(self->buf); [self->image removeRepresentation:self->rep]; - [self->image dealloc]; - [self->rep dealloc]; + [self->image release]; + [self->rep release]; self->image = NULL; self->rep = NULL; } @@ -134,7 +134,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { width:(int)width height:(int)height handle:(MwLL)r { - MilskoCocoa* c = [MilskoCocoa alloc]; + MilskoCocoa* c = [MilskoCocoa alloc]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [c retain]; /* @@ -156,7 +158,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { c->window = [[MilskoCocoaWindow alloc] initWithContentRect:rectFlip(c->rect) styleMask:(NSTitledWindowMask | - NSTexturedBackgroundWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) backing:NSBackingStoreBuffered @@ -190,15 +191,12 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { NSRect rect = localRectFlip(c->rect, p->view); c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; [c->view setBounds:c->rect]; - [c->view retain]; - [c->view setNeedsDisplay:TRUE]; [c->view setChild]; [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; [p->view addSubview:c->view]; - [p->window setContentView:p->view]; } [c->window setAcceptsMouseMovedEvents:MwTRUE]; @@ -219,6 +217,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { c->pointerLocked = MwFALSE; + [pool release]; return c; } @@ -331,7 +330,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { frame = localRectFlip(frame, parent->cocoa.real->view); [self->view setBounds:frame]; } - self->_eventsPending = MwTRUE; + // [self->view setNeedsDisplay:true]; + [self nudge]; }; - (void)setW:(int)w H:(int)h { NSRect frame = [self->window frame]; @@ -346,7 +346,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } else { [self->window setFrame:frame display:YES animate:false]; } - self->_eventsPending = MwTRUE; + [self nudge]; }; - (int)pending { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -360,12 +360,12 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { MwLL h = [self->handle pointer]; if(_forceRender) { MwLLDispatch(h, draw, NULL); - [self->view setNeedsDisplay:true]; + // [self->view setNeedsDisplay:true]; _forceRender = MwFALSE; } if(_eventsPending) { MwLLDispatch(h, draw, NULL); - [self->view setNeedsDisplay:true]; + // [self->view setNeedsDisplay:true]; _eventsPending = MwFALSE; } [self sendClipboardEvent]; @@ -579,9 +579,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { }; - (void)destroy { [self->handle release]; - [self->handle dealloc]; [self->window release]; - [self->window dealloc]; } - (MwLL)getParent { @@ -596,7 +594,13 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } - (void)nudge { + MwLL p = self->parent; self->_eventsPending = MwTRUE; + + if(p) { + [p->cocoa.real->view setNeedsDisplay:true]; + p = p->cocoa.real->parent; + } } - (void)pushCursor { @@ -661,15 +665,10 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } - (void)drawRect:(NSRect)dirtyRect { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSSize sz = [self->rep size]; - MwLL ll = [((MilskoFakePointer*)[[[[self window] contentView] subviews] - objectAtIndex:0]) pointer]; - NSRect bounds; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSArray* subviews = [self subviews]; int i; - [super drawRect:dirtyRect]; if(!self->rep) { if(dirtyRect.size.width && dirtyRect.size.height) { [self initRepAndContextWithWidth:dirtyRect.size.width @@ -682,22 +681,41 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } } - // MwLLDispatch(ll, draw, NULL); - - [self->rep drawInRect:dirtyRect]; + if(!_child) + [self->rep drawInRect:[self bounds]]; for(i = 0; i < [subviews count]; i++) { - NSView* subview = [subviews objectAtIndex:i]; - bounds = [subview bounds]; - [subview drawRect:bounds]; + MilskoCocoaView* subview = [subviews objectAtIndex:i]; + NSRect bounds = [subview bounds]; + if([subview respondsToSelector:@selector(drawRectSub:)]) { + [subview drawRectSub:bounds]; + } } - - [self->rep bitmapData]; - [pool release]; } +- (void)drawRectSub:(NSRect)dirtyRect { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + if(!self->rep) { + if(dirtyRect.size.width && dirtyRect.size.height) { + [self initRepAndContextWithWidth:dirtyRect.size.width + Height:dirtyRect.size.height]; + self->width = dirtyRect.size.width; + self->height = dirtyRect.size.height; + } else { + [pool release]; + return; + } + } + + [self->rep drawInRect:dirtyRect]; + + [pool release]; +}; + - (void)initRepAndContextWithWidth:(float)w Height:(float)h { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; self->rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:w @@ -712,10 +730,14 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { assert(self->rep); [self->rep retain]; + [self->rep setOpaque:MwFALSE]; + [self->rep setAlpha:MwTRUE]; + self->context = [NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep]; assert(self->context); [self->context retain]; + [pool release]; } - (void)destroy { @@ -1142,11 +1164,7 @@ static void MwLLFreeColorImpl(MwLLColor color) { } static int MwLLPendingImpl(MwLL handle) { - int p = [handle->cocoa.real pending]; - if(p) { - MwLLDispatch(handle, draw, NULL); - } - return p; + return [handle->cocoa.real pending]; } static void MwLLNextEventImpl(MwLL handle) { @@ -1186,7 +1204,7 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) { static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { MilskoCocoaPixmap* p = pixmap->cocoa.real; [p destroy]; - [p dealloc]; + [p release]; free(pixmap); } From f44a70d4ecc621897eb723eb30c848cb6235fd9d Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 16:21:30 -0700 Subject: [PATCH 10/21] mac: untested code but i'll fall asleep at night with this in the codebase compared to the other thing --- include/Mw/LowLevel/Cocoa.h | 1 - src/backend/cocoa.m | 51 +++++++++---------------------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index fc39b07..89e5f58 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -104,7 +104,6 @@ - (void)destroy; - (NSBitmapImageRep*)getRep; - (void)setChild; -- (void)drawRectSub:(NSRect)dirtyRect; @end @interface MilskoCocoaSubView : MilskoCocoaView { diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index dc30287..0f979b9 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -669,51 +669,24 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { NSArray* subviews = [self subviews]; int i; - if(!self->rep) { - if(dirtyRect.size.width && dirtyRect.size.height) { - [self initRepAndContextWithWidth:dirtyRect.size.width - Height:dirtyRect.size.height]; - self->width = dirtyRect.size.width; - self->height = dirtyRect.size.height; - } else { - [pool release]; - return; - } + if(self->rep) { + [self->rep release]; + } + if(dirtyRect.size.width && dirtyRect.size.height) { + [self initRepAndContextWithWidth:dirtyRect.size.width + Height:dirtyRect.size.height]; + self->width = dirtyRect.size.width; + self->height = dirtyRect.size.height; + } else { + [pool release]; + return; } - if(!_child) - [self->rep drawInRect:[self bounds]]; + [self->rep drawInRect:[self bounds]]; - for(i = 0; i < [subviews count]; i++) { - MilskoCocoaView* subview = [subviews objectAtIndex:i]; - NSRect bounds = [subview bounds]; - if([subview respondsToSelector:@selector(drawRectSub:)]) { - [subview drawRectSub:bounds]; - } - } [pool release]; } -- (void)drawRectSub:(NSRect)dirtyRect { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - if(!self->rep) { - if(dirtyRect.size.width && dirtyRect.size.height) { - [self initRepAndContextWithWidth:dirtyRect.size.width - Height:dirtyRect.size.height]; - self->width = dirtyRect.size.width; - self->height = dirtyRect.size.height; - } else { - [pool release]; - return; - } - } - - [self->rep drawInRect:dirtyRect]; - - [pool release]; -}; - - (void)initRepAndContextWithWidth:(float)w Height:(float)h { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; self->rep = From b661face2647645499a5d475ce1e99e0561d3138 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 16:43:31 -0700 Subject: [PATCH 11/21] mac: more untested changes but its just removing dead comments so i know this won't break anything --- src/backend/cocoa.m | 89 +++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 64 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 0f979b9..a66b31c 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -330,7 +330,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { frame = localRectFlip(frame, parent->cocoa.real->view); [self->view setBounds:frame]; } - // [self->view setNeedsDisplay:true]; [self nudge]; }; - (void)setW:(int)w H:(int)h { @@ -360,12 +359,10 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { MwLL h = [self->handle pointer]; if(_forceRender) { MwLLDispatch(h, draw, NULL); - // [self->view setNeedsDisplay:true]; _forceRender = MwFALSE; } if(_eventsPending) { MwLLDispatch(h, draw, NULL); - // [self->view setNeedsDisplay:true]; _eventsPending = MwFALSE; } [self sendClipboardEvent]; @@ -443,18 +440,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { }; - (void)forceRender { self->_forceRender = MwTRUE; - // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - // NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined - // location:NSMakePoint(0, 0) - // modifierFlags:0 - // timestamp:0 - // windowNumber:0 - // context:nil - // subtype:0 - // data1:0 - // data2:0]; - // [NSApp postEvent:event atStart:YES]; - // [pool release]; }; - (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask { int y, x, ys, xs; @@ -670,8 +655,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { int i; if(self->rep) { - [self->rep release]; - } + [self->rep release]; + } if(dirtyRect.size.width && dirtyRect.size.height) { [self initRepAndContextWithWidth:dirtyRect.size.width Height:dirtyRect.size.height]; @@ -993,7 +978,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { if([ptr isKindOfClass:[MilskoFakePointer class]]) { MwLL h = [(MilskoFakePointer*)ptr pointer]; MwLLDispatch(h, resize, NULL); - // MwLLDispatch(h, draw, NULL); } } return frameSize; @@ -1118,18 +1102,15 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) { static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* height) { - MilskoCocoa* h = handle->cocoa.real; - [h getX:x Y:y W:w H:height]; + [handle->cocoa.real getX:x Y:y W:w H:height]; } static void MwLLSetXYImpl(MwLL handle, int x, int y) { - MilskoCocoa* h = handle->cocoa.real; - [h setX:x Y:y]; + [handle->cocoa.real setX:x Y:y]; } static void MwLLSetWHImpl(MwLL handle, int w, int height) { - MilskoCocoa* h = handle->cocoa.real; - [h setW:w H:height]; + [handle->cocoa.real setW:w H:height]; } static void MwLLFreeColorImpl(MwLLColor color) { @@ -1141,13 +1122,11 @@ static int MwLLPendingImpl(MwLL handle) { } static void MwLLNextEventImpl(MwLL handle) { - MilskoCocoa* h = handle->cocoa.real; - [h getNextEvent]; + [handle->cocoa.real getNextEvent]; } static void MwLLSetTitleImpl(MwLL handle, const char* title) { - MilskoCocoa* h = handle->cocoa.real; - [h setTitle:title]; + [handle->cocoa.real setTitle:title]; } static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, @@ -1170,77 +1149,63 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, } static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) { - MilskoCocoaPixmap* p = pixmap->cocoa.real; - [p updateWithData:pixmap->common.raw]; + [pixmap->cocoa.real updateWithData:pixmap->common.raw]; } static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { - MilskoCocoaPixmap* p = pixmap->cocoa.real; - [p destroy]; - [p release]; + [pixmap->cocoa.real destroy]; + [pixmap->cocoa.real release]; free(pixmap); } static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { - MilskoCocoa* h = handle->cocoa.real; - [h drawPixmap:pixmap rect:rect]; + [handle->cocoa.real drawPixmap:pixmap rect:rect]; MwLLForceRender(handle); } static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { - MilskoCocoa* h = handle->cocoa.real; - [h setIcon:pixmap]; + [handle->cocoa.real setIcon:pixmap]; } static void MwLLForceRenderImpl(MwLL handle) { - MilskoCocoa* h = handle->cocoa.real; - [h forceRender]; + [handle->cocoa.real forceRender]; } static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) { - MilskoCocoa* h = handle->cocoa.real; - [h setCursor:image mask:mask]; + [handle->cocoa.real setCursor:image mask:mask]; } static void MwLLDetachImpl(MwLL handle, MwPoint* point) { - MilskoCocoa* h = handle->cocoa.real; - [h detachWithPoint:point]; + [handle->cocoa.real detachWithPoint:point]; } static void MwLLShowImpl(MwLL handle, int show) { - MilskoCocoa* h = handle->cocoa.real; - [h show:show]; + [handle->cocoa.real show:show]; } static void MwLLMakePopupImpl(MwLL handle, MwLL parent) { - MilskoCocoa* h = handle->cocoa.real; - [h makePopupWithParent:parent]; + [handle->cocoa.real makePopupWithParent:parent]; } static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) { - MilskoCocoa* h = handle->cocoa.real; - [h setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy]; + [handle->cocoa.real setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy]; } static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) { - MilskoCocoa* h = handle->cocoa.real; - [h makeBorderless:toggle]; + [handle->cocoa.real makeBorderless:toggle]; } static void MwLLFocusImpl(MwLL handle) { - MilskoCocoa* h = handle->cocoa.real; - [h focus]; + [handle->cocoa.real focus]; } static void MwLLGrabPointerImpl(MwLL handle, int toggle) { - MilskoCocoa* h = handle->cocoa.real; - [h grabPointer:toggle]; + [handle->cocoa.real grabPointer:toggle]; } static void MwLLSetClipboardImpl(MwLL handle, const char* text) { - MilskoCocoa* h = handle->cocoa.real; - [h setClipboard:text]; + [handle->cocoa.real setClipboard:text]; } static void MwLLGetClipboardImpl(MwLL handle) { @@ -1248,19 +1213,15 @@ static void MwLLGetClipboardImpl(MwLL handle) { } static void MwLLMakeToolWindowImpl(MwLL handle) { - - MilskoCocoa* h = handle->cocoa.real; - [h makeToolWindow]; + [handle->cocoa.real makeToolWindow]; } static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { - MilskoCocoa* h = handle->cocoa.real; - [h getCursorCoord:point]; + [handle->cocoa.real getCursorCoord:point]; } static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) { - MilskoCocoa* h = handle->cocoa.real; - [h getScreenSize:rect]; + [handle->cocoa.real getScreenSize:rect]; } static void MwLLBeginStateChangeImpl(MwLL handle) { From bb876b96201a93c1fe6a55583ebcd79a9842b27f Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 16:45:20 -0700 Subject: [PATCH 12/21] mac: only recreate rep if width/height is different. also untested but i'm confident in this --- src/backend/cocoa.m | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index a66b31c..6961a96 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -654,17 +654,19 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { NSArray* subviews = [self subviews]; int i; - if(self->rep) { - [self->rep release]; - } - if(dirtyRect.size.width && dirtyRect.size.height) { - [self initRepAndContextWithWidth:dirtyRect.size.width - Height:dirtyRect.size.height]; - self->width = dirtyRect.size.width; - self->height = dirtyRect.size.height; - } else { - [pool release]; - return; + if(self->width != dirtyRect.size.width || self->height != dirtyRect.size.height) { + if(self->rep) { + [self->rep release]; + } + if(dirtyRect.size.width && dirtyRect.size.height) { + [self initRepAndContextWithWidth:dirtyRect.size.width + Height:dirtyRect.size.height]; + self->width = dirtyRect.size.width; + self->height = dirtyRect.size.height; + } else { + [pool release]; + return; + } } [self->rep drawInRect:[self bounds]]; From a4c61b0e38c9737978e28014e38d5fc48fe02f06 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 17:44:27 -0700 Subject: [PATCH 13/21] gnustep support? --- configure | 17 ++++++++++------- include/Mw/LowLevel/Cocoa.h | 34 +++++++++++++--------------------- pl/rules.pl | 6 +++++- pl/utils.pl | 1 - src/backend/cocoa.m | 18 +++++++++--------- src/backend/x11.c | 3 +-- 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/configure b/configure index 0c17663..5551d4c 100755 --- a/configure +++ b/configure @@ -66,6 +66,7 @@ my %features = ( "shared" => "build shared library", "static" => "build static library", "wayland" => "enable wayland backend", + "gnustep" => "use gnustep", ); my @features_keys = ( "1classic-theme", "1stb-image", @@ -73,9 +74,16 @@ my @features_keys = ( "1opengl", "2xrender", "1vulkan", "2vulkan-string-helper", "1shared", "1static", - "1wayland", + "1wayland", "1gnustep", ); +if($target eq "Linux") { + param_set("x11", 1); + if(!param_get("tiny")){ + param_set("wayland", 1); + } +} + foreach my $l (@ARGV) { if ($l =~ /^--with-([^=]+)=(.+)$/) { param_set($1, $2); @@ -138,12 +146,7 @@ foreach my $l (@ARGV) { } } -if($target eq "Linux") { - param_set("x11", 1); - if(!param_get("tiny")){ - param_set("wayland", 1); - } -} + if (-f "./pl/ostype/${target}.pl") { require("./pl/ostype/${target}.pl"); diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 89e5f58..d31e590 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -15,12 +15,6 @@ #import #import -#ifdef __APPLE__ -#import -#else -#import -#endif - @interface MilskoCocoaApplication : NSApplication { MwBool doPending; } @@ -29,9 +23,9 @@ // Note: implements NSApplicationDelegate @interface MilskoCocoaApplicationDelegate : NSObject { - MilskoCocoaApplication* appl; + NSApplication* appl; } -- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)appl; +- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)appl; @end @interface MilskoCocoaWindow : NSWindow { @@ -40,7 +34,7 @@ // Note: implements NSWindowDelegate @interface MilskoCocoaWindowDelegate : NSObject { - MilskoCocoaWindow* w; + NSWindow* w; } - (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win; @end @@ -89,8 +83,6 @@ NSBitmapImageRep* rep; NSGraphicsContext* context; MwBool valid; - CGColorSpaceRef space; - CGDataProviderRef provider; NSRect givenRect; float x; float y; @@ -111,16 +103,16 @@ @end @interface MilskoCocoa : NSObject { - MilskoCocoaApplication* application; - MwBool _forceRender; - MwBool _eventsPending; - MilskoCocoaWindow* window; - NSRect rect; - MilskoCocoaView* view; - MwLL parent; - MilskoFakePointer* handle; - unsigned int strHash; - NSEvent* lastEvent; + NSApplication* application; + MwBool _forceRender; + MwBool _eventsPending; + MilskoCocoaWindow* window; + NSRect rect; + MilskoCocoaView* view; + MwLL parent; + MilskoFakePointer* handle; + unsigned int strHash; + NSEvent* lastEvent; MilskoCocoaPixmap* cursorPixmap; NSCursor* cursor; diff --git a/pl/rules.pl b/pl/rules.pl index bf18575..000a6fe 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -52,10 +52,14 @@ if (grep(/^wayland$/, @backends)) { $gl_libs = "-lGL -lGLU"; } -if (grep(/^cocoa$/, @backends)) { +if (grep(/^cocoa$/, @backends) || param_get("gnustep")) { add_cflags("-DUSE_COCOA"); new_object("src/backend/cocoa.m"); + if(param_get("gnustep")){ + add_ldflags("-lobjc -lgnustep-base -lm -lgnustep-gui"); + } + if (param_get("opengl")) { new_object("src/widget/opengl_cocoa.m"); } diff --git a/pl/utils.pl b/pl/utils.pl index 9472123..70c0b51 100644 --- a/pl/utils.pl +++ b/pl/utils.pl @@ -55,7 +55,6 @@ sub new_object { my @l = glob($_[0]); foreach my $e (@l) { $e =~ s/\.(c|m)$/$object_suffix/; - print($e."\n"); push(@library_targets, $e); } } diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 6961a96..7b28172 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -325,7 +325,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { if(!parent) { frame = rectFlip(frame); - [self->window setFrame:frame display:TRUE animate:TRUE]; + [self->window setFrame:frame display:MwTRUE animate:MwTRUE]; } else { frame = localRectFlip(frame, parent->cocoa.real->view); [self->view setBounds:frame]; @@ -367,6 +367,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } [self sendClipboardEvent]; +#ifdef __APPLE__ if(self->pointerLocked && [self->window isMainWindow] && self->lastEvent) { struct CGPoint pos; pos.x = [window frame].origin.x + [window frame].size.width / 2; @@ -374,6 +375,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { CGWarpMouseCursorPosition(pos); } +#endif [self->application updateWindows]; }; @@ -617,13 +619,12 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { @implementation MilskoCocoaView - (id)initWithFrame:(NSRect)frame { - givenRect = frame; - x = frame.origin.x; - y = frame.origin.y; - width = frame.size.width; - height = frame.size.height; - self = [super initWithFrame:frame]; - self->space = CGColorSpaceCreateDeviceRGB(); + givenRect = frame; + x = frame.origin.x; + y = frame.origin.y; + width = frame.size.width; + height = frame.size.height; + self = [super initWithFrame:frame]; if(width == 0 || height == 0) { self->rep = NULL; @@ -701,7 +702,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } - (void)destroy { - CGColorSpaceRelease(self->space); [self->rep release]; [self->context release]; } diff --git a/src/backend/x11.c b/src/backend/x11.c index 4068186..ad97d68 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -1280,8 +1280,7 @@ static int MwLLX11CallInitImpl(void) { if(getenv("MILSKO_BACKEND")) { loadX11 |= (strcmp(getenv("MILSKO_BACKEND"), "x11") == 0); - } - if(getenv("DISPLAY")) { + } else if(getenv("DISPLAY")) { loadX11 |= (getenv("DISPLAY") != NULL); } From 7d85a784f589a79d14bd3158a3a258d6175cefff Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 18:39:21 -0700 Subject: [PATCH 14/21] i think we're now linking to gnustep properly --- pl/rules.pl | 4 +++- src/backend/cocoa.m | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pl/rules.pl b/pl/rules.pl index 000a6fe..3d1f2c0 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -57,7 +57,9 @@ if (grep(/^cocoa$/, @backends) || param_get("gnustep")) { new_object("src/backend/cocoa.m"); if(param_get("gnustep")){ - add_ldflags("-lobjc -lgnustep-base -lm -lgnustep-gui"); + add_incdir2("-I/usr/GNUstep/System/Library/Headers"); + add_libdir("-L/usr/GNUstep/System/Library/Libraries"); + add_ldflags("-fblocks -lobjc -lgnustep-base -lm -lgnustep-gui"); } if (param_get("opengl")) { diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 7b28172..1048f82 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -151,7 +151,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { y = r ? ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.) : 0; } - c->application = [MilskoCocoaApplication sharedApplication]; + c->application = NSApp; c->rect = NSMakeRect(x, y, width, height); if(parent == NULL) { @@ -1235,6 +1235,8 @@ static void MwLLEndStateChangeImpl(MwLL handle) { } static int MwLLCocoaCallInitImpl(void) { + [NSApplication sharedApplication]; + return 0; } From 9283455cb971857e14e62f0aa594b4b4091ace0b Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Mon, 13 Apr 2026 20:07:00 -0700 Subject: [PATCH 15/21] links to gnustep but doesn't run --- configure | 2 -- include/Mw/LowLevel/Cocoa.h | 29 ++++++++++++++--------------- pl/rules.pl | 7 ++++--- src/backend/cocoa.m | 29 ++++++++++++++++------------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/configure b/configure index 5551d4c..5d98108 100755 --- a/configure +++ b/configure @@ -146,8 +146,6 @@ foreach my $l (@ARGV) { } } - - if (-f "./pl/ostype/${target}.pl") { require("./pl/ostype/${target}.pl"); } diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index d31e590..ff70295 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -23,9 +23,9 @@ // Note: implements NSApplicationDelegate @interface MilskoCocoaApplicationDelegate : NSObject { - NSApplication* appl; + MilskoCocoaApplication* appl; } -- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)appl; +- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)appl; @end @interface MilskoCocoaWindow : NSWindow { @@ -36,7 +36,7 @@ @interface MilskoCocoaWindowDelegate : NSObject { NSWindow* w; } -- (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win; +- (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win; @end /* @@ -103,16 +103,16 @@ @end @interface MilskoCocoa : NSObject { - NSApplication* application; - MwBool _forceRender; - MwBool _eventsPending; - MilskoCocoaWindow* window; - NSRect rect; - MilskoCocoaView* view; - MwLL parent; - MilskoFakePointer* handle; - unsigned int strHash; - NSEvent* lastEvent; + MilskoCocoaApplication* application; + MwBool _forceRender; + MwBool _eventsPending; + NSWindow* window; + NSRect rect; + MilskoCocoaView* view; + MwLL parent; + MilskoFakePointer* handle; + unsigned int strHash; + NSEvent* lastEvent; MilskoCocoaPixmap* cursorPixmap; NSCursor* cursor; @@ -163,14 +163,13 @@ - (MwLL)getParent; - (NSView*)getView; -- (MilskoCocoaWindow*)getWindow; +- (NSWindow*)getWindow; - (void)nudge; - (void)pushCursor; - (void)popCursor; - (MilskoFakePointer*)getHandle; -+ (void)eventCanceller:(MilskoCocoa*)this; @end #define OBJC(x) x diff --git a/pl/rules.pl b/pl/rules.pl index 3d1f2c0..6c23006 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -57,9 +57,10 @@ if (grep(/^cocoa$/, @backends) || param_get("gnustep")) { new_object("src/backend/cocoa.m"); if(param_get("gnustep")){ - add_incdir2("-I/usr/GNUstep/System/Library/Headers"); - add_libdir("-L/usr/GNUstep/System/Library/Libraries"); - add_ldflags("-fblocks -lobjc -lgnustep-base -lm -lgnustep-gui"); + add_incdir("-I".`gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS`); + add_libdir("-L".`gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES`); + add_cflags("-fobjc-runtime=gnustep-2.0 -fblocks"); + add_ldflags("-lobjc -lgnustep-base -lm -lgnustep-gui"); } if (param_get("opengl")) { diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index 1048f82..adf8f74 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -136,8 +136,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { handle:(MwLL)r { MilskoCocoa* c = [MilskoCocoa alloc]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - [c retain]; + c->application = (MilskoCocoaApplication*)[MilskoCocoaApplication sharedApplication]; + [c->application retain]; /* * MacOS doesn't really have a "default" window position, you're actually @@ -151,11 +152,10 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { y = r ? ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.) : 0; } - c->application = NSApp; - c->rect = NSMakeRect(x, y, width, height); + c->rect = NSMakeRect(x, y, width, height); if(parent == NULL) { - c->window = [[MilskoCocoaWindow alloc] + c->window = [[NSWindow alloc] initWithContentRect:rectFlip(c->rect) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | @@ -183,6 +183,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [c->application retain]; [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; + c->modalSession = [c->application beginModalSessionForWindow:c->window]; } else { MilskoCocoa* p = parent->cocoa.real; @@ -197,6 +198,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; [p->view addSubview:c->view]; + + c->modalSession = p->modalSession; } [c->window setAcceptsMouseMovedEvents:MwTRUE]; @@ -205,8 +208,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [c->handle setPointer:r]; [c->view addSubview:c->handle]; - c->modalSession = [c->application beginModalSessionForWindow:c->window]; - c->parent = parent; + c->parent = parent; c->_forceRender = MwTRUE; c->strHash = 0; @@ -350,7 +352,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { - (int)pending { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; MwBool isPending = [self->application pending]; - [NSApp runModalSession:self->modalSession]; + [self->application runModalSession:self->modalSession]; [pool release]; return _forceRender || _eventsPending || isPending; }; @@ -954,7 +956,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { @end @implementation MilskoCocoaApplicationDelegate -- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)_appl { +- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)_appl { self->appl = _appl; return self; } @@ -1001,10 +1003,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { // This will close/terminate the application when the main window is closed. - (void)windowWillClose:(NSNotification*)notification { (void)notification; - // MilskoCocoa *window = notification.object; - // MwLL handle = [window getHandle].pointer; - // MwLLDispatch(handle, close, NULL); - [NSApp terminate:nil]; + MilskoCocoa* window = notification.object; + MwLL handle = [window getHandle].pointer; + MwLLDispatch(handle, close, NULL); } - (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win { @@ -1235,7 +1236,9 @@ static void MwLLEndStateChangeImpl(MwLL handle) { } static int MwLLCocoaCallInitImpl(void) { - [NSApplication sharedApplication]; + printf("Using GNUStep Backend\n"); + + [MilskoCocoaApplication sharedApplication]; return 0; } From 522f32cfcdd1f0edc85ab429c447482058a201ec Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 21:19:09 -0700 Subject: [PATCH 16/21] mac: revert back to what i had before with drawing, i still don't know how to fix this but it's better then nothing --- src/backend/cocoa.m | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index adf8f74..c8fa2a9 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -657,10 +657,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { NSArray* subviews = [self subviews]; int i; - if(self->width != dirtyRect.size.width || self->height != dirtyRect.size.height) { - if(self->rep) { - [self->rep release]; - } + if(!self->rep) { if(dirtyRect.size.width && dirtyRect.size.height) { [self initRepAndContextWithWidth:dirtyRect.size.width Height:dirtyRect.size.height]; @@ -672,8 +669,13 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } } - [self->rep drawInRect:[self bounds]]; + [self->rep drawInRect:NSMakeRect(dirtyRect.origin.x, dirtyRect.origin.y, [self->rep pixelsWide], [self->rep pixelsHigh])]; + for(i = 0; i < [subviews count]; i++) { + MilskoCocoaView* subview = [subviews objectAtIndex:i]; + NSRect bounds = [subview bounds]; + [subview drawRect:bounds]; + } [pool release]; } @@ -1003,9 +1005,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { // This will close/terminate the application when the main window is closed. - (void)windowWillClose:(NSNotification*)notification { (void)notification; - MilskoCocoa* window = notification.object; - MwLL handle = [window getHandle].pointer; - MwLLDispatch(handle, close, NULL); + // MilskoCocoa* window = notification.object; + // MwLL handle = [window getHandle].pointer; + // MwLLDispatch(handle, close, NULL); } - (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win { @@ -1236,7 +1238,9 @@ static void MwLLEndStateChangeImpl(MwLL handle) { } static int MwLLCocoaCallInitImpl(void) { +#ifndef __APPLE__ printf("Using GNUStep Backend\n"); +#endif [MilskoCocoaApplication sharedApplication]; From 554e5cd5ddf711ebb8d69f06768de73eeb6d3afc Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 21:36:17 -0700 Subject: [PATCH 17/21] mac: merge all the MilskoCocoa* functions into the C Milsko functions that call them, cleaning up the codebase --- include/Mw/LowLevel/Cocoa.h | 37 +- src/backend/cocoa.m | 820 +++++++++++++++++------------------- 2 files changed, 377 insertions(+), 480 deletions(-) diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index ff70295..3577ad0 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -61,6 +61,7 @@ @end @interface MilskoCocoaPixmap : NSObject { + @public MwBool valid; int width; int height; @@ -103,6 +104,7 @@ @end @interface MilskoCocoa : NSObject { + @public MilskoCocoaApplication* application; MwBool _forceRender; MwBool _eventsPending; @@ -123,41 +125,6 @@ MwBool rejectFirstTest; } - -+ (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)getNextEvent; -- (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)show:(int)show; -- (void)makePopupWithParent:(MwLL)parent; -- (void)setSizeHintsWithMinX:(int)minx - 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)makeToolWindow; -- (void)getCursorCoord:(MwPoint*)point; -- (void)getScreenSize:(MwRect*)rect; - (void)destroy; - (void)sendClipboardEvent; diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index c8fa2a9..b43aef2 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -127,261 +127,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { @end @implementation MilskoCocoa - -+ (MilskoCocoa*)newWithParent:(MwLL)parent - x:(int)x - y:(int)y - width:(int)width - height:(int)height - handle:(MwLL)r { - MilskoCocoa* c = [MilskoCocoa alloc]; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - [c retain]; - c->application = (MilskoCocoaApplication*)[MilskoCocoaApplication sharedApplication]; - [c->application retain]; - - /* - * MacOS doesn't really have a "default" window position, you're actually - * meant to center the window yourself, so if the user passes MwDEFAULT - * respond appropriately. Also for child windows just have it be 0. - */ - if(x == MwDEFAULT) { - x = r ? ([[NSScreen mainScreen] frame].size.width / 2.) - (width / 2.) : 0; - } - if(y == MwDEFAULT) { - y = r ? ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.) - : 0; - } - c->rect = NSMakeRect(x, y, width, height); - - if(parent == NULL) { - c->window = [[NSWindow alloc] - initWithContentRect:rectFlip(c->rect) - styleMask:(NSTitledWindowMask | - NSClosableWindowMask | NSMiniaturizableWindowMask | - NSResizableWindowMask) - backing:NSBackingStoreBuffered - defer:NO]; - [c->window - setDelegate:[[MilskoCocoaWindowDelegate alloc] initWithWin:c->window]]; - [c->window retain]; - - [c->window makeKeyAndOrderFront:c->application]; - [c->window makeFirstResponder:c->view]; - - c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect]; - [c->view retain]; - [c->window setContentView:c->view]; - - if([c->application respondsToSelector:@selector(setActivationPolicy:)]) { - [c->application - setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */]; - } - [c->application activateIgnoringOtherApps:MwTRUE]; - [c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc] - initWithAppl:c->application]]; - [c->application retain]; - - [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; - c->modalSession = [c->application beginModalSessionForWindow:c->window]; - } else { - MilskoCocoa* p = parent->cocoa.real; - - c->window = p->window; - - NSRect rect = localRectFlip(c->rect, p->view); - c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; - [c->view setBounds:c->rect]; - [c->view retain]; - [c->view setChild]; - - [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; - - [p->view addSubview:c->view]; - - c->modalSession = p->modalSession; - } - [c->window setAcceptsMouseMovedEvents:MwTRUE]; - - c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)]; - [c->handle retain]; - [c->handle setPointer:r]; - [c->view addSubview:c->handle]; - - c->parent = parent; - - c->_forceRender = MwTRUE; - c->strHash = 0; - - c->cursorPixmap = NULL; - - [c->application finishLaunching]; - - c->pointerLocked = MwFALSE; - - [pool release]; - return c; -} - -- (void)polygonWithPoints:(MwPoint*)points - points_count:(int)points_count - color:(MwLLColor)color { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSGraphicsContext* ctx = [self->view context]; - if(ctx) { - int i; - NSBezierPath* path = [NSBezierPath bezierPath]; - /* whatever rect we use for coordinate flipping */ - NSRect _rect = parent ? [self->view bounds] : [self->window frame]; - - NSColor* nscolor = - [NSColor colorWithCalibratedRed:color->common.red / 255. - green:color->common.green / 255. - blue:color->common.blue / 255. - alpha:1.0]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:ctx]; - - [nscolor setFill]; - for(i = 0; i < points_count; i++) { - NSPoint p = localPointFlip(NSMakePoint(points[i].x, points[i].y), self->view); - if(i == 0) { - [path moveToPoint:p]; - } else { - [path lineToPoint:p]; - } - } - - [path closePath]; - [path fill]; - - [NSGraphicsContext restoreGraphicsState]; - - [self->view setNeedsDisplay:YES]; - } - [pool release]; -}; -- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSGraphicsContext* ctx = [self->view context]; - if(ctx) { - int i; - NSBezierPath* path = [NSBezierPath bezierPath]; - /* whatever rect we use for coordinate flipping */ - NSRect _rect = parent ? [self->view bounds] : [self->window frame]; - - NSColor* nscolor = - [NSColor colorWithCalibratedRed:color->common.red / 255. - green:color->common.green / 255. - blue:color->common.blue / 255. - alpha:1.0]; - - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:ctx]; - - [nscolor setFill]; - for(i = 0; i < 2; i++) { - NSPoint p = localPointFlip(NSMakePoint(points[i].x, points[i].y), self->view); - if(i == 0) { - [path moveToPoint:p]; - } else { - [path lineToPoint:p]; - } - } - - [path closePath]; - [path stroke]; - - [NSGraphicsContext restoreGraphicsState]; - - [self->view setNeedsDisplay:YES]; - } - [pool release]; -}; -- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h { - NSRect frame; - if(parent) { - frame = [self->view frame]; - } else { - frame = [self->window frame]; - } - frame = rectFlip(frame); - - *x = frame.origin.x; - *y = frame.origin.y; - - *w = frame.size.width; - *h = frame.size.height; -}; -- (void)setX:(int)x Y:(int)y { - NSRect frame; - if(parent) { - frame = [self->view frame]; - } else { - frame = [self->window frame]; - } - - frame.origin.x = x; - frame.origin.y = y; - - if(!parent) { - frame = rectFlip(frame); - [self->window setFrame:frame display:MwTRUE animate:MwTRUE]; - } else { - frame = localRectFlip(frame, parent->cocoa.real->view); - [self->view setBounds:frame]; - } - [self nudge]; -}; -- (void)setW:(int)w H:(int)h { - NSRect frame = [self->window frame]; - frame.size.width = w; - frame.size.height = h; - - self->rect = frame; - - [self->view setFrameSize:frame.size]; - if(self->parent) { - [self->view setFrame:frame]; - } else { - [self->window setFrame:frame display:YES animate:false]; - } - [self nudge]; -}; -- (int)pending { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - MwBool isPending = [self->application pending]; - [self->application runModalSession:self->modalSession]; - [pool release]; - return _forceRender || _eventsPending || isPending; -}; - -- (void)getNextEvent { - MwLL h = [self->handle pointer]; - if(_forceRender) { - MwLLDispatch(h, draw, NULL); - _forceRender = MwFALSE; - } - if(_eventsPending) { - MwLLDispatch(h, draw, NULL); - _eventsPending = MwFALSE; - } - [self sendClipboardEvent]; - -#ifdef __APPLE__ - if(self->pointerLocked && [self->window isMainWindow] && self->lastEvent) { - struct CGPoint pos; - pos.x = [window frame].origin.x + [window frame].size.width / 2; - pos.y = [window frame].origin.y + [window frame].size.height / 2; - - CGWarpMouseCursorPosition(pos); - } -#endif - - [self->application updateWindows]; -}; - - (void)sendClipboardEvent { /*NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; @@ -413,159 +158,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [pool release];*/ } -- (void)setTitle:(const char*)title { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - [self->window - setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; - [pool release]; -}; -- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)_rect { - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - MilskoCocoaPixmap* p = pixmap->cocoa.real; - NSGraphicsContext* ctx = [self->view context]; - if(ctx) { - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:ctx]; - - [[p image] - drawInRect:localRectFlip(NSMakeRect(_rect->x, _rect->y, _rect->width, _rect->height), self->view) - fromRect:NSZeroRect - operation:NSCompositeSourceOver - fraction:1.0]; - - [NSGraphicsContext restoreGraphicsState]; - - [self->view setNeedsDisplay:YES]; - } - [pool release]; -}; -- (void)setIcon:(MwLLPixmap)pixmap { - [self->application setApplicationIconImage:[pixmap->cocoa.real image]]; -}; -- (void)forceRender { - self->_forceRender = MwTRUE; -}; -- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask { - int y, x, ys, xs; - unsigned char* di = malloc(image->width * image->height * 4); - memset(di, 0, image->width * image->height * 4); - - if(self->cursorPixmap) { - [self->cursorPixmap destroy]; - } - self->cursorPixmap = - [MilskoCocoaPixmap newWithWidth:image->width - height:image->height]; - - xs = -mask->x + image->x; - ys = MwCursorDataHeight + mask->y; - ys = MwCursorDataHeight + image->y - ys; - - for(y = 0; y < mask->height; y++) { - unsigned int d = mask->data[y]; - for(x = mask->width - 1; x >= 0; x--) { - int px = 0; - int idx = ((y * mask->width) + x) * 4; - - if(d & 1) { - di[idx + 3] = 255; - }; - d = d >> 1; - } - } - for(y = 0; y < image->height; y++) { - unsigned int d = image->data[y]; - for(x = image->width - 1; x >= 0; x--) { - int px = 0; - int idx = ((y * image->width) + x) * 4; - - if(d & 1) { - px = 255; - }; - - di[idx] = px; - di[idx + 1] = px; - di[idx + 2] = px; - d = d >> 1; - } - } - - [self->cursorPixmap updateWithData:di]; - - self->cursor = [[NSCursor alloc] - initWithImage:[self->cursorPixmap image] - hotSpot:NSMakePoint(image->x, image->y + image->height)]; - [self->cursor retain]; - - [self->cursor pop]; - [self->cursor push]; - - free(di); -}; -- (void)detachWithPoint:(MwPoint*)point { - [self->window setParentWindow:NULL]; -}; -- (void)show:(int)show { - (void)show; -}; -- (void)makePopupWithParent:(MwLL)_parent { - (void)_parent; -}; -- (void)setSizeHintsWithMinX:(int)minx - MinY:(int)miny - MaxX:(int)maxx - MaxY:(int)maxy { - [self->window setMinSize:NSMakeSize(minx, miny)]; - [self->window setMaxSize:NSMakeSize(maxx, maxy)]; -}; -- (void)makeBorderless:(int)toggle { - MwU32 mask = [self->window styleMask]; - if(toggle) { - mask ^= NSBorderlessWindowMask; - mask |= NSTitledWindowMask; - } else { - mask |= NSBorderlessWindowMask; - mask ^= NSTitledWindowMask; - } - [self->window initWithContentRect:self->rect - styleMask:mask - backing:NSBackingStoreBuffered - defer:NO]; -}; -- (void)focus { - [self->window makeMainWindow]; -}; -- (void)grabPointer:(int)toggle { - self->pointerLocked = toggle; -}; -- (void)setClipboard:(const char*)text { - (void)text; - // TODO: find out how to do this while supporting 10.4 - // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - // NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; - // [pasteboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString] - // owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text] - // forType:NSPasteboardTypeString]; [pool release]; -}; -- (void)makeToolWindow { - /* If my understand of what a "tool window" usually is is correct then I - * highly doubt the Mac OS has this and if they did they probably outright - * removed it along time ago is this kind of conflicts with modern UX. So - * we'll just make it borderless idgaf */ - [self makeBorderless:MwTRUE]; -}; -- (void)getCursorCoord:(MwPoint*)point { - NSPoint p = [NSEvent mouseLocation]; - point->x = p.x; - point->y = p.y; -}; -- (void)getScreenSize:(MwRect*)_rect { - NSScreen* screen = [self->window screen]; - _rect->x = [screen frame].origin.x; - _rect->y = [screen frame].origin.y; - _rect->width = [screen frame].size.width; - _rect->height = [screen frame].size.height; -}; - (void)destroy { [self->handle release]; [self->window release]; @@ -1046,18 +638,98 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { @end static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { - MwLL r; - r = malloc(sizeof(*r)); + MwLL r; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + MilskoCocoa* c = [MilskoCocoa alloc]; + r = malloc(sizeof(*r)); MwLLCreateCommon(r); - MilskoCocoa* o = [MilskoCocoa newWithParent:parent - x:x - y:y - width:width - height:height - handle:r]; - r->cocoa.real = o; + [c retain]; + c->application = (MilskoCocoaApplication*)[MilskoCocoaApplication sharedApplication]; + [c->application retain]; + + /* + * MacOS doesn't really have a "default" window position, you're actually + * meant to center the window yourself, so if the user passes MwDEFAULT + * respond appropriately. Also for child windows just have it be 0. + */ + if(x == MwDEFAULT) { + x = r ? ([[NSScreen mainScreen] frame].size.width / 2.) - (width / 2.) : 0; + } + if(y == MwDEFAULT) { + y = r ? ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.) + : 0; + } + c->rect = NSMakeRect(x, y, width, height); + + if(parent == NULL) { + c->window = [[NSWindow alloc] + initWithContentRect:rectFlip(c->rect) + styleMask:(NSTitledWindowMask | + NSClosableWindowMask | NSMiniaturizableWindowMask | + NSResizableWindowMask) + backing:NSBackingStoreBuffered + defer:NO]; + [c->window + setDelegate:[[MilskoCocoaWindowDelegate alloc] initWithWin:c->window]]; + [c->window retain]; + + [c->window makeKeyAndOrderFront:c->application]; + [c->window makeFirstResponder:c->view]; + + c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect]; + [c->view retain]; + [c->window setContentView:c->view]; + + if([c->application respondsToSelector:@selector(setActivationPolicy:)]) { + [c->application + setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */]; + } + [c->application activateIgnoringOtherApps:MwTRUE]; + [c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc] + initWithAppl:c->application]]; + [c->application retain]; + + [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; + c->modalSession = [c->application beginModalSessionForWindow:c->window]; + } else { + MilskoCocoa* p = parent->cocoa.real; + + c->window = p->window; + + NSRect rect = localRectFlip(c->rect, p->view); + c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; + [c->view setBounds:c->rect]; + [c->view retain]; + [c->view setChild]; + + [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; + + [p->view addSubview:c->view]; + + c->modalSession = p->modalSession; + } + [c->window setAcceptsMouseMovedEvents:MwTRUE]; + + c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)]; + [c->handle retain]; + [c->handle setPointer:r]; + [c->view addSubview:c->handle]; + + c->parent = parent; + + c->_forceRender = MwTRUE; + c->strHash = 0; + + c->cursorPixmap = NULL; + + [c->application finishLaunching]; + + c->pointerLocked = MwFALSE; + + [pool release]; + r->cocoa.real = c; return r; } @@ -1082,13 +754,81 @@ static void MwLLEndDrawImpl(MwLL handle) { static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { - MilskoCocoa* h = handle->cocoa.real; - [h polygonWithPoints:points points_count:points_count color:color]; + MilskoCocoa* self = handle->cocoa.real; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSGraphicsContext* ctx = [self->view context]; + if(ctx) { + int i; + NSBezierPath* path = [NSBezierPath bezierPath]; + /* whatever rect we use for coordinate flipping */ + NSRect _rect = self->parent ? [self->view bounds] : [self->window frame]; + + NSColor* nscolor = + [NSColor colorWithCalibratedRed:color->common.red / 255. + green:color->common.green / 255. + blue:color->common.blue / 255. + alpha:1.0]; + + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:ctx]; + + [nscolor setFill]; + for(i = 0; i < points_count; i++) { + NSPoint p = localPointFlip(NSMakePoint(points[i].x, points[i].y), self->view); + if(i == 0) { + [path moveToPoint:p]; + } else { + [path lineToPoint:p]; + } + } + + [path closePath]; + [path fill]; + + [NSGraphicsContext restoreGraphicsState]; + + [self->view setNeedsDisplay:YES]; + } + [pool release]; } static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { - MilskoCocoa* h = handle->cocoa.real; - [h lineWithPoints:points color:color]; + MilskoCocoa* self = handle->cocoa.real; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSGraphicsContext* ctx = [self->view context]; + if(ctx) { + int i; + NSBezierPath* path = [NSBezierPath bezierPath]; + /* whatever rect we use for coordinate flipping */ + NSRect _rect = self->parent ? [self->view bounds] : [self->window frame]; + + NSColor* nscolor = + [NSColor colorWithCalibratedRed:color->common.red / 255. + green:color->common.green / 255. + blue:color->common.blue / 255. + alpha:1.0]; + + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:ctx]; + + [nscolor setFill]; + for(i = 0; i < 2; i++) { + NSPoint p = localPointFlip(NSMakePoint(points[i].x, points[i].y), self->view); + if(i == 0) { + [path moveToPoint:p]; + } else { + [path lineToPoint:p]; + } + } + + [path closePath]; + [path stroke]; + + [NSGraphicsContext restoreGraphicsState]; + + [self->view setNeedsDisplay:YES]; + } + [pool release]; } static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { @@ -1106,16 +846,60 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) { } static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, - unsigned int* height) { - [handle->cocoa.real getX:x Y:y W:w H:height]; + unsigned int* h) { + MilskoCocoa* self = handle->cocoa.real; + NSRect frame; + if(self->parent) { + frame = [self->view frame]; + } else { + frame = [self->window frame]; + } + frame = rectFlip(frame); + + *x = frame.origin.x; + *y = frame.origin.y; + + *w = frame.size.width; + *h = frame.size.height; } static void MwLLSetXYImpl(MwLL handle, int x, int y) { - [handle->cocoa.real setX:x Y:y]; + MilskoCocoa* self = handle->cocoa.real; + NSRect frame; + if(self->parent) { + frame = [self->view frame]; + } else { + frame = [self->window frame]; + } + + frame.origin.x = x; + frame.origin.y = y; + + if(!self->parent) { + frame = rectFlip(frame); + [self->window setFrame:frame display:MwTRUE animate:MwTRUE]; + } else { + frame = localRectFlip(frame, self->parent->cocoa.real->view); + [self->view setBounds:frame]; + } + [self nudge]; } -static void MwLLSetWHImpl(MwLL handle, int w, int height) { - [handle->cocoa.real setW:w H:height]; +static void MwLLSetWHImpl(MwLL handle, int w, int h) { + MilskoCocoa* self = handle->cocoa.real; + NSRect frame = [self->window frame]; + frame.size.width = w; + frame.size.height = h; + + self->rect = frame; + + [self->view setFrameSize:frame.size]; + if(self->parent) { + [self->view setFrame:frame]; + } else { + [self->window setFrame:frame display:YES animate:false]; + } + [self nudge]; } static void MwLLFreeColorImpl(MwLLColor color) { @@ -1123,15 +907,45 @@ static void MwLLFreeColorImpl(MwLLColor color) { } static int MwLLPendingImpl(MwLL handle) { - return [handle->cocoa.real pending]; + MilskoCocoa* self = handle->cocoa.real; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + MwBool isPending = [self->application pending]; + [self->application runModalSession:self->modalSession]; + [pool release]; + return self->_forceRender || self->_eventsPending || isPending; } static void MwLLNextEventImpl(MwLL handle) { - [handle->cocoa.real getNextEvent]; + MilskoCocoa* self = handle->cocoa.real; + MwLL h = [self->handle pointer]; + if(self->_forceRender) { + MwLLDispatch(h, draw, NULL); + self->_forceRender = MwFALSE; + } + if(self->_eventsPending) { + MwLLDispatch(h, draw, NULL); + self->_eventsPending = MwFALSE; + } + [self sendClipboardEvent]; + +#ifdef __APPLE__ + if(self->pointerLocked && [self->window isMainWindow] && self->lastEvent) { + struct CGPoint pos; + pos.x = [self->window frame].origin.x + [self->window frame].size.width / 2; + pos.y = [self->window frame].origin.y + [self->window frame].size.height / 2; + + CGWarpMouseCursorPosition(pos); + } +#endif + + [self->application updateWindows]; } static void MwLLSetTitleImpl(MwLL handle, const char* title) { - [handle->cocoa.real setTitle:title]; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [handle->cocoa.real->window + setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; + [pool release]; } static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, @@ -1154,7 +968,24 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, } static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) { - [pixmap->cocoa.real updateWithData:pixmap->common.raw]; + MilskoCocoaPixmap* self = pixmap->cocoa.real; + memcpy(self->buf, pixmap->common.raw, pixmap->common.width * pixmap->common.height * 4); + if(self->rep) { + [self->image removeRepresentation:self->rep]; + [self->rep release]; + } + self->rep = + [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&self->buf + pixelsWide:(int)pixmap->common.width + pixelsHigh:(int)pixmap->common.height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:(int)pixmap->common.width * 4 + bitsPerPixel:32]; + [self->image addRepresentation:self->rep]; } static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { @@ -1164,53 +995,141 @@ static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { } static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { - [handle->cocoa.real drawPixmap:pixmap rect:rect]; + MilskoCocoa* self = handle->cocoa.real; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + MilskoCocoaPixmap* p = pixmap->cocoa.real; + NSGraphicsContext* ctx = [self->view context]; + if(ctx) { + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:ctx]; + + [[p image] + drawInRect:localRectFlip(NSMakeRect(rect->x, rect->y, rect->width, rect->height), self->view) + fromRect:NSZeroRect + operation:NSCompositeSourceOver + fraction:1.0]; + + [NSGraphicsContext restoreGraphicsState]; + + [self->view setNeedsDisplay:YES]; + } + [pool release]; MwLLForceRender(handle); } static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { - [handle->cocoa.real setIcon:pixmap]; + [handle->cocoa.real->application setApplicationIconImage:[pixmap->cocoa.real image]]; } static void MwLLForceRenderImpl(MwLL handle) { - [handle->cocoa.real forceRender]; + handle->cocoa.real->_forceRender = MwTRUE; } static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) { - [handle->cocoa.real setCursor:image mask:mask]; + MilskoCocoa* self = handle->cocoa.real; + int y, x, ys, xs; + unsigned char* di = malloc(image->width * image->height * 4); + memset(di, 0, image->width * image->height * 4); + + if(self->cursorPixmap) { + [self->cursorPixmap destroy]; + } + self->cursorPixmap = + [MilskoCocoaPixmap newWithWidth:image->width + height:image->height]; + + xs = -mask->x + image->x; + ys = MwCursorDataHeight + mask->y; + ys = MwCursorDataHeight + image->y - ys; + + for(y = 0; y < mask->height; y++) { + unsigned int d = mask->data[y]; + for(x = mask->width - 1; x >= 0; x--) { + int px = 0; + int idx = ((y * mask->width) + x) * 4; + + if(d & 1) { + di[idx + 3] = 255; + }; + d = d >> 1; + } + } + for(y = 0; y < image->height; y++) { + unsigned int d = image->data[y]; + for(x = image->width - 1; x >= 0; x--) { + int px = 0; + int idx = ((y * image->width) + x) * 4; + + if(d & 1) { + px = 255; + }; + + di[idx] = px; + di[idx + 1] = px; + di[idx + 2] = px; + d = d >> 1; + } + } + + [self->cursorPixmap updateWithData:di]; + + self->cursor = [[NSCursor alloc] + initWithImage:[self->cursorPixmap image] + hotSpot:NSMakePoint(image->x, image->y + image->height)]; + [self->cursor retain]; + + [self->cursor pop]; + [self->cursor push]; + + free(di); } static void MwLLDetachImpl(MwLL handle, MwPoint* point) { - [handle->cocoa.real detachWithPoint:point]; + [handle->cocoa.real->window setParentWindow:NULL]; } static void MwLLShowImpl(MwLL handle, int show) { - [handle->cocoa.real show:show]; + (void)show; } static void MwLLMakePopupImpl(MwLL handle, MwLL parent) { - [handle->cocoa.real makePopupWithParent:parent]; + (void)parent; } static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) { - [handle->cocoa.real setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy]; + MilskoCocoa* self = handle->cocoa.real; + [self->window setMinSize:NSMakeSize(minx, miny)]; + [self->window setMaxSize:NSMakeSize(maxx, maxy)]; } static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) { - [handle->cocoa.real makeBorderless:toggle]; + MilskoCocoa* self = handle->cocoa.real; + MwU32 mask = [self->window styleMask]; + if(toggle) { + mask ^= NSBorderlessWindowMask; + mask |= NSTitledWindowMask; + } else { + mask |= NSBorderlessWindowMask; + mask ^= NSTitledWindowMask; + } + [self->window initWithContentRect:self->rect + styleMask:mask + backing:NSBackingStoreBuffered + defer:NO]; } static void MwLLFocusImpl(MwLL handle) { - [handle->cocoa.real focus]; + [handle->cocoa.real->application activateIgnoringOtherApps:MwTRUE]; } static void MwLLGrabPointerImpl(MwLL handle, int toggle) { - [handle->cocoa.real grabPointer:toggle]; + handle->cocoa.real->pointerLocked = toggle; } static void MwLLSetClipboardImpl(MwLL handle, const char* text) { - [handle->cocoa.real setClipboard:text]; + (void)handle; + (void)text; } static void MwLLGetClipboardImpl(MwLL handle) { @@ -1218,15 +1137,26 @@ static void MwLLGetClipboardImpl(MwLL handle) { } static void MwLLMakeToolWindowImpl(MwLL handle) { - [handle->cocoa.real makeToolWindow]; + /* If my understand of what a "tool window" usually is is correct then I + * highly doubt the Mac OS has this and if they did they probably outright + * removed it along time ago is this kind of conflicts with modern UX. So + * we'll just make it borderless idgaf */ + MwLLMakeBorderlessImpl(handle, 1); } static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { - [handle->cocoa.real getCursorCoord:point]; + NSPoint p = [NSEvent mouseLocation]; + point->x = p.x; + point->y = p.y; } static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) { - [handle->cocoa.real getScreenSize:rect]; + MilskoCocoa* self = handle->cocoa.real; + NSScreen* screen = [self->window screen]; + rect->x = [screen frame].origin.x; + rect->y = [screen frame].origin.y; + rect->width = [screen frame].size.width; + rect->height = [screen frame].size.height; } static void MwLLBeginStateChangeImpl(MwLL handle) { From c0d7cb3fbc71811cf4bd6346b58d579567ac890c Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 21:50:10 -0700 Subject: [PATCH 18/21] mac: add a few comments --- src/backend/cocoa.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index b43aef2..ec20af1 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -327,6 +327,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { - (void)handleKeyEvent:(NSEvent*)ev ll:(MwLL)ll down:(MwBool)isDown { int ch; + /* todo: consolidate these values into the below switch case. */ enum { kVK_ANSI_A = 0x00, kVK_ANSI_S = 0x01, @@ -682,10 +683,12 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { [c->view retain]; [c->window setContentView:c->view]; + /* In order for our application to be front and center when launched, we need to use this function introduced in 10.5. There's no function that works on 10.4 or below as far as I know because what you're actually supposed to do is use a feature of XCode project files to modify the settings of the compiled app to set the activation policy. */ if([c->application respondsToSelector:@selector(setActivationPolicy:)]) { [c->application setActivationPolicy:0 /* NSApplicationActivationPolicyRegular */]; } + [c->application activateIgnoringOtherApps:MwTRUE]; [c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc] initWithAppl:c->application]]; @@ -694,12 +697,11 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; c->modalSession = [c->application beginModalSessionForWindow:c->window]; } else { - MilskoCocoa* p = parent->cocoa.real; + MilskoCocoa* p = parent->cocoa.real; + NSRect rect = localRectFlip(c->rect, p->view); c->window = p->window; - - NSRect rect = localRectFlip(c->rect, p->view); - c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; + c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; [c->view setBounds:c->rect]; [c->view retain]; [c->view setChild]; @@ -729,6 +731,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { c->pointerLocked = MwFALSE; [pool release]; + r->cocoa.real = c; return r; From fe72bc92bfd3781b723c7c65ccbc36d8cc04cefb Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 13 Apr 2026 22:30:25 -0700 Subject: [PATCH 19/21] mac: actually dispatch close event. reorganize code slightly more now that less is in objective-c methods --- src/backend/cocoa.m | 317 ++++++++++++++++++++------------------------ 1 file changed, 143 insertions(+), 174 deletions(-) diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index ec20af1..b88bd42 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -64,139 +64,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { } }; -@implementation MilskoCocoaPixmap - -+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height { - MilskoCocoaPixmap* p = [MilskoCocoaPixmap alloc]; - - p->width = width; - p->height = height; - p->image = NULL; - - p->buf = malloc(width * height * 4); - - p->rep = - [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&p->buf - pixelsWide:(int)width - pixelsHigh:(int)height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:(int)width * 4 - bitsPerPixel:32]; - assert(p->rep); - - p->image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; - assert(p->image); - [p->image addRepresentation:p->rep]; - - return p; -} -- (void)updateWithData:(unsigned char*)_data { - memcpy(self->buf, _data, width * height * 4); - if(self->rep) { - [self->image removeRepresentation:self->rep]; - [self->rep release]; - } - self->rep = - [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&self->buf - pixelsWide:(int)width - pixelsHigh:(int)height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:(int)width * 4 - bitsPerPixel:32]; - [self->image addRepresentation:self->rep]; -} -- (void)destroy { - free(self->buf); - [self->image removeRepresentation:self->rep]; - [self->image release]; - [self->rep release]; - self->image = NULL; - self->rep = NULL; -} -- (NSImage*)image { - return self->image; -} -@end - -@implementation MilskoCocoa -- (void)sendClipboardEvent { - /*NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; - NSArray* items = @[ - @"public.utf8-plain-text", - @"public.utf16-external-plain-text", - @"com.apple.traditional-mac-plain-text", - ]; - MwLL this = self->handle.pointer; - - if([pasteboard canReadItemWithDataConformingToTypes:items]) { - char* data = NULL; - size_t size = 0; - for(NSPasteboardItem* item in [pasteboard pasteboardItems]) { - for(NSString* it in items) { - NSString* itemData = [item - stringForType:(NSString*)it]; if(itemData != NULL) { if(strHash != 0 && - strHash != [itemData hash]) { char* text = malloc([itemData length]); - strncpy(text, [itemData UTF8String], - [itemData length]); MwLLDispatch(this, clipboard, text); printf("%s -> %p\n", - text, this); free(text); - } - strHash = [itemData hash]; - } - } - } - } - - [pool release];*/ -} - -- (void)destroy { - [self->handle release]; - [self->window release]; -} - -- (MwLL)getParent { - return self->parent; -} - -- (NSView*)getView { - return view; -} -- (NSWindow*)getWindow { - return window; -} - -- (void)nudge { - MwLL p = self->parent; - self->_eventsPending = MwTRUE; - - if(p) { - [p->cocoa.real->view setNeedsDisplay:true]; - p = p->cocoa.real->parent; - } -} - -- (void)pushCursor { - [self->cursor push]; -} -- (void)popCursor { - [self->cursor pop]; -} - -- (MilskoFakePointer*)getHandle { - return handle; -} - -@end - @implementation MilskoCocoaApplication - (void)sendEvent:(NSEvent*)event { self->doPending = MwTRUE; @@ -555,17 +422,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { self->appl = _appl; return self; } -- (void)applicationDidBecomeActive:(NSNotification*)notification { - [self->appl activateIgnoringOtherApps:true]; - // printf("test\n"); -} -- (void)applicationWillFinishLaunching:(NSNotification*)notification { - // printf("test\n"); - // [self->appl activateIgnoringOtherApps:MwTRUE]; -} -- (void)applicationDidFinishLaunching:(NSNotification*)notification { - // [self->appl activateIgnoringOtherApps:MwTRUE]; -} @end @implementation MilskoCocoaWindowDelegate @@ -591,23 +447,19 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { [self->w makeKeyAndOrderFront:nil]; } -- (void)windowDidResize:(NSNotification*)notification { - (void)notification; -} - -// This will close/terminate the application when the main window is closed. -- (void)windowWillClose:(NSNotification*)notification { - (void)notification; - // MilskoCocoa* window = notification.object; - // MwLL handle = [window getHandle].pointer; - // MwLLDispatch(handle, close, NULL); -} - - (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win { self->w = win; return self; } +- (void)windowWillClose:(NSNotification*)notification { + if([[[w contentView] subviews] count] != 0) { + MwLL h = [((MilskoFakePointer*)[[[w contentView] subviews] + objectAtIndex:0]) pointer]; + MwLLDispatch(h, close, NULL); + } +} + @end @implementation MilskoFakePointer @@ -638,6 +490,138 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { @end +@implementation MilskoCocoaPixmap ++ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height { + MilskoCocoaPixmap* p = [MilskoCocoaPixmap alloc]; + + p->width = width; + p->height = height; + p->image = NULL; + + p->buf = malloc(width * height * 4); + + p->rep = + [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&p->buf + pixelsWide:(int)width + pixelsHigh:(int)height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:(int)width * 4 + bitsPerPixel:32]; + assert(p->rep); + + p->image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; + assert(p->image); + [p->image addRepresentation:p->rep]; + + return p; +} +- (void)updateWithData:(unsigned char*)_data { + memcpy(self->buf, _data, width * height * 4); + if(self->rep) { + [self->image removeRepresentation:self->rep]; + [self->rep release]; + } + self->rep = + [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&self->buf + pixelsWide:(int)width + pixelsHigh:(int)height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:(int)width * 4 + bitsPerPixel:32]; + [self->image addRepresentation:self->rep]; +} +- (void)destroy { + free(self->buf); + [self->image removeRepresentation:self->rep]; + [self->image release]; + [self->rep release]; + self->image = NULL; + self->rep = NULL; +} +- (NSImage*)image { + return self->image; +} +@end + +@implementation MilskoCocoa +- (void)sendClipboardEvent { + /*NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; + NSArray* items = @[ + @"public.utf8-plain-text", + @"public.utf16-external-plain-text", + @"com.apple.traditional-mac-plain-text", + ]; + MwLL this = self->handle.pointer; + + if([pasteboard canReadItemWithDataConformingToTypes:items]) { + char* data = NULL; + size_t size = 0; + for(NSPasteboardItem* item in [pasteboard pasteboardItems]) { + for(NSString* it in items) { + NSString* itemData = [item + stringForType:(NSString*)it]; if(itemData != NULL) { if(strHash != 0 && + strHash != [itemData hash]) { char* text = malloc([itemData length]); + strncpy(text, [itemData UTF8String], + [itemData length]); MwLLDispatch(this, clipboard, text); printf("%s -> %p\n", + text, this); free(text); + } + strHash = [itemData hash]; + } + } + } + } + + [pool release];*/ +} + +- (void)destroy { + [self->handle release]; + [self->window release]; +} + +- (MwLL)getParent { + return self->parent; +} + +- (NSView*)getView { + return view; +} +- (NSWindow*)getWindow { + return window; +} + +- (void)nudge { + MwLL p = self->parent; + self->_eventsPending = MwTRUE; + + if(p) { + [p->cocoa.real->view setNeedsDisplay:true]; + p = p->cocoa.real->parent; + } +} + +- (void)pushCursor { + [self->cursor push]; +} +- (void)popCursor { + [self->cursor pop]; +} + +- (MilskoFakePointer*)getHandle { + return handle; +} + +@end + static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { MwLL r; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -953,9 +937,9 @@ static void MwLLSetTitleImpl(MwLL handle, const char* title) { static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) { - (void)handle; - MwLLPixmap r = malloc(sizeof(*r)); + + (void)handle; memset(r, 0, sizeof(*r)); r->common.raw = malloc(4 * width * height); @@ -973,22 +957,7 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) { MilskoCocoaPixmap* self = pixmap->cocoa.real; memcpy(self->buf, pixmap->common.raw, pixmap->common.width * pixmap->common.height * 4); - if(self->rep) { - [self->image removeRepresentation:self->rep]; - [self->rep release]; - } - self->rep = - [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&self->buf - pixelsWide:(int)pixmap->common.width - pixelsHigh:(int)pixmap->common.height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:(int)pixmap->common.width * 4 - bitsPerPixel:32]; - [self->image addRepresentation:self->rep]; + [pixmap->cocoa.real updateWithData:pixmap->common.raw]; } static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { From 0e2e3a190157cc5f29fdbb1a54a2301383e9f97d Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Tue, 14 Apr 2026 13:13:17 -0700 Subject: [PATCH 20/21] some gnustep fixes, probably close to giving up on this ngl --- include/Mw/LowLevel/Cocoa.h | 2 ++ src/backend/cocoa.m | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 3577ad0..2a8c7ec 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -81,6 +81,8 @@ @end @interface MilskoCocoaView : NSView { + @public + unsigned char* buf; NSBitmapImageRep* rep; NSGraphicsContext* context; MwBool valid; diff --git a/src/backend/cocoa.m b/src/backend/cocoa.m index b88bd42..c336f7f 100644 --- a/src/backend/cocoa.m +++ b/src/backend/cocoa.m @@ -140,8 +140,11 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { - (void)initRepAndContextWithWidth:(float)w Height:(float)h { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + self->buf = malloc(w * h * 4); + memset(self->buf, 255, w * h * 4); + self->rep = - [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL + [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&self->buf pixelsWide:w pixelsHigh:h bitsPerSample:8 @@ -536,6 +539,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) { colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:(int)width * 4 bitsPerPixel:32]; + assert(self->rep); [self->image addRepresentation:self->rep]; } - (void)destroy { @@ -975,7 +979,7 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:ctx]; - [[p image] + [p->image drawInRect:localRectFlip(NSMakeRect(rect->x, rect->y, rect->width, rect->height), self->view) fromRect:NSZeroRect operation:NSCompositeSourceOver From f22f45d5bf61f1b2fb9dd819bfe6b3f73acfb303 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Tue, 14 Apr 2026 13:34:49 -0700 Subject: [PATCH 21/21] give up on rounded borders --- include/Mw/Draw.h | 6 +- src/core.c | 1 - src/draw.c | 284 ++++++++++----------------------------- src/widget/box.c | 2 +- src/widget/combobox.c | 2 +- src/widget/entry.c | 2 +- src/widget/frame.c | 2 +- src/widget/image.c | 2 +- src/widget/listbox.c | 6 +- src/widget/menu.c | 2 +- src/widget/progressbar.c | 2 +- src/widget/separator.c | 2 +- src/widget/submenu.c | 2 +- src/widget/treeview.c | 8 +- src/widget/window.c | 2 +- 15 files changed, 92 insertions(+), 233 deletions(-) diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index c6c3612..9208d72 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -53,7 +53,7 @@ MWDECL void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color); * @param rect Rectangle area * @param color Color */ -MWDECL void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int rounded); +MWDECL void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color); /*! * @brief Draws a frame @@ -63,7 +63,7 @@ MWDECL void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int * @param invert Invert the 3D border color or not * @warning `rect` gets changed to the area of rectangle inside */ -MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int rounded); +MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert); /*! * @brief Does the DrawFrame/DrawRect combo used for drawing widget. @@ -96,7 +96,7 @@ MWDECL void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int i * @param rounded Rounded or not * @warning `rect` gets changed to the area of rectangle inside */ -MWDECL void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same, int rounded); +MWDECL void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same); /*! * @brief Creates a pixmap from image diff --git a/src/core.c b/src/core.c index cdd0723..2b98ec5 100644 --- a/src/core.c +++ b/src/core.c @@ -606,7 +606,6 @@ int MwGetInteger(MwWidget handle, const char* key) { #else if(strcmp(key, MwNmodernLook) == 0) return inherit_integer(handle, key, 1); #endif - if(strcmp(key, MwNisRounded) == 0) return inherit_integer(handle, key, 1); if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0); if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0); } diff --git a/src/draw.c b/src/draw.c index 12ccb51..f5e1368 100644 --- a/src/draw.c +++ b/src/draw.c @@ -11,10 +11,6 @@ #include "../external/stb_ds.h" -#define DEFAULT_ROUNDNESS 5 -#define MAX_ROUNDNESS 30 -#define BORDER_SMOOTHNESS 50 - static int get_color_diff(MwWidget handle) { if(MwGetInteger(handle, MwNmodernLook)) { return 40; @@ -106,7 +102,7 @@ void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) { MwLLPolygon(handle->lowlevel, p, 4, color); } -void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int rounded) { +void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { MwLLPixmap pixmap; int y, i; double darken = 0.; @@ -115,17 +111,18 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int rounde unsigned long sz = 1 * rect->height * 4; unsigned char* data = malloc(sz); MwRect r = *rect; - int roundness = MwGetInteger(handle, MwNroundness); double div; if(rect->width <= 0 || rect->height <= 0) { free(data); return; } - if(roundness == MwDEFAULT) roundness = DEFAULT_ROUNDNESS; - if(roundness >= MAX_ROUNDNESS) roundness = MAX_ROUNDNESS; - div = (roundness <= 10) ? 7. : 10.; memset(data, 0, sz); + r.x += 1; + r.y += 1; + r.width -= 2; + r.height -= 2; + for(y = 0; y < rect->height; y++) { MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken); int idx = y * 4; @@ -138,42 +135,18 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int rounde } pixmap = MwLLCreatePixmap(handle->lowlevel, data, 1, rect->height); - if(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0) { - for(i = 0; i < roundness; i++) { - int x = (roundness + 2); - int y = rect->y + (roundness + 2); - double point = ((i + (M_PI * 4)) / div); - r.x = (roundness + 4) - (sin(point) * roundness); - r.y = y + (cos(point) * roundness) + 1; - r.width = roundness; - r.height = (rect->height - ((r.y - rect->y) * 2) - 1); - MwLLDrawPixmap(handle->lowlevel, &r, pixmap); - r.width = x + (sin(point + 1) * roundness); - r.x = ((rect->width - (roundness + 1)) + (sin(point) * roundness)) - r.width; - MwLLDrawPixmap(handle->lowlevel, &r, pixmap); - } - - r = *rect; - r.x += roundness; - r.y += 3; - r.width -= (roundness * 2) + 1; - r.height -= 6; - MwLLDrawPixmap(handle->lowlevel, &r, pixmap); - - } else { - MwLLDrawPixmap(handle->lowlevel, &r, pixmap); - } + MwLLDrawPixmap(handle->lowlevel, &r, pixmap); MwLLDestroyPixmap(pixmap); free(data); } -void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int rounded) { +void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) { int inv; if((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv) invert = 1; if(MwGetInteger(handle, MwNmodernLook)) { - MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle), 0, 0, rounded); + MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle), 0, 0); } else { int diff = get_color_diff(handle) / 3 * 2; @@ -181,18 +154,17 @@ void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int int i; int st = invert ? 1 : 0; for(i = st; i < st + 2; i++) { - if((i % 2) == 0) MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle) - 1, -diff, (handle->parent == NULL || handle->parent->lowlevel == NULL) ? 1 : 0, 0); - if((i % 2) == 1) MwDrawFrameEx(handle, rect, color, invert, 1, diff, 0, 0); + if((i % 2) == 0) MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle) - 1, -diff, (handle->parent == NULL || handle->parent->lowlevel == NULL) ? 1 : 0); + if((i % 2) == 1) MwDrawFrameEx(handle, rect, color, invert, 1, diff, 0); } } else { - MwDrawFrameEx(handle, rect, color, invert, 1, 0, 0, 0); + MwDrawFrameEx(handle, rect, color, invert, 1, 0, 0); } } } void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) { MwLLColor col; - MwBool rounded = MwGetInteger(handle, MwNroundness) != MwDEFAULT && MwGetInteger(handle, MwNisRounded) != 0; if(rect->width <= 0 || rect->height <= 0) return; @@ -206,11 +178,11 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert } } - MwDrawFrame(handle, rect, color, invert, rounded); + MwDrawFrame(handle, rect, color, invert); } col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color; if(MwGetInteger(handle, MwNmodernLook)) { - MwDrawRectFading(handle, rect, col, rounded); + MwDrawRectFading(handle, rect, col); } else { MwDrawRect(handle, rect, col); } @@ -284,55 +256,47 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) { MwLLFreeColor(darker); } -static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same, int rounded) { +static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) { MwPoint p[7]; int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff); MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, ColorDiff - diff, ColorDiff - diff, ColorDiff - diff); - int roundness = MwGetInteger(handle, MwNroundness); + p[0].x = rect->x; + p[0].y = rect->y; - if(roundness == MwDEFAULT) roundness = DEFAULT_ROUNDNESS; - if(roundness >= MAX_ROUNDNESS) roundness = MAX_ROUNDNESS; - if(!(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0)) { - p[0].x = rect->x; - p[0].y = rect->y; + p[1].x = rect->x + rect->width; + p[1].y = rect->y; - p[1].x = rect->x + rect->width; - p[1].y = rect->y; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + border; + p[3].x = rect->x + border; + p[3].y = rect->y + border; - p[2].x = rect->x + rect->width - border; - p[2].y = rect->y + border; - p[3].x = rect->x + border; - p[3].y = rect->y + border; + p[4].x = rect->x + border; + p[4].y = rect->y + rect->height - border; - p[4].x = rect->x + border; - p[4].y = rect->y + rect->height - border; - - p[5].x = rect->x; - p[5].y = rect->y + rect->height; - } + p[5].x = rect->x; + p[5].y = rect->y + rect->height; MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter); - if(!(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0)) { - p[0].x = rect->x + rect->width; - p[0].y = rect->y; + p[0].x = rect->x + rect->width; + p[0].y = rect->y; - p[1].x = rect->x + rect->width - border; - p[1].y = rect->y + border; + p[1].x = rect->x + rect->width - border; + p[1].y = rect->y + border; - p[2].x = rect->x + rect->width - border; - p[2].y = rect->y + rect->height - border; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + rect->height - border; - p[3].x = rect->x + border; - p[3].y = rect->y + rect->height - border; + p[3].x = rect->x + border; + p[3].y = rect->y + rect->height - border; - p[4].x = rect->x; - p[4].y = rect->y + rect->height; + p[4].x = rect->x; + p[4].y = rect->y + rect->height; - p[5].x = rect->x + rect->width; - p[5].y = rect->y + rect->height; - MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); - } + p[5].x = rect->x + rect->width; + p[5].y = rect->y + rect->height; + MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); MwLLFreeColor(lighter); MwLLFreeColor(darker); @@ -343,168 +307,64 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, rect->height -= border * 2; } -static void frame_border_complex(MwWidget handle, MwRect* rect, MwLLColor lighter, MwLLColor darker, int invert, int border, int diff, int same, int rounded) { +static void frame_border_complex(MwWidget handle, MwRect* rect, MwLLColor lighter, MwLLColor darker, int invert, int border, int diff, int same) { MwPoint p[7]; - int roundness = MwGetInteger(handle, MwNroundness); int i; (void)diff; (void)same; - if(roundness == MwDEFAULT) roundness = DEFAULT_ROUNDNESS; - if(roundness >= MAX_ROUNDNESS) roundness = MAX_ROUNDNESS; - if(rounded && rect->height >= (roundness * 4) && rect->width >= (roundness * 4) && roundness > 0) { - /* top left edge */ - for(i = 0; i < BORDER_SMOOTHNESS; i += 2) { - MwPoint line[2]; - double point = ((i + (M_PI * (BORDER_SMOOTHNESS / 2.))) / (BORDER_SMOOTHNESS)); - int x = rect->x + (roundness + 2); - int y = rect->y + (roundness + 2); + p[0].x = rect->x; + p[0].y = rect->y; - line[0].x = x - (sin(point) * roundness); - line[0].y = y + (cos(point) * roundness); - line[1].x = x - (sin(point + 1) * roundness); - line[1].y = y + (cos(point + 1) * roundness); - MwLLLine(handle->lowlevel, line, invert ? lighter : darker); - } + p[1].x = rect->x + rect->width; + p[1].y = rect->y; - p[0].x = rect->x + roundness; - p[0].y = rect->y + border; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + border; + p[3].x = rect->x + border; + p[3].y = rect->y + border; - p[1].x = rect->x + rect->width - border - roundness; - p[1].y = rect->y + border; + p[4].x = rect->x + border; + p[4].y = rect->y + rect->height - border; - p[2].x = rect->x + rect->width - border - roundness; - p[2].y = rect->y + border + roundness; - - p[3].x = rect->x + border; - p[3].y = rect->y + border + roundness; - - p[4].x = rect->x + border; - p[4].y = (rect->y + border) + rect->height - roundness; - - p[5].x = rect->x + roundness; - p[5].y = (rect->y + border) + rect->height - roundness; - MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); - - /* top right edge */ - for(i = 0; i < BORDER_SMOOTHNESS; i += 2) { - MwPoint line[2]; - double point = ((i + (M_PI * (BORDER_SMOOTHNESS / 2.))) / (BORDER_SMOOTHNESS)); - int x = (rect->x + rect->width) - (roundness + 2); - int y = rect->y + (roundness + 2); - double placeholder = (sin(point) * roundness); - line[0].x = x + placeholder; - line[0].y = y + (cos(point) * roundness); - line[1].x = x + (sin(point + 1) * roundness); - line[1].y = y + (cos(point + 1) * roundness); - MwLLLine(handle->lowlevel, line, invert ? lighter : darker); - } - } else { - p[0].x = rect->x; - p[0].y = rect->y; - - p[1].x = rect->x + rect->width; - p[1].y = rect->y; - - p[2].x = rect->x + rect->width - border; - p[2].y = rect->y + border; - p[3].x = rect->x + border; - p[3].y = rect->y + border; - - p[4].x = rect->x + border; - p[4].y = rect->y + rect->height - border; - - p[5].x = rect->x; - p[5].y = rect->y + rect->height; - } + p[5].x = rect->x; + p[5].y = rect->y + rect->height; MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); - if(rounded && rect->height >= (roundness * 4) && rect->width >= (roundness * 4) && roundness > 0) { - /* bottom left edge */ - for(i = 0; i < BORDER_SMOOTHNESS; i += 2) { - MwPoint line[2]; - double point = ((i + (M_PI * (BORDER_SMOOTHNESS / 2.))) / (BORDER_SMOOTHNESS)); - int x = rect->x + (roundness + 2); - int y = (rect->y + rect->height) - (roundness + 2); + p[0].x = rect->x + rect->width; + p[0].y = rect->y; - line[0].x = x - (sin(point) * roundness); - line[0].y = y - (cos(point) * roundness); - line[1].x = x - (sin(point + 1) * roundness); - line[1].y = y - (cos(point + 1) * roundness); - MwLLLine(handle->lowlevel, line, invert ? lighter : darker); - } - p[0].x = rect->x + roundness; - p[0].y = rect->y + border + roundness; + p[1].x = rect->x + rect->width - border; + p[1].y = rect->y + border; - p[1].x = rect->x + rect->width - border; - p[1].y = rect->y + border + roundness; + p[2].x = rect->x + rect->width - border; + p[2].y = rect->y + rect->height - border; - p[2].x = rect->x + rect->width - border; - p[2].y = rect->y + rect->height - border - roundness; + p[3].x = rect->x + border; + p[3].y = rect->y + rect->height - border; - p[3].x = rect->x + rect->width - border - roundness; - p[3].y = rect->y + rect->height - border; + p[4].x = rect->x; + p[4].y = rect->y + rect->height; - p[4].x = rect->x + border + roundness; - p[4].y = rect->y + rect->height - border; - - p[5].x = rect->x + roundness; - p[5].y = rect->y + rect->height - roundness; - - p[6].x = rect->x + rect->width - border - roundness; - p[6].y = rect->y + rect->height - roundness; - - MwLLPolygon(handle->lowlevel, p, 7, invert ? lighter : darker); - - /* bottom right edge */ - for(i = 0; i < BORDER_SMOOTHNESS; i += 2) { - MwPoint line[2]; - double point = ((i + (M_PI * (BORDER_SMOOTHNESS / 2.))) / (BORDER_SMOOTHNESS)); - int x = (rect->x + rect->width) - (roundness + 2); - int y = (rect->y + rect->height) - (roundness + 2); - - line[0].x = x + (sin(point) * roundness); - line[0].y = y - (cos(point) * roundness); - line[1].x = x + (sin(point + 1) * roundness); - line[1].y = y - (cos(point + 1) * roundness); - MwLLLine(handle->lowlevel, line, invert ? lighter : darker); - } - } else { - p[0].x = rect->x + rect->width; - p[0].y = rect->y; - - p[1].x = rect->x + rect->width - border; - p[1].y = rect->y + border; - - p[2].x = rect->x + rect->width - border; - p[2].y = rect->y + rect->height - border; - - p[3].x = rect->x + border; - p[3].y = rect->y + rect->height - border; - - p[4].x = rect->x; - p[4].y = rect->y + rect->height; - - p[5].x = rect->x + rect->width; - p[5].y = rect->y + rect->height; - MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); - } + p[5].x = rect->x + rect->width; + p[5].y = rect->y + rect->height; + MwLLPolygon(handle->lowlevel, p, 6, invert ? lighter : darker); } -static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same, int rounded) { +static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) { int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff); MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff); MwRect r = *rect; - frame_border_complex(handle, rect, lighter, darker, invert, border, diff, same, rounded); + frame_border_complex(handle, rect, lighter, darker, invert, border, diff, same); r.x += 1; r.y += 1; r.width -= 2; r.height -= 2; - frame_border_complex(handle, &r, lighter, darker, !invert, border, diff, same, rounded); + frame_border_complex(handle, &r, lighter, darker, !invert, border, diff, same); MwLLFreeColor(lighter); MwLLFreeColor(darker); @@ -515,11 +375,11 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color rect->height -= border * 2; } -void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same, int rounded) { +void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) { if(MwGetInteger(handle, MwNmodernLook)) { - MwDrawFrameEx_complex(handle, rect, color, invert, border, diff, same, rounded); + MwDrawFrameEx_complex(handle, rect, color, invert, border, diff, same); } else { - MwDrawFrameEx_simple(handle, rect, color, invert, border, diff, same, rounded); + MwDrawFrameEx_simple(handle, rect, color, invert, border, diff, same); } } diff --git a/src/widget/box.c b/src/widget/box.c index 0cc8df1..a87000f 100644 --- a/src/widget/box.c +++ b/src/widget/box.c @@ -86,7 +86,7 @@ static void draw(MwWidget handle) { r.height = MwGetInteger(handle, MwNheight); if(MwGetInteger(handle, MwNhasBorder)) { - MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0); + MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted)); } MwDrawRect(handle, &r, base); diff --git a/src/widget/combobox.c b/src/widget/combobox.c index d52cc25..22a9006 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -72,7 +72,7 @@ static void draw(MwWidget handle) { r.y += r.height; r.height = MwDefaultBorderWidth(handle) * 2; - MwDrawFrame(handle, &r, base, 0, 0); + MwDrawFrame(handle, &r, base, 0); MwLLFreeColor(text); MwLLFreeColor(base); diff --git a/src/widget/entry.c b/src/widget/entry.c index 3a7aa76..bd7dbe1 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -49,7 +49,7 @@ static void draw(MwWidget handle) { int attr; MwRect currc; - p.x = (r.width - (r.width / w * w)) / 2 + (MwGetInteger(handle, MwNisRounded) ? MwGetInteger(handle, MwNroundness) : 0); + p.x = (r.width - (r.width / w * w)) / 2; p.y = r.height / 2; len = (r.width - p.x * 2) / w; diff --git a/src/widget/frame.c b/src/widget/frame.c index 3c2ffe9..117b0f8 100644 --- a/src/widget/frame.c +++ b/src/widget/frame.c @@ -22,7 +22,7 @@ static void draw(MwWidget handle) { fr.y = 0; fr.width = MwGetInteger(handle, MwNwidth); fr.height = MwGetInteger(handle, MwNheight); - MwDrawFrame(handle, &fr, base, inverted, 0); + MwDrawFrame(handle, &fr, base, inverted); rr.x = MwDefaultBorderWidth(handle); rr.y = MwDefaultBorderWidth(handle); diff --git a/src/widget/image.c b/src/widget/image.c index cadddb3..74ee0bf 100644 --- a/src/widget/image.c +++ b/src/widget/image.c @@ -20,7 +20,7 @@ static void draw(MwWidget handle) { r.width = MwGetInteger(handle, MwNwidth); r.height = MwGetInteger(handle, MwNheight); - if(MwGetInteger(handle, MwNhasBorder)) MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0); + if(MwGetInteger(handle, MwNhasBorder)) MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted)); MwDrawRect(handle, &r, base); if(px != NULL) { diff --git a/src/widget/listbox.c b/src/widget/listbox.c index b25528f..9960e1d 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -210,7 +210,7 @@ static void frame_draw(MwWidget handle) { p.x = MwDefaultBorderWidth(handle); p.y = MwDefaultBorderWidth(handle); - MwDrawFrame(handle, &r, base, 1, 0); + MwDrawFrame(handle, &r, base, 1); MwDrawRect(handle, &r, base2); r = r2; @@ -284,7 +284,7 @@ static void frame_draw(MwWidget handle) { handle->bgcolor = NULL; } - MwDrawFrame(handle, &r, base, 1, 0); + MwDrawFrame(handle, &r, base, 1); MwLLFreeColor(text2); MwLLFreeColor(text); @@ -403,7 +403,7 @@ static void draw(MwWidget handle) { r.y = 0; r.width = get_col_width(lb, i); r.height = MwDefaultBorderWidth(handle) * 2 + MwTextHeight(handle, NULL, "M"); - MwDrawFrame(handle, &r, base, 0, 0); + MwDrawFrame(handle, &r, base, 0); x += MwDefaultBorderWidth(handle); diff --git a/src/widget/menu.c b/src/widget/menu.c index 85753f9..0808f69 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -100,7 +100,7 @@ static void draw(MwWidget handle) { BEGIN_MENU_LOOP; if(m->sub[i]->wsub != NULL || (in_area && handle->pressed)) { - MwDrawFrame(handle, &r, base, MwFALSE, 0); + MwDrawFrame(handle, &r, base, MwFALSE); MwDrawWidgetBack(handle, &r, base, 0, MwFALSE); } diff --git a/src/widget/progressbar.c b/src/widget/progressbar.c index 7be7bff..d85a8dd 100644 --- a/src/widget/progressbar.c +++ b/src/widget/progressbar.c @@ -23,7 +23,7 @@ static void draw(MwWidget handle) { r.width = MwGetInteger(handle, MwNwidth); r.height = MwGetInteger(handle, MwNheight); - MwDrawFrame(handle, &r, base, 1, 0); + MwDrawFrame(handle, &r, base, 1); MwDrawRect(handle, &r, base); w = MwGetInteger(handle, MwNvalue) - MwGetInteger(handle, MwNminValue); w = w / (MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue)); diff --git a/src/widget/separator.c b/src/widget/separator.c index 571c5df..8fcfc5b 100644 --- a/src/widget/separator.c +++ b/src/widget/separator.c @@ -25,7 +25,7 @@ static void draw(MwWidget handle) { r.y = (r.height - 2) / 2; r.height = 2; } - MwDrawFrameEx(handle, &r, base, 1, 1, 0, 0, MwGetInteger(handle, MwNmodernLook)); + MwDrawFrameEx(handle, &r, base, 1, 1, 0, 0); MwLLFreeColor(base); } diff --git a/src/widget/submenu.c b/src/widget/submenu.c index 3b64605..4990fd2 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -59,7 +59,7 @@ static void draw(MwWidget handle) { rc.x += MwGetInteger(handle, MwNleftPadding); - MwDrawFrameEx(handle, &rc, base, 1, 1, 0, 0, 0); + MwDrawFrameEx(handle, &rc, base, 1, 1, 0, 0); p.y += 2 + 1; } else { diff --git a/src/widget/treeview.c b/src/widget/treeview.c index 16898ef..acc35bf 100644 --- a/src/widget/treeview.c +++ b/src/widget/treeview.c @@ -64,7 +64,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry** const int len = 4; MwDrawRect(handle, &r, col); - MwDrawFrame(handle, &r, base, tree->opened, 0); + MwDrawFrame(handle, &r, base, tree->opened); if(tree->opened) { l[0].x = r.x + (r.width - len) / 2; l[0].y = r.y + r.height / 2; @@ -91,7 +91,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwTreeViewEntry** MwLLLine(handle->lowlevel, &l[0], text); } r = r2; - MwDrawFrame(handle, &r, base, tree->opened, 0); + MwDrawFrame(handle, &r, base, tree->opened); if(col != base) MwLLFreeColor(col); } else { @@ -183,7 +183,7 @@ static void frame_draw(MwWidget handle) { p.x = MwDefaultBorderWidth(handle); p.y = MwDefaultBorderWidth(handle); - MwDrawFrame(handle, &r, base, 1, 0); + MwDrawFrame(handle, &r, base, 1); MwDrawRect(handle, &r, base2); r = r2; @@ -193,7 +193,7 @@ static void frame_draw(MwWidget handle) { recursion(handle, tv->tree[i], tv->tree, base, text, base2, text2, &p, 0, LineSpace, &skip, &shared, 1, NULL); } - MwDrawFrame(handle, &r, base, 1, 0); + MwDrawFrame(handle, &r, base, 1); MwLLFreeColor(text2); MwLLFreeColor(text); diff --git a/src/widget/window.c b/src/widget/window.c index 74a96e6..979e073 100644 --- a/src/widget/window.c +++ b/src/widget/window.c @@ -18,7 +18,7 @@ static void draw(MwWidget handle) { r.width = MwGetInteger(handle, MwNwidth); r.height = MwGetInteger(handle, MwNheight); - if(MwGetInteger(handle, MwNhasBorder)) MwDrawFrame(handle, &r, c, MwGetInteger(handle, MwNinverted), 0); + if(MwGetInteger(handle, MwNhasBorder)) MwDrawFrame(handle, &r, c, MwGetInteger(handle, MwNinverted)); MwDrawRect(handle, &r, c);