ladybird/Libraries/LibCore/CMakeLists.txt
ayeteadoe f4c8fd4bef LibCore+LibWebView+UI/Qt: Support TimeZoneWatcher on Windows
To detect system time zone changes on Windows, the event we need to look
for is WM_TIMECHANGE. The problem is how the callback with said message
actually gets invoked is very particular. (1) We must have an active
message pump (event loop) for the message to ever be processed. (2) We
must be a GUI application as WM_TIMECHANGE messages are seemingly sent
to top level windows only. It doesn't say that in the docs for the
event, but attempts of creating a LibTest-based application with a
message pump and a message only window and never receiving the event
point to that probably being true.

This workaround is built off the fact that Qt's message pump defined
internally in QEventDispatcherWin32::processEvents does in fact receive
WM_TIMECHANGE events, even though it is not exposed as a QEvent::Type.
Given the requirements stated above it makes sense that it works here as
the message pump is executing in a QGuiApplication context. So we use a
native event filter to hook into the unexposed WM_TIMECHANGE event and
forward it along to the on_time_zone_changed() callback.

Note that if a Windows GUI framework is done in the future, we'll have
to re-add support to ensure the TimeZoneWatcher still gets invoked.
2025-10-05 15:46:15 +02:00

166 lines
4.4 KiB
CMake

# These are the minimal set of sources needed to build the code generators. We separate them to allow
# LibCore to depend on generated sources.
set(SOURCES
ArgsParser.cpp
Directory.cpp
DirectoryEntry.cpp
DirIterator.cpp
Environment.cpp
File.cpp
StandardPaths.cpp
Version.cpp
)
if (WIN32)
list(APPEND SOURCES
ProcessWindows.cpp
SocketpairWindows.cpp
SystemWindows.cpp)
else()
list(APPEND SOURCES
Process.cpp
System.cpp)
endif()
ladybird_lib(LibCoreMinimal coreminimal)
if (WIN32)
find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED)
target_include_directories(LibCoreMinimal PRIVATE ${DIRENT_INCLUDE_DIR})
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
# NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
target_link_libraries(LibCoreMinimal PRIVATE rt)
endif()
if (LAGOM_TOOLS_ONLY)
return()
endif()
set(SOURCES
ConfigFile.cpp
ElapsedTimer.cpp
EventLoop.cpp
EventLoopImplementation.cpp
EventReceiver.cpp
MappedFile.cpp
MimeData.cpp
Notifier.cpp
Resource.cpp
ResourceImplementation.cpp
ResourceImplementationFile.cpp
SystemServerTakeover.cpp
ThreadEventQueue.cpp
Timer.cpp
)
if (WIN32)
list(APPEND SOURCES
SocketWindows.cpp
AnonymousBufferWindows.cpp
EventLoopImplementationWindows.cpp
UDPServerWindows.cpp
TCPServerWindows.cpp)
else()
list(APPEND SOURCES
Socket.cpp
AnonymousBuffer.cpp
EventLoopImplementationUnix.cpp
UDPServer.cpp
TCPServer.cpp)
endif()
if (NOT WIN32 AND NOT EMSCRIPTEN)
list(APPEND SOURCES LocalServer.cpp)
elseif (WIN32)
list(APPEND SOURCES LocalServerWindows.cpp)
endif()
# FIXME: Implement these for other systems.
if (LINUX AND NOT EMSCRIPTEN)
list(APPEND SOURCES
FileWatcherLinux.cpp
Platform/ProcessStatisticsLinux.cpp
TimeZoneWatcherLinux.cpp
)
elseif (APPLE AND NOT IOS)
list(APPEND SOURCES
FileWatcherUnimplemented.cpp
Platform/ProcessStatisticsMach.cpp
TimeZoneWatcherMacOS.mm
)
elseif (WIN32)
list(APPEND SOURCES
FileWatcherUnimplemented.cpp
Platform/ProcessStatisticsUnimplemented.cpp
TimeZoneWatcherWindows.cpp
)
else()
list(APPEND SOURCES
FileWatcherUnimplemented.cpp
Platform/ProcessStatisticsUnimplemented.cpp
TimeZoneWatcherUnimplemented.cpp
)
endif()
if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "GNU")
list(APPEND SOURCES MachPort.cpp)
endif()
if (APPLE)
list(APPEND SOURCES IOSurface.cpp)
endif()
ladybird_lib(LibCore core)
target_link_libraries(LibCore PRIVATE LibUnicode LibURL Threads::Threads)
target_link_libraries(LibCore PUBLIC LibCoreMinimal)
if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
# NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
target_link_libraries(LibCore PRIVATE rt)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
# Solaris has socket and networking related functions in two extra libraries
target_link_libraries(LibCore PRIVATE nsl socket)
endif()
if (HAIKU)
# Haiku has networking related functions in the network library
target_link_libraries(LibCore PRIVATE network)
endif()
if (APPLE)
target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")
target_link_libraries(LibCore PUBLIC "-framework CoreServices")
target_link_libraries(LibCore PUBLIC "-framework Foundation")
target_link_libraries(LibCore PUBLIC "-framework IOSurface")
endif()
if (ANDROID)
target_link_libraries(LibCore PRIVATE log)
endif()
if (ENABLE_SWIFT)
set(SWIFT_EXCLUDE_HEADERS "SocketAddressWindows.h")
if(WIN32)
list(APPEND SWIFT_EXCLUDE_HEADERS "EventLoopImplementationUnix.h")
else()
list(APPEND SWIFT_EXCLUDE_HEADERS "EventLoopImplementationWindows.h")
endif()
if (NOT APPLE)
list(APPEND SWIFT_EXCLUDE_HEADERS
IOSurface.h
MachPort.h
MachMessageTypes.h
ProcessStatisticsMach.h
)
endif()
generate_clang_module_map(LibCore EXCLUDE_FILES ${SWIFT_EXCLUDE_HEADERS})
target_sources(LibCore PRIVATE
EventSwift.mm
EventLoopExecutor.swift)
set_source_files_properties(EventSwift.mm PRIVATE PROPERTIES COMPILE_FLAGS -fblocks)
target_link_libraries(LibCore PRIVATE AK)
add_swift_target_properties(LibCore LAGOM_LIBRARIES AK)
endif()