add plugin system

This commit is contained in:
gamegrd 2021-07-26 19:51:56 +08:00
parent ab12b6c981
commit 3760c8c222
4 changed files with 58 additions and 2 deletions

View file

@ -2,6 +2,7 @@ src = [
'src/main.c',
'src/adb.c',
'src/cli.c',
'src/plugin.c',
'src/compat.c',
'src/control_msg.c',
'src/controller.c',

49
app/src/plugin.c Normal file
View file

@ -0,0 +1,49 @@
#include "plugin.h"
#include "scrcpy.h"
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
#ifdef _WIN32
// not needed here, but winsock2.h must never be included AFTER windows.h
# include <winsock2.h>
# include <windows.h>
#endif
#ifdef _WIN32
#define WM_PLUGIN_BASE WM_USER
void on_window_message(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, int64_t lParam){
(void)(userdata);
(void)(hWnd);
if (message >= WM_PLUGIN_BASE ){
message -= WM_PLUGIN_BASE;
switch (message)
{
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
{
SDL_Event sdlevent;
sdlevent.type = message;
sdlevent.tfinger.fingerId = 0;
sdlevent.tfinger.pressure = 0.8;
sdlevent.tfinger.x = (double)(wParam) / (1000*1000);
sdlevent.tfinger.y = (double)(lParam) / (1000*1000);
SDL_PushEvent(&sdlevent);
}
break;
default:
break;
}
}
}
#endif
void plugin_init(){
#ifdef _WIN32
SDL_SetWindowsMessageHook(on_window_message,NULL);
#endif
}

5
app/src/plugin.h Normal file
View file

@ -0,0 +1,5 @@
#ifndef __PLUGIN_H__
#define __PLUGIN_H__
void plugin_init();
#endif

View file

@ -1,5 +1,5 @@
#include "scrcpy.h"
#include "plugin.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@ -115,6 +115,7 @@ sdl_init_and_configure(bool display, const char *render_driver,
SDL_EnableScreenSaver();
}
plugin_init();
return true;
}
@ -290,7 +291,7 @@ scrcpy(const struct scrcpy_options *options) {
options->disable_screensaver)) {
goto end;
}
char device_name[DEVICE_NAME_FIELD_LENGTH];
struct size frame_size;