Mir

Merge lp:~mir-team/mir/cursor-spike-phase-7-name-some-cursors into lp:mir

Proposed by Robert Carr
Status: Merged
Approved by: Robert Carr
Approved revision: no longer in the source branch.
Merged at revision: 1782
Proposed branch: lp:~mir-team/mir/cursor-spike-phase-7-name-some-cursors
Merge into: lp:mir
Prerequisite: lp:~mir-team/mir/cursor-spike-phase-6-load-x-cursors
Diff against target: 391 lines (+283/-17)
7 files modified
examples/CMakeLists.txt (+6/-0)
examples/cursors_demo_client.c (+75/-0)
include/client/mir_toolkit/mir_cursor_configuration.h (+3/-2)
include/shared/mir_toolkit/common.h (+2/-11)
include/shared/mir_toolkit/cursors.h (+115/-0)
src/client/mir_cursor_api.cpp (+13/-0)
src/server/input/xcursor_loader.cpp (+69/-4)
To merge this branch: bzr merge lp:~mir-team/mir/cursor-spike-phase-7-name-some-cursors
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Cemil Azizoglu (community) Approve
Alan Griffiths Approve
Review via email: mp+225242@code.launchpad.net

This proposal supersedes a proposal from 2014-07-01.

Commit message

Provide some symbolic names for cursors.

Description of the change

Add some cursor names and translate to the standard xcursor names. The xcursor names are quite a mess (caret->"xterm" pointing hand->"hand2"),etc...so we want to provide clients something better than this.

Inspired by: http://qt-project.org/doc/qt-4.8/qt.html#CursorShape-enum

Adds a demo client which makes a small window and cycles through cursors.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:1558
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mir-team/mir/cursor-spike-phase-7-name-some-cursors/+merge/225204/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/mir-team-mir-development-branch-ci/2049/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-android-utopic-i386-build/787
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-clang-utopic-amd64-build/793
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-utopic-touch/786
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-team-mir-development-branch-utopic-amd64-ci/570
        deb: http://jenkins.qa.ubuntu.com/job/mir-team-mir-development-branch-utopic-amd64-ci/570/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-team-mir-development-branch-utopic-armhf-ci/568
        deb: http://jenkins.qa.ubuntu.com/job/mir-team-mir-development-branch-utopic-armhf-ci/568/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2393
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2393/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-mediumtests-runner-mako/1940
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9119

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/mir-team-mir-development-branch-ci/2049/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

181 +/* This is C code. Not C++. */
...
197 +extern char const* const mir_arrow_cursor_name;

I thought in "in C code" the * goes to the right?

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

needs info:
include/shared/mir_toolkit/cursors.h
Is providing a bunch of names as part of the API flexible enough?

nit:
89 + configure_cursor(mir_eglapp_native_surface(), cursor_index);
90 +
91 + // Of course we are subject to hypothetical overflow here, but it is of no consequence
92 + cursor_index++;

I'd be just as happy with:
configure_cursor(mir_eglapp_native_surface(), cursor_index++);

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

Alan:

Are you just referring to the whitespace? i.e. extern char const *const ? I couldn't find this in the style guide...I feel like I must be doing something stupid here :p

Kevin:
Removed strangely OCD comment lol.

In addition to providing a bunch of names we will need to support custom upload of cursor data. We want to provide some way for apps to request cursors from the system theme though. In X, the situation is a little hairy. One can request cursors from the X cursor theme, but only using an obscure series of names, for which there is literally no official documentation (in addition the names are surprising "Caret" is "xterm"! Toolkits improve on this by creating a set of enums etc, for standard cursors. This list was based off of a survey of Qt, GTK, and cursors available in the Ubuntu default theme. I think removing the responsibility from toolkits to maintain this strange list of names...is an improvement. I think names are more appropriate than enums as there is no serious use case to enumerate available cursors.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'm not convinced an if..elseif chain is the most efficient lookup, but OK

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

Of course :) I think it's an infrequent operation though so I wasn't too worried and it didnt seem worth to use a better string lookup.

