window.c: Cache outputs

This commit is contained in:
Kristian Høgsberg 2011-11-26 17:27:37 -05:00
parent 47fe08aad5
commit 53ff2f6672
2 changed files with 60 additions and 11 deletions

View File

@ -64,7 +64,6 @@ struct display {
struct wl_shm *shm;
struct wl_output *output;
struct wl_data_device_manager *data_device_manager;
struct rectangle screen_allocation;
EGLDisplay dpy;
EGLConfig rgb_config;
EGLConfig premultiplied_argb_config;
@ -82,6 +81,7 @@ struct display {
struct wl_list window_list;
struct wl_list input_list;
struct wl_list output_list;
char *device_name;
cairo_surface_t *active_frame, *inactive_frame, *shadow;
struct xkb_desc *xkb;
@ -162,6 +162,13 @@ struct input {
struct data_offer *selection_offer;
};
struct output {
struct display *display;
struct wl_output *output;
struct rectangle allocation;
struct wl_list link;
};
enum {
POINTER_DEFAULT = 100,
POINTER_UNSET
@ -1789,15 +1796,17 @@ void
window_set_fullscreen(struct window *window, int fullscreen)
{
int32_t width, height;
struct output *output;
if ((window->type == TYPE_FULLSCREEN) == fullscreen)
return;
if (fullscreen) {
output = display_get_output(window->display);
window->type = TYPE_FULLSCREEN;
window->saved_allocation = window->allocation;
width = window->display->screen_allocation.width;
height = window->display->screen_allocation.height;
width = output->allocation.width;
height = output->allocation.height;
window->decoration = 0;
} else {
window->type = TYPE_TOPLEVEL;
@ -2026,10 +2035,10 @@ display_handle_geometry(void *data,
const char *make,
const char *model)
{
struct display *display = data;
struct output *output = data;
display->screen_allocation.x = x;
display->screen_allocation.y = y;
output->allocation.x = x;
output->allocation.y = y;
}
static void
@ -2040,10 +2049,12 @@ display_handle_mode(void *data,
int height,
int refresh)
{
struct display *display = data;
struct output *output = data;
display->screen_allocation.width = width;
display->screen_allocation.height = height;
if (flags & WL_OUTPUT_MODE_CURRENT) {
output->allocation.width = width;
output->allocation.height = height;
}
}
static const struct wl_output_listener output_listener = {
@ -2051,6 +2062,30 @@ static const struct wl_output_listener output_listener = {
display_handle_mode
};
static void
display_add_output(struct display *d, uint32_t id)
{
struct output *output;
output = malloc(sizeof *output);
if (output == NULL)
return;
memset(output, 0, sizeof *output);
output->display = d;
output->output =
wl_display_bind(d->display, id, &wl_output_interface);
wl_list_insert(d->output_list.prev, &output->link);
wl_output_add_listener(output->output, &output_listener, output);
}
void
output_get_allocation(struct output *output, struct rectangle *allocation)
{
*allocation = output->allocation;
}
static void
display_add_input(struct display *d, uint32_t id)
{
@ -2089,8 +2124,7 @@ display_handle_global(struct wl_display *display, uint32_t id,
d->compositor =
wl_display_bind(display, id, &wl_compositor_interface);
} else if (strcmp(interface, "wl_output") == 0) {
d->output = wl_display_bind(display, id, &wl_output_interface);
wl_output_add_listener(d->output, &output_listener, d);
display_add_output(d, id);
} else if (strcmp(interface, "wl_input_device") == 0) {
display_add_input(d, id);
} else if (strcmp(interface, "wl_shell") == 0) {
@ -2309,6 +2343,7 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
wl_list_init(&d->deferred_list);
wl_list_init(&d->input_list);
wl_list_init(&d->output_list);
/* Set up listener so we'll catch all events. */
wl_display_add_global_listener(d->display,
@ -2341,6 +2376,12 @@ display_get_display(struct display *display)
return display->display;
}
struct output *
display_get_output(struct display *display)
{
return container_of(display->output_list.next, struct output, link);
}
struct wl_compositor *
display_get_compositor(struct display *display)
{

View File

@ -32,6 +32,7 @@ struct window;
struct item;
struct display;
struct input;
struct output;
struct task {
void (*run)(struct task *task, uint32_t events);
@ -57,6 +58,9 @@ display_get_compositor(struct display *display);
struct wl_shell *
display_get_shell(struct display *display);
struct output *
display_get_output(struct display *display);
struct wl_data_source *
display_create_data_source(struct display *display);
@ -351,6 +355,10 @@ int
input_receive_selection_data(struct input *input, const char *mime_type,
data_func_t func, void *data);
void
output_get_allocation(struct output *output, struct rectangle *allocation);
enum {
CONFIG_KEY_INTEGER,
CONFIG_KEY_STRING,