Add a simple processing of the event queue on X11/Skia port

This commit is contained in:
David Capello 2017-04-19 19:35:26 -03:00
parent 8b0c269b56
commit 706b9a84c6
8 changed files with 82 additions and 30 deletions

View File

@ -210,6 +210,7 @@ if(USE_SKIA_BACKEND)
else() else()
list(APPEND SHE_SOURCES list(APPEND SHE_SOURCES
skia/skia_window_x11.cpp skia/skia_window_x11.cpp
x11/event_queue.cpp
x11/keys.cpp x11/keys.cpp
x11/x11.cpp) x11/x11.cpp)
endif() endif()

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2012-2016 David Capello // Copyright (C) 2012-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -25,7 +25,7 @@
namespace she { namespace she {
System* create_system_impl() { System* create_system_impl() {
return new SkiaSystem(); return new SkiaSystem;
} }
void error_message(const char* msg) void error_message(const char* msg)

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2012-2016 David Capello // Copyright (C) 2012-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -25,7 +25,8 @@
#define SkiaSystemBase OSXSystem #define SkiaSystemBase OSXSystem
#else #else
#include "she/x11/event_queue.h" #include "she/x11/event_queue.h"
#define SkiaSystemBase CommonSystem #include "she/x11/system.h"
#define SkiaSystemBase X11System
#endif #endif
#include "SkGraphics.h" #include "SkGraphics.h"

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2016 David Capello // Copyright (C) 2016-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -11,16 +11,18 @@
#include "she/skia/skia_window_x11.h" #include "she/skia/skia_window_x11.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "she/event.h"
#include "she/event_queue.h"
#include "she/skia/skia_display.h"
#include "she/x11/x11.h" #include "she/x11/x11.h"
#include "SkBitmap.h"
namespace she { namespace she {
SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display, SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display,
int width, int height, int scale) int width, int height, int scale)
: X11Window(X11::instance()->display(), width, height) : X11Window(X11::instance()->display(), width, height)
, m_queue(queue)
, m_display(display)
, m_clientSize(width, height) , m_clientSize(width, height)
, m_scale(scale) , m_scale(scale)
{ {
@ -30,6 +32,12 @@ SkiaWindow::~SkiaWindow()
{ {
} }
void SkiaWindow::queueEventImpl(Event& ev)
{
ev.setDisplay(m_display);
m_queue->queueEvent(ev);
}
int SkiaWindow::scale() const int SkiaWindow::scale() const
{ {
return m_scale; return m_scale;

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2016 David Capello // Copyright (C) 2016-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -20,7 +20,7 @@ namespace she {
class EventQueue; class EventQueue;
class SkiaDisplay; class SkiaDisplay;
class SkiaWindow : public X11Window { class SkiaWindow : public X11Window<SkiaWindow> {
public: public:
enum class Backend { NONE, GL }; enum class Backend { NONE, GL };
@ -28,6 +28,8 @@ public:
int width, int height, int scale); int width, int height, int scale);
~SkiaWindow(); ~SkiaWindow();
void queueEventImpl(Event& ev);
int scale() const; int scale() const;
void setScale(int scale); void setScale(int scale);
void setVisible(bool visible); void setVisible(bool visible);
@ -51,6 +53,8 @@ public:
private: private:
void onExpose() override; void onExpose() override;
EventQueue* m_queue;
SkiaDisplay* m_display;
gfx::Size m_clientSize; gfx::Size m_clientSize;
int m_scale; int m_scale;

View File

@ -0,0 +1,46 @@
// SHE library
// Copyright (C) 2016-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "she/x11/event_queue.h"
#include <X11/Xlib.h>
namespace she {
void X11EventQueue::getEvent(Event& ev, bool canWait)
{
::Display* display = X11::instance()->display();
XSync(display, False);
XEvent event;
int events = XEventsQueued(display, QueuedAlready);
for (int i=0; i<events; ++i) {
XNextEvent(display, &event);
processX11Event(event);
}
if (m_events.empty()) {
#pragma push_macro("None")
#undef None // Undefine the X11 None macro
ev.setType(Event::None);
#pragma pop_macro("None")
}
else {
ev = m_events.front();
m_events.pop();
}
}
void X11EventQueue::processX11Event(XEvent& event)
{
// TODO
}
} // namespace she

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2016 David Capello // Copyright (C) 2016-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -14,31 +14,18 @@
#include <queue> #include <queue>
#pragma push_macro("None")
#undef None // Undefine the X11 None macro
namespace she { namespace she {
class X11EventQueue : public EventQueue { class X11EventQueue : public EventQueue {
public: public:
void getEvent(Event& ev, bool canWait) override { void getEvent(Event& ev, bool canWait) override;
XEvent event;
XNextEvent(X11::instance()->display(), &event);
if (m_events.empty()) {
ev.setType(Event::None);
}
else {
ev = m_events.front();
m_events.pop();
}
}
void queueEvent(const Event& ev) override { void queueEvent(const Event& ev) override {
m_events.push(ev); m_events.push(ev);
} }
private: private:
void processX11Event(XEvent& event);
std::queue<Event> m_events; std::queue<Event> m_events;
}; };
@ -46,6 +33,4 @@ typedef X11EventQueue EventQueueImpl;
} // namespace she } // namespace she
#pragma pop_macro("None")
#endif #endif

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2016 David Capello // Copyright (C) 2016-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -16,6 +16,9 @@
namespace she { namespace she {
class Event;
template<typename T>
class X11Window { class X11Window {
public: public:
X11Window(::Display* display, int width, int height) X11Window(::Display* display, int width, int height)
@ -48,6 +51,10 @@ public:
XDestroyWindow(m_display, m_window); XDestroyWindow(m_display, m_window);
} }
void queueEvent(Event& ev) {
static_cast<T*>(this)->queueEventImpl(ev);
}
void setTitle(const std::string& title) { void setTitle(const std::string& title) {
XTextProperty prop; XTextProperty prop;
prop.value = (unsigned char*)title.c_str(); prop.value = (unsigned char*)title.c_str();