window.c: Cache outputs

dev
Kristian Høgsberg 13 years ago
parent 47fe08aad5
commit 53ff2f6672
  1. 63
      clients/window.c
  2. 8
      clients/window.h

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

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

Loading…
Cancel
Save