Unix: Rename X11Display to X11Window and make it work again with Spectre/Window/Window
This commit is contained in:
parent
96f6725428
commit
45d3bff620
9 changed files with 60 additions and 62 deletions
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <Platform/PlatformDisplay.h>
|
||||
#include <Platform/PlatformWindow.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
|
||||
#include "glad_glx.h"
|
||||
|
|
@ -70,12 +70,12 @@ GLXContext::~GLXContext()
|
|||
destroy();
|
||||
}
|
||||
|
||||
bool GLXContext::create(const PlatformDisplay* display)
|
||||
bool GLXContext::create(const PlatformWindow* window)
|
||||
{
|
||||
// Destroy any previous context first.
|
||||
destroy();
|
||||
|
||||
m_win = (::Window) display->getHandle();
|
||||
m_win = (::Window) window->getHandle();
|
||||
|
||||
if (!createGLContext()) {
|
||||
destroy();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// X11 OpenGL Context (glx)
|
||||
|
||||
#include "glad_glx.h"
|
||||
#include <Spectre/Display/GLContext.h>
|
||||
#include <Spectre/Window/GLContext.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
|
|
@ -15,8 +15,8 @@ public :
|
|||
GLXContext();
|
||||
~GLXContext();
|
||||
|
||||
// Create a context associated with a display.
|
||||
bool create(const PlatformDisplay* display);
|
||||
// Create a context associated with a window.
|
||||
bool create(const PlatformWindow* window);
|
||||
|
||||
void destroy();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include "X11Keyboard.h"
|
||||
#include "X11Display.h"
|
||||
#include "X11Window.h"
|
||||
#include "Xlib.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
|
@ -354,7 +354,7 @@ bool X11Keyboard::handleMessage(XKeyEvent* xkeyevent, Event& event)
|
|||
|
||||
void X11Keyboard::update(InputModule *input)
|
||||
{
|
||||
X11Display *focus = X11Display::getFocused();
|
||||
X11Window *focus = X11Window::getFocused();
|
||||
m_win = focus ? (::Window) focus->getHandle() : 0;
|
||||
|
||||
// If we have focus.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <Spectre/System/Event.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "Xlib.h"
|
||||
#include "X11Display.h"
|
||||
#include "X11Window.h"
|
||||
#include "X11Mouse.h"
|
||||
|
||||
#define XBUTTON1BIT (1<<0)
|
||||
|
|
@ -89,7 +89,7 @@ void X11Mouse::update(InputModule *input)
|
|||
|
||||
void X11Mouse::updateFocusedWindow()
|
||||
{
|
||||
X11Display *focus = X11Display::getFocused();
|
||||
X11Window *focus = X11Window::getFocused();
|
||||
m_win = focus ? (::Window) focus->getHandle() : 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "Xlib.h"
|
||||
#include "wm_hints.h"
|
||||
#include "GLXContext.h"
|
||||
#include "X11Display.h"
|
||||
#include "X11Window.h"
|
||||
|
||||
// Sometimes not defined in headers.
|
||||
#ifndef _NET_WM_STATE_TOGGLE
|
||||
|
|
@ -19,17 +19,17 @@ namespace sp {
|
|||
|
||||
namespace _priv {
|
||||
|
||||
// Pointer to the display that has focus (or NULL if none have).
|
||||
X11Display* focused_display = NULL;
|
||||
// Pointer to the window that has focus (or NULL if none have).
|
||||
X11Window* focused_window = NULL;
|
||||
}
|
||||
|
||||
X11Display* X11Display::getFocused()
|
||||
X11Window* X11Window::getFocused()
|
||||
{
|
||||
return _priv::focused_display;
|
||||
return _priv::focused_window;
|
||||
}
|
||||
|
||||
X11Display::
|
||||
X11Display() :
|
||||
X11Window::
|
||||
X11Window() :
|
||||
m_screen (0),
|
||||
m_size (200,200),
|
||||
m_cur_last (0),
|
||||
|
|
@ -37,13 +37,13 @@ m_cur_hidden (0)
|
|||
{
|
||||
}
|
||||
|
||||
bool X11Display::create(DisplayDescription description)
|
||||
bool X11Window::create(WindowDescription description)
|
||||
{
|
||||
XSetWindowAttributes attr;
|
||||
XVisualInfo* vi;
|
||||
Atom protocols;
|
||||
Visual* visual;
|
||||
Window root_win;
|
||||
::Window root_win;
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
|
||||
m_screen = DefaultScreen(disp);
|
||||
|
|
@ -92,7 +92,7 @@ bool X11Display::create(DisplayDescription description)
|
|||
return true;
|
||||
}
|
||||
|
||||
void X11Display::destroy()
|
||||
void X11Window::destroy()
|
||||
{
|
||||
if (m_win) {
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
|
|
@ -101,17 +101,17 @@ void X11Display::destroy()
|
|||
}
|
||||
}
|
||||
|
||||
bool X11Display::isValid()
|
||||
bool X11Window::isValid()
|
||||
{
|
||||
return m_win;
|
||||
}
|
||||
|
||||
void* X11Display::getHandle() const
|
||||
void* X11Window::getHandle() const
|
||||
{
|
||||
return (void*) m_win;
|
||||
}
|
||||
|
||||
void X11Display::setSize(unsigned int width, unsigned int height)
|
||||
void X11Window::setSize(unsigned int width, unsigned int height)
|
||||
{
|
||||
Log::info("X11: Set size %dx%d", width, height);
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ void X11Display::setSize(unsigned int width, unsigned int height)
|
|||
::XResizeWindow(Xlib::getDisplay(), m_win, m_size.x, m_size.y);
|
||||
}
|
||||
|
||||
Vector2u X11Display::getSize() const
|
||||
Vector2u X11Window::getSize() const
|
||||
{
|
||||
int x, y;
|
||||
unsigned int w, h, bw, d;
|
||||
|
|
@ -146,12 +146,12 @@ Vector2u X11Display::getSize() const
|
|||
return Vector2u(w, h);
|
||||
}
|
||||
|
||||
void X11Display::setPosition(unsigned int x, unsigned int y)
|
||||
void X11Window::setPosition(unsigned int x, unsigned int y)
|
||||
{
|
||||
::XMoveWindow(Xlib::getDisplay(), m_win, x, y);
|
||||
}
|
||||
|
||||
Vector2u X11Display::getPosition() const
|
||||
Vector2u X11Window::getPosition() const
|
||||
{
|
||||
int x, y;
|
||||
unsigned int w, h, bw, d;
|
||||
|
|
@ -169,7 +169,7 @@ Vector2u X11Display::getPosition() const
|
|||
return Vector2u(x, y);
|
||||
}
|
||||
|
||||
void X11Display::setVisible(bool visible)
|
||||
void X11Window::setVisible(bool visible)
|
||||
{
|
||||
if (visible) {
|
||||
::XMapWindow(Xlib::getDisplay(), m_win);
|
||||
|
|
@ -178,7 +178,7 @@ void X11Display::setVisible(bool visible)
|
|||
}
|
||||
}
|
||||
|
||||
void X11Display::setDecoration(unsigned decoration)
|
||||
void X11Window::setDecoration(unsigned decoration)
|
||||
{
|
||||
Atom WMHintsAtom = Xlib::getAtom("_MOTIF_WM_HINTS", false);
|
||||
|
||||
|
|
@ -191,19 +191,19 @@ void X11Display::setDecoration(unsigned decoration)
|
|||
hints.decorations = 0;
|
||||
hints.functions = 0;
|
||||
|
||||
if (decoration & DisplayDecorate::Menu) {
|
||||
if (decoration & WindowDecorate::Menu) {
|
||||
Log::info("X11: Decoration Menu");
|
||||
hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU;
|
||||
hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE;
|
||||
}
|
||||
|
||||
if (decoration & DisplayDecorate::Resize) {
|
||||
if (decoration & WindowDecorate::Resize) {
|
||||
Log::info("X11: Decoration Resize");
|
||||
hints.decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH;
|
||||
hints.functions |= MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
|
||||
}
|
||||
|
||||
if (decoration & DisplayDecorate::Close) {
|
||||
if (decoration & WindowDecorate::Close) {
|
||||
Log::info("X11: Decoration Close");
|
||||
hints.decorations |= 0;
|
||||
hints.functions |= MWM_FUNC_CLOSE;
|
||||
|
|
@ -215,12 +215,12 @@ void X11Display::setDecoration(unsigned decoration)
|
|||
}
|
||||
}
|
||||
|
||||
void X11Display::minimize()
|
||||
void X11Window::minimize()
|
||||
{
|
||||
::XIconifyWindow(Xlib::getDisplay(), m_win, m_screen);
|
||||
}
|
||||
|
||||
void X11Display::maximize()
|
||||
void X11Window::maximize()
|
||||
{
|
||||
::XClientMessageEvent ev = {};
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
|
|
@ -238,7 +238,7 @@ void X11Display::maximize()
|
|||
SubstructureNotifyMask, (XEvent*) &ev);
|
||||
}
|
||||
|
||||
void X11Display::enterFullscreen(DisplayMode mode)
|
||||
void X11Window::enterFullscreen(DisplayMode mode)
|
||||
{
|
||||
if (!XRandR::FindMode(Xlib::getDisplay(), mode.width, mode.height, mode.bpp, &m_fullscreen_mode.size, &m_fullscreen_mode.rate)) {
|
||||
Log::warn("X11: Failed to find a mode");
|
||||
|
|
@ -248,7 +248,7 @@ void X11Display::enterFullscreen(DisplayMode mode)
|
|||
toggleFullscreen(true);
|
||||
}
|
||||
|
||||
void X11Display::toggleFullscreen(bool enable)
|
||||
void X11Window::toggleFullscreen(bool enable)
|
||||
{
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
::Window root;
|
||||
|
|
@ -272,7 +272,7 @@ void X11Display::toggleFullscreen(bool enable)
|
|||
XRRSetScreenConfigAndRate(disp, conf, root, mode->size, RR_Rotate_0, mode->rate, CurrentTime);
|
||||
}
|
||||
|
||||
void X11Display::exitFullscreen()
|
||||
void X11Window::exitFullscreen()
|
||||
{
|
||||
if (m_fullscreen_mode.rate > 0) {
|
||||
toggleFullscreen(false);
|
||||
|
|
@ -286,7 +286,7 @@ void X11Display::exitFullscreen()
|
|||
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
|
||||
#define _NET_WM_STATE_ADD 1 /* add/set property */
|
||||
|
||||
void X11Display::wm_fullscreen(bool enabled) {
|
||||
void X11Window::wm_fullscreen(bool enabled) {
|
||||
|
||||
::Display* disp = sp::Xlib::getDisplay();
|
||||
|
||||
|
|
@ -309,12 +309,12 @@ void X11Display::wm_fullscreen(bool enabled) {
|
|||
}
|
||||
|
||||
|
||||
void X11Display::setCaption(const std::string& caption)
|
||||
void X11Window::setCaption(const std::string& caption)
|
||||
{
|
||||
::XStoreName(Xlib::getDisplay(), m_win, caption.c_str());
|
||||
}
|
||||
|
||||
void X11Display::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels)
|
||||
void X11Window::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels)
|
||||
{
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
::Atom net_wm_icon = Xlib::getAtom("_NET_WM_ICON", False);
|
||||
|
|
@ -342,7 +342,7 @@ void X11Display::setIcon(unsigned int width, unsigned int height, const uint8_t
|
|||
XFlush(disp);
|
||||
}
|
||||
|
||||
void X11Display::createHiddenCursor()
|
||||
void X11Window::createHiddenCursor()
|
||||
{
|
||||
::Display* disp = Xlib::getDisplay();
|
||||
XColor c;
|
||||
|
|
@ -361,12 +361,12 @@ void X11Display::createHiddenCursor()
|
|||
::XFreeGC(disp, gc);
|
||||
}
|
||||
|
||||
void X11Display::showCursor(bool value)
|
||||
void X11Window::showCursor(bool value)
|
||||
{
|
||||
XDefineCursor(Xlib::getDisplay(), m_win, value ? m_cur_last : m_cur_hidden);
|
||||
}
|
||||
|
||||
void X11Display::grabCursor(bool value)
|
||||
void X11Window::grabCursor(bool value)
|
||||
{
|
||||
if (value) {
|
||||
int result = ::XGrabPointer(Xlib::getDisplay(), m_win, True, None,
|
||||
|
|
@ -380,7 +380,7 @@ void X11Display::grabCursor(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
void X11Display::processEvent(const ::XEvent& event)
|
||||
void X11Window::processEvent(const ::XEvent& event)
|
||||
{
|
||||
Vector2u size;
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ void X11Display::processEvent(const ::XEvent& event)
|
|||
break;
|
||||
case FocusIn:
|
||||
Log::debug("X11: FocusIn");
|
||||
_priv::focused_display = this;
|
||||
_priv::focused_window = this;
|
||||
|
||||
if (m_fullscreen_mode.rate > 0) {
|
||||
toggleFullscreen(true);
|
||||
|
|
@ -409,7 +409,7 @@ void X11Display::processEvent(const ::XEvent& event)
|
|||
break;
|
||||
case FocusOut:
|
||||
Log::debug("X11: FocusOut");
|
||||
_priv::focused_display = NULL;
|
||||
_priv::focused_window = NULL;
|
||||
if (m_fullscreen_mode.rate > 0) {
|
||||
toggleFullscreen(false);
|
||||
minimize();
|
||||
|
|
@ -1,27 +1,25 @@
|
|||
|
||||
#ifndef PLATFORM_UNIX_X11DISPLAY_H
|
||||
#define PLATFORM_UNIX_X11DISPLAY_H
|
||||
#ifndef PLATFORM_UNIX_X11WINDOW_H
|
||||
#define PLATFORM_UNIX_X11WINDOW_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <cstdint>
|
||||
#include <Platform/PlatformDisplay.h>
|
||||
#include <Platform/PlatformWindow.h>
|
||||
#include "Xrandr.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
// NOTE: This class wraps a X11 Window and Screen handle
|
||||
// and is NOT a Class wrapper around X11's `Display` type.
|
||||
class X11Display : public PlatformDisplay
|
||||
class X11Window : public PlatformWindow
|
||||
{
|
||||
public :
|
||||
|
||||
static X11Display* getFocused();
|
||||
static X11Window* getFocused();
|
||||
|
||||
X11Display();
|
||||
X11Window();
|
||||
|
||||
virtual bool create(DisplayDescription description);
|
||||
virtual bool create(WindowDescription description);
|
||||
|
||||
virtual void destroy();
|
||||
|
||||
|
|
@ -85,4 +83,4 @@ protected :
|
|||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_UNIX_X11DISPLAY_H */
|
||||
#endif /* PLATFORM_UNIX_X11WINDOW_H */
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "X11Display.h"
|
||||
#include "X11Window.h"
|
||||
#include "X11WindowEventHandler.h"
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Context used to store X11Display pointer.
|
||||
// Context used to store X11Window pointer.
|
||||
::XContext X11WindowEventHandler::win_context = None;
|
||||
|
||||
void X11WindowEventHandler::registerHandler(::Display* disp, ::Window window, X11Display *ptr)
|
||||
void X11WindowEventHandler::registerHandler(::Display* disp, ::Window window, X11Window *ptr)
|
||||
{
|
||||
// Initialize context before use.
|
||||
if (win_context == None) {
|
||||
|
|
@ -41,7 +41,7 @@ void X11WindowEventHandler::process(::Display* disp, const ::XEvent& event)
|
|||
|
||||
// Get the pointer for window ID.
|
||||
if (XFindContext(disp, event.xany.window, win_context, &ptr) == 0) {
|
||||
X11Display* disp_ptr = (X11Display*) ptr;
|
||||
X11Window* disp_ptr = (X11Window*) ptr;
|
||||
|
||||
// Delegate
|
||||
disp_ptr->processEvent(event);
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
namespace sp {
|
||||
|
||||
class X11Display;
|
||||
class X11Window;
|
||||
|
||||
class X11WindowEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
static void registerHandler(::Display* disp, ::Window window, X11Display *ptr);
|
||||
static void registerHandler(::Display* disp, ::Window window, X11Window *ptr);
|
||||
|
||||
static void unregisterHandler(::Display* disp, ::Window window);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue