diff --git a/src/she/CMakeLists.txt b/src/she/CMakeLists.txt index c4d0c2dd8..5c369a80e 100644 --- a/src/she/CMakeLists.txt +++ b/src/she/CMakeLists.txt @@ -210,6 +210,7 @@ if(USE_SKIA_BACKEND) else() list(APPEND SHE_SOURCES skia/skia_window_x11.cpp + x11/event_queue.cpp x11/keys.cpp x11/x11.cpp) endif() diff --git a/src/she/skia/she.cpp b/src/she/skia/she.cpp index 37c5e91e0..a8a7482d8 100644 --- a/src/she/skia/she.cpp +++ b/src/she/skia/she.cpp @@ -1,5 +1,5 @@ // 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. // Read LICENSE.txt for more information. @@ -25,7 +25,7 @@ namespace she { System* create_system_impl() { - return new SkiaSystem(); + return new SkiaSystem; } void error_message(const char* msg) diff --git a/src/she/skia/skia_system.h b/src/she/skia/skia_system.h index cb6e07fd5..5e0007474 100644 --- a/src/she/skia/skia_system.h +++ b/src/she/skia/skia_system.h @@ -1,5 +1,5 @@ // 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. // Read LICENSE.txt for more information. @@ -25,7 +25,8 @@ #define SkiaSystemBase OSXSystem #else #include "she/x11/event_queue.h" - #define SkiaSystemBase CommonSystem + #include "she/x11/system.h" + #define SkiaSystemBase X11System #endif #include "SkGraphics.h" diff --git a/src/she/skia/skia_window_x11.cpp b/src/she/skia/skia_window_x11.cpp index 908e5b144..576241e2e 100644 --- a/src/she/skia/skia_window_x11.cpp +++ b/src/she/skia/skia_window_x11.cpp @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2016 David Capello +// Copyright (C) 2016-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -11,16 +11,18 @@ #include "she/skia/skia_window_x11.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 "SkBitmap.h" - - namespace she { SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display, int width, int height, int scale) : X11Window(X11::instance()->display(), width, height) + , m_queue(queue) + , m_display(display) , m_clientSize(width, height) , 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 { return m_scale; diff --git a/src/she/skia/skia_window_x11.h b/src/she/skia/skia_window_x11.h index 454b2f12c..c962632ba 100644 --- a/src/she/skia/skia_window_x11.h +++ b/src/she/skia/skia_window_x11.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2016 David Capello +// Copyright (C) 2016-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -20,7 +20,7 @@ namespace she { class EventQueue; class SkiaDisplay; -class SkiaWindow : public X11Window { +class SkiaWindow : public X11Window<SkiaWindow> { public: enum class Backend { NONE, GL }; @@ -28,6 +28,8 @@ public: int width, int height, int scale); ~SkiaWindow(); + void queueEventImpl(Event& ev); + int scale() const; void setScale(int scale); void setVisible(bool visible); @@ -51,6 +53,8 @@ public: private: void onExpose() override; + EventQueue* m_queue; + SkiaDisplay* m_display; gfx::Size m_clientSize; int m_scale; diff --git a/src/she/x11/event_queue.cpp b/src/she/x11/event_queue.cpp new file mode 100644 index 000000000..d67e7319b --- /dev/null +++ b/src/she/x11/event_queue.cpp @@ -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 diff --git a/src/she/x11/event_queue.h b/src/she/x11/event_queue.h index 850228ca3..5887bcb35 100644 --- a/src/she/x11/event_queue.h +++ b/src/she/x11/event_queue.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2016 David Capello +// Copyright (C) 2016-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -14,31 +14,18 @@ #include <queue> -#pragma push_macro("None") -#undef None // Undefine the X11 None macro - namespace she { class X11EventQueue : public EventQueue { public: - 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 getEvent(Event& ev, bool canWait) override; void queueEvent(const Event& ev) override { m_events.push(ev); } private: + void processX11Event(XEvent& event); + std::queue<Event> m_events; }; @@ -46,6 +33,4 @@ typedef X11EventQueue EventQueueImpl; } // namespace she -#pragma pop_macro("None") - #endif diff --git a/src/she/x11/window.h b/src/she/x11/window.h index e608fe15c..b5c530bff 100644 --- a/src/she/x11/window.h +++ b/src/she/x11/window.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2016 David Capello +// Copyright (C) 2016-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -16,6 +16,9 @@ namespace she { +class Event; + +template<typename T> class X11Window { public: X11Window(::Display* display, int width, int height) @@ -48,6 +51,10 @@ public: XDestroyWindow(m_display, m_window); } + void queueEvent(Event& ev) { + static_cast<T*>(this)->queueEventImpl(ev); + } + void setTitle(const std::string& title) { XTextProperty prop; prop.value = (unsigned char*)title.c_str();