• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdbool.h>
27 #include <stdint.h>
28 #include <time.h>
29 
30 #include <libweston/libweston.h>
31 #include <libweston/xwayland-api.h>
32 
33 #include "weston-desktop-shell-server-protocol.h"
34 
35 enum animation_type {
36 	ANIMATION_NONE,
37 
38 	ANIMATION_ZOOM,
39 	ANIMATION_FADE,
40 	ANIMATION_DIM_LAYER,
41 };
42 
43 enum fade_type {
44 	FADE_IN,
45 	FADE_OUT
46 };
47 
48 enum exposay_target_state {
49 	EXPOSAY_TARGET_OVERVIEW, /* show all windows */
50 	EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */
51 	EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */
52 };
53 
54 enum exposay_layout_state {
55 	EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */
56 	EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */
57 	EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */
58 	EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */
59 };
60 
61 struct exposay_output {
62 	int num_surfaces;
63 	int grid_size;
64 	int surface_size;
65 	int padding_inner;
66 };
67 
68 struct exposay {
69 	/* XXX: Make these exposay_surfaces. */
70 	struct weston_view *focus_prev;
71 	struct weston_view *focus_current;
72 	struct weston_view *clicked;
73 	struct workspace *workspace;
74 	struct weston_seat *seat;
75 
76 	struct wl_list surface_list;
77 
78 	struct weston_keyboard_grab grab_kbd;
79 	struct weston_pointer_grab grab_ptr;
80 
81 	enum exposay_target_state state_target;
82 	enum exposay_layout_state state_cur;
83 	int in_flight; /* number of animations still running */
84 
85 	int row_current;
86 	int column_current;
87 	struct exposay_output *cur_output;
88 
89 	bool mod_pressed;
90 	bool mod_invalid;
91 };
92 
93 struct focus_surface {
94 	struct weston_surface *surface;
95 	struct weston_view *view;
96 	struct weston_transform workspace_transform;
97 };
98 
99 struct workspace {
100 	struct weston_layer layer;
101 
102 	struct wl_list focus_list;
103 	struct wl_listener seat_destroyed_listener;
104 
105 	struct focus_surface *fsurf_front;
106 	struct focus_surface *fsurf_back;
107 	struct weston_view_animation *focus_animation;
108 };
109 
110 struct shell_output {
111 	struct desktop_shell  *shell;
112 	struct weston_output  *output;
113 	struct exposay_output eoutput;
114 	struct wl_listener    destroy_listener;
115 	struct wl_list        link;
116 
117 	struct weston_surface *panel_surface;
118 	struct wl_listener panel_surface_listener;
119 
120 	struct weston_surface *background_surface;
121 	struct wl_listener background_surface_listener;
122 
123 	struct {
124 		struct weston_view *view;
125 		struct weston_view_animation *animation;
126 		enum fade_type type;
127 		struct wl_event_source *startup_timer;
128 	} fade;
129 };
130 
131 struct weston_desktop;
132 struct desktop_shell {
133 	struct weston_compositor *compositor;
134 	struct weston_desktop *desktop;
135 	const struct weston_xwayland_surface_api *xwayland_surface_api;
136 
137 	struct wl_listener idle_listener;
138 	struct wl_listener wake_listener;
139 	struct wl_listener transform_listener;
140 	struct wl_listener resized_listener;
141 	struct wl_listener destroy_listener;
142 	struct wl_listener show_input_panel_listener;
143 	struct wl_listener hide_input_panel_listener;
144 	struct wl_listener update_input_panel_listener;
145 
146 	struct weston_layer fullscreen_layer;
147 	struct weston_layer panel_layer;
148 	struct weston_layer background_layer;
149 	struct weston_layer lock_layer;
150 	struct weston_layer input_panel_layer;
151 
152 	struct wl_listener pointer_focus_listener;
153 	struct weston_surface *grab_surface;
154 
155 	struct {
156 		struct wl_client *client;
157 		struct wl_resource *desktop_shell;
158 		struct wl_listener client_destroy_listener;
159 
160 		unsigned deathcount;
161 		struct timespec deathstamp;
162 	} child;
163 
164 	bool locked;
165 	bool showing_input_panels;
166 	bool prepare_event_sent;
167 
168 	struct text_backend *text_backend;
169 
170 	struct {
171 		struct weston_surface *surface;
172 		pixman_box32_t cursor_rectangle;
173 	} text_input;
174 
175 	struct weston_surface *lock_surface;
176 	struct wl_listener lock_surface_listener;
177 
178 	struct {
179 		struct wl_array array;
180 		unsigned int current;
181 		unsigned int num;
182 
183 		struct wl_list client_list;
184 
185 		struct weston_animation animation;
186 		struct wl_list anim_sticky_list;
187 		int anim_dir;
188 		struct timespec anim_timestamp;
189 		double anim_current;
190 		struct workspace *anim_from;
191 		struct workspace *anim_to;
192 	} workspaces;
193 
194 	struct {
195 		struct wl_resource *binding;
196 		struct wl_list surfaces;
197 	} input_panel;
198 
199 	struct exposay exposay;
200 
201 	bool allow_zap;
202 	uint32_t binding_modifier;
203 	uint32_t exposay_modifier;
204 	enum animation_type win_animation_type;
205 	enum animation_type win_close_animation_type;
206 	enum animation_type startup_animation_type;
207 	enum animation_type focus_animation_type;
208 
209 	struct weston_layer minimized_layer;
210 
211 	struct wl_listener seat_create_listener;
212 	struct wl_listener output_create_listener;
213 	struct wl_listener output_move_listener;
214 	struct wl_list output_list;
215 
216 	enum weston_desktop_shell_panel_position panel_position;
217 
218 	char *client;
219 
220 	struct timespec startup_time;
221 };
222 
223 struct weston_output *
224 get_default_output(struct weston_compositor *compositor);
225 
226 struct weston_view *
227 get_default_view(struct weston_surface *surface);
228 
229 struct shell_surface *
230 get_shell_surface(struct weston_surface *surface);
231 
232 struct workspace *
233 get_current_workspace(struct desktop_shell *shell);
234 
235 void
236 get_output_work_area(struct desktop_shell *shell,
237 		     struct weston_output *output,
238 		     pixman_rectangle32_t *area);
239 
240 void
241 lower_fullscreen_layer(struct desktop_shell *shell,
242 		       struct weston_output *lowering_output);
243 
244 void
245 activate(struct desktop_shell *shell, struct weston_view *view,
246 	 struct weston_seat *seat, uint32_t flags);
247 
248 void
249 exposay_binding(struct weston_keyboard *keyboard,
250 		enum weston_keyboard_modifier modifier,
251 		void *data);
252 int
253 input_panel_setup(struct desktop_shell *shell);
254 void
255 input_panel_destroy(struct desktop_shell *shell);
256 
257 typedef void (*shell_for_each_layer_func_t)(struct desktop_shell *,
258 					    struct weston_layer *, void *);
259 
260 void
261 shell_for_each_layer(struct desktop_shell *shell,
262 		     shell_for_each_layer_func_t func,
263 		     void *data);
264