Skip to content

Commit

Permalink
Modify mir_{pointer,touch}_event_axis_value to expose local x and y.
Browse files Browse the repository at this point in the history
Also, use these modifications to make `UserDecorationExample`'s input
handling work.
  • Loading branch information
tarek-y-ismail committed Nov 7, 2024
1 parent f2a8a4b commit d2ca284
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
29 changes: 15 additions & 14 deletions examples/miral-custom-decorations/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
*/


#include "mir/geometry/forward.h"
#include "mir_toolkit/events/enums.h"
#include "user_decoration_example.h"
#include "input.h"
#include "threadsafe_access.h"
#include "window.h"

#include <functional>
#include <mircommon/mir_toolkit/events/event.h>
#include "mircommon/mir_toolkit/cursors.h"
#include <mircommon/mir_toolkit/cursors.h>
#include <mircommon/mir_toolkit/events/input/pointer_event.h>

namespace geom = mir::geometry;

Expand Down Expand Up @@ -135,12 +138,12 @@ void InputManager::handle_input_event(std::shared_ptr<MirEvent const> const& eve
case mir_pointer_action_motion:
case mir_pointer_action_enter:
{
// TODO: figure out how to access local_position
/* if (auto const position = pointer_ev->local_position()) */
/* { */
/* bool pressed = mir_pointer_event_button_state(pointer_ev, mir_pointer_button_primary); */
/* pointer_event(event, geom::Point{position.value()}, pressed); */
/* } */
auto const position = geom::PointF{
mir_pointer_event_axis_value(pointer_ev, mir_pointer_axis_local_x),
mir_pointer_event_axis_value(pointer_ev, mir_pointer_axis_local_y)};

bool pressed = mir_pointer_event_button_state(pointer_ev, mir_pointer_button_primary);
pointer_event(event, geom::Point{position}, pressed);
}
break;
case mir_pointer_action_leave:
Expand All @@ -157,20 +160,18 @@ void InputManager::handle_input_event(std::shared_ptr<MirEvent const> const& eve
case mir_input_event_type_touch:
{
MirTouchEvent const* const touch_ev = mir_input_event_get_touch_event(input_ev);
for (unsigned int i = 0; i < mir_touch_event_point_count(touch_ev); i++)
for (size_t i = 0; i < mir_touch_event_point_count(touch_ev); i++)
{
auto const id = mir_touch_event_id(touch_ev, i);
switch (mir_touch_event_action(touch_ev, i))
{
case mir_touch_action_down:
case mir_touch_action_change:
{

// TODO: figure out how to access local_position
/* if (auto const position = touch_ev->local_position(i)) */
/* { */
/* touch_event(event, id, geom::Point{position.value()}); */
/* } */
auto const position = geom::PointF{
mir_touch_event_axis_value(touch_ev, i, mir_touch_axis_local_x),
mir_touch_event_axis_value(touch_ev, i, mir_touch_axis_local_y)};
touch_event(event, id, geom::Point{position});
}
break;
case mir_touch_action_up:
Expand Down
8 changes: 8 additions & 0 deletions include/core/mir_toolkit/events/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ typedef enum {
/* Axis representing the diameter of a circle centered on the touch
point */
mir_touch_axis_size = 5,
/* Axis representing the local x coordinate for the touch */
mir_touch_axis_local_x = 6,
/* Axis representing the local y coordinate for the touch */
mir_touch_axis_local_y = 7,

mir_touch_axes
} MirTouchAxis;
Expand Down Expand Up @@ -189,6 +193,10 @@ typedef enum {
/* Relative axis containing fractional values of 120 for high-res scrolling as reported by the horizontal scroll wheel */
/* When a discrete value is given (libinput < 1.19), value120 is determined by multiplying (discrete * 120) */
mir_pointer_axis_hscroll_value120 = 9,
/* Local axis containing the x coordinate of the pointer */
mir_pointer_axis_local_x = 10,
/* Local axis containing the y coordinate of the pointer */
mir_pointer_axis_local_y = 11,

mir_pointer_axes
} MirPointerAxis;
Expand Down
12 changes: 11 additions & 1 deletion src/common/input/input_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "mir/geometry/forward.h"
#include "mir_toolkit/events/enums.h"
#define MIR_LOG_COMPONENT "input-event-access"


Expand Down Expand Up @@ -234,6 +236,10 @@ float mir_touch_event_axis_value(MirTouchEvent const* event,
return std::max(
event->touch_major(touch_index),
event->touch_minor(touch_index));
case mir_touch_axis_local_x:
return event->local_position(touch_index).value_or(geom::PointF{}).x.as_value();
case mir_touch_axis_local_y:
return event->local_position(touch_index).value_or(geom::PointF{}).y.as_value();
default:
return -1;
}
Expand Down Expand Up @@ -308,6 +314,10 @@ float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis ax
return pev->v_scroll().value120.as_value();
case mir_pointer_axis_hscroll_value120:
return pev->h_scroll().value120.as_value();
case mir_pointer_axis_local_x:
return pev->local_position().value_or(geom::PointF{}).x.as_value();
case mir_pointer_axis_local_y:
return pev->local_position().value_or(geom::PointF{}).y.as_value();
default:
mir::fatal_error_abort("Invalid axis enumeration %d", axis);
}
Expand All @@ -333,4 +343,4 @@ bool mir_pointer_event_axis_stop(MirPointerEvent const* pev, MirPointerAxis axis
default:
mir::fatal_error_abort("Invalid axis enumeration %d", axis);
}
})
})

0 comments on commit d2ca284

Please sign in to comment.