Skip to content

Commit

Permalink
Merge #964
Browse files Browse the repository at this point in the history
964: Add LayerShellV1::get_window() r=AlanGriffiths a=wmww

Tested using GDB, and appears to work. Fixes #963

Co-authored-by: William Wold <[email protected]>
  • Loading branch information
2 people authored and AlanGriffiths committed Aug 12, 2019
1 parent d014a1d commit 636fe4e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/server/frontend_wayland/layer_shell_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#include "wl_surface.h"
#include "window_wl_surface_role.h"
#include "xdg_shell_stable.h"
#include "wayland_utils.h"

#include "mir/shell/surface_specification.h"
#include "mir/frontend/session.h"
#include "mir/log.h"
#include <boost/throw_exception.hpp>
#include <deque>
#include <mutex>
Expand Down Expand Up @@ -89,6 +92,8 @@ class LayerSurfaceV1 : public wayland::LayerSurfaceV1, public WindowWlSurfaceRol

~LayerSurfaceV1() = default;

static auto from(wl_resource* surface) -> std::experimental::optional<LayerSurfaceV1*>;

private:
struct OptionalSize
{
Expand Down Expand Up @@ -158,6 +163,29 @@ mf::LayerShellV1::LayerShellV1(
{
}

auto mf::LayerShellV1::get_window(wl_resource* surface) -> std::shared_ptr<Surface>
{
namespace mw = mir::wayland;

if (mw::LayerSurfaceV1::is_instance(surface))
{
auto const layer_surface = LayerSurfaceV1::from(surface);
if (layer_surface)
{
auto const id = layer_surface.value()->surface_id();
if (id.as_value())
{
auto const session = get_session(static_cast<mw::LayerSurfaceV1*>(layer_surface.value())->client);
return session->get_surface(id);
}
}

log_debug("No window currently associated with wayland::LayerSurfaceV1 %p", surface);
}

return {};
}

void mf::LayerShellV1::bind(wl_resource* new_resource)
{
new Instance{new_resource, this};
Expand Down Expand Up @@ -202,6 +230,18 @@ mf::LayerSurfaceV1::LayerSurfaceV1(
apply_spec(spec);
}

auto mf::LayerSurfaceV1::from(wl_resource* surface) -> std::experimental::optional<LayerSurfaceV1*>
{
if (!mw::LayerSurfaceV1::is_instance(surface))
return std::experimental::nullopt;
auto const mw_surface = mw::LayerSurfaceV1::from(surface);
auto const mf_surface = dynamic_cast<mf::LayerSurfaceV1*>(mw_surface);
if (mf_surface)
return mf_surface;
else
return std::experimental::nullopt;
}

auto mf::LayerSurfaceV1::get_placement_gravity() const -> MirPlacementGravity
{
MirPlacementGravity edges = mir_placement_gravity_center;
Expand Down
2 changes: 2 additions & 0 deletions src/server/frontend_wayland/layer_shell_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ namespace frontend
{

class Shell;
class Surface;
class WlSeat;
class OutputManager;

class LayerShellV1 : public wayland::LayerShellV1::Global
{
public:
LayerShellV1(wl_display* display, std::shared_ptr<Shell> const shell, WlSeat& seat, OutputManager* output_manager);
static auto get_window(wl_resource* surface) -> std::shared_ptr<Surface>;

std::shared_ptr<Shell> const shell;
WlSeat& seat;
Expand Down
3 changes: 3 additions & 0 deletions src/server/frontend_wayland/wayland_default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,8 @@ auto mir::frontend::get_window(wl_resource* surface) -> std::shared_ptr<Surface>
if (auto result = XdgShellV6::get_window(surface))
return result;

if (auto result = LayerShellV1::get_window(surface))
return result;

return {};
}

0 comments on commit 636fe4e

Please sign in to comment.