Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010-2012 Intel Corporation |
| 3 | * Copyright © 2011-2012 Collabora, Ltd. |
| 4 | * Copyright © 2013 Raspberry Pi Foundation |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <stdint.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <unistd.h> |
| 33 | #include <linux/input.h> |
| 34 | #include <assert.h> |
| 35 | #include <signal.h> |
| 36 | #include <math.h> |
| 37 | #include <sys/types.h> |
| 38 | |
| 39 | #include "compositor/weston.h" |
Pekka Paalanen | 91b1010 | 2019-04-04 14:27:31 +0300 | [diff] [blame^] | 40 | #include <libweston/config-parser.h> |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 41 | #include "shared/helpers.h" |
| 42 | #include "libweston-desktop/libweston-desktop.h" |
| 43 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 44 | struct desktest_shell { |
| 45 | struct wl_listener compositor_destroy_listener; |
| 46 | struct weston_desktop *desktop; |
| 47 | struct weston_layer background_layer; |
| 48 | struct weston_surface *background_surface; |
| 49 | struct weston_view *background_view; |
| 50 | struct weston_layer layer; |
| 51 | struct weston_view *view; |
| 52 | }; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 53 | |
| 54 | static void |
| 55 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 56 | void *shell) |
| 57 | { |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 58 | struct desktest_shell *dts = shell; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 59 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 60 | assert(!dts->view); |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 61 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 62 | dts->view = weston_desktop_surface_create_view(desktop_surface); |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 63 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 64 | assert(dts->view); |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void |
| 68 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 69 | void *shell) |
| 70 | { |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 71 | struct desktest_shell *dts = shell; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 72 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 73 | assert(dts->view); |
| 74 | |
| 75 | weston_desktop_surface_unlink_view(dts->view); |
| 76 | weston_view_destroy(dts->view); |
| 77 | dts->view = NULL; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void |
| 81 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 82 | int32_t sx, int32_t sy, void *shell) |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 83 | { |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 84 | struct desktest_shell *dts = shell; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 85 | struct weston_surface *surface = |
| 86 | weston_desktop_surface_get_surface(desktop_surface); |
| 87 | struct weston_geometry geometry = |
| 88 | weston_desktop_surface_get_geometry(desktop_surface); |
| 89 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 90 | assert(dts->view); |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 91 | |
| 92 | if (weston_surface_is_mapped(surface)) |
| 93 | return; |
| 94 | |
| 95 | surface->is_mapped = true; |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 96 | weston_layer_entry_insert(&dts->layer.view_list, &dts->view->layer_link); |
| 97 | weston_view_set_position(dts->view, 0 - geometry.x, 0 - geometry.y); |
| 98 | weston_view_update_transform(dts->view); |
| 99 | dts->view->is_mapped = true; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static void |
| 103 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 104 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 110 | struct weston_seat *seat, uint32_t serial, |
| 111 | enum weston_desktop_surface_edge edges, void *shell) |
| 112 | { |
| 113 | } |
| 114 | |
| 115 | static void |
| 116 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 117 | bool fullscreen, |
| 118 | struct weston_output *output, void *shell) |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | static void |
| 123 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 124 | bool maximized, void *shell) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static void |
| 129 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 130 | void *shell) |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | static void |
| 135 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 136 | void *shell) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 142 | void *shell) |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | static const struct weston_desktop_api shell_desktop_api = { |
| 147 | .struct_size = sizeof(struct weston_desktop_api), |
| 148 | .surface_added = desktop_surface_added, |
| 149 | .surface_removed = desktop_surface_removed, |
| 150 | .committed = desktop_surface_committed, |
| 151 | .move = desktop_surface_move, |
| 152 | .resize = desktop_surface_resize, |
| 153 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 154 | .maximized_requested = desktop_surface_maximized_requested, |
| 155 | .minimized_requested = desktop_surface_minimized_requested, |
| 156 | .ping_timeout = desktop_surface_ping_timeout, |
| 157 | .pong = desktop_surface_pong, |
| 158 | }; |
| 159 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 160 | static void |
| 161 | shell_destroy(struct wl_listener *listener, void *data) |
| 162 | { |
| 163 | struct desktest_shell *dts; |
| 164 | |
| 165 | dts = container_of(listener, struct desktest_shell, |
| 166 | compositor_destroy_listener); |
| 167 | |
| 168 | weston_desktop_destroy(dts->desktop); |
| 169 | weston_view_destroy(dts->background_view); |
| 170 | weston_surface_destroy(dts->background_surface); |
| 171 | free(dts); |
| 172 | } |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 173 | |
| 174 | WL_EXPORT int |
| 175 | wet_shell_init(struct weston_compositor *ec, |
| 176 | int *argc, char *argv[]) |
| 177 | { |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 178 | struct desktest_shell *dts; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 179 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 180 | dts = zalloc(sizeof *dts); |
| 181 | if (!dts) |
| 182 | return -1; |
| 183 | |
| 184 | dts->compositor_destroy_listener.notify = shell_destroy; |
| 185 | wl_signal_add(&ec->destroy_signal, &dts->compositor_destroy_listener); |
| 186 | |
| 187 | weston_layer_init(&dts->layer, ec); |
| 188 | weston_layer_init(&dts->background_layer, ec); |
| 189 | |
| 190 | weston_layer_set_position(&dts->layer, |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 191 | WESTON_LAYER_POSITION_NORMAL); |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 192 | weston_layer_set_position(&dts->background_layer, |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 193 | WESTON_LAYER_POSITION_BACKGROUND); |
| 194 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 195 | dts->background_surface = weston_surface_create(ec); |
| 196 | if (dts->background_surface == NULL) |
| 197 | goto out_free; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 198 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 199 | dts->background_view = weston_view_create(dts->background_surface); |
| 200 | if (dts->background_view == NULL) |
| 201 | goto out_surface; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 202 | |
Pekka Paalanen | a21b5eb | 2017-01-27 17:30:25 +0100 | [diff] [blame] | 203 | weston_surface_set_color(dts->background_surface, 0.16, 0.32, 0.48, 1.); |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 204 | pixman_region32_fini(&dts->background_surface->opaque); |
| 205 | pixman_region32_init_rect(&dts->background_surface->opaque, 0, 0, 2000, 2000); |
| 206 | pixman_region32_fini(&dts->background_surface->input); |
| 207 | pixman_region32_init_rect(&dts->background_surface->input, 0, 0, 2000, 2000); |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 208 | |
Pekka Paalanen | 7bcec20 | 2017-01-27 17:30:24 +0100 | [diff] [blame] | 209 | weston_surface_set_size(dts->background_surface, 2000, 2000); |
| 210 | weston_view_set_position(dts->background_view, 0, 0); |
| 211 | weston_layer_entry_insert(&dts->background_layer.view_list, &dts->background_view->layer_link); |
| 212 | weston_view_update_transform(dts->background_view); |
| 213 | |
| 214 | dts->desktop = weston_desktop_create(ec, &shell_desktop_api, dts); |
| 215 | if (dts->desktop == NULL) |
| 216 | goto out_view; |
| 217 | |
| 218 | return 0; |
| 219 | |
| 220 | out_view: |
| 221 | weston_view_destroy(dts->background_view); |
| 222 | |
| 223 | out_surface: |
| 224 | weston_surface_destroy(dts->background_surface); |
| 225 | |
| 226 | out_free: |
| 227 | free(dts); |
| 228 | |
| 229 | return -1; |
Quentin Glidic | 642bcaf | 2017-01-27 17:30:23 +0100 | [diff] [blame] | 230 | } |