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

fix build and key shortcuts on macOS + disable AppNap #1705

Closed
wants to merge 0 commits into from

Conversation

matatata
Copy link

The qxt-mini library did not properly register keyboards presses and releases. I've fixed that. Without that the center binding would cause opentrack to always keep centering for instance. I also made small other tweaks to be able to build and run it.

@sthalik
Copy link
Member

sthalik commented Aug 25, 2023

I already cherry-picked the qxt-mini fix. It was a long time coming, thank you.

The macdeployqt change can't be merged, as Qt can be installed from anything from the official installer, macports, homebrew, or straight from the source code. So expecting the user to set up PATH is more of a general solution.

If the qApp assert fails, something's wrong. I guess it's before main? It should never be called like that. It becomes legal to call once QApplication gets instantiated. If it's called after it does and still crashes, then it can be something worse like multiple versions of Qt linked into the same process.

@matatata
Copy link
Author

matatata commented Aug 25, 2023

Hi, I'm glad you could use some of my changes. In fact the keyboard change is the most important one. I'm not sure why the assert failed, but when I take it away the program works just fine.

There's one other important thing I noticed: macOS is throttling the process when in background rendering it somewhat useless. The feature is called AppNap and I've been looking into the docs and apparently you can write some code to let macOS know it should not throttle the process... such as

http://arsenkin.com/Disable-app-nap.html

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheAppLevel.html#//apple_ref/doc/uid/TP40013929-CH36-SW1

If I only knew how to add some objective-c code to the project I might be able to try things out. Do you have a clue where to put the code best? I'm struggling with all the make boilerplates and I just cannot figure out how to make the adaptations.

@sthalik
Copy link
Member

sthalik commented Aug 25, 2023

If I only knew how to add some objective-c code to the project I might be able to try things out. Do you have a clue where to put the code best?

Try adding it after a space character.

file(GLOB cxx CONFIGURE_DEPENDS "${dir}/*.cpp" "${dir}/*.m" "${dir}/*.mm")

The actual objc file extension notwithstanding.

lib.m
)

enable_language(OBJCXX)
Copy link
Member

Choose a reason for hiding this comment

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

Add around enable_language(RC) in toplevel cmakelists.txt.

if(APPLE)
    enable_language(OBJCXX)
endif()

enable_language(OBJCXX)


add_library(AppNapLib SHARED
Copy link
Member

Choose a reason for hiding this comment

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

Link statically.


)

