-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move decoration input resolution code to a shared class
InputResolver
Added `InputResolverAdapter` to expose a more stable(?) interface. It allows users to point to their implementation of `process_{enter,leave,up,down,motion, drag}`. Remove ununsed `DeviceEvent&` parameter from `process_{leave,up,down}`.
- Loading branch information
1 parent
4c33535
commit 977ef38
Showing
15 changed files
with
627 additions
and
480 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
include/miral/miral/decoration/decoration_input_resolver_adapter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright © Canonical Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 or 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MIRAL_DECORATION_DECORATION_INPUT_MANAGER_ADAPTER_H | ||
#define MIRAL_DECORATION_DECORATION_INPUT_MANAGER_ADAPTER_H | ||
|
||
#include "mir/shell/input_resolver.h" | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
namespace miral::decoration | ||
{ | ||
class InputResolverBuilder; | ||
class InputResolverAdapter : public mir::shell::decoration::InputResolver | ||
{ | ||
protected: | ||
void process_enter(DeviceEvent& device) override; | ||
void process_leave() override; | ||
void process_down() override; | ||
void process_up() override; | ||
void process_move(DeviceEvent& device) override; | ||
void process_drag(DeviceEvent& device) override; | ||
|
||
private: | ||
friend InputResolverBuilder; | ||
InputResolverAdapter(); | ||
|
||
std::function<void(DeviceEvent& device)> on_process_enter; | ||
std::function<void()> on_process_leave; | ||
std::function<void()> on_process_down; | ||
std::function<void()> on_process_up; | ||
std::function<void(DeviceEvent& device)> on_process_move; | ||
std::function<void(DeviceEvent& device)> on_process_drag; | ||
}; | ||
|
||
class InputResolverBuilder | ||
{ | ||
public: | ||
using DeviceEvent = mir::shell::decoration::InputResolver::DeviceEvent; | ||
static auto build( | ||
std::function<void(DeviceEvent& device)> on_process_enter, | ||
std::function<void()> on_process_leave, | ||
std::function<void()> on_process_down, | ||
std::function<void()> on_process_up, | ||
std::function<void(DeviceEvent& device)> on_process_move, | ||
std::function<void(DeviceEvent& device)> on_process_drag) -> InputResolverBuilder; | ||
|
||
auto done() -> std::unique_ptr<InputResolverAdapter>; | ||
|
||
private: | ||
InputResolverBuilder(); | ||
|
||
std::unique_ptr<InputResolverAdapter> adapter; | ||
}; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright © Canonical Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 or 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MIR_SHELL_DECORATION_INPUT_MANAGER_H_ | ||
#define MIR_SHELL_DECORATION_INPUT_MANAGER_H_ | ||
|
||
#include "mir/geometry/rectangle.h" | ||
#include "mir_toolkit/common.h" | ||
|
||
#include <memory> | ||
#include <mutex> | ||
#include <map> | ||
#include <optional> | ||
|
||
struct MirEvent; | ||
|
||
namespace mir | ||
{ | ||
namespace scene | ||
{ | ||
class Surface; | ||
} | ||
namespace input | ||
{ | ||
class CursorImages; | ||
} | ||
namespace shell | ||
{ | ||
class Shell; | ||
namespace decoration | ||
{ | ||
class Decoration; | ||
class WindowState; | ||
class BasicDecoration; | ||
class StaticGeometry; | ||
template<typename T> class ThreadsafeAccess; | ||
|
||
enum class ButtonState | ||
{ | ||
Up, ///< The user is not interacting with this button | ||
Hovered, ///< The user is hovering over this button | ||
Down, ///< The user is currently pressing this button | ||
}; | ||
|
||
// Given an input event, figures out which decoration callback should be | ||
// invoked to respond. | ||
class InputResolver | ||
{ | ||
public: | ||
|
||
/// Pointer or touchpoint | ||
struct DeviceEvent | ||
{ | ||
DeviceEvent(geometry::Point location, bool pressed) | ||
: location{location}, | ||
pressed{pressed} | ||
|
||
{ | ||
} | ||
|
||
geometry::Point location; | ||
bool pressed; | ||
}; | ||
|
||
virtual ~InputResolver() = default; | ||
void handle_input_event(std::shared_ptr<MirEvent const> const& event); | ||
auto latest_event() -> std::shared_ptr<MirEvent const> const; | ||
|
||
protected: | ||
// To be overriden by child classes. | ||
// Called into from {pointer,touch}_{event,leave} | ||
|
||
/// The input device has entered the surface | ||
virtual void process_enter(DeviceEvent& device) = 0; | ||
/// The input device has left the surface | ||
virtual void process_leave() = 0; | ||
/// The input device has clicked down | ||
/// A touch triggers a process_enter() followed by a process_down() | ||
virtual void process_down() = 0; | ||
/// The input device has released | ||
/// A touch release triggers a process_up() followed by a process_leave() | ||
virtual void process_up() = 0; | ||
/// The device has moved while up | ||
virtual void process_move(DeviceEvent& device) = 0; | ||
/// The device has moved while down | ||
virtual void process_drag(DeviceEvent& device) = 0; | ||
|
||
std::mutex mutex; | ||
private: | ||
void pointer_event(std::shared_ptr<MirEvent const> const& event, geometry::Point location, bool pressed); | ||
void pointer_leave(std::shared_ptr<MirEvent const> const& event); | ||
void touch_event(std::shared_ptr<MirEvent const> const& event, int32_t id, geometry::Point location); | ||
void touch_up(std::shared_ptr<MirEvent const> const& event, int32_t id); | ||
|
||
/// The most recent event, or the event currently being processed | ||
std::shared_ptr<MirEvent const> latest_event_; | ||
std::optional<DeviceEvent> pointer; | ||
std::map<int32_t, DeviceEvent> touches; | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.