2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef ANBOX_PLATFORM_SDL_PLATFORM_H_
19 #define ANBOX_PLATFORM_SDL_PLATFORM_H_
21 #include "anbox/platform/sdl/window.h"
22 #include "anbox/platform/sdl/sdl_wrapper.h"
23 #include "anbox/platform/base_platform.h"
24 #include "anbox/graphics/emugl/DisplayManager.h"
25 #include "anbox/input/device.h"
42 class Platform : public std::enable_shared_from_this<Platform>,
43 public platform::BasePlatform,
44 public Window::Observer {
46 Platform(const std::shared_ptr<input::Manager> &input_manager,
47 const Configuration &config);
50 std::shared_ptr<wm::Window> create_window(
51 const anbox::wm::Task::Id &task,
52 const anbox::graphics::Rect &frame,
53 const std::string &title) override;
55 void window_deleted(const Window::Id &id) override;
56 void window_wants_focus(const Window::Id &id) override;
57 void window_moved(const Window::Id &id, const std::int32_t &x,
58 const std::int32_t &y) override;
59 void window_resized(const Window::Id &id, const std::int32_t &width,
60 const std::int32_t &height) override;
62 void set_renderer(const std::shared_ptr<Renderer> &renderer) override;
63 void set_window_manager(const std::shared_ptr<wm::Manager> &window_manager) override;
65 void set_clipboard_data(const ClipboardData &data) override;
66 ClipboardData get_clipboard_data() override;
68 std::shared_ptr<audio::Sink> create_audio_sink() override;
69 std::shared_ptr<audio::Source> create_audio_source() override;
71 bool supports_multi_window() const override;
74 void process_events();
75 void process_input_event(const SDL_Event &event);
77 bool adjust_coordinates(std::int32_t &x, std::int32_t &y);
78 bool adjust_coordinates(SDL_Window *window, std::int32_t &x, std::int32_t &y);
79 bool calculate_touch_coordinates(const SDL_Event &event, std::int32_t &x,
82 static Window::Id next_window_id();
83 static constexpr std::uint32_t emulated_touch_id_ = 0;
85 std::shared_ptr<Renderer> renderer_;
86 std::shared_ptr<input::Manager> input_manager_;
87 std::shared_ptr<wm::Manager> window_manager_;
88 // We don't own the windows anymore after the got created by us so we
89 // need to be careful once we try to use them again.
90 std::map<Window::Id, std::weak_ptr<Window>> windows_;
91 std::shared_ptr<Window> current_window_;
92 std::thread event_thread_;
93 bool event_thread_running_;
94 std::shared_ptr<input::Device> pointer_;
95 std::shared_ptr<input::Device> keyboard_;
96 std::shared_ptr<input::Device> touch_;
97 graphics::Rect display_frame_;
98 bool window_size_immutable_ = false;
99 std::uint32_t focused_sdl_window_id_ = 0;
100 Configuration config_;
102 static const int MAX_FINGERS = 10;
103 static const int MAX_TRACKING_ID = 10;
104 int touch_slots[MAX_FINGERS];
107 int find_touch_slot(int id);
108 void push_slot(std::vector<input::Event> &touch_events, int slot);
109 void push_finger_down(int x, int y, int finger_id, std::vector<input::Event> &touch_events);
110 void push_finger_up(int finger_id, std::vector<input::Event> &touch_events);
111 void push_finger_motion(int x, int y, int finger_id, std::vector<input::Event> &touch_events);
114 } // namespace platform