9e95167eda170fb3b91d4a9945bcfe605586251f
[AGL/meta-agl-demo.git] / recipes-graphics / wayland / wayland-ivi-extension / 0001-simple-id-agent-initial-commit.patch
1 From 8f67f40f7c6b6f62e094f0bdc5044793ae76b1c7 Mon Sep 17 00:00:00 2001
2 From: Emre Ucan <eucan@de.adit-jv.com>
3 Date: Fri, 24 Nov 2017 16:24:51 +0100
4 Subject: [PATCH 1/2] simple-id-agent: initial commit
5
6 it is a very simple id-agent plugin.
7 It is possible to configure default surface id
8 offset. Assigned ids would start
9 from the given id offset.
10
11 Please check the example weston.ini for loading
12 and configuring the simple-id-agent
13
14 Signed-off-by: Emre Ucan <eucan@de.adit-jv.com>
15 ---
16  CMakeLists.txt                                     |   1 +
17  id-agent-modules/simple-id-agent/CMakeLists.txt    |  72 ++++++++++++
18  .../simple-id-agent/src/simple-id-agent.c          | 124 +++++++++++++++++++++
19  id-agent-modules/simple-id-agent/weston.ini.in     |  11 ++
20  4 files changed, 208 insertions(+)
21  create mode 100644 id-agent-modules/simple-id-agent/CMakeLists.txt
22  create mode 100644 id-agent-modules/simple-id-agent/src/simple-id-agent.c
23  create mode 100644 id-agent-modules/simple-id-agent/weston.ini.in
24
25 diff --git a/CMakeLists.txt b/CMakeLists.txt
26 index bad85df..d07abf5 100644
27 --- a/CMakeLists.txt
28 +++ b/CMakeLists.txt
29 @@ -35,6 +35,7 @@ add_subdirectory(ivi-layermanagement-api/ilmClient)
30  add_subdirectory(ivi-layermanagement-api/ilmControl)
31  add_subdirectory(ivi-layermanagement-api/test)
32  add_subdirectory(ivi-layermanagement-examples)
33 +add_subdirectory(id-agent-modules/simple-id-agent)
34  
35  if(WITH_ILM_INPUT)
36      add_subdirectory(ivi-input-api/ilmInput)
37 diff --git a/id-agent-modules/simple-id-agent/CMakeLists.txt b/id-agent-modules/simple-id-agent/CMakeLists.txt
38 new file mode 100644
39 index 0000000..8290722
40 --- /dev/null
41 +++ b/id-agent-modules/simple-id-agent/CMakeLists.txt
42 @@ -0,0 +1,72 @@
43 +############################################################################
44 +#
45 +# Copyright (C) 2013 DENSO CORPORATION
46 +# Copyright 2014 BMW Car IT GmbH
47 +#
48 +#
49 +# Licensed under the Apache License, Version 2.0 (the "License");
50 +# you may not use this file except in compliance with the License.
51 +# You may obtain a copy of the License at
52 +#
53 +#              http://www.apache.org/licenses/LICENSE-2.0
54 +#
55 +# Unless required by applicable law or agreed to in writing, software
56 +# distributed under the License is distributed on an "AS IS" BASIS,
57 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58 +# See the License for the specific language governing permissions and
59 +# limitations under the License.
60 +#
61 +############################################################################
62 +
63 +cmake_minimum_required (VERSION 2.6)
64 +
65 +project(simple-id-agent)
66 +
67 +find_package(PkgConfig REQUIRED)
68 +pkg_check_modules(WAYLAND_SERVER wayland-server>=1.13.0 REQUIRED)
69 +pkg_check_modules(WESTON weston>=2.0.0 REQUIRED)
70 +pkg_check_modules(PIXMAN pixman-1 REQUIRED)
71 +
72 +find_package(Threads REQUIRED)
73 +
74 +GET_TARGET_PROPERTY(IVI_EXTENSION_INCLUDE_DIRS ivi-extension-protocol INCLUDE_DIRECTORIES)
75 +
76 +include_directories(
77 +    src
78 +    ${IVI_EXTENSION_INCLUDE_DIRS}
79 +    ${WAYLAND_SERVER_INCLUDE_DIRS}
80 +    ${WESTON_INCLUDE_DIRS}
81 +    ${PIXMAN_INCLUDE_DIRS}
82 +)
83 +
84 +link_directories(
85 +    ${WAYLAND_SERVER_LIBRARY_DIRS}
86 +    ${PIXMAN_LIBRARY_DIRS}
87 +)
88 +
89 +add_library(${PROJECT_NAME} MODULE
90 +    src/simple-id-agent.c
91 +)
92 +
93 +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
94 +
95 +add_dependencies(${PROJECT_NAME}
96 +    ivi-extension-protocol
97 +    ${WAYLAND_SERVER_LIBRARIES}
98 +    ${PIXMAN_LIBRARIES}
99 +)
100 +
101 +set(LIBS
102 +    ${LIBS}
103 +    ivi-extension-protocol
104 +    ${WAYLAND_SERVER_LIBRARIES}
105 +)
106 +
107 +set(CMAKE_C_LDFLAGS "-module -avoid-version")
108 +
109 +target_link_libraries(${PROJECT_NAME} ${LIBS})
110 +
111 +install (
112 +    TARGETS             ${PROJECT_NAME}
113 +    LIBRARY DESTINATION lib${LIB_SUFFIX}/weston
114 +)
115 diff --git a/id-agent-modules/simple-id-agent/src/simple-id-agent.c b/id-agent-modules/simple-id-agent/src/simple-id-agent.c
116 new file mode 100644
117 index 0000000..3c9e989
118 --- /dev/null
119 +++ b/id-agent-modules/simple-id-agent/src/simple-id-agent.c
120 @@ -0,0 +1,124 @@
121 +/*
122 + * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
123 + *
124 + * Permission to use, copy, modify, distribute, and sell this software and
125 + * its documentation for any purpose is hereby granted without fee, provided
126 + * that the above copyright notice appear in all copies and that both that
127 + * copyright notice and this permission notice appear in supporting
128 + * documentation, and that the name of the copyright holders not be used in
129 + * advertising or publicity pertaining to distribution of the software
130 + * without specific, written prior permission.  The copyright holders make
131 + * no representations about the suitability of this software for any
132 + * purpose.  It is provided "as is" without express or implied warranty.
133 + *
134 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
135 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
136 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
137 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
138 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
139 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
140 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
141 + */
142 +
143 +#include <stdlib.h>
144 +#include <stdio.h>
145 +#include <string.h>
146 +#include <limits.h>
147 +
148 +#include <weston.h>
149 +#include <weston/ivi-layout-export.h>
150 +
151 +struct ivi_id_agent
152 +{
153 +    uint32_t default_id_offset;
154 +    uint32_t last_assigned_id;
155 +    struct weston_compositor *compositor;
156 +    const struct ivi_layout_interface *interface;
157 +    struct wl_listener desktop_surface_configured;
158 +};
159 +
160 +static void
161 +desktop_surface_event_configure(struct wl_listener *listener,
162 +        void *data)
163 +{
164 +    struct ivi_id_agent *ida = wl_container_of(listener, ida,
165 +            desktop_surface_configured);
166 +    struct ivi_layout_surface *layout_surface =
167 +            (struct ivi_layout_surface *) data;
168 +    uint32_t tmp_id;
169 +
170 +    tmp_id = ++ida->last_assigned_id;
171 +
172 +    /* Find an unused id */
173 +    while(ida->interface->get_surface_from_id(tmp_id)) {
174 +        weston_log("simple-id-agent: surface id: %d is already used\n", tmp_id);
175 +        tmp_id++;
176 +    }
177 +
178 +    ida->last_assigned_id = tmp_id;
179 +
180 +    if (ida->interface->surface_set_id(layout_surface, ida->last_assigned_id) != 0)
181 +        weston_log("simple-id-agent: failed to set surface id :%d\n", ida->last_assigned_id);
182 +}
183 +
184 +static void
185 +deinit(struct ivi_id_agent *ida)
186 +{
187 +    wl_list_remove(&ida->desktop_surface_configured.link);
188 +    free(ida);
189 +}
190 +
191 +static int32_t
192 +read_config(struct ivi_id_agent *ida)
193 +{
194 +    struct weston_config *config = NULL;
195 +    struct weston_config_section *section = NULL;
196 +    const char *name = NULL;
197 +
198 +    config = wet_get_config(ida->compositor);
199 +    if (!config)
200 +        return -1;
201 +
202 +    section = weston_config_get_section(config, "id-agent", NULL, NULL);
203 +
204 +    if (section) {
205 +
206 +        weston_config_section_get_uint(section, "default-id-offset",
207 +                &ida->default_id_offset, 0);
208 +
209 +    } else {
210 +        ida->default_id_offset = 0;
211 +    }
212 +
213 +    return 0;
214 +}
215 +
216 +WL_EXPORT int32_t
217 +id_agent_module_init(struct weston_compositor *ec,
218 +                             const struct ivi_layout_interface *interface,
219 +                             size_t interface_version)
220 +{
221 +    struct ivi_id_agent *ida;
222 +
223 +    ida = calloc(1, sizeof *ida);
224 +    if (ida == NULL) {
225 +        weston_log("failed to allocate ivi_id_agent\n");
226 +        return -1;
227 +    }
228 +
229 +    ida->compositor = ec;
230 +    ida->interface = interface;
231 +    ida->desktop_surface_configured.notify = desktop_surface_event_configure;
232 +    ida->interface->add_listener_configure_desktop_surface(&ida->desktop_surface_configured);
233 +
234 +    if(read_config(ida) != 0) {
235 +        deinit(ida);
236 +        return -1;
237 +    }
238 +
239 +    ida->last_assigned_id = ida->default_id_offset;
240 +
241 +    weston_log("id_agent_module_init: success\n");
242 +
243 +    return 0;
244 +}
245 diff --git a/id-agent-modules/simple-id-agent/weston.ini.in b/id-agent-modules/simple-id-agent/weston.ini.in
246 new file mode 100644
247 index 0000000..b5e5fa1
248 --- /dev/null
249 +++ b/id-agent-modules/simple-id-agent/weston.ini.in
250 @@ -0,0 +1,11 @@
251 +[core]
252 +shell=ivi-shell.so
253 +require-input=false
254 +
255 +[ivi-shell]
256 +ivi-module=ivi-controller.so
257 +ivi-input-module=ivi-input-controller.so
258 +id-agent-module=simple-id-agent.so
259 +
260 +[id-agent]
261 +default-id-offset=10
262 -- 
263 2.13.6
264