Skip to content

Commit

Permalink
made WlPointer::focused_surface an optional instead of nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
William Wold committed Apr 27, 2018
1 parent fe79075 commit 41defcb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/server/frontend_wayland/wl_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mf::WlPointer::WlPointer(
mf::WlPointer::~WlPointer()
{
if (focused_surface)
focused_surface->remove_destroy_listener(this);
focused_surface.value()->remove_destroy_listener(this);
on_destroy(this);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ void mf::WlPointer::handle_event(MirPointerEvent const* event, WlSurface* surfac
mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
auto transformed = surface->transform_point(point);

if (transformed && transformed.value().second == focused_surface)
if (transformed && focused_surface && transformed.value().second == focused_surface.value())
{
if (!last_position || transformed.value().first != last_position.value())
{
Expand Down Expand Up @@ -208,24 +208,24 @@ void mf::WlPointer::handle_enter(Point position, WlSurface* surface)
surface->raw_resource(),
wl_fixed_from_double(position.x.as_int()),
wl_fixed_from_double(position.y.as_int()));
focused_surface = surface;
focused_surface->add_destroy_listener(this, [this]()
surface->add_destroy_listener(this, [this]()
{
handle_leave();
});
focused_surface = surface;
}

void mf::WlPointer::handle_leave()
{
if (!focused_surface)
return;
focused_surface->remove_destroy_listener(this);
focused_surface.value()->remove_destroy_listener(this);
auto const serial = wl_display_next_serial(display);
wl_pointer_send_leave(
resource,
serial,
focused_surface->raw_resource());
focused_surface = nullptr;
focused_surface.value()->raw_resource());
focused_surface = std::experimental::nullopt;
last_position = std::experimental::nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/frontend_wayland/wl_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WlPointer : public wayland::Pointer

MirPointerButtons last_buttons{0};
std::experimental::optional<mir::geometry::Point> last_position;
WlSurface* focused_surface = nullptr;
std::experimental::optional<WlSurface*> focused_surface;

void handle_enter(mir::geometry::Point position, WlSurface* surface);
void handle_leave();
Expand Down
2 changes: 1 addition & 1 deletion src/server/frontend_wayland/wl_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ std::experimental::optional<std::pair<geom::Point, mf::WlSurface*>> mf::WlSurfac
if (result)
return result;
}
for (auto& rect : input_shape.value_or(std::vector<geom::Rectangle>{{{}, buffer_size_}}))
for (auto& rect : input_shape.value_or(std::vector<geom::Rectangle>{{{}, buffer_size()}}))
{
if (rect.contains(point))
return std::make_pair(point, this);
Expand Down

0 comments on commit 41defcb

Please sign in to comment.