[DEV] new step in reupdate to the wayland backend (not functionnal)

This commit is contained in:
Edouard DUPIN 2019-04-01 21:56:32 +02:00
parent 41952bf140
commit cbc0ac7dbc
2 changed files with 347 additions and 150 deletions

View File

@ -52,6 +52,14 @@ extern "C" {
#include <poll.h> #include <poll.h>
} }
#define XDG_INTERFACE 1
#ifdef XDG_INTERFACE
extern "C" {
#include <xdg-shell-client-protocol.h>
}
#endif
#include <gale/renderer/openGL/openGL-include.hpp> #include <gale/renderer/openGL/openGL-include.hpp>
static bool hasDisplay = false; static bool hasDisplay = false;
@ -101,14 +109,31 @@ static void configure_callback(void* _data, struct wl_callback* _callback, uint3
static struct wl_callback_listener configure_callback_listener = { static struct wl_callback_listener configure_callback_listener = {
configure_callback, configure_callback,
}; };
static void handle_ping(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _serial); #if O
static void handle_configure(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _edges, int32_t _width, int32_t _height); static void handle_ping(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _serial);
static void handle_popup_done(void* _data, struct wl_shell_surface* _shellSurface); static void handle_configure(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _edges, int32_t _width, int32_t _height);
static const struct wl_shell_surface_listener shell_surface_listener = { static void handle_popup_done(void* _data, struct wl_shell_surface* _shellSurface);
handle_ping, static const struct wl_shell_surface_listener shell_surface_listener = {
handle_configure, handle_ping,
handle_popup_done handle_configure,
}; handle_popup_done
};
#else
static void handle_ping(void* _data, struct xdg_wm_base* _wdgWmBase, uint32_t _serial);
static const struct xdg_wm_base_listener wm_base_listener = {
handle_ping,
};
static void xdg_surface_handle_configure(void* _data, struct xdg_surface* _xdgSurface, uint32_t _serial);
static const struct xdg_surface_listener xdg_surface_listener = {
xdg_surface_handle_configure,
};
static void xdg_toplevel_handle_configure(void* _data, struct xdg_toplevel* _xdgToplevel, int32_t _width, int32_t _height, struct wl_array* _states);
static void xdg_toplevel_handle_close(void* _data, struct xdg_toplevel* _xdgToplevel);
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
xdg_toplevel_handle_configure,
xdg_toplevel_handle_close,
};
#endif
static void keyboard_handle_keymap(void* _data, struct wl_keyboard* _keyboard, uint32_t _format, int _fd, uint32_t _size); static void keyboard_handle_keymap(void* _data, struct wl_keyboard* _keyboard, uint32_t _format, int _fd, uint32_t _size);
static void keyboard_handle_enter(void* _data, struct wl_keyboard* _keyboard, uint32_t _serial, struct wl_surface* _surface, struct wl_array* _keys); static void keyboard_handle_enter(void* _data, struct wl_keyboard* _keyboard, uint32_t _serial, struct wl_surface* _surface, struct wl_array* _keys);
static void keyboard_handle_leave(void* _data, struct wl_keyboard* _keyboard, uint32_t _serial, struct wl_surface* _surface); static void keyboard_handle_leave(void* _data, struct wl_keyboard* _keyboard, uint32_t _serial, struct wl_surface* _surface);
@ -215,90 +240,60 @@ static const struct wl_data_source_listener data_source_listener = {
class WAYLANDInterface : public gale::Context { class WAYLANDInterface : public gale::Context {
private: private:
gale::key::Special m_guiKeyBoardMode; gale::key::Special m_guiKeyBoardMode;
ivec2 m_size; ivec2 m_size = ivec2(800,600);
bool m_inputIsPressed[MAX_MANAGE_INPUT]; bool m_inputIsPressed[MAX_MANAGE_INPUT];
etk::String m_uniqueWindowsName; etk::String m_uniqueWindowsName;
bool m_run; bool m_run = false;
bool m_fullscreen; bool m_fullscreen = false;
bool m_configured; bool m_configured = false;
bool m_opaque; bool m_opaque = false;
enum gale::context::cursor m_cursorCurrent; //!< curent cursor enum gale::context::cursor m_cursorCurrent = gale::context::cursor::leftArrow; //!< curent cursor
vec2 m_cursorCurrentPosition; vec2 m_cursorCurrentPosition = vec2(0,0);
char32_t m_lastKeyPressed; char32_t m_lastKeyPressed = 0;
// Wayland interface // Wayland interface
struct wl_display* m_display; struct wl_display* m_display = null;
struct wl_registry* m_registry; struct wl_registry* m_registry = null;
struct wl_compositor* m_compositor; struct wl_compositor* m_compositor = null;
struct wl_shell* m_shell; #if 0
struct wl_seat* m_seat; struct wl_shell* m_shell = null;
struct wl_pointer* m_pointer; struct wl_shell_surface *m_shellSurface = null;
struct wl_keyboard* m_keyboard; #else
struct wl_shm* m_shm; struct xdg_wm_base* m_xdgWmBase = null;
struct wl_cursor_theme* m_cursorTheme; struct xdg_surface* m_xdgSurface = null;
struct wl_cursor* m_cursorDefault; struct xdg_toplevel* m_xdgTopLevel = null;
struct wl_surface* m_cursorSurface; #endif
struct wl_egl_window *m_eglWindow; struct wl_seat* m_seat = null;
struct wl_surface *m_surface; struct wl_pointer* m_pointer = null;
struct wl_shell_surface *m_shellSurface; struct wl_keyboard* m_keyboard = null;
struct wl_callback *m_callback; struct wl_shm* m_shm = null;
struct wl_data_device_manager* m_dataDeviceManager; struct wl_surface *m_surface = null;
int32_t m_dataDeviceManagerVersion; struct wl_cursor_theme* m_cursorTheme = null;
struct wl_data_device *m_dataDevice; struct wl_cursor* m_cursorDefault = null;
int32_t m_serial; //!< Unique ID of the serial element (based on the enter time) struct wl_surface* m_cursorSurface = null;
bool m_offerIsInside; //!< Offer request in inside the windows struct wl_egl_window *m_eglWindow = null;
bool m_offerInternalCopy; //!< The windows own th copy buffer struct wl_callback *m_callback = null;
struct wl_data_offer* m_offerCopy; struct wl_data_device_manager* m_dataDeviceManager = null;
struct wl_data_source* m_dataSource; int32_t m_dataDeviceManagerVersion = 0;
struct wl_data_device *m_dataDevice = null;
int32_t m_serial = 0; //!< Unique ID of the serial element (based on the enter time)
bool m_offerIsInside = false; //!< Offer request in inside the windows
bool m_offerInternalCopy = false; //!< The windows own th copy buffer
struct wl_data_offer* m_offerCopy = null;
struct wl_data_source* m_dataSource = null;
// EGL interface: // EGL interface:
EGLDisplay m_eglDisplay; EGLDisplay m_eglDisplay;
EGLContext m_eglContext; EGLContext m_eglContext;
EGLConfig m_eglConfig; EGLConfig m_eglConfig;
EGLSurface m_eglSurface; EGLSurface m_eglSurface;
#ifdef GALE_XKB_WRAPPER_INPUT #ifdef GALE_XKB_WRAPPER_INPUT
struct xkb_context* m_XKBContext; struct xkb_context* m_XKBContext = null;
struct xkb_keymap* m_XKBKeymap; struct xkb_keymap* m_XKBKeymap = null;
struct xkb_state* m_XKBState; struct xkb_state* m_XKBState = null;
#endif #endif
public: public:
WAYLANDInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) : WAYLANDInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
gale::Context(_application, _argc, _argv), gale::Context(_application, _argc, _argv) {
m_size(800,600),
m_run(false),
m_fullscreen(false),
m_configured(false),
m_opaque(false),
m_cursorCurrent(gale::context::cursor::leftArrow),
m_lastKeyPressed(0),
m_display(null),
m_registry(null),
m_compositor(null),
m_shell(null),
m_seat(null),
m_pointer(null),
m_keyboard(null),
m_shm(null),
m_cursorTheme(null),
m_cursorDefault(null),
m_cursorSurface(null),
m_eglWindow(null),
m_surface(null),
m_shellSurface(null),
m_callback(null),
m_dataDeviceManager(null),
m_dataDeviceManagerVersion(0),
m_dataDevice(null),
m_serial(0),
m_offerIsInside(false),
m_offerInternalCopy(false),
m_offerCopy(null),
m_dataSource(null)
#ifdef GALE_XKB_WRAPPER_INPUT
,m_XKBContext(null),
m_XKBKeymap(null),
m_XKBState(null)
#endif
{
// in case ... // in case ...
GALE_WARNING("WAYLAND: INIT [START]"); GALE_WARNING("WAYLAND: INIT [START]");
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) { for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
@ -311,23 +306,36 @@ class WAYLANDInterface : public gale::Context {
GALE_CRITICAL("Couldn't create xkb context"); GALE_CRITICAL("Couldn't create xkb context");
} }
#endif #endif
GALE_WARNING("WAYLAND: INIT [step 1]");
m_display = wl_display_connect(null); m_display = wl_display_connect(null);
assert(m_display); assert(m_display);
GALE_WARNING("WAYLAND: INIT [step 2]");
m_registry = wl_display_get_registry(m_display); m_registry = wl_display_get_registry(m_display);
wl_registry_add_listener(m_registry, &registry_listener, this); wl_registry_add_listener(m_registry, &registry_listener, this);
GALE_WARNING("WAYLAND: INIT [step 3]");
wl_display_dispatch(m_display); wl_display_dispatch(m_display);
wl_display_roundtrip(m_display);
initEgl(m_opaque); initEgl(m_opaque);
GALE_WARNING("WAYLAND: INIT [step 4]");
createSurface(); createSurface();
GALE_WARNING("WAYLAND: INIT [step 5]");
m_cursorSurface = wl_compositor_create_surface(m_compositor); m_cursorSurface = wl_compositor_create_surface(m_compositor);
if (m_cursorSurface == null) {
GALE_CRITICAL("Can not create surface for the windows");
}
// set the DPI for the current screen: TODO : do it with real value, for now, we use a generic dpi value (most common screen) // set the DPI for the current screen: TODO : do it with real value, for now, we use a generic dpi value (most common screen)
gale::Dimension::setPixelRatio(vec2(75,75),gale::distance::inch); gale::Dimension::setPixelRatio(vec2(75,75),gale::distance::inch);
m_uniqueWindowsName = "GALE_" + etk::toString(etk::tool::irand(0, 1999999999)); m_uniqueWindowsName = "GALE_" + etk::toString(etk::tool::irand(0, 1999999999));
GALE_INFO("Start a windows name : '" << m_uniqueWindowsName << "'");
m_run = true; m_run = true;
GALE_WARNING("WAYLAND: INIT [STOP]"); GALE_WARNING("WAYLAND: INIT [STOP]");
start2ndThreadProcessing(); start2ndThreadProcessing();
@ -355,10 +363,17 @@ class WAYLANDInterface : public gale::Context {
wl_cursor_theme_destroy(m_cursorTheme); wl_cursor_theme_destroy(m_cursorTheme);
m_cursorTheme = null; m_cursorTheme = null;
} }
if (m_shell != null) { #if 0
wl_shell_destroy(m_shell); if (m_shell != null) {
m_shell = null; wl_shell_destroy(m_shell);
} m_shell = null;
}
#else
if (m_xdgWmBase != null) {
xdg_wm_base_destroy(m_xdgWmBase);
m_xdgWmBase = null;
}
#endif
if (m_compositor != null) { if (m_compositor != null) {
wl_compositor_destroy(m_compositor); wl_compositor_destroy(m_compositor);
m_compositor = null; m_compositor = null;
@ -378,7 +393,7 @@ class WAYLANDInterface : public gale::Context {
} }
} }
/****************************************************************************************/ /****************************************************************************************/
int32_t run() { int32_t run() override {
int ret = 0; int ret = 0;
while ( m_run == true while ( m_run == true
&& ret != -1) { && ret != -1) {
@ -419,22 +434,23 @@ class WAYLANDInterface : public gale::Context {
GALE_CRITICAL("Can't initialise Bind"); GALE_CRITICAL("Can't initialise Bind");
return; return;
} }
EGLint nnn; EGLint nnn = 0;
EGLBoolean ret = eglChooseConfig(m_eglDisplay, config_attribs, &m_eglConfig, 1, &nnn); EGLBoolean ret = eglChooseConfig(m_eglDisplay, config_attribs, &m_eglConfig, 1, &nnn);
/* GALE_WARNING("get openGL config ret=" << ret);
EGLint count = 0; #if 1
eglGetConfigs(m_egl_display, null, 0, &count); EGLint count = 0;
GALE_INFO("EGL has " << count << " configs"); eglGetConfigs(m_eglDisplay, null, 0, &count);
EGLConfig* configs = (EGLConfig*)calloc(count, sizeof *configs); GALE_INFO("EGL has " << count << " configs");
GALE_INFO("Display all configs:"); EGLConfig* configs = (EGLConfig*)calloc(count, sizeof(EGLConfig));
for (int32_t iii=0; iii<nnn; ++iii) { GALE_INFO("Display all configs:");
EGLint size = 0; for (int32_t iii=0; iii<nnn; ++iii) {
EGLint sizeRed = 0; EGLint size = 0;
eglGetConfigAttrib(m_eglDisplay, configs[iii], EGL_BUFFER_SIZE, &size); EGLint sizeRed = 0;
eglGetConfigAttrib(m_eglDisplay, configs[iii], EGL_RED_SIZE, &sizeRed); eglGetConfigAttrib(m_eglDisplay, configs[iii], EGL_BUFFER_SIZE, &size);
GALE_INFO(" " << iii << " BufferSize=" << size << " red size=" << sizeRed); eglGetConfigAttrib(m_eglDisplay, configs[iii], EGL_RED_SIZE, &sizeRed);
} GALE_INFO(" " << iii << " BufferSize=" << size << " red size=" << sizeRed);
*/ }
#endif
//assert(ret && n == 1); //assert(ret && n == 1);
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, context_attribs); m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, context_attribs);
@ -451,26 +467,64 @@ class WAYLANDInterface : public gale::Context {
GALE_INFO("un-Init EGL [STOP]"); GALE_INFO("un-Init EGL [STOP]");
} }
void createSurface() { void createSurface() {
GALE_INFO("CRATE the SURFACE [START]"); GALE_INFO("CRATE the SURFACE [START]");
EGLBoolean ret; EGLBoolean ret;
m_surface = wl_compositor_create_surface(m_compositor); m_surface = wl_compositor_create_surface(m_compositor);
m_shellSurface = wl_shell_get_shell_surface(m_shell, m_surface); if (m_surface == null) {
wl_shell_surface_add_listener(m_shellSurface, &shell_surface_listener, this); GALE_CRITICAL("WAYLAND: Can not create compositor surface");
}
#if 0
if (m_shell == null) {
GALE_ERROR("Try to get a shell surface without the shekk interface ==> might crash");
}
m_shellSurface = wl_shell_get_shell_surface(m_shell, m_surface);
if (m_shellSurface == null) {
GALE_CRITICAL("WAYLAND: Can not get the shell surface");
}
wl_shell_surface_add_listener(m_shellSurface, &shell_surface_listener, this);
#else
if (m_xdgWmBase == null) {
GALE_ERROR("Try to get a shell surface without the shekk interface ==> might crash");
}
m_xdgSurface = xdg_wm_base_get_xdg_surface(m_xdgWmBase, m_surface);
if (m_xdgSurface == null) {
GALE_CRITICAL("WAYLAND: Can not get the XDG surface");
}
xdg_wm_base_add_listener(m_xdgWmBase, &wm_base_listener, this);
m_xdgTopLevel= xdg_surface_get_toplevel(m_xdgSurface);
if (m_xdgTopLevel == null) {
GALE_CRITICAL("WAYLAND: Can not get top level element");
}
xdg_surface_add_listener(m_xdgSurface, &xdg_surface_listener, this);
xdg_toplevel_add_listener(m_xdgTopLevel, &xdg_toplevel_listener, this);
#endif
m_eglWindow = wl_egl_window_create(m_surface, m_size.x(), m_size.y()); m_eglWindow = wl_egl_window_create(m_surface, m_size.x(), m_size.y());
wl_surface_commit(m_surface);
wl_display_roundtrip(m_display);
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglWindow, null); m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglWindow, null);
wl_shell_surface_set_title(m_shellSurface, m_uniqueWindowsName.c_str()); #if 0
wl_shell_surface_set_title(m_shellSurface, m_uniqueWindowsName.c_str());
#else
xdg_toplevel_set_title(m_xdgTopLevel, m_uniqueWindowsName.c_str());
xdg_toplevel_set_app_id(m_xdgTopLevel, m_uniqueWindowsName.c_str());
#endif
ret = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext); ret = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
assert(ret == EGL_TRUE); assert(ret == EGL_TRUE);
toggleFullscreen(); toggleFullscreen();
GALE_INFO("CRATE the SURFACE [STOP]"); GALE_INFO("CREATE the SURFACE [STOP]");
} }
void destroySurface() { void destroySurface() {
GALE_INFO("DESTROY the SURFACE [START]"); GALE_INFO("DESTROY the SURFACE [START]");
wl_egl_window_destroy(m_eglWindow); wl_egl_window_destroy(m_eglWindow);
wl_shell_surface_destroy(m_shellSurface); #if 0
wl_shell_surface_destroy(m_shellSurface);
#else
xdg_surface_destroy(m_xdgSurface);
xdg_toplevel_destroy(m_xdgTopLevel);
#endif
wl_surface_destroy(m_surface); wl_surface_destroy(m_surface);
if (m_callback) { if (m_callback) {
wl_callback_destroy(m_callback); wl_callback_destroy(m_callback);
@ -482,10 +536,18 @@ class WAYLANDInterface : public gale::Context {
GALE_INFO("toggleFullscreen [START]"); GALE_INFO("toggleFullscreen [START]");
m_configured = false; m_configured = false;
if (m_fullscreen) { if (m_fullscreen) {
wl_shell_surface_set_fullscreen(m_shellSurface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, null); #if 0
wl_shell_surface_set_fullscreen(m_shellSurface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, null);
#else
// TODO:
#endif
} else { } else {
wl_shell_surface_set_toplevel(m_shellSurface); #if 0
handleConfigure(m_shellSurface, 0, m_size); wl_shell_surface_set_toplevel(m_shellSurface);
handleConfigure(m_shellSurface, 0, m_size);
#else
// TODO:
#endif
} }
struct wl_callback *callback = wl_display_sync(m_display); struct wl_callback *callback = wl_display_sync(m_display);
wl_callback_add_listener(callback, &configure_callback_listener, this); wl_callback_add_listener(callback, &configure_callback_listener, this);
@ -496,12 +558,27 @@ class WAYLANDInterface : public gale::Context {
// recorder on elements ... // recorder on elements ...
void registryHandler(struct wl_registry* _registry, uint32_t _id, const char* _interface, uint32_t _version) { void registryHandler(struct wl_registry* _registry, uint32_t _id, const char* _interface, uint32_t _version) {
GALE_DEBUG("Got a registry event for '" << _interface << "' id=" << _id); GALE_INFO("Got a registry event for '" << _interface << "' id=" << _id);
if (strcmp(_interface, "wl_compositor") == 0) { if (strcmp(_interface, wl_compositor_interface.name) == 0) {
GALE_INFO("Get INTERFACE " << wl_compositor_interface.name);
m_compositor = (struct wl_compositor *)wl_registry_bind(_registry, _id, &wl_compositor_interface, 1); m_compositor = (struct wl_compositor *)wl_registry_bind(_registry, _id, &wl_compositor_interface, 1);
#if 0
} else if (strcmp(_interface, "wl_shell") == 0) { } else if (strcmp(_interface, "wl_shell") == 0) {
m_shell = (struct wl_shell*)wl_registry_bind(_registry, _id, &wl_shell_interface, 1); GALE_INFO("Get INTERFACE wl_shell");
} else if (strcmp(_interface, "wl_seat") == 0) { m_shell = (struct wl_shell*)wl_registry_bind(_registry, _id, &wl_shell_interface, 1);
if (m_shell == null) {
GALE_ERROR("Can not get the shell surfaces...");
}
#else
} else if (strcmp(_interface, xdg_wm_base_interface.name) == 0) {
GALE_INFO("Get INTERFACE" << xdg_wm_base_interface.name);
m_xdgWmBase = (struct xdg_wm_base *)wl_registry_bind(_registry, _id, &xdg_wm_base_interface, 1);
if (m_xdgWmBase == null) {
GALE_ERROR("Can not get the shell surfaces...");
}
#endif
} else if (strcmp(_interface, wl_seat_interface.name) == 0) {
GALE_INFO("Get INTERFACE " << wl_seat_interface.name);
m_seat = (struct wl_seat*)wl_registry_bind(_registry, _id, &wl_seat_interface, 1); m_seat = (struct wl_seat*)wl_registry_bind(_registry, _id, &wl_seat_interface, 1);
wl_seat_add_listener(m_seat, &seat_listener, this); wl_seat_add_listener(m_seat, &seat_listener, this);
if (m_dataDeviceManager != null) { if (m_dataDeviceManager != null) {
@ -510,7 +587,8 @@ class WAYLANDInterface : public gale::Context {
m_dataSource = wl_data_device_manager_create_data_source(m_dataDeviceManager); m_dataSource = wl_data_device_manager_create_data_source(m_dataDeviceManager);
wl_data_source_add_listener(m_dataSource, &data_source_listener, this); wl_data_source_add_listener(m_dataSource, &data_source_listener, this);
} }
} else if (strcmp(_interface, "wl_shm") == 0) { } else if (strcmp(_interface, wl_shm_interface.name) == 0) {
GALE_INFO("Get INFERFACE " << wl_shm_interface.name);
m_shm = (struct wl_shm*)wl_registry_bind(_registry, _id, &wl_shm_interface, 1); m_shm = (struct wl_shm*)wl_registry_bind(_registry, _id, &wl_shm_interface, 1);
m_cursorTheme = wl_cursor_theme_load(null, 32, m_shm); m_cursorTheme = wl_cursor_theme_load(null, 32, m_shm);
if (m_cursorTheme != null) { if (m_cursorTheme != null) {
@ -519,6 +597,7 @@ class WAYLANDInterface : public gale::Context {
GALE_WARNING("Can not get the generic theme"); GALE_WARNING("Can not get the generic theme");
} }
} else if (strcmp(_interface, "wl_data_device_manager") == 0) { } else if (strcmp(_interface, "wl_data_device_manager") == 0) {
GALE_INFO("Get INTERFACE wl_data_device_manager");
m_dataDeviceManagerVersion = etk::min(3, int32_t(_version)); m_dataDeviceManagerVersion = etk::min(3, int32_t(_version));
m_dataDeviceManager = (struct wl_data_device_manager*)wl_registry_bind(_registry, _id, &wl_data_device_manager_interface, m_dataDeviceManagerVersion); m_dataDeviceManager = (struct wl_data_device_manager*)wl_registry_bind(_registry, _id, &wl_data_device_manager_interface, m_dataDeviceManagerVersion);
} else { } else {
@ -526,7 +605,9 @@ class WAYLANDInterface : public gale::Context {
} }
GALE_DEBUG("registry_handle_global [STOP]"); GALE_DEBUG("registry_handle_global [STOP]");
} }
void registryRemover(struct wl_registry* _registry, uint32_t _id) { void registryRemover(struct wl_registry* _registry, uint32_t _id) {
GALE_WARNING("Got a registry losing event for " << _id); GALE_WARNING("Got a registry losing event for " << _id);
} }
@ -701,24 +782,47 @@ class WAYLANDInterface : public gale::Context {
} }
/****************************************************************************************/ /****************************************************************************************/
void handlePing(struct wl_shell_surface* _shell_surface, uint32_t _serial) { #if 0
wl_shell_surface_pong(_shell_surface, _serial); void handlePing(struct wl_shell_surface* _shell_surface, uint32_t _serial) {
GALE_WARNING("Ping ==> pong"); wl_shell_surface_pong(_shell_surface, _serial);
} GALE_WARNING("Ping ==> pong");
void handleConfigure(struct wl_shell_surface* _shell_surface, uint32_t _edges, ivec2 _size) {
GALE_WARNING("configure surface : _edges=" << _edges << " size=" << _size);
if (m_eglWindow != null) {
wl_egl_window_resize(m_eglWindow, _size.x(), _size.y(), 0, 0);
} }
m_size = _size;
OS_Resize(vec2(m_size.x(), m_size.y())); void handleConfigure(struct wl_shell_surface* _shell_surface, uint32_t _edges, ivec2 _size) {
GALE_WARNING("configure [STOP]"); GALE_WARNING("configure surface : _edges=" << _edges << " size=" << _size);
} if (m_eglWindow != null) {
wl_egl_window_resize(m_eglWindow, _size.x(), _size.y(), 0, 0);
void handlePopupDone(struct wl_shell_surface* _shell_surface) { }
GALE_WARNING("Pop-up done"); m_size = _size;
} OS_Resize(vec2(m_size.x(), m_size.y()));
GALE_WARNING("configure [STOP]");
}
void handlePopupDone(struct wl_shell_surface* _shell_surface) {
GALE_WARNING("Pop-up done");
}
#else
void handlePing(struct xdg_wm_base* _wdgWmBase, uint32_t _serial) {
xdg_wm_base_pong(_wdgWmBase, _serial);
GALE_WARNING("Ping ==> pong");
}
void xdgSurfaceHandleConfigure(struct xdg_surface* _xdgSurface, uint32_t _serial) {
GALE_ERROR("configure the surface ****************************************************");
xdg_surface_ack_configure(_xdgSurface, _serial);
}
void xdgToplevelHandleConfigure(struct xdg_toplevel* _xdgToplevel, ivec2 _size, struct wl_array* _states) {
GALE_ERROR("Top Level configure configure: " << _size);
if (m_eglWindow != null) {
wl_egl_window_resize(m_eglWindow, _size.x(), _size.y(), 0, 0);
}
m_size = _size;
OS_Resize(vec2(m_size.x(), m_size.y()));
}
void xdgToplevelHandleClose(struct xdg_toplevel* _xdgToplevel) {
GALE_ERROR("Top Level CLOSE ==> requested ...");
}
#endif
/****************************************************************************************/ /****************************************************************************************/
void keyboardKeymap(struct wl_keyboard* _keyboard, enum wl_keyboard_keymap_format _format, int _fd, uint32_t _size) { void keyboardKeymap(struct wl_keyboard* _keyboard, enum wl_keyboard_keymap_format _format, int _fd, uint32_t _size) {
//GALE_INFO("KEY MAP : '" << _format << "'"); //GALE_INFO("KEY MAP : '" << _format << "'");
@ -942,7 +1046,7 @@ class WAYLANDInterface : public gale::Context {
find = true; find = true;
switch(sym) { switch(sym) {
case XKB_KEY_dead_circumflex: m_lastKeyPressed = '^'; break; case XKB_KEY_dead_circumflex: m_lastKeyPressed = '^'; break;
case XKB_KEY_dead_diaeresis: m_lastKeyPressed = '"'; break; case XKB_KEY_dead_diaeresis: m_lastKeyPressed = '"'; break; //"
//case XKB_KEY_ISO_Level3_Shif: m_lastKeyPressed = '~'; break; //case XKB_KEY_ISO_Level3_Shif: m_lastKeyPressed = '~'; break;
//case XKB_KEY_: m_lastKeyPressed = ''; break; //case XKB_KEY_: m_lastKeyPressed = ''; break;
default: default:
@ -1179,12 +1283,12 @@ class WAYLANDInterface : public gale::Context {
} }
/****************************************************************************************/ /****************************************************************************************/
virtual void stop() { virtual void stop() override {
WAYLAND_INFO("WAYLAND-API: Stop"); WAYLAND_INFO("WAYLAND-API: Stop");
m_run = false; m_run = false;
} }
/****************************************************************************************/ /****************************************************************************************/
virtual void setSize(const vec2& _size) { virtual void setSize(const vec2& _size) override {
WAYLAND_INFO("WAYLAND-API: changeSize=" << _size); WAYLAND_INFO("WAYLAND-API: changeSize=" << _size);
/* /*
m_currentHeight = _size.y(); m_currentHeight = _size.y();
@ -1193,14 +1297,14 @@ class WAYLANDInterface : public gale::Context {
*/ */
} }
/****************************************************************************************/ /****************************************************************************************/
void setFullScreen(bool _status) { void setFullScreen(bool _status) override {
WAYLAND_INFO("WAYLAND-API: changeFullscreen=" << _status); WAYLAND_INFO("WAYLAND-API: changeFullscreen=" << _status);
m_fullscreen = _status; m_fullscreen = _status;
toggleFullscreen(); toggleFullscreen();
// TODO : Grab all event from keyborad // TODO : Grab all event from keyborad
} }
/****************************************************************************************/ /****************************************************************************************/
virtual void grabKeyboardEvents(bool _status) { virtual void grabKeyboardEvents(bool _status) override {
GALE_WARNING("grabKeyboardEvents [START]"); GALE_WARNING("grabKeyboardEvents [START]");
/* /*
if (_status == true) { if (_status == true) {
@ -1218,7 +1322,7 @@ class WAYLANDInterface : public gale::Context {
GALE_WARNING("grabKeyboardEvents [STOP]"); GALE_WARNING("grabKeyboardEvents [STOP]");
} }
/****************************************************************************************/ /****************************************************************************************/
virtual void setWindowsDecoration(bool _status) { virtual void setWindowsDecoration(bool _status) override {
WAYLAND_INFO("WAYLAND-API: setWindows Decoration :" << _status); WAYLAND_INFO("WAYLAND-API: setWindows Decoration :" << _status);
/* /*
// Remove/set decoration // Remove/set decoration
@ -1237,7 +1341,7 @@ class WAYLANDInterface : public gale::Context {
*/ */
}; };
/****************************************************************************************/ /****************************************************************************************/
virtual void setPos(const vec2& _pos) { virtual void setPos(const vec2& _pos) override {
WAYLAND_INFO("WAYLAND-API: changePos=" << _pos); WAYLAND_INFO("WAYLAND-API: changePos=" << _pos);
/* /*
m_windowsPos = _pos; m_windowsPos = _pos;
@ -1257,7 +1361,7 @@ class WAYLANDInterface : public gale::Context {
} }
*/ */
/****************************************************************************************/ /****************************************************************************************/
virtual void setCursor(enum gale::context::cursor _newCursor) { virtual void setCursor(enum gale::context::cursor _newCursor) override {
if (m_cursorCurrent == _newCursor) { if (m_cursorCurrent == _newCursor) {
return; return;
} }
@ -1326,7 +1430,7 @@ class WAYLANDInterface : public gale::Context {
} }
} }
/****************************************************************************************/ /****************************************************************************************/
void grabPointerEvents(bool _status, const vec2& _forcedPosition) { void grabPointerEvents(bool _status, const vec2& _forcedPosition) override {
/* /*
if (_status == true) { if (_status == true) {
WAYLAND_DEBUG("WAYLAND-API: Grab Events"); WAYLAND_DEBUG("WAYLAND-API: Grab Events");
@ -1375,7 +1479,7 @@ class WAYLANDInterface : public gale::Context {
*/ */
} }
/****************************************************************************************/ /****************************************************************************************/
void setIcon(const etk::String& _inputFile) { void setIcon(const etk::Uri& _inputFile) override {
/* /*
#if defined(GALE_BUILD_EGAMI) \ #if defined(GALE_BUILD_EGAMI) \
&& !defined(__TARGET_OS__Web) && !defined(__TARGET_OS__Web)
@ -1523,17 +1627,25 @@ class WAYLANDInterface : public gale::Context {
*/ */
} }
/****************************************************************************************/ /****************************************************************************************/
void setTitle(const etk::String& _title) { void setTitle(const etk::String& _title) override {
WAYLAND_INFO("WAYLAND: set Title (START)"); WAYLAND_INFO("WAYLAND: set Title (START)");
m_uniqueWindowsName = _title; m_uniqueWindowsName = _title;
if (m_shellSurface == null) { #if 0
GALE_ERROR("WAYLAND: set Title (END) ==> missing surface pointer"); if (m_shellSurface == null) {
return; GALE_ERROR("WAYLAND: set Title (END) ==> missing surface pointer");
} return;
wl_shell_surface_set_title(m_shellSurface, m_uniqueWindowsName.c_str()); }
wl_shell_surface_set_title(m_shellSurface, m_uniqueWindowsName.c_str());
#else
if (m_xdgTopLevel == null) {
GALE_ERROR("WAYLAND: set Title (END) ==> missing top-level pointer");
return;
}
xdg_toplevel_set_title(m_xdgTopLevel, m_uniqueWindowsName.c_str());
#endif
WAYLAND_INFO("WAYLAND: set Title (END)"); WAYLAND_INFO("WAYLAND: set Title (END)");
} }
void openURL(const etk::String& _url) { void openURL(const etk::String& _url) override {
etk::String req = "xdg-open "; etk::String req = "xdg-open ";
req += _url; req += _url;
system(req.c_str()); system(req.c_str());
@ -1594,7 +1706,7 @@ class WAYLANDInterface : public gale::Context {
return false; return false;
} }
/****************************************************************************************/ /****************************************************************************************/
void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) { void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) override {
switch (_clipboardID) { switch (_clipboardID) {
case gale::context::clipBoard::clipboardSelection: case gale::context::clipBoard::clipboardSelection:
OS_ClipBoardArrive(_clipboardID); OS_ClipBoardArrive(_clipboardID);
@ -1613,7 +1725,7 @@ class WAYLANDInterface : public gale::Context {
} }
} }
/****************************************************************************************/ /****************************************************************************************/
void clipBoardSet(enum gale::context::clipBoard::clipboardListe _clipboardID) { void clipBoardSet(enum gale::context::clipBoard::clipboardListe _clipboardID) override {
switch (_clipboardID) { switch (_clipboardID) {
case gale::context::clipBoard::clipboardSelection: case gale::context::clipBoard::clipboardSelection:
// Use internal middle button ... // Use internal middle button ...
@ -1746,6 +1858,7 @@ static void configure_callback(void* _data, struct wl_callback* _callback, uint3
interface->configureCallback(_callback, _time); interface->configureCallback(_callback, _time);
} }
#if 0
static void handle_ping(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _serial) { static void handle_ping(void* _data, struct wl_shell_surface* _shellSurface, uint32_t _serial) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data; WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) { if (interface == null) {
@ -1771,7 +1884,42 @@ static void handle_popup_done(void* _data, struct wl_shell_surface* _shellSurfac
} }
interface->handlePopupDone(_shellSurface); interface->handlePopupDone(_shellSurface);
} }
#else
static void handle_ping(void* _data, struct xdg_wm_base* _wdgWmBase, uint32_t _serial) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) {
GALE_ERROR(" ==> null");
return;
}
interface->handlePing(_wdgWmBase, _serial);
}
static void xdg_surface_handle_configure(void* _data, struct xdg_surface* _xdgSurface, uint32_t _serial) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) {
GALE_ERROR(" ==> null");
return;
}
interface->xdgSurfaceHandleConfigure(_xdgSurface, _serial);
}
static void xdg_toplevel_handle_configure(void* _data, struct xdg_toplevel* _xdgToplevel, int32_t _width, int32_t _height, struct wl_array* _states) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) {
GALE_ERROR(" ==> null");
return;
}
interface->xdgToplevelHandleConfigure(_xdgToplevel, ivec2(_width, _height), _states);
}
static void xdg_toplevel_handle_close(void* _data, struct xdg_toplevel* _xdgToplevel) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) {
GALE_ERROR(" ==> null");
return;
}
interface->xdgToplevelHandleClose(_xdgToplevel);
}
#endif
static void keyboard_handle_keymap(void* _data, struct wl_keyboard* _keyboard, uint32_t _format, int _fd, uint32_t _size) { static void keyboard_handle_keymap(void* _data, struct wl_keyboard* _keyboard, uint32_t _format, int _fd, uint32_t _size) {
WAYLANDInterface* interface = (WAYLANDInterface*)_data; WAYLANDInterface* interface = (WAYLANDInterface*)_data;
if (interface == null) { if (interface == null) {

View File

@ -186,6 +186,7 @@ def configure(target, my_module):
'gles2', 'gles2',
'xkbcommon' 'xkbcommon'
]) ])
my_module.add_action(tool_generate_wayland_protocol, data={})
elif "Android" in target.get_type(): elif "Android" in target.get_type():
my_module.add_depend(["SDK", "jvm-basics"]) my_module.add_depend(["SDK", "jvm-basics"])
# add tre creator of the basic java class ... # add tre creator of the basic java class ...
@ -212,6 +213,54 @@ def configure(target, my_module):
##################################################################
##
## Wayland specific section
##
##################################################################
def tool_generate_wayland_protocol(target, module, package_name):
file_list = []
debug.warning("------------------------------------------------------------------------")
debug.warning("Generate wayland back elements... '" + str(module) + "'" )
debug.warning("------------------------------------------------------------------------")
cmd = ["pkg-config", "wayland-protocols", "--variable=pkgdatadir"]
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
if ret == False:
debug.error("Can not execute protocol extraction...")
WAYLAND_PROTOCOLS_DIR = ret
debug.warning("WAYLAND_PROTOCOLS_DIR = " + str(WAYLAND_PROTOCOLS_DIR))
cmd = ["pkg-config", "--variable=wayland_scanner", "wayland-scanner"]
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
if ret == False:
debug.error("Can not execute protocol extraction...")
WAYLAND_SCANNER = ret
debug.warning("WAYLAND_SCANNER = " + str(WAYLAND_SCANNER))
XDG_SHELL_PROTOCOL = os.path.join(WAYLAND_PROTOCOLS_DIR, "stable", "xdg-shell", "xdg-shell.xml")
debug.warning("XDG_SHELL_PROTOCOL = " + str(XDG_SHELL_PROTOCOL))
client_protocol_header = "xdg-shell-client-protocol.h"
client_protocol = "xdg-shell-protocol.c"
# create files
debug.warning("Generate file = " + client_protocol_header)
tmp_file = "/tmp/gale_wayland.tmp"
cmd = [WAYLAND_SCANNER, "client-header", XDG_SHELL_PROTOCOL, tmp_file]
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
if ret == False:
debug.error("error in generate wayland header code")
tmp_file_data = tools.file_read_data(tmp_file)
module.add_generated_header_file(tmp_file_data, client_protocol_header)
debug.warning("Generate file = " + client_protocol)
cmd = [WAYLAND_SCANNER, "private-code", XDG_SHELL_PROTOCOL, tmp_file]
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
if ret == False:
debug.error("Error in wayland generation code of private header protocole")
tmp_file_data = tools.file_read_data(tmp_file)
module.add_generated_src_file(tmp_file_data, client_protocol)
################################################################## ##################################################################
## ##
## Android specific section ## Android specific section