Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# for clang-format 17.0.1
Language: Cpp
Expand Down Expand Up @@ -188,3 +190,196 @@ TabWidth: 4
UseTab: Never
# VerilogBreakBetweenInstancePorts:
# WhitespaceSensitiveMacros:

---

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# for clang-format 17.0.1
Language: ObjC
BasedOnStyle: "WebKit"
# AccessModifierOffset: 2
AlignAfterOpenBracket: "AlwaysBreak"
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
# AlignConsecutiveShortCaseStatements: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 1
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
# AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
# AttributeMacros:
# - __pragma
# - _Pragma
# - __attribute__
# - __declspec
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: After
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: true
# AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# BracedInitializerIndentWidth: 4
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: true
BreakArrays: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 140
# CommentPragmas: '^ MEO pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
# ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
# ForEachMacros:
# - foreach
# - Q_FOREACH
# - BOOST_FOREACH
# IfMacros:
# - 'KJ_IF_MAYBE'
IncludeBlocks: Preserve
# IncludeCategories:
# IncludeIsMainRegex:
# IncludeIsMainSourceRegex:
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequiresClause: false
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: Wrapped
IntegerLiteralSeparator:
Binary: 4
BinaryMinDigits: 9
Decimal: 3
DecimalMinDigits: 7
Hex: -1
# JavaImportGroups:
# JavaScriptQuotes:
# JavaScriptWrapImports:
KeepEmptyLinesAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
# LineEnding: LF
# MacroBlockBegin: "MAA.*_NS_BEGIN$"
# MacroBlockEnd: "MAA.*_NS_END$"
# Macros:
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
# NamespaceMacros:
# ObjCBinPackProtocolList:
# ObjCBlockIndentWidth:
# ObjCBreakBeforeNestedBlockParam:
# ObjCSpaceAfterProperty:
# ObjCSpaceBeforeProtocolList:
PackConstructorInitializers: Never
# PenaltyBreakAssignment:
# PenaltyBreakBeforeFirstCallParameter:
# PenaltyBreakComment:
# PenaltyBreakFirstLessLess:
# PenaltyBreakOpenParenthesis:
# PenaltyBreakTemplateDeclaration:
# PenaltyExcessCharacter:
# PenaltyIndentedWhitespace:
# PenaltyReturnTypeOnItsOwnLine:
PointerAlignment: Left
# QualifierAlignment: Custom
# QualifierOrder:
# - inline
# - static
# - const
# - constexpr
# - type
ReferenceAlignment: Left
ReflowComments: true
RemoveBracesLLVM: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1000
SortIncludes: CaseSensitive
# SortJavaStaticImport:
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
# SpaceBeforeParensOptions:
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInSquareBrackets: false
Standard: c++20
# StatementAttributeLikeMacros:
# StatementMacros:
TabWidth: 4
# TypeNames:
# TypenameMacros:
UseTab: Never
# VerilogBreakBetweenInstancePorts:
# WhitespaceSensitiveMacros:
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(Boost_NO_WARN_NEW_VERSIONS ON)

option(WITH_ADB_CONTROLLER "build with adb controller" ON)
option(WITH_WIN32_CONTROLLER "build with win32 controller" ON)
option(WITH_MAC_CONTROLLER "build with mac controller" ON)
option(WITH_DBG_CONTROLLER "build with debugging controller" ON)
option(WITH_CUSTOM_CONTROLLER "build with custom controller" ON)
option(WITH_NODEJS_BINDING "build with nodejs binding" OFF)
Expand Down Expand Up @@ -51,6 +52,11 @@ if(WITH_WIN32_CONTROLLER AND NOT WIN32)
set(WITH_WIN32_CONTROLLER OFF)
endif()

if(WITH_MAC_CONTROLLER AND NOT APPLE)
message(STATUS "Not on MacOS, disable WITH_MAC_CONTROLLER")
set(WITH_MAC_CONTROLLER OFF)
endif()

find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)
find_package(Boost REQUIRED CONFIG COMPONENTS system)
find_package(ZLIB REQUIRED)
Expand Down Expand Up @@ -132,3 +138,4 @@ if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/export_targets.cmake)
#
# cmake-format: on
endif()
add_subdirectory(test/dummy)
10 changes: 9 additions & 1 deletion include/MaaFramework/Instance/MaaController.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* @file MaaController.h
* @author
* @brief The controller interface. See \ref MaaControllerPostRequest for details on how to post requests to the controller.
* @brief The controller interface. See \ref MaaControllerPostRequest for details on how to post
* requests to the controller.
*
* @copyright Copyright (c) 2024
*
Expand Down Expand Up @@ -38,6 +39,13 @@ extern "C"
MaaNotificationCallback notify,
void* notify_trans_arg);

MAA_FRAMEWORK_API MaaController* MaaMacControllerCreate(
uint32_t windowId,
MaaMacScreencapMethod screencap_method,
MaaMacInputMethod input_method,
MaaNotificationCallback notify,
void* notify_trans_arg);

MAA_FRAMEWORK_API MaaController* MaaCustomControllerCreate(
MaaCustomControllerCallbacks* controller,
void* controller_arg,
Expand Down
16 changes: 16 additions & 0 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ typedef uint64_t MaaWin32InputMethod;
#define MaaWin32InputMethod_Seize 1ULL
#define MaaWin32InputMethod_SendMessage (1ULL << 1)

// MaaMacScreencapMethod:
/**
* No bitwise OR, just set it
*/
typedef uint64_t MaaMacScreencapMethod;
#define MaaMacScreencapMethod_None 0ULL
#define MaaMacScreencapMethod_CGWindowList 1ULL

// MaaMacInputMethod:
/**
* No bitwise OR, just set it
*/
typedef uint64_t MaaMacInputMethod;
#define MaaMacInputMethod_None 0ULL
#define MaaMacInputMethod_CGEvent 1ULL

// MaaDbgControllerType:
/**
* No bitwise OR, just set it
Expand Down
4 changes: 4 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if(WITH_WIN32_CONTROLLER)
add_subdirectory(MaaWin32ControlUnit)
endif()

if(WITH_MAC_CONTROLLER)
add_subdirectory(MaaMacControlUnit)
endif()

if(WITH_DBG_CONTROLLER)
add_subdirectory(MaaDbgControlUnit)
endif()
Expand Down
40 changes: 40 additions & 0 deletions source/LibraryHolder/ControlUnit/ControlUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ControlUnit/AdbControlUnitAPI.h"
#include "ControlUnit/CustomControlUnitAPI.h"
#include "ControlUnit/DbgControlUnitAPI.h"
#include "ControlUnit/MacControlUnitAPI.h"
#include "ControlUnit/Win32ControlUnitAPI.h"
#include "Utils/Logger.h"
#include "Utils/Runtime.h"
Expand Down Expand Up @@ -131,6 +132,45 @@ std::shared_ptr<MAA_CTRL_UNIT_NS::ControlUnitAPI>
return std::shared_ptr<MAA_CTRL_UNIT_NS::ControlUnitAPI>(control_unit_handle, destroy_control_unit_func);
}

std::shared_ptr<MAA_CTRL_UNIT_NS::ControlUnitAPI> MacControlUnitLibraryHolder::create_control_unit(
uint32_t windowId,
MaaMacScreencapMethod screencap_method,
MaaMacInputMethod input_method)
{
if (!load_library(library_dir() / libname_)) {
LogError << "Failed to load library" << VAR(library_dir()) << VAR(libname_);
return nullptr;
}

check_version<MacControlUnitLibraryHolder, decltype(MaaMacControlUnitGetVersion)>(version_func_name_);

auto create_control_unit_func = get_function<decltype(MaaMacControlUnitCreate)>(create_func_name_);
if (!create_control_unit_func) {
LogError << "Failed to get function create_control_unit";
return nullptr;
}

auto destroy_control_unit_func = get_function<decltype(MaaMacControlUnitDestroy)>(destroy_func_name_);
if (!destroy_control_unit_func) {
LogError << "Failed to get function destroy_control_unit";
return nullptr;
}

auto control_unit_handle = create_control_unit_func(windowId, screencap_method, input_method);

if (!control_unit_handle) {
LogError << "Failed to create control unit";
return nullptr;
}

auto destroy_control_unit = [destroy_control_unit_func](MaaControlUnitHandle handle) {
destroy_control_unit_func(handle);
unload_library();
};

return std::shared_ptr<MAA_CTRL_UNIT_NS::ControlUnitAPI>(control_unit_handle, destroy_control_unit);
}

std::shared_ptr<MAA_CTRL_UNIT_NS::ControlUnitAPI>
CustomControlUnitLibraryHolder::create_control_unit(MaaCustomControllerCallbacks* controller, void* controller_arg)
{
Expand Down
33 changes: 33 additions & 0 deletions source/MaaFramework/API/MaaFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ MaaController* MaaWin32ControllerCreate(
#endif
}

MaaController* MaaMacControllerCreate(
uint32_t windowId,
MaaMacScreencapMethod screencap_method,
MaaMacInputMethod input_method,
MaaNotificationCallback notify,
void* notify_trans_arg)
{
LogFunc << VAR(windowId) << VAR(screencap_method) << VAR(input_method) << VAR_VOIDP(notify) << VAR_VOIDP(notify_trans_arg);

#ifndef __APPLE__

LogError << "This API" << __FUNCTION__ << "is only available on MacOS";
return nullptr;

#else

if (!windowId) {
LogError << "windowId is 0";
return nullptr;
}

auto control_unit = MAA_NS::MacControlUnitLibraryHolder::create_control_unit(windowId, screencap_method, input_method);

if (!control_unit) {
LogError << "Failed to create control unit";
return nullptr;
}

return new MAA_CTRL_NS::ControllerAgent(std::move(control_unit), notify, notify_trans_arg);

#endif
}

MaaController* MaaCustomControllerCreate(
MaaCustomControllerCallbacks* controller,
void* controller_arg,
Expand Down
Loading
Loading