Skip to content

Initial refactor for NSMenu for ARC and nullability (and a whole lot of TODO/FIXME comments)#520

Closed
reactive-firewall wants to merge 10000 commits intoravynsoft:mainfrom
reactive-firewall:Patch-NSMenu-518
Closed

Initial refactor for NSMenu for ARC and nullability (and a whole lot of TODO/FIXME comments)#520
reactive-firewall wants to merge 10000 commits intoravynsoft:mainfrom
reactive-firewall:Patch-NSMenu-518

Conversation

@reactive-firewall
Copy link

Patch Notes

This code is still unpolished but now it should actually behave more like an NSMenu should.

... or it would if NSMenuItem was working 🤦 ... but let's take it one class at a time.

Impacted GHI


Misc. Comments:

bsdimp and others added 30 commits September 2, 2025 09:23
…esystem devsw"

This reverts commit dfafdbd. There's no
author, and also problems with it. I'll redo it.

Sponsored by:		Netflix
LLVM-21 enables -Wuninitialized-const-pointer which results in the
following compiler warning and the bdev_file_open_by_path() interface
not being detected for 6.9 and newer kernels.  The blk_holder_ops
are not used by the ZFS code so we can safely use a NULL argument
for this check.

    bdev_file_open_by_path/bdev_file_open_by_path.c:110:54: error:
    variable 'h' is uninitialized when passed as a const pointer
    argument here [-Werror,-Wuninitialized-const-pointer]

Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #17682
Closes #17684
A VM had no virtual terminals and emitted a warning on boot
`eval: cannot open /dev/ttyv*: No such file or directory`.

Break the loop in this case to avoid the warning.

PR:		289173
Reviewed by:	jlduran
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52344
Reviewed by:	ziaee, bapt
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D52343
These fields all need to be explicitly initialized with zeroes.  Prior
to the conversion to C++ these fields were zeroed by calloc().

This worked for me in earlier testing as my test boxes had
MALLOC_PRODUCTION enabled in make.conf.

PR:		289115
Reported by:	Slawa Olhovchenkov <slw zxy.spb.ru>
Fixes:		eb0dc90 ("ctld: Convert struct auth_group to a C++ class")
Fixes:		6acc7af ("ctld: Convert struct port to a hierarchy of C++ classes")
Fixes:		2bb9180 ("ctld: Convert struct target to a C++ class")
Fixes:		ed07690 ("ctld: Convert struct ctld_connection to a C++ class")
Sponsored by:	Chelsio Communications
Chase commit 8e8d306 ("amd64 GENERIC: enable bloating kernel with
ext errors strings") from amd64.  In general we would like to keep
GENERIC kernel options in sync between the Tier-1 architectures.

PR:		289236
Reviewed by:	andrew
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52342
When fixing bug 286692, the change eafe596, that fixed a case when
peer side does close(), also had regressed a case when our side does
shutdown(SHUT_WR).  These actually are two independent code paths, and the
eafe596 shouldn't have touched the second block.  The removal of
'kn->kn_flags |= EV_EOF' was incorrect and the statement on original
behavior in the commit message was also incorrect.

Do not add back so_error setting, since I failed to find a test case that
would return anything but 0 in kevent.fflags when run on stable/14.

This was found with help of https://github.com/tokio-rs/mio.  Add a test
case into our test suite for that.

Fixes:	eafe596

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D52327
This reverts commit e4ea162.

kp reports failures related to pf tests. Revert until we
understand what is going wrong.
internal representation of icmp type/code in pfctl(8)/pf(4) does not
fit into u_int8_t. Issue has been noticed and kindly reported by
amalinin _at_ bh0.amt.ru via bugs@.

OK bluhm@

Obtained from:	OpenBSD, sashan <sashan@openbsd.org>, 1fdb608f55
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Issue found and kindly reported by Luca Di Gregorio <lucdig _at_ gmail>

OK bluhm@

Obtained from:	OpenBSD, sashan <sashan@openbsd.org>, 58feb3ffc6
Sponsored by:	Rubicon Communications, LLC ("Netgate")
This fixes a few KNF issues and ugly line wrapping by using a local
version of nitems(); fix two bsearch() on top.

ok claudio

FreeBSD note: we already used nitems(), but now pick up the use of size_t over
unsigned int.

Obtained from:	OpenBSD, tb <tb@openbsd.org>, 3d49904c6e
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Currently used M_TEMP and M_IFADDR types are unreasonable for that purpose.
This dedicated statistics simplify the future pf(4) unlocking work by decreasing
search area of possible memory leaks.

ok bluhm sashan

FreeBSD note: The unlocking work has already been done in FreeBSD, but it's
still useful to have all pf malloc() allocations be accounted to pf, not the
generic 'temp' bucket.

Obtained from:	OpenBSD, mvs <mvs@openbsd.org>, 062cda8b8d
Sponsored by:	Rubicon Communications, LLC ("Netgate")
We never actually use action or reason in pf_state_key_addr_setup(), so just
pass NULL to pf_pull_hdr().

No functional change.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
with TTL field to zero. To fix it function pf_test_state_icmp()
must initialize ttl field in pf_pdesc structure for inner packet.

feedback from bluhm@

OK bluhm@

Obtained from:	OpenBSD, sashan <sashan@openbsd.org>, 0d48c46cfe
Sponsored by:	Rubicon Communications, LLC ("Netgate")
If we fail to copy the data out we didn't free the temporary allocation.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Make sure we free all of the trees we allocated when we free the ruleset.
Found by 'kldunload pf' after a test run, now that the allocation is done from a
pf-specific malloc type.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Suggested by:	imp
Reviewed by:	alc, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D52348
Cyclades and digiboard drivers were removed in 2017 and 2016
respectively. There's no need for these anymore.

Sponsored by:		Netflix
Reviewed by:		kevans, emaste
Differential Revision:	https://reviews.freebsd.org/D52315
The dtrwait wait functionality was dropped in the TTY MPSAFE rewrite for
FreeBSD 8. Remove referneces to it here. Also, the sysctl was renamed
for drainwait, so use the new name. Given the 16 years between this
event and somebody noticing, I strongly suspect this file can just be
removed.

Sponsored by:		Netflix
Reviewed by:		kevans, emaste
Differential Revision:	https://reviews.freebsd.org/D52316
Nothing uses dtrwait anymore. This was elimianted with the tty mpsafe
rewrite for FreeBSD 8. Only these zombie symbols and functionality
remain. GC them. Add comcontrol to the list things to remove in 16.0.

Sponsored by:		Netflix
Reviewed by:		kevans, emaste
Differential Revision:	https://reviews.freebsd.org/D52317
When booting with boot_verbose, you want a larger msgbuf size. Add a
poitner to its tuneable.

Suggested by:		John De Boskey (Ages ago)
Sponsored by:		Netflix
Reported by:	Timo Völker
Fixes:		ac87d70 ("vtnet.4: improve existing descriptions and add missing ones")
MFC after:	3 days
Sponsored by:	Netflix, Inc.
Earlier versions (than 2.7.0) do not support float notifications or link-local
addresses. Skip the relevant tests there.

PR:		289150
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D52234
The pre-load, aka linker_preload() runs at the order of SI_SUB_KLD, but
a pre-loaded module may have SYSINITs that have startup order prior to
SI_SUB_KLD, e.g. TUNABLE_INT() / TUNABLE_LONG(), hence it is possible
that we run into abnormal orders.

Without this change, the subsystem of the pre-loaded kernel modules
will be melted into previous one. That is mostly harmless but confusing.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47904
A port using linux(kpi) header files but not using skbuffs is hitting
the case that it cannot find opt_wlan.h.  Give up to the idea that
skbuff.h is only used by wireless drivers (or in-tree) and that
IEEE80211_DEBUG (via opt_lwan.h) could autmatically compile in debug
support.

It is likely time to add a LINUXKPI_DEBUG knob in the near future
(also for linuxkpi_debug or linuxkpi_debug_rcu).

PR:		289268
MFC after:	3 days
This macro was replaced by a collection of architecture ifdefs in
tcpdump 4.99.4 so defining it does nothing.

Fixes:		51a1830 ("Import tcpdump 4.99.4")
Reviewed by:	jrm, emaste
Differential Revision:	https://reviews.freebsd.org/D52333
The version now comes from the PACKAGE_VERSION macro.

Fixes:		0a7e5f1 ("tcpdump: Update to 4.99.5")
Reviewed by:	jrm, emaste
Differential Revision:	https://reviews.freebsd.org/D52334
0mp and others added 19 commits September 10, 2025 11:04
make(1)'s -D flag does not allow for setting the value of the variable.
It just defines the variable and sets its value to 1. In fact, make(1)
treats "=" as just another character in the variable name:

```
$ make -DA=2 -V A  # Output is just an empty line.

$ make -DA=2 -V A=2  # Variable "A=2" is defined and set to "1".
1
```

Fixes:	d25f7d3 ports.7: Document DEBUG_FLAGS and the process of debugging ports
MFC after:	3 days
- Fix an mbuf leak with iflib.simple_tx=1 when we run out of tx descs
in iflib_encap().  It seems odd to free the mbuf in iflib_encap(),
but that routine consumes mbufs for other reasons, and it seemed
safest to free there rather than have the simple tx routine parse
return values to determine what needed to be freed.

- Increment counters for output drops when ENOBUFS is encountered
and output errors when other transmit errors are encountered for both
the simple and normal tx routines.

- Performed driver changes so that iflib drivers now add the generic
output drop and output error counters to their private counters in their
ifdi_get_counter routines.

Reviewed by: kbowling, markj
Differential Revision: https://reviews.freebsd.org/D52369
Sponsored by: Netflix
Reviewed by:	andrew
Obtained from:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D52401
Currently, F_SETFL always invokes FIONBIO and FIOASYNC ioctls on the
file descriptor even if the state of the associated flag has not
changed.  This means that a character device driver that implements
non-blocking I/O but not async I/O needs a handler for FIOASYNC that
permits setting the value to 0.  This also means that
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)) can fail for a character device
driver that does not handle both FIONBIO and FIOASYNC.  These
requirements are not obvious nor well documented.

Instead, only invoke FIONBIO and FIOASYNC if the relevant flag changes
state.  This only requires a device driver to implement support for
FIONBIO or FIOASYNC if it supports the corresponding flag.

While here, if a request aims to toggle both F_NOBLOCK and F_ASYNC and
FIOASYNC fails, pass the previous state of F_NONBLOCK to FIONBIO
instead of always disabling non-blocking I/O and then possibly
reverting the flag back to on in f_flags.

Reviewed by:	mckusick, imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D52403
struct sysinit's func pointer requires its address, thus a real function
is generated in every translation unit when the source file has SYSINITs
declared. That results in plenty of identical sysinit_tslog_shim in the
final kernel file, in which only one is used and others are left useless.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D52413
Notable upstream pull request merges:
 #15869 ee7c362 Add description of default sorting behavior to zfs_list.8
 #17375 ced72fd tunables: remove legacy FreeBSD aliases
 #17600 1da2c30 Update pam_zfs_key.c default path for FreeBSD
 #17632 b6bd322 Synchronize the update of feature refcount
 #17645 59f8f5d zfs_vnops_os.c: Add support for the _PC_CLONE_BLKSIZE name
 #17665 0d54ae2 zdb: Fix format strings on 32-bit systems
 #17673 976f765 Update compatibility.d files
 #17699 e3c3e86 Fix wrong dedup_table_size for legacy dedup
 #17704 e29bfa5 Fix warnings about sha2_is_supported on FreeBSD/i386
 #17706 a242431 Fix the build on 32-bit FreeBSD with GCC

Obtained from:	OpenZFS
OpenZFS commit:	7939bad
When sending UDP packets:
* compute the checksum in the correct order. This only has an impact
  if the length of the payload is odd.
* don't send packet with a checksum of zero, use 0xffff instead as
  required.
When receiving UDP packets:
* don't do any computations when the checksum is zero.
* compute the checksum in the correct order. This only has an impact
  if the length of the payload is odd.
* when computing the checksum, store the pseudo header checksum
* if the checksum is computed as zero, use 0xffff instead.
* also accept packets, when the checksum in the packet is the pseudo
  header checksum.
The last point fixes a problem when the DHCP client runs in a VM,
the DHCP server runs on the host serving the VM and the network
interface supports transmit checksum offloading. Since dhclient
doesn't use UDP sockets but bpf devices to read the packets, the
checksum will be incorrect and only contain the checksum of the
pseudo header.

PR:			263229
Reviewed by:		markj, Timo Völker
Tested by:		danilo
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D52394
Suppose an nvlist nvl belongs to a parent nvlist or nvlist array.  In
this case, nvl contains a pointer to its container.  This trips up
nvlist_send(nvl) and nvlist_dump(nvl), which intuitively should only
operate on nvl and its nvpairs.  In particular, both of these functions
will traverse to nvl's parent and start sending/dumping the parent's
nvpairs, which results in assertion failures or nonsensical output,
respectively.

Reviewed by:	oshogbo
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52360
printm is specific to the FreeBSD dtrace port.  I believe it's
effectively the same as tracemem(), though printm apparently predates
it.  It stores the size of the buffer of traced data inline.  Currently
it represents that size using a uintptr_t, which isn't really right and
poses challenges when porting to CHERI because
`DTRACE_STORE(uintptr_t, ...`  requires the destination to be suitably
aligned, but this isn't necessary since we're just storing a size.

Convert to using a size_t.  This should be a no-op since
sizeof(uintptr_t) == sizeof(size_t) on non-CHERI platforms (and besides
that I don't see a reason to use printm() when tracemem() is available
and is simpler to use.)

Reviewed by:	Domagoj Stolfa, avg
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D52055
It may pass packets up the stack and so needs to be called in a network
epoch.  When a watchdog timeout happens, we need to enter a section
explicitly.

Reviewed by:	zlei, glebius, adrian
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D51885
Otherwise we don't do anything to kick vcpu threads out of a sleep
state when destroying a VM.  For instance, suppose a guest executes hlt
on amd64 or wfi on arm64 with interrupts disabled.  Then,
bhyvectl --destroy will hang until the vcpu thread somehow comes out of
vm_handle_hlt()/vm_handle_wfi() since destroy_dev() is waiting for vCPU
threads to drain.

Note that on amd64, if hw.vmm.halt_detection is set to 1 (the default),
the guest will automatically exit in this case since it's treated as a
shutdown.  But, the above should not hang if halt_detection is set to 0.

Here, vm_suspend() wakes up vcpu threads, and a subsequent attempt to
run the vCPU will result in an error which gets propagated to userspace,
allowing destroy_dev() to proceed.

Add a new suspend code for this purpose.  Modify bhyve to exit with
status 4 ("exited due to an error") when it's received, since that's
what'll happen generally when the VM is destroyed asynchronously.

Reported by:	def
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D51761
PR:		288960
Reported by:	michaelo
MFC after:	2 days
This function was never safe to use.  We marked it deprecated in the
manual page in 2016, and it is marked obsolete in POSIX 2024.  We
previously added a linker warning and annotated the prototype; now that
stable/15 has been branched, we can remove it from main.

Relnotes:	yes
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D52474
If SRCCONF is not defined and src.conf exists at the top level of the
source tree, use that instead of /etc/src.conf.

MFC after:	3 days
Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D52470
Ref: GHI #518

This code is still a work-in-progress but now should actually behave more like an NSMenu should.

* note the pelethra of TODOs and FIXMEs left for future itterations

* this should unblock GHI #509
@github-actions
Copy link

Thank you for taking the time to contribute to FreeBSD!
There are a few issues that need to be fixed:

  • Missing Signed-off-by lines0c0f0b5
  • Real email address is needed0c0f0b5

