Merge lp:~alan-griffiths/miral/fix-1699084 into lp:miral

Proposed by Alan Griffiths
Status: Merged
Approved by: Gerry Boland
Approved revision: no longer in the source branch.
Merged at revision: 564
Proposed branch: lp:~alan-griffiths/miral/fix-1699084
Merge into: lp:miral
Diff against target: 96 lines (+10/-22)
1 file modified
miral/xcursor_loader.cpp (+10/-22)
To merge this branch: bzr merge lp:~alan-griffiths/miral/fix-1699084
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+327709@code.launchpad.net

Commit message

Allow cursors that are not the default size (24x24) (LP: #1699084)

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:564
https://mir-jenkins.ubuntu.com/job/miral-ci/43/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-miral/65
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4951
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/4940
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/4940
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4940
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=artful/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=artful/69/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=xenial/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=xenial/69/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=zesty/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=amd64,release=zesty/69/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=artful/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=artful/69/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=xenial/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=xenial/69/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=zesty/69
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-miral/arch=i386,release=zesty/69/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/miral-ci/43/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

LGTM

review: Approve
lp:~alan-griffiths/miral/fix-1699084 updated
564. By Alan Griffiths

Allow cursors that are not the default size (24x24) (LP: #1699084). Fixes: https://bugs.launchpad.net/bugs/1699084.

Approved by Gerry Boland, mir-ci-bot.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'miral/xcursor_loader.cpp'
2--- miral/xcursor_loader.cpp 2016-09-28 10:38:36 +0000
3+++ miral/xcursor_loader.cpp 2017-07-19 12:04:50 +0000
4@@ -48,12 +48,6 @@
5 : image(image),
6 save_resource(save_resource)
7 {
8- if (image->width != mi::default_cursor_size.width.as_uint32_t() ||
9- image->height != mi::default_cursor_size.height.as_uint32_t())
10- {
11- BOOST_THROW_EXCEPTION(
12- std::runtime_error("Somehow we got a cursor not of the default size (currently only 24x24 supported)"));
13- }
14 }
15
16 ~XCursorImage()
17@@ -66,7 +60,7 @@
18 }
19 geom::Size size() const override
20 {
21- return mi::default_cursor_size;
22+ return {image->width, image->height};
23 }
24 geom::Displacement hotspot() const override
25 {
26@@ -161,39 +155,37 @@
27 // Each XcursorImages represents images for the different sizes of a given symbolic cursor.
28 void miral::XCursorLoader::load_appropriately_sized_image(_XcursorImages *images)
29 {
30- // We would rather take this lock in load_cursor_theme but the Xcursor lib style
31+ // We would rather take this lock in load_cursor_theme but the Xcursor lib style
32 // makes it difficult to use our standard 'pass the lg around to _locked members' pattern
33 std::lock_guard<std::mutex> lg(guard);
34
35 // We have to save all the images as XCursor expects us to free them.
36- // This contains the actual image data though, so we need to ensure they stay alive
37+ // This contains the actual image data though, so we need to ensure they stay alive
38 // with the lifetime of the mg::CursorImage instance which refers to them.
39 auto saved_xcursor_library_resource = std::shared_ptr<_XcursorImages>(images, [](_XcursorImages *images)
40 {
41 XcursorImagesDestroy(images);
42 });
43
44- _XcursorImage *image_of_correct_size = nullptr;
45 for (int i = 0; i < images->nimage; i++)
46 {
47 _XcursorImage *candidate = images->images[i];
48 if (candidate->width == mi::default_cursor_size.width.as_uint32_t() &&
49 candidate->height == mi::default_cursor_size.height.as_uint32_t())
50 {
51- image_of_correct_size = candidate;
52- break;
53+ loaded_images[std::string(images->name)] = std::make_shared<XCursorImage>(candidate, saved_xcursor_library_resource);
54+ return;
55 }
56 }
57- if (!image_of_correct_size)
58- return;
59- loaded_images[std::string(images->name)] = std::make_shared<XCursorImage>(image_of_correct_size, saved_xcursor_library_resource);
60+
61+ loaded_images[std::string(images->name)] = std::make_shared<XCursorImage>(images->images[0], saved_xcursor_library_resource);
62 }
63
64 void miral::XCursorLoader::load_cursor_theme(std::string const& theme_name)
65 {
66 // Cursors are named by their square dimension...called the nominal size in XCursor terminology, so we just look up by width.
67 // Later we verify the actual size.
68- xcursor_load_theme(theme_name.c_str(), mi::default_cursor_size.width.as_uint32_t(),
69+ xcursor_load_theme(theme_name.c_str(), mi::default_cursor_size.width.as_uint32_t(),
70 [](XcursorImages* images, void *this_ptr) -> void
71 {
72 // Can't use lambda capture as this lambda is thunked to a C function ptr
73@@ -204,14 +196,10 @@
74
75 std::shared_ptr<mg::CursorImage> miral::XCursorLoader::image(
76 std::string const& cursor_name,
77- geom::Size const& size)
78+ geom::Size const& /*size*/)
79 {
80 auto xcursor_name = xcursor_name_for_mir_cursor(cursor_name);
81
82- if (size != mi::default_cursor_size)
83- BOOST_THROW_EXCEPTION(
84- std::logic_error("Only the default cursor size is currently supported (mi::default_cursor_size)"));
85-
86 std::lock_guard<std::mutex> lg(guard);
87
88 auto it = loaded_images.find(xcursor_name);
89@@ -222,6 +210,6 @@
90 it = loaded_images.find("arrow");
91 if (it != loaded_images.end())
92 return it->second;
93-
94+
95 return nullptr;
96 }

Subscribers

People subscribed via source and target branches