From e8fc51d80cdd955f47113f63e22068f3a00d4224 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sun, 2 Nov 2014 07:58:34 +0200 Subject: Get output width and height. --- lib/renderers/cairo.h | 6 +++++- lib/renderers/wayland/registry.c | 44 ++++++++++++++++++++++++++++++++++++++-- lib/renderers/wayland/wayland.c | 3 +++ lib/renderers/wayland/wayland.h | 3 ++- lib/renderers/wayland/window.c | 20 ++++-------------- 5 files changed, 56 insertions(+), 20 deletions(-) (limited to 'lib/renderers') diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index 7eb5bd1..d9ba093 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -10,6 +10,10 @@ # define MAX(a,b) (((a)>(b))?(a):(b)) #endif +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + struct cairo { cairo_t *cr; cairo_surface_t *surface; @@ -145,7 +149,7 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, const struc bm_cairo_draw_line(cairo, &paint, &result, "%s", (menu->filter ? menu->filter : "")); uint32_t displayed = 1; - uint32_t lines = MAX(height / (paint.fe.height + 4), menu->lines); + uint32_t lines = MAX(height / (paint.fe.height + 4), 1); if (lines > 1) { uint32_t start_x = 0; if (menu->prefix) { diff --git a/lib/renderers/wayland/registry.c b/lib/renderers/wayland/registry.c index 1faef18..9521374 100644 --- a/lib/renderers/wayland/registry.c +++ b/lib/renderers/wayland/registry.c @@ -236,8 +236,45 @@ seat_handle_name(void *data, struct wl_seat *seat, const char *name) } static const struct wl_seat_listener seat_listener = { - seat_handle_capabilities, - seat_handle_name + .capabilities = seat_handle_capabilities, + .name = seat_handle_name +}; + +static void +display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y, int physical_width, int physical_height, int subpixel, const char *make, const char *model, int transform) +{ + (void)data, (void)wl_output, (void)x, (void)y, (void)physical_width, (void)physical_height, (void)subpixel, (void)make, (void)model, (void)transform; +} + +static void +display_handle_done(void *data, struct wl_output *wl_output) +{ + (void)data, (void)wl_output; +} + +static void +display_handle_scale(void *data, struct wl_output *wl_output, int32_t scale) +{ + (void)data, (void)wl_output, (void)scale; +} + +static void +display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags, int width, int height, int refresh) +{ + (void)wl_output, (void)refresh, (void)height; + struct wayland *wayland = data; + + if (flags & WL_OUTPUT_MODE_CURRENT) { + wayland->window.width = width; + wayland->window.max_height = height; + } +} + +static const struct wl_output_listener output_listener = { + .geometry = display_handle_geometry, + .mode = display_handle_mode, + .done = display_handle_done, + .scale = display_handle_scale }; static void @@ -260,6 +297,9 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t id, co } else if (strcmp(interface, "wl_shm") == 0) { wayland->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1); wl_shm_add_listener(wayland->shm, &shm_listener, data); + } else if (strcmp(interface, "wl_output") == 0) { + wayland->output = wl_registry_bind(registry, id, &wl_output_interface, 2); + wl_output_add_listener(wayland->output, &output_listener, wayland); } } diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index c447b6e..2cdedec 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -183,6 +183,9 @@ constructor(struct bm_menu *menu) if (!(menu->renderer->internal = wayland = calloc(1, sizeof(struct wayland)))) goto fail; + wayland->window.width = 800; + wayland->window.height = 14; + if (!(wayland->display = wl_display_connect(NULL))) goto fail; diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index db837e9..50455b5 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -80,7 +80,7 @@ struct window { struct xdg_surface *xdg_surface; struct wl_shm *shm; struct buffer buffers[2]; - uint32_t width, height; + uint32_t width, height, max_height; uint32_t displayed; struct { @@ -97,6 +97,7 @@ struct wayland { struct wl_display *display; struct wl_registry *registry; struct wl_compositor *compositor; + struct wl_output *output; struct wl_seat *seat; struct xdg_shell *xdg_shell; struct wl_shell *shell; diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index 057863d..bfd1715 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -194,25 +194,17 @@ next_buffer(struct window *window) return buffer; } -static void -resize(struct window *window, uint32_t width, uint32_t height) -{ - window->width = width; - window->height = height; -} - static void shell_surface_ping(void *data, struct wl_shell_surface *surface, uint32_t serial) { - (void)data; + (void)data; wl_shell_surface_pong(surface, serial); } static void shell_surface_configure(void *data, struct wl_shell_surface *surface, uint32_t edges, int32_t width, int32_t height) { - (void)surface, (void)edges; - resize(data, width, height); + (void)data, (void)surface, (void)edges, (void)width, (void)height; } static void @@ -230,8 +222,7 @@ static const struct wl_shell_surface_listener shell_surface_listener = { static void xdg_surface_configure(void *data, struct xdg_surface *surface, int32_t width, int32_t height, struct wl_array *states, uint32_t serial) { - (void)states; - resize(data, width, height); + (void)data, (void)states, (void)width, (void)height, (void)states, (void)serial; xdg_surface_ack_configure(surface, serial); } @@ -273,7 +264,7 @@ bm_wl_window_render(struct window *window, const struct bm_menu *menu, uint32_t cairo_font_extents_t fe; bm_cairo_get_font_extents(&buffer->cairo, &menu->font, &fe); - window->height = lines * (fe.height + 4); + window->height = MIN(lines * (fe.height + 4), window->max_height); if (window->height != buffer->height && !(buffer = next_buffer(window))) return; @@ -325,9 +316,6 @@ bm_wl_window_create(struct window *window, struct wl_shm *shm, struct wl_shell * return false; } - window->width = 800; - window->height = 240; - window->shm = shm; window->surface = surface; wl_surface_damage(surface, 0, 0, window->width, window->height); -- cgit v1.2.3-70-g09d2