summaryrefslogtreecommitdiffstats
path: root/ui/wayland/wayland_screen.cc
blob: c29bc567744d407d512fa01c1bed8449f87958e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/wayland/wayland_screen.h"

#include <wayland-client.h>

#include "ui/wayland/wayland_display.h"

namespace ui {

WaylandScreen::WaylandScreen(WaylandDisplay* display, uint32_t id)
    : output_(NULL),
      display_(display) {
  static const wl_output_listener kOutputListener = {
    WaylandScreen::OutputHandleGeometry,
    WaylandScreen::OutputHandleMode,
  };

  output_ = static_cast<wl_output*>(
      wl_display_bind(display_->display(), id, &wl_output_interface));
  wl_output_add_listener(output_, &kOutputListener, this);
}

WaylandScreen::~WaylandScreen() {
  if (output_)
    wl_output_destroy(output_);
}

gfx::Rect WaylandScreen::GetAllocation() const {
  gfx::Rect allocation;
  allocation.set_origin(position_);

  // Find the active mode and pass its dimensions.
  for (Modes::const_iterator i = modes_.begin(); i != modes_.end(); ++i) {
    if ((*i).flags & WL_OUTPUT_MODE_CURRENT) {
      allocation.set_width((*i).width);
      allocation.set_height((*i).height);
      break;
    }
  }

  return allocation;
}

// static
void WaylandScreen::OutputHandleGeometry(void* data,
                                         wl_output* output,
                                         int32_t x,
                                         int32_t y,
                                         int32_t physical_width,
                                         int32_t physical_height,
                                         int32_t subpixel,
                                         const char* make,
                                         const char* model) {
  WaylandScreen* screen = static_cast<WaylandScreen*>(data);
  screen->position_.SetPoint(x, y);
}

// static
void WaylandScreen::OutputHandleMode(void* data,
                                     wl_output* wl_output,
                                     uint32_t flags,
                                     int32_t width,
                                     int32_t height,
                                     int32_t refresh) {
  WaylandScreen* screen = static_cast<WaylandScreen*>(data);

  Mode mode;
  mode.width = width;
  mode.height = height;
  mode.refresh = refresh;
  mode.flags = flags;

  screen->modes_.push_back(mode);
}

}  // namespace ui