Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

adding a surface observer interface #8

Open
wants to merge 1 commit into
base: mir-1.9-miroil
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions include/miroil/miroil/surface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2021 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 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 warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MIROIL_SURFACE_H
#define MIROIL_SURFACE_H
#include <memory>
#include <unordered_map>
#include <mir_toolkit/mir_input_device_types.h>
#include <mir_toolkit/common.h>
#include <mir/graphics/renderable.h>

namespace mir {
namespace scene { class Surface; }
namespace shell { class InputTargeter; }
namespace geometry { struct Rectangle; }
namespace graphics { class CursorImage; }
namespace compositor { class BufferStream; }
}

namespace miroil {

class SurfaceObserver;
class SurfaceObserverImpl;

using CompositorID = void const*;

class Surface
{
public:
Surface(std::shared_ptr<mir::scene::Surface> wrapped);
~Surface() = default;

auto getWrapped() const -> mir::scene::Surface*;
void add_observer(std::shared_ptr<miroil::SurfaceObserver> const& observer);
void remove_observer(std::shared_ptr<miroil::SurfaceObserver> const& observer);

int buffers_ready_for_compositor(void const* compositor_id) const;
auto generate_renderables(miroil::CompositorID id) const -> mir::graphics::RenderableList;

bool is_confined_to_window();
void set_orientation(MirOrientation orientation);
void set_keymap(MirInputDeviceId id, std::string const& model, std::string const& layout,
std::string const& variant, std::string const& options);

void set_confine_pointer_state(MirPointerConfinementState state);
auto parent() const -> std::shared_ptr<mir::scene::Surface>;

/// Top-left corner (of the window frame if present)
mir::geometry::Point top_left() const;
bool visible() const;

// TODO a legacy of old interactions and needs removing
int configure(MirWindowAttrib attrib, int value);
// TODO a legacy of old interactions and needs removing
int query(MirWindowAttrib attrib) const;

private:
std::shared_ptr<mir::scene::Surface> wrapped;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be const?

std::unordered_map<std::shared_ptr<miroil::SurfaceObserver>, std::shared_ptr<miroil::SurfaceObserverImpl>> observers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't access to this be protected by (at least) a mutex?

It is probably best to copy the SurfaceObservers implementation (by using BasicObservers<> to achieve threadsafety.)

};

}

#endif
65 changes: 65 additions & 0 deletions include/miroil/miroil/surface_observer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright © 2021 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 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/>.
*/
#include <mir_toolkit/common.h>
#include <mir/geometry/size.h>
#include <mir/geometry/rectangle.h>
#include <mir/graphics/cursor_image.h>
#include <glm/glm.hpp>
#include <mir_toolkit/mir_input_device_types.h>
#include <vector>

namespace mir { namespace scene { class SurfaceObserver; } }
namespace mir { namespace scene { class Surface; } }
namespace mir { namespace input { enum class InputReceptionMode; } }

struct MirEvent;
struct MirInputEvent;

namespace miroil
{

class SurfaceObserver
{
public:
SurfaceObserver() = default;
SurfaceObserver(SurfaceObserver const&) = delete;
SurfaceObserver& operator=(SurfaceObserver const&) = delete;
virtual ~SurfaceObserver();

virtual void attrib_changed(mir::scene::Surface const* surf, MirWindowAttrib attrib, int value) = 0;
virtual void window_resized_to(mir::scene::Surface const* surf, mir::geometry::Size const& window_size) = 0;
virtual void content_resized_to(mir::scene::Surface const* surf, mir::geometry::Size const& content_size) = 0;
virtual void moved_to(mir::scene::Surface const* surf, mir::geometry::Point const& top_left) = 0;
virtual void hidden_set_to(mir::scene::Surface const* surf, bool hide) = 0;
virtual void frame_posted(mir::scene::Surface const* surf, int frames_available, mir::geometry::Size const& size) = 0;
virtual void alpha_set_to(mir::scene::Surface const* surf, float alpha) = 0;
virtual void orientation_set_to(mir::scene::Surface const* surf, MirOrientation orientation) = 0;
virtual void transformation_set_to(mir::scene::Surface const* surf, glm::mat4 const& t) = 0;
virtual void reception_mode_set_to(mir::scene::Surface const* surf, mir::input::InputReceptionMode mode) = 0;
virtual void cursor_image_set_to(mir::scene::Surface const* surf, mir::graphics::CursorImage const& image) = 0;
virtual void client_surface_close_requested(mir::scene::Surface const* surf) = 0;
virtual void keymap_changed(mir::scene::Surface const* surf, MirInputDeviceId id, std::string const& model,
std::string const& layout, std::string const& variant, std::string const& options) = 0;
virtual void renamed(mir::scene::Surface const* surf, char const* name) = 0;
virtual void cursor_image_removed(mir::scene::Surface const* surf) = 0;
virtual void placed_relative(mir::scene::Surface const* surf, mir::geometry::Rectangle const& placement) = 0;
virtual void input_consumed(mir::scene::Surface const* surf, MirEvent const* event) = 0;
virtual void start_drag_and_drop(mir::scene::Surface const* surf, std::vector<uint8_t> const& handle) = 0;
virtual void depth_layer_set_to(mir::scene::Surface const* surf, MirDepthLayer depth_layer) = 0;
virtual void application_id_set_to(mir::scene::Surface const* surf, std::string const& application_id) = 0;
};

}
2 changes: 2 additions & 0 deletions src/miroil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ add_library(miroil SHARED
prompt_session_listener.cpp ${miroil_include}/miroil/prompt_session_listener.h
prompt_session_manager.cpp ${miroil_include}/miroil/prompt_session_manager.h
set_compositor.cpp ${miroil_include}/miroil/set_compositor.h
surface.cpp ${miroil_include}/miroil/surface.h
surface_observer.cpp ${miroil_include}/miroil/surface_observer.h
${miroil_include}/miroil/display_configuration_storage.h
${miroil_include}/miroil/display_id.h
)
Expand Down
Loading