diff options
author | Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp> | 2014-04-19 22:15:20 +0900 |
---|---|---|
committer | Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp> | 2014-04-19 22:15:20 +0900 |
commit | 2991da5687fa2828d551fd7b2388d9648a19ecc2 (patch) | |
tree | 56aff659352fa256c7a8f78c21835e213978d0c9 /clients/fullscreen.c | |
parent | ef9195febc0e67a116b2f1d093cbcbeb629c92b4 (diff) | |
download | weston-2991da5687fa2828d551fd7b2388d9648a19ecc2.tar.gz |
1.4.91
Change-Id: Ibfed4937c6083937d2b29154e0485c1caf8365a1
Diffstat (limited to 'clients/fullscreen.c')
-rw-r--r-- | clients/fullscreen.c | 271 |
1 files changed, 247 insertions, 24 deletions
diff --git a/clients/fullscreen.c b/clients/fullscreen.c index 034a3528..fa8028a9 100644 --- a/clients/fullscreen.c +++ b/clients/fullscreen.c @@ -21,6 +21,8 @@ * OF THIS SOFTWARE. */ +#include "config.h" + #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -32,15 +34,26 @@ #include <linux/input.h> #include <wayland-client.h> #include "window.h" +#include "fullscreen-shell-client-protocol.h" + +struct fs_output { + struct wl_list link; + struct output *output; +}; struct fullscreen { struct display *display; struct window *window; struct widget *widget; + struct _wl_fullscreen_shell *fshell; + enum _wl_fullscreen_shell_present_method present_method; int width, height; int fullscreen; float pointer_x, pointer_y; - enum wl_shell_surface_fullscreen_method fullscreen_method; + int focussed, draw_cursor; + + struct wl_list output_list; + struct fs_output *current_output; }; static void @@ -114,7 +127,7 @@ redraw_handler(struct widget *widget, void *data) cairo_t *cr; int i; double x, y, border; - const char *method_name[] = { "default", "scale", "driver", "fill" }; + const char *method_name[] = { "default", "center", "zoom", "zoom_crop", "stretch"}; surface = window_get_surface(fullscreen->window); if (surface == NULL || @@ -140,17 +153,33 @@ redraw_handler(struct widget *widget, void *data) allocation.y + 25); cairo_set_source_rgb(cr, 1, 1, 1); - draw_string(cr, - "Surface size: %d, %d\n" - "Scale: %d, transform: %d\n" - "Pointer: %f,%f\n" - "Fullscreen: %d, method: %s\n" - "Keys: (s)cale, (t)ransform, si(z)e, (m)ethod, (f)ullscreen, (q)uit\n", - fullscreen->width, fullscreen->height, - window_get_buffer_scale (fullscreen->window), - window_get_buffer_transform (fullscreen->window), - fullscreen->pointer_x, fullscreen->pointer_y, - fullscreen->fullscreen, method_name[fullscreen->fullscreen_method]); + if (fullscreen->fshell) { + draw_string(cr, + "Surface size: %d, %d\n" + "Scale: %d, transform: %d\n" + "Pointer: %f,%f\n" + "Output: %s, present method: %s\n" + "Keys: (s)cale, (t)ransform, si(z)e, (m)ethod,\n" + " (o)utput, modes(w)itch, (q)uit\n", + fullscreen->width, fullscreen->height, + window_get_buffer_scale (fullscreen->window), + window_get_buffer_transform (fullscreen->window), + fullscreen->pointer_x, fullscreen->pointer_y, + method_name[fullscreen->present_method], + fullscreen->current_output ? output_get_model(fullscreen->current_output->output): "null"); + } else { + draw_string(cr, + "Surface size: %d, %d\n" + "Scale: %d, transform: %d\n" + "Pointer: %f,%f\n" + "Fullscreen: %d\n" + "Keys: (s)cale, (t)ransform, si(z)e, (f)ullscreen, (q)uit\n", + fullscreen->width, fullscreen->height, + window_get_buffer_scale (fullscreen->window), + window_get_buffer_transform (fullscreen->window), + fullscreen->pointer_x, fullscreen->pointer_y, + fullscreen->fullscreen); + } y = 100; i = 0; @@ -160,7 +189,8 @@ redraw_handler(struct widget *widget, void *data) x = 50; cairo_set_line_width (cr, border); while (x + 70 < fullscreen->width) { - if (fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 && + if (fullscreen->focussed && + fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 && fullscreen->pointer_y >= y && fullscreen->pointer_y < y + 40) { cairo_set_source_rgb(cr, 1, 0, 0); cairo_rectangle(cr, @@ -179,6 +209,44 @@ redraw_handler(struct widget *widget, void *data) y += 50; } + if (fullscreen->focussed && fullscreen->draw_cursor) { + cairo_set_source_rgb(cr, 1, 1, 1); + cairo_set_line_width (cr, 8); + cairo_move_to(cr, + fullscreen->pointer_x - 12, + fullscreen->pointer_y - 12); + cairo_line_to(cr, + fullscreen->pointer_x + 12, + fullscreen->pointer_y + 12); + cairo_stroke(cr); + + cairo_move_to(cr, + fullscreen->pointer_x + 12, + fullscreen->pointer_y - 12); + cairo_line_to(cr, + fullscreen->pointer_x - 12, + fullscreen->pointer_y + 12); + cairo_stroke(cr); + + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_set_line_width (cr, 4); + cairo_move_to(cr, + fullscreen->pointer_x - 10, + fullscreen->pointer_y - 10); + cairo_line_to(cr, + fullscreen->pointer_x + 10, + fullscreen->pointer_y + 10); + cairo_stroke(cr); + + cairo_move_to(cr, + fullscreen->pointer_x + 10, + fullscreen->pointer_y - 10); + cairo_line_to(cr, + fullscreen->pointer_x - 10, + fullscreen->pointer_y + 10); + cairo_stroke(cr); + } + cairo_destroy(cr); } @@ -190,6 +258,8 @@ key_handler(struct window *window, struct input *input, uint32_t time, struct fullscreen *fullscreen = data; int transform, scale; static int current_size = 0; + struct fs_output *fsout; + struct wl_output *wl_output; int widths[] = { 640, 320, 800, 400 }; int heights[] = { 480, 240, 600, 300 }; @@ -223,13 +293,68 @@ key_handler(struct window *window, struct input *input, uint32_t time, break; case XKB_KEY_m: - fullscreen->fullscreen_method = (fullscreen->fullscreen_method + 1) % 4; - window_set_fullscreen_method(fullscreen->window, - fullscreen->fullscreen_method); + if (!fullscreen->fshell) + break; + + wl_output = NULL; + if (fullscreen->current_output) + wl_output = output_get_wl_output(fullscreen->current_output->output); + fullscreen->present_method = (fullscreen->present_method + 1) % 5; + _wl_fullscreen_shell_present_surface(fullscreen->fshell, + window_get_wl_surface(fullscreen->window), + fullscreen->present_method, + wl_output); + window_schedule_redraw(window); + break; + + case XKB_KEY_o: + if (!fullscreen->fshell) + break; + + fsout = fullscreen->current_output; + wl_output = fsout ? output_get_wl_output(fsout->output) : NULL; + + /* Clear the current presentation */ + _wl_fullscreen_shell_present_surface(fullscreen->fshell, NULL, + 0, wl_output); + + if (fullscreen->current_output) { + if (fullscreen->current_output->link.next == &fullscreen->output_list) + fsout = NULL; + else + fsout = wl_container_of(fullscreen->current_output->link.next, + fsout, link); + } else { + fsout = wl_container_of(fullscreen->output_list.next, + fsout, link); + } + + fullscreen->current_output = fsout; + wl_output = fsout ? output_get_wl_output(fsout->output) : NULL; + _wl_fullscreen_shell_present_surface(fullscreen->fshell, + window_get_wl_surface(fullscreen->window), + fullscreen->present_method, + wl_output); + window_schedule_redraw(window); + break; + + case XKB_KEY_w: + if (!fullscreen->fshell || !fullscreen->current_output) + break; + + wl_output = NULL; + if (fullscreen->current_output) + wl_output = output_get_wl_output(fullscreen->current_output->output); + _wl_fullscreen_shell_mode_feedback_destroy( + _wl_fullscreen_shell_present_surface_for_mode(fullscreen->fshell, + window_get_wl_surface(fullscreen->window), + wl_output, 0)); window_schedule_redraw(window); break; case XKB_KEY_f: + if (fullscreen->fshell) + break; fullscreen->fullscreen ^= 1; window_set_fullscreen(window, fullscreen->fullscreen); break; @@ -253,9 +378,37 @@ motion_handler(struct widget *widget, fullscreen->pointer_y = y; widget_schedule_redraw(widget); - return 0; + + return fullscreen->draw_cursor ? CURSOR_BLANK : CURSOR_LEFT_PTR; +} + +static int +enter_handler(struct widget *widget, + struct input *input, + float x, float y, void *data) +{ + struct fullscreen *fullscreen = data; + + fullscreen->focussed++; + + fullscreen->pointer_x = x; + fullscreen->pointer_y = y; + + widget_schedule_redraw(widget); + + return fullscreen->draw_cursor ? CURSOR_BLANK : CURSOR_LEFT_PTR; } +static void +leave_handler(struct widget *widget, + struct input *input, void *data) +{ + struct fullscreen *fullscreen = data; + + fullscreen->focussed--; + + widget_schedule_redraw(widget); +} static void button_handler(struct widget *widget, @@ -287,6 +440,25 @@ touch_handler(struct widget *widget, struct input *input, } static void +fshell_capability_handler(void *data, struct _wl_fullscreen_shell *fshell, + uint32_t capability) +{ + struct fullscreen *fullscreen = data; + + switch (capability) { + case _WL_FULLSCREEN_SHELL_CAPABILITY_CURSOR_PLANE: + fullscreen->draw_cursor = 0; + break; + default: + break; + } +} + +struct _wl_fullscreen_shell_listener fullscreen_shell_listener = { + fshell_capability_handler +}; + +static void usage(int error_code) { fprintf(stderr, "Usage: fullscreen [OPTIONS]\n\n" @@ -297,6 +469,38 @@ usage(int error_code) exit(error_code); } +static void +output_handler(struct output *output, void *data) +{ + struct fullscreen *fullscreen = data; + struct fs_output *fsout; + + /* If we've already seen this one, don't add it to the list */ + wl_list_for_each(fsout, &fullscreen->output_list, link) + if (fsout->output == output) + return; + + fsout = calloc(1, sizeof *fsout); + fsout->output = output; + wl_list_insert(&fullscreen->output_list, &fsout->link); +} + +static void +global_handler(struct display *display, uint32_t id, const char *interface, + uint32_t version, void *data) +{ + struct fullscreen *fullscreen = data; + + if (strcmp(interface, "_wl_fullscreen_shell") == 0) { + fullscreen->fshell = display_bind(display, id, + &_wl_fullscreen_shell_interface, + 1); + _wl_fullscreen_shell_add_listener(fullscreen->fshell, + &fullscreen_shell_listener, + fullscreen); + } +} + int main(int argc, char *argv[]) { struct fullscreen fullscreen; @@ -306,8 +510,10 @@ int main(int argc, char *argv[]) fullscreen.width = 640; fullscreen.height = 480; fullscreen.fullscreen = 0; - fullscreen.fullscreen_method = - WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; + fullscreen.focussed = 0; + fullscreen.present_method = _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT; + wl_list_init(&fullscreen.output_list); + fullscreen.current_output = NULL; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-w") == 0) { @@ -333,21 +539,38 @@ int main(int argc, char *argv[]) } fullscreen.display = d; - fullscreen.window = window_create(d); + fullscreen.fshell = NULL; + display_set_user_data(fullscreen.display, &fullscreen); + display_set_global_handler(fullscreen.display, global_handler); + display_set_output_configure_handler(fullscreen.display, output_handler); + + if (fullscreen.fshell) { + fullscreen.window = window_create_custom(d); + _wl_fullscreen_shell_present_surface(fullscreen.fshell, + window_get_wl_surface(fullscreen.window), + fullscreen.present_method, + NULL); + /* If we get the CURSOR_PLANE capability, we'll change this */ + fullscreen.draw_cursor = 1; + } else { + fullscreen.window = window_create(d); + fullscreen.draw_cursor = 0; + } + fullscreen.widget = window_add_widget(fullscreen.window, &fullscreen); window_set_title(fullscreen.window, "Fullscreen"); - window_set_fullscreen_method(fullscreen.window, - fullscreen.fullscreen_method); widget_set_transparent(fullscreen.widget, 0); - widget_set_default_cursor(fullscreen.widget, CURSOR_LEFT_PTR); + widget_set_default_cursor(fullscreen.widget, CURSOR_LEFT_PTR); widget_set_resize_handler(fullscreen.widget, resize_handler); widget_set_redraw_handler(fullscreen.widget, redraw_handler); widget_set_button_handler(fullscreen.widget, button_handler); widget_set_motion_handler(fullscreen.widget, motion_handler); + widget_set_enter_handler(fullscreen.widget, enter_handler); + widget_set_leave_handler(fullscreen.widget, leave_handler); widget_set_touch_down_handler(fullscreen.widget, touch_handler); |