Mir

Merge lp:~mir-team/mir/allow-lock-surf-orientation into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Merged at revision: 2127
Proposed branch: lp:~mir-team/mir/allow-lock-surf-orientation
Merge into: lp:mir
Diff against target: 326 lines (+140/-7)
14 files modified
client-ABI-sha1sums (+2/-2)
common-ABI-sha1sums (+1/-1)
include/client/mir_toolkit/mir_surface.h (+17/-0)
include/common/mir_toolkit/common.h (+15/-0)
platform-ABI-sha1sums (+1/-1)
server-ABI-sha1sums (+1/-1)
src/client/mir_surface.cpp (+7/-0)
src/client/mir_surface.h (+2/-1)
src/client/mir_surface_api.cpp (+33/-0)
src/server/scene/basic_surface.cpp (+23/-0)
src/server/scene/basic_surface.h (+2/-0)
tests/acceptance-tests/test_client_surface_events.cpp (+16/-0)
tests/unit-tests/client/test_client_mir_surface.cpp (+2/-1)
tests/unit-tests/scene/test_surface_impl.cpp (+18/-0)
To merge this branch: bzr merge lp:~mir-team/mir/allow-lock-surf-orientation
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Gerry Boland (community) Approve
Kevin DuBois (community) Approve
Alexandros Frantzis (community) Approve
Robert Carr (community) Approve
Andreas Pokorny (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+242984@code.launchpad.net

Commit message

Add client API to set the preferred orientation of a surface.

Description of the change

This is now basically a big setter/getter MP.

The shell can reject the preference request through SurfaceConfigurator->select_attribute_value.

Mir does not do anything with this value currently. It's up to each shell implementation to deal with device orientation changes; such implementations may query the preferred orientation for each surface and decide to ignore or honour the preference, calling surface->set_orientation(...) accordingly.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

lgtm

review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Too bad MirOrientation values are not bit flags. Would it be preferable to change the MirOrientation values instead of introducing a new enum?

Needs discussion

review: Needs Information
Revision history for this message
Gerry Boland (gerboland) wrote :

I think it should be up to the shell to decide whether to honour an client orientation restrictions. There are many cases in our converged world where the client's request cannot be honoured - one example is tablet in landscape, so it has a landscape main stage application open, and a sidestage app. If that sidestage app wants to be landscape too - shell cannot let it, it must remain portrait.

I'm a little worried about adding this feature to the mir client API if it's not something we were planning to support as a platform. E.g. we're adding orientation support to shell where it sets the preferred orientations in the desktop file, and these cannot be altered at runtime - design and the UITK guys were happy enough with this.

Sure I can see advantages to runtime alterations, but could we check with design & uitk to see if they really want this?

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I think that we ought to either change the MirOrientation values to bitflags or abstract out the necessary conversions.

*Needs Discussion*

I agree with Gerry that setting the "allowed orientations" is a request, not a requirement and that the shell could refuse.

I also wonder if this is something that should be set on the surface spec and applied at creation (or mutation) time rather than being an attribute on the surface that can be set at arbitrary times.

review: Needs Information
Revision history for this message
Gerry Boland (gerboland) wrote :

I'm just out of a meeting with UITK folk, and they could find use-cases to justify runtime changing of preferred orientations. A Netflix would be a big user of this feature - on phone list of video would ideally be in portrait, but playback would be best in landscape. So yeah this is good.

Still needs to be a request shell can deny if necessary though.

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

I introduced the new enum to avoid breaking client ABI. If the team is ok breaking ABI for this, then no problem changing it.

The shell/server is given a change to reject the setting with SurfaceConfigurator->select_attribute_value, just return the appropriate value for the mir_surface_attrib_permitted_orientations attribute.

Revision history for this message
Robert Carr (robertcarr) wrote :

As discussed in the stand-up I think I am ok with breaking ABI.

If we don't break ABI, maybe lets think of a better name? I think "permit" misphrases the balance
of power here, rather the client declares it's "Supported" orientations.

Diff looks fine though and name is reasonable enough so +1 if you end up deciding to land it this way.

Nit:

40 + * set the orientations a surface is allowed to change into.
41 + * The server may reject the request so you may have to wait on the function
42 + * and check the result using mir_surface_get_permitted_orientations.

This reads weird imo, I think the object is unclear and the first sentence, and the second one becomes run on due to repetition of a clause

"Request to set the orientations which a surface supports. This request may be rejected by the server, so it is necessary to wait on the result and check the applied value using mir_surface_get_permitted_orientations"

Rest of diff looks fine

review: Approve
Revision history for this message
Chris Halse Rogers (raof) wrote :

+1 for mir_surface_{get,set}_supported_orientations.

Nit:
178 +MirPermittedOrientations mir_surface_get_permitted_orientations(MirSurface *surf)
...
184 + if (surf)
185 + {

Incorrect precondition check. If you're going to do a precondition check it should be mir_surface_is_valid(surf), and it should abort() if the precondition fails.

Revision history for this message
Chris Halse Rogers (raof) wrote :

Also - what is the expectation if you call mir_surface_set_supported_orientations() and don't include the *current* orientation in the set of supported orientations?

It's technically possible to change MirOrientation to a bitfield without changing ABI by the magic of symbol versioning - since mir_surface_get_orientation is the only client-visible user of MirOrientation you'd just need to provide a translation shim for that one function.

I guess I'm suggesting that MirPermittedOrientations shouldn't exist :)

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Do we have the right "orientation" here?

I would guess (with insufficient data) that most apps that restrict supported orientations care more about landscape/portrait than they do about the angle from the "natural" display orientation. Forcing them to discover screen metrics before requesting orientation restrictions seems perverse.

Revision history for this message
Gerry Boland (gerboland) wrote :

> Also - what is the expectation if you call
> mir_surface_set_supported_orientations() and don't include the *current*
> orientation in the set of supported orientations?

That's the apps way to ask for shell to change orientation to suit it. Usecase: youtube app, list of videos portrait, but playing video should be landscape. So app would change its preferred orientations from [portrait] to [landscape].

Of course shell may not respect that immediately (e.g. user interacting with Indicators at the time), or at all (tablet side stage)

> It's technically possible to change MirOrientation to a bitfield without
> changing ABI by the magic of symbol versioning - since
> mir_surface_get_orientation is the only client-visible user of MirOrientation
> you'd just need to provide a translation shim for that one function.
>
> I guess I'm suggesting that MirPermittedOrientations shouldn't exist :)

