mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-03 09:01:42 -05:00
Add an orange pop-up menu to test the new map_transient request
This commit is contained in:
parent
8dc378ff76
commit
248c1b61ce
10 changed files with 140 additions and 20 deletions
|
|
@ -628,7 +628,6 @@ static struct dnd *
|
||||||
dnd_create(struct display *display)
|
dnd_create(struct display *display)
|
||||||
{
|
{
|
||||||
struct dnd *dnd;
|
struct dnd *dnd;
|
||||||
gchar *title;
|
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
int32_t width, height;
|
int32_t width, height;
|
||||||
|
|
||||||
|
|
@ -637,9 +636,9 @@ dnd_create(struct display *display)
|
||||||
return dnd;
|
return dnd;
|
||||||
memset(dnd, 0, sizeof *dnd);
|
memset(dnd, 0, sizeof *dnd);
|
||||||
|
|
||||||
title = g_strdup_printf("Wayland Drag and Drop Demo");
|
dnd->window = window_create(display, 400, 400);
|
||||||
|
window_set_title(dnd->window, "Wayland Drag and Drop Demo");
|
||||||
|
|
||||||
dnd->window = window_create(display, title, 500, 400);
|
|
||||||
dnd->display = display;
|
dnd->display = display;
|
||||||
dnd->key = 100;
|
dnd->key = 100;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,9 +141,9 @@ int main(int argc, char *argv[])
|
||||||
flower.width = 200;
|
flower.width = 200;
|
||||||
flower.height = 200;
|
flower.height = 200;
|
||||||
flower.display = d;
|
flower.display = d;
|
||||||
flower.window = window_create(d, "flower",
|
flower.window = window_create(d, flower.width, flower.height);
|
||||||
flower.width, flower.height);
|
|
||||||
|
|
||||||
|
window_set_title(flower.window, "flower");
|
||||||
window_set_decoration(flower.window, 0);
|
window_set_decoration(flower.window, 0);
|
||||||
window_draw(flower.window);
|
window_draw(flower.window);
|
||||||
s = window_get_surface(flower.window);
|
s = window_get_surface(flower.window);
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,8 @@ gears_create(struct display *display)
|
||||||
gears = malloc(sizeof *gears);
|
gears = malloc(sizeof *gears);
|
||||||
memset(gears, 0, sizeof *gears);
|
memset(gears, 0, sizeof *gears);
|
||||||
gears->d = display;
|
gears->d = display;
|
||||||
gears->window = window_create(display, "Wayland Gears", width, height);
|
gears->window = window_create(display, width, height);
|
||||||
|
window_set_title(gears->window, "Wayland Gears");
|
||||||
|
|
||||||
gears->display = display_get_egl_display(gears->d);
|
gears->display = display_get_egl_display(gears->d);
|
||||||
if (gears->display == NULL)
|
if (gears->display == NULL)
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,8 @@ image_create(struct display *display, uint32_t key, const char *filename)
|
||||||
|
|
||||||
image->filename = g_strdup(filename);
|
image->filename = g_strdup(filename);
|
||||||
|
|
||||||
image->window = window_create(display, title, 500, 400);
|
image->window = window_create(display, 500, 400);
|
||||||
|
window_set_title(image->window, title);
|
||||||
image->display = display;
|
image->display = display;
|
||||||
|
|
||||||
/* FIXME: Window uses key 1 for moves, need some kind of
|
/* FIXME: Window uses key 1 for moves, need some kind of
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
struct resizor {
|
struct resizor {
|
||||||
struct display *display;
|
struct display *display;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
|
struct window *menu;
|
||||||
int32_t width;
|
int32_t width;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -148,6 +149,38 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_menu(struct resizor *resizor, struct input *input)
|
||||||
|
{
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
int32_t x, y, width = 200, height = 200;
|
||||||
|
|
||||||
|
input_get_position(input, &x, &y);
|
||||||
|
resizor->menu = window_create_transient(resizor->display,
|
||||||
|
resizor->window,
|
||||||
|
x - 10, y - 10, width, height);
|
||||||
|
|
||||||
|
window_draw(resizor->menu);
|
||||||
|
window_flush(resizor->menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
button_handler(struct window *window,
|
||||||
|
struct input *input, uint32_t time,
|
||||||
|
int button, int state, void *data)
|
||||||
|
{
|
||||||
|
struct resizor *resizor = data;
|
||||||
|
|
||||||
|
switch (button) {
|
||||||
|
case 274:
|
||||||
|
if (state)
|
||||||
|
show_menu(resizor, input);
|
||||||
|
else
|
||||||
|
window_destroy(resizor->menu);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static struct resizor *
|
static struct resizor *
|
||||||
resizor_create(struct display *display)
|
resizor_create(struct display *display)
|
||||||
{
|
{
|
||||||
|
|
@ -159,7 +192,8 @@ resizor_create(struct display *display)
|
||||||
return resizor;
|
return resizor;
|
||||||
memset(resizor, 0, sizeof *resizor);
|
memset(resizor, 0, sizeof *resizor);
|
||||||
|
|
||||||
resizor->window = window_create(display, "Wayland Resizor", 500, 400);
|
resizor->window = window_create(display, 500, 400);
|
||||||
|
window_set_title(resizor->window, "Wayland Resizor");
|
||||||
resizor->display = display;
|
resizor->display = display;
|
||||||
|
|
||||||
window_set_key_handler(resizor->window, key_handler);
|
window_set_key_handler(resizor->window, key_handler);
|
||||||
|
|
@ -175,6 +209,7 @@ resizor_create(struct display *display)
|
||||||
height = resizor->height.current + 0.5;
|
height = resizor->height.current + 0.5;
|
||||||
|
|
||||||
window_set_child_size(resizor->window, resizor->width, height);
|
window_set_child_size(resizor->window, resizor->width, height);
|
||||||
|
window_set_button_handler(resizor->window, button_handler);
|
||||||
|
|
||||||
resizor_draw(resizor);
|
resizor_draw(resizor);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,8 @@ int main(int argc, char *argv[])
|
||||||
smoke.width = 200;
|
smoke.width = 200;
|
||||||
smoke.height = 200;
|
smoke.height = 200;
|
||||||
smoke.display = d;
|
smoke.display = d;
|
||||||
smoke.window = window_create(d, "smoke", smoke.width, smoke.height);
|
smoke.window = window_create(d, smoke.width, smoke.height);
|
||||||
|
window_set_title(smoke.window, "smoke");
|
||||||
|
|
||||||
window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM);
|
window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
|
|
||||||
|
|
@ -2213,8 +2213,8 @@ terminal_create(struct display *display, int fullscreen)
|
||||||
terminal_init(terminal);
|
terminal_init(terminal);
|
||||||
terminal->margin_top = 0;
|
terminal->margin_top = 0;
|
||||||
terminal->margin_bottom = -1;
|
terminal->margin_bottom = -1;
|
||||||
terminal->window = window_create(display, "Wayland Terminal",
|
terminal->window = window_create(display, 500, 400);
|
||||||
500, 400);
|
window_set_title(terminal->window, "Wayland Terminal");
|
||||||
|
|
||||||
init_state_machine(&terminal->state_machine);
|
init_state_machine(&terminal->state_machine);
|
||||||
init_color_table(terminal);
|
init_color_table(terminal);
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,8 @@ view_create(struct display *display, uint32_t key, const char *filename)
|
||||||
|
|
||||||
view->filename = g_strdup(filename);
|
view->filename = g_strdup(filename);
|
||||||
|
|
||||||
view->window = window_create(display, title, 500, 400);
|
view->window = window_create(display, 500, 400);
|
||||||
|
window_set_title(view->window, title);
|
||||||
view->display = display;
|
view->display = display;
|
||||||
|
|
||||||
/* FIXME: Window uses key 1 for moves, need some kind of
|
/* FIXME: Window uses key 1 for moves, need some kind of
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,11 @@ struct display {
|
||||||
|
|
||||||
struct window {
|
struct window {
|
||||||
struct display *display;
|
struct display *display;
|
||||||
|
struct window *parent;
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
const char *title;
|
const char *title;
|
||||||
struct rectangle allocation, saved_allocation, server_allocation;
|
struct rectangle allocation, saved_allocation, server_allocation;
|
||||||
|
int x, y;
|
||||||
int resize_edges;
|
int resize_edges;
|
||||||
int redraw_scheduled;
|
int redraw_scheduled;
|
||||||
int minimum_width, minimum_height;
|
int minimum_width, minimum_height;
|
||||||
|
|
@ -598,7 +600,12 @@ window_attach_surface(struct window *window)
|
||||||
wl_display_sync_callback(display->display, free_surface, window);
|
wl_display_sync_callback(display->display, free_surface, window);
|
||||||
|
|
||||||
if (!window->mapped) {
|
if (!window->mapped) {
|
||||||
|
if (!window->parent)
|
||||||
wl_surface_map_toplevel(window->surface);
|
wl_surface_map_toplevel(window->surface);
|
||||||
|
else
|
||||||
|
wl_surface_map_transient(window->surface,
|
||||||
|
window->parent->surface,
|
||||||
|
window->x, window->y, 0);
|
||||||
window->mapped = 1;
|
window->mapped = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -650,6 +657,28 @@ window_create_surface(struct window *window)
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_draw_menu(struct window *window)
|
||||||
|
{
|
||||||
|
cairo_t *cr;
|
||||||
|
int width, height, r = 5;
|
||||||
|
|
||||||
|
window_create_surface(window);
|
||||||
|
|
||||||
|
cr = cairo_create(window->cairo_surface);
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
||||||
|
cairo_paint(cr);
|
||||||
|
|
||||||
|
width = window->allocation.width;
|
||||||
|
height = window->allocation.height;
|
||||||
|
rounded_rect(cr, r, r, width - r, height - r, r);
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_set_source_rgba(cr, 1.0, 1.0, 0.0, 0.5);
|
||||||
|
cairo_fill(cr);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_draw_decorations(struct window *window)
|
window_draw_decorations(struct window *window)
|
||||||
{
|
{
|
||||||
|
|
@ -706,6 +735,14 @@ window_draw_decorations(struct window *window)
|
||||||
cairo_device_flush (window->display->device);
|
cairo_device_flush (window->display->device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
window_destroy(struct window *window)
|
||||||
|
{
|
||||||
|
wl_surface_destroy(window->surface);
|
||||||
|
wl_list_remove(&window->link);
|
||||||
|
free(window);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
display_flush_cairo_device(struct display *display)
|
display_flush_cairo_device(struct display *display)
|
||||||
{
|
{
|
||||||
|
|
@ -715,7 +752,9 @@ display_flush_cairo_device(struct display *display)
|
||||||
void
|
void
|
||||||
window_draw(struct window *window)
|
window_draw(struct window *window)
|
||||||
{
|
{
|
||||||
if (window->fullscreen || !window->decoration)
|
if (window->parent)
|
||||||
|
window_draw_menu(window);
|
||||||
|
else if (window->fullscreen || !window->decoration)
|
||||||
window_create_surface(window);
|
window_create_surface(window);
|
||||||
else
|
else
|
||||||
window_draw_decorations(window);
|
window_draw_decorations(window);
|
||||||
|
|
@ -1202,8 +1241,8 @@ window_damage(struct window *window, int32_t x, int32_t y,
|
||||||
wl_surface_damage(window->surface, x, y, width, height);
|
wl_surface_damage(window->surface, x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct window *
|
static struct window *
|
||||||
window_create(struct display *display, const char *title,
|
window_create_internal(struct display *display, struct window *parent,
|
||||||
int32_t width, int32_t height)
|
int32_t width, int32_t height)
|
||||||
{
|
{
|
||||||
struct window *window;
|
struct window *window;
|
||||||
|
|
@ -1214,7 +1253,7 @@ window_create(struct display *display, const char *title,
|
||||||
|
|
||||||
memset(window, 0, sizeof *window);
|
memset(window, 0, sizeof *window);
|
||||||
window->display = display;
|
window->display = display;
|
||||||
window->title = strdup(title);
|
window->parent = parent;
|
||||||
window->surface = wl_compositor_create_surface(display->compositor);
|
window->surface = wl_compositor_create_surface(display->compositor);
|
||||||
window->allocation.x = 0;
|
window->allocation.x = 0;
|
||||||
window->allocation.y = 0;
|
window->allocation.y = 0;
|
||||||
|
|
@ -1235,6 +1274,41 @@ window_create(struct display *display, const char *title,
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
window_set_title(struct window *window, const char *title)
|
||||||
|
{
|
||||||
|
window->title = strdup(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct window *
|
||||||
|
window_create(struct display *display, int32_t width, int32_t height)
|
||||||
|
{
|
||||||
|
struct window *window;
|
||||||
|
|
||||||
|
window = window_create_internal(display, NULL, width, height);
|
||||||
|
if (!window)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct window *
|
||||||
|
window_create_transient(struct display *display, struct window *parent,
|
||||||
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||||||
|
{
|
||||||
|
struct window *window;
|
||||||
|
|
||||||
|
window = window_create_internal(parent->display,
|
||||||
|
parent, width, height);
|
||||||
|
if (!window)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
window->x = x;
|
||||||
|
window->y = y;
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
window_set_buffer_type(struct window *window, enum window_buffer_type type)
|
window_set_buffer_type(struct window *window, enum window_buffer_type type)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,16 @@ typedef void (*display_global_handler_t)(struct display *display,
|
||||||
uint32_t version);
|
uint32_t version);
|
||||||
|
|
||||||
struct window *
|
struct window *
|
||||||
window_create(struct display *display, const char *title,
|
window_create(struct display *display, int32_t width, int32_t height);
|
||||||
int32_t width, int32_t height);
|
struct window *
|
||||||
|
window_create_transient(struct display *display, struct window *parent,
|
||||||
|
int32_t x, int32_t y, int32_t width, int32_t height);
|
||||||
|
|
||||||
|
void
|
||||||
|
window_destroy(struct window *window);
|
||||||
|
|
||||||
|
void
|
||||||
|
window_set_title(struct window *window, const char *title);
|
||||||
|
|
||||||
void
|
void
|
||||||
window_move(struct window *window, struct input *input, uint32_t time);
|
window_move(struct window *window, struct input *input, uint32_t time);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue