TEST_F(InputEventBuilder, makes_valid_pointer_event)
{
    MirPointerAction action = mir_pointer_action_enter;
    auto depressed_buttons = mir_pointer_button_back | mir_pointer_button_tertiary;
    float x_axis_value = 3.9, y_axis_value = 7.4, hscroll_value = .9, vscroll_value = .3;
    auto const relative_x_value = 0.0;
    auto const relative_y_value = 0.0;
    auto ev = mev::make_event(device_id, timestamp, mac, modifiers, 
        action, depressed_buttons, x_axis_value, y_axis_value,
        hscroll_value, vscroll_value, relative_x_value, relative_y_value);
    auto e = ev.get();

    EXPECT_EQ(mir_event_type_input, mir_event_get_type(e));
    auto ie = mir_event_get_input_event(e);
    EXPECT_EQ(mir_input_event_type_pointer, mir_input_event_get_type(ie));
    auto pev = mir_input_event_get_pointer_event(ie);
    EXPECT_EQ(modifiers, mir_pointer_event_modifiers(pev));
    EXPECT_EQ(action, mir_pointer_event_action(pev));
    EXPECT_EQ(mac, mir_pointer_event_get_cookie(pev).mac);
    EXPECT_EQ(timestamp.count(), mir_pointer_event_get_cookie(pev).timestamp);
    EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_back));
    EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_tertiary));
    EXPECT_FALSE(mir_pointer_event_button_state(pev, mir_pointer_button_primary));
    EXPECT_FALSE(mir_pointer_event_button_state(pev, mir_pointer_button_secondary));
    EXPECT_FALSE(mir_pointer_event_button_state(pev, mir_pointer_button_forward));
    EXPECT_EQ(x_axis_value, mir_pointer_event_axis_value(pev, mir_pointer_axis_x));
    EXPECT_EQ(y_axis_value, mir_pointer_event_axis_value(pev, mir_pointer_axis_y));
    EXPECT_EQ(hscroll_value, mir_pointer_event_axis_value(pev, mir_pointer_axis_hscroll));
    EXPECT_EQ(vscroll_value, mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll));
}
示例#2
0
static guint
get_button_state (const MirPointerEvent *event)
{
  guint state = 0;

  if (mir_pointer_event_button_state (event, mir_pointer_button_primary)) /* left */
    state |= GDK_BUTTON1_MASK;
  if (mir_pointer_event_button_state (event, mir_pointer_button_secondary)) /* right */
    state |= GDK_BUTTON3_MASK;
  if (mir_pointer_event_button_state (event, mir_pointer_button_tertiary)) /* middle */
    state |= GDK_BUTTON2_MASK;

  return state;
}
示例#3
0
void
_gdk_mir_print_motion_event (const MirInputEvent *event)
{
  const MirPointerEvent *pointer_event = mir_input_event_get_pointer_event (event);

  if (!pointer_event)
    return;

  g_printerr ("MOTION\n");
  g_printerr (" Device %lld\n", (long long int) mir_input_event_get_device_id (event));
  g_printerr (" Action ");
  switch (mir_pointer_event_action (pointer_event))
    {
    case mir_pointer_action_button_down:
      g_printerr ("down");
      break;
    case mir_pointer_action_button_up:
      g_printerr ("up");
      break;
    case mir_pointer_action_enter:
      g_printerr ("enter");
      break;
    case mir_pointer_action_leave:
      g_printerr ("leave");
      break;
    case mir_pointer_action_motion:
      g_printerr ("motion");
      break;
    default:
      g_printerr ("%u", mir_pointer_event_action (pointer_event));
    }
  g_printerr ("\n");
  _gdk_mir_print_modifiers (mir_pointer_event_modifiers (pointer_event));
  g_printerr (" Button State");
  if (mir_pointer_event_button_state (pointer_event, mir_pointer_button_primary))
    g_printerr (" primary");
  if (mir_pointer_event_button_state (pointer_event, mir_pointer_button_secondary))
    g_printerr (" secondary");
  if (mir_pointer_event_button_state (pointer_event, mir_pointer_button_tertiary))
    g_printerr (" tertiary");
  if (mir_pointer_event_button_state (pointer_event, mir_pointer_button_back))
    g_printerr (" back");
  if (mir_pointer_event_button_state (pointer_event, mir_pointer_button_forward))
    g_printerr (" forward");
  g_printerr ("\n");
  g_printerr (" Offset (%f, %f)\n", mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_x),
                                    mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_y));
  g_printerr (" Event Time %lli\n", (long long int) mir_input_event_get_event_time (event));
}
示例#4
0
static guint
mir_pointer_event_get_button_state (const MirPointerEvent *event)
{
  guint button_state = 0;

  if (mir_pointer_event_button_state (event, mir_pointer_button_primary))
    button_state |= mir_pointer_button_primary;
  if (mir_pointer_event_button_state (event, mir_pointer_button_secondary))
    button_state |= mir_pointer_button_secondary;
  if (mir_pointer_event_button_state (event, mir_pointer_button_tertiary))
    button_state |= mir_pointer_button_tertiary;
  if (mir_pointer_event_button_state (event, mir_pointer_button_back))
    button_state |= mir_pointer_button_back;
  if (mir_pointer_event_button_state (event, mir_pointer_button_forward))
    button_state |= mir_pointer_button_forward;

  return button_state;
}
示例#5
0
bool me::WindowManager::handle_pointer_event(MirPointerEvent const* pev)
{
    bool handled = false;

    geometry::Point cursor{mir_pointer_event_axis_value(pev, mir_pointer_axis_x),
                           mir_pointer_event_axis_value(pev, mir_pointer_axis_y)};
    auto action = mir_pointer_event_action(pev);
    auto modifiers = mir_pointer_event_modifiers(pev);
    auto vscroll = mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll);
    auto primary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_primary);
    auto tertiary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_tertiary);

    float new_zoom_mag = 0.0f;  // zero means unchanged

   if (modifiers & mir_input_event_modifier_meta &&
       action == mir_pointer_action_motion)
   {
        zoom_exponent += vscroll;

        // Negative exponents do work too, but disable them until
        // there's a clear edge to the desktop.
        if (zoom_exponent < 0)
            zoom_exponent = 0;
    
        new_zoom_mag = powf(1.2f, zoom_exponent);
        handled = true;
    }

    me::DemoCompositor::for_each(
        [new_zoom_mag,&cursor](me::DemoCompositor& c)
        {
            if (new_zoom_mag > 0.0f)
                c.zoom(new_zoom_mag);
            c.on_cursor_movement(cursor);
        });

    if (zoom_exponent || new_zoom_mag)
        force_redraw();

    auto const surf = focus_controller->focused_surface();
    if (surf &&
        (modifiers & mir_input_event_modifier_alt) && (primary_button_pressed || tertiary_button_pressed))
    {
        // Start of a gesture: When the latest finger/button goes down
        if (action == mir_pointer_action_button_down)
        {
            click = cursor;
            save_edges(*surf, click);
            handled = true;
        }
        else if (action == mir_pointer_action_motion)
        {
            geometry::Displacement drag = cursor - old_cursor;

            if (tertiary_button_pressed)
            {  // Resize by mouse middle button
                resize(*surf, cursor);
            }
            else
            {
                surf->move_to(old_pos + drag);
            }

            handled = true;
        }

        old_pos = surf->top_left();
        old_size = surf->size();
    }

    if (surf && 
        (modifiers & mir_input_event_modifier_alt) &&
        action == mir_pointer_action_motion &&
        vscroll)
    {
        float alpha = surf->alpha();
        alpha += 0.1f * vscroll;
        if (alpha < 0.0f)
            alpha = 0.0f;
        else if (alpha > 1.0f)
            alpha = 1.0f;
        surf->set_alpha(alpha);
        handled = true;
    }

    old_cursor = cursor;
    return handled;
}