diff --git a/src/Carbon/CMakeLists.txt b/src/Carbon/CMakeLists.txt new file mode 100644 index 000000000..88c7cded5 --- /dev/null +++ b/src/Carbon/CMakeLists.txt @@ -0,0 +1,23 @@ +project(Carbon) + +cmake_minimum_required(VERSION 2.4.0) +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +#configure_file(config.h.in config.h) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util) + +set(Carbon_SRCS + HIToolbox/MacWindows.cpp +) + +add_library(Carbon SHARED ${Carbon_SRCS}) +target_link_libraries(Carbon util CoreServices -lX11) + +install(TARGETS Carbon DESTINATION "lib${SUFFIX}/darling") + diff --git a/src/Carbon/HIToolbox/MacWindows.cpp b/src/Carbon/HIToolbox/MacWindows.cpp new file mode 100644 index 000000000..a48fbf747 --- /dev/null +++ b/src/Carbon/HIToolbox/MacWindows.cpp @@ -0,0 +1,92 @@ +#include "MacWindows.h" +#include +#include +#include + +static Display* g_display = nullptr; +static void closeDisplay() __attribute__((destructor)); + +Display* Darling::Carbon::getDisplay() +{ + if (g_display) + return g_display; + + g_display = XOpenDisplay(nullptr); + + if (!g_display) + { + std::cerr << "Darling Carbon: Cannot open a connection to the X server!\n"; + if (!getenv("DISPLAY")) + std::cerr << "The application you are trying to run requires an X server and cannot be run only in the console.\n"; + abort(); + } + + return g_display; +} + +void closeDisplay() +{ + if (g_display) + { + XCloseDisplay(g_display); + g_display = nullptr; + } +} + +OSStatus CreateNewWindow(WindowClass cls, WindowAttributes attr, const Rect* rect, WindowRef* newWindow) +{ + Window win; + Display* dpy; + int blackColor, whiteColor; + + *newWindow = 0; + + if (rect->right < rect->left || rect->bottom < rect->top) + return paramErr; + + dpy = Darling::Carbon::getDisplay(); + blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + whiteColor = WhitePixel(dpy, DefaultScreen(dpy)); + + win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), rect->left, + rect->top, rect->right - rect->left, + rect->bottom - rect->top, 0, blackColor, whiteColor); + + if (!win) + return paramErr; + + *newWindow = win; + return noErr; +} + +void DisposeWindow(WindowRef wnd) +{ + if (wnd) + XDestroyWindow(wnd); +} + +void ShowWindow(WindowRef wnd) +{ + if (wnd) + XMapWindow(Darling::Carbon::getDisplay(), Window(wnd)); +} + +void HideWindow(WindowRef wnd) +{ + if (wnd) + XUnmapWindow(Darling::Carbon::getDisplay(), Window(wnd)); +} + +void ShowHide(WindowRef wnd, Boolean showFlag) +{ + if (showFlag) + ShowWindow(wnd); + else + HideWindow(wnd); +} + +Boolean IsWindowVisible(WindowRef wnd) +{ + +} + diff --git a/src/Carbon/HIToolbox/MacWindows.h b/src/Carbon/HIToolbox/MacWindows.h new file mode 100644 index 000000000..1be00df24 --- /dev/null +++ b/src/Carbon/HIToolbox/MacWindows.h @@ -0,0 +1,43 @@ +#ifndef MACWINDOWS_H +#define MACWINDOWS_H +//#include +#include "../../CoreServices/MacErrors.h" +#include "../../CoreServices/MacTypes.h" +#include + +#pragma pack(2) + +extern "C" { + +typedef int WindowRef; // mapped to X11 Window +typedef WindowRef HIWindowRef; + +typedef uint32_t WindowClass; +typedef OptionBits WindowAttributes; + +struct Rect +{ + short top, left, bottom, right; +}; + +OSStatus CreateNewWindow(WindowClass cls, WindowAttributes attr, const Rect* rect, WindowRef* newWindow); +void DisposeWindow(WindowRef wnd); + +void ShowWindow(WindowRef wnd); +void HideWindow(WindowRef wnd); +void ShowHide(WindowRef wnd, Boolean showFlag); +Boolean IsWindowVisible(WindowRef wnd); + +} + +namespace Darling { +namespace Carbon { + +Display* getDisplay(); + +}} // end namespaces + +#pragma pack() + +#endif +