Message ID | 20240318113140.88151-2-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | ui/display: Introduce API to change console orientation | expand |
On 2024/03/18 20:31, Philippe Mathieu-Daudé wrote: > Extract the following methods: > > - qemu_console_set_rotate() > - qemu_console_is_rotated() > - qemu_console_get_rotate_arcdegree() > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> > --- > include/ui/console.h | 3 +++ > ui/console.c | 16 ++++++++++++++++ > ui/input.c | 9 ++++----- > 3 files changed, 23 insertions(+), 5 deletions(-) > > diff --git a/include/ui/console.h b/include/ui/console.h > index a4a49ffc64..86ba36e391 100644 > --- a/include/ui/console.h > +++ b/include/ui/console.h > @@ -422,15 +422,18 @@ bool qemu_console_is_visible(QemuConsole *con); > bool qemu_console_is_graphic(QemuConsole *con); > bool qemu_console_is_fixedsize(QemuConsole *con); > bool qemu_console_is_gl_blocked(QemuConsole *con); > +bool qemu_console_is_rotated(QemuConsole *con); > char *qemu_console_get_label(QemuConsole *con); > int qemu_console_get_index(QemuConsole *con); > uint32_t qemu_console_get_head(QemuConsole *con); > int qemu_console_get_width(QemuConsole *con, int fallback); > int qemu_console_get_height(QemuConsole *con, int fallback); > +unsigned qemu_console_get_rotate_arcdegree(QemuConsole *con); > /* Return the low-level window id for the console */ > int qemu_console_get_window_id(QemuConsole *con); > /* Set the low-level window id for the console */ > void qemu_console_set_window_id(QemuConsole *con, int window_id); > +void qemu_console_set_rotate(QemuConsole *con, unsigned arcdegree); > > void console_select(unsigned int index); > void qemu_console_resize(QemuConsole *con, int width, int height); > diff --git a/ui/console.c b/ui/console.c > index 832055675c..84aee76846 100644 > --- a/ui/console.c > +++ b/ui/console.c > @@ -37,6 +37,7 @@ > #include "trace.h" > #include "exec/memory.h" > #include "qom/object.h" > +#include "sysemu/sysemu.h" > > #include "console-priv.h" > > @@ -207,6 +208,21 @@ void qemu_console_set_window_id(QemuConsole *con, int window_id) > con->window_id = window_id; > } > > +void qemu_console_set_rotate(QemuConsole *con, unsigned arcdegree) > +{ > + graphic_rotate = arcdegree; > +} > + > +bool qemu_console_is_rotated(QemuConsole *con) > +{ > + return graphic_rotate != 0; > +} > + > +unsigned qemu_console_get_rotate_arcdegree(QemuConsole *con) > +{ > + return graphic_rotate; > +} > + > void graphic_hw_invalidate(QemuConsole *con) > { > if (!con) { > diff --git a/ui/input.c b/ui/input.c > index dc745860f4..951806bf05 100644 > --- a/ui/input.c > +++ b/ui/input.c > @@ -1,5 +1,4 @@ > #include "qemu/osdep.h" > -#include "sysemu/sysemu.h" > #include "qapi/error.h" > #include "qapi/qapi-commands-ui.h" > #include "trace.h" > @@ -179,10 +178,10 @@ static int qemu_input_transform_invert_abs_value(int value) > return (int64_t)INPUT_EVENT_ABS_MAX - value + INPUT_EVENT_ABS_MIN; > } > > -static void qemu_input_transform_abs_rotate(InputEvent *evt) > +static void qemu_input_transform_abs_rotate(QemuConsole *src, InputEvent *evt) > { > InputMoveEvent *move = evt->u.abs.data; > - switch (graphic_rotate) { > + switch (qemu_console_get_rotate_arcdegree(src)) { > case 90: > if (move->axis == INPUT_AXIS_X) { > move->axis = INPUT_AXIS_Y; > @@ -341,8 +340,8 @@ void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt) > qemu_input_event_trace(src, evt); > > /* pre processing */ > - if (graphic_rotate && (evt->type == INPUT_EVENT_KIND_ABS)) { > - qemu_input_transform_abs_rotate(evt); > + if (qemu_console_is_rotated(src) && (evt->type == INPUT_EVENT_KIND_ABS)) { > + qemu_input_transform_abs_rotate(src, evt); > } > > /* send event */
diff --git a/include/ui/console.h b/include/ui/console.h index a4a49ffc64..86ba36e391 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -422,15 +422,18 @@ bool qemu_console_is_visible(QemuConsole *con); bool qemu_console_is_graphic(QemuConsole *con); bool qemu_console_is_fixedsize(QemuConsole *con); bool qemu_console_is_gl_blocked(QemuConsole *con); +bool qemu_console_is_rotated(QemuConsole *con); char *qemu_console_get_label(QemuConsole *con); int qemu_console_get_index(QemuConsole *con); uint32_t qemu_console_get_head(QemuConsole *con); int qemu_console_get_width(QemuConsole *con, int fallback); int qemu_console_get_height(QemuConsole *con, int fallback); +unsigned qemu_console_get_rotate_arcdegree(QemuConsole *con); /* Return the low-level window id for the console */ int qemu_console_get_window_id(QemuConsole *con); /* Set the low-level window id for the console */ void qemu_console_set_window_id(QemuConsole *con, int window_id); +void qemu_console_set_rotate(QemuConsole *con, unsigned arcdegree); void console_select(unsigned int index); void qemu_console_resize(QemuConsole *con, int width, int height); diff --git a/ui/console.c b/ui/console.c index 832055675c..84aee76846 100644 --- a/ui/console.c +++ b/ui/console.c @@ -37,6 +37,7 @@ #include "trace.h" #include "exec/memory.h" #include "qom/object.h" +#include "sysemu/sysemu.h" #include "console-priv.h" @@ -207,6 +208,21 @@ void qemu_console_set_window_id(QemuConsole *con, int window_id) con->window_id = window_id; } +void qemu_console_set_rotate(QemuConsole *con, unsigned arcdegree) +{ + graphic_rotate = arcdegree; +} + +bool qemu_console_is_rotated(QemuConsole *con) +{ + return graphic_rotate != 0; +} + +unsigned qemu_console_get_rotate_arcdegree(QemuConsole *con) +{ + return graphic_rotate; +} + void graphic_hw_invalidate(QemuConsole *con) { if (!con) { diff --git a/ui/input.c b/ui/input.c index dc745860f4..951806bf05 100644 --- a/ui/input.c +++ b/ui/input.c @@ -1,5 +1,4 @@ #include "qemu/osdep.h" -#include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-commands-ui.h" #include "trace.h" @@ -179,10 +178,10 @@ static int qemu_input_transform_invert_abs_value(int value) return (int64_t)INPUT_EVENT_ABS_MAX - value + INPUT_EVENT_ABS_MIN; } -static void qemu_input_transform_abs_rotate(InputEvent *evt) +static void qemu_input_transform_abs_rotate(QemuConsole *src, InputEvent *evt) { InputMoveEvent *move = evt->u.abs.data; - switch (graphic_rotate) { + switch (qemu_console_get_rotate_arcdegree(src)) { case 90: if (move->axis == INPUT_AXIS_X) { move->axis = INPUT_AXIS_Y; @@ -341,8 +340,8 @@ void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt) qemu_input_event_trace(src, evt); /* pre processing */ - if (graphic_rotate && (evt->type == INPUT_EVENT_KIND_ABS)) { - qemu_input_transform_abs_rotate(evt); + if (qemu_console_is_rotated(src) && (evt->type == INPUT_EVENT_KIND_ABS)) { + qemu_input_transform_abs_rotate(src, evt); } /* send event */
Extract the following methods: - qemu_console_set_rotate() - qemu_console_is_rotated() - qemu_console_get_rotate_arcdegree() Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/ui/console.h | 3 +++ ui/console.c | 16 ++++++++++++++++ ui/input.c | 9 ++++----- 3 files changed, 23 insertions(+), 5 deletions(-)