Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cocoa port #32

Merged
merged 10 commits into from
Dec 13, 2022
Merged

Cocoa port #32

merged 10 commits into from
Dec 13, 2022

Conversation

Frityet
Copy link
Contributor

@Frityet Frityet commented Dec 6, 2022

this PR will eventually have a full port to Cocoa, the native GUI library for MacOS.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

@AndroGR I need some help adding Cocoa to the CMakeLists.txt, I am not used to cmake

@tseli0s
Copy link
Owner

tseli0s commented Dec 6, 2022

Hello,
These days I'm not getting on my computer due to school and being sick. So while I'll be able to see your progress, I can't (temporarily) make any code commits or test anything out.

In the meantime, if you have any questions, feel free to make them; I'm able to help at any moment.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

if you have any questions, feel free to make them

How do I add a new target to the cmake? in my testing this seems to completley not work as when I try to build it only goes to GTK4

@tseli0s
Copy link
Owner

tseli0s commented Dec 6, 2022

You seem to have confused what previously written code (Specifically the WIN32_TARGET option) does, and that's why. Try using the Gtk3 or libadwaita parts instead. Otherwise I'll take care of it while you write the actual backend.

ED: The WIN32_TARGET option is used to build a Windows library from Linux, it's just for Wine testing.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

You seem to have confused what previously written code (Specifically the WIN32_TARGET option) does, and that's why. Try using the Gtk3 or libadwaita parts instead. Otherwise I'll take care of it while you write the actual backend.

ED: The WIN32_TARGET option is used to build a Windows library from Linux, it's just for Wine testing.

Oh okay, thank you!

@tseli0s
Copy link
Owner

tseli0s commented Dec 6, 2022

Another thing I've noticed, you seem to mix Objective C and C code in one file, and then to the actual library. This is a horrible decision: It may not work between compilers due to different ABIs, may fail to build in the first place or may cause undefined behavior due to type mismatches.

If possible, create a C file where you call the functions from another, independently built library. So something like this could do:

// backend/cocoa/nvdialog_file_dialog.c

void nvd_get_file_location_cocoa(...) {
    // FFI call, from your Obj-C code
    nvd_get_file_location_cocoa_REAL(...)
}

And implement nvd_get_file_location_cocoa_REAL in another file, which you're going to link as a library.

If all that sounds hard, you can try writing a Makefile to use temporarily. You can also use extern "C" if it helps but I'm still challenging the idea it's actually going to work.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

Objective C is fully ABI compatible with C, and each C function (not methods) use the C ABI. If required I will do that, but it will be the same result

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

                 U _OBJC_CLASS_$_OFConstantString
                 U _OFStdOut
0000000100000000 T __mh_execute_header
0000000100003f30 T _fn
0000000100003f60 T _main
                 U _objc_msgSend
                 U dyld_stub_binder

from this

#import <ObjFW/OFStdIOStream.h>

void fn(OFString *str)
{
	[OFStdOut writeLine: str];
}

int main()
{
	[OFStdOut writeLine: @"Calling!"];
	fn(@"Called!");
}

@Frityet
Copy link
Contributor Author

Frityet commented Dec 6, 2022

Screen Shot 2022-12-06 at 12 36 09

Same result on linux

@tseli0s
Copy link
Owner

tseli0s commented Dec 7, 2022

Okay, I guess I'll leave that to you.

@tseli0s
Copy link
Owner

tseli0s commented Dec 7, 2022

I'll fix the CMake script to compile, I hope you can test if it actually compiles.
ED: Made the first commits, I'll set up CI later to test automatically.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 7, 2022

I'll fix the CMake script to compile, I hope you can test if it actually compiles. ED: Made the first commits, I'll set up CI later to test automatically.

The objc code def compiles and works, for I have used it for previous projects

@Frityet
Copy link
Contributor Author

Frityet commented Dec 7, 2022

Still trying to build for GTK4 :/

GTK 4 runs on MacOS btw

@tseli0s
Copy link
Owner

tseli0s commented Dec 7, 2022

While it does, you can skip it altogether because the whole point of NvDialog is to use Cocoa in this case, or the native UI library in general on each system.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 7, 2022

While it does, you can skip it altogether because the whole point of NvDialog is to use Cocoa in this case, or the native UI library in general on each system.

How do I make it build with cocoa though

@Frityet
Copy link
Contributor Author

Frityet commented Dec 8, 2022

Update: figured it out!

@Frityet
Copy link
Contributor Author

Frityet commented Dec 8, 2022

Screen Shot 2022-12-07 at 17 04 32

@tseli0s
Copy link
Owner

tseli0s commented Dec 8, 2022

Looks like we've got most of the work away. However I noticed you enabled the libadwaita backend too. You need to disable it:

How do I make it build with cocoa though

Since the previous changes I made in CMakeLists.txt, if macOS is detected it will automatically use Cocoa.

@Frityet
Copy link
Contributor Author

Frityet commented Dec 11, 2022

@AndroGR with the exeception of "about" and notifications, the PR should be ready

@tseli0s
Copy link
Owner

tseli0s commented Dec 12, 2022

For the about dialog part, is there a ready to use Cocoa function? Because otherwise you can skip it for now and make it return NULL when called.

@tseli0s
Copy link
Owner

tseli0s commented Dec 12, 2022

Also, make sure to sync with master, there are some conflicts because you are using the older version of the tests/ folder.

@tseli0s tseli0s added enhancement New feature or request good first issue Good for newcomers labels Dec 12, 2022
@tseli0s tseli0s assigned tseli0s and unassigned Frityet and tseli0s Dec 12, 2022
@tseli0s tseli0s linked an issue Dec 12, 2022 that may be closed by this pull request
@Frityet
Copy link
Contributor Author

Frityet commented Dec 12, 2022

For the about dialog part, is there a ready to use Cocoa function?

Nope, none from what I have seen

@Frityet
Copy link
Contributor Author

Frityet commented Dec 12, 2022

Done, ready to be merged

@Frityet
Copy link
Contributor Author

Frityet commented Dec 12, 2022

nvm found out how to make about windows

@Frityet
Copy link
Contributor Author

Frityet commented Dec 12, 2022

it is done

@Frityet Frityet marked this pull request as ready for review December 12, 2022 21:35
@tseli0s
Copy link
Owner

tseli0s commented Dec 13, 2022

Merging, thanks for the contribution!

@tseli0s tseli0s merged commit a4bf3ba into tseli0s:master Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MacOS X Support
2 participants