PADnull reformat

This commit is contained in:
Clang Format 2016-08-24 23:18:58 +02:00 committed by Gregory Hainaut
parent 6613862aed
commit eb18a2ac0f
9 changed files with 253 additions and 235 deletions

View File

@ -23,43 +23,43 @@
extern std::string s_strIniPath;
PluginConf Ini;
EXPORT_C_(void) PADabout()
EXPORT_C_(void)
PADabout()
{
SysMessage("PADnull: A simple null plugin.");
SysMessage("PADnull: A simple null plugin.");
}
EXPORT_C_(void) PADconfigure()
EXPORT_C_(void)
PADconfigure()
{
LoadConfig();
PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log);
SaveConfig();
LoadConfig();
PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log);
SaveConfig();
}
void LoadConfig()
{
const std::string iniFile(s_strIniPath + "/Padnull.ini");
if (!Ini.Open(iniFile, READ_FILE))
{
printf("failed to open %s\n", iniFile.c_str());
SaveConfig();//save and return
return;
}
if (!Ini.Open(iniFile, READ_FILE)) {
printf("failed to open %s\n", iniFile.c_str());
SaveConfig(); //save and return
return;
}
conf.Log = Ini.ReadInt("logging", 0);
Ini.Close();
conf.Log = Ini.ReadInt("logging", 0);
Ini.Close();
}
void SaveConfig()
{
const std::string iniFile(s_strIniPath + "/Padnull.ini");
if (!Ini.Open(iniFile, WRITE_FILE))
{
printf("failed to open %s\n", iniFile.c_str());
return;
}
if (!Ini.Open(iniFile, WRITE_FILE)) {
printf("failed to open %s\n", iniFile.c_str());
return;
}
Ini.WriteInt("logging", conf.Log);
Ini.Close();
Ini.WriteInt("logging", conf.Log);
Ini.Close();
}

View File

@ -18,75 +18,70 @@
#include <gdk/gdkx.h>
#include "PadLinux.h"
Display *GSdsp;
Display* GSdsp;
int autoRepeatMode;
void _PadUpdate(int pad)
{
XEvent evt;
KeySym key;
XEvent evt;
KeySym key;
// keyboard input
while (XPending(GSdsp) > 0)
{
XNextEvent(GSdsp, &evt);
switch (evt.type)
{
case KeyPress:
key = XLookupKeysym((XKeyEvent *) &evt, 0);
// keyboard input
while (XPending(GSdsp) > 0) {
XNextEvent(GSdsp, &evt);
switch (evt.type) {
case KeyPress:
key = XLookupKeysym((XKeyEvent*)&evt, 0);
// Add code to check if it's one of the keys we configured here on a real pda plugin..
// Add code to check if it's one of the keys we configured here on a real pda plugin..
event.evt = KEYPRESS;
event.key = key;
break;
event.evt = KEYPRESS;
event.key = key;
break;
case KeyRelease:
key = XLookupKeysym((XKeyEvent *) &evt, 0);
case KeyRelease:
key = XLookupKeysym((XKeyEvent*)&evt, 0);
// Add code to check if it's one of the keys we configured here on a real pda plugin..
// Add code to check if it's one of the keys we configured here on a real pda plugin..
event.evt = KEYRELEASE;
event.key = key;
break;
event.evt = KEYRELEASE;
event.key = key;
break;
case FocusIn:
XAutoRepeatOff(GSdsp);
break;
case FocusIn:
XAutoRepeatOff(GSdsp);
break;
case FocusOut:
XAutoRepeatOn(GSdsp);
break;
}
}
case FocusOut:
XAutoRepeatOn(GSdsp);
break;
}
}
}
s32 _PADOpen(void *pDsp)
s32 _PADOpen(void* pDsp)
{
GtkScrolledWindow *win;
win = *(GtkScrolledWindow**) pDsp;
GtkScrolledWindow* win;
if (GTK_IS_WIDGET(win))
{
// Since we have a GtkScrolledWindow, for now we'll grab whatever display
// comes along instead. Later, we can fiddle with this, but I'm not sure the
// best way to get a Display* out of a GtkScrolledWindow. A GtkWindow I might
// be able to manage... --arcum42
win = *(GtkScrolledWindow**)pDsp;
if (GTK_IS_WIDGET(win)) {
// Since we have a GtkScrolledWindow, for now we'll grab whatever display
// comes along instead. Later, we can fiddle with this, but I'm not sure the
// best way to get a Display* out of a GtkScrolledWindow. A GtkWindow I might
// be able to manage... --arcum42
GSdsp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
}
else
{
} else {
GSdsp = *(Display**)pDsp;
}
XAutoRepeatOff(GSdsp);
}
return 0;
XAutoRepeatOff(GSdsp);
return 0;
}
void _PADClose()
void _PADClose()
{
XAutoRepeatOn(GSdsp);
XAutoRepeatOn(GSdsp);
}

View File

@ -23,7 +23,7 @@
#include <X11/Xlib.h>
void _PadUpdate(int pad);
s32 _PADOpen(void *pDsp);
s32 _PADOpen(void* pDsp);
void _PADClose();
#endif

View File

@ -21,149 +21,164 @@ using namespace std;
#include "svnrev.h"
#include "Pad.h"
const u8 version = PS2E_PAD_VERSION;
const u8 version = PS2E_PAD_VERSION;
const u8 revision = 0;
const u8 build = 1; // increase that with each version
const u8 build = 1; // increase that with each version
#ifdef _MSC_VER
#define snprintf sprintf_s
#endif
static char libraryName[256];
string s_strIniPath="inis";
string s_strLogPath="logs";
string s_strIniPath = "inis";
string s_strLogPath = "logs";
FILE *padLog;
FILE* padLog;
Config conf;
keyEvent event;
static keyEvent s_event;
EXPORT_C_(u32) PS2EgetLibType()
EXPORT_C_(u32)
PS2EgetLibType()
{
return PS2E_LT_PAD;
return PS2E_LT_PAD;
}
EXPORT_C_(char*) PS2EgetLibName()
EXPORT_C_(char*)
PS2EgetLibName()
{
snprintf( libraryName, 255, "Padnull Driver %lld%s",SVN_REV, SVN_MODS ? "m" : "");
return libraryName;
snprintf(libraryName, 255, "Padnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
return libraryName;
}
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{
return (version<<16) | (revision<<8) | build;
return (version << 16) | (revision << 8) | build;
}
void __Log(const char *fmt, ...)
void __Log(const char* fmt, ...)
{
va_list list;
va_list list;
if (padLog == NULL) return;
va_start(list, fmt);
vfprintf(padLog, fmt, list);
va_end(list);
if (padLog == NULL)
return;
va_start(list, fmt);
vfprintf(padLog, fmt, list);
va_end(list);
}
void __LogToConsole(const char *fmt, ...)
void __LogToConsole(const char* fmt, ...)
{
va_list list;
va_list list;
va_start(list, fmt);
va_start(list, fmt);
if (padLog != NULL) vfprintf(padLog, fmt, list);
if (padLog != NULL)
vfprintf(padLog, fmt, list);
printf("PadNull: ");
vprintf(fmt, list);
va_end(list);
printf("PadNull: ");
vprintf(fmt, list);
va_end(list);
}
EXPORT_C_(void) PADsetSettingsDir(const char* dir)
EXPORT_C_(void)
PADsetSettingsDir(const char* dir)
{
s_strIniPath = (dir == NULL) ? "inis" : dir;
s_strIniPath = (dir == NULL) ? "inis" : dir;
}
bool OpenLog() {
bool OpenLog()
{
bool result = true;
#ifdef PAD_LOG
if(padLog) return result;
if (padLog)
return result;
const std::string LogFile(s_strLogPath + "/padnull.log");
padLog = fopen(LogFile.c_str(), "w");
if (padLog != NULL)
setvbuf(padLog, NULL, _IONBF, 0);
setvbuf(padLog, NULL, _IONBF, 0);
else {
fprintf(stderr, "Can't create log file %s\n", LogFile.c_str());
result = false;
}
PAD_LOG("PADinit\n");
PAD_LOG("PADinit\n");
#endif
return result;
}
EXPORT_C_(void) PADsetLogDir(const char* dir)
EXPORT_C_(void)
PADsetLogDir(const char* dir)
{
// Get the path to the log directory.
s_strLogPath = (dir==NULL) ? "logs" : dir;
// Get the path to the log directory.
s_strLogPath = (dir == NULL) ? "logs" : dir;
// Reload the log file after updated the path
if (padLog) {
// Reload the log file after updated the path
if (padLog) {
fclose(padLog);
padLog = NULL;
}
OpenLog();
}
EXPORT_C_(s32) PADinit(u32 flags)
EXPORT_C_(s32)
PADinit(u32 flags)
{
LoadConfig();
LoadConfig();
OpenLog();
return 0;
return 0;
}
EXPORT_C_(void) PADshutdown()
EXPORT_C_(void)
PADshutdown()
{
#ifdef PAD_LOG
if (padLog)
{
fclose(padLog);
padLog = NULL;
}
if (padLog) {
fclose(padLog);
padLog = NULL;
}
#endif
}
EXPORT_C_(s32) PADopen(void *pDsp)
EXPORT_C_(s32)
PADopen(void* pDsp)
{
memset(&event, 0, sizeof(event));
memset(&event, 0, sizeof(event));
return _PADOpen(pDsp);
return _PADOpen(pDsp);
}
EXPORT_C_(void) PADclose()
EXPORT_C_(void)
PADclose()
{
_PADClose();
_PADClose();
}
// PADkeyEvent is called every vsync (return NULL if no event)
EXPORT_C_(keyEvent*) PADkeyEvent()
EXPORT_C_(keyEvent*)
PADkeyEvent()
{
s_event = event;
event.evt = 0;
event.key = 0;
s_event = event;
event.evt = 0;
event.key = 0;
return &s_event;
return &s_event;
}
EXPORT_C_(u8) PADstartPoll(int pad)
EXPORT_C_(u8)
PADstartPoll(int pad)
{
return 0;
return 0;
}
EXPORT_C_(u8) PADpoll(u8 value)
EXPORT_C_(u8)
PADpoll(u8 value)
{
return 0;
return 0;
}
// call to give a hint to the PAD plugin to query for the keyboard state. A
@ -173,29 +188,34 @@ EXPORT_C_(u8) PADpoll(u8 value)
// the window (and input). Note that PADupdate can be called from a different
// thread than the other functions, so mutex or other multithreading primitives
// have to be added to maintain data integrity.
EXPORT_C_(u32) PADquery()
EXPORT_C_(u32)
PADquery()
// returns: 1 if supported pad1
// 2 if supported pad2
// 3 if both are supported
{
return 3;
return 3;
}
EXPORT_C_(void) PADupdate(int pad)
EXPORT_C_(void)
PADupdate(int pad)
{
_PadUpdate(pad);
_PadUpdate(pad);
}
EXPORT_C_(void) PADgsDriverInfo(GSdriverInfo *info)
EXPORT_C_(void)
PADgsDriverInfo(GSdriverInfo* info)
{
}
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
EXPORT_C_(s32)
PADfreeze(int mode, freezeData* data)
{
return 0;
return 0;
}
EXPORT_C_(s32) PADtest()
EXPORT_C_(s32)
PADtest()
{
return 0;
return 0;
}

View File

@ -31,21 +31,21 @@
#ifdef _MSC_VER
#define EXPORT_C_(type) extern "C" type CALLBACK
#else
#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
#endif
#define PAD_LOG __Log
typedef struct
{
s32 Log;
s32 Log;
} Config;
extern Config conf;
extern FILE *padLog;
extern FILE* padLog;
extern keyEvent event;
extern void __Log(char *fmt, ...);
extern void __Log(char* fmt, ...);
extern void SaveConfig();
extern void LoadConfig();

View File

@ -19,29 +19,27 @@ extern std::string s_strIniPath;
void SaveConfig()
{
const std::string iniFile = s_strIniPath + "/Padnull.ini";
const std::string iniFile = s_strIniPath + "/Padnull.ini";
PluginConf ini;
if (!ini.Open(iniFile, READ_FILE))
{
printf("failed to open %s\n", iniFile.c_str());
SaveConfig();//save and return
return;
}
conf.Log = ini.ReadInt("logging", 0);
ini.Close();
PluginConf ini;
if (!ini.Open(iniFile, READ_FILE)) {
printf("failed to open %s\n", iniFile.c_str());
SaveConfig(); //save and return
return;
}
conf.Log = ini.ReadInt("logging", 0);
ini.Close();
}
void LoadConfig()
{
const std::string iniFile(s_strIniPath + "/Padnull.ini");
const std::string iniFile(s_strIniPath + "/Padnull.ini");
PluginConf ini;
if (!ini.Open(iniFile, WRITE_FILE))
{
printf("failed to open %s\n", iniFile.c_str());
return;
}
ini.WriteInt("logging", conf.Log);
ini.Close();
PluginConf ini;
if (!ini.Open(iniFile, WRITE_FILE)) {
printf("failed to open %s\n", iniFile.c_str());
return;
}
ini.WriteInt("logging", conf.Log);
ini.Close();
}

View File

@ -21,56 +21,54 @@ HWND GShwnd = NULL;
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_KEYDOWN:
if (lParam & 0x40000000)return TRUE;
switch (msg) {
case WM_KEYDOWN:
if (lParam & 0x40000000)
return TRUE;
event.evt = KEYPRESS;
event.key = wParam;
break;
event.evt = KEYPRESS;
event.key = wParam;
break;
case WM_KEYUP:
event.evt = KEYRELEASE;
event.key = wParam;
break;
case WM_KEYUP:
event.evt = KEYRELEASE;
event.key = wParam;
break;
case WM_DESTROY:
case WM_QUIT:
event.evt = KEYPRESS;
event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam);
case WM_DESTROY:
case WM_QUIT:
event.evt = KEYPRESS;
event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam);
default:
return GSwndProc(hWnd, msg, wParam, lParam);
};
default:
return GSwndProc(hWnd, msg, wParam, lParam);
};
return TRUE;
return TRUE;
}
void _PadUpdate(int pad)
{
}
s32 _PADOpen(void *pDsp)
s32 _PADOpen(void* pDsp)
{
GShwnd = (HWND)*(long*)pDsp;
GShwnd = (HWND) * (long*)pDsp;
if (GShwnd != NULL && GSwndProc != NULL)
{
// revert
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
}
if (GShwnd != NULL && GSwndProc != NULL) {
// revert
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
}
GSwndProc = (WNDPROC)GetWindowLongPtr(GShwnd, GWLP_WNDPROC);
GSwndProc = ((WNDPROC)SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(PADwndProc)));
return 0;
return 0;
}
void _PADClose()
void _PADClose()
{
if (GShwnd != NULL && GSwndProc != NULL)
{
if (GShwnd != NULL && GSwndProc != NULL) {
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
GSwndProc = NULL;
GShwnd = NULL;

View File

@ -20,7 +20,7 @@
#include <windows.h>
void _PadUpdate(int pad);
s32 _PADOpen(void *pDsp);
s32 _PADOpen(void* pDsp);
void _PADClose();
#endif

View File

@ -20,65 +20,72 @@
HINSTANCE hInst;
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
LoadConfig();
if (conf.Log) CheckDlgButton(hW, IDC_LOGGING, TRUE);
return TRUE;
switch (uMsg) {
case WM_INITDIALOG:
LoadConfig();
if (conf.Log)
CheckDlgButton(hW, IDC_LOGGING, TRUE);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDCANCEL:
EndDialog(hW, TRUE);
return TRUE;
case IDOK:
if (IsDlgButtonChecked(hW, IDC_LOGGING))
conf.Log = 1;
else
conf.Log = 0;
SaveConfig();
EndDialog(hW, FALSE);
return TRUE;
}
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
EndDialog(hW, TRUE);
return TRUE;
case IDOK:
if (IsDlgButtonChecked(hW, IDC_LOGGING))
conf.Log = 1;
else
conf.Log = 0;
SaveConfig();
EndDialog(hW, FALSE);
return TRUE;
}
}
return FALSE;
}
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_INITDIALOG:
return TRUE;
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hW, FALSE);
return TRUE;
}
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hW, FALSE);
return TRUE;
}
}
return FALSE;
}
EXPORT_C_(void) PADconfigure() {
EXPORT_C_(void)
PADconfigure()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
}
EXPORT_C_(void) PADabout() {
EXPORT_C_(void)
PADabout()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(),
(DLGPROC)AboutDlgProc);
}
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason,
LPVOID lpReserved) {
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason,
LPVOID lpReserved)
{
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
}