Permalink
Browse files

Fix numpad/scroll lock/insert mapping to wrong keys. Also get the cli…

…ent running on solaris.
  • Loading branch information...
UnknownShadow200 committed Nov 9, 2018
1 parent 34172f3 commit ba5a6dff1f2da80faf9f49aa75c06decb8a01f76
Showing with 104 additions and 70 deletions.
  1. +2 −2 OpenTK/Platform/X11/X11KeyMap.cs
  2. +9 −1 src/Core.h
  3. +21 −28 src/ErrorHandler.c
  4. +3 −3 src/NixWindow.c
  5. +69 −36 src/Platform.c
@@ -182,8 +182,8 @@ internal class X11KeyMap : Dictionary<int, Key> {
Add(XKey.Pause, Key.Pause);
Add(XKey.Break, Key.Pause);
Add(XKey.Scroll_Lock, Key.Pause);
Add(XKey.Insert, Key.PrintScreen);
Add(XKey.Scroll_Lock, Key.ScrollLock);
Add(XKey.Insert, Key.Insert);
Add(XKey.Print, Key.PrintScreen);
Add(XKey.Sys_Req, Key.PrintScreen);
View
@@ -26,7 +26,7 @@ typedef signed __int64 int64_t;
#include <stdint.h>
#define NOINLINE_ __attribute__((noinline))
#define ALIGN_HINT_(x) __attribute__((aligned(x)))
#define EXPORT_ __attribute__((noinline))
#define EXPORT_ __attribute__((visibility("default"), noinline))
#else
#error "I don't recognise this compiler. You'll need to add required definitions in Core.h!"
#endif
@@ -73,9 +73,17 @@ typedef struct Bitmap_ { uint8_t* Scan0; int Width, Height; } Bitmap;
#endif
#ifdef __linux__
#define CC_BUILD_NIX
#define CC_BUILD_POSIX
#define CC_BUILD_X11
#endif
#ifdef __APPLE__
#define CC_BUILD_OSX
#define CC_BUILD_POSIX
#endif
#ifdef __sun__
#define CC_BUILD_SOLARIS
#define CC_BUILD_POSIX
#define CC_BUILD_X11
#endif
#endif
View
@@ -9,14 +9,6 @@ static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void
static void ErrorHandler_DumpCommon(String* str, void* ctx);
static void ErrorHandler_DumpRegisters(void* ctx);
/* POSIX is mainly shared between Linux and OSX */
#ifdef CC_BUILD_NIX
#define CC_BUILD_POSIX
#endif
#ifdef CC_BUILD_OSX
#define CC_BUILD_POSIX
#endif
#ifdef CC_BUILD_WIN
#define WIN32_LEAN_AND_MEAN
#define NOSERVICE
@@ -39,17 +31,17 @@ static int ErrorHandler_GetFrames(CONTEXT* ctx, struct StackPointers* pointers,
frame.AddrStack.Mode = AddrModeFlat;
DWORD type;
#ifdef _M_IX86
#if defined _M_IX86
type = IMAGE_FILE_MACHINE_I386;
frame.AddrPC.Offset = ctx->Eip;
frame.AddrFrame.Offset = ctx->Ebp;
frame.AddrStack.Offset = ctx->Esp;
#elif _M_X64
#elif defined _M_X64
type = IMAGE_FILE_MACHINE_AMD64;
frame.AddrPC.Offset = ctx->Rip;
frame.AddrFrame.Offset = ctx->Rsp;
frame.AddrStack.Offset = ctx->Rsp;
#elif _M_IA64
#elif defined _M_IA64
type = IMAGE_FILE_MACHINE_IA64;
frame.AddrPC.Offset = ctx->StIIP;
frame.AddrFrame.Offset = ctx->IntSp;
@@ -153,18 +145,18 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
String_InitArray(str, strBuffer);
String_AppendConst(&str, "-- registers --\r\n");
#ifdef _M_IX86
#if defined _M_IX86
String_Format3(&str, "eax=%x ebx=%x ecx=%x\r\n", &r->Eax, &r->Ebx, &r->Ecx);
String_Format3(&str, "edx=%x esi=%x edi=%x\r\n", &r->Edx, &r->Esi, &r->Edi);
String_Format3(&str, "eip=%x ebp=%x esp=%x\r\n", &r->Eip, &r->Ebp, &r->Esp);
#elif _M_X64
#elif defined _M_X64
String_Format3(&str, "rax=%x rbx=%x rcx=%x\r\n", &r->Rax, &r->Rbx, &r->Rcx);
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\r\n", &r->Rdx, &r->Rsi, &r->Rdi);
String_Format3(&str, "rip=%x rbp=%x rsp=%x\r\n", &r->Rip, &r->Rbp, &r->Rsp);
String_Format3(&str, "r8 =%x r9 =%x r10=%x\r\n", &r->R8, &r->R9, &r->R10);
String_Format3(&str, "r11=%x r12=%x r13=%x\r\n", &r->R11, &r->R12, &r->R13);
String_Format2(&str, "r14=%x r15=%x\r\n" , &r->R14, &r->R15);
#elif _M_IA64
#elif defined _M_IA64
String_Format3(&str, "r1 =%x r2 =%x r3 =%x\r\n", &r->IntGp, &r->IntT0, &r->IntT1);
String_Format3(&str, "r4 =%x r5 =%x r6 =%x\r\n", &r->IntS0, &r->IntS1, &r->IntS2);
String_Format3(&str, "r7 =%x r8 =%x r9 =%x\r\n", &r->IntS3, &r->IntV0, &r->IntT2);
@@ -258,6 +250,7 @@ void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
#pragma optimize ("", on)
#endif
#endif
/* POSIX is mainly shared between Linux and OSX */
#ifdef CC_BUILD_POSIX
#include <ucontext.h>
#include <execinfo.h>
@@ -339,13 +332,12 @@ void ErrorHandler_Fail2(ReturnCode result, const char* raw_msg) {
ErrorHandler_FailCommon(result, raw_msg, &ctx);
}
#endif
#ifdef CC_BUILD_NIX
#ifdef CC_BUILD_X11
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
/*########################################################################################################################*
*-----------------------------------------------------X11 message box-----------------------------------------------------*
*#########################################################################################################################*/
@@ -573,10 +565,20 @@ static void X11_MessageBox(const char* title, const char* text, X11Window* w) {
}
}
void ErrorHandler_ShowDialog(const char* title, const char* msg) {
X11Window w = { 0 };
dpy = DisplayDevice_Meta;
X11_MessageBox(title, msg, &w);
X11Window_Free(&w);
}
#endif
/*########################################################################################################################*
*-------------------------------------------------------Info dumping------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_NIX || defined CC_BUILD_SOLARIS
static void ErrorHandler_DumpRegisters(void* ctx) {
mcontext_t r;
String str; char strBuffer[STRING_SIZE * 8];
@@ -628,16 +630,7 @@ static void ErrorHandler_DumpCommon(String* str, void* ctx) {
ErrorHandler_Log(&memMap);
ErrorHandler_DumpMemoryMap();
}
void ErrorHandler_ShowDialog(const char* title, const char* msg) {
X11Window w = { 0 };
dpy = DisplayDevice_Meta;
X11_MessageBox(title, msg, &w);
X11Window_Free(&w);
}
#endif
#ifdef CC_BUILD_OSX
#elif defined CC_BUILD_OSX
static void ErrorHandler_DumpRegisters(void* ctx) {
mcontext_t r;
String str; char strBuffer[STRING_SIZE * 8];
@@ -648,11 +641,11 @@ static void ErrorHandler_DumpRegisters(void* ctx) {
String_AppendConst(&str, "-- registers --\n");
/* You can find these definitions at /usr/include/mach/i386/_structs.h */
#ifdef __i386__
#if defined __i386__
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r->__ss.__eax, &r->__ss.__ebx, &r->__ss.__ecx);
String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r->__ss.__edx, &r->__ss.__esi, &r->__ss.__edi);
String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r->__ss.__eip, &r->__ss.__ebp, &r->__ss.__esp);
#elif __x86_64__
#elif defined __x86_64__
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r->__ss.__rax, &r->__ss.__rbx, &r->__ss.__rcx);
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r->__ss.__rdx, &r->__ss.__rsi, &r->__ss.__rdi);
String_Format3(&str, "rip=%x rbp=%x rsp=%x\n", &r->__ss.__rip, &r->__ss.__rbp, &r->__ss.__rsp);
View
@@ -1,5 +1,5 @@
#include "Window.h"
#ifdef CC_BUILD_NIX
#ifdef CC_BUILD_X11
#include "ErrorHandler.h"
#include "Input.h"
#include "Funcs.h"
@@ -75,8 +75,8 @@ static Key Window_MapKey(KeySym key) {
case XK_Pause: return Key_Pause;
case XK_Break: return Key_Pause;
case XK_Scroll_Lock: return Key_Pause;
case XK_Insert: return Key_PrintScreen;
case XK_Scroll_Lock: return Key_ScrollLock;
case XK_Insert: return Key_Insert;
case XK_Print: return Key_PrintScreen;
case XK_Sys_Req: return Key_PrintScreen;
View
@@ -12,14 +12,8 @@
#include "freetype/freetype.h"
#include "freetype/ftmodapi.h"
/* POSIX is mainly shared between Linux and OSX */
#ifdef CC_BUILD_NIX
#define CC_BUILD_POSIX
#endif
#ifdef CC_BUILD_OSX
#define CC_BUILD_POSIX
#endif
static void Platform_InitDisplay(void);
static void Platform_InitStopwatch(void);
#ifdef CC_BUILD_WIN
#define WIN32_LEAN_AND_MEAN
@@ -52,6 +46,7 @@ ReturnCode ReturnCode_InvalidArg = ERROR_INVALID_PARAMETER;
ReturnCode ReturnCode_SocketInProgess = WSAEINPROGRESS;
ReturnCode ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK;
#endif
/* POSIX is mainly shared between Linux and OSX */
#ifdef CC_BUILD_POSIX
#include <curl/curl.h>
#include <errno.h>
@@ -87,9 +82,13 @@ ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
#include <X11/Xlib.h>
#include <AL/al.h>
#include <AL/alc.h>
char* Font_DefaultName = "Century Schoolbook L Roman";
#endif
#ifdef CC_BUILD_SOLARIS
#include <X11/Xlib.h>
#include <AL/al.h>
#include <AL/alc.h>
#include <sys/filio.h>
#endif
char* Font_DefaultName = "Century Schoolbook L Roman";
#endif
#ifdef CC_BUILD_OSX
@@ -344,6 +343,11 @@ uint64_t Stopwatch_Measure(void) {
return (uint64_t)t.tv_sec * NS_PER_SEC + t.tv_nsec;
}
#endif
#ifdef CC_BUILD_SOLARIS
uint64_t Stopwatch_Measure(void) {
return gethrtime();
}
#endif
#ifdef CC_BUILD_OSX
uint64_t Stopwatch_Measure(void) {
return mach_absolute_time();
@@ -1059,6 +1063,9 @@ static void Font_Init(void) {
#ifdef CC_BUILD_NIX
static String dir = String_FromConst("/usr/share/fonts");
#endif
#ifdef CC_BUILD_SOLARIS
static String dir = String_FromConst("/usr/share/fonts");
#endif
#ifdef CC_BUILD_OSX
static String dir = String_FromConst("/Library/Fonts");
#endif
@@ -1779,19 +1786,13 @@ int Platform_ConvertString(void* data, const String* src) {
return src->length * 2;
}
void Platform_Init(void) {
LARGE_INTEGER freq;
void Platform_Init(void) {
WSADATA wsaData;
ReturnCode res;
Platform_InitDisplay();
Platform_InitStopwatch();
heap = GetProcessHeap();
sw_highRes = QueryPerformanceFrequency(&freq);
if (sw_highRes) {
sw_freqMul = 1000 * 1000;
sw_freqDiv = freq.QuadPart;
} else { sw_freqDiv = 10; }
res = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (res) ErrorHandler_Fail2(res, "WSAStartup failed");
@@ -1814,6 +1815,16 @@ static void Platform_InitDisplay(void) {
ReleaseDC(NULL, hdc);
}
static void Platform_InitStopwatch(void) {
LARGE_INTEGER freq;
sw_highRes = QueryPerformanceFrequency(&freq);
if (sw_highRes) {
sw_freqMul = 1000 * 1000;
sw_freqDiv = freq.QuadPart;
} else { sw_freqDiv = 10; }
}
void Platform_SetWorkingDir(void) {
WCHAR dirName[FILENAME_SIZE + 1];
DWORD len = GetModuleFileNameW(NULL, dirName, FILENAME_SIZE);
@@ -1898,6 +1909,7 @@ int Platform_ConvertString(void* data, const String* src) {
void Platform_Init(void) {
Platform_InitDisplay();
Platform_InitStopwatch();
pthread_mutex_init(&event_mutex, NULL);
pthread_mutex_init(&audio_lock, NULL);
}
@@ -1942,27 +1954,14 @@ static void Platform_TrimFilename(char* path, int len) {
}
}
#endif
#ifdef CC_BUILD_NIX
ReturnCode Platform_StartShell(const String* args) {
return Platform_RunOpen("xdg-open %s", args);
}
void Platform_SetWorkingDir(void) {
char path[FILENAME_SIZE + 1] = { 0 };
int len = readlink("/proc/self/exe", path, FILENAME_SIZE);
if (len <= 0) return;
Platform_TrimFilename(path, len);
chdir(path);
}
#ifdef CC_BUILD_X11
static void Platform_InitDisplay(void) {
Display* display = XOpenDisplay(NULL);
int screen;
if (!display) ErrorHandler_Fail("Failed to open display");
DisplayDevice_Meta = display;
screen = DefaultScreen(display);
sw_freqDiv = 1000;
/* TODO: Use Xinerama and XRandR for querying these */
DisplayDevice_Default.Bounds.X = 0;
@@ -1972,6 +1971,37 @@ static void Platform_InitDisplay(void) {
DisplayDevice_Default.BitsPerPixel = DefaultDepth(display, screen);
}
#endif
#ifdef CC_BUILD_NIX
ReturnCode Platform_StartShell(const String* args) {
return Platform_RunOpen("xdg-open %s", args);
}
static void Platform_InitStopwatch(void) { sw_freqDiv = 1000; }
void Platform_SetWorkingDir(void) {
char path[FILENAME_SIZE + 1] = { 0 };
int len = readlink("/proc/self/exe", path, FILENAME_SIZE);
if (len <= 0) return;
Platform_TrimFilename(path, len);
chdir(path);
}
#endif
#ifdef CC_BUILD_SOLARIS
ReturnCode Platform_StartShell(const String* args) {
/* TODO: Is this on solaris, or just an OpenIndiana thing */
return Platform_RunOpen("xdg-open %s", args);
}
static void Platform_InitStopwatch(void) { sw_freqDiv = 1000; }
void Platform_SetWorkingDir(void) {
char path[FILENAME_SIZE + 1] = { 0 };
int len = readlink("/proc/self/path/a.out", path, FILENAME_SIZE);
if (len <= 0) return;
Platform_TrimFilename(path, len);
chdir(path);
}
#endif
#ifdef CC_BUILD_OSX
ReturnCode Platform_StartShell(const String* args) {
return Platform_RunOpen("/usr/bin/open %s", args);
@@ -2002,17 +2032,20 @@ void Platform_SetWorkingDir(void) {
static void Platform_InitDisplay(void) {
CGDirectDisplayID display = CGMainDisplayID();
CGRect bounds = CGDisplayBounds(display);
mach_timebase_info_data_t tb = { 0 };
mach_timebase_info(&tb);
sw_freqMul = tb.numer;
sw_freqDiv = tb.denom * 1000;
CGRect bounds = CGDisplayBounds(display);
DisplayDevice_Default.Bounds.X = (int)bounds.origin.x;
DisplayDevice_Default.Bounds.Y = (int)bounds.origin.y;
DisplayDevice_Default.Bounds.Width = (int)bounds.size.width;
DisplayDevice_Default.Bounds.Height = (int)bounds.size.height;
DisplayDevice_Default.BitsPerPixel = CGDisplayBitsPerPixel(display);
}
static void Platform_InitStopwatch(void) {
mach_timebase_info_data_t tb = { 0 };
mach_timebase_info(&tb);
sw_freqMul = tb.numer;
sw_freqDiv = tb.denom * 1000;
}
#endif

0 comments on commit ba5a6df

Please sign in to comment.