Mostly cleanup and style modifications
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,21 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2016-2017 Dawid Gan
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef CIRRDEVICEWAYLAND_H
|
||||
#define CIRRDEVICEWAYLAND_H
|
||||
|
||||
@@ -6,340 +24,308 @@
|
||||
#ifdef _IRR_COMPILE_WITH_WAYLAND
|
||||
|
||||
#include "CIrrDeviceStub.h"
|
||||
#include "IrrlichtDevice.h"
|
||||
#include "IImagePresenter.h"
|
||||
#include "ICursorControl.h"
|
||||
#include "os.h"
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <wayland-cursor.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#define KeySym s32
|
||||
|
||||
class ContextManagerEGL;
|
||||
|
||||
// Note : only supporting shell interface
|
||||
|
||||
namespace irr
|
||||
{
|
||||
class CIrrDeviceWayland : public CIrrDeviceStub,
|
||||
public video::IImagePresenter
|
||||
{
|
||||
public:
|
||||
friend class WaylandCallbacks;
|
||||
|
||||
class CIrrDeviceWayland : public CIrrDeviceStub, public video::IImagePresenter
|
||||
{
|
||||
public:
|
||||
//! constructor
|
||||
CIrrDeviceWayland(const SIrrlichtCreationParameters& param);
|
||||
|
||||
//! constructor
|
||||
CIrrDeviceWayland(const SIrrlichtCreationParameters& param);
|
||||
//! destructor
|
||||
virtual ~CIrrDeviceWayland();
|
||||
|
||||
//! destructor
|
||||
virtual ~CIrrDeviceWayland();
|
||||
//! runs the device. Returns false if device wants to be deleted
|
||||
virtual bool run();
|
||||
|
||||
//! runs the device. Returns false if device wants to be deleted
|
||||
virtual bool run();
|
||||
//! Cause the device to temporarily pause execution and let other
|
||||
//! processes to run. This should bring down processor usage without
|
||||
//! major performance loss for Irrlicht
|
||||
virtual void yield();
|
||||
|
||||
//! Cause the device to temporarily pause execution and let other processes to run
|
||||
// This should bring down processor usage without major performance loss for Irrlicht
|
||||
virtual void yield();
|
||||
//! Pause execution and let other processes to run for a specified
|
||||
//! amount of time.
|
||||
virtual void sleep(u32 timeMs, bool pauseTimer);
|
||||
|
||||
//! Pause execution and let other processes to run for a specified amount of time.
|
||||
virtual void sleep(u32 timeMs, bool pauseTimer);
|
||||
//! sets the caption of the window
|
||||
virtual void setWindowCaption(const wchar_t* text);
|
||||
|
||||
//! sets the caption of the window
|
||||
virtual void setWindowCaption(const wchar_t* text);
|
||||
//! returns if window is active. if not, nothing need to be drawn
|
||||
virtual bool isWindowActive() const;
|
||||
|
||||
//! returns if window is active. if not, nothing need to be drawn
|
||||
virtual bool isWindowActive() const;
|
||||
//! returns if window has focus.
|
||||
virtual bool isWindowFocused() const;
|
||||
|
||||
//! returns if window has focus.
|
||||
virtual bool isWindowFocused() const;
|
||||
//! returns if window is minimized.
|
||||
virtual bool isWindowMinimized() const;
|
||||
|
||||
//! returns if window is minimized.
|
||||
virtual bool isWindowMinimized() const;
|
||||
//! returns color format of the window.
|
||||
virtual video::ECOLOR_FORMAT getColorFormat() const;
|
||||
|
||||
//! returns color format of the window.
|
||||
virtual video::ECOLOR_FORMAT getColorFormat() const;
|
||||
//! presents a surface in the client area
|
||||
virtual bool present(video::IImage* surface, void* windowId=0,
|
||||
core::rect<s32>* src=0);
|
||||
|
||||
//! presents a surface in the client area
|
||||
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0 );
|
||||
//! notifies the device that it should close itself
|
||||
virtual void closeDevice();
|
||||
|
||||
//! notifies the device that it should close itself
|
||||
virtual void closeDevice();
|
||||
//! \return Returns a pointer to a list with all video modes
|
||||
//! supported by the gfx adapter.
|
||||
video::IVideoModeList* getVideoModeList();
|
||||
|
||||
//! \return Returns a pointer to a list with all video modes
|
||||
//! supported by the gfx adapter.
|
||||
video::IVideoModeList* getVideoModeList();
|
||||
//! Sets if the window should be resizable in windowed mode.
|
||||
virtual void setResizable(bool resize=false);
|
||||
|
||||
//! Sets if the window should be resizable in windowed mode.
|
||||
virtual void setResizable(bool resize=false);
|
||||
//! Minimizes the window.
|
||||
virtual void minimizeWindow();
|
||||
|
||||
//! Minimizes the window.
|
||||
virtual void minimizeWindow();
|
||||
//! Maximizes the window.
|
||||
virtual void maximizeWindow();
|
||||
|
||||
//! Maximizes the window.
|
||||
virtual void maximizeWindow();
|
||||
//! Restores the window size.
|
||||
virtual void restoreWindow();
|
||||
|
||||
//! Restores the window size.
|
||||
virtual void restoreWindow();
|
||||
//! Activate any joysticks, and generate events for them.
|
||||
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo);
|
||||
|
||||
//! Activate any joysticks, and generate events for them.
|
||||
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
|
||||
//! Set the current Gamma Value for the Display
|
||||
virtual bool setGammaRamp(f32 red, f32 green, f32 blue,
|
||||
f32 brightness, f32 contrast);
|
||||
|
||||
//! Set the current Gamma Value for the Display
|
||||
virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast );
|
||||
//! Get the current Gamma Value for the Display
|
||||
virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue,
|
||||
f32 &brightness, f32 &contrast);
|
||||
|
||||
//! Get the current Gamma Value for the Display
|
||||
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
|
||||
//! gets text from the clipboard
|
||||
//! \return Returns 0 if no string is in there.
|
||||
virtual const c8* getTextFromClipboard() const;
|
||||
|
||||
//! gets text from the clipboard
|
||||
//! \return Returns 0 if no string is in there.
|
||||
virtual const c8* getTextFromClipboard() const;
|
||||
//! copies text to the clipboard
|
||||
virtual void copyToClipboard(const c8* text) const;
|
||||
|
||||
//! copies text to the clipboard
|
||||
//! This sets the clipboard selection and _not_ the primary selection which you have on X on the middle mouse button.
|
||||
virtual void copyToClipboard(const c8* text) const;
|
||||
//! Remove all messages pending in the system message loop
|
||||
virtual void clearSystemMessages();
|
||||
|
||||
//! Remove all messages pending in the system message loop
|
||||
virtual void clearSystemMessages();
|
||||
//! Get the device type
|
||||
virtual E_DEVICE_TYPE getType() const
|
||||
{
|
||||
return EIDT_WAYLAND;
|
||||
}
|
||||
|
||||
//! Get the device type
|
||||
virtual E_DEVICE_TYPE getType() const
|
||||
{
|
||||
return EIDT_WAYLAND;
|
||||
}
|
||||
static bool isWaylandDeviceWorking();
|
||||
|
||||
private:
|
||||
ContextManagerEGL* getEGLContext() {return m_egl_context;}
|
||||
void swapBuffers();
|
||||
void updateCursor();
|
||||
unsigned int getWidth() {return m_width;}
|
||||
unsigned int getHeight() {return m_height;}
|
||||
|
||||
//! create the driver
|
||||
void createDriver();
|
||||
private:
|
||||
|
||||
void initEGL();
|
||||
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
|
||||
struct JoystickInfo
|
||||
{
|
||||
int fd;
|
||||
int axes;
|
||||
int buttons;
|
||||
SEvent persistentData;
|
||||
|
||||
bool createWindow();
|
||||
JoystickInfo() : fd(-1), axes(0), buttons(0) { }
|
||||
};
|
||||
|
||||
void createKeyMap();
|
||||
core::array<JoystickInfo> m_active_joysticks;
|
||||
#endif
|
||||
|
||||
void pollJoysticks();
|
||||
wl_compositor* m_compositor;
|
||||
wl_cursor* m_cursor;
|
||||
wl_cursor_theme* m_cursor_theme;
|
||||
wl_display* m_display;
|
||||
wl_egl_window* m_egl_window;
|
||||
wl_keyboard* m_keyboard;
|
||||
wl_output* m_output;
|
||||
wl_pointer* m_pointer;
|
||||
wl_registry* m_registry;
|
||||
wl_seat* m_seat;
|
||||
wl_shell* m_shell;
|
||||
wl_shell_surface* m_shell_surface;
|
||||
wl_shm* m_shm;
|
||||
wl_surface* m_cursor_surface;
|
||||
wl_surface* m_surface;
|
||||
uint32_t m_enter_serial;
|
||||
|
||||
//! Implementation of the linux cursor control
|
||||
class CCursorControl : public gui::ICursorControl
|
||||
{
|
||||
public:
|
||||
xkb_context* m_xkb_context;
|
||||
xkb_compose_table* m_xkb_compose_table;
|
||||
xkb_compose_state* m_xkb_compose_state;
|
||||
xkb_keymap* m_xkb_keymap;
|
||||
xkb_state* m_xkb_state;
|
||||
xkb_mod_mask_t m_xkb_control_mask;
|
||||
xkb_mod_mask_t m_xkb_alt_mask;
|
||||
xkb_mod_mask_t m_xkb_shift_mask;
|
||||
uint32_t m_xkb_modifiers;
|
||||
|
||||
CCursorControl(CIrrDeviceWayland* dev, bool null);
|
||||
uint32_t m_mouse_button_states;
|
||||
unsigned int m_width;
|
||||
unsigned int m_height;
|
||||
|
||||
~CCursorControl();
|
||||
bool m_window_has_focus;
|
||||
bool m_window_minimized;
|
||||
mutable core::stringc m_clipboard;
|
||||
std::map<int, EKEY_CODE> m_key_map;
|
||||
std::vector<SEvent> m_events;
|
||||
std::vector<core::dimension2du> m_modes;
|
||||
ContextManagerEGL* m_egl_context;
|
||||
|
||||
//! Changes the visible state of the mouse cursor.
|
||||
virtual void setVisible(bool visible)
|
||||
{
|
||||
if (visible==IsVisible)
|
||||
return;
|
||||
|
||||
IsVisible = visible;
|
||||
Device->updateCursor();
|
||||
}
|
||||
void createDriver();
|
||||
void createKeyMap();
|
||||
bool createWindow();
|
||||
bool initEGL();
|
||||
void signalEvent(const SEvent&);
|
||||
void pollJoysticks();
|
||||
void closeJoysticks();
|
||||
};
|
||||
|
||||
//! Returns if the cursor is currently visible.
|
||||
virtual bool isVisible() const
|
||||
{
|
||||
return IsVisible;
|
||||
}
|
||||
//! Implementation of the linux cursor control
|
||||
class CCursorControl : public gui::ICursorControl
|
||||
{
|
||||
public:
|
||||
CCursorControl(CIrrDeviceWayland* device) : m_device(device),
|
||||
m_is_visible(true), m_use_reference_rect(false) {};
|
||||
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(const core::position2d<f32> &pos)
|
||||
{
|
||||
setPosition(pos.X, pos.Y);
|
||||
}
|
||||
~CCursorControl() {};
|
||||
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(f32 x, f32 y)
|
||||
{
|
||||
setPosition((s32)(x*Device->Width), (s32)(y*Device->Height));
|
||||
}
|
||||
//! Changes the visible state of the mouse cursor.
|
||||
virtual void setVisible(bool visible)
|
||||
{
|
||||
if (visible == m_is_visible)
|
||||
return;
|
||||
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(const core::position2d<s32> &pos)
|
||||
{
|
||||
setPosition(pos.X, pos.Y);
|
||||
}
|
||||
m_is_visible = visible;
|
||||
m_device->updateCursor();
|
||||
}
|
||||
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(s32 x, s32 y)
|
||||
{
|
||||
//TODO
|
||||
CursorPos.X = x;
|
||||
CursorPos.Y = y;
|
||||
}
|
||||
//! Returns if the cursor is currently visible.
|
||||
virtual bool isVisible() const
|
||||
{
|
||||
return m_is_visible;
|
||||
}
|
||||
|
||||
//! Returns the current position of the mouse cursor.
|
||||
virtual const core::position2d<s32>& getPosition()
|
||||
{
|
||||
return CursorPos;
|
||||
}
|
||||
|
||||
virtual core::position2d<f32> getRelativePosition()
|
||||
{
|
||||
if (!UseReferenceRect)
|
||||
{
|
||||
return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
|
||||
CursorPos.Y / (f32)Device->Height);
|
||||
}
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(const core::position2d<f32> &pos)
|
||||
{
|
||||
setPosition(pos.X, pos.Y);
|
||||
}
|
||||
|
||||
return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
|
||||
CursorPos.Y / (f32)ReferenceRect.getHeight());
|
||||
}
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(f32 x, f32 y)
|
||||
{
|
||||
setPosition((s32)(x * m_device->getWidth()),
|
||||
(s32)(y * m_device->getHeight()));
|
||||
}
|
||||
|
||||
virtual void setReferenceRect(core::rect<s32>* rect=0)
|
||||
{
|
||||
if (rect)
|
||||
{
|
||||
ReferenceRect = *rect;
|
||||
UseReferenceRect = true;
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(const core::position2d<s32> &pos)
|
||||
{
|
||||
setPosition(pos.X, pos.Y);
|
||||
}
|
||||
|
||||
// prevent division through zero and uneven sizes
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(s32 x, s32 y)
|
||||
{
|
||||
m_cursor_pos.X = x;
|
||||
m_cursor_pos.Y = y;
|
||||
}
|
||||
|
||||
if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
|
||||
ReferenceRect.LowerRightCorner.Y += 1;
|
||||
//! Returns the current position of the mouse cursor.
|
||||
virtual const core::position2d<s32>& getPosition()
|
||||
{
|
||||
return m_cursor_pos;
|
||||
}
|
||||
|
||||
if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
|
||||
ReferenceRect.LowerRightCorner.X += 1;
|
||||
}
|
||||
else
|
||||
UseReferenceRect = false;
|
||||
}
|
||||
virtual core::position2d<f32> getRelativePosition()
|
||||
{
|
||||
if (!m_use_reference_rect)
|
||||
{
|
||||
return core::position2d<f32>(
|
||||
m_cursor_pos.X / (f32)m_device->getWidth(),
|
||||
m_cursor_pos.Y / (f32)m_device->getHeight());
|
||||
}
|
||||
|
||||
//! Sets the active cursor icon
|
||||
virtual void setActiveIcon(gui::ECURSOR_ICON iconId) {};
|
||||
return core::position2d<f32>(
|
||||
m_cursor_pos.X / (f32)m_reference_rect.getWidth(),
|
||||
m_cursor_pos.Y / (f32)m_reference_rect.getHeight());
|
||||
}
|
||||
|
||||
//! Gets the currently active icon
|
||||
virtual gui::ECURSOR_ICON getActiveIcon() const
|
||||
{
|
||||
return ActiveIcon;
|
||||
}
|
||||
virtual void setReferenceRect(core::rect<s32>* rect=0)
|
||||
{
|
||||
m_use_reference_rect = false;
|
||||
|
||||
//! Add a custom sprite as cursor icon.
|
||||
virtual gui::ECURSOR_ICON addIcon(const gui::SCursorSprite& icon)
|
||||
{
|
||||
return gui::ECI_NORMAL;
|
||||
}
|
||||
if (rect)
|
||||
{
|
||||
m_reference_rect = *rect;
|
||||
m_use_reference_rect = true;
|
||||
|
||||
//! replace the given cursor icon.
|
||||
virtual void changeIcon(gui::ECURSOR_ICON iconId, const gui::SCursorSprite& icon) {}
|
||||
// prevent division through zero and uneven sizes
|
||||
if (m_reference_rect.getHeight() == 0 ||
|
||||
m_reference_rect.getHeight() % 2)
|
||||
m_reference_rect.LowerRightCorner.Y += 1;
|
||||
|
||||
//! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work.
|
||||
virtual core::dimension2di getSupportedIconSize() const
|
||||
{
|
||||
return core::dimension2di(0, 0);
|
||||
}
|
||||
private:
|
||||
if (m_reference_rect.getWidth() == 0 ||
|
||||
m_reference_rect.getWidth() % 2)
|
||||
m_reference_rect.LowerRightCorner.X += 1;
|
||||
}
|
||||
}
|
||||
|
||||
CIrrDeviceWayland* Device;
|
||||
core::position2d<s32> CursorPos;
|
||||
core::rect<s32> ReferenceRect;
|
||||
bool IsVisible;
|
||||
bool Null;
|
||||
bool UseReferenceRect;
|
||||
gui::ECURSOR_ICON ActiveIcon;
|
||||
u32 ActiveIconStartTime;
|
||||
};
|
||||
//! Sets the active cursor icon
|
||||
virtual void setActiveIcon(gui::ECURSOR_ICON iconId) {};
|
||||
|
||||
friend class CCursorControl;
|
||||
//! Gets the currently active icon
|
||||
virtual gui::ECURSOR_ICON getActiveIcon() const
|
||||
{
|
||||
return gui::ECI_NORMAL;
|
||||
}
|
||||
|
||||
friend class COpenGLDriver;
|
||||
//! Add a custom sprite as cursor icon.
|
||||
virtual gui::ECURSOR_ICON addIcon(const gui::SCursorSprite& icon)
|
||||
{
|
||||
return gui::ECI_NORMAL;
|
||||
}
|
||||
|
||||
friend class WaylandCallbacks;
|
||||
std::vector<SEvent> events;
|
||||
std::vector<core::dimension2du> Modes;
|
||||
core::dimension2du CurrentModes;
|
||||
//! replace the given cursor icon.
|
||||
virtual void changeIcon(gui::ECURSOR_ICON iconId,
|
||||
const gui::SCursorSprite& icon) {}
|
||||
|
||||
ContextManagerEGL* EglContext;
|
||||
|
||||
public:
|
||||
static bool isWaylandDeviceWorking();
|
||||
void signalEvent(const SEvent&);
|
||||
void addMode(const core::dimension2du &mode) { Modes.push_back(mode); }
|
||||
void setCurrentMode(const core::dimension2du &mode) { CurrentModes = mode; }
|
||||
/** Return a system-specific size which is supported for cursors.
|
||||
Larger icons will fail, smaller icons might work. */
|
||||
virtual core::dimension2di getSupportedIconSize() const
|
||||
{
|
||||
return core::dimension2di(0, 0);
|
||||
}
|
||||
|
||||
wl_display *display;
|
||||
wl_registry *registry;
|
||||
wl_compositor *compositor;
|
||||
wl_seat *seat;
|
||||
wl_pointer *pointer;
|
||||
wl_keyboard *keyboard;
|
||||
wl_output *output;
|
||||
|
||||
wl_shm* shm;
|
||||
wl_cursor_theme* cursor_theme;
|
||||
wl_cursor* default_cursor;
|
||||
wl_surface* cursor_surface;
|
||||
|
||||
xkb_context *xkbctx;
|
||||
xkb_keymap *keymap;
|
||||
xkb_state *state;
|
||||
xkb_mod_mask_t control_mask;
|
||||
xkb_mod_mask_t alt_mask;
|
||||
xkb_mod_mask_t shift_mask;
|
||||
uint32_t modifiers;
|
||||
struct xkb_compose_table *compose_table;
|
||||
struct xkb_compose_state *compose_state;
|
||||
|
||||
wl_shell *shell;
|
||||
wl_surface *surface;
|
||||
wl_shell_surface *shell_surface;
|
||||
wl_egl_window *egl_window;
|
||||
|
||||
u32 ButtonStates;
|
||||
uint32_t enter_serial;
|
||||
|
||||
ContextManagerEGL* getEGLContext() {return EglContext;}
|
||||
void swapBuffers();
|
||||
void updateCursor();
|
||||
|
||||
private:
|
||||
mutable core::stringc Clipboard;
|
||||
u32 Width, Height;
|
||||
bool WindowHasFocus;
|
||||
bool WindowMinimized;
|
||||
public:
|
||||
struct SKeyMap
|
||||
{
|
||||
SKeyMap() {}
|
||||
SKeyMap(s32 x11, s32 win32)
|
||||
: X11Key(x11), Win32Key(win32)
|
||||
{
|
||||
}
|
||||
|
||||
KeySym X11Key;
|
||||
s32 Win32Key;
|
||||
|
||||
bool operator<(const SKeyMap& o) const
|
||||
{
|
||||
return X11Key<o.X11Key;
|
||||
}
|
||||
};
|
||||
|
||||
core::array<SKeyMap> KeyMap;
|
||||
private:
|
||||
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
|
||||
struct JoystickInfo
|
||||
{
|
||||
int fd;
|
||||
int axes;
|
||||
int buttons;
|
||||
|
||||
SEvent persistentData;
|
||||
|
||||
JoystickInfo() : fd(-1), axes(0), buttons(0) { }
|
||||
};
|
||||
core::array<JoystickInfo> ActiveJoysticks;
|
||||
#endif
|
||||
};
|
||||
private:
|
||||
|
||||
CIrrDeviceWayland* m_device;
|
||||
core::position2d<s32> m_cursor_pos;
|
||||
core::rect<s32> m_reference_rect;
|
||||
bool m_is_visible;
|
||||
bool m_use_reference_rect;
|
||||
};
|
||||
|
||||
} // end namespace irr
|
||||
|
||||
|
||||
Reference in New Issue
Block a user