-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
graphics/MultiplexingDisplay: Add HW cursor support. #3206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright © 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 2 or 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 "multiplexing_hw_cursor.h" | ||
|
||
#include "mir/graphics/display.h" | ||
#include <boost/throw_exception.hpp> | ||
|
||
namespace mg = mir::graphics; | ||
|
||
namespace | ||
{ | ||
auto construct_platform_cursors(std::span<mg::Display*> platform_displays) -> std::vector<std::shared_ptr<mg::Cursor>> | ||
{ | ||
std::vector<std::shared_ptr<mg::Cursor>> cursors; | ||
for (auto display : platform_displays) | ||
{ | ||
cursors.push_back(display->create_hardware_cursor()); | ||
if (cursors.back() == nullptr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
BOOST_THROW_EXCEPTION((std::runtime_error{"Platform failed to create hardware cursor"})); | ||
} | ||
Comment on lines
+31
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not a problem here, but thinking forward: this means that when adding a virtual display we offer different behaviour. (Obviously, fixing that would need something more complex than "hardware cursor" xor "software cursor") |
||
} | ||
return cursors; | ||
} | ||
} | ||
|
||
mg::MultiplexingCursor::MultiplexingCursor(std::span<Display*> platform_displays) | ||
: platform_cursors{construct_platform_cursors(platform_displays)} | ||
{ | ||
} | ||
|
||
void mg::MultiplexingCursor::show(CursorImage const& image) | ||
{ | ||
for (auto& cursor : platform_cursors) | ||
{ | ||
cursor->show(image); | ||
} | ||
} | ||
|
||
void mg::MultiplexingCursor::hide() | ||
{ | ||
for (auto& cursor: platform_cursors) | ||
{ | ||
cursor->hide(); | ||
} | ||
} | ||
|
||
void mg::MultiplexingCursor::move_to(geometry::Point position) | ||
{ | ||
for (auto& cursor : platform_cursors) | ||
{ | ||
cursor->move_to(position); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright © 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 2 or 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 <vector> | ||
#include <span> | ||
|
||
#include "mir/graphics/cursor.h" | ||
|
||
namespace mir::graphics | ||
{ | ||
class Display; | ||
|
||
class MultiplexingCursor : public Cursor | ||
{ | ||
public: | ||
explicit MultiplexingCursor(std::span<Display*> platform_displays); | ||
|
||
void show(CursorImage const& image) override; | ||
void hide() override; | ||
void move_to(geometry::Point position) override; | ||
|
||
private: | ||
std::vector<std::shared_ptr<Cursor>> const platform_cursors; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why, but I prefer default constructing a
shared_ptr<...>
(original code) to implicitly constructing it withnullptr
.