2020-03-02 20:00:01 +01:00
|
|
|
/*
|
|
|
|
* a class for mouse support
|
|
|
|
*/
|
2020-03-03 15:17:39 +01:00
|
|
|
|
|
|
|
#include <Platform.h>
|
|
|
|
|
2020-03-02 20:00:01 +01:00
|
|
|
#include "XPointer.h"
|
2020-03-02 13:00:24 +01:00
|
|
|
#include "libegint.h" //this includes platform.h
|
|
|
|
#include "../refit/screen.h"
|
2020-03-13 14:11:58 +01:00
|
|
|
#include "../refit/menu.h"
|
2020-03-02 13:00:24 +01:00
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
|
|
|
#define DEBUG_MOUSE 1
|
|
|
|
#else
|
|
|
|
#define DEBUG_MOUSE DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_MOUSE == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_MOUSE, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2020-03-07 07:37:19 +01:00
|
|
|
// Initial value, but later it will be theme dependent
|
|
|
|
#define POINTER_WIDTH 64
|
|
|
|
#define POINTER_HEIGHT 64
|
2020-03-02 20:00:01 +01:00
|
|
|
|
|
|
|
XPointer::XPointer()
|
2020-03-09 10:35:14 +01:00
|
|
|
: SimplePointerProtocol(NULL), PointerImage(NULL),
|
|
|
|
// newImage(POINTER_WIDTH, POINTER_HEIGHT),
|
|
|
|
oldImage(0, 0), Alive(false)
|
2020-03-02 20:00:01 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XPointer::~XPointer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XPointer::Hide()
|
|
|
|
{
|
2020-03-05 19:23:21 +01:00
|
|
|
if (Alive) {
|
2020-03-09 09:14:05 +01:00
|
|
|
oldImage.DrawWithoutCompose(oldPlace.XPos, oldPlace.YPos);
|
2020-03-02 20:00:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 15:17:39 +01:00
|
|
|
bool XPointer::isAlive()
|
|
|
|
{
|
|
|
|
return Alive;
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:00:01 +01:00
|
|
|
EFI_STATUS XPointer::MouseBirth()
|
|
|
|
{
|
2020-03-02 13:00:24 +01:00
|
|
|
EFI_STATUS Status = EFI_UNSUPPORTED;
|
|
|
|
|
|
|
|
if (!gSettings.PointerEnabled) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SimplePointerProtocol) { //do not double
|
2020-03-07 07:43:50 +01:00
|
|
|
// DBG("Mouse is already here\n");
|
2020-03-03 15:17:39 +01:00
|
|
|
Draw();
|
2020-03-02 13:00:24 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2020-03-02 20:00:01 +01:00
|
|
|
|
2020-03-02 13:00:24 +01:00
|
|
|
// Try first to use mouse from System Table
|
|
|
|
Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gEfiSimplePointerProtocolGuid, (VOID**)&SimplePointerProtocol);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
// not found, so use the first found device
|
|
|
|
DBG("MouseBirth: No mouse at ConIn, checking if any other device exists\n");
|
|
|
|
Status = gBS->LocateProtocol(&gEfiSimplePointerProtocolGuid, NULL, (VOID**)&SimplePointerProtocol);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-03-07 07:43:50 +01:00
|
|
|
MsgLog("No mouse driver found!\n");
|
2020-03-07 07:37:19 +01:00
|
|
|
if (PointerImage) {
|
|
|
|
delete PointerImage;
|
|
|
|
PointerImage = NULL;
|
|
|
|
}
|
2020-03-02 13:00:24 +01:00
|
|
|
MouseEvent = NoEvents;
|
|
|
|
SimplePointerProtocol = NULL;
|
|
|
|
gSettings.PointerEnabled = FALSE;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-03-07 07:37:19 +01:00
|
|
|
if (PointerImage && !PointerImage->isEmpty() ) {
|
2020-03-06 20:56:32 +01:00
|
|
|
delete PointerImage;
|
2020-03-07 07:37:19 +01:00
|
|
|
PointerImage = nullptr;
|
2020-03-02 13:00:24 +01:00
|
|
|
}
|
2020-03-07 07:37:19 +01:00
|
|
|
// Now update image because of other theme has other image
|
2020-03-30 10:34:16 +02:00
|
|
|
#if USE_XTHEME
|
|
|
|
// XImage PointerImageX = ThemeX.GetIcon(BUILTIN_ICON_POINTER);
|
|
|
|
// PointerImage = &PointerImageX;
|
|
|
|
PointerImage = new XImage(ThemeX.GetIcon(BUILTIN_ICON_POINTER));
|
|
|
|
#else
|
2020-03-06 20:56:32 +01:00
|
|
|
PointerImage = new XImage(BuiltinIcon(BUILTIN_ICON_POINTER));
|
2020-03-30 10:34:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-03-09 10:35:14 +01:00
|
|
|
oldImage.setSizeInPixels(PointerImage->GetWidth(), PointerImage->GetHeight());
|
2020-03-07 07:37:19 +01:00
|
|
|
LastClickTime = 0;
|
2020-03-02 13:00:24 +01:00
|
|
|
oldPlace.XPos = (INTN)(UGAWidth >> 2);
|
|
|
|
oldPlace.YPos = (INTN)(UGAHeight >> 2);
|
2020-03-07 07:37:19 +01:00
|
|
|
oldPlace.Width = PointerImage->GetWidth();
|
|
|
|
oldPlace.Height = PointerImage->GetHeight();
|
2020-03-25 18:49:01 +01:00
|
|
|
// CopyMem(&newPlace, &oldPlace, sizeof(EG_RECT));
|
|
|
|
newPlace = oldPlace;
|
2020-03-03 15:17:39 +01:00
|
|
|
Draw();
|
2020-03-02 13:00:24 +01:00
|
|
|
MouseEvent = NoEvents;
|
2020-03-03 15:17:39 +01:00
|
|
|
Alive = true;
|
2020-03-02 20:00:01 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-03-03 15:17:39 +01:00
|
|
|
VOID XPointer::Draw()
|
2020-03-02 13:00:24 +01:00
|
|
|
{
|
2020-03-10 11:27:05 +01:00
|
|
|
oldPlace = newPlace;
|
|
|
|
// CopyMem(&oldPlace, &newPlace, sizeof(EG_RECT)); //can we use oldPlace = newPlace; ?
|
2020-03-07 07:37:19 +01:00
|
|
|
// take background image for later to restore background
|
2020-03-31 14:35:04 +02:00
|
|
|
newPlace.Width = PointerImage->GetWidth();
|
|
|
|
newPlace.Height = PointerImage->GetHeight();
|
|
|
|
oldImage.GetArea(newPlace); //GetArea will resize oldImage, so correct newPlace
|
|
|
|
newPlace.Width = oldImage.GetWidth();
|
|
|
|
newPlace.Height = oldImage.GetHeight();
|
2020-03-25 18:49:01 +01:00
|
|
|
PointerImage->Draw(newPlace.XPos, newPlace.YPos); //zero means no scale
|
2020-03-02 13:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID XPointer::KillMouse()
|
|
|
|
{
|
2020-03-07 07:37:19 +01:00
|
|
|
|
2020-03-03 15:17:39 +01:00
|
|
|
Alive = false;
|
2020-03-02 13:00:24 +01:00
|
|
|
if (!SimplePointerProtocol) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-07 07:37:19 +01:00
|
|
|
// DBG("KillMouse\n");
|
2020-03-02 13:00:24 +01:00
|
|
|
|
2020-03-06 20:56:32 +01:00
|
|
|
if (PointerImage) {
|
|
|
|
delete PointerImage;
|
|
|
|
PointerImage = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-03-02 13:00:24 +01:00
|
|
|
MouseEvent = NoEvents;
|
|
|
|
SimplePointerProtocol = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID XPointer::UpdatePointer()
|
|
|
|
{
|
|
|
|
UINT64 Now;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SIMPLE_POINTER_STATE tmpState;
|
|
|
|
EFI_SIMPLE_POINTER_MODE *CurrentMode;
|
|
|
|
INTN ScreenRelX;
|
|
|
|
INTN ScreenRelY;
|
|
|
|
|
|
|
|
// Now = gRT->GetTime(&Now, NULL);
|
|
|
|
Now = AsmReadTsc();
|
|
|
|
Status = SimplePointerProtocol->GetState(SimplePointerProtocol, &tmpState);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
if (!State.LeftButton && tmpState.LeftButton) // press left
|
|
|
|
MouseEvent = LeftMouseDown;
|
|
|
|
else if (!State.RightButton && tmpState.RightButton) // press right
|
|
|
|
MouseEvent = RightMouseDown;
|
|
|
|
else if (State.LeftButton && !tmpState.LeftButton) { //release left
|
|
|
|
// time for double click 500ms into menu
|
|
|
|
if (TimeDiff(LastClickTime, Now) < gSettings.DoubleClickTime)
|
|
|
|
MouseEvent = DoubleClick;
|
|
|
|
else
|
|
|
|
MouseEvent = LeftClick;
|
|
|
|
LastClickTime = Now;
|
|
|
|
}
|
|
|
|
else if (State.RightButton && !tmpState.RightButton) //release right
|
|
|
|
MouseEvent = RightClick;
|
|
|
|
else if (State.RelativeMovementZ > 0)
|
|
|
|
MouseEvent = ScrollDown;
|
|
|
|
else if (State.RelativeMovementZ < 0)
|
|
|
|
MouseEvent = ScrollUp;
|
|
|
|
else if (State.RelativeMovementX || State.RelativeMovementY)
|
|
|
|
MouseEvent = MouseMove;
|
|
|
|
else
|
|
|
|
MouseEvent = NoEvents;
|
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
CopyMem(&State, &tmpState, sizeof(State));
|
2020-03-02 13:00:24 +01:00
|
|
|
CurrentMode = SimplePointerProtocol->Mode;
|
|
|
|
|
2020-03-29 20:02:54 +02:00
|
|
|
ScreenRelX = (UGAWidth * State.RelativeMovementX * gSettings.PointerSpeed / (INTN)CurrentMode->ResolutionX) >> 10;
|
2020-03-02 13:00:24 +01:00
|
|
|
if (gSettings.PointerMirror) {
|
|
|
|
newPlace.XPos -= ScreenRelX;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newPlace.XPos += ScreenRelX;
|
|
|
|
}
|
|
|
|
if (newPlace.XPos < 0) newPlace.XPos = 0;
|
|
|
|
if (newPlace.XPos > UGAWidth - 1) newPlace.XPos = UGAWidth - 1;
|
|
|
|
|
|
|
|
// YPosPrev = newPlace.YPos;
|
2020-03-29 20:02:54 +02:00
|
|
|
ScreenRelY = (UGAHeight * State.RelativeMovementY * gSettings.PointerSpeed / (INTN)CurrentMode->ResolutionY) >> 10;
|
2020-03-02 13:00:24 +01:00
|
|
|
newPlace.YPos += ScreenRelY;
|
|
|
|
if (newPlace.YPos < 0) newPlace.YPos = 0;
|
|
|
|
if (newPlace.YPos > UGAHeight - 1) newPlace.YPos = UGAHeight - 1;
|
|
|
|
|
2020-03-10 11:27:05 +01:00
|
|
|
if ( oldPlace != newPlace ) {
|
2020-03-09 02:12:24 +01:00
|
|
|
Hide();
|
|
|
|
Draw();
|
|
|
|
}
|
2020-03-02 13:00:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XPointer::MouseInRect(EG_RECT *Place)
|
|
|
|
{
|
|
|
|
return ((newPlace.XPos >= Place->XPos) &&
|
|
|
|
(newPlace.XPos < (Place->XPos + (INTN)Place->Width)) &&
|
|
|
|
(newPlace.YPos >= Place->YPos) &&
|
|
|
|
(newPlace.YPos < (Place->YPos + (INTN)Place->Height)));
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS XPointer::CheckMouseEvent(REFIT_MENU_SCREEN *Screen)
|
|
|
|
{
|
|
|
|
if (!Screen) {
|
|
|
|
return EFI_TIMEOUT;
|
|
|
|
}
|
2020-03-20 18:48:19 +01:00
|
|
|
EFI_STATUS Status = EFI_TIMEOUT;
|
|
|
|
Screen->mAction = ActionNone;
|
2020-03-25 19:22:34 +01:00
|
|
|
bool Move = false;
|
2020-03-02 13:00:24 +01:00
|
|
|
|
|
|
|
if (!IsDragging && MouseEvent == MouseMove)
|
|
|
|
MouseEvent = NoEvents;
|
|
|
|
|
2020-03-20 18:48:19 +01:00
|
|
|
if (Screen->ScrollEnabled){
|
|
|
|
if (MouseInRect(&UpButton) && MouseEvent == LeftClick)
|
|
|
|
Screen->mAction = ActionScrollUp;
|
|
|
|
else if (MouseInRect(&DownButton) && MouseEvent == LeftClick)
|
|
|
|
Screen->mAction = ActionScrollDown;
|
|
|
|
else if (MouseInRect(&Scrollbar) && MouseEvent == LeftMouseDown) {
|
|
|
|
IsDragging = TRUE;
|
2020-03-25 19:22:34 +01:00
|
|
|
Move = true;
|
2020-03-25 18:49:01 +01:00
|
|
|
// Screen->mAction = ActionMoveScrollbar;
|
2020-03-20 18:48:19 +01:00
|
|
|
ScrollbarYMovement = 0;
|
|
|
|
ScrollbarOldPointerPlace.XPos = ScrollbarNewPointerPlace.XPos = newPlace.XPos;
|
|
|
|
ScrollbarOldPointerPlace.YPos = ScrollbarNewPointerPlace.YPos = newPlace.YPos;
|
|
|
|
}
|
|
|
|
else if (IsDragging && MouseEvent == LeftClick) {
|
|
|
|
IsDragging = FALSE;
|
2020-03-25 19:22:34 +01:00
|
|
|
Move = true;
|
2020-03-25 18:49:01 +01:00
|
|
|
// Screen->mAction = ActionMoveScrollbar;
|
2020-03-20 18:48:19 +01:00
|
|
|
}
|
|
|
|
else if (IsDragging && MouseEvent == MouseMove) {
|
|
|
|
Screen->mAction = ActionMoveScrollbar;
|
|
|
|
ScrollbarNewPointerPlace.XPos = newPlace.XPos;
|
|
|
|
ScrollbarNewPointerPlace.YPos = newPlace.YPos;
|
|
|
|
}
|
|
|
|
else if (MouseInRect(&ScrollbarBackground) &&
|
|
|
|
MouseEvent == LeftClick) {
|
|
|
|
if (newPlace.YPos < Scrollbar.YPos) // up
|
|
|
|
Screen->mAction = ActionPageUp;
|
|
|
|
else // down
|
|
|
|
Screen->mAction = ActionPageDown;
|
2020-03-02 13:00:24 +01:00
|
|
|
// page up/down, like in OS X
|
2020-03-20 18:48:19 +01:00
|
|
|
}
|
|
|
|
else if (MouseEvent == ScrollDown) {
|
|
|
|
Screen->mAction = ActionScrollDown;
|
|
|
|
}
|
|
|
|
else if (MouseEvent == ScrollUp) {
|
|
|
|
Screen->mAction = ActionScrollUp;
|
|
|
|
}
|
2020-03-25 19:22:34 +01:00
|
|
|
}
|
|
|
|
if (!Screen->ScrollEnabled || (Screen->mAction == ActionNone && !Move) ) {
|
2020-03-25 18:49:01 +01:00
|
|
|
for (UINTN EntryId = 0; EntryId < Screen->Entries.size(); EntryId++) {
|
|
|
|
if (MouseInRect(&(Screen->Entries[EntryId].Place))) {
|
|
|
|
switch (MouseEvent) {
|
|
|
|
case LeftClick:
|
|
|
|
Screen->mAction = Screen->Entries[EntryId].AtClick;
|
|
|
|
// DBG("Click\n");
|
|
|
|
break;
|
|
|
|
case RightClick:
|
|
|
|
Screen->mAction = Screen->Entries[EntryId].AtRightClick;
|
|
|
|
break;
|
|
|
|
case DoubleClick:
|
|
|
|
Screen->mAction = Screen->Entries[EntryId].AtDoubleClick;
|
|
|
|
break;
|
|
|
|
case ScrollDown:
|
|
|
|
Screen->mAction = ActionScrollDown;
|
|
|
|
break;
|
|
|
|
case ScrollUp:
|
|
|
|
Screen->mAction = ActionScrollUp;
|
|
|
|
break;
|
|
|
|
case MouseMove:
|
|
|
|
Screen->mAction = Screen->Entries[EntryId].AtMouseOver;
|
|
|
|
//how to do the action once?
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Screen->mAction = ActionNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Screen->mItemID = EntryId;
|
2020-03-02 13:00:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-03-25 18:49:01 +01:00
|
|
|
else { //click in milk
|
|
|
|
switch (MouseEvent) {
|
|
|
|
case LeftClick:
|
|
|
|
Screen->mAction = ActionDeselect;
|
|
|
|
break;
|
|
|
|
case RightClick:
|
|
|
|
Screen->mAction = ActionFinish;
|
|
|
|
break;
|
|
|
|
case ScrollDown:
|
|
|
|
Screen->mAction = ActionScrollDown;
|
|
|
|
break;
|
|
|
|
case ScrollUp:
|
|
|
|
Screen->mAction = ActionScrollUp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Screen->mAction = ActionNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Screen->mItemID = 0xFFFF;
|
2020-03-02 13:00:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-25 19:22:34 +01:00
|
|
|
|
2020-03-02 13:00:24 +01:00
|
|
|
}
|
2020-03-20 18:48:19 +01:00
|
|
|
|
2020-03-02 13:00:24 +01:00
|
|
|
if (Screen->mAction != ActionNone) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
MouseEvent = NoEvents; //clear event as set action
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|