mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-24 06:59:50 -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
|
|
@ -38,6 +38,7 @@
|
|||
struct resizor {
|
||||
struct display *display;
|
||||
struct window *window;
|
||||
struct window *menu;
|
||||
int32_t width;
|
||||
|
||||
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 *
|
||||
resizor_create(struct display *display)
|
||||
{
|
||||
|
|
@ -159,7 +192,8 @@ resizor_create(struct display *display)
|
|||
return 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;
|
||||
|
||||
window_set_key_handler(resizor->window, key_handler);
|
||||
|
|
@ -175,6 +209,7 @@ resizor_create(struct display *display)
|
|||
height = resizor->height.current + 0.5;
|
||||
|
||||
window_set_child_size(resizor->window, resizor->width, height);
|
||||
window_set_button_handler(resizor->window, button_handler);
|
||||
|
||||
resizor_draw(resizor);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue