From b65cb9c2d27a7d5edae45c6dcd25aa15a5b1dbd3 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 24 Dec 2019 21:32:05 +0100 Subject: [PATCH] source/Platform/Unix/X11Display.cpp: Initial implementation --- source/Platform/Unix/X11Display.cpp | 64 +++++++++++++++++++++++++---- source/Platform/Unix/X11Display.h | 13 ++++++ 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/source/Platform/Unix/X11Display.cpp b/source/Platform/Unix/X11Display.cpp index eb32495..92f2bfb 100644 --- a/source/Platform/Unix/X11Display.cpp +++ b/source/Platform/Unix/X11Display.cpp @@ -1,31 +1,81 @@ +#include // Prevents conflict with X.h defining "None" +#include +#include "X11SharedDisplay.h" +#include "GLXContext.h" #include "X11Display.h" namespace sp { +X11Display:: +X11Display() : +m_screen (0), +m_disp (NULL), +m_size (200,200) +{ +} + bool X11Display::create(DisplayDescription description) { + XSetWindowAttributes attr; + XVisualInfo* vi; + + m_disp = XGetDisplay(); + if (m_disp == NULL) { + Log::warn("X11: Could not open display"); + return false; + } + + m_screen = DefaultScreen(m_disp); + + attr.border_pixel = BlackPixel(m_disp, m_screen); + attr.background_pixel = WhitePixel(m_disp, m_screen); + //attr.override_redirect = True; + attr.colormap = ::XCreateColormap(m_disp, RootWindow(m_disp, m_screen), DefaultVisual(m_disp, m_screen), AllocNone); + attr.event_mask = ExposureMask; + + m_win = XCreateWindow(m_disp, + RootWindow(m_disp, m_screen), + 0, 0, + m_size.x, m_size.y, 0, DefaultDepth(m_disp, m_screen), + InputOutput, DefaultVisual(m_disp, m_screen), + CWBackPixel | CWColormap | CWBorderPixel | CWEventMask, &attr); + + + XMapWindow(m_disp, m_win); + + // Clear and take focus + XClearWindow(m_disp, m_win); + XMapRaised(m_disp, m_win); + + Log::info("X11: Created display"); + return true; } void X11Display::destroy() { - + if (m_disp) { + XReleaseDisplay(); + m_disp = NULL; + } } bool X11Display::isValid() { - return true; + return m_disp && m_win; } void* X11Display::getHandle() const { - return NULL; + return (void*) m_win; } void X11Display::setSize(unsigned int width, unsigned int height) { m_size = Vector2u(width, height); + + ::XResizeWindow(m_disp, m_win, m_size.x, m_size.y); } Vector2u X11Display::getSize() const @@ -35,22 +85,22 @@ Vector2u X11Display::getSize() const void X11Display::setPosition(unsigned int x, unsigned int y) { - + ::XMoveWindow(m_disp, m_win, x, y); } void X11Display::setCaption(const std::string& caption) { - + ::XStoreName(m_disp, m_win, caption.c_str()); } void X11Display::setIcon(const std::string& icon) { - + // TODO: Implement } void X11Display::showCursor(bool value) { - + // TODO: Implement } } // namespace sp diff --git a/source/Platform/Unix/X11Display.h b/source/Platform/Unix/X11Display.h index 5e1724d..28818b8 100644 --- a/source/Platform/Unix/X11Display.h +++ b/source/Platform/Unix/X11Display.h @@ -2,6 +2,10 @@ #ifndef PLATFORM_UNIX_X11DISPLAY_H #define PLATFORM_UNIX_X11DISPLAY_H +#include // Prevents conflict with X.h defining "None" +#include +#include +#include #include namespace sp { @@ -9,6 +13,7 @@ namespace sp { class X11Display : public PlatformDisplay { public : + X11Display(); virtual bool create(DisplayDescription description); @@ -32,6 +37,14 @@ public : protected : + ::Display* m_disp; + + ::Window m_win; + + int m_screen; + + //GC m_GC; + Vector2u m_size; };