window: expose outputs to applications

Add output_configure_handler as a display property. This exposes only
configured outputs, that is the current mode info is already received,
to applications.

The handler is also called for mode changes on an existing output. This
simplifies the implementation in toytoolkit as we can defer the handler
calls from wl_output binding time to when we receive the current mode.
We do not need separate handlers for "new output" and "mode changed". A
plain "new output" handler would be problematic as the current mode is
not known yet.

Also add delete_handler hook for outputs, but that will never be called
for now, as the protocol lacks a way to signal output disconnections.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
dev
Pekka Paalanen 13 years ago
parent 6e16811e5e
commit 999c5b5dcb
  1. 64
      clients/window.c
  2. 31
      clients/window.h

@ -90,6 +90,10 @@ struct display {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
PFNEGLCREATEIMAGEKHRPROC create_image;
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
display_output_handler_t output_configure_handler;
void *user_data;
};
enum {
@ -168,6 +172,9 @@ struct output {
struct wl_output *output;
struct rectangle allocation;
struct wl_list link;
display_output_handler_t destroy_handler;
void *user_data;
};
enum {
@ -2076,10 +2083,14 @@ display_handle_mode(void *data,
int refresh)
{
struct output *output = data;
struct display *display = output->display;
if (flags & WL_OUTPUT_MODE_CURRENT) {
output->allocation.width = width;
output->allocation.height = height;
if (display->output_configure_handler)
(*display->output_configure_handler)(
output, display->user_data);
}
}
@ -2106,12 +2117,53 @@ display_add_output(struct display *d, uint32_t id)
wl_output_add_listener(output->output, &output_listener, output);
}
void
display_set_output_configure_handler(struct display *display,
display_output_handler_t handler)
{
struct output *output;
display->output_configure_handler = handler;
if (!handler)
return;
wl_list_for_each(output, &display->output_list, link)
(*display->output_configure_handler)(output,
display->user_data);
}
void
output_set_user_data(struct output *output, void *data)
{
output->user_data = data;
}
void *
output_get_user_data(struct output *output)
{
return output->user_data;
}
void
output_set_destroy_handler(struct output *output,
display_output_handler_t handler)
{
output->destroy_handler = handler;
/* FIXME: implement this, once we have way to remove outputs */
}
void
output_get_allocation(struct output *output, struct rectangle *allocation)
{
*allocation = output->allocation;
}
struct wl_output *
output_get_wl_output(struct output *output)
{
return output->output;
}
static void
display_add_input(struct display *d, uint32_t id)
{
@ -2395,6 +2447,18 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
return d;
}
void
display_set_user_data(struct display *display, void *data)
{
display->user_data = data;
}
void *
display_get_user_data(struct display *display)
{
return display->user_data;
}
struct wl_display *
display_get_display(struct display *display)
{

@ -49,6 +49,12 @@ struct rectangle {
struct display *
display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
void
display_set_user_data(struct display *display, void *data);
void *
display_get_user_data(struct display *display);
struct wl_display *
display_get_display(struct display *display);
@ -61,6 +67,19 @@ display_get_shell(struct display *display);
struct output *
display_get_output(struct display *display);
typedef void (*display_output_handler_t)(struct output *output, void *data);
/*
* The output configure handler is called, when a new output is connected
* and we know its current mode, or when the current mode changes.
* Test and set the output user data in your handler to know, if the
* output is new. Note: 'data' in the configure handler is the display
* user data.
*/
void
display_set_output_configure_handler(struct display *display,
display_output_handler_t handler);
struct wl_data_source *
display_create_data_source(struct display *display);
@ -358,8 +377,20 @@ int
input_receive_selection_data(struct input *input, const char *mime_type,
data_func_t func, void *data);
void
output_set_user_data(struct output *output, void *data);
void *
output_get_user_data(struct output *output);
void
output_set_destroy_handler(struct output *output,
display_output_handler_t handler);
void
output_get_allocation(struct output *output, struct rectangle *allocation);
struct wl_output *
output_get_wl_output(struct output *output);
#endif

Loading…
Cancel
Save