Skip to content

Commit

Permalink
Add a simple processing of the event queue on X11/Skia port
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Apr 19, 2017
1 parent 8b0c269 commit 706b9a8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/she/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/she/skia/she.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +25,7 @@
namespace she {

System* create_system_impl() {
return new SkiaSystem();
return new SkiaSystem;
}

void error_message(const char* msg)
Expand Down
5 changes: 3 additions & 2 deletions src/she/skia/skia_system.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions src/she/skia/skia_window_x11.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/she/skia/skia_window_x11.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,14 +20,16 @@ namespace she {
class EventQueue;
class SkiaDisplay;

class SkiaWindow : public X11Window {
class SkiaWindow : public X11Window<SkiaWindow> {
public:
enum class Backend { NONE, GL };

SkiaWindow(EventQueue* queue, SkiaDisplay* display,
int width, int height, int scale);
~SkiaWindow();

void queueEventImpl(Event& ev);

int scale() const;
void setScale(int scale);
void setVisible(bool visible);
Expand All @@ -51,6 +53,8 @@ class SkiaWindow : public X11Window {
private:
void onExpose() override;

EventQueue* m_queue;
SkiaDisplay* m_display;
gfx::Size m_clientSize;
int m_scale;

Expand Down
46 changes: 46 additions & 0 deletions src/she/x11/event_queue.cpp
Original file line number Diff line number Diff line change
@@ -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
23 changes: 4 additions & 19 deletions src/she/x11/event_queue.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,38 +14,23 @@

#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;
};

typedef X11EventQueue EventQueueImpl;

} // namespace she

#pragma pop_macro("None")

#endif
9 changes: 8 additions & 1 deletion src/she/x11/window.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,6 +16,9 @@

namespace she {

class Event;

template<typename T>
class X11Window {
public:
X11Window(::Display* display, int width, int height)
Expand Down Expand Up @@ -48,6 +51,10 @@ class X11Window {
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();
Expand Down

0 comments on commit 706b9a8

Please sign in to comment.