target_link_libraries(AppNapLib
Copy link
Member

Choose a reason for hiding this comment

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

With STATIC, try target_link_libraries(AppNapLib INTERFACE "-framework Foundation").

opentrack/main-window.cpp Outdated Show resolved Hide resolved
set_source_files_properties(resources.rc OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/opentrack.ico")

target_link_libraries(${self} opentrack-user-interface opentrack-version)
target_link_libraries(${self} opentrack-user-interface opentrack-version AppNapLib)
Copy link
Member

Choose a reason for hiding this comment

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

Just add another target_link_libraries() line dependent on APPLE.

@matatata matatata force-pushed the master branch 2 times, most recently from 7be6157 to 6dae83a Compare August 25, 2023 17:02
@sthalik
Copy link
Member

sthalik commented Aug 25, 2023

@matatata, See if this cleaned up diff works for you. If it does, I'm going to commit it with your name on it.

I don't have vmware unlocker installed right now so I can't run run the OSX build for the time being.

patch.diff.txt

@matatata matatata changed the title fix build and key shortcuts on macOS fix build and key shortcuts on macOS + disable AppNap Aug 25, 2023
@matatata
Copy link
Author

matatata commented Aug 25, 2023

If I only knew how to add some objective-c code to the project I might be able to try things out. Do you have a clue where to put the code best?

Try adding it after a space character.

file(GLOB cxx CONFIGURE_DEPENDS "${dir}/*.cpp" "${dir}/*.m" "${dir}/*.mm")

The actual objc file extension notwithstanding.

Thank you. That helped indeed. I've made the changes. It was quite simple in the end. It works fine so far.. no throttling any more. Please have a look at the latest commit.

@matatata
Copy link
Author

oh I just see that you had commented my previous attempt. As you can see I threw most of it away.

@sthalik
Copy link
Member

sthalik commented Aug 25, 2023

The cmake code still isn't ok. Just test this patch via git apply on a clean repo and come back to me. This way we avoid a longer back-and-forth with me having to nitpick trivial lines in the commit.

@matatata
Copy link
Author

I'll work in your cleanups ..you sent me. sorry did not realise. was too focussed..

@matatata
Copy link
Author

I'm done so far. Unfortunately the *.mm change broke the linux build. Maybe you can help? I need to go now. Will check back later. CU

@matatata
Copy link
Author

matatata commented Aug 25, 2023 via email

@sthalik
Copy link
Member

sthalik commented Aug 25, 2023

Merged, thanks.

With regard to your qApp problem -- you may want to verify whether the assertion trips after QApplication has already been created. If it gets called before that, it's an opentrack bug. Otherwise:

$ DYLD_PRINT_LIBRARIES=1 opentrack 2>&1 | grep Qt | sort

See if there are any duplicates, such as QtCore loaded from 2 different .so's or something.

@matatata
Copy link
Author

matatata commented Aug 26, 2023 via email

@sthalik
Copy link
Member

sthalik commented Aug 26, 2023

Then macdeployqt doesn't run install_name_tool properly. Consider modifying the build process to use the old method.

@matatata
Copy link
Author

matatata commented Aug 26, 2023

Then macdeployqt doesn't run install_name_tool properly. Consider modifying the build process to use the old method.

Actually I tried to remove the calls of that install-fail-tool script and at least for me macdeployqt does very well. No issues anymore. I could open the binary on a different mac as well. Perhaps it is not needed anymore and does more harm than good.

@sthalik
Copy link
Member

sthalik commented Aug 26, 2023

Just to make it clear, you no longer need to remove the qApp assert as long as install-fail-tool is commented out?

@matatata
Copy link
Author

matatata commented Aug 26, 2023 via email

sthalik added a commit that referenced this pull request Aug 27, 2023
Using install-fail-tool with macdeployqt together will load duplicate
copies of the shared libraries into the process, leading to crashes.

Reported by: @matatata
Issue: #1705
@sthalik
Copy link
Member

sthalik commented Aug 27, 2023

It's very important that this got fixed. Thanks for reporting that.

As for macdeployqt's path in the shell script -- generally for Unix systems users are expected to make a symlink to the binaries or simply add them to their PATH. Do you think this should be the case here or not?

@sthalik
Copy link
Member

sthalik commented Aug 27, 2023

There's also another osx issue where qxt-mini doesn't understand keystrokes such as 'home' or 'left arrow'. Since you knew how to fix the lack of the keyup event, you might want to look at that too.

@matatata
Copy link
Author

It's very important that this got fixed. Thanks for reporting that.

As for macdeployqt's path in the shell script -- generally for Unix systems users are expected to make a symlink to the binaries or simply add them to their PATH. Do you think this should be the case here or not?

I did put it in the PATH eventually. You cannot know in advance where it will be on the user's system, so I think it's ok that the user compiling it needs to symlink it or put it in the PATH.

@matatata
Copy link
Author

There's also another osx issue where qxt-mini doesn't understand keystrokes such as 'home' or 'left arrow'. Since you knew how to fix the lack of the keyup event, you might want to look at that too.

I just checked and seems all keys work except the keys on the numpad. Yes I plan to take a look at it in future. Out of curiosity: The Freetrack 2.0 Enhanced Output plugin is not available on Mac, because it's some third party thing, right?

@sthalik
Copy link
Member

sthalik commented Aug 27, 2023

The Freetrack 2.0 Enhanced Output plugin is not available on Mac, because it's some third party thing, right?

Use proto/wine. You must set a cache variable for it to become available.

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

Successfully merging this pull request may close these issues.

2 participants