1 | /*
|
---|
2 | * Copyright (c) 2012 Petr Koupy
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup compositor
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <sys/types.h>
|
---|
36 | #include <stdbool.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <str_error.h>
|
---|
39 | #include <byteorder.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <libc.h>
|
---|
42 |
|
---|
43 | #include <align.h>
|
---|
44 | #include <as.h>
|
---|
45 | #include <malloc.h>
|
---|
46 |
|
---|
47 | #include <atomic.h>
|
---|
48 | #include <fibril_synch.h>
|
---|
49 | #include <adt/prodcons.h>
|
---|
50 | #include <adt/list.h>
|
---|
51 | #include <io/input.h>
|
---|
52 | #include <ipc/graph.h>
|
---|
53 | #include <ipc/window.h>
|
---|
54 |
|
---|
55 | #include <async.h>
|
---|
56 | #include <loc.h>
|
---|
57 |
|
---|
58 | #include <event.h>
|
---|
59 | #include <io/keycode.h>
|
---|
60 | #include <io/mode.h>
|
---|
61 | #include <io/visualizer.h>
|
---|
62 | #include <io/window.h>
|
---|
63 |
|
---|
64 | #include <transform.h>
|
---|
65 | #include <rectangle.h>
|
---|
66 | #include <surface.h>
|
---|
67 | #include <cursor.h>
|
---|
68 | #include <source.h>
|
---|
69 | #include <drawctx.h>
|
---|
70 | #include <codec/tga.h>
|
---|
71 |
|
---|
72 | #include "compositor.h"
|
---|
73 |
|
---|
74 | #define NAME "compositor"
|
---|
75 | #define NAMESPACE "comp"
|
---|
76 |
|
---|
77 | /* Until there is blitter support and some further optimizations, window
|
---|
78 | * animations are too slow to be practically usable. */
|
---|
79 | #ifndef ANIMATE_WINDOW_TRANSFORMS
|
---|
80 | #define ANIMATE_WINDOW_TRANSFORMS 0
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | static char *server_name;
|
---|
84 | static sysarg_t coord_origin;
|
---|
85 | static pixel_t bg_color;
|
---|
86 |
|
---|
87 | typedef struct {
|
---|
88 | link_t link;
|
---|
89 | atomic_t ref_cnt;
|
---|
90 | service_id_t in_dsid;
|
---|
91 | service_id_t out_dsid;
|
---|
92 | prodcons_t queue;
|
---|
93 | transform_t transform;
|
---|
94 | double dx;
|
---|
95 | double dy;
|
---|
96 | double fx;
|
---|
97 | double fy;
|
---|
98 | double angle;
|
---|
99 | uint8_t opacity;
|
---|
100 | surface_t *surface;
|
---|
101 | } window_t;
|
---|
102 |
|
---|
103 | static service_id_t winreg_id;
|
---|
104 | static sysarg_t window_id = 0;
|
---|
105 | static FIBRIL_MUTEX_INITIALIZE(window_list_mtx);
|
---|
106 | static LIST_INITIALIZE(window_list);
|
---|
107 | static double scale_back_x;
|
---|
108 | static double scale_back_y;
|
---|
109 |
|
---|
110 | typedef struct {
|
---|
111 | link_t link;
|
---|
112 | sysarg_t id;
|
---|
113 | uint8_t state;
|
---|
114 | desktop_point_t pos;
|
---|
115 | sysarg_t btn_num;
|
---|
116 | desktop_point_t btn_pos;
|
---|
117 | desktop_vector_t accum;
|
---|
118 | sysarg_t grab_flags;
|
---|
119 | bool pressed;
|
---|
120 | cursor_t cursor;
|
---|
121 | window_t ghost;
|
---|
122 | desktop_vector_t accum_ghost;
|
---|
123 | } pointer_t;
|
---|
124 |
|
---|
125 | static sysarg_t pointer_id = 0;
|
---|
126 | static FIBRIL_MUTEX_INITIALIZE(pointer_list_mtx);
|
---|
127 | static LIST_INITIALIZE(pointer_list);
|
---|
128 |
|
---|
129 | typedef struct {
|
---|
130 | link_t link;
|
---|
131 | service_id_t dsid;
|
---|
132 | vslmode_t mode;
|
---|
133 | async_sess_t *sess;
|
---|
134 | desktop_point_t pos;
|
---|
135 | surface_t *surface;
|
---|
136 | } viewport_t;
|
---|
137 |
|
---|
138 | static desktop_rect_t viewport_bound_rect;
|
---|
139 | static FIBRIL_MUTEX_INITIALIZE(viewport_list_mtx);
|
---|
140 | static LIST_INITIALIZE(viewport_list);
|
---|
141 |
|
---|
142 | static FIBRIL_MUTEX_INITIALIZE(discovery_mtx);
|
---|
143 |
|
---|
144 | /** Input server proxy */
|
---|
145 | static input_t *input;
|
---|
146 |
|
---|
147 | static int comp_key_press(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
|
---|
148 | static int comp_mouse_move(input_t *, int, int);
|
---|
149 | static int comp_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
|
---|
150 | static int comp_mouse_button(input_t *, int, int);
|
---|
151 |
|
---|
152 | static input_ev_ops_t input_ev_ops = {
|
---|
153 | .key = comp_key_press,
|
---|
154 | .move = comp_mouse_move,
|
---|
155 | .abs_move = comp_abs_move,
|
---|
156 | .button = comp_mouse_button
|
---|
157 | };
|
---|
158 |
|
---|
159 | static void input_disconnect(void);
|
---|
160 |
|
---|
161 | static pointer_t *input_pointer(input_t *input)
|
---|
162 | {
|
---|
163 | return input->user;
|
---|
164 | }
|
---|
165 |
|
---|
166 | static pointer_t *pointer_create(void)
|
---|
167 | {
|
---|
168 | pointer_t *p = (pointer_t *) malloc(sizeof(pointer_t));
|
---|
169 | if (!p)
|
---|
170 | return NULL;
|
---|
171 |
|
---|
172 | link_initialize(&p->link);
|
---|
173 | p->pos.x = coord_origin;
|
---|
174 | p->pos.y = coord_origin;
|
---|
175 | p->btn_num = 1;
|
---|
176 | p->btn_pos = p->pos;
|
---|
177 | p->accum.x = 0;
|
---|
178 | p->accum.y = 0;
|
---|
179 | p->grab_flags = GF_EMPTY;
|
---|
180 | p->pressed = false;
|
---|
181 | p->state = 0;
|
---|
182 | cursor_init(&p->cursor, CURSOR_DECODER_EMBEDDED, NULL);
|
---|
183 |
|
---|
184 | /* Ghost window for transformation animation. */
|
---|
185 | transform_identity(&p->ghost.transform);
|
---|
186 | transform_translate(&p->ghost.transform, coord_origin, coord_origin);
|
---|
187 | p->ghost.dx = coord_origin;
|
---|
188 | p->ghost.dy = coord_origin;
|
---|
189 | p->ghost.fx = 1;
|
---|
190 | p->ghost.fy = 1;
|
---|
191 | p->ghost.angle = 0;
|
---|
192 | p->ghost.opacity = 255;
|
---|
193 | p->ghost.surface = NULL;
|
---|
194 | p->accum_ghost.x = 0;
|
---|
195 | p->accum_ghost.y = 0;
|
---|
196 |
|
---|
197 | return p;
|
---|
198 | }
|
---|
199 |
|
---|
200 | static void pointer_destroy(pointer_t *p)
|
---|
201 | {
|
---|
202 | if (p) {
|
---|
203 | cursor_release(&p->cursor);
|
---|
204 | free(p);
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | static window_t *window_create(void)
|
---|
209 | {
|
---|
210 | window_t *win = (window_t *) malloc(sizeof(window_t));
|
---|
211 | if (!win)
|
---|
212 | return NULL;
|
---|
213 |
|
---|
214 | link_initialize(&win->link);
|
---|
215 | atomic_set(&win->ref_cnt, 0);
|
---|
216 | prodcons_initialize(&win->queue);
|
---|
217 | transform_identity(&win->transform);
|
---|
218 | transform_translate(&win->transform, coord_origin, coord_origin);
|
---|
219 | win->dx = coord_origin;
|
---|
220 | win->dy = coord_origin;
|
---|
221 | win->fx = 1;
|
---|
222 | win->fy = 1;
|
---|
223 | win->angle = 0;
|
---|
224 | win->opacity = 255;
|
---|
225 | win->surface = NULL;
|
---|
226 |
|
---|
227 | return win;
|
---|
228 | }
|
---|
229 |
|
---|
230 | static void window_destroy(window_t *win)
|
---|
231 | {
|
---|
232 | if ((win) && (atomic_get(&win->ref_cnt) == 0)) {
|
---|
233 | while (!list_empty(&win->queue.list)) {
|
---|
234 | window_event_t *event = (window_event_t *) list_first(&win->queue.list);
|
---|
235 | list_remove(&event->link);
|
---|
236 | free(event);
|
---|
237 | }
|
---|
238 |
|
---|
239 | if (win->surface)
|
---|
240 | surface_destroy(win->surface);
|
---|
241 |
|
---|
242 | free(win);
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | static bool comp_coord_to_client(sysarg_t x_in, sysarg_t y_in, transform_t win_trans,
|
---|
247 | sysarg_t x_lim, sysarg_t y_lim, sysarg_t *x_out, sysarg_t *y_out)
|
---|
248 | {
|
---|
249 | double x = x_in;
|
---|
250 | double y = y_in;
|
---|
251 | transform_invert(&win_trans);
|
---|
252 | transform_apply_affine(&win_trans, &x, &y);
|
---|
253 |
|
---|
254 | /*
|
---|
255 | * Since client coordinate origin is (0, 0), it is necessary to check
|
---|
256 | * coordinates to avoid underflow. Moreover, it is convenient to also
|
---|
257 | * check against provided upper limits to determine whether the converted
|
---|
258 | * coordinates are within the client window.
|
---|
259 | */
|
---|
260 | if ((x < 0) || (y < 0))
|
---|
261 | return false;
|
---|
262 |
|
---|
263 | (*x_out) = (sysarg_t) (x + 0.5);
|
---|
264 | (*y_out) = (sysarg_t) (y + 0.5);
|
---|
265 |
|
---|
266 | if (((*x_out) >= x_lim) || ((*y_out) >= y_lim))
|
---|
267 | return false;
|
---|
268 |
|
---|
269 | return true;
|
---|
270 | }
|
---|
271 |
|
---|
272 | static void comp_coord_from_client(double x_in, double y_in, transform_t win_trans,
|
---|
273 | sysarg_t *x_out, sysarg_t *y_out)
|
---|
274 | {
|
---|
275 | double x = x_in;
|
---|
276 | double y = y_in;
|
---|
277 | transform_apply_affine(&win_trans, &x, &y);
|
---|
278 |
|
---|
279 | /*
|
---|
280 | * It is assumed that compositor coordinate origin is chosen in such way,
|
---|
281 | * that underflow/overflow here would be unlikely.
|
---|
282 | */
|
---|
283 | (*x_out) = (sysarg_t) (x + 0.5);
|
---|
284 | (*y_out) = (sysarg_t) (y + 0.5);
|
---|
285 | }
|
---|
286 |
|
---|
287 | static void comp_coord_bounding_rect(double x_in, double y_in,
|
---|
288 | double w_in, double h_in, transform_t win_trans,
|
---|
289 | sysarg_t *x_out, sysarg_t *y_out, sysarg_t *w_out, sysarg_t *h_out)
|
---|
290 | {
|
---|
291 | if ((w_in > 0) && (h_in > 0)) {
|
---|
292 | sysarg_t x[4];
|
---|
293 | sysarg_t y[4];
|
---|
294 |
|
---|
295 | comp_coord_from_client(x_in, y_in, win_trans, &x[0], &y[0]);
|
---|
296 | comp_coord_from_client(x_in + w_in - 1, y_in, win_trans, &x[1], &y[1]);
|
---|
297 | comp_coord_from_client(x_in + w_in - 1, y_in + h_in - 1, win_trans, &x[2], &y[2]);
|
---|
298 | comp_coord_from_client(x_in, y_in + h_in - 1, win_trans, &x[3], &y[3]);
|
---|
299 |
|
---|
300 | (*x_out) = x[0];
|
---|
301 | (*y_out) = y[0];
|
---|
302 | (*w_out) = x[0];
|
---|
303 | (*h_out) = y[0];
|
---|
304 |
|
---|
305 | for (unsigned int i = 1; i < 4; ++i) {
|
---|
306 | (*x_out) = (x[i] < (*x_out)) ? x[i] : (*x_out);
|
---|
307 | (*y_out) = (y[i] < (*y_out)) ? y[i] : (*y_out);
|
---|
308 | (*w_out) = (x[i] > (*w_out)) ? x[i] : (*w_out);
|
---|
309 | (*h_out) = (y[i] > (*h_out)) ? y[i] : (*h_out);
|
---|
310 | }
|
---|
311 |
|
---|
312 | (*w_out) = (*w_out) - (*x_out) + 1;
|
---|
313 | (*h_out) = (*h_out) - (*y_out) + 1;
|
---|
314 | } else {
|
---|
315 | (*x_out) = 0;
|
---|
316 | (*y_out) = 0;
|
---|
317 | (*w_out) = 0;
|
---|
318 | (*h_out) = 0;
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | static void comp_update_viewport_bound_rect(void)
|
---|
323 | {
|
---|
324 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
325 |
|
---|
326 | sysarg_t x_res = coord_origin;
|
---|
327 | sysarg_t y_res = coord_origin;
|
---|
328 | sysarg_t w_res = 0;
|
---|
329 | sysarg_t h_res = 0;
|
---|
330 |
|
---|
331 | if (!list_empty(&viewport_list)) {
|
---|
332 | viewport_t *vp = (viewport_t *) list_first(&viewport_list);
|
---|
333 | x_res = vp->pos.x;
|
---|
334 | y_res = vp->pos.y;
|
---|
335 | surface_get_resolution(vp->surface, &w_res, &h_res);
|
---|
336 | }
|
---|
337 |
|
---|
338 | list_foreach(viewport_list, link, viewport_t, vp) {
|
---|
339 | sysarg_t w_vp, h_vp;
|
---|
340 | surface_get_resolution(vp->surface, &w_vp, &h_vp);
|
---|
341 | rectangle_union(x_res, y_res, w_res, h_res,
|
---|
342 | vp->pos.x, vp->pos.y, w_vp, h_vp,
|
---|
343 | &x_res, &y_res, &w_res, &h_res);
|
---|
344 | }
|
---|
345 |
|
---|
346 | viewport_bound_rect.x = x_res;
|
---|
347 | viewport_bound_rect.y = y_res;
|
---|
348 | viewport_bound_rect.w = w_res;
|
---|
349 | viewport_bound_rect.h = h_res;
|
---|
350 |
|
---|
351 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
352 | }
|
---|
353 |
|
---|
354 | static void comp_restrict_pointers(void)
|
---|
355 | {
|
---|
356 | comp_update_viewport_bound_rect();
|
---|
357 |
|
---|
358 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
359 |
|
---|
360 | list_foreach(pointer_list, link, pointer_t, ptr) {
|
---|
361 | ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x;
|
---|
362 | ptr->pos.y = ptr->pos.y > viewport_bound_rect.y ? ptr->pos.y : viewport_bound_rect.y;
|
---|
363 | ptr->pos.x = ptr->pos.x < viewport_bound_rect.x + viewport_bound_rect.w ?
|
---|
364 | ptr->pos.x : viewport_bound_rect.x + viewport_bound_rect.w;
|
---|
365 | ptr->pos.y = ptr->pos.y < viewport_bound_rect.y + viewport_bound_rect.h ?
|
---|
366 | ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h;
|
---|
367 | }
|
---|
368 |
|
---|
369 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
370 | }
|
---|
371 |
|
---|
372 | static void comp_damage(sysarg_t x_dmg_glob, sysarg_t y_dmg_glob,
|
---|
373 | sysarg_t w_dmg_glob, sysarg_t h_dmg_glob)
|
---|
374 | {
|
---|
375 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
376 | fibril_mutex_lock(&window_list_mtx);
|
---|
377 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
378 |
|
---|
379 | list_foreach(viewport_list, link, viewport_t, vp) {
|
---|
380 | /* Determine what part of the viewport must be updated. */
|
---|
381 | sysarg_t x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp;
|
---|
382 | surface_get_resolution(vp->surface, &w_dmg_vp, &h_dmg_vp);
|
---|
383 | bool isec_vp = rectangle_intersect(
|
---|
384 | x_dmg_glob, y_dmg_glob, w_dmg_glob, h_dmg_glob,
|
---|
385 | vp->pos.x, vp->pos.y, w_dmg_vp, h_dmg_vp,
|
---|
386 | &x_dmg_vp, &y_dmg_vp, &w_dmg_vp, &h_dmg_vp);
|
---|
387 |
|
---|
388 | if (isec_vp) {
|
---|
389 |
|
---|
390 | /* Paint background color. */
|
---|
391 | for (sysarg_t y = y_dmg_vp - vp->pos.y; y < y_dmg_vp - vp->pos.y + h_dmg_vp; ++y) {
|
---|
392 | pixel_t *dst = pixelmap_pixel_at(
|
---|
393 | surface_pixmap_access(vp->surface), x_dmg_vp - vp->pos.x, y);
|
---|
394 | sysarg_t count = w_dmg_vp;
|
---|
395 | while (count-- != 0) {
|
---|
396 | *dst++ = bg_color;
|
---|
397 | }
|
---|
398 | }
|
---|
399 | surface_add_damaged_region(vp->surface,
|
---|
400 | x_dmg_vp - vp->pos.x, y_dmg_vp - vp->pos.y, w_dmg_vp, h_dmg_vp);
|
---|
401 |
|
---|
402 | transform_t transform;
|
---|
403 | source_t source;
|
---|
404 | drawctx_t context;
|
---|
405 |
|
---|
406 | source_init(&source);
|
---|
407 | source_set_filter(&source, filter_nearest);
|
---|
408 | drawctx_init(&context, vp->surface);
|
---|
409 | drawctx_set_compose(&context, compose_over);
|
---|
410 | drawctx_set_source(&context, &source);
|
---|
411 |
|
---|
412 | /* For each window. */
|
---|
413 | for (link_t *link = window_list.head.prev;
|
---|
414 | link != &window_list.head; link = link->prev) {
|
---|
415 |
|
---|
416 | /* Determine what part of the window intersects with the
|
---|
417 | * updated area of the current viewport. */
|
---|
418 | window_t *win = list_get_instance(link, window_t, link);
|
---|
419 | if (!win->surface) {
|
---|
420 | continue;
|
---|
421 | }
|
---|
422 | sysarg_t x_dmg_win, y_dmg_win, w_dmg_win, h_dmg_win;
|
---|
423 | surface_get_resolution(win->surface, &w_dmg_win, &h_dmg_win);
|
---|
424 | comp_coord_bounding_rect(0, 0, w_dmg_win, h_dmg_win, win->transform,
|
---|
425 | &x_dmg_win, &y_dmg_win, &w_dmg_win, &h_dmg_win);
|
---|
426 | bool isec_win = rectangle_intersect(
|
---|
427 | x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp,
|
---|
428 | x_dmg_win, y_dmg_win, w_dmg_win, h_dmg_win,
|
---|
429 | &x_dmg_win, &y_dmg_win, &w_dmg_win, &h_dmg_win);
|
---|
430 |
|
---|
431 | if (isec_win) {
|
---|
432 | /* Prepare conversion from global coordinates to viewport
|
---|
433 | * coordinates. */
|
---|
434 | transform = win->transform;
|
---|
435 | double_point_t pos;
|
---|
436 | pos.x = vp->pos.x;
|
---|
437 | pos.y = vp->pos.y;
|
---|
438 | transform_translate(&transform, -pos.x, -pos.y);
|
---|
439 |
|
---|
440 | source_set_transform(&source, transform);
|
---|
441 | source_set_texture(&source, win->surface, false);
|
---|
442 | source_set_alpha(&source, PIXEL(win->opacity, 0, 0, 0));
|
---|
443 |
|
---|
444 | drawctx_transfer(&context,
|
---|
445 | x_dmg_win - vp->pos.x, y_dmg_win - vp->pos.y, w_dmg_win, h_dmg_win);
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | list_foreach(pointer_list, link, pointer_t, ptr) {
|
---|
450 | if (ptr->ghost.surface) {
|
---|
451 |
|
---|
452 | sysarg_t x_bnd_ghost, y_bnd_ghost, w_bnd_ghost, h_bnd_ghost;
|
---|
453 | sysarg_t x_dmg_ghost, y_dmg_ghost, w_dmg_ghost, h_dmg_ghost;
|
---|
454 | surface_get_resolution(ptr->ghost.surface, &w_bnd_ghost, &h_bnd_ghost);
|
---|
455 | comp_coord_bounding_rect(0, 0, w_bnd_ghost, h_bnd_ghost, ptr->ghost.transform,
|
---|
456 | &x_bnd_ghost, &y_bnd_ghost, &w_bnd_ghost, &h_bnd_ghost);
|
---|
457 | bool isec_ghost = rectangle_intersect(
|
---|
458 | x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp,
|
---|
459 | x_bnd_ghost, y_bnd_ghost, w_bnd_ghost, h_bnd_ghost,
|
---|
460 | &x_dmg_ghost, &y_dmg_ghost, &w_dmg_ghost, &h_dmg_ghost);
|
---|
461 |
|
---|
462 | if (isec_ghost) {
|
---|
463 | /* FIXME: Ghost is currently drawn based on the bounding
|
---|
464 | * rectangle of the window, which is sufficient as long
|
---|
465 | * as the windows can be rotated only by 90 degrees.
|
---|
466 | * For ghost to be compatible with arbitrary-angle
|
---|
467 | * rotation, it should be drawn as four lines adjusted
|
---|
468 | * by the transformation matrix. That would however
|
---|
469 | * require to equip libdraw with line drawing functionality. */
|
---|
470 |
|
---|
471 | transform_t transform = ptr->ghost.transform;
|
---|
472 | double_point_t pos;
|
---|
473 | pos.x = vp->pos.x;
|
---|
474 | pos.y = vp->pos.y;
|
---|
475 | transform_translate(&transform, -pos.x, -pos.y);
|
---|
476 |
|
---|
477 | pixel_t ghost_color;
|
---|
478 |
|
---|
479 | if (y_bnd_ghost == y_dmg_ghost) {
|
---|
480 | for (sysarg_t x = x_dmg_ghost - vp->pos.x;
|
---|
481 | x < x_dmg_ghost - vp->pos.x + w_dmg_ghost; ++x) {
|
---|
482 | ghost_color = surface_get_pixel(vp->surface,
|
---|
483 | x, y_dmg_ghost - vp->pos.y);
|
---|
484 | surface_put_pixel(vp->surface,
|
---|
485 | x, y_dmg_ghost - vp->pos.y, INVERT(ghost_color));
|
---|
486 | }
|
---|
487 | }
|
---|
488 |
|
---|
489 | if (y_bnd_ghost + h_bnd_ghost == y_dmg_ghost + h_dmg_ghost) {
|
---|
490 | for (sysarg_t x = x_dmg_ghost - vp->pos.x;
|
---|
491 | x < x_dmg_ghost - vp->pos.x + w_dmg_ghost; ++x) {
|
---|
492 | ghost_color = surface_get_pixel(vp->surface,
|
---|
493 | x, y_dmg_ghost - vp->pos.y + h_dmg_ghost - 1);
|
---|
494 | surface_put_pixel(vp->surface,
|
---|
495 | x, y_dmg_ghost - vp->pos.y + h_dmg_ghost - 1, INVERT(ghost_color));
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | if (x_bnd_ghost == x_dmg_ghost) {
|
---|
500 | for (sysarg_t y = y_dmg_ghost - vp->pos.y;
|
---|
501 | y < y_dmg_ghost - vp->pos.y + h_dmg_ghost; ++y) {
|
---|
502 | ghost_color = surface_get_pixel(vp->surface,
|
---|
503 | x_dmg_ghost - vp->pos.x, y);
|
---|
504 | surface_put_pixel(vp->surface,
|
---|
505 | x_dmg_ghost - vp->pos.x, y, INVERT(ghost_color));
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | if (x_bnd_ghost + w_bnd_ghost == x_dmg_ghost + w_dmg_ghost) {
|
---|
510 | for (sysarg_t y = y_dmg_ghost - vp->pos.y;
|
---|
511 | y < y_dmg_ghost - vp->pos.y + h_dmg_ghost; ++y) {
|
---|
512 | ghost_color = surface_get_pixel(vp->surface,
|
---|
513 | x_dmg_ghost - vp->pos.x + w_dmg_ghost - 1, y);
|
---|
514 | surface_put_pixel(vp->surface,
|
---|
515 | x_dmg_ghost - vp->pos.x + w_dmg_ghost - 1, y, INVERT(ghost_color));
|
---|
516 | }
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | }
|
---|
521 | }
|
---|
522 |
|
---|
523 | list_foreach(pointer_list, link, pointer_t, ptr) {
|
---|
524 |
|
---|
525 | /* Determine what part of the pointer intersects with the
|
---|
526 | * updated area of the current viewport. */
|
---|
527 | sysarg_t x_dmg_ptr, y_dmg_ptr, w_dmg_ptr, h_dmg_ptr;
|
---|
528 | surface_t *sf_ptr = ptr->cursor.states[ptr->state];
|
---|
529 | surface_get_resolution(sf_ptr, &w_dmg_ptr, &h_dmg_ptr);
|
---|
530 | bool isec_ptr = rectangle_intersect(
|
---|
531 | x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp,
|
---|
532 | ptr->pos.x, ptr->pos.y, w_dmg_ptr, h_dmg_ptr,
|
---|
533 | &x_dmg_ptr, &y_dmg_ptr, &w_dmg_ptr, &h_dmg_ptr);
|
---|
534 |
|
---|
535 | if (isec_ptr) {
|
---|
536 | /* Pointer is currently painted directly by copying pixels.
|
---|
537 | * However, it is possible to draw the pointer similarly
|
---|
538 | * as window by using drawctx_transfer. It would allow
|
---|
539 | * more sophisticated control over drawing, but would also
|
---|
540 | * cost more regarding the performance. */
|
---|
541 |
|
---|
542 | sysarg_t x_vp = x_dmg_ptr - vp->pos.x;
|
---|
543 | sysarg_t y_vp = y_dmg_ptr - vp->pos.y;
|
---|
544 | sysarg_t x_ptr = x_dmg_ptr - ptr->pos.x;
|
---|
545 | sysarg_t y_ptr = y_dmg_ptr - ptr->pos.y;
|
---|
546 |
|
---|
547 | for (sysarg_t y = 0; y < h_dmg_ptr; ++y) {
|
---|
548 | pixel_t *src = pixelmap_pixel_at(
|
---|
549 | surface_pixmap_access(sf_ptr), x_ptr, y_ptr + y);
|
---|
550 | pixel_t *dst = pixelmap_pixel_at(
|
---|
551 | surface_pixmap_access(vp->surface), x_vp, y_vp + y);
|
---|
552 | sysarg_t count = w_dmg_ptr;
|
---|
553 | while (count-- != 0) {
|
---|
554 | *dst = (*src & 0xff000000) ? *src : *dst;
|
---|
555 | ++dst; ++src;
|
---|
556 | }
|
---|
557 | }
|
---|
558 | surface_add_damaged_region(vp->surface, x_vp, y_vp, w_dmg_ptr, h_dmg_ptr);
|
---|
559 | }
|
---|
560 |
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 |
|
---|
565 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
566 | fibril_mutex_unlock(&window_list_mtx);
|
---|
567 |
|
---|
568 | /* Notify visualizers about updated regions. */
|
---|
569 | list_foreach(viewport_list, link, viewport_t, vp) {
|
---|
570 | sysarg_t x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp;
|
---|
571 | surface_get_damaged_region(vp->surface, &x_dmg_vp, &y_dmg_vp, &w_dmg_vp, &h_dmg_vp);
|
---|
572 | surface_reset_damaged_region(vp->surface);
|
---|
573 | visualizer_update_damaged_region(
|
---|
574 | vp->sess, x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp, 0, 0);
|
---|
575 | }
|
---|
576 |
|
---|
577 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
578 | }
|
---|
579 |
|
---|
580 | static void comp_window_get_event(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
581 | {
|
---|
582 | window_event_t *event = (window_event_t *) prodcons_consume(&win->queue);
|
---|
583 |
|
---|
584 | ipc_callid_t callid;
|
---|
585 | size_t len;
|
---|
586 |
|
---|
587 | if (!async_data_read_receive(&callid, &len)) {
|
---|
588 | async_answer_0(iid, EINVAL);
|
---|
589 | free(event);
|
---|
590 | return;
|
---|
591 | }
|
---|
592 |
|
---|
593 | int rc = async_data_read_finalize(callid, event, len);
|
---|
594 | if (rc != EOK) {
|
---|
595 | async_answer_0(iid, ENOMEM);
|
---|
596 | free(event);
|
---|
597 | return;
|
---|
598 | }
|
---|
599 |
|
---|
600 | async_answer_0(iid, EOK);
|
---|
601 | free(event);
|
---|
602 | }
|
---|
603 |
|
---|
604 | static void comp_window_damage(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
605 | {
|
---|
606 | double x = IPC_GET_ARG1(*icall);
|
---|
607 | double y = IPC_GET_ARG2(*icall);
|
---|
608 | double width = IPC_GET_ARG3(*icall);
|
---|
609 | double height = IPC_GET_ARG4(*icall);
|
---|
610 |
|
---|
611 | if ((width == 0) || (height == 0)) {
|
---|
612 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
613 | } else {
|
---|
614 | fibril_mutex_lock(&window_list_mtx);
|
---|
615 | sysarg_t x_dmg_glob, y_dmg_glob, w_dmg_glob, h_dmg_glob;
|
---|
616 | comp_coord_bounding_rect(x - 1, y - 1, width + 2, height + 2,
|
---|
617 | win->transform, &x_dmg_glob, &y_dmg_glob, &w_dmg_glob, &h_dmg_glob);
|
---|
618 | fibril_mutex_unlock(&window_list_mtx);
|
---|
619 | comp_damage(x_dmg_glob, y_dmg_glob, w_dmg_glob, h_dmg_glob);
|
---|
620 | }
|
---|
621 |
|
---|
622 | async_answer_0(iid, EOK);
|
---|
623 | }
|
---|
624 |
|
---|
625 | static void comp_window_grab(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
626 | {
|
---|
627 | sysarg_t pos_id = IPC_GET_ARG1(*icall);
|
---|
628 | sysarg_t grab_flags = IPC_GET_ARG2(*icall);
|
---|
629 |
|
---|
630 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
631 | list_foreach(pointer_list, link, pointer_t, pointer) {
|
---|
632 | if (pointer->id == pos_id) {
|
---|
633 | pointer->grab_flags = pointer->pressed ? grab_flags : GF_EMPTY;
|
---|
634 | // TODO change pointer->state according to grab_flags
|
---|
635 | break;
|
---|
636 | }
|
---|
637 | }
|
---|
638 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
639 |
|
---|
640 | if ((grab_flags & GF_RESIZE_X) || (grab_flags & GF_RESIZE_Y)) {
|
---|
641 | scale_back_x = 1;
|
---|
642 | scale_back_y = 1;
|
---|
643 | }
|
---|
644 |
|
---|
645 | async_answer_0(iid, EOK);
|
---|
646 | }
|
---|
647 |
|
---|
648 | static void comp_recalc_transform(window_t *win)
|
---|
649 | {
|
---|
650 | transform_t translate;
|
---|
651 | transform_identity(&translate);
|
---|
652 | transform_translate(&translate, win->dx, win->dy);
|
---|
653 |
|
---|
654 | transform_t scale;
|
---|
655 | transform_identity(&scale);
|
---|
656 | if ((win->fx != 1) || (win->fy != 1))
|
---|
657 | transform_scale(&scale, win->fx, win->fy);
|
---|
658 |
|
---|
659 | transform_t rotate;
|
---|
660 | transform_identity(&rotate);
|
---|
661 | if (win->angle != 0)
|
---|
662 | transform_rotate(&rotate, win->angle);
|
---|
663 |
|
---|
664 | transform_t transform;
|
---|
665 | transform_t temp;
|
---|
666 | transform_identity(&transform);
|
---|
667 | temp = transform;
|
---|
668 | transform_product(&transform, &temp, &translate);
|
---|
669 | temp = transform;
|
---|
670 | transform_product(&transform, &temp, &rotate);
|
---|
671 | temp = transform;
|
---|
672 | transform_product(&transform, &temp, &scale);
|
---|
673 |
|
---|
674 | win->transform = transform;
|
---|
675 | }
|
---|
676 |
|
---|
677 | static void comp_window_resize(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
678 | {
|
---|
679 | ipc_callid_t callid;
|
---|
680 | size_t size;
|
---|
681 | unsigned int flags;
|
---|
682 |
|
---|
683 | /* Start sharing resized window with client. */
|
---|
684 | if (!async_share_out_receive(&callid, &size, &flags)) {
|
---|
685 | async_answer_0(iid, EINVAL);
|
---|
686 | return;
|
---|
687 | }
|
---|
688 |
|
---|
689 | void *new_cell_storage;
|
---|
690 | int rc = async_share_out_finalize(callid, &new_cell_storage);
|
---|
691 | if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
|
---|
692 | async_answer_0(iid, ENOMEM);
|
---|
693 | return;
|
---|
694 | }
|
---|
695 |
|
---|
696 | /* Create new surface for the resized window. */
|
---|
697 | surface_t *new_surface = surface_create(IPC_GET_ARG3(*icall),
|
---|
698 | IPC_GET_ARG4(*icall), new_cell_storage, SURFACE_FLAG_SHARED);
|
---|
699 | if (!new_surface) {
|
---|
700 | as_area_destroy(new_cell_storage);
|
---|
701 | async_answer_0(iid, ENOMEM);
|
---|
702 | return;
|
---|
703 | }
|
---|
704 |
|
---|
705 | sysarg_t offset_x = IPC_GET_ARG1(*icall);
|
---|
706 | sysarg_t offset_y = IPC_GET_ARG2(*icall);
|
---|
707 | window_placement_flags_t placement_flags =
|
---|
708 | (window_placement_flags_t) IPC_GET_ARG5(*icall);
|
---|
709 |
|
---|
710 | comp_update_viewport_bound_rect();
|
---|
711 |
|
---|
712 | /* Switch new surface with old surface and calculate damage. */
|
---|
713 | fibril_mutex_lock(&window_list_mtx);
|
---|
714 |
|
---|
715 | sysarg_t old_width = 0;
|
---|
716 | sysarg_t old_height = 0;
|
---|
717 |
|
---|
718 | if (win->surface) {
|
---|
719 | surface_get_resolution(win->surface, &old_width, &old_height);
|
---|
720 | surface_destroy(win->surface);
|
---|
721 | }
|
---|
722 |
|
---|
723 | win->surface = new_surface;
|
---|
724 |
|
---|
725 | sysarg_t new_width = 0;
|
---|
726 | sysarg_t new_height = 0;
|
---|
727 | surface_get_resolution(win->surface, &new_width, &new_height);
|
---|
728 |
|
---|
729 | if (placement_flags & WINDOW_PLACEMENT_CENTER_X)
|
---|
730 | win->dx = viewport_bound_rect.x + viewport_bound_rect.w / 2 -
|
---|
731 | new_width / 2;
|
---|
732 |
|
---|
733 | if (placement_flags & WINDOW_PLACEMENT_CENTER_Y)
|
---|
734 | win->dy = viewport_bound_rect.y + viewport_bound_rect.h / 2 -
|
---|
735 | new_height / 2;
|
---|
736 |
|
---|
737 | if (placement_flags & WINDOW_PLACEMENT_LEFT)
|
---|
738 | win->dx = viewport_bound_rect.x;
|
---|
739 |
|
---|
740 | if (placement_flags & WINDOW_PLACEMENT_TOP)
|
---|
741 | win->dy = viewport_bound_rect.y;
|
---|
742 |
|
---|
743 | if (placement_flags & WINDOW_PLACEMENT_RIGHT)
|
---|
744 | win->dx = viewport_bound_rect.x + viewport_bound_rect.w -
|
---|
745 | new_width;
|
---|
746 |
|
---|
747 | if (placement_flags & WINDOW_PLACEMENT_BOTTOM)
|
---|
748 | win->dy = viewport_bound_rect.y + viewport_bound_rect.h -
|
---|
749 | new_height;
|
---|
750 |
|
---|
751 | if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_X)
|
---|
752 | win->dx = coord_origin + offset_x;
|
---|
753 |
|
---|
754 | if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_Y)
|
---|
755 | win->dy = coord_origin + offset_y;
|
---|
756 |
|
---|
757 | /* Transform the window and calculate damage. */
|
---|
758 | sysarg_t x1;
|
---|
759 | sysarg_t y1;
|
---|
760 | sysarg_t width1;
|
---|
761 | sysarg_t height1;
|
---|
762 |
|
---|
763 | comp_coord_bounding_rect(0, 0, old_width, old_height, win->transform,
|
---|
764 | &x1, &y1, &width1, &height1);
|
---|
765 |
|
---|
766 | comp_recalc_transform(win);
|
---|
767 |
|
---|
768 | sysarg_t x2;
|
---|
769 | sysarg_t y2;
|
---|
770 | sysarg_t width2;
|
---|
771 | sysarg_t height2;
|
---|
772 |
|
---|
773 | comp_coord_bounding_rect(0, 0, new_width, new_height, win->transform,
|
---|
774 | &x2, &y2, &width2, &height2);
|
---|
775 |
|
---|
776 | sysarg_t x;
|
---|
777 | sysarg_t y;
|
---|
778 | sysarg_t width;
|
---|
779 | sysarg_t height;
|
---|
780 |
|
---|
781 | rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
782 | &x, &y, &width, &height);
|
---|
783 |
|
---|
784 | fibril_mutex_unlock(&window_list_mtx);
|
---|
785 |
|
---|
786 | comp_damage(x, y, width, height);
|
---|
787 |
|
---|
788 | async_answer_0(iid, EOK);
|
---|
789 | }
|
---|
790 |
|
---|
791 | static void comp_post_event_win(window_event_t *event, window_t *target)
|
---|
792 | {
|
---|
793 | fibril_mutex_lock(&window_list_mtx);
|
---|
794 |
|
---|
795 | list_foreach(window_list, link, window_t, window) {
|
---|
796 | if (window == target) {
|
---|
797 | prodcons_produce(&window->queue, &event->link);
|
---|
798 | fibril_mutex_unlock(&window_list_mtx);
|
---|
799 | return;
|
---|
800 | }
|
---|
801 | }
|
---|
802 |
|
---|
803 | fibril_mutex_unlock(&window_list_mtx);
|
---|
804 | free(event);
|
---|
805 | }
|
---|
806 |
|
---|
807 | static void comp_post_event_top(window_event_t *event)
|
---|
808 | {
|
---|
809 | fibril_mutex_lock(&window_list_mtx);
|
---|
810 |
|
---|
811 | window_t *win = (window_t *) list_first(&window_list);
|
---|
812 | if (win)
|
---|
813 | prodcons_produce(&win->queue, &event->link);
|
---|
814 | else
|
---|
815 | free(event);
|
---|
816 |
|
---|
817 | fibril_mutex_unlock(&window_list_mtx);
|
---|
818 | }
|
---|
819 |
|
---|
820 | static void comp_window_close(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
821 | {
|
---|
822 | /* Stop managing the window. */
|
---|
823 | fibril_mutex_lock(&window_list_mtx);
|
---|
824 | list_remove(&win->link);
|
---|
825 | window_t *win_focus = (window_t *) list_first(&window_list);
|
---|
826 | window_event_t *event_focus = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
827 | if (event_focus) {
|
---|
828 | link_initialize(&event_focus->link);
|
---|
829 | event_focus->type = ET_WINDOW_FOCUS;
|
---|
830 | }
|
---|
831 | fibril_mutex_unlock(&window_list_mtx);
|
---|
832 |
|
---|
833 | if (event_focus && win_focus) {
|
---|
834 | comp_post_event_win(event_focus, win_focus);
|
---|
835 | }
|
---|
836 |
|
---|
837 | loc_service_unregister(win->in_dsid);
|
---|
838 | loc_service_unregister(win->out_dsid);
|
---|
839 |
|
---|
840 | /* In case the client was killed, input fibril of the window might be
|
---|
841 | * still blocked on the condition within comp_window_get_event. */
|
---|
842 | window_event_t *event_dummy = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
843 | if (event_dummy) {
|
---|
844 | link_initialize(&event_dummy->link);
|
---|
845 | prodcons_produce(&win->queue, &event_dummy->link);
|
---|
846 | }
|
---|
847 |
|
---|
848 | /* Calculate damage. */
|
---|
849 | sysarg_t x = 0;
|
---|
850 | sysarg_t y = 0;
|
---|
851 | sysarg_t width = 0;
|
---|
852 | sysarg_t height = 0;
|
---|
853 | if (win->surface) {
|
---|
854 | surface_get_resolution(win->surface, &width, &height);
|
---|
855 | comp_coord_bounding_rect(
|
---|
856 | 0, 0, width, height, win->transform, &x, &y, &width, &height);
|
---|
857 | }
|
---|
858 |
|
---|
859 | comp_damage(x, y, width, height);
|
---|
860 | async_answer_0(iid, EOK);
|
---|
861 | }
|
---|
862 |
|
---|
863 | static void comp_window_close_request(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
|
---|
864 | {
|
---|
865 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
866 | if (event == NULL) {
|
---|
867 | async_answer_0(iid, ENOMEM);
|
---|
868 | return;
|
---|
869 | }
|
---|
870 |
|
---|
871 | link_initialize(&event->link);
|
---|
872 | event->type = ET_WINDOW_CLOSE;
|
---|
873 |
|
---|
874 | prodcons_produce(&win->queue, &event->link);
|
---|
875 | async_answer_0(iid, EOK);
|
---|
876 | }
|
---|
877 |
|
---|
878 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
879 | {
|
---|
880 | ipc_call_t call;
|
---|
881 | ipc_callid_t callid;
|
---|
882 | service_id_t service_id = (service_id_t) IPC_GET_ARG1(*icall);
|
---|
883 |
|
---|
884 | /* Allocate resources for new window and register it to the location service. */
|
---|
885 | if (service_id == winreg_id) {
|
---|
886 | async_answer_0(iid, EOK);
|
---|
887 |
|
---|
888 | callid = async_get_call(&call);
|
---|
889 | if (IPC_GET_IMETHOD(call) == WINDOW_REGISTER) {
|
---|
890 | fibril_mutex_lock(&window_list_mtx);
|
---|
891 |
|
---|
892 | window_t *win = window_create();
|
---|
893 | if (!win) {
|
---|
894 | async_answer_2(callid, ENOMEM, 0, 0);
|
---|
895 | return;
|
---|
896 | }
|
---|
897 |
|
---|
898 | char name_in[LOC_NAME_MAXLEN + 1];
|
---|
899 | snprintf(name_in, LOC_NAME_MAXLEN, "%s%s/win%zuin", NAMESPACE,
|
---|
900 | server_name, window_id);
|
---|
901 |
|
---|
902 | char name_out[LOC_NAME_MAXLEN + 1];
|
---|
903 | snprintf(name_out, LOC_NAME_MAXLEN, "%s%s/win%zuout", NAMESPACE,
|
---|
904 | server_name, window_id);
|
---|
905 |
|
---|
906 | ++window_id;
|
---|
907 |
|
---|
908 | if (loc_service_register(name_in, &win->in_dsid) != EOK) {
|
---|
909 | window_destroy(win);
|
---|
910 | async_answer_2(callid, EINVAL, 0, 0);
|
---|
911 | return;
|
---|
912 | }
|
---|
913 |
|
---|
914 | if (loc_service_register(name_out, &win->out_dsid) != EOK) {
|
---|
915 | loc_service_unregister(win->in_dsid);
|
---|
916 | window_destroy(win);
|
---|
917 | async_answer_2(callid, EINVAL, 0, 0);
|
---|
918 | return;
|
---|
919 | }
|
---|
920 |
|
---|
921 | window_t *win_unfocus = (window_t *) list_first(&window_list);
|
---|
922 | list_prepend(&win->link, &window_list);
|
---|
923 |
|
---|
924 | window_event_t *event_unfocus = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
925 | if (event_unfocus) {
|
---|
926 | link_initialize(&event_unfocus->link);
|
---|
927 | event_unfocus->type = ET_WINDOW_UNFOCUS;
|
---|
928 | }
|
---|
929 |
|
---|
930 | async_answer_2(callid, EOK, win->in_dsid, win->out_dsid);
|
---|
931 | fibril_mutex_unlock(&window_list_mtx);
|
---|
932 |
|
---|
933 | if (event_unfocus && win_unfocus) {
|
---|
934 | comp_post_event_win(event_unfocus, win_unfocus);
|
---|
935 | }
|
---|
936 |
|
---|
937 | return;
|
---|
938 | } else {
|
---|
939 | async_answer_0(callid, EINVAL);
|
---|
940 | return;
|
---|
941 | }
|
---|
942 | }
|
---|
943 |
|
---|
944 | /* Match the client with pre-allocated window. */
|
---|
945 | window_t *win = NULL;
|
---|
946 | fibril_mutex_lock(&window_list_mtx);
|
---|
947 | list_foreach(window_list, link, window_t, cur) {
|
---|
948 | if (cur->in_dsid == service_id || cur->out_dsid == service_id) {
|
---|
949 | win = cur;
|
---|
950 | break;
|
---|
951 | }
|
---|
952 | }
|
---|
953 | fibril_mutex_unlock(&window_list_mtx);
|
---|
954 |
|
---|
955 | if (win) {
|
---|
956 | atomic_inc(&win->ref_cnt);
|
---|
957 | async_answer_0(iid, EOK);
|
---|
958 | } else {
|
---|
959 | async_answer_0(iid, EINVAL);
|
---|
960 | return;
|
---|
961 | }
|
---|
962 |
|
---|
963 | /* Each client establishes two separate connections. */
|
---|
964 | if (win->in_dsid == service_id) {
|
---|
965 | while (true) {
|
---|
966 | callid = async_get_call(&call);
|
---|
967 |
|
---|
968 | if (!IPC_GET_IMETHOD(call)) {
|
---|
969 | async_answer_0(callid, EOK);
|
---|
970 | atomic_dec(&win->ref_cnt);
|
---|
971 | window_destroy(win);
|
---|
972 | return;
|
---|
973 | }
|
---|
974 |
|
---|
975 | switch (IPC_GET_IMETHOD(call)) {
|
---|
976 | case WINDOW_GET_EVENT:
|
---|
977 | comp_window_get_event(win, callid, &call);
|
---|
978 | break;
|
---|
979 | default:
|
---|
980 | async_answer_0(callid, EINVAL);
|
---|
981 | }
|
---|
982 | }
|
---|
983 | } else if (win->out_dsid == service_id) {
|
---|
984 | while (true) {
|
---|
985 | callid = async_get_call(&call);
|
---|
986 |
|
---|
987 | if (!IPC_GET_IMETHOD(call)) {
|
---|
988 | comp_window_close(win, callid, &call);
|
---|
989 | atomic_dec(&win->ref_cnt);
|
---|
990 | window_destroy(win);
|
---|
991 | return;
|
---|
992 | }
|
---|
993 |
|
---|
994 | switch (IPC_GET_IMETHOD(call)) {
|
---|
995 | case WINDOW_DAMAGE:
|
---|
996 | comp_window_damage(win, callid, &call);
|
---|
997 | break;
|
---|
998 | case WINDOW_GRAB:
|
---|
999 | comp_window_grab(win, callid, &call);
|
---|
1000 | break;
|
---|
1001 | case WINDOW_RESIZE:
|
---|
1002 | comp_window_resize(win, callid, &call);
|
---|
1003 | break;
|
---|
1004 | case WINDOW_CLOSE:
|
---|
1005 | /*
|
---|
1006 | * Postpone the closing until the phone is hung up to cover
|
---|
1007 | * the case when the client is killed abruptly.
|
---|
1008 | */
|
---|
1009 | async_answer_0(callid, EOK);
|
---|
1010 | break;
|
---|
1011 | case WINDOW_CLOSE_REQUEST:
|
---|
1012 | comp_window_close_request(win, callid, &call);
|
---|
1013 | break;
|
---|
1014 | default:
|
---|
1015 | async_answer_0(callid, EINVAL);
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | static void comp_mode_change(viewport_t *vp, ipc_callid_t iid, ipc_call_t *icall)
|
---|
1022 | {
|
---|
1023 | sysarg_t mode_idx = IPC_GET_ARG2(*icall);
|
---|
1024 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
1025 |
|
---|
1026 | /* Retrieve the mode that shall be set. */
|
---|
1027 | vslmode_t new_mode;
|
---|
1028 | int rc = visualizer_get_mode(vp->sess, &new_mode, mode_idx);
|
---|
1029 | if (rc != EOK) {
|
---|
1030 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1031 | async_answer_0(iid, EINVAL);
|
---|
1032 | return;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | /* Create surface with respect to the retrieved mode. */
|
---|
1036 | surface_t *new_surface = surface_create(new_mode.screen_width,
|
---|
1037 | new_mode.screen_height, NULL, SURFACE_FLAG_SHARED);
|
---|
1038 | if (!new_surface) {
|
---|
1039 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1040 | async_answer_0(iid, ENOMEM);
|
---|
1041 | return;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | /* Try to set the mode and share out the surface. */
|
---|
1045 | rc = visualizer_set_mode(vp->sess,
|
---|
1046 | new_mode.index, new_mode.version, surface_direct_access(new_surface));
|
---|
1047 | if (rc != EOK) {
|
---|
1048 | surface_destroy(new_surface);
|
---|
1049 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1050 | async_answer_0(iid, rc);
|
---|
1051 | return;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | /* Destroy old surface and update viewport. */
|
---|
1055 | surface_destroy(vp->surface);
|
---|
1056 | vp->mode = new_mode;
|
---|
1057 | vp->surface = new_surface;
|
---|
1058 |
|
---|
1059 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1060 | async_answer_0(iid, EOK);
|
---|
1061 |
|
---|
1062 | comp_restrict_pointers();
|
---|
1063 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | static void viewport_destroy(viewport_t *vp)
|
---|
1067 | {
|
---|
1068 | if (vp) {
|
---|
1069 | visualizer_yield(vp->sess);
|
---|
1070 | surface_destroy(vp->surface);
|
---|
1071 | async_hangup(vp->sess);
|
---|
1072 | free(vp);
|
---|
1073 | }
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | static void comp_visualizer_disconnect(viewport_t *vp, ipc_callid_t iid, ipc_call_t *icall)
|
---|
1077 | {
|
---|
1078 | /* Release viewport resources. */
|
---|
1079 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
1080 |
|
---|
1081 | list_remove(&vp->link);
|
---|
1082 | viewport_destroy(vp);
|
---|
1083 |
|
---|
1084 | /* Terminate compositor if there are no more viewports. */
|
---|
1085 | if (list_empty(&viewport_list)) {
|
---|
1086 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1087 | loc_service_unregister(winreg_id);
|
---|
1088 | input_disconnect();
|
---|
1089 |
|
---|
1090 | /* Close all clients and their windows. */
|
---|
1091 | fibril_mutex_lock(&window_list_mtx);
|
---|
1092 | list_foreach(window_list, link, window_t, win) {
|
---|
1093 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1094 | if (event) {
|
---|
1095 | link_initialize(&event->link);
|
---|
1096 | event->type = WINDOW_CLOSE;
|
---|
1097 | prodcons_produce(&win->queue, &event->link);
|
---|
1098 | }
|
---|
1099 | }
|
---|
1100 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1101 |
|
---|
1102 | async_answer_0(iid, EOK);
|
---|
1103 |
|
---|
1104 | /* All fibrils of the compositor will terminate soon. */
|
---|
1105 | } else {
|
---|
1106 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1107 | async_answer_0(iid, EOK);
|
---|
1108 |
|
---|
1109 | comp_restrict_pointers();
|
---|
1110 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | static void vsl_notifications(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
1115 | {
|
---|
1116 | viewport_t *vp = NULL;
|
---|
1117 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
1118 | list_foreach(viewport_list, link, viewport_t, cur) {
|
---|
1119 | if (cur->dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
|
---|
1120 | vp = cur;
|
---|
1121 | break;
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1125 |
|
---|
1126 | if (!vp)
|
---|
1127 | return;
|
---|
1128 |
|
---|
1129 | /* Ignore parameters, the connection is already opened. */
|
---|
1130 | while (true) {
|
---|
1131 | ipc_call_t call;
|
---|
1132 | ipc_callid_t callid = async_get_call(&call);
|
---|
1133 |
|
---|
1134 | if (!IPC_GET_IMETHOD(call)) {
|
---|
1135 | async_hangup(vp->sess);
|
---|
1136 | return;
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | switch (IPC_GET_IMETHOD(call)) {
|
---|
1140 | case VISUALIZER_MODE_CHANGE:
|
---|
1141 | comp_mode_change(vp, callid, &call);
|
---|
1142 | break;
|
---|
1143 | case VISUALIZER_DISCONNECT:
|
---|
1144 | comp_visualizer_disconnect(vp, callid, &call);
|
---|
1145 | return;
|
---|
1146 | default:
|
---|
1147 | async_answer_0(callid, EINVAL);
|
---|
1148 | }
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | static async_sess_t *vsl_connect(service_id_t sid, const char *svc)
|
---|
1153 | {
|
---|
1154 | int rc;
|
---|
1155 | async_sess_t *sess;
|
---|
1156 |
|
---|
1157 | sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 0);
|
---|
1158 | if (sess == NULL) {
|
---|
1159 | printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
|
---|
1160 | return NULL;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
1164 | rc = async_connect_to_me(exch, sid, 0, 0, vsl_notifications, NULL);
|
---|
1165 | async_exchange_end(exch);
|
---|
1166 |
|
---|
1167 | if (rc != EOK) {
|
---|
1168 | async_hangup(sess);
|
---|
1169 | printf("%s: Unable to create callback connection to service %s (%s)\n",
|
---|
1170 | NAME, svc, str_error(rc));
|
---|
1171 | return NULL;
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 | return sess;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | static viewport_t *viewport_create(service_id_t sid)
|
---|
1178 | {
|
---|
1179 | int rc;
|
---|
1180 | char *vsl_name = NULL;
|
---|
1181 | viewport_t *vp = NULL;
|
---|
1182 | bool claimed = false;
|
---|
1183 |
|
---|
1184 | rc = loc_service_get_name(sid, &vsl_name);
|
---|
1185 | if (rc != EOK)
|
---|
1186 | goto error;
|
---|
1187 |
|
---|
1188 | vp = (viewport_t *) calloc(1, sizeof(viewport_t));
|
---|
1189 | if (!vp)
|
---|
1190 | goto error;
|
---|
1191 |
|
---|
1192 | link_initialize(&vp->link);
|
---|
1193 | vp->pos.x = coord_origin;
|
---|
1194 | vp->pos.y = coord_origin;
|
---|
1195 |
|
---|
1196 | /* Establish output bidirectional connection. */
|
---|
1197 | vp->dsid = sid;
|
---|
1198 | vp->sess = vsl_connect(sid, vsl_name);
|
---|
1199 | if (vp->sess == NULL)
|
---|
1200 | goto error;
|
---|
1201 |
|
---|
1202 | /* Claim the given visualizer. */
|
---|
1203 | rc = visualizer_claim(vp->sess, 0);
|
---|
1204 | if (rc != EOK) {
|
---|
1205 | printf("%s: Unable to claim visualizer (%s)\n", NAME, str_error(rc));
|
---|
1206 | goto error;
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | claimed = true;
|
---|
1210 |
|
---|
1211 | /* Retrieve the default mode. */
|
---|
1212 | rc = visualizer_get_default_mode(vp->sess, &vp->mode);
|
---|
1213 | if (rc != EOK) {
|
---|
1214 | printf("%s: Unable to retrieve mode (%s)\n", NAME, str_error(rc));
|
---|
1215 | goto error;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | /* Create surface with respect to the retrieved mode. */
|
---|
1219 | vp->surface = surface_create(vp->mode.screen_width, vp->mode.screen_height,
|
---|
1220 | NULL, SURFACE_FLAG_SHARED);
|
---|
1221 | if (vp->surface == NULL) {
|
---|
1222 | printf("%s: Unable to create surface (%s)\n", NAME, str_error(rc));
|
---|
1223 | goto error;
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | /* Try to set the mode and share out the surface. */
|
---|
1227 | rc = visualizer_set_mode(vp->sess,
|
---|
1228 | vp->mode.index, vp->mode.version, surface_direct_access(vp->surface));
|
---|
1229 | if (rc != EOK) {
|
---|
1230 | printf("%s: Unable to set mode (%s)\n", NAME, str_error(rc));
|
---|
1231 | goto error;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | return vp;
|
---|
1235 | error:
|
---|
1236 | if (claimed)
|
---|
1237 | visualizer_yield(vp->sess);
|
---|
1238 |
|
---|
1239 | if (vp->sess != NULL)
|
---|
1240 | async_hangup(vp->sess);
|
---|
1241 |
|
---|
1242 | free(vp);
|
---|
1243 | free(vsl_name);
|
---|
1244 | return NULL;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | static void comp_window_animate(pointer_t *pointer, window_t *win,
|
---|
1248 | sysarg_t *dmg_x, sysarg_t *dmg_y, sysarg_t *dmg_width, sysarg_t *dmg_height)
|
---|
1249 | {
|
---|
1250 | /* window_list_mtx locked by caller */
|
---|
1251 | /* pointer_list_mtx locked by caller */
|
---|
1252 |
|
---|
1253 | int dx = pointer->accum.x;
|
---|
1254 | int dy = pointer->accum.y;
|
---|
1255 | pointer->accum.x = 0;
|
---|
1256 | pointer->accum.y = 0;
|
---|
1257 |
|
---|
1258 | bool move = (pointer->grab_flags & GF_MOVE_X) || (pointer->grab_flags & GF_MOVE_Y);
|
---|
1259 | bool scale = (pointer->grab_flags & GF_SCALE_X) || (pointer->grab_flags & GF_SCALE_Y);
|
---|
1260 | bool resize = (pointer->grab_flags & GF_RESIZE_X) || (pointer->grab_flags & GF_RESIZE_Y);
|
---|
1261 |
|
---|
1262 | sysarg_t width, height;
|
---|
1263 | surface_get_resolution(win->surface, &width, &height);
|
---|
1264 |
|
---|
1265 | if (move) {
|
---|
1266 | double cx = 0;
|
---|
1267 | double cy = 0;
|
---|
1268 |
|
---|
1269 | if (pointer->grab_flags & GF_MOVE_X)
|
---|
1270 | cx = 1;
|
---|
1271 |
|
---|
1272 | if (pointer->grab_flags & GF_MOVE_Y)
|
---|
1273 | cy = 1;
|
---|
1274 |
|
---|
1275 | if (((scale) || (resize)) && (win->angle != 0)) {
|
---|
1276 | transform_t rotate;
|
---|
1277 | transform_identity(&rotate);
|
---|
1278 |
|
---|
1279 | transform_rotate(&rotate, win->angle);
|
---|
1280 | transform_apply_linear(&rotate, &cx, &cy);
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | cx = (cx < 0) ? (-1 * cx) : cx;
|
---|
1284 | cy = (cy < 0) ? (-1 * cy) : cy;
|
---|
1285 |
|
---|
1286 | win->dx += (cx * dx);
|
---|
1287 | win->dy += (cy * dy);
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | if ((scale) || (resize)) {
|
---|
1291 | double _dx = dx;
|
---|
1292 | double _dy = dy;
|
---|
1293 | if (win->angle != 0) {
|
---|
1294 | transform_t unrotate;
|
---|
1295 | transform_identity(&unrotate);
|
---|
1296 | transform_rotate(&unrotate, -win->angle);
|
---|
1297 | transform_apply_linear(&unrotate, &_dx, &_dy);
|
---|
1298 | }
|
---|
1299 | _dx = (pointer->grab_flags & GF_MOVE_X) ? -_dx : _dx;
|
---|
1300 | _dy = (pointer->grab_flags & GF_MOVE_Y) ? -_dy : _dy;
|
---|
1301 |
|
---|
1302 | if ((pointer->grab_flags & GF_SCALE_X) || (pointer->grab_flags & GF_RESIZE_X)) {
|
---|
1303 | double fx = 1.0 + (_dx / ((width - 1) * win->fx));
|
---|
1304 | if (fx > 0) {
|
---|
1305 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1306 | if (scale)
|
---|
1307 | win->fx *= fx;
|
---|
1308 | #endif
|
---|
1309 | #if ANIMATE_WINDOW_TRANSFORMS == 1
|
---|
1310 | win->fx *= fx;
|
---|
1311 | #endif
|
---|
1312 | scale_back_x *= fx;
|
---|
1313 | }
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if ((pointer->grab_flags & GF_SCALE_Y) || (pointer->grab_flags & GF_RESIZE_Y)) {
|
---|
1317 | double fy = 1.0 + (_dy / ((height - 1) * win->fy));
|
---|
1318 | if (fy > 0) {
|
---|
1319 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1320 | if (scale) win->fy *= fy;
|
---|
1321 | #endif
|
---|
1322 | #if ANIMATE_WINDOW_TRANSFORMS == 1
|
---|
1323 | win->fy *= fy;
|
---|
1324 | #endif
|
---|
1325 | scale_back_y *= fy;
|
---|
1326 | }
|
---|
1327 | }
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | sysarg_t x1, y1, width1, height1;
|
---|
1331 | sysarg_t x2, y2, width2, height2;
|
---|
1332 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1333 | &x1, &y1, &width1, &height1);
|
---|
1334 | comp_recalc_transform(win);
|
---|
1335 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1336 | &x2, &y2, &width2, &height2);
|
---|
1337 | rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
1338 | dmg_x, dmg_y, dmg_width, dmg_height);
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1342 | static void comp_ghost_animate(pointer_t *pointer,
|
---|
1343 | desktop_rect_t *rect1, desktop_rect_t *rect2, desktop_rect_t *rect3, desktop_rect_t *rect4)
|
---|
1344 | {
|
---|
1345 | /* window_list_mtx locked by caller */
|
---|
1346 | /* pointer_list_mtx locked by caller */
|
---|
1347 |
|
---|
1348 | int dx = pointer->accum_ghost.x;
|
---|
1349 | int dy = pointer->accum_ghost.y;
|
---|
1350 | pointer->accum_ghost.x = 0;
|
---|
1351 | pointer->accum_ghost.y = 0;
|
---|
1352 |
|
---|
1353 | bool move = (pointer->grab_flags & GF_MOVE_X) || (pointer->grab_flags & GF_MOVE_Y);
|
---|
1354 | bool scale = (pointer->grab_flags & GF_SCALE_X) || (pointer->grab_flags & GF_SCALE_Y);
|
---|
1355 | bool resize = (pointer->grab_flags & GF_RESIZE_X) || (pointer->grab_flags & GF_RESIZE_Y);
|
---|
1356 |
|
---|
1357 | sysarg_t width, height;
|
---|
1358 | surface_get_resolution(pointer->ghost.surface, &width, &height);
|
---|
1359 |
|
---|
1360 | if (move) {
|
---|
1361 | double cx = 0;
|
---|
1362 | double cy = 0;
|
---|
1363 | if (pointer->grab_flags & GF_MOVE_X) {
|
---|
1364 | cx = 1;
|
---|
1365 | }
|
---|
1366 | if (pointer->grab_flags & GF_MOVE_Y) {
|
---|
1367 | cy = 1;
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | if (scale || resize) {
|
---|
1371 | transform_t rotate;
|
---|
1372 | transform_identity(&rotate);
|
---|
1373 | transform_rotate(&rotate, pointer->ghost.angle);
|
---|
1374 | transform_apply_linear(&rotate, &cx, &cy);
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | cx = (cx < 0) ? (-1 * cx) : cx;
|
---|
1378 | cy = (cy < 0) ? (-1 * cy) : cy;
|
---|
1379 |
|
---|
1380 | pointer->ghost.dx += (cx * dx);
|
---|
1381 | pointer->ghost.dy += (cy * dy);
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | if (scale || resize) {
|
---|
1385 | double _dx = dx;
|
---|
1386 | double _dy = dy;
|
---|
1387 | transform_t unrotate;
|
---|
1388 | transform_identity(&unrotate);
|
---|
1389 | transform_rotate(&unrotate, -pointer->ghost.angle);
|
---|
1390 | transform_apply_linear(&unrotate, &_dx, &_dy);
|
---|
1391 | _dx = (pointer->grab_flags & GF_MOVE_X) ? -_dx : _dx;
|
---|
1392 | _dy = (pointer->grab_flags & GF_MOVE_Y) ? -_dy : _dy;
|
---|
1393 |
|
---|
1394 | if ((pointer->grab_flags & GF_SCALE_X) || (pointer->grab_flags & GF_RESIZE_X)) {
|
---|
1395 | double fx = 1.0 + (_dx / ((width - 1) * pointer->ghost.fx));
|
---|
1396 | pointer->ghost.fx *= fx;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | if ((pointer->grab_flags & GF_SCALE_Y) || (pointer->grab_flags & GF_RESIZE_Y)) {
|
---|
1400 | double fy = 1.0 + (_dy / ((height - 1) * pointer->ghost.fy));
|
---|
1401 | pointer->ghost.fy *= fy;
|
---|
1402 | }
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | sysarg_t x1, y1, width1, height1;
|
---|
1406 | sysarg_t x2, y2, width2, height2;
|
---|
1407 | comp_coord_bounding_rect(0, 0, width, height, pointer->ghost.transform,
|
---|
1408 | &x1, &y1, &width1, &height1);
|
---|
1409 | comp_recalc_transform(&pointer->ghost);
|
---|
1410 | comp_coord_bounding_rect(0, 0, width, height, pointer->ghost.transform,
|
---|
1411 | &x2, &y2, &width2, &height2);
|
---|
1412 |
|
---|
1413 | sysarg_t x_u, y_u, w_u, h_u;
|
---|
1414 | rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
1415 | &x_u, &y_u, &w_u, &h_u);
|
---|
1416 |
|
---|
1417 | sysarg_t x_i, y_i, w_i, h_i;
|
---|
1418 | rectangle_intersect(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
1419 | &x_i, &y_i, &w_i, &h_i);
|
---|
1420 |
|
---|
1421 | if (w_i == 0 || h_i == 0) {
|
---|
1422 | rect1->x = x_u; rect2->x = 0; rect3->x = 0; rect4->x = 0;
|
---|
1423 | rect1->y = y_u; rect2->y = 0; rect3->y = 0; rect4->y = 0;
|
---|
1424 | rect1->w = w_u; rect2->w = 0; rect3->w = 0; rect4->w = 0;
|
---|
1425 | rect1->h = h_u; rect2->h = 0; rect3->h = 0; rect4->h = 0;
|
---|
1426 | } else {
|
---|
1427 | rect1->x = x_u;
|
---|
1428 | rect1->y = y_u;
|
---|
1429 | rect1->w = x_i - x_u + 1;
|
---|
1430 | rect1->h = h_u;
|
---|
1431 |
|
---|
1432 | rect2->x = x_u;
|
---|
1433 | rect2->y = y_u;
|
---|
1434 | rect2->w = w_u;
|
---|
1435 | rect2->h = y_i - y_u + 1;
|
---|
1436 |
|
---|
1437 | rect3->x = x_i + w_i - 1;
|
---|
1438 | rect3->y = y_u;
|
---|
1439 | rect3->w = w_u - w_i - x_i + x_u + 1;
|
---|
1440 | rect3->h = h_u;
|
---|
1441 |
|
---|
1442 | rect4->x = x_u;
|
---|
1443 | rect4->y = y_i + h_i - 1;
|
---|
1444 | rect4->w = w_u;
|
---|
1445 | rect4->h = h_u - h_i - y_i + y_u + 1;
|
---|
1446 | }
|
---|
1447 | }
|
---|
1448 | #endif
|
---|
1449 |
|
---|
1450 | static int comp_abs_move(input_t *input, unsigned x , unsigned y,
|
---|
1451 | unsigned max_x, unsigned max_y)
|
---|
1452 | {
|
---|
1453 | /* XXX TODO Use absolute coordinates directly */
|
---|
1454 |
|
---|
1455 | pointer_t *pointer = input_pointer(input);
|
---|
1456 |
|
---|
1457 | sysarg_t width, height;
|
---|
1458 |
|
---|
1459 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
1460 | if (list_empty(&viewport_list)) {
|
---|
1461 | printf("No viewport found\n");
|
---|
1462 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1463 | return EOK; /* XXX */
|
---|
1464 | }
|
---|
1465 | link_t *link = list_first(&viewport_list);
|
---|
1466 | viewport_t *vp = list_get_instance(link, viewport_t, link);
|
---|
1467 | surface_get_resolution(vp->surface, &width, &height);
|
---|
1468 | desktop_point_t vp_pos = vp->pos;
|
---|
1469 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
1470 |
|
---|
1471 | desktop_point_t pos_in_viewport;
|
---|
1472 | pos_in_viewport.x = x * width / max_x;
|
---|
1473 | pos_in_viewport.y = y * height / max_y;
|
---|
1474 |
|
---|
1475 | /* Calculate offset from pointer */
|
---|
1476 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
1477 | desktop_vector_t delta;
|
---|
1478 | delta.x = (vp_pos.x + pos_in_viewport.x) - pointer->pos.x;
|
---|
1479 | delta.y = (vp_pos.y + pos_in_viewport.y) - pointer->pos.y;
|
---|
1480 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1481 |
|
---|
1482 | return comp_mouse_move(input, delta.x, delta.y);
|
---|
1483 | }
|
---|
1484 |
|
---|
1485 | static int comp_mouse_move(input_t *input, int dx, int dy)
|
---|
1486 | {
|
---|
1487 | pointer_t *pointer = input_pointer(input);
|
---|
1488 |
|
---|
1489 | comp_update_viewport_bound_rect();
|
---|
1490 |
|
---|
1491 | /* Update pointer position. */
|
---|
1492 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
1493 |
|
---|
1494 | desktop_point_t old_pos = pointer->pos;
|
---|
1495 |
|
---|
1496 | sysarg_t cursor_width;
|
---|
1497 | sysarg_t cursor_height;
|
---|
1498 | surface_get_resolution(pointer->cursor.states[pointer->state],
|
---|
1499 | &cursor_width, &cursor_height);
|
---|
1500 |
|
---|
1501 | if (pointer->pos.x + dx < viewport_bound_rect.x)
|
---|
1502 | dx = -1 * (pointer->pos.x - viewport_bound_rect.x);
|
---|
1503 |
|
---|
1504 | if (pointer->pos.y + dy < viewport_bound_rect.y)
|
---|
1505 | dy = -1 * (pointer->pos.y - viewport_bound_rect.y);
|
---|
1506 |
|
---|
1507 | if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w)
|
---|
1508 | dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x);
|
---|
1509 |
|
---|
1510 | if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h)
|
---|
1511 | dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y);
|
---|
1512 |
|
---|
1513 | pointer->pos.x += dx;
|
---|
1514 | pointer->pos.y += dy;
|
---|
1515 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1516 | comp_damage(old_pos.x, old_pos.y, cursor_width, cursor_height);
|
---|
1517 | comp_damage(old_pos.x + dx, old_pos.y + dy, cursor_width, cursor_height);
|
---|
1518 |
|
---|
1519 | fibril_mutex_lock(&window_list_mtx);
|
---|
1520 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
1521 | window_t *top = (window_t *) list_first(&window_list);
|
---|
1522 | if (top && top->surface) {
|
---|
1523 |
|
---|
1524 | if (pointer->grab_flags == GF_EMPTY) {
|
---|
1525 | /* Notify top-level window about move event. */
|
---|
1526 | bool within_client = false;
|
---|
1527 | sysarg_t point_x, point_y;
|
---|
1528 | sysarg_t width, height;
|
---|
1529 | surface_get_resolution(top->surface, &width, &height);
|
---|
1530 | within_client = comp_coord_to_client(pointer->pos.x, pointer->pos.y,
|
---|
1531 | top->transform, width, height, &point_x, &point_y);
|
---|
1532 |
|
---|
1533 | window_event_t *event = NULL;
|
---|
1534 | if (within_client) {
|
---|
1535 | event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1536 | if (event) {
|
---|
1537 | link_initialize(&event->link);
|
---|
1538 | event->type = ET_POSITION_EVENT;
|
---|
1539 | event->data.pos.pos_id = pointer->id;
|
---|
1540 | event->data.pos.type = POS_UPDATE;
|
---|
1541 | event->data.pos.btn_num = pointer->btn_num;
|
---|
1542 | event->data.pos.hpos = point_x;
|
---|
1543 | event->data.pos.vpos = point_y;
|
---|
1544 | }
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1548 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1549 |
|
---|
1550 | if (event) {
|
---|
1551 | comp_post_event_top(event);
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | } else {
|
---|
1555 | /* Pointer is grabbed by top-level window action. */
|
---|
1556 | pointer->accum.x += dx;
|
---|
1557 | pointer->accum.y += dy;
|
---|
1558 | pointer->accum_ghost.x += dx;
|
---|
1559 | pointer->accum_ghost.y += dy;
|
---|
1560 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1561 | if (pointer->ghost.surface == NULL) {
|
---|
1562 | pointer->ghost.surface = top->surface;
|
---|
1563 | pointer->ghost.dx = top->dx;
|
---|
1564 | pointer->ghost.dy = top->dy;
|
---|
1565 | pointer->ghost.fx = top->fx;
|
---|
1566 | pointer->ghost.fy = top->fy;
|
---|
1567 | pointer->ghost.angle = top->angle;
|
---|
1568 | pointer->ghost.transform = top->transform;
|
---|
1569 | }
|
---|
1570 | desktop_rect_t dmg_rect1, dmg_rect2, dmg_rect3, dmg_rect4;
|
---|
1571 | comp_ghost_animate(pointer, &dmg_rect1, &dmg_rect2, &dmg_rect3, &dmg_rect4);
|
---|
1572 | #endif
|
---|
1573 | #if ANIMATE_WINDOW_TRANSFORMS == 1
|
---|
1574 | sysarg_t x, y, width, height;
|
---|
1575 | comp_window_animate(pointer, top, &x, &y, &width, &height);
|
---|
1576 | #endif
|
---|
1577 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1578 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1579 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1580 | comp_damage(dmg_rect1.x, dmg_rect1.y, dmg_rect1.w, dmg_rect1.h);
|
---|
1581 | comp_damage(dmg_rect2.x, dmg_rect2.y, dmg_rect2.w, dmg_rect2.h);
|
---|
1582 | comp_damage(dmg_rect3.x, dmg_rect3.y, dmg_rect3.w, dmg_rect3.h);
|
---|
1583 | comp_damage(dmg_rect4.x, dmg_rect4.y, dmg_rect4.w, dmg_rect4.h);
|
---|
1584 | #endif
|
---|
1585 | #if ANIMATE_WINDOW_TRANSFORMS == 1
|
---|
1586 | comp_damage(x, y, width, height);
|
---|
1587 | #endif
|
---|
1588 | }
|
---|
1589 | } else {
|
---|
1590 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1591 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | return EOK;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | static int comp_mouse_button(input_t *input, int bnum, int bpress)
|
---|
1598 | {
|
---|
1599 | pointer_t *pointer = input_pointer(input);
|
---|
1600 |
|
---|
1601 | fibril_mutex_lock(&window_list_mtx);
|
---|
1602 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
1603 | window_t *win = NULL;
|
---|
1604 | sysarg_t point_x = 0;
|
---|
1605 | sysarg_t point_y = 0;
|
---|
1606 | sysarg_t width, height;
|
---|
1607 | bool within_client = false;
|
---|
1608 |
|
---|
1609 | /* Determine the window which the mouse click belongs to. */
|
---|
1610 | list_foreach(window_list, link, window_t, cw) {
|
---|
1611 | win = cw;
|
---|
1612 | if (win->surface) {
|
---|
1613 | surface_get_resolution(win->surface, &width, &height);
|
---|
1614 | within_client = comp_coord_to_client(pointer->pos.x, pointer->pos.y,
|
---|
1615 | win->transform, width, height, &point_x, &point_y);
|
---|
1616 | }
|
---|
1617 | if (within_client) {
|
---|
1618 | break;
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | /* Check whether the window is top-level window. */
|
---|
1623 | window_t *top = (window_t *) list_first(&window_list);
|
---|
1624 | if (!win || !top) {
|
---|
1625 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1626 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1627 | return EOK;
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 | window_event_t *event_top = NULL;
|
---|
1631 | window_event_t *event_unfocus = NULL;
|
---|
1632 | window_t *win_unfocus = NULL;
|
---|
1633 | sysarg_t dmg_x, dmg_y;
|
---|
1634 | sysarg_t dmg_width = 0;
|
---|
1635 | sysarg_t dmg_height = 0;
|
---|
1636 |
|
---|
1637 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1638 | desktop_rect_t dmg_rect1, dmg_rect2, dmg_rect3, dmg_rect4;
|
---|
1639 | #endif
|
---|
1640 |
|
---|
1641 | if (bpress) {
|
---|
1642 | pointer->btn_pos = pointer->pos;
|
---|
1643 | pointer->btn_num = bnum;
|
---|
1644 | pointer->pressed = true;
|
---|
1645 |
|
---|
1646 | /* Bring the window to the foreground. */
|
---|
1647 | if ((win != top) && within_client) {
|
---|
1648 | win_unfocus = (window_t *) list_first(&window_list);
|
---|
1649 | list_remove(&win->link);
|
---|
1650 | list_prepend(&win->link, &window_list);
|
---|
1651 | event_unfocus = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1652 | if (event_unfocus) {
|
---|
1653 | link_initialize(&event_unfocus->link);
|
---|
1654 | event_unfocus->type = ET_WINDOW_UNFOCUS;
|
---|
1655 | }
|
---|
1656 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1657 | &dmg_x, &dmg_y, &dmg_width, &dmg_height);
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 | /* Notify top-level window about mouse press. */
|
---|
1661 | if (within_client) {
|
---|
1662 | event_top = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1663 | if (event_top) {
|
---|
1664 | link_initialize(&event_top->link);
|
---|
1665 | event_top->type = ET_POSITION_EVENT;
|
---|
1666 | event_top->data.pos.pos_id = pointer->id;
|
---|
1667 | event_top->data.pos.type = POS_PRESS;
|
---|
1668 | event_top->data.pos.btn_num = bnum;
|
---|
1669 | event_top->data.pos.hpos = point_x;
|
---|
1670 | event_top->data.pos.vpos = point_y;
|
---|
1671 | }
|
---|
1672 | pointer->grab_flags = GF_EMPTY;
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | } else if (pointer->pressed && pointer->btn_num == (unsigned)bnum) {
|
---|
1676 | pointer->pressed = false;
|
---|
1677 |
|
---|
1678 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1679 | sysarg_t pre_x = 0;
|
---|
1680 | sysarg_t pre_y = 0;
|
---|
1681 | sysarg_t pre_width = 0;
|
---|
1682 | sysarg_t pre_height = 0;
|
---|
1683 |
|
---|
1684 | if (pointer->grab_flags != GF_EMPTY) {
|
---|
1685 | if (pointer->ghost.surface) {
|
---|
1686 | comp_ghost_animate(pointer, &dmg_rect1, &dmg_rect2, &dmg_rect3, &dmg_rect4);
|
---|
1687 | pointer->ghost.surface = NULL;
|
---|
1688 | }
|
---|
1689 | comp_window_animate(pointer, top, &pre_x, &pre_y, &pre_width, &pre_height);
|
---|
1690 | dmg_x = pre_x;
|
---|
1691 | dmg_y = pre_y;
|
---|
1692 | dmg_width = pre_width;
|
---|
1693 | dmg_height = pre_height;
|
---|
1694 | }
|
---|
1695 | #endif
|
---|
1696 |
|
---|
1697 | if ((pointer->grab_flags & GF_RESIZE_X) || (pointer->grab_flags & GF_RESIZE_Y)) {
|
---|
1698 |
|
---|
1699 | surface_get_resolution(top->surface, &width, &height);
|
---|
1700 | #if ANIMATE_WINDOW_TRANSFORMS == 1
|
---|
1701 | top->fx *= (1.0 / scale_back_x);
|
---|
1702 | top->fy *= (1.0 / scale_back_y);
|
---|
1703 | comp_recalc_transform(top);
|
---|
1704 | #endif
|
---|
1705 |
|
---|
1706 | /* Commit proper resize action. */
|
---|
1707 | event_top = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1708 | if (event_top) {
|
---|
1709 | link_initialize(&event_top->link);
|
---|
1710 | event_top->type = ET_WINDOW_RESIZE;
|
---|
1711 |
|
---|
1712 | event_top->data.resize.offset_x = 0;
|
---|
1713 | event_top->data.resize.offset_y = 0;
|
---|
1714 |
|
---|
1715 | int dx = (int) (((double) width) * (scale_back_x - 1.0));
|
---|
1716 | int dy = (int) (((double) height) * (scale_back_y - 1.0));
|
---|
1717 |
|
---|
1718 | if (pointer->grab_flags & GF_RESIZE_X)
|
---|
1719 | event_top->data.resize.width =
|
---|
1720 | ((((int) width) + dx) >= 0) ? (width + dx) : 0;
|
---|
1721 | else
|
---|
1722 | event_top->data.resize.width = width;
|
---|
1723 |
|
---|
1724 | if (pointer->grab_flags & GF_RESIZE_Y)
|
---|
1725 | event_top->data.resize.height =
|
---|
1726 | ((((int) height) + dy) >= 0) ? (height + dy) : 0;
|
---|
1727 | else
|
---|
1728 | event_top->data.resize.height = height;
|
---|
1729 |
|
---|
1730 | event_top->data.resize.placement_flags =
|
---|
1731 | WINDOW_PLACEMENT_ANY;
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | pointer->grab_flags = GF_EMPTY;
|
---|
1735 |
|
---|
1736 | } else if (within_client && (pointer->grab_flags == GF_EMPTY) && (top == win)) {
|
---|
1737 |
|
---|
1738 | /* Notify top-level window about mouse release. */
|
---|
1739 | event_top = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1740 | if (event_top) {
|
---|
1741 | link_initialize(&event_top->link);
|
---|
1742 | event_top->type = ET_POSITION_EVENT;
|
---|
1743 | event_top->data.pos.pos_id = pointer->id;
|
---|
1744 | event_top->data.pos.type = POS_RELEASE;
|
---|
1745 | event_top->data.pos.btn_num = bnum;
|
---|
1746 | event_top->data.pos.hpos = point_x;
|
---|
1747 | event_top->data.pos.vpos = point_y;
|
---|
1748 | }
|
---|
1749 | pointer->grab_flags = GF_EMPTY;
|
---|
1750 |
|
---|
1751 | } else {
|
---|
1752 | pointer->grab_flags = GF_EMPTY;
|
---|
1753 | }
|
---|
1754 |
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
1758 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1759 |
|
---|
1760 | #if ANIMATE_WINDOW_TRANSFORMS == 0
|
---|
1761 | comp_damage(dmg_rect1.x, dmg_rect1.y, dmg_rect1.w, dmg_rect1.h);
|
---|
1762 | comp_damage(dmg_rect2.x, dmg_rect2.y, dmg_rect2.w, dmg_rect2.h);
|
---|
1763 | comp_damage(dmg_rect3.x, dmg_rect3.y, dmg_rect3.w, dmg_rect3.h);
|
---|
1764 | comp_damage(dmg_rect4.x, dmg_rect4.y, dmg_rect4.w, dmg_rect4.h);
|
---|
1765 | #endif
|
---|
1766 |
|
---|
1767 | if (dmg_width > 0 && dmg_height > 0) {
|
---|
1768 | comp_damage(dmg_x, dmg_y, dmg_width, dmg_height);
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 | if (event_unfocus && win_unfocus) {
|
---|
1772 | comp_post_event_win(event_unfocus, win_unfocus);
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | if (event_top) {
|
---|
1776 | comp_post_event_top(event_top);
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | return EOK;
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | static int comp_key_press(input_t *input, kbd_event_type_t type, keycode_t key,
|
---|
1783 | keymod_t mods, wchar_t c)
|
---|
1784 | {
|
---|
1785 | bool win_transform = (mods & KM_ALT) && (
|
---|
1786 | key == KC_W || key == KC_S || key == KC_A || key == KC_D ||
|
---|
1787 | key == KC_Q || key == KC_E || key == KC_R || key == KC_F);
|
---|
1788 | bool win_resize = (mods & KM_ALT) && (
|
---|
1789 | key == KC_T || key == KC_G || key == KC_B || key == KC_N);
|
---|
1790 | bool win_opacity = (mods & KM_ALT) && (
|
---|
1791 | key == KC_C || key == KC_V);
|
---|
1792 | bool win_close = (mods & KM_ALT) && (key == KC_X);
|
---|
1793 | bool win_switch = (mods & KM_ALT) && (key == KC_TAB);
|
---|
1794 | bool viewport_move = (mods & KM_ALT) && (
|
---|
1795 | key == KC_I || key == KC_K || key == KC_J || key == KC_L);
|
---|
1796 | bool viewport_change = (mods & KM_ALT) && (
|
---|
1797 | key == KC_O || key == KC_P);
|
---|
1798 | bool kconsole_switch = (mods & KM_ALT) && (key == KC_M);
|
---|
1799 |
|
---|
1800 | bool filter = (type == KEY_RELEASE) && (win_transform || win_resize ||
|
---|
1801 | win_opacity || win_close || win_switch || viewport_move ||
|
---|
1802 | viewport_change || kconsole_switch);
|
---|
1803 |
|
---|
1804 | if (filter) {
|
---|
1805 | /* no-op */
|
---|
1806 | } else if (win_transform) {
|
---|
1807 | fibril_mutex_lock(&window_list_mtx);
|
---|
1808 | window_t *win = (window_t *) list_first(&window_list);
|
---|
1809 | if (win && win->surface) {
|
---|
1810 | switch (key) {
|
---|
1811 | case KC_W:
|
---|
1812 | win->dy += -20;
|
---|
1813 | break;
|
---|
1814 | case KC_S:
|
---|
1815 | win->dy += 20;
|
---|
1816 | break;
|
---|
1817 | case KC_A:
|
---|
1818 | win->dx += -20;
|
---|
1819 | break;
|
---|
1820 | case KC_D:
|
---|
1821 | win->dx += 20;
|
---|
1822 | break;
|
---|
1823 | case KC_Q:
|
---|
1824 | win->angle += 0.1;
|
---|
1825 | break;
|
---|
1826 | case KC_E:
|
---|
1827 | win->angle -= 0.1;
|
---|
1828 | break;
|
---|
1829 | case KC_R:
|
---|
1830 | win->fx *= 0.95;
|
---|
1831 | win->fy *= 0.95;
|
---|
1832 | break;
|
---|
1833 | case KC_F:
|
---|
1834 | win->fx *= 1.05;
|
---|
1835 | win->fy *= 1.05;
|
---|
1836 | break;
|
---|
1837 | default:
|
---|
1838 | break;
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | /* Transform the window and calculate damage. */
|
---|
1842 | sysarg_t x, y, width, height;
|
---|
1843 | surface_get_resolution(win->surface, &width, &height);
|
---|
1844 | sysarg_t x1, y1, width1, height1;
|
---|
1845 | sysarg_t x2, y2, width2, height2;
|
---|
1846 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1847 | &x1, &y1, &width1, &height1);
|
---|
1848 | comp_recalc_transform(win);
|
---|
1849 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1850 | &x2, &y2, &width2, &height2);
|
---|
1851 | rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
1852 | &x, &y, &width, &height);
|
---|
1853 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1854 |
|
---|
1855 | comp_damage(x, y, width, height);
|
---|
1856 | } else {
|
---|
1857 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1858 | }
|
---|
1859 | } else if (win_resize) {
|
---|
1860 | fibril_mutex_lock(&window_list_mtx);
|
---|
1861 | window_t *win = (window_t *) list_first(&window_list);
|
---|
1862 | if (win && win->surface) {
|
---|
1863 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1864 | if (event == NULL) {
|
---|
1865 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1866 | return ENOMEM;
|
---|
1867 | }
|
---|
1868 |
|
---|
1869 | sysarg_t width, height;
|
---|
1870 | surface_get_resolution(win->surface, &width, &height);
|
---|
1871 |
|
---|
1872 | link_initialize(&event->link);
|
---|
1873 | event->type = ET_WINDOW_RESIZE;
|
---|
1874 |
|
---|
1875 | event->data.resize.offset_x = 0;
|
---|
1876 | event->data.resize.offset_y = 0;
|
---|
1877 |
|
---|
1878 | switch (key) {
|
---|
1879 | case KC_T:
|
---|
1880 | event->data.resize.width = width;
|
---|
1881 | event->data.resize.height = (height >= 20) ? height - 20 : 0;
|
---|
1882 | break;
|
---|
1883 | case KC_G:
|
---|
1884 | event->data.resize.width = width;
|
---|
1885 | event->data.resize.height = height + 20;
|
---|
1886 | break;
|
---|
1887 | case KC_B:
|
---|
1888 | event->data.resize.width = (width >= 20) ? width - 20 : 0;;
|
---|
1889 | event->data.resize.height = height;
|
---|
1890 | break;
|
---|
1891 | case KC_N:
|
---|
1892 | event->data.resize.width = width + 20;
|
---|
1893 | event->data.resize.height = height;
|
---|
1894 | break;
|
---|
1895 | default:
|
---|
1896 | event->data.resize.width = 0;
|
---|
1897 | event->data.resize.height = 0;
|
---|
1898 | break;
|
---|
1899 | }
|
---|
1900 |
|
---|
1901 | event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY;
|
---|
1902 |
|
---|
1903 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1904 | comp_post_event_top(event);
|
---|
1905 | } else {
|
---|
1906 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1907 | }
|
---|
1908 | } else if (win_opacity) {
|
---|
1909 | fibril_mutex_lock(&window_list_mtx);
|
---|
1910 | window_t *win = (window_t *) list_first(&window_list);
|
---|
1911 | if (win && win->surface) {
|
---|
1912 | switch (key) {
|
---|
1913 | case KC_C:
|
---|
1914 | if (win->opacity > 0) {
|
---|
1915 | win->opacity -= 5;
|
---|
1916 | }
|
---|
1917 | break;
|
---|
1918 | case KC_V:
|
---|
1919 | if (win->opacity < 255) {
|
---|
1920 | win->opacity += 5;
|
---|
1921 | }
|
---|
1922 | break;
|
---|
1923 | default:
|
---|
1924 | break;
|
---|
1925 | }
|
---|
1926 |
|
---|
1927 | /* Calculate damage. */
|
---|
1928 | sysarg_t x, y, width, height;
|
---|
1929 | surface_get_resolution(win->surface, &width, &height);
|
---|
1930 | comp_coord_bounding_rect(0, 0, width, height, win->transform,
|
---|
1931 | &x, &y, &width, &height);
|
---|
1932 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1933 |
|
---|
1934 | comp_damage(x, y, width, height);
|
---|
1935 | } else {
|
---|
1936 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1937 | }
|
---|
1938 | } else if (win_close) {
|
---|
1939 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1940 | if (event == NULL)
|
---|
1941 | return ENOMEM;
|
---|
1942 |
|
---|
1943 | link_initialize(&event->link);
|
---|
1944 | event->type = ET_WINDOW_CLOSE;
|
---|
1945 |
|
---|
1946 | comp_post_event_top(event);
|
---|
1947 | } else if (win_switch) {
|
---|
1948 | fibril_mutex_lock(&window_list_mtx);
|
---|
1949 | if (!list_empty(&window_list)) {
|
---|
1950 | window_t *win1 = (window_t *) list_first(&window_list);
|
---|
1951 | list_remove(&win1->link);
|
---|
1952 | list_append(&win1->link, &window_list);
|
---|
1953 | window_t *win2 = (window_t *) list_first(&window_list);
|
---|
1954 |
|
---|
1955 | window_event_t *event1 = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1956 | if (event1) {
|
---|
1957 | link_initialize(&event1->link);
|
---|
1958 | event1->type = ET_WINDOW_UNFOCUS;
|
---|
1959 | }
|
---|
1960 |
|
---|
1961 | window_event_t *event2 = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
1962 | if (event2) {
|
---|
1963 | link_initialize(&event2->link);
|
---|
1964 | event2->type = ET_WINDOW_FOCUS;
|
---|
1965 | }
|
---|
1966 |
|
---|
1967 | sysarg_t x1 = 0;
|
---|
1968 | sysarg_t y1 = 0;
|
---|
1969 | sysarg_t width1 = 0;
|
---|
1970 | sysarg_t height1 = 0;
|
---|
1971 | if (win1->surface) {
|
---|
1972 | sysarg_t width, height;
|
---|
1973 | surface_get_resolution(win1->surface, &width, &height);
|
---|
1974 | comp_coord_bounding_rect(0, 0, width, height, win1->transform,
|
---|
1975 | &x1, &y1, &width1, &height1);
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | sysarg_t x2 = 0;
|
---|
1979 | sysarg_t y2 = 0;
|
---|
1980 | sysarg_t width2 = 0;
|
---|
1981 | sysarg_t height2 = 0;
|
---|
1982 | if (win2->surface) {
|
---|
1983 | sysarg_t width, height;
|
---|
1984 | surface_get_resolution(win2->surface, &width, &height);
|
---|
1985 | comp_coord_bounding_rect(0, 0, width, height, win2->transform,
|
---|
1986 | &x2, &y2, &width2, &height2);
|
---|
1987 | }
|
---|
1988 |
|
---|
1989 | sysarg_t x, y, width, height;
|
---|
1990 | rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
|
---|
1991 | &x, &y, &width, &height);
|
---|
1992 |
|
---|
1993 | fibril_mutex_unlock(&window_list_mtx);
|
---|
1994 |
|
---|
1995 | if (event1 && win1) {
|
---|
1996 | comp_post_event_win(event1, win1);
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 | if (event2 && win2) {
|
---|
2000 | comp_post_event_win(event2, win2);
|
---|
2001 | }
|
---|
2002 |
|
---|
2003 | comp_damage(x, y, width, height);
|
---|
2004 | } else {
|
---|
2005 | fibril_mutex_unlock(&window_list_mtx);
|
---|
2006 | }
|
---|
2007 | } else if (viewport_move) {
|
---|
2008 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
2009 | viewport_t *vp = (viewport_t *) list_first(&viewport_list);
|
---|
2010 | if (vp) {
|
---|
2011 | switch (key) {
|
---|
2012 | case KC_I:
|
---|
2013 | vp->pos.x += 0;
|
---|
2014 | vp->pos.y += -20;
|
---|
2015 | break;
|
---|
2016 | case KC_K:
|
---|
2017 | vp->pos.x += 0;
|
---|
2018 | vp->pos.y += 20;
|
---|
2019 | break;
|
---|
2020 | case KC_J:
|
---|
2021 | vp->pos.x += -20;
|
---|
2022 | vp->pos.y += 0;
|
---|
2023 | break;
|
---|
2024 | case KC_L:
|
---|
2025 | vp->pos.x += 20;
|
---|
2026 | vp->pos.y += 0;
|
---|
2027 | break;
|
---|
2028 | default:
|
---|
2029 | vp->pos.x += 0;
|
---|
2030 | vp->pos.y += 0;
|
---|
2031 | break;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | sysarg_t x = vp->pos.x;
|
---|
2035 | sysarg_t y = vp->pos.y;
|
---|
2036 | sysarg_t width, height;
|
---|
2037 | surface_get_resolution(vp->surface, &width, &height);
|
---|
2038 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
2039 |
|
---|
2040 | comp_restrict_pointers();
|
---|
2041 | comp_damage(x, y, width, height);
|
---|
2042 | } else {
|
---|
2043 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
2044 | }
|
---|
2045 | } else if (viewport_change) {
|
---|
2046 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
2047 |
|
---|
2048 | viewport_t *vp;
|
---|
2049 | switch (key) {
|
---|
2050 | case KC_O:
|
---|
2051 | vp = (viewport_t *) list_first(&viewport_list);
|
---|
2052 | if (vp) {
|
---|
2053 | list_remove(&vp->link);
|
---|
2054 | list_append(&vp->link, &viewport_list);
|
---|
2055 | }
|
---|
2056 | break;
|
---|
2057 | case KC_P:
|
---|
2058 | vp = (viewport_t *) list_last(&viewport_list);
|
---|
2059 | if (vp) {
|
---|
2060 | list_remove(&vp->link);
|
---|
2061 | list_prepend(&vp->link, &viewport_list);
|
---|
2062 | }
|
---|
2063 | break;
|
---|
2064 | default:
|
---|
2065 | break;
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
2069 | } else if (kconsole_switch) {
|
---|
2070 | __SYSCALL0(SYS_DEBUG_CONSOLE);
|
---|
2071 | } else {
|
---|
2072 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
2073 | if (event == NULL)
|
---|
2074 | return ENOMEM;
|
---|
2075 |
|
---|
2076 | link_initialize(&event->link);
|
---|
2077 | event->type = ET_KEYBOARD_EVENT;
|
---|
2078 | event->data.kbd.type = type;
|
---|
2079 | event->data.kbd.key = key;
|
---|
2080 | event->data.kbd.mods = mods;
|
---|
2081 | event->data.kbd.c = c;
|
---|
2082 |
|
---|
2083 | comp_post_event_top(event);
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | return EOK;
|
---|
2087 | }
|
---|
2088 |
|
---|
2089 | static int input_connect(const char *svc)
|
---|
2090 | {
|
---|
2091 | async_sess_t *sess;
|
---|
2092 | service_id_t dsid;
|
---|
2093 |
|
---|
2094 | int rc = loc_service_get_id(svc, &dsid, 0);
|
---|
2095 | if (rc != EOK) {
|
---|
2096 | printf("%s: Input service %s not found\n", NAME, svc);
|
---|
2097 | return rc;
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0);
|
---|
2101 | if (sess == NULL) {
|
---|
2102 | printf("%s: Unable to connect to input service %s\n", NAME,
|
---|
2103 | svc);
|
---|
2104 | return EIO;
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 | fibril_mutex_lock(&pointer_list_mtx);
|
---|
2108 | pointer_t *pointer = pointer_create();
|
---|
2109 | if (pointer != NULL) {
|
---|
2110 | pointer->id = pointer_id++;
|
---|
2111 | list_append(&pointer->link, &pointer_list);
|
---|
2112 | }
|
---|
2113 | fibril_mutex_unlock(&pointer_list_mtx);
|
---|
2114 |
|
---|
2115 | if (pointer == NULL) {
|
---|
2116 | printf("%s: Cannot create pointer.\n", NAME);
|
---|
2117 | async_hangup(sess);
|
---|
2118 | return ENOMEM;
|
---|
2119 | }
|
---|
2120 |
|
---|
2121 | rc = input_open(sess, &input_ev_ops, pointer, &input);
|
---|
2122 | if (rc != EOK) {
|
---|
2123 | async_hangup(sess);
|
---|
2124 | printf("%s: Unable to communicate with service %s (%s)\n",
|
---|
2125 | NAME, svc, str_error(rc));
|
---|
2126 | return rc;
|
---|
2127 | }
|
---|
2128 |
|
---|
2129 | return EOK;
|
---|
2130 | }
|
---|
2131 |
|
---|
2132 | static void input_disconnect(void)
|
---|
2133 | {
|
---|
2134 | pointer_t *pointer = input->user;
|
---|
2135 | input_close(input);
|
---|
2136 | pointer_destroy(pointer);
|
---|
2137 | }
|
---|
2138 |
|
---|
2139 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
|
---|
2140 | {
|
---|
2141 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
2142 | }
|
---|
2143 |
|
---|
2144 | static int discover_viewports(void)
|
---|
2145 | {
|
---|
2146 | /* Create viewports and connect them to visualizers. */
|
---|
2147 | category_id_t cat_id;
|
---|
2148 | int rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING);
|
---|
2149 | if (rc != EOK) {
|
---|
2150 | printf("%s: Failed to get visualizer category.\n", NAME);
|
---|
2151 | return -1;
|
---|
2152 | }
|
---|
2153 |
|
---|
2154 | service_id_t *svcs;
|
---|
2155 | size_t svcs_cnt = 0;
|
---|
2156 | rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt);
|
---|
2157 | if (rc != EOK || svcs_cnt == 0) {
|
---|
2158 | printf("%s: Failed to get visualizer category services.\n", NAME);
|
---|
2159 | return -1;
|
---|
2160 | }
|
---|
2161 |
|
---|
2162 | fibril_mutex_lock(&viewport_list_mtx);
|
---|
2163 | for (size_t i = 0; i < svcs_cnt; ++i) {
|
---|
2164 | bool exists = false;
|
---|
2165 | list_foreach(viewport_list, link, viewport_t, vp) {
|
---|
2166 | if (vp->dsid == svcs[i]) {
|
---|
2167 | exists = true;
|
---|
2168 | break;
|
---|
2169 | }
|
---|
2170 | }
|
---|
2171 |
|
---|
2172 | if (exists)
|
---|
2173 | continue;
|
---|
2174 |
|
---|
2175 | viewport_t *vp = viewport_create(svcs[i]);
|
---|
2176 | if (vp != NULL)
|
---|
2177 | list_append(&vp->link, &viewport_list);
|
---|
2178 | }
|
---|
2179 | fibril_mutex_unlock(&viewport_list_mtx);
|
---|
2180 |
|
---|
2181 | /* TODO damage only newly added viewports */
|
---|
2182 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
2183 | return EOK;
|
---|
2184 | }
|
---|
2185 |
|
---|
2186 | static void category_change_cb(void)
|
---|
2187 | {
|
---|
2188 | fibril_mutex_lock(&discovery_mtx);
|
---|
2189 | discover_viewports();
|
---|
2190 | fibril_mutex_unlock(&discovery_mtx);
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | static int compositor_srv_init(char *input_svc, char *name)
|
---|
2194 | {
|
---|
2195 | /* Coordinates of the central pixel. */
|
---|
2196 | coord_origin = UINT32_MAX / 4;
|
---|
2197 |
|
---|
2198 | /* Color of the viewport background. Must be opaque. */
|
---|
2199 | bg_color = PIXEL(255, 69, 51, 103);
|
---|
2200 |
|
---|
2201 | /* Register compositor server. */
|
---|
2202 | async_set_client_connection(client_connection);
|
---|
2203 |
|
---|
2204 | int rc = loc_server_register(NAME);
|
---|
2205 | if (rc != EOK) {
|
---|
2206 | printf("%s: Unable to register server (%s)\n", NAME, str_error(rc));
|
---|
2207 | return -1;
|
---|
2208 | }
|
---|
2209 |
|
---|
2210 | /* Register interrupt handler to switch back from kconsole. */
|
---|
2211 | async_set_interrupt_received(interrupt_received);
|
---|
2212 | rc = event_subscribe(EVENT_KCONSOLE, 0);
|
---|
2213 | if (rc != EOK) {
|
---|
2214 | printf("%s: Failed to register kconsole notifications (%s)\n",
|
---|
2215 | NAME, str_error(rc));
|
---|
2216 | }
|
---|
2217 |
|
---|
2218 | server_name = name;
|
---|
2219 |
|
---|
2220 | char svc[LOC_NAME_MAXLEN + 1];
|
---|
2221 | snprintf(svc, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, server_name);
|
---|
2222 |
|
---|
2223 | service_id_t service_id;
|
---|
2224 | rc = loc_service_register(svc, &service_id);
|
---|
2225 | if (rc != EOK) {
|
---|
2226 | printf("%s: Unable to register service %s\n", NAME, svc);
|
---|
2227 | return rc;
|
---|
2228 | }
|
---|
2229 |
|
---|
2230 | /* Prepare window registrator (entrypoint for clients). */
|
---|
2231 | char winreg[LOC_NAME_MAXLEN + 1];
|
---|
2232 | snprintf(winreg, LOC_NAME_MAXLEN, "%s%s/winreg", NAMESPACE, server_name);
|
---|
2233 | if (loc_service_register(winreg, &winreg_id) != EOK) {
|
---|
2234 | printf("%s: Unable to register service %s\n", NAME, winreg);
|
---|
2235 | return -1;
|
---|
2236 | }
|
---|
2237 |
|
---|
2238 | /* Establish input bidirectional connection. */
|
---|
2239 | rc = input_connect(input_svc);
|
---|
2240 | if (rc != EOK) {
|
---|
2241 | printf("%s: Failed to connect to input service.\n", NAME);
|
---|
2242 | return rc;
|
---|
2243 | }
|
---|
2244 |
|
---|
2245 | rc = loc_register_cat_change_cb(category_change_cb);
|
---|
2246 | if (rc != EOK) {
|
---|
2247 | printf("%s: Failed to register category change callback\n", NAME);
|
---|
2248 | input_disconnect();
|
---|
2249 | return rc;
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | rc = discover_viewports();
|
---|
2253 | if (rc != EOK) {
|
---|
2254 | input_disconnect();
|
---|
2255 | return rc;
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | if (list_empty(&viewport_list)) {
|
---|
2259 | printf("%s: Failed to get viewports.\n", NAME);
|
---|
2260 | input_disconnect();
|
---|
2261 | return -1;
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | comp_restrict_pointers();
|
---|
2265 | comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
|
---|
2266 |
|
---|
2267 | return EOK;
|
---|
2268 | }
|
---|
2269 |
|
---|
2270 | static void usage(char *name)
|
---|
2271 | {
|
---|
2272 | printf("Usage: %s <input_dev> <server_name>\n", name);
|
---|
2273 | }
|
---|
2274 |
|
---|
2275 | int main(int argc, char *argv[])
|
---|
2276 | {
|
---|
2277 | if (argc < 3) {
|
---|
2278 | usage(argv[0]);
|
---|
2279 | return 1;
|
---|
2280 | }
|
---|
2281 |
|
---|
2282 | printf("%s: HelenOS Compositor server\n", NAME);
|
---|
2283 |
|
---|
2284 | int rc = compositor_srv_init(argv[1], argv[2]);
|
---|
2285 | if (rc != EOK)
|
---|
2286 | return rc;
|
---|
2287 |
|
---|
2288 | printf("%s: Accepting connections\n", NAME);
|
---|
2289 | task_retval(0);
|
---|
2290 | async_manager();
|
---|
2291 |
|
---|
2292 | /* Never reached */
|
---|
2293 | return 0;
|
---|
2294 | }
|
---|
2295 |
|
---|
2296 | /** @}
|
---|
2297 | */
|
---|