~alan-griffiths/mir/0.21-hacks

« back to all changes in this revision

Viewing changes to src/server/shell/surface.cpp

  • Committer: Daniel van Vugt
  • Date: 2013-04-24 05:22:20 UTC
  • mfrom: (628 trunk)
  • mto: This revision was merged to the branch mainline in revision 629.
  • Revision ID: daniel.van.vugt@canonical.com-20130424052220-qhpyhw2resxzr7bq
MergeĀ latestĀ lp:mir

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "mir/shell/surface.h"
20
20
#include "mir/shell/surface_builder.h"
21
21
#include "mir/input/input_channel.h"
 
22
#include "mir_toolkit/event.h"
 
23
#include "mir/event_sink.h"
22
24
 
23
25
#include <boost/throw_exception.hpp>
24
26
 
25
27
#include <stdexcept>
 
28
#include <cstring>
26
29
 
27
30
namespace msh = mir::shell;
28
31
namespace mc = mir::compositor;
35
38
  : builder(builder),
36
39
    input_channel(input_channel),
37
40
    surface(builder->create_surface(params)),
38
 
    type_value(mir_surface_type_normal)
 
41
    id(0),
 
42
    type_value(mir_surface_type_normal),
 
43
    state_value(mir_surface_state_restored)
39
44
{
40
45
}
41
46
 
47
52
    }
48
53
}
49
54
 
 
55
void msh::Surface::set_id(mir::frontend::SurfaceId i)
 
56
{
 
57
    id = i;
 
58
}
 
59
 
 
60
void msh::Surface::set_event_target(std::shared_ptr<EventSink> const& sink)
 
61
{
 
62
    event_sink = sink;
 
63
}
 
64
 
50
65
void msh::Surface::hide()
51
66
{
52
67
    if (auto const& s = surface.lock())
169
184
                                                   "type."));
170
185
        result = type();
171
186
        break;
 
187
    case mir_surface_attrib_state:
 
188
        if (value != mir_surface_state_unknown &&
 
189
            !set_state(static_cast<MirSurfaceState>(value)))
 
190
            BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface state."));
 
191
        result = state();
 
192
        break;
172
193
    default:
173
194
        BOOST_THROW_EXCEPTION(std::logic_error("Invalid surface "
174
195
                                               "attribute."));
195
216
 
196
217
    return valid;
197
218
}
 
219
 
 
220
MirSurfaceState msh::Surface::state() const
 
221
{
 
222
    return state_value;
 
223
}
 
224
 
 
225
bool msh::Surface::set_state(MirSurfaceState s)
 
226
{
 
227
    bool valid = false;
 
228
 
 
229
    if (s > mir_surface_state_unknown &&
 
230
        s < mir_surface_state_arraysize_)
 
231
    {
 
232
        state_value = s;
 
233
        valid = true;
 
234
 
 
235
        notify_change(mir_surface_attrib_state, s);
 
236
    }
 
237
 
 
238
    return valid;
 
239
}
 
240
 
 
241
void msh::Surface::notify_change(MirSurfaceAttrib attrib, int value)
 
242
{
 
243
    if (event_sink)
 
244
    {
 
245
        MirEvent e;
 
246
 
 
247
        // This memset is not really required. However it does avoid some
 
248
        // harmless uninitialized memory reads that valgrind will complain
 
249
        // about, due to gaps in MirEvent.
 
250
        memset(&e, 0, sizeof e);
 
251
 
 
252
        e.type = mir_event_type_surface;
 
253
        e.surface.id = id.as_value();
 
254
        e.surface.attrib = attrib;
 
255
        e.surface.value = value;
 
256
 
 
257
        event_sink->handle_event(e);
 
258
    }
 
259
}