[PATCH weston 6/7] shell: Implement maximize menu button functionality.
Scott Moreau
oreaus at gmail.com
Sat Nov 3 22:31:36 PDT 2012
---
clients/desktop-shell.c | 41 +++++++++++++++++++++++++++++++++++++----
clients/window.c | 6 ++++++
protocol/desktop-shell.xml | 10 ++++++++++
src/shell.c | 23 +++++++++++++++++++++++
4 files changed, 76 insertions(+), 4 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index cc3004b..f52a4f9 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -72,7 +72,7 @@ struct surface {
struct wl_list item_list;
uint32_t output_mask;
char *title;
- bool minimized;
+ bool maximized, minimized;
bool focused;
struct wl_list link;
@@ -1207,7 +1207,17 @@ list_item_menu_handle_button(struct list_item *item, int index)
surface->minimized = true;
}
break;
- case 1: /* Close */
+ case 1: /* (Un)Maximize */
+ if (surface->maximized) {
+ surface_data_unmaximize(surface->surface_data);
+ surface->maximized = false;
+ }
+ else {
+ surface_data_maximize(surface->surface_data);
+ surface->maximized = true;
+ }
+ break;
+ case 2: /* Close */
surface_data_close(surface->surface_data);
break;
default:
@@ -1235,7 +1245,7 @@ list_item_menu_func(struct window *window, int index, void *data)
}
}
-#define NUM_ENTRIES 2
+#define NUM_ENTRIES 3
static void
list_item_show_menu(struct list_item *item, struct input *input, uint32_t time)
@@ -1245,7 +1255,8 @@ list_item_show_menu(struct list_item *item, struct input *input, uint32_t time)
static const char *entries[NUM_ENTRIES];
entries[0] = item->surface->minimized ? "Unminimize" : "Minimize";
- entries[1] = "Close";
+ entries[1] = item->surface->maximized ? "Unmaximize" : "Maximize";
+ entries[2] = "Close";
panel = item->panel;
input_get_position(input, &x, &y);
@@ -1468,6 +1479,7 @@ desktop_create_surface(struct desktop *desktop,
surface->surface_data = surface_data;
surface->title = strdup("unknown");
surface->output_mask = 1;
+ surface->maximized = false;
surface->minimized = false;
surface->focused = false;
wl_list_init(&surface->item_list);
@@ -1557,6 +1569,26 @@ surface_data_set_title(void *data,
}
static void
+surface_data_set_maximized_state(void *data,
+ struct surface_data *surface_data,
+ int maximized)
+{
+ struct desktop *desktop;
+ struct surface *surface;
+
+ desktop = data;
+
+ surface = desktop_get_surface(desktop, surface_data);
+
+ if (!surface)
+ surface = desktop_create_surface(desktop, surface_data);
+
+ surface->maximized = maximized;
+
+ desktop_update_list_items(desktop, surface);
+}
+
+static void
surface_data_set_minimized_state(void *data,
struct surface_data *surface_data,
int minimized)
@@ -1631,6 +1663,7 @@ surface_data_destroy_handler(void *data, struct surface_data *surface_data)
static const struct surface_data_listener surface_data_listener = {
surface_data_set_output_mask,
surface_data_set_title,
+ surface_data_set_maximized_state,
surface_data_set_minimized_state,
surface_data_set_focused_state,
surface_data_destroy_handler
diff --git a/clients/window.c b/clients/window.c
index 8f2b985..a9eb440 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -2936,11 +2936,17 @@ handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
static void
handle_maximize(void *data, struct wl_shell_surface *shell_surface)
{
+ struct window *window = data;
+
+ window_set_maximized(window, 1);
}
static void
handle_unmaximize(void *data, struct wl_shell_surface *shell_surface)
{
+ struct window *window = data;
+
+ window_set_maximized(window, 0);
}
static void
diff --git a/protocol/desktop-shell.xml b/protocol/desktop-shell.xml
index 254825e..2af3b85 100644
--- a/protocol/desktop-shell.xml
+++ b/protocol/desktop-shell.xml
@@ -87,6 +87,12 @@
The shell can use this interface to receive surface information or make
requests for this surface.
</description>
+ <request name="maximize">
+ <description summary="ask the compositor to maximize the surface"/>
+ </request>
+ <request name="unmaximize">
+ <description summary="ask the compositor to unmaximize the surface"/>
+ </request>
<request name="minimize">
<description summary="ask the compositor to minimize the surface"/>
</request>
@@ -113,6 +119,10 @@
<description summary="send the surface object title to the shell"/>
<arg name="title" type="string"/>
</event>
+ <event name="maximized">
+ <description summary="send the surface object maximize state to the shell"/>
+ <arg name="maximized" type="int"/>
+ </event>
<event name="minimized">
<description summary="send the surface object minimize state to the shell"/>
<arg name="minimized" type="int"/>
diff --git a/src/shell.c b/src/shell.c
index 506ce5d..af1e0ba 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1510,12 +1510,31 @@ shell_surface_unminimize(struct shell_surface *shsurf)
shsurf->type = shsurf->saved_type;
shell_surface_focus(shsurf);
send_surface_data_focused_state(surface);
+ shsurf->type = shsurf->saved_type;
wl_shell_surface_send_unminimize(&shsurf->resource);
weston_compositor_damage_all(compositor);
}
}
static void
+surface_data_maximize_handler(struct wl_client *client,
+ struct wl_resource *resource)
+{
+ struct surface_data *surface_data = resource->data;
+
+ wl_shell_surface_send_maximize(&surface_data->shsurf->resource);
+}
+
+static void
+surface_data_unmaximize_handler(struct wl_client *client,
+ struct wl_resource *resource)
+{
+ struct surface_data *surface_data = resource->data;
+
+ wl_shell_surface_send_unmaximize(&surface_data->shsurf->resource);
+}
+
+static void
surface_data_minimize_handler(struct wl_client *client,
struct wl_resource *resource)
{
@@ -1578,6 +1597,8 @@ surface_data_close_handler(struct wl_client *client,
static const struct surface_data_interface
surface_data_implementation = {
+ surface_data_maximize_handler,
+ surface_data_unmaximize_handler,
surface_data_minimize_handler,
surface_data_unminimize_handler,
surface_data_focus_handler,
@@ -1791,6 +1812,7 @@ reset_shell_surface_type(struct shell_surface *surface)
weston_surface_set_position(surface->surface,
surface->saved_x,
surface->saved_y);
+ surface_data_send_maximized(&surface->surface_data->resource, false);
break;
case SHELL_SURFACE_NONE:
case SHELL_SURFACE_TOPLEVEL:
@@ -1828,6 +1850,7 @@ set_surface_type(struct shell_surface *shsurf)
shsurf->saved_x = surface->geometry.x;
shsurf->saved_y = surface->geometry.y;
shsurf->saved_position_valid = true;
+ surface_data_send_maximized(&shsurf->surface_data->resource, true);
break;
case SHELL_SURFACE_FULLSCREEN:
--
1.7.11.7
More information about the wayland-devel
mailing list