I thought about using an enum but strings felt marginally more flexible, and ultimately more clear (cursor shapes aren't really meaningfully enumerable?)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

LGTM...

o Not sure what the following comment is... for sarcasm?
323 + return "xterm"; // Yep

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

I still hope that we move away from the x cursor names, but at least I understand what's going on a bit better. +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/CMakeLists.txt'
2--- examples/CMakeLists.txt 2014-06-11 16:11:32 +0000
3+++ examples/CMakeLists.txt 2014-07-21 15:42:48 +0000
4@@ -36,6 +36,12 @@
5 target_link_libraries(mir_demo_client_eglplasma
6 eglapp
7 )
8+add_executable(mir_demo_client_cursors
9+ cursors_demo_client.c
10+)
11+target_link_libraries(mir_demo_client_cursors
12+ eglapp
13+)
14
15 add_executable(mir_demo_client_basic
16 basic.c
17
18=== added file 'examples/cursors_demo_client.c'
19--- examples/cursors_demo_client.c 1970-01-01 00:00:00 +0000
20+++ examples/cursors_demo_client.c 2014-07-21 15:42:48 +0000
21@@ -0,0 +1,75 @@
22+/*
23+ * Copyright © 2014 Canonical LTD
24+ *
25+ * This program is free software: you can redistribute it and/or modify
26+ * it under the terms of the GNU General Public License version 3 as
27+ * published by the Free Software Foundation.
28+ *
29+ * This program is distributed in the hope that it will be useful,
30+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
31+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+ * GNU General Public License for more details.
33+ *
34+ * You should have received a copy of the GNU General Public License
35+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
36+ *
37+ * Author: Robert Carr <robert.carr@canonical.com>
38+ */
39+
40+#include "mir_toolkit/mir_client_library.h"
41+
42+#include "eglapp.h"
43+#include <stdio.h>
44+#include <unistd.h>
45+#include <GLES2/gl2.h>
46+
47+void configure_cursor(MirSurface *surface, unsigned int cursor_index)
48+{
49+ char const *const cursors[] = {
50+ mir_arrow_cursor_name,
51+ mir_busy_cursor_name,
52+ mir_caret_cursor_name,
53+ mir_pointing_hand_cursor_name,
54+ mir_open_hand_cursor_name,
55+ mir_closed_hand_cursor_name,
56+ mir_horizontal_resize_cursor_name,
57+ mir_vertical_resize_cursor_name,
58+ mir_diagonal_resize_bottom_to_top_cursor_name,
59+ mir_diagonal_resize_top_to_bottom_cursor_name,
60+ mir_omnidirectional_resize_cursor_name,
61+ mir_vsplit_resize_cursor_name,
62+ mir_hsplit_resize_cursor_name
63+ };
64+
65+ size_t num_cursors = sizeof(cursors)/sizeof(*cursors);
66+ size_t real_index = cursor_index % num_cursors;
67+
68+ MirCursorConfiguration *conf = mir_cursor_configuration_from_name(cursors[real_index]);
69+
70+ mir_wait_for(mir_surface_configure_cursor(surface, conf));
71+
72+ mir_cursor_configuration_destroy(conf);
73+}
74+
75+int main(int argc, char *argv[])
76+{
77+ unsigned int width = 128, height = 128;
78+
79+ if (!mir_eglapp_init(argc, argv, &width, &height))
80+ return 1;
81+
82+ glClearColor(0.5, 0.5, 0.5, mir_eglapp_background_opacity);
83+ glClear(GL_COLOR_BUFFER_BIT);
84+ mir_eglapp_swap_buffers();
85+
86+ unsigned int cursor_index = 0;
87+ while (mir_eglapp_running())
88+ {
89+ configure_cursor(mir_eglapp_native_surface(), cursor_index++);
90+ sleep(1);
91+ }
92+
93+ mir_eglapp_shutdown();
94+
95+ return 0;
96+}
97
98=== modified file 'include/client/mir_toolkit/mir_cursor_configuration.h'
99--- include/client/mir_toolkit/mir_cursor_configuration.h 2014-06-17 22:07:15 +0000
100+++ include/client/mir_toolkit/mir_cursor_configuration.h 2014-07-21 15:42:48 +0000
101@@ -42,8 +42,9 @@
102
103 /**
104 * Returns a new MirCursorConfiguration representing a named cursor
105- * from the system cursor theme. Currently only the symbolic values,
106- * mir_default_cursor_name and mir_disabled_cursor_name are supported
107+ * from the system cursor theme. Symbolic cursor names, such as
108+ * mir_default_cursor_name and mir_caret_cursor_name are available
109+ * see (mir_toolkit/cursors.h).
110 * as input.
111 * \param [in] name The cursor name
112 * \return A cursor parameters object which must be passed
113
114=== modified file 'include/shared/mir_toolkit/common.h'
115--- include/shared/mir_toolkit/common.h 2014-07-08 17:16:01 +0000
116+++ include/shared/mir_toolkit/common.h 2014-07-21 15:42:48 +0000
117@@ -21,6 +21,8 @@
118 #ifndef MIR_COMMON_H_
119 #define MIR_COMMON_H_
120
121+#include <mir_toolkit/cursors.h>
122+
123 /**
124 * \addtogroup mir_toolkit
125 * @{
126@@ -137,17 +139,6 @@
127 mir_orientation_right = 270
128 } MirOrientation;
129
130-/**
131- * A special cursor name for use with mir_cursor_configuration_from_name
132- * representing the system default cursor.
133- */
134-extern char const *const mir_default_cursor_name;
135-/**
136- * A special cursor name for use with mir_cursor_configuration_from_name
137- * representing a disabled cursor image.
138- */
139-extern char const *const mir_disabled_cursor_name;
140-
141 /**@}*/
142
143 #endif
144
145=== added file 'include/shared/mir_toolkit/cursors.h'
146--- include/shared/mir_toolkit/cursors.h 1970-01-01 00:00:00 +0000
147+++ include/shared/mir_toolkit/cursors.h 2014-07-21 15:42:48 +0000
148@@ -0,0 +1,115 @@
149+/*
150+ * Cursor name definitions.
151+ *
152+ * Copyright © 2014 Canonical Ltd.
153+ *
154+ * This program is free software: you can redistribute it and/or modify
155+ * it under the terms of the GNU Lesser General Public License version 3 as
156+ * published by the Free Software Foundation.
157+ *
158+ * This program is distributed in the hope that it will be useful,
159+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
160+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+ * GNU Lesser General Public License for more details.
162+ *
163+ * You should have received a copy of the GNU Lesser General Public License
164+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
165+ *
166+ * Author: Robert Carr <robert.carr@canonical.com>
167+ */
168+
169+#ifndef MIR_CURSORS_H_
170+#define MIR_CURSORS_H_
171+
172+/**
173+ * \addtogroup mir_toolkit
174+ * @{
175+ */
176+
177+/* This is C code. Not C++. */
178+
179+/**
180+ * A special cursor name for use with mir_cursor_configuration_from_name
181+ * representing the system default cursor.
182+ */
183+extern char const *const mir_default_cursor_name;
184+/**
185+ * A special cursor name for use with mir_cursor_configuration_from_name
186+ * representing a disabled cursor image.
187+ */
188+extern char const *const mir_disabled_cursor_name;
189+
190+/**
191+ * The standard arrow cursor (typically the system default)
192+ */
193+extern char const* const mir_arrow_cursor_name;
194+
195+/**
196+ * The "wait" cursor, typically an hourglass or watch used during operations
197+ * which prevent the user from interacting.
198+ */
199+extern char const* const mir_busy_cursor_name;
200+
201+/**
202+ * The caret or ibeam cursor, indicating acceptance of text input
203+ */
204+extern char const* const mir_caret_cursor_name;
205+
206+/**
207+ * The pointing hand cursor, typically used for clickable elements such
208+ * as hyperlinks.
209+ */
210+extern char const* const mir_pointing_hand_cursor_name;
211+
212+/**
213+ * The open handed cursor, typically used to indicate that the area beneath
214+ * the cursor may be clicked and dragged around.
215+ */
216+extern char const* const mir_open_hand_cursor_name;
217+
218+/**
219+ * The close handed cursor, typically used to indicate that a drag operation is in process
220+ * which involves scrolling.
221+ */
222+extern char const* const mir_closed_hand_cursor_name;
223+
224+/**
225+ * The cursor used to indicate a horizontal resize operation.
226+ */
227+extern char const* const mir_horizontal_resize_cursor_name;
228+
229+/**
230+ * The cursor used to indicate a vertical resize operation.
231+ */
232+extern char const* const mir_vertical_resize_cursor_name;
233+
234+/**
235+ * The cursor used to indicate diagonal resize from top-right and bottom-left corners.
236+ */
237+extern char const* const mir_diagonal_resize_bottom_to_top_cursor_name;
238+
239+/**
240+ * The cursor used to indicate diagonal resize from bottom-left and top-right corners.
241+ */
242+extern char const* const mir_diagonal_resize_top_to_bottom_cursor_name;
243+
244+/**
245+ * The cursor used to indicate resize with no directional constraint.
246+ */
247+extern char const* const mir_omnidirectional_resize_cursor_name;
248+
249+/**
250+ * The cursor used for vertical splitters, indicating that a handle may be
251+ * dragged to adjust vertical space.
252+ */
253+extern char const* const mir_vsplit_resize_cursor_name;
254+
255+/**
256+ * The cursor used for horizontal splitters, indicating that a handle may be
257+ * dragged to adjust horizontal space.
258+ */
259+extern char const* const mir_hsplit_resize_cursor_name;
260+
261+/**@}*/
262+
263+#endif
264
265=== modified file 'src/client/mir_cursor_api.cpp'
266--- src/client/mir_cursor_api.cpp 2014-06-17 22:07:15 +0000
267+++ src/client/mir_cursor_api.cpp 2014-07-21 15:42:48 +0000
268@@ -23,6 +23,19 @@
269
270 char const *const mir_default_cursor_name = "default";
271 char const *const mir_disabled_cursor_name = "disabled";
272+char const* const mir_arrow_cursor_name = "arrow";
273+char const* const mir_busy_cursor_name = "busy";
274+char const* const mir_caret_cursor_name = "caret";
275+char const* const mir_pointing_hand_cursor_name = "pointing-hand";
276+char const* const mir_open_hand_cursor_name = "open-hand";
277+char const* const mir_closed_hand_cursor_name = "closed-hand";
278+char const* const mir_horizontal_resize_cursor_name = "horizontal-resize";
279+char const* const mir_vertical_resize_cursor_name = "vertical-resize";
280+char const* const mir_diagonal_resize_bottom_to_top_cursor_name = "diagonal-resize-bottom-to-top";
281+char const* const mir_diagonal_resize_top_to_bottom_cursor_name = "diagonal-resize-top_to_bottom";
282+char const* const mir_omnidirectional_resize_cursor_name = "omnidirectional-resize";
283+char const* const mir_vsplit_resize_cursor_name = "vsplit-resize";
284+char const* const mir_hsplit_resize_cursor_name = "hsplit-resize";
285
286 MirCursorConfiguration::MirCursorConfiguration(char const* name) :
287 name{name ? name : std::string()}
288
289=== modified file 'src/server/input/xcursor_loader.cpp'
290--- src/server/input/xcursor_loader.cpp 2014-06-25 05:16:43 +0000
291+++ src/server/input/xcursor_loader.cpp 2014-07-21 15:42:48 +0000
292@@ -25,6 +25,8 @@
293
294 #include <string.h>
295
296+#include <mir_toolkit/cursors.h>
297+
298 // Unforunately this can not be compiled as C++...so we can not namespace
299 // these symbols. In order to differentiate from internal symbols
300 // we refer to them via their _ prefixed version, i.e. _XcursorImage
301@@ -75,6 +77,71 @@
302 _XcursorImage *image;
303 std::shared_ptr<_XcursorImages> const save_resource;
304 };
305+
306+std::string const
307+xcursor_name_for_mir_cursor(std::string const& mir_cursor_name)
308+{
309+ if (mir_cursor_name == mir_default_cursor_name)
310+ {
311+ return "arrow";
312+ }
313+ else if (mir_cursor_name == mir_arrow_cursor_name)
314+ {
315+ return "arrow";
316+ }
317+ else if (mir_cursor_name == mir_busy_cursor_name)
318+ {
319+ return "watch";
320+ }
321+ else if (mir_cursor_name == mir_caret_cursor_name)
322+ {
323+ return "xterm"; // Yep
324+ }
325+ else if (mir_cursor_name == mir_pointing_hand_cursor_name)
326+ {
327+ return "hand2";
328+ }
329+ else if (mir_cursor_name == mir_open_hand_cursor_name)
330+ {
331+ return "hand";
332+ }
333+ else if (mir_cursor_name == mir_closed_hand_cursor_name)
334+ {
335+ return "grabbing";
336+ }
337+ else if (mir_cursor_name == mir_horizontal_resize_cursor_name)
338+ {
339+ return "h_double_arrow";
340+ }
341+ else if (mir_cursor_name == mir_vertical_resize_cursor_name)
342+ {
343+ return "v_double_arrow";
344+ }
345+ else if (mir_cursor_name == mir_diagonal_resize_bottom_to_top_cursor_name)
346+ {
347+ return "top_right_corner";
348+ }
349+ else if (mir_cursor_name == mir_diagonal_resize_top_to_bottom_cursor_name)
350+ {
351+ return "bottom_right_corner";
352+ }
353+ else if (mir_cursor_name == mir_omnidirectional_resize_cursor_name)
354+ {
355+ return "fleur";
356+ }
357+ else if (mir_cursor_name == mir_vsplit_resize_cursor_name)
358+ {
359+ return "v_double_arrow";
360+ }
361+ else if (mir_cursor_name == mir_hsplit_resize_cursor_name)
362+ {
363+ return "h_double_arrow";
364+ }
365+ else
366+ {
367+ return mir_cursor_name;
368+ }
369+}
370 }
371
372 mi::XCursorLoader::XCursorLoader()
373@@ -129,9 +196,7 @@
374 std::shared_ptr<mg::CursorImage> mi::XCursorLoader::image(std::string const& cursor_name,
375 geom::Size const& size)
376 {
377- // 'arrow' is the default cursor in XCursor themes.
378- if (cursor_name == "default")
379- return image("arrow", size);
380+ auto xcursor_name = xcursor_name_for_mir_cursor(cursor_name);
381
382 if (size != mi::default_cursor_size)
383 BOOST_THROW_EXCEPTION(
384@@ -139,7 +204,7 @@
385
386 std::lock_guard<std::mutex> lg(guard);
387
388- auto it = loaded_images.find(cursor_name);
389+ auto it = loaded_images.find(xcursor_name);
390 if (it != loaded_images.end())
391 return it->second;
392

Subscribers

People subscribed via source and target branches