2012-11-27 19:03:44 +04:00
|
|
|
/*
|
2012-11-30 19:34:26 +04:00
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
2012-11-27 19:03:44 +04:00
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2012-11-27 19:03:44 +04:00
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2012-11-27 19:03:44 +04:00
|
|
|
*/
|
|
|
|
|
2014-04-07 15:40:35 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
#include <stdint.h>
|
2012-11-27 19:03:44 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2019-04-27 00:57:31 +03:00
|
|
|
#include <errno.h>
|
2012-11-30 19:34:26 +04:00
|
|
|
#include <cairo.h>
|
2012-11-27 19:03:44 +04:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <wayland-client.h>
|
2012-11-30 19:34:26 +04:00
|
|
|
#include "window.h"
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
struct transformed {
|
2012-11-27 19:03:44 +04:00
|
|
|
struct display *display;
|
2012-11-30 19:34:26 +04:00
|
|
|
struct window *window;
|
|
|
|
struct widget *widget;
|
|
|
|
int width, height;
|
|
|
|
int fullscreen;
|
2012-11-27 19:03:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-05-22 16:41:26 +04:00
|
|
|
draw_stuff(cairo_t *cr, int width, int height)
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_matrix_t m;
|
2013-05-22 16:41:26 +04:00
|
|
|
cairo_get_matrix (cr, &m);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_translate(cr, width / 2, height / 2);
|
|
|
|
cairo_scale(cr, width / 2, height / 2);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0.3, 1.0);
|
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
|
|
|
|
cairo_rectangle(cr, -1, -1, 2, 2);
|
|
|
|
cairo_fill(cr);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_source_rgb(cr, 1, 0, 0);
|
|
|
|
cairo_move_to(cr, 0, 0);
|
|
|
|
cairo_line_to(cr, 0, -1);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_save(cr);
|
2013-05-22 16:41:26 +04:00
|
|
|
cairo_set_matrix(cr, &m);
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_line_width(cr, 2.0);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
cairo_restore(cr);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_source_rgb(cr, 0, 1, 0);
|
|
|
|
cairo_move_to(cr, 0, 0);
|
|
|
|
cairo_line_to(cr, 1, 0);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_save(cr);
|
2013-05-22 16:41:26 +04:00
|
|
|
cairo_set_matrix(cr, &m);
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_line_width(cr, 2.0);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
cairo_restore(cr);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
cairo_move_to(cr, 0, 0);
|
|
|
|
cairo_line_to(cr, 0, 1);
|
|
|
|
cairo_move_to(cr, 0, 0);
|
|
|
|
cairo_line_to(cr, -1, 0);
|
|
|
|
|
|
|
|
cairo_save(cr);
|
2013-05-22 16:41:26 +04:00
|
|
|
cairo_set_matrix(cr, &m);
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_set_line_width(cr, 2.0);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
cairo_restore(cr);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_destroy(cr);
|
2012-11-27 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-30 19:34:26 +04:00
|
|
|
fullscreen_handler(struct window *window, void *data)
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
struct transformed *transformed = data;
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
transformed->fullscreen ^= 1;
|
|
|
|
window_set_fullscreen(window, transformed->fullscreen);
|
|
|
|
}
|
2012-11-27 19:03:44 +04:00
|
|
|
|
|
|
|
static void
|
2012-11-30 19:34:26 +04:00
|
|
|
redraw_handler(struct widget *widget, void *data)
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
struct transformed *transformed = data;
|
|
|
|
struct rectangle allocation;
|
|
|
|
cairo_surface_t *surface;
|
2013-05-22 16:41:26 +04:00
|
|
|
cairo_t *cr;
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
surface = window_get_surface(transformed->window);
|
|
|
|
if (surface == NULL ||
|
|
|
|
cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to create cairo egl surface\n");
|
|
|
|
return;
|
2012-11-27 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
widget_get_allocation(transformed->widget, &allocation);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2013-05-22 16:41:26 +04:00
|
|
|
cr = widget_cairo_create(widget);
|
|
|
|
draw_stuff(cr, allocation.width, allocation.height);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
cairo_surface_destroy(surface);
|
2012-11-27 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-30 19:34:26 +04:00
|
|
|
output_handler(struct window *window, struct output *output, int enter,
|
|
|
|
void *data)
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
if (!enter)
|
|
|
|
return;
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
window_set_buffer_transform(window, output_get_transform(output));
|
2013-05-22 16:41:30 +04:00
|
|
|
window_set_buffer_scale(window, output_get_scale(output));
|
2012-11-30 19:34:26 +04:00
|
|
|
window_schedule_redraw(window);
|
2012-11-27 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 16:41:35 +04:00
|
|
|
static void
|
|
|
|
key_handler(struct window *window, struct input *input, uint32_t time,
|
|
|
|
uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int transform, scale;
|
|
|
|
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
transform = window_get_buffer_transform (window);
|
|
|
|
scale = window_get_buffer_scale (window);
|
|
|
|
switch (sym) {
|
|
|
|
case XKB_KEY_Left:
|
|
|
|
if (transform == 0)
|
|
|
|
transform = 3;
|
|
|
|
else if (transform == 4)
|
|
|
|
transform = 7;
|
|
|
|
else
|
|
|
|
transform--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XKB_KEY_Right:
|
|
|
|
if (transform == 3)
|
|
|
|
transform = 0;
|
|
|
|
else if (transform == 7)
|
|
|
|
transform = 4;
|
|
|
|
else
|
|
|
|
transform++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XKB_KEY_space:
|
|
|
|
if (transform >= 4)
|
|
|
|
transform -= 4;
|
|
|
|
else
|
|
|
|
transform += 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XKB_KEY_z:
|
|
|
|
if (scale == 1)
|
|
|
|
scale = 2;
|
|
|
|
else
|
|
|
|
scale = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("setting buffer transform to %d\n", transform);
|
|
|
|
printf ("setting buffer scale to %d\n", scale);
|
|
|
|
window_set_buffer_transform(window, transform);
|
|
|
|
window_set_buffer_scale(window, scale);
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
|
|
|
|
2012-11-27 19:03:44 +04:00
|
|
|
static void
|
2012-11-30 19:34:26 +04:00
|
|
|
button_handler(struct widget *widget,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
uint32_t button, enum wl_pointer_button_state state, void *data)
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
struct transformed *transformed = data;
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
switch (button) {
|
|
|
|
case BTN_LEFT:
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
window_move(transformed->window, input,
|
|
|
|
display_get_serial(transformed->display));
|
|
|
|
break;
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
widget_schedule_redraw(widget);
|
|
|
|
break;
|
|
|
|
case BTN_RIGHT:
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
window_show_frame_menu(transformed->window, input, time);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-27 19:03:44 +04:00
|
|
|
}
|
|
|
|
|
2013-08-15 20:10:08 +04:00
|
|
|
static void
|
2015-05-15 18:17:47 +03:00
|
|
|
touch_handler(struct widget *widget, struct input *input,
|
|
|
|
uint32_t serial, uint32_t time, int32_t id,
|
2013-08-15 20:10:08 +04:00
|
|
|
float x, float y, void *data)
|
|
|
|
{
|
|
|
|
struct transformed *transformed = data;
|
2013-11-13 05:19:57 +04:00
|
|
|
window_move(transformed->window, input, display_get_serial(transformed->display));
|
2013-08-15 20:10:08 +04:00
|
|
|
}
|
|
|
|
|
2012-12-14 19:37:24 +04:00
|
|
|
static void
|
|
|
|
usage(int error_code)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: transformed [OPTIONS]\n\n"
|
|
|
|
" -w <width>\tSet window width to <width>\n"
|
|
|
|
" -h <height>\tSet window height to <height>\n"
|
|
|
|
" --help\tShow this help text\n\n");
|
|
|
|
|
Redefine output rotations
It was discovered in issue #99 that the implementations of the 90 and 270
degree rotations were actually the inverse of what the Wayland specification
spelled out. This patch fixes the libweston implementation to follow the
specification.
As a result, the behaviour of the the weston.ini transform key also changes. To
force all users to re-think their configuration, the transform key values are
also changed. Since Weston and libweston change their behaviour, the handling
of clients' buffer transform changes too.
All the functions had their 90/270 cases simply swapped, probably due to
confusion of whether WL_OUTPUT_TRANSFORM_* refers to rotating the monitor or
the content.
Hint: a key to understanding weston_matrix_rotate_xy(m, c, s) is that the
rotation matrix is formed as
c -s
s c
that is, it's column-major. This fooled me at first.
Fixing window.c fixes weston-terminal and weston-transformed.
In simple-damage, window_get_transformed_ball() is fixed to follow the proper
transform definitions, but the fix to the viewport path in redraw() is purely
mechanical. The viewport path looks broken to me in the presence of any
transform, but it is not this patch's job to fix it.
Screen-share fix just repeats the general code fix pattern, I did not even try
to understand that bit.
https://gitlab.freedesktop.org/wayland/weston/issues/99
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2020-02-06 16:27:54 +03:00
|
|
|
fprintf(stderr, "This version has been fixed for "
|
|
|
|
"https://gitlab.freedesktop.org/wayland/weston/issues/99 .\n");
|
|
|
|
|
2012-12-14 19:37:24 +04:00
|
|
|
exit(error_code);
|
|
|
|
}
|
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
int main(int argc, char *argv[])
|
2012-11-27 19:03:44 +04:00
|
|
|
{
|
2012-11-30 19:34:26 +04:00
|
|
|
struct transformed transformed;
|
|
|
|
struct display *d;
|
2012-12-14 19:37:24 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
transformed.width = 500;
|
|
|
|
transformed.height = 250;
|
|
|
|
transformed.fullscreen = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2013-11-12 04:04:29 +04:00
|
|
|
if (strcmp(argv[i], "-w") == 0) {
|
2012-12-14 19:37:24 +04:00
|
|
|
if (++i >= argc)
|
|
|
|
usage(EXIT_FAILURE);
|
|
|
|
|
|
|
|
transformed.width = atol(argv[i]);
|
|
|
|
} else if (strcmp(argv[i], "-h") == 0) {
|
|
|
|
if (++i >= argc)
|
|
|
|
usage(EXIT_FAILURE);
|
|
|
|
|
|
|
|
transformed.height = atol(argv[i]);
|
|
|
|
} else if (strcmp(argv[i], "--help") == 0)
|
|
|
|
usage(EXIT_SUCCESS);
|
|
|
|
else
|
|
|
|
usage(EXIT_FAILURE);
|
|
|
|
}
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2013-02-21 00:27:49 +04:00
|
|
|
d = display_create(&argc, argv);
|
2012-11-30 19:34:26 +04:00
|
|
|
if (d == NULL) {
|
2019-04-27 00:57:31 +03:00
|
|
|
fprintf(stderr, "failed to create display: %s\n",
|
|
|
|
strerror(errno));
|
2012-11-30 19:34:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
transformed.display = d;
|
|
|
|
transformed.window = window_create(d);
|
|
|
|
transformed.widget =
|
|
|
|
window_add_widget(transformed.window, &transformed);
|
2012-12-14 19:37:24 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
window_set_title(transformed.window, "Transformed");
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
widget_set_transparent(transformed.widget, 0);
|
2012-11-30 23:54:35 +04:00
|
|
|
widget_set_default_cursor(transformed.widget, CURSOR_BLANK);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
widget_set_redraw_handler(transformed.widget, redraw_handler);
|
|
|
|
widget_set_button_handler(transformed.widget, button_handler);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2013-08-15 20:10:08 +04:00
|
|
|
widget_set_touch_down_handler(transformed.widget, touch_handler);
|
|
|
|
|
2013-05-22 16:41:35 +04:00
|
|
|
window_set_key_handler(transformed.window, key_handler);
|
2012-11-30 19:34:26 +04:00
|
|
|
window_set_fullscreen_handler(transformed.window, fullscreen_handler);
|
|
|
|
window_set_output_handler(transformed.window, output_handler);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
window_set_user_data(transformed.window, &transformed);
|
|
|
|
window_schedule_resize(transformed.window,
|
|
|
|
transformed.width, transformed.height);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
2012-11-30 19:34:26 +04:00
|
|
|
display_run(d);
|
2014-05-15 17:28:16 +04:00
|
|
|
widget_destroy(transformed.widget);
|
|
|
|
window_destroy(transformed.window);
|
|
|
|
display_destroy(d);
|
2012-11-27 19:03:44 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|