Please review CONTRIBUTING.md, then update and push your branch again.

#if __has_feature(objc_categories)
@end

@implementation NSMenu (MenuHelpers)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in the Objective-C category MenuHelpers of NSMenu is focused on GHI #509

@mszoek please review around lines 1353-1440 (end)


TL;DR - rest of changes are just custodial and do not result in major change yet.

Areas to focus on: how should the DBus IDs for RavynOS be generated, the previous code never initializes them and there is no equivilant of these in apple's public APIs of NSMenu so I'll leave that executive decision up to you, I did implement the accessor/modifiers for the property on systems that define __RAVYNOS__ but that means the helper functions need to set it if it is to be used by other components. I followed the typical Objective-C principle of using the overflow values for the invalid indexes so unset values can be identified (even without Foundation's NSNotFound defined 👀 )

I also found the code to be a mix of manual and ARC and even what looked like c89 code (seriously it wasn't even Objective-C code) so I stabilized that and prepared the code for future work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical Summary


Overview

This PR introduces significant enhancements and modernizations to the NSMenu.h header file in the AppKit framework for ravynos. It adds platform-specific definitions, modern Objective-C attributes, improved nullability handling, more robust property/method declarations, and explicit support for the ravynos environment. The code is annotated with extensive comments and TODOs for future maintainability and compatibility.


Key Changes

1. Platform & Compatibility Macros

  • New Defines for ravynos:
    Introduces NSMENU_RAVYN_OS_PATTERN_* macros for common menu string patterns. These facilitate the use of localized or standardized menu item titles for application and system menus under ravynos.
  • Feature Detection Macros:
    Adds guards and feature checks (__has_feature(nullability), __has_feature(objc_arc), __has_feature(objc_protocol_qualifier_mangling)) for conditional compilation, improving cross-platform and cross-compiler compatibility.

2. Objective-C Attribute Support

  • OBJC_DESIGNATED_INITIALIZER Macro:
    Conditional macro for marking designated initializers, providing compiler-checked correctness in modern Objective-C.

3. Class Interface Modernization

  • Class Declaration:
    • Now conforms to both <NSCopying> and <NSCoding>, indicating support for copying and serialization.
    • Uses @protected and @private visibility for ivars, clarifying encapsulation.
  • DBusInstanceID Typedef:
    Adds a typedef for DBusInstanceID, with conditional definition.
  • Nullability Annotations:
    Properties and methods are now conditionally annotated for nullability, improving safety when used in Swift or modern Objective-C.

4. Properties and Methods

  • Properties:
    • Declares properties for supermenu, title, itemArray, and delegate with appropriate memory management attributes (weak, retain, copy, assign), all conditionally chosen based on ARC and nullability support.
  • Method Signatures:
    • All major API methods are updated to include nullability, and in some cases, new overloads are added for compatibility.
    • New methods for setting and getting itemArray.
    • Adds conditionally-compiled methods and properties for ravynos-specific features (e.g., _name, _menuWithName:).
  • Designated Initializer:
    • Adds documentation and the OBJC_DESIGNATED_INITIALIZER attribute to -initWithTitle:.
  • Menu Bar Height:
    • Adds method to get menu bar height if the proper macro is defined.

5. ravynos-Specific Enhancements

  • Menu Patterns:
    • Macros and helpers for common menu item naming conventions.
  • App Menu Construction Helper:
    • Adds a category method +newMenuAsApplicationMenu: to help construct an application menu based on the app name (ravynos only).
  • Warnings:
    • Explicit warnings for unsupported features (like NSFont and NSScreen) in this implementation.

6. Improved Nullability and Type Safety

  • Nullability Guards:
    • Extensive use of __nullable, __nonnull, __null_unspecified for pointers, making the API more robust for modern development.
  • Type Annotations for NSArray:
    • Uses __kindof for arrays where appropriate.

7. Comments, Fixmes, and Documentation

  • Rich Commenting:
    • Extensive FIXMEs, TODOs, and documentation for maintainers and future developers.
    • Licensing and authorship notes updated.

Technical Impact

  • Modernizes API and increases safety for Objective-C and Swift clients.
  • Improves cross-platform compatibility and prepares the code for better static analysis and compiler checking.
  • Provides ravynos-specific enhancements for system and application menu conventions.
  • Documents areas for future improvement and highlights current platform limitations.

Summary:
This PR is a major reworking of the NSMenu.h header, bringing it in line with modern Objective-C practices, increasing robustness, and adding ravynos-specific APIs and macros. It lays a strong foundation for future cross-platform and cross-language usability while documenting deliberate platform differences and pending work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical Summary


The changes to NSMenu.m in this PR represent a substantial refactor and modernization of the Objective-C implementation for RavynOS. Key technical updates include:

  • Major code expansion: The file grew by over 1,000 lines, adding detailed handling for menu structure, item management, and compatibility macros.
  • Enhanced platform-specific support: Numerous sections are now guarded by RAVYNOS and related macros, enabling RavynOS-specific behaviors and patterns (e.g., menu naming conventions, pattern strings for standard menu items).
  • Improved nullability annotations and Objective-C feature detection: Widespread use of __has_feature, OBJC_DESIGNATED_INITIALIZER, and other compile-time checks improves compatibility with modern Objective-C compilers and clarifies intent.
  • Expanded menu API: The NSMenu class now fully supports copying, encoding/decoding (NSCoding), thread-safety preparations (locking placeholders), and more robust item and submenu lookup.
  • Application menu helpers: A major addition is newMenuAsApplicationMenu:, which programmatically builds a standard application menu with About, Preferences, Services, Hide, Show, and Quit items, following platform conventions.
  • More robust memory management: Retain/release logic is explicit, and items are removed or updated safely, with placeholder logic for thread safety.
  • Extended validation and event handling: Key equivalent handling, click handling, and item enable/disable logic are more robust and modular.
  • Extensive documentation and TODOs: The code is heavily commented with implementation notes, platform compatibility warnings, and developer guidance.

In summary, this PR transforms NSMenu.m from a minimal implementation into a comprehensive, modern, platform-adapted menu system suitable for RavynOS, with extensibility and future improvements in mind.

@reactive-firewall
Copy link
Author

@mszoek,
I wanted to circle back this week on this; I would still love to get your opinion on these changes, when you get a chance.

@mszoek
Copy link
Collaborator

mszoek commented Sep 26, 2025

@mszoek, I wanted to circle back this week on this; I would still love to get your opinion on these changes, when you get a chance.

Hey! Sorry I haven't been able to review/merge this yet. I'm still trying to bisect the code to resolve some breakage from upstream, so can't really merge anything new until I get the branch back in shape. Soon I hope!

@reactive-firewall
Copy link
Author

Hey! Sorry I haven't been able to review/merge this yet. I'm still trying to bisect the code to resolve some breakage from upstream, so can't really merge anything new until I get the branch back in shape. Soon I hope!

No worries; The Breakage is why I kept the changes to one file at a time. If you'd rather a fully working AppKit, that will take me quite a bit longer, but is part of my own interest here (I'm interested namely in a stable Foundation.framework, and UIKit.framework AND/OR AppKit.framework)

Warning

If a broken main is an issue (I assumed just a sideffect of W.I.P.) Please don't merge this to main, keep it on a feature branch. See #519 for why it will break.

Side Note TL;DR; Now that I've taken a look at the AppKit as a whole (it seems clearly a derivative of Cocotron from a while back) my plan is to piecewise refactor (e.g. one class at a time when I have the time) and modernize the codebase, focusing on core interfaces (leaving extensions for now). NSMenuItem is next on my list.

Important

What I namely need to get your opinion on is the RavynOS specific design:

@implementation NSMenu (MenuHelpers)
#endif
/*
Circa 2025
Modification provided by Mr. Walls under MIT
*/
#if !__has_feature(nullability)
+(NSMenu *)newMenuAsApplicationMenu:(NSString*)appName
#else
+(NSMenu * _Nonnull)newMenuAsApplicationMenu:(NSString*)appName
#endif
{
//TODO: add localization logic
NSMenu *aMenu = [NSMenu new];
// legacy code:
//[aMenu setValue:@"NSAppleMenu" forKey:@"name"]; // assuming KvP
//FIXME: generate valid DBus
#if defined(DBusInstanceID)
//FIXME: generate valid DBusItemID for this menu and assign it here
#endif
[aMenu setTitle:appName];
NSMenuItem *aboutItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSMENU_RAVYN_OS_PATTERN_APPMENU_ABOUT_TITLE, appName]
action:@selector(orderFrontStandardAboutPanel:)
keyEquivalent:@""];
[aboutItem setTarget:[NSApplication sharedApplication]]; // FIXME: should be set to first-responder
[aMenu addItem:aboutItem];
[aMenu addItem:[NSMenuItem separatorItem]];
// this stuff must be customized by the App Developer
NSMenuItem *prefItem = [[NSMenuItem alloc] initWithTitle:NSMENU_RAVYN_OS_PATTERN_APPMENU_PREFERENCES_TITLE
action:NULL
keyEquivalent:@","];
[prefItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand]; // now it is command+comma
[prefItem setTarget:nil]; // FIXME: should be set to custom target
// consider default of [prefItem setEnabled:NO];
[aMenu addItem:prefItem];
[aMenu addItem:[NSMenuItem separatorItem]];
#if defined(NSMENU_RAVYN_OS_SUPPORTS_APP_SERVICES) && NSMENU_RAVYN_OS_SUPPORTS_APP_SERVICES
//FIXME: handle services menu stuff
NSMenuItem *servicesItem = [[NSMenuItem alloc] initWithTitle:@"Services"
action:NULL
keyEquivalent:@""];
[servicesItem setTarget:nil]; // FIXME: should be set to system
[servicesItem setSubmenu:[NSMenu new]]; // FIXME: this is an empty placeholder for system services menu
[aMenu addItem:servicesItem];
[aMenu addItem:[NSMenuItem separatorItem]];
#endif
NSMenuItem *hideSelfItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSMENU_RAVYN_OS_PATTERN_APPMENU_HIDE_SELF_TITLE, appName]
action:@selector(hide:)
keyEquivalent:@"h"];
[hideSelfItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand]; // now it is command+h
[hideSelfItem setTarget:[NSApplication sharedApplication]]; // FIXME: should be set to first-responder
[aMenu addItem:hideSelfItem];
NSMenuItem *hideOthersItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSMENU_RAVYN_OS_PATTERN_APPMENU_HIDE_OTHERS_TITLE, appName]
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"];
[hideOthersItem setKeyEquivalentModifierMask:(NSEventModifierFlagCommand|NSEventModifierFlagOption)]; // now it is command+option/alt+h
[hideOthersItem setTarget:[NSApplication sharedApplication]]; // FIXME: should be set to first-responder
[aMenu addItem:hideOthersItem];
NSMenuItem *showAllItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSMENU_RAVYN_OS_PATTERN_APPMENU_SHOW_ALL_TITLE, appName]
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
[showAllItem setTarget:[NSApplication sharedApplication]]; // FIXME: should be set to first-responder
[aMenu addItem:showAllItem];
[aMenu addItem:[NSMenuItem separatorItem]];
// see GHI https://github.com/ravynsoft/ravynos/issues/288
NSMenuItem *quitItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSMENU_RAVYN_OS_PATTERN_APPMENU_QUIT_TITLE, appName] action:@selector(terminate:) keyEquivalent:@"q"];
[quitItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand]; // now it is command+q
[quitItem setTarget:[NSApplication sharedApplication]];
[aMenu addItem:quitItem];
return aMenu;
}
#endif /* !__RAVYNOS__ */
@end

e.g., does this look like what you feel we discussed in GHI #509


If you still want to get the upstream stuff working, first, I'll be patient, so no rush from me. 🙇 I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet