mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Use factory method to create mouse controller on MacOS
This commit is contained in:
49
src/device_controller/mouse/mac/mouse_controller.cpp
Normal file
49
src/device_controller/mouse/mac/mouse_controller.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "mouse_controller.h"
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
MouseController::MouseController() {}
|
||||
|
||||
MouseController::~MouseController() {}
|
||||
|
||||
int MouseController::Init(int screen_width, int screen_height) {
|
||||
screen_width_ = screen_width;
|
||||
screen_height_ = screen_height;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MouseController::Destroy() { return 0; }
|
||||
|
||||
int MouseController::SendCommand(RemoteAction remote_action) {
|
||||
int mouse_pos_x = remote_action.m.x * screen_width_ / 1280;
|
||||
int mouse_pos_y = remote_action.m.y * screen_height_ / 720;
|
||||
|
||||
if (remote_action.type == ControlType::mouse) {
|
||||
CGEventRef mouse_event;
|
||||
CGEventType mouse_type;
|
||||
|
||||
if (remote_action.m.flag == MouseFlag::left_down) {
|
||||
mouse_type = kCGEventLeftMouseDown;
|
||||
} else if (remote_action.m.flag == MouseFlag::left_up) {
|
||||
mouse_type = kCGEventLeftMouseUp;
|
||||
} else if (remote_action.m.flag == MouseFlag::right_down) {
|
||||
mouse_type = kCGEventRightMouseDown;
|
||||
} else if (remote_action.m.flag == MouseFlag::right_up) {
|
||||
mouse_type = kCGEventRightMouseUp;
|
||||
} else {
|
||||
mouse_type = kCGEventMouseMoved;
|
||||
}
|
||||
|
||||
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type,
|
||||
CGPointMake(mouse_pos_x, mouse_pos_y),
|
||||
kCGMouseButtonLeft);
|
||||
|
||||
CGEventPost(kCGHIDEventTap, mouse_event);
|
||||
CFRelease(mouse_event);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
27
src/device_controller/mouse/mac/mouse_controller.h
Normal file
27
src/device_controller/mouse/mac/mouse_controller.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @Author: DI JUNKUN
|
||||
* @Date: 2023-12-14
|
||||
* Copyright (c) 2023 by DI JUNKUN, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _MOUSE_CONTROLLER_H_
|
||||
#define _MOUSE_CONTROLLER_H_
|
||||
|
||||
#include "device_controller.h"
|
||||
|
||||
class MouseController : public DeviceController {
|
||||
public:
|
||||
MouseController();
|
||||
virtual ~MouseController();
|
||||
|
||||
public:
|
||||
virtual int Init(int screen_width, int screen_height);
|
||||
virtual int Destroy();
|
||||
virtual int SendCommand(RemoteAction remote_action);
|
||||
|
||||
private:
|
||||
int screen_width_ = 0;
|
||||
int screen_height_ = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user