23#include <Protocol/GraphicsOutput.h>
24#include <Protocol/UgaDraw.h>
25#include <Protocol/SimplePointer.h>
29#include <Library/BaseLib.h>
30#include <Library/BaseMemoryLib.h>
31#include <Library/DebugLib.h>
32#include <Library/MemoryAllocationLib.h>
33#include <Library/UefiBootServicesTableLib.h>
34#include <Library/UefiLib.h>
35#include <Library/UefiRuntimeServicesTableLib.h>
36#include <Library/TimerLib.h>
40#include <Library/BaseLib.h>
47#define MIN_POINTER_POLL_PERIOD 10
48#define MAX_POINTER_POLL_PERIOD 80
50#define MAX_CLICK_DURATION 148
51#define MAX_DOUBLE_CLICK_SPEED 748
53#define MAX_POLL_DURATION ((MAX_UINT32 / 10000) / MAX_DOUBLE_CLICK_SPEED)
62#define MINIMAL_MOVEMENT 5
162 Status =
gRT->GetVariable (
169 if (EFI_ERROR (Status) || (
mUiScale != 2)) {
176 IN UINT32 PointerPollMin,
177 IN UINT32 PointerPollMax,
178 IN UINT32 PointerPollMask
205 IN UINT16 PointerSpeedDiv,
206 IN UINT16 PointerSpeedMul
209 if (PointerSpeedDiv != 0) {
214 "OCAE: Illegal PointerSpeedDiv value 0, using 1\n",
225 IN UINT16 ClickTimeout,
226 IN UINT16 DoubleClickTimeout,
240 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
246 DEBUG ((DEBUG_VERBOSE,
"InternalRegisterSimplePointerInterface\n"));
248 Instance = AllocateZeroPool (
252 if (Instance != NULL) {
269 Instance[Index].
Interface = SimplePointer;
282 SimplePointer->Mode->ResolutionX,
292 SimplePointer->Mode->ResolutionY,
306 DEBUG ((DEBUG_VERBOSE,
"EventSimplePointerDesctructor\n"));
322 IN UINTN *NumberOfInstances,
323 IN EFI_GUID *Protocol
334 UINTN NumberOfMatches;
336 DEBUG ((DEBUG_VERBOSE,
"InternalRemoveUninstalledInstances\n"));
338 OrgInstances = *InstancesPtr;
340 Status =
gBS->LocateHandleBuffer (
348 if (!EFI_ERROR (Status)) {
349 if (*NumberOfInstances > 0) {
352 for (Index = 0; Index < *NumberOfInstances; ++Index) {
353 Instance = &OrgInstances[Index];
356 for (Index2 = 0; Index2 < NumberHandles; ++Index2) {
363 if (NumberHandles == Index2) {
369 if (NumberOfMatches != *NumberOfInstances) {
374 if (NumberOfMatches > 0) {
375 NewInstances = AllocateZeroPool (
376 NumberOfMatches *
sizeof (*NewInstances)
380 if (NewInstances != NULL) {
382 for (Index = 0; Index < *NumberOfInstances; ++Index) {
383 Instance = &OrgInstances[Index];
386 (VOID *)&NewInstances[Index2],
395 FreePool (OrgInstances);
397 *InstancesPtr = NewInstances;
398 *NumberOfInstances = NumberOfMatches;
405 if (OrgInstances != NULL) {
406 FreePool (OrgInstances);
409 *InstancesPtr = NULL;
410 *NumberOfInstances = 0;
427 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
429 DEBUG ((DEBUG_VERBOSE,
"InternalSimplePointerInstallNotifyFunction\n"));
432 Status =
gBS->LocateHandleBuffer (
440 Status =
gBS->LocateHandleBuffer (
449 if (!EFI_ERROR (Status)) {
450 for (Index = 0; Index < NumberHandles; ++Index) {
451 Status =
gBS->HandleProtocol (
454 (VOID **)&SimplePointer
457 if (!EFI_ERROR (Status)) {
462 FreePool ((VOID *)
Buffer);
474 DEBUG ((DEBUG_VERBOSE,
"EventCreateSimplePointerInstallNotifyEvent\n"));
476 Status =
gBS->CreateEvent (
484 if (!EFI_ERROR (Status)) {
485 Status =
gBS->RegisterProtocolNotify (
491 if (EFI_ERROR (Status)) {
509 DEBUG ((DEBUG_VERBOSE,
"EventCloseSimplePointerInstallNotifyEvent\n"));
524 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
525 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
526 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
527 UINT32 HorizontalResolution;
528 UINT32 VerticalResolution;
532 DEBUG ((DEBUG_VERBOSE,
"InternalGetScreenResolution\n"));
538 HorizontalResolution = 0;
539 VerticalResolution = 0;
541 Status =
gBS->HandleProtocol (
542 gST->ConsoleOutHandle,
544 (VOID **)&GraphicsOutput
546 if (!EFI_ERROR (Status)) {
547 Info = GraphicsOutput->Mode->Info;
548 HorizontalResolution = Info->HorizontalResolution;
549 VerticalResolution = Info->VerticalResolution;
550 }
else if (Status == EFI_UNSUPPORTED) {
551 Status =
gBS->HandleProtocol (
552 gST->ConsoleOutHandle,
558 "OCAE: Failed to handle GOP, discovering UGA - %r\n",
562 if (!EFI_ERROR (Status)) {
563 Status = UgaDraw->GetMode (
565 &HorizontalResolution,
573 if (!EFI_ERROR (Status)) {
574 if ((HorizontalResolution > 0) && (VerticalResolution > 0)) {
588 "OCAE: Set screen resolution to %dx%d - %r\n",
594 DEBUG ((DEBUG_INFO,
"OCAE: Screen resolution has 0-dimension\n"));
599 "OCAE: Failed to get screen resolution - %r\n",
616 DEBUG ((DEBUG_VERBOSE,
"InternalGetUiScaleData\n"));
618 AbsoluteValue = ABS (Movement);
619 Value = HighBitSet64 ((UINT64)(AbsoluteValue));
623 Factor = (HighBitSet64 ((UINT64)(AbsoluteValue) + 1));
640 UINT32 FinalEventType;
643 DEBUG ((DEBUG_VERBOSE,
"InternalCreatePointerEventQueueInformation\n"));
669 IN EFI_STATUS PointerStatus,
675 INT32 HorizontalMovement;
676 INT32 VerticalMovement;
679 DEBUG ((DEBUG_VERBOSE,
"InternalHandleButtonInteraction\n"));
681 if (!EFI_ERROR (PointerStatus)) {
682 if (!Pointer->PreviousButton) {
683 if (Pointer->CurrentButton) {
684 Pointer->ButtonTicksHold = 0;
692 if (Information != NULL) {
696 }
else if (!Pointer->CurrentButton) {
702 if (Information != NULL) {
731 (Pointer->EventType | EventType),
735 if (Information != NULL) {
745 Pointer->PreviousClickEventType = EventType;
747 Pointer->ButtonTicksSinceClick = 0;
752 Pointer->PreviousButton = Pointer->CurrentButton;
755 if (Pointer->PreviousButton && Pointer->CurrentButton) {
756 ++Pointer->ButtonTicksHold;
759 ++Pointer->ButtonTicksSinceClick;
789 if (Information != NULL) {
797 if (Information != NULL) {
805 if (Information != NULL) {
816 BOOLEAN ClickDisabled;
817 BOOLEAN DoubleClickDisabled;
823 if (ClickDisabled && DoubleClickDisabled) {
837 if (DoubleClickDisabled) {
858 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
860 EFI_STATUS CommonStatus;
861 EFI_SIMPLE_POINTER_STATE State;
871 INT64 MaxRawPointerX;
872 INT64 MaxRawPointerY;
874 UINT32 DoubleClickTemp;
875 UINT64 SimplePointerPollTime;
879 DEBUG ((DEBUG_VERBOSE,
"InternalSimplePointerPollNotifyFunction\n"));
889 CommonStatus = EFI_UNSUPPORTED;
892 CommonStatus = EFI_NOT_READY;
903 Status = SimplePointer->GetState (SimplePointer, &State);
905 if (!EFI_ERROR (Status)) {
923 if (SimplePointer->Mode->ResolutionX > 0) {
926 (INT64)SimplePointer->Mode->ResolutionX,
931 if (SimplePointer->Mode->ResolutionY > 0) {
934 (INT64)SimplePointer->Mode->ResolutionY,
947 if (ScaledX > MaxRawPointerX) {
948 ScaledX = MaxRawPointerX;
949 }
else if (ScaledX < 0) {
960 if (ScaledY > MaxRawPointerY) {
961 ScaledY = MaxRawPointerY;
962 }
else if (ScaledY < 0) {
981 NewPosition.
Vertical = (INT32)ScaledY;
999 CommonStatus = Status;
1009 if (EFI_ERROR (CommonStatus)) {
1010 if (CommonStatus == EFI_UNSUPPORTED) {
1026 if (Information != NULL) {
1040 if (StartTime > EndTime) {
1041 EndTime = StartTime;
1050 SimplePointerPollTime =
DivU64x32 (EndTime, 50);
1074 DEBUG ((DEBUG_VERBOSE,
"EventCreateSimplePointerPollEvent\n"));
1100 Status = EFI_OUT_OF_RESOURCES;
1108 Status = EFI_SUCCESS;
1120 DEBUG ((DEBUG_VERBOSE,
"EventCancelSimplePointerPollEvent\n"));
1135 DEBUG ((DEBUG_VERBOSE,
"EventSetCursorPositionImpl\n"));
1139 Status = EFI_INVALID_PARAMETER;
1145 if ( (Position->Horizontal >= 0) && (Position->Vertical >= 0)
1159 Status = EFI_SUCCESS;
#define APPLE_EVENT_TYPE_MOUSE_MOVED
#define APPLE_EVENT_TYPE_RIGHT_BUTTON
#define APPLE_EVENT_TYPE_MOUSE_CLICK
#define APPLE_EVENT_TYPE_LEFT_BUTTON
#define APPLE_CLICK_MOUSE_EVENTS
#define APPLE_EVENT_TYPE_MOUSE_DOUBLE_CLICK
#define APPLE_ALL_MOUSE_EVENTS
#define APPLE_EVENT_TYPE_MOUSE_DOWN
#define APPLE_EVENT_TYPE_MOUSE_UP
APPLE_EVENT_INFORMATION * EventCreateAppleEventQueueInfo(IN APPLE_EVENT_DATA EventData, IN APPLE_EVENT_TYPE EventType, IN DIMENSION *PointerPosition, IN APPLE_MODIFIER_MAP Modifiers)
VOID EventAddEventToQueue(IN APPLE_EVENT_INFORMATION *Information)
APPLE_MODIFIER_MAP InternalGetModifierStrokes(VOID)
EFI_EVENT EventLibCreateNotifyTimerEvent(IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext, IN UINT64 TriggerTime, IN BOOLEAN SignalPeriodic)
VOID EventLibCancelEvent(IN EFI_EVENT Event)
UINT16 APPLE_MODIFIER_MAP
EFI_GUID gAppleVendorVariableGuid
#define APPLE_UI_SCALE_VARIABLE_NAME
#define POINTER_POLL_ALL_MASK
#define POINTER_POLL_DEFAULT
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
APPLE_EVENT_HANDLE Handle
VOID InternalSetDwellClicking(IN UINT16 ClickTimeout, IN UINT16 DoubleClickTimeout, IN UINT16 Radius)
STATIC UINT32 mSimplePointerMaxPollTime
#define MAX_DOUBLE_CLICK_SPEED
STATIC VOID EFIAPI InternalSimplePointerInstallNotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
STATIC INT64 InternalGetUiScaleData(IN INT64 Movement)
STATIC DIMENSION mResolution
#define MAX_POLL_DURATION
STATIC UINT16 mMaximumClickDuration
EFI_STATUS EventSetCursorPositionImpl(IN DIMENSION *Position)
STATIC VOID InternalHandleButtonInteraction(IN EFI_STATUS PointerStatus, IN OUT POINTER_BUTTON_INFORMATION *Pointer, IN APPLE_MODIFIER_MAP Modifiers)
STATIC VOID InternalGetScreenResolution(VOID)
STATIC VOID InternalResetDwellClicking(VOID)
VOID InternalSetPointerSpeed(IN UINT16 PointerSpeedDiv, IN UINT16 PointerSpeedMul)
STATIC UINT32 mSimplePointerMinPollTime
VOID EventCancelSimplePointerPollEvent(VOID)
STATIC BOOLEAN mMouseMoved
EFI_STATUS EventCreateSimplePointerPollEvent(VOID)
STATIC VOID InternalRemoveUninstalledInstances(IN OUT SIMPLE_POINTER_INSTANCE **InstancesPtr, IN UINTN *NumberOfInstances, IN EFI_GUID *Protocol)
STATIC DIMENSION mCursorPosition
STATIC SIMPLE_POINTER_INSTANCE * mPointerProtocols
STATIC UINT64 mMaxPointerResolutionY
STATIC POINTER_BUTTON_INFORMATION mLeftButtonInfo
GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mPointerSpeedMul
STATIC UINT32 mDwellClickTime
VOID InternalInitializePointerUiScale(VOID)
#define MIN_POINTER_POLL_PERIOD
STATIC UINT64 mPointerRawX
STATIC EFI_EVENT mSimplePointerInstallNotifyEvent
STATIC UINTN mNumberOfPointerProtocols
VOID InternalSetPointerPolling(IN UINT32 PointerPollMin, IN UINT32 PointerPollMax, IN UINT32 PointerPollMask)
STATIC UINT32 mDwellDoubleClickTimeout
STATIC UINT64 mPointerRawY
STATIC UINT32 mSimplePointerPollTime
GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mPointerSpeedDiv
STATIC VOID InternalRegisterSimplePointerInterface(IN EFI_HANDLE Handle, IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer)
VOID EventCloseSimplePointerInstallNotifyEvent(VOID)
VOID EventSimplePointerDesctructor(VOID)
STATIC VOID InternalHandleDwellClicking(IN APPLE_MODIFIER_MAP Modifiers)
STATIC DIMENSION mDwellPosition
EFI_STATUS EventCreateSimplePointerInstallNotifyEvent(VOID)
STATIC EFI_EVENT mSimplePointerPollEvent
STATIC VOID InternalQueueDwellClick(IN APPLE_EVENT_TYPE EventType, IN APPLE_MODIFIER_MAP Modifiers)
STATIC UINT32 mDwellClickRadiusSqr
STATIC VOID * mSimplePointerInstallNotifyRegistration
STATIC UINT16 mMaximumDoubleClickSpeed
STATIC APPLE_EVENT_INFORMATION * InternalCreatePointerEventQueueInformation(IN APPLE_EVENT_TYPE EventType, IN APPLE_MODIFIER_MAP Modifiers)
#define MAX_POINTER_POLL_PERIOD
STATIC VOID EFIAPI InternalSimplePointerPollNotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
STATIC POINTER_BUTTON_INFORMATION mRightButtonInfo
#define MAX_CLICK_DURATION
STATIC UINT32 mSimplePointerPollMask
STATIC UINT64 mMaxPointerResolutionX
STATIC UINT32 mDwellClickTimeout
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_RUNTIME_SERVICES * gRT
EFI_GUID gEfiUgaDrawProtocolGuid
EFI_GUID gEfiGraphicsOutputProtocolGuid
EFI_GUID gEfiSimplePointerProtocolGuid
UINT64 EFIAPI MultU64x64(IN UINT64 Multiplicand, IN UINT64 Multiplier)
INT64 EFIAPI DivS64x64Remainder(IN INT64 Dividend, IN INT64 Divisor, OUT INT64 *Remainder OPTIONAL)
UINT64 EFIAPI DivU64x64Remainder(IN UINT64 Dividend, IN UINT64 Divisor, OUT UINT64 *Remainder OPTIONAL)
INT64 EFIAPI MultS64x64(IN INT64 Multiplicand, IN INT64 Multiplier)
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
#define DivU64x32(x, y, z)
UINTN PreviousClickEventType
APPLE_EVENT_TYPE EventType
UINTN ButtonTicksSinceClick
DIMENSION MouseDownPosition
EFI_SIMPLE_POINTER_PROTOCOL * Interface
APPLE_POINTER_EVENT_TYPE PointerEventType