Get output width and height.

This commit is contained in:
Jari Vetoniemi 2014-11-02 07:58:34 +02:00
parent dfda59ad18
commit e8fc51d80c
5 changed files with 56 additions and 20 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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);