Mir

Merge lp:~alan-griffiths/mir/fix-1706004 into lp:mir

Proposed by Alan Griffiths on 2017-07-24
Status: Merged
Approved by: Gerry Boland on 2017-07-24
Approved revision: 4213
Merged at revision: 4213
Proposed branch: lp:~alan-griffiths/mir/fix-1706004
Merge into: lp:mir
Diff against target: 191 lines (+85/-74)
2 files modified
examples/client_helpers.cpp (+6/-0)
examples/eglsquare.cpp (+79/-74)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1706004
Reviewer Review Type Date Requested Status
Gerry Boland 2017-07-24 Approve on 2017-07-24
Mir CI Bot continuous-integration Approve on 2017-07-24
Review via email: mp+327955@code.launchpad.net

Commit message

Handle mir_event_type_close_window in examples (LP: #1706004)

To post a comment you must log in.
Alan Griffiths (alan-griffiths) wrote :

Also fixes some whitespace in examples/eglsquare.cpp

Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:4213
https://mir-jenkins.ubuntu.com/job/mir-ci/3506/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/4797
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/4974
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/4963
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/4963
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/4963
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/4834/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4834
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/4834/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Gerry Boland (gerboland) wrote :

Yep, ok

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/client_helpers.cpp'
2--- examples/client_helpers.cpp 2017-06-06 14:57:41 +0000
3+++ examples/client_helpers.cpp 2017-07-24 10:03:39 +0000
4@@ -18,6 +18,8 @@
5
6 #include "client_helpers.h"
7 #include "mir_toolkit/mir_client_library.h"
8+#include <unistd.h>
9+#include <signal.h>
10
11 namespace me = mir::examples;
12
13@@ -89,6 +91,10 @@
14 break;
15 }
16
17+ case mir_event_type_close_window:
18+ kill(getpid(), SIGTERM);
19+ break;
20+
21 default:
22 break;
23 }
24
25=== modified file 'examples/eglsquare.cpp'
26--- examples/eglsquare.cpp 2017-06-06 13:55:51 +0000
27+++ examples/eglsquare.cpp 2017-07-24 10:03:39 +0000
28@@ -169,84 +169,89 @@
29
30 pos = Pos{x, y};
31 cv.notify_one();
32+ break;
33 }
34
35+ case mir_event_type_close_window:
36+ kill(getpid(), SIGTERM);
37+ break;
38+
39 default:;
40 }
41- }
42-
43- SquareRenderingSurface(SquareRenderingSurface const&) = delete;
44- SquareRenderingSurface& operator=(SquareRenderingSurface const&) = delete;
45- private:
46- struct OutputDimensions
47- {
48- unsigned int const width;
49- unsigned int const height;
50- } const dimensions;
51-
52- me::Context context;
53- me::NormalWindow window;
54- RenderProgram program;
55-
56- OutputDimensions active_output_dimensions(MirConnection* connection)
57- {
58- unsigned int width{0};
59- unsigned int height{0};
60- auto display_config = mir_connection_create_display_configuration(connection);
61- auto num_outputs = mir_display_config_get_num_outputs(display_config);
62- for (auto i = 0; i < num_outputs; i++)
63- {
64- auto output = mir_display_config_get_output(display_config, i);
65- auto state = mir_output_get_connection_state(output);
66- if (state == mir_output_connection_state_connected && mir_output_is_enabled(output))
67- {
68- auto mode = mir_output_get_current_mode(output);
69- width = mir_output_mode_get_width(mode);
70- height = mir_output_mode_get_height(mode);
71- break;
72- }
73- }
74- mir_display_config_release(display_config);
75- if (width == 0 || height == 0)
76- throw std::logic_error("could not determine display size");
77- return {width, height};
78- }
79-
80- static void on_event(MirWindow*, const MirEvent *event, void *context)
81- {
82- auto surface = reinterpret_cast<SquareRenderingSurface*>(context);
83- if (surface) surface->on_event(event);
84- }
85-
86- private:
87- void do_work()
88- {
89- std::unique_lock<decltype(mutex)> lock(mutex);
90-
91- while (true)
92- {
93- cv.wait(lock);
94-
95- if (!running) return;
96-
97- Pos pos = this->pos;
98-
99- context.make_current();
100- program.draw(
101- pos.x/static_cast<float>(dimensions.width)*2.0 - 1.0,
102- pos.y/static_cast<float>(dimensions.height)*-2.0 + 1.0);
103- context.swapbuffers();
104- }
105- }
106-
107- struct Pos { float x; float y; };
108- std::atomic<Pos> pos;
109-
110- std::thread worker;
111- std::condition_variable cv;
112- std::mutex mutex;
113- bool running{true};
114- };
115+ }
116+
117+ SquareRenderingSurface(SquareRenderingSurface const&) = delete;
118+ SquareRenderingSurface& operator=(SquareRenderingSurface const&) = delete;
119+private:
120+ struct OutputDimensions
121+ {
122+ unsigned int const width;
123+ unsigned int const height;
124+ } const dimensions;
125+
126+ me::Context context;
127+ me::NormalWindow window;
128+ RenderProgram program;
129+
130+ OutputDimensions active_output_dimensions(MirConnection* connection)
131+ {
132+ unsigned int width{0};
133+ unsigned int height{0};
134+ auto display_config = mir_connection_create_display_configuration(connection);
135+ auto num_outputs = mir_display_config_get_num_outputs(display_config);
136+ for (auto i = 0; i < num_outputs; i++)
137+ {
138+ auto output = mir_display_config_get_output(display_config, i);
139+ auto state = mir_output_get_connection_state(output);
140+ if (state == mir_output_connection_state_connected && mir_output_is_enabled(output))
141+ {
142+ auto mode = mir_output_get_current_mode(output);
143+ width = mir_output_mode_get_width(mode);
144+ height = mir_output_mode_get_height(mode);
145+ break;
146+ }
147+ }
148+ mir_display_config_release(display_config);
149+ if (width == 0 || height == 0)
150+ throw std::logic_error("could not determine display size");
151+ return {width, height};
152+ }
153+
154+ static void on_event(MirWindow*, const MirEvent *event, void *context)
155+ {
156+ auto surface = reinterpret_cast<SquareRenderingSurface*>(context);
157+ if (surface) surface->on_event(event);
158+ }
159+
160+private:
161+ void do_work()
162+ {
163+ std::unique_lock<decltype(mutex)> lock(mutex);
164+
165+ while (true)
166+ {
167+ cv.wait(lock);
168+
169+ if (!running) return;
170+
171+ Pos pos = this->pos;
172+
173+ context.make_current();
174+ program.draw(
175+ pos.x/static_cast<float>(dimensions.width)*2.0 - 1.0,
176+ pos.y/static_cast<float>(dimensions.height)*-2.0 + 1.0);
177+ context.swapbuffers();
178+ }
179+ }
180+
181+ struct Pos { float x; float y; };
182+ std::atomic<Pos> pos;
183+
184+ std::thread worker;
185+ std::condition_variable cv;
186+ std::mutex mutex;
187+ bool running{true};
188+};
189 }
190
191 int main(int argc, char *argv[])

Subscribers

People subscribed via source and target branches