1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the Qt Compositor.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
41 #include "wlextendedoutput.h"
43 #include "wlcompositor.h"
44 #include "wlsurface.h"
49 OutputExtensionGlobal::OutputExtensionGlobal(Compositor *compositor)
50 : m_compositor(compositor)
52 wl_display_add_global(compositor->wl_display(),
53 &wl_output_extension_interface,
55 OutputExtensionGlobal::bind_func);
58 void OutputExtensionGlobal::bind_func(wl_client *client, void *data, uint32_t version, uint32_t id)
61 wl_client_add_object(client,&wl_output_extension_interface,&output_extension_interface,id,data);
64 void OutputExtensionGlobal::get_extended_output(wl_client *client, wl_resource *output_extension_resource, uint32_t id, wl_resource *output_resource)
66 OutputExtensionGlobal *output_extension = static_cast<OutputExtensionGlobal *>(output_extension_resource->data);
67 Output *output = static_cast<Output *>(output_resource->data);
68 new ExtendedOutput(client,id,output,output_extension->m_compositor);
71 const struct wl_output_extension_interface OutputExtensionGlobal::output_extension_interface = {
72 OutputExtensionGlobal::get_extended_output
75 ExtendedOutput::ExtendedOutput(struct wl_client *client, uint32_t id, Output *output, Compositor *compositor)
77 , m_compositor(compositor)
79 static const struct wl_extended_output_interface extended_output_interface = {
80 set_orientation_update_mask
82 Q_ASSERT(m_output->extendedOutput() == 0);
83 m_output->setExtendedOutput(this);
84 m_extended_output_resource = wl_client_add_object(client,&wl_extended_output_interface,&extended_output_interface,id,this);
85 m_extended_output_resource->destroy = ExtendedOutput::destroy_resource;
87 sendOutputOrientation(m_compositor->screenOrientation());
90 void ExtendedOutput::destroy_resource(wl_resource *resource)
92 ExtendedOutput *output = static_cast<ExtendedOutput *>(resource->data);
97 void ExtendedOutput::set_orientation_update_mask(struct wl_client *client,
98 struct wl_resource *resource,
99 int32_t orientation_update_mask)
101 ExtendedOutput *output = static_cast<ExtendedOutput *>(resource->data);
103 Qt::ScreenOrientations mask = 0;
104 if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION)
105 mask |= Qt::PortraitOrientation;
106 if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION)
107 mask |= Qt::LandscapeOrientation;
108 if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION)
109 mask |= Qt::InvertedPortraitOrientation;
110 if (orientation_update_mask & WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION)
111 mask |= Qt::InvertedLandscapeOrientation;
113 Qt::ScreenOrientations oldMask = output->m_orientationUpdateMask;
114 output->m_orientationUpdateMask = mask;
116 if (mask != oldMask) {
117 QList<Surface*> surfaces = output->m_compositor->surfacesForClient(client);
118 foreach (Surface *surface, surfaces) {
119 if (surface->waylandSurface())
120 emit surface->waylandSurface()->orientationUpdateMaskChanged();
125 void ExtendedOutput::sendOutputOrientation(Qt::ScreenOrientation orientation)
128 switch (orientation) {
129 case Qt::PortraitOrientation:
130 sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
132 case Qt::LandscapeOrientation:
133 sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION;
135 case Qt::InvertedPortraitOrientation:
136 sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION;
138 case Qt::InvertedLandscapeOrientation:
139 sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION;
142 sendOpperation = WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
144 wl_extended_output_send_set_screen_rotation(m_extended_output_resource, sendOpperation);