/me didn't follow

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> Also - what is the expectation if you call
> mir_surface_set_supported_orientations() and don't include the *current*
> orientation in the set of supported orientations?
>
> It's technically possible to change MirOrientation to a bitfield without
> changing ABI by the magic of symbol versioning - since
> mir_surface_get_orientation is the only client-visible user of MirOrientation
> you'd just need to provide a translation shim for that one function.

One also needs to translate the orientation values for the event handler during orientation events.

>
> I guess I'm suggesting that MirPermittedOrientations shouldn't exist :)

Right the options were break the ABI and change the existing MirOrientation enum, introduce a new enum and avoid symbol magic or use symbol magic and maintain backwards compatibility.

I've done the latter locally (symbol magic) but the results in oddness in testing and because of the event handler, MirSurface then needs to know whether to translate the values or not depending on the client symbol version that setup the handler.

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> Do we have the right "orientation" here?
>
> I would guess (with insufficient data) that most apps that restrict supported
> orientations care more about landscape/portrait than they do about the angle
> from the "natural" display orientation. Forcing them to discover screen
> metrics before requesting orientation restrictions seems perverse.

One use case I was thinking about was a client may want to keep a surface in a specific orientation relative to a sensor location - say for example a flute app that requires you to blow into the mic, but perhaps if an application already has a list of sensor locations per phone model, then they should know the "natural" orientation of the screen - so portrait/landscape make sense.

So perhaps they SHOULD be separate - leave MirOrientation as is and introduce:

MirOrientationMode
{
    mir_orientation_mode_portrait = 1 << 1,
    mir_orientation_mode_landscape = 1 << 2,
    mir_orientation_mode_inverted_portrait = 1 << 3,
    mir_orientation_mode_inverted_landscape = 1 << 4,
    mir_orientation_mode_portrait_any = mir_orientation_mode_portrait | mir_orientation_mode_inverted_portrait,
    mir_orientation_mode_landscape_any = mir_orientation_mode_landscape | mir_orientation_mode_inverted_landscape,
    mir_orientation_mode_any = mir_orientation_mode_portrait_any | mir_orientation_mode_landscape_any
}

MirWaitHandle* mir_surface_set_preferred_orientation(MirSurface *surface, MirOrientationMode orientation_mode)

MirOrientationMode mir_surface_get_preferred_orientation(MirSurface *surface)

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Awaiting final version for review. For now I have the following nits :

It'd make sense to base this MP on ~vanvugt/mir/named-attrib-values
---------------------------
82 + mir_permitted_orientation_all = mir_permitted_orientation_normal |
83 + mir_permitted_orientation_left |
84 + mir_permitted_orientation_right |
85 + mir_permitted_orientation_inverted,
Would make more sense if mir_permitted_orientation_all were at the end.
---------------------------
180 + MirPermittedOrientations perm_orientations = mir_permitted_orientation_all;
Would it not make more sense to restrict the client to something like mir_permitted_orientation_normal if this function were to throw?

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> +1 for mir_surface_{get,set}_supported_orientations.
>
> Nit:
> 178 +MirPermittedOrientations
> mir_surface_get_permitted_orientations(MirSurface *surf)
> ...
> 184 + if (surf)
> 185 + {
>
> Incorrect precondition check. If you're going to do a precondition check it
> should be mir_surface_is_valid(surf), and it should abort() if the
> precondition fails.

OK, I guess we ought to fix all the other function preconditions checks as well as this was copy/pasta.

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

67 + MirOrientationMode mode = mir_orientation_mode_any;

I'd slightly prefer we had a mir_orientation_mode_unknown value and return that on error. Having said that, if surf->attrib() throws then something is very wrong, and it probably won't matter that we may have misinformed the client.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Trunk has changed

<<<<<<< TREE
=======
void ms::BasicSurface::initialize_attributes()
{
    std::lock_guard<std::mutex> lg(guard);

    attrib_values[mir_surface_attrib_type] = mir_surface_type_normal;
    attrib_values[mir_surface_attrib_state] = mir_surface_state_restored;
    attrib_values[mir_surface_attrib_swapinterval] = 1;
    attrib_values[mir_surface_attrib_focus] = mir_surface_unfocused;
    attrib_values[mir_surface_attrib_dpi] = 0;
    attrib_values[mir_surface_attrib_visibility] = mir_surface_visibility_exposed;
    attrib_values[mir_surface_attrib_preferred_orientation] = mir_orientation_mode_any;
}

>>>>>>> MERGE-SOURCE

review: Needs Fixing
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm, apart from the needed update.

review: Approve
Revision history for this message
Gerry Boland (gerboland) :
review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve
Revision history for this message
Laurie Bradshaw (lauriebradshaw) wrote :

I've been trying to integrate with the system rotation instead of doing it myself for neverball, neverputt and tuxracer.

mir_surface_set_preferred_orientation doesn't seem to do anything on my bq aquaris, with or without X-Ubuntu-Supported-Orientations in the desktop file, is this due to missing shell support?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client-ABI-sha1sums'
--- client-ABI-sha1sums 2014-12-05 03:26:03 +0000
+++ client-ABI-sha1sums 2014-12-05 22:17:20 +0000
@@ -5,11 +5,11 @@
51ef8f51a3e3f8d1559266c5af58fbfde7cfabf0a include/client/mir_toolkit/mir_cursor_configuration.h51ef8f51a3e3f8d1559266c5af58fbfde7cfabf0a include/client/mir_toolkit/mir_cursor_configuration.h
69d50df5a141ca03ee8a79f7e844ed4b8b3b7d5d3 include/client/mir_toolkit/mir_prompt_session.h69d50df5a141ca03ee8a79f7e844ed4b8b3b7d5d3 include/client/mir_toolkit/mir_prompt_session.h
721d07e655e85eeec8a3523e1c6f9c2252176ec01 include/client/mir_toolkit/mir_screencast.h721d07e655e85eeec8a3523e1c6f9c2252176ec01 include/client/mir_toolkit/mir_screencast.h
8b9a11709737d6178c4bf30d067922ca823957045 include/client/mir_toolkit/mir_surface.h842bcad3a72b47f4d904e6b7033b0001b89cb9779 include/client/mir_toolkit/mir_surface.h
9b141c4d79802ad626d969249c0004744e5c2a525 include/client/mir_toolkit/mir_wait.h9b141c4d79802ad626d969249c0004744e5c2a525 include/client/mir_toolkit/mir_wait.h
10c367f5c9285936820fbd50961827d6ce58fb7ff4 include/client/mir_toolkit/version.h10c367f5c9285936820fbd50961827d6ce58fb7ff4 include/client/mir_toolkit/version.h
111863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h111863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h
122100c0674d9d882c1845550847357f6a5de5af66 include/common/mir_toolkit/common.h123e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
13fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h13fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
14bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h14bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h
154975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h154975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h
1616
=== modified file 'common-ABI-sha1sums'
--- common-ABI-sha1sums 2014-12-05 03:26:03 +0000
+++ common-ABI-sha1sums 2014-12-05 22:17:20 +0000
@@ -15,7 +15,7 @@
152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h
169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h
182100c0674d9d882c1845550847357f6a5de5af66 include/common/mir_toolkit/common.h183e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h
214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h
2222
=== modified file 'include/client/mir_toolkit/mir_surface.h'
--- include/client/mir_toolkit/mir_surface.h 2014-12-05 03:26:03 +0000
+++ include/client/mir_toolkit/mir_surface.h 2014-12-05 22:17:20 +0000
@@ -408,6 +408,23 @@
408 */408 */
409MirOrientation mir_surface_get_orientation(MirSurface *surface);409MirOrientation mir_surface_get_orientation(MirSurface *surface);
410410
411/**
412 * Request to set the preferred orientations of a surface.
413 * The request may be rejected by the server; to check wait on the
414 * result and check the applied value using mir_surface_get_preferred_orientation
415 * \param [in] surface The surface to operate on
416 * \param [in] orientation The preferred orientation modes
417 * \return A wait handle that can be passed to mir_wait_for
418 */
419MirWaitHandle* mir_surface_set_preferred_orientation(MirSurface *surface, MirOrientationMode orientation);
420
421/**
422 * Get the preferred orientation modes of a surface.
423 * \param [in] surface The surface to query
424 * \return The preferred orientation modes
425 */
426MirOrientationMode mir_surface_get_preferred_orientation(MirSurface *surface);
427
411#ifdef __cplusplus428#ifdef __cplusplus
412}429}
413/**@}*/430/**@}*/
414431
=== modified file 'include/common/mir_toolkit/common.h'
--- include/common/mir_toolkit/common.h 2014-12-05 03:26:03 +0000
+++ include/common/mir_toolkit/common.h 2014-12-05 22:17:20 +0000
@@ -42,6 +42,7 @@
42 mir_surface_attrib_focus,42 mir_surface_attrib_focus,
43 mir_surface_attrib_dpi,43 mir_surface_attrib_dpi,
44 mir_surface_attrib_visibility,44 mir_surface_attrib_visibility,
45 mir_surface_attrib_preferred_orientation,
45 /* Must be last */46 /* Must be last */
46 mir_surface_attribs47 mir_surface_attribs
47} MirSurfaceAttrib;48} MirSurfaceAttrib;
@@ -143,6 +144,20 @@
143 mir_orientation_right = 270144 mir_orientation_right = 270
144} MirOrientation;145} MirOrientation;
145146
147typedef enum MirOrientationMode
148{
149 mir_orientation_mode_portrait = 1 << 0,
150 mir_orientation_mode_landscape = 1 << 1,
151 mir_orientation_mode_portrait_inverted = 1 << 2,
152 mir_orientation_mode_landscape_inverted = 1 << 3,
153 mir_orientation_mode_portrait_any = mir_orientation_mode_portrait |
154 mir_orientation_mode_portrait_inverted,
155 mir_orientation_mode_landscape_any = mir_orientation_mode_landscape |
156 mir_orientation_mode_landscape_inverted,
157 mir_orientation_mode_any = mir_orientation_mode_portrait_any |
158 mir_orientation_mode_landscape_any
159} MirOrientationMode;
160
146/**@}*/161/**@}*/
147162
148#endif163#endif
149164
=== modified file 'platform-ABI-sha1sums'
--- platform-ABI-sha1sums 2014-12-05 03:26:03 +0000
+++ platform-ABI-sha1sums 2014-12-05 22:17:20 +0000
@@ -15,7 +15,7 @@
152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h
169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h
182100c0674d9d882c1845550847357f6a5de5af66 include/common/mir_toolkit/common.h183e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h
214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h
2222
=== modified file 'server-ABI-sha1sums'
--- server-ABI-sha1sums 2014-12-05 03:26:03 +0000
+++ server-ABI-sha1sums 2014-12-05 22:17:20 +0000
@@ -15,7 +15,7 @@
152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h152fd7274766a92f22e8784cb64af91947ba03d0de include/common/mir/logging/logger.h
169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h169ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h171863a7fe3a382061f2752c0236cc971e7e68f93f include/common/mir_toolkit/client_types.h
182100c0674d9d882c1845550847357f6a5de5af66 include/common/mir_toolkit/common.h183e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h19fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h20bccde9cdbc2f0d07e186c2950ef88d3a7d5f0d3b include/common/mir_toolkit/event.h
214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h214975998aa1056ed0d39dcc538127453e516ad8e9 include/common/mir_toolkit/mesa/native_display.h
2222
=== modified file 'src/client/mir_surface.cpp'
--- src/client/mir_surface.cpp 2014-12-05 03:26:03 +0000
+++ src/client/mir_surface.cpp 2014-12-05 22:17:20 +0000
@@ -501,6 +501,7 @@
501 case mir_surface_attrib_focus:501 case mir_surface_attrib_focus:
502 case mir_surface_attrib_swapinterval:502 case mir_surface_attrib_swapinterval:
503 case mir_surface_attrib_dpi:503 case mir_surface_attrib_dpi:
504 case mir_surface_attrib_preferred_orientation:
504 if (configure_result.has_ivalue())505 if (configure_result.has_ivalue())
505 attrib_cache[a] = configure_result.ivalue();506 attrib_cache[a] = configure_result.ivalue();
506 else507 else
@@ -607,3 +608,9 @@
607608
608 return orientation;609 return orientation;
609}610}
611
612MirWaitHandle* MirSurface::set_preferred_orientation(MirOrientationMode mode)
613{
614 return configure(mir_surface_attrib_preferred_orientation, mode);
615}
616
610617
=== modified file 'src/client/mir_surface.h'
--- src/client/mir_surface.h 2014-12-05 03:26:03 +0000
+++ src/client/mir_surface.h 2014-12-05 22:17:20 +0000
@@ -121,7 +121,8 @@
121 int attrib(MirSurfaceAttrib a) const;121 int attrib(MirSurfaceAttrib a) const;
122122
123 MirOrientation get_orientation() const;123 MirOrientation get_orientation() const;
124 124 MirWaitHandle* set_preferred_orientation(MirOrientationMode mode);
125
125 MirWaitHandle* configure_cursor(MirCursorConfiguration const* cursor);126 MirWaitHandle* configure_cursor(MirCursorConfiguration const* cursor);
126127
127 void set_event_handler(MirEventDelegate const* delegate);128 void set_event_handler(MirEventDelegate const* delegate);
128129
=== modified file 'src/client/mir_surface_api.cpp'
--- src/client/mir_surface_api.cpp 2014-12-05 03:26:03 +0000
+++ src/client/mir_surface_api.cpp 2014-12-05 22:17:20 +0000
@@ -435,3 +435,36 @@
435435
436 return result;436 return result;
437}437}
438
439MirOrientationMode mir_surface_get_preferred_orientation(MirSurface *surf)
440{
441 if (!mir_surface_is_valid(surf)) abort();
442
443 MirOrientationMode mode = mir_orientation_mode_any;
444
445 try
446 {
447 mode = static_cast<MirOrientationMode>(surf->attrib(mir_surface_attrib_preferred_orientation));
448 }
449 catch (...)
450 {
451 }
452
453 return mode;
454}
455
456MirWaitHandle* mir_surface_set_preferred_orientation(MirSurface *surf, MirOrientationMode mode)
457{
458 if (!mir_surface_is_valid(surf)) abort();
459
460 MirWaitHandle *result{nullptr};
461 try
462 {
463 result = surf->set_preferred_orientation(mode);
464 }
465 catch (...)
466 {
467 }
468
469 return result;
470}
438471
=== modified file 'src/server/scene/basic_surface.cpp'
--- src/server/scene/basic_surface.cpp 2014-12-05 03:26:03 +0000
+++ src/server/scene/basic_surface.cpp 2014-12-05 22:17:20 +0000
@@ -465,6 +465,25 @@
465 return new_state;465 return new_state;
466}466}
467467
468MirOrientationMode ms::BasicSurface::set_preferred_orientation(MirOrientationMode new_orientation_mode)
469{
470 if ((new_orientation_mode & mir_orientation_mode_any) == 0)
471 {
472 BOOST_THROW_EXCEPTION(std::logic_error("Invalid orientation mode"));
473 }
474
475 std::unique_lock<std::mutex> lg(guard);
476 if (pref_orientation_mode != new_orientation_mode)
477 {
478 pref_orientation_mode = new_orientation_mode;
479 lg.unlock();
480
481 observers.attrib_changed(mir_surface_attrib_preferred_orientation, new_orientation_mode);
482 }
483
484 return new_orientation_mode;
485}
486
468void ms::BasicSurface::take_input_focus(std::shared_ptr<msh::InputTargeter> const& targeter)487void ms::BasicSurface::take_input_focus(std::shared_ptr<msh::InputTargeter> const& targeter)
469{488{
470 targeter->focus_changed(input_channel());489 targeter->focus_changed(input_channel());
@@ -493,6 +512,9 @@
493 case mir_surface_attrib_visibility:512 case mir_surface_attrib_visibility:
494 result = set_visibility(static_cast<MirSurfaceVisibility>(result));513 result = set_visibility(static_cast<MirSurfaceVisibility>(result));
495 break;514 break;
515 case mir_surface_attrib_preferred_orientation:
516 result = set_preferred_orientation(static_cast<MirOrientationMode>(result));
517 break;
496 default:518 default:
497 BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface "519 BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface "
498 "attribute."));520 "attribute."));
@@ -515,6 +537,7 @@
515 case mir_surface_attrib_focus: return focus_;537 case mir_surface_attrib_focus: return focus_;
516 case mir_surface_attrib_dpi: return dpi_;538 case mir_surface_attrib_dpi: return dpi_;
517 case mir_surface_attrib_visibility: return visibility_;539 case mir_surface_attrib_visibility: return visibility_;
540 case mir_surface_attrib_preferred_orientation: return pref_orientation_mode;
518 default: BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface "541 default: BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface "
519 "attribute."));542 "attribute."));
520 }543 }
521544
=== modified file 'src/server/scene/basic_surface.h'
--- src/server/scene/basic_surface.h 2014-12-05 03:26:03 +0000
+++ src/server/scene/basic_surface.h 2014-12-05 22:17:20 +0000
@@ -158,6 +158,7 @@
158 MirSurfaceVisibility set_visibility(MirSurfaceVisibility v);158 MirSurfaceVisibility set_visibility(MirSurfaceVisibility v);
159 int set_swap_interval(int);159 int set_swap_interval(int);
160 MirSurfaceFocusState set_focus_state(MirSurfaceFocusState f);160 MirSurfaceFocusState set_focus_state(MirSurfaceFocusState f);
161 MirOrientationMode set_preferred_orientation(MirOrientationMode mode);
161162
162 SurfaceObservers observers;163 SurfaceObservers observers;
163 std::mutex mutable guard;164 std::mutex mutable guard;
@@ -184,6 +185,7 @@
184 MirSurfaceFocusState focus_ = mir_surface_unfocused;185 MirSurfaceFocusState focus_ = mir_surface_unfocused;
185 int dpi_ = 0;186 int dpi_ = 0;
186 MirSurfaceVisibility visibility_ = mir_surface_visibility_exposed;187 MirSurfaceVisibility visibility_ = mir_surface_visibility_exposed;
188 MirOrientationMode pref_orientation_mode = mir_orientation_mode_any;
187};189};
188190
189}191}
190192
=== modified file 'tests/acceptance-tests/test_client_surface_events.cpp'
--- tests/acceptance-tests/test_client_surface_events.cpp 2014-12-05 03:26:03 +0000
+++ tests/acceptance-tests/test_client_surface_events.cpp 2014-12-05 22:17:20 +0000
@@ -270,3 +270,19 @@
270 EXPECT_THAT(last_event_surface, Eq(surface));270 EXPECT_THAT(last_event_surface, Eq(surface));
271 EXPECT_THAT(last_event.type, Eq(mir_event_type_close_surface));271 EXPECT_THAT(last_event.type, Eq(mir_event_type_close_surface));
272}272}
273
274TEST_F(ClientSurfaceEvents, client_can_query_preferred_orientation)
275{
276
277 for (auto const mode:
278 {mir_orientation_mode_portrait, mir_orientation_mode_portrait_inverted,
279 mir_orientation_mode_landscape, mir_orientation_mode_landscape_inverted,
280 mir_orientation_mode_portrait_any, mir_orientation_mode_landscape_any,
281 mir_orientation_mode_any})
282 {
283 reset_last_event();
284
285 mir_wait_for(mir_surface_set_preferred_orientation(surface, mode));
286 EXPECT_THAT(mir_surface_get_preferred_orientation(surface), Eq(mode));
287 }
288}
273289
=== modified file 'tests/unit-tests/client/test_client_mir_surface.cpp'
--- tests/unit-tests/client/test_client_mir_surface.cpp 2014-12-05 03:26:03 +0000
+++ tests/unit-tests/client/test_client_mir_surface.cpp 2014-12-05 22:17:20 +0000
@@ -188,7 +188,8 @@
188 { mir_surface_attrib_swapinterval, 1 },188 { mir_surface_attrib_swapinterval, 1 },
189 { mir_surface_attrib_focus, mir_surface_focused },189 { mir_surface_attrib_focus, mir_surface_focused },
190 { mir_surface_attrib_dpi, 19 },190 { mir_surface_attrib_dpi, 19 },
191 { mir_surface_attrib_visibility, mir_surface_visibility_exposed }191 { mir_surface_attrib_visibility, mir_surface_visibility_exposed },
192 { mir_surface_attrib_preferred_orientation, mir_orientation_mode_any }
192};193};
193194
194struct MockBuffer : public mcl::ClientBuffer195struct MockBuffer : public mcl::ClientBuffer
195196
=== modified file 'tests/unit-tests/scene/test_surface_impl.cpp'
--- tests/unit-tests/scene/test_surface_impl.cpp 2014-12-05 03:26:03 +0000
+++ tests/unit-tests/scene/test_surface_impl.cpp 2014-12-05 22:17:20 +0000
@@ -460,3 +460,21 @@
460460
461 surf.request_client_surface_close();461 surf.request_client_surface_close();
462}462}
463
464TEST_F(Surface, preferred_orientation_mode_defaults_to_any)
465{
466 using namespace testing;
467
468 ms::BasicSurface surf(
469 std::string("stub"),
470 geom::Rectangle{{},{}},
471 false,
472 buffer_stream,
473 std::shared_ptr<mi::InputChannel>(),
474 stub_input_sender,
475 null_configurator,
476 std::shared_ptr<mg::CursorImage>(),
477 report);
478
479 EXPECT_EQ(mir_orientation_mode_any, surf.query(mir_surface_attrib_preferred_orientation));
480}

Subscribers

People subscribed via source and target branches