mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-23 22:43:32 +00:00
Add a simple processing of the event queue on X11/Skia port
This commit is contained in:
parent
8b0c269b56
commit
706b9a84c6
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
46
src/she/x11/event_queue.cpp
Normal file
46
src/she/x11/event_queue.cpp
Normal 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
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user