Merge pull request #390 from emersion/rootston-maximize

Maximize views in rootston
This commit is contained in:
Drew DeVault 2017-11-10 08:26:20 -05:00 committed by GitHub
commit e6babc07a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 220 additions and 47 deletions

View File

@ -11,9 +11,10 @@ struct roots_wl_shell_surface {
// TODO: Maybe destroy listener should go in roots_view
struct wl_listener destroy;
struct wl_listener ping_timeout;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_set_maximized;
struct wl_listener set_state;
struct wl_listener surface_commit;
};
@ -26,6 +27,7 @@ struct roots_xdg_surface_v6 {
struct wl_listener destroy;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
};
struct roots_xwayland_surface {
@ -36,6 +38,7 @@ struct roots_xwayland_surface {
struct wl_listener request_configure;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
struct wl_listener map_notify;
struct wl_listener unmap_notify;
};
@ -48,8 +51,17 @@ enum roots_view_type {
struct roots_view {
struct roots_desktop *desktop;
double x, y;
float rotation;
bool maximized;
struct {
double x, y;
uint32_t width, height;
float rotation;
} saved;
// TODO: Something for roots-enforced width/height
enum roots_view_type type;
union {
@ -67,6 +79,7 @@ struct roots_view {
#endif
};
struct wlr_surface *wlr_surface;
// TODO: This would probably be better as a field that's updated on a
// configure event from the xdg_shell
// If not then this should follow the typical type/impl pattern we use
@ -77,6 +90,7 @@ struct roots_view {
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
void (*move_resize)(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height);
void (*maximize)(struct roots_view *view, bool maximized);
void (*close)(struct roots_view *view);
};
@ -86,6 +100,7 @@ void view_move(struct roots_view *view, double x, double y);
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
void view_move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height);
void view_maximize(struct roots_view *view, bool maximized);
void view_close(struct roots_view *view);
bool view_center(struct roots_view *view);
void view_setup(struct roots_view *view);

View File

@ -42,6 +42,8 @@ struct wlr_wl_shell_popup_grab {
enum wlr_wl_shell_surface_state {
WLR_WL_SHELL_SURFACE_STATE_NONE,
WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL,
WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED,
WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN,
WLR_WL_SHELL_SURFACE_STATE_TRANSIENT,
WLR_WL_SHELL_SURFACE_STATE_POPUP,
};

View File

@ -126,6 +126,8 @@ struct wlr_xdg_surface_v6 {
struct wl_signal ack_configure;
struct wl_signal ping_timeout;
struct wl_signal request_maximize;
struct wl_signal request_fullscreen;
struct wl_signal request_minimize;
struct wl_signal request_move;
struct wl_signal request_resize;

View File

@ -42,8 +42,15 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
input->mode = ROOTS_CURSOR_MOVE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_x = view->x;
input->view_y = view->y;
if (view->maximized) {
input->view_x = view->saved.x;
input->view_y = view->saved.y;
} else {
input->view_x = view->x;
input->view_y = view->y;
}
view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme);
@ -57,13 +64,22 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
input->mode = ROOTS_CURSOR_RESIZE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_x = view->x;
input->view_y = view->y;
struct wlr_box size;
view_get_size(view, &size);
input->view_width = size.width;
input->view_height = size.height;
if (view->maximized) {
input->view_x = view->saved.x;
input->view_y = view->saved.y;
input->view_width = view->saved.width;
input->view_height = view->saved.height;
} else {
input->view_x = view->x;
input->view_y = view->y;
struct wlr_box size;
view_get_size(view, &size);
input->view_width = size.width;
input->view_height = size.height;
}
input->resize_edges = edges;
view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges);
@ -78,6 +94,8 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
input->offs_x = cursor->x;
input->offs_y = cursor->y;
input->view_rotation = view->rotation;
view_maximize(view, false);
wlr_seat_pointer_clear_focus(input->wl_seat);
struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme);
@ -102,7 +120,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
set_compositor_cursor = view_client != input->cursor_client;
}
if (set_compositor_cursor) {
struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
struct wlr_xcursor *xcursor =
get_default_xcursor(input->xcursor_theme);
cursor_set_xcursor_image(input, xcursor->images[0]);
input->cursor_client = NULL;
}

View File

@ -106,6 +106,50 @@ void view_move_resize(struct roots_view *view, double x, double y,
view_resize(view, width, height);
}
void view_maximize(struct roots_view *view, bool maximized) {
if (view->maximized == maximized) {
return;
}
if (view->maximize) {
view->maximize(view, maximized);
}
if (!view->maximized && maximized) {
struct wlr_box view_box;
view_get_size(view, &view_box);
view->maximized = true;
view->saved.x = view->x;
view->saved.y = view->y;
view->saved.rotation = view->rotation;
view->saved.width = view_box.width;
view->saved.height = view_box.height;
double output_x, output_y;
wlr_output_layout_closest_point(view->desktop->layout, NULL,
view->x + (double)view_box.width/2,
view->y + (double)view_box.height/2,
&output_x, &output_y);
struct wlr_output *output = wlr_output_layout_output_at(
view->desktop->layout, output_x, output_y);
struct wlr_box *output_box =
wlr_output_layout_get_box(view->desktop->layout, output);
view_move_resize(view, output_box->x, output_box->y, output_box->width,
output_box->height);
view->rotation = 0;
}
if (view->maximized && !maximized) {
view->maximized = false;
view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
view->saved.height);
view->rotation = view->saved.rotation;
}
}
void view_close(struct roots_view *view) {
if (view->close) {
view->close(view);

View File

@ -49,6 +49,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, event->cursor, view, e->edges);
}
static void handle_request_set_maximized(struct wl_listener *listener,
void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, request_set_maximized);
struct roots_view *view = roots_surface->view;
//struct wlr_wl_shell_surface_set_maximized_event *e = data;
view_maximize(view, true);
}
static void handle_set_state(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, set_state);
struct roots_view *view = roots_surface->view;
struct wlr_wl_shell_surface *surface = view->wl_shell_surface;
if (view->maximized &&
surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) {
view_maximize(view, false);
}
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
// TODO do we need to do anything here?
}
@ -60,6 +80,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
wl_list_remove(&roots_surface->request_set_maximized.link);
wl_list_remove(&roots_surface->set_state.link);
wl_list_remove(&roots_surface->surface_commit.link);
view_destroy(roots_surface->view);
free(roots_surface);
}
@ -93,6 +116,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
roots_surface->request_set_maximized.notify = handle_request_set_maximized;
wl_signal_add(&surface->events.request_set_maximized,
&roots_surface->request_set_maximized);
roots_surface->set_state.notify = handle_set_state;
wl_signal_add(&surface->events.set_state, &roots_surface->set_state);
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);

View File

@ -84,6 +84,16 @@ static void move_resize(struct roots_view *view, double x, double y,
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height);
}
static void maximize(struct roots_view *view, bool maximized) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return;
}
wlr_xdg_toplevel_v6_set_maximized(surface, maximized);
}
static void close(struct roots_view *view) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
@ -118,8 +128,25 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, event->cursor, view, e->edges);
}
static void handle_request_maximize(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_maximize);
struct roots_view *view = roots_xdg_surface->view;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
return;
}
view_maximize(view, surface->toplevel_state->next.maximized);
}
static void handle_commit(struct wl_listener *listener, void *data) {
// TODO is there anything we need to do here?
//struct roots_xdg_surface_v6 *roots_xdg_surface =
// wl_container_of(listener, roots_xdg_surface, commit);
//struct roots_view *view = roots_xdg_surface->view;
//struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
// TODO
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@ -164,6 +191,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_maximize);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) {
@ -178,6 +208,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->activate = activate;
view->resize = resize;
view->move_resize = move_resize;
view->maximize = maximize;
view->close = close;
view->desktop = desktop;
roots_surface->view = view;

View File

@ -85,11 +85,22 @@ static void close(struct roots_view *view) {
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface);
}
static void maximize(struct roots_view *view, bool maximized) {
assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_set_maximized(view->desktop->xwayland,
view->xwayland_surface, maximized);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
view_teardown(roots_surface->view);
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_configure.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
wl_list_remove(&roots_surface->request_maximize.link);
wl_list_remove(&roots_surface->map_notify.link);
wl_list_remove(&roots_surface->unmap_notify.link);
view_destroy(roots_surface->view);
@ -161,6 +172,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
view_begin_resize(input, cursor, view, e->edges);
}
static void handle_request_maximize(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, request_maximize);
struct roots_view *view = roots_surface->view;
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
bool maximized = xwayland_surface->maximized_vert &&
xwayland_surface->maximized_horz;
view_maximize(view, maximized);
}
static void handle_map_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, map_notify);
@ -202,24 +224,24 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
if (roots_surface == NULL) {
return;
}
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
roots_surface->request_configure.notify = handle_request_configure;
wl_signal_add(&surface->events.request_configure,
&roots_surface->request_configure);
roots_surface->map_notify.notify = handle_map_notify;
wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify);
roots_surface->unmap_notify.notify = handle_unmap_notify;
wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify);
roots_surface->request_move.notify = handle_request_move;
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize);
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
roots_surface->request_maximize.notify = handle_request_maximize;
wl_signal_add(&surface->events.request_maximize,
&roots_surface->request_maximize);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (view == NULL) {
@ -237,6 +259,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->resize = resize;
view->move = move;
view->move_resize = move_resize;
view->maximize = maximize;
view->close = close;
roots_surface->view = view;
wlr_list_add(desktop->views, view);

View File

@ -171,7 +171,6 @@ static void shell_surface_destroy_popup_state(
}
}
static void shell_surface_protocol_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, enum wl_shell_surface_resize edges) {
@ -287,9 +286,8 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
output = wl_resource_get_user_data(output_resource);
}
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) {
return;
}
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN,
NULL, NULL);
struct wlr_wl_shell_surface_set_fullscreen_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_fullscreen_event));
@ -377,9 +375,8 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client,
output = wl_resource_get_user_data(output_resource);
}
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) {
return;
}
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED,
NULL, NULL);
struct wlr_wl_shell_surface_set_maximized_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_maximized_event));

View File

@ -664,24 +664,28 @@ static void xdg_toplevel_protocol_set_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.maximized = true;
wl_signal_emit(&surface->events.request_maximize, surface);
}
static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.maximized = false;
wl_signal_emit(&surface->events.request_maximize, surface);
}
static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.fullscreen = true;
wl_signal_emit(&surface->events.request_fullscreen, surface);
}
static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.fullscreen = false;
wl_signal_emit(&surface->events.request_fullscreen, surface);
}
static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
@ -1143,6 +1147,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_list_init(&surface->configure_list);
wl_list_init(&surface->popups);
wl_signal_init(&surface->events.request_maximize);
wl_signal_init(&surface->events.request_fullscreen);
wl_signal_init(&surface->events.request_minimize);
wl_signal_init(&surface->events.request_move);
wl_signal_init(&surface->events.request_resize);

View File

@ -823,41 +823,47 @@ static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm,
if (!xsurface) {
return;
}
if (client_message->format != 32) {
return;
}
int maximized = xsurface_is_maximized(xsurface);
bool fullscreen = xsurface->fullscreen;
bool maximized = xsurface_is_maximized(xsurface);
uint32_t action = client_message->data.data32[0];
uint32_t property = client_message->data.data32[1];
for (size_t i = 0; i < 2; ++i) {
uint32_t property = client_message->data.data32[1 + i];
if (property == xwm->atoms[_NET_WM_STATE_FULLSCREEN] &&
update_state(action, &xsurface->fullscreen)) {
xsurface_set_net_wm_state(xsurface);
if (property == xwm->atoms[_NET_WM_STATE_FULLSCREEN] &&
update_state(action, &xsurface->fullscreen)) {
xsurface_set_net_wm_state(xsurface);
} else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] &&
update_state(action, &xsurface->maximized_vert)) {
xsurface_set_net_wm_state(xsurface);
} else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] &&
update_state(action, &xsurface->maximized_horz)) {
xsurface_set_net_wm_state(xsurface);
}
}
// client_message->data.data32[3] is the source indication
// all other values are set to 0
if (fullscreen != xsurface->fullscreen) {
if (xsurface->fullscreen) {
xsurface->saved_width = xsurface->width;
xsurface->saved_height = xsurface->height;
}
wl_signal_emit(&xsurface->events.request_fullscreen, xsurface);
} else {
if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] &&
update_state(action, &xsurface->maximized_vert)) {
xsurface_set_net_wm_state(xsurface);
}
if (maximized != xsurface_is_maximized(xsurface)) {
if (xsurface_is_maximized(xsurface)) {
xsurface->saved_width = xsurface->width;
xsurface->saved_height = xsurface->height;
}
if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] &&
update_state(action, &xsurface->maximized_horz)) {
xsurface_set_net_wm_state(xsurface);
}
if (maximized != xsurface_is_maximized(xsurface)) {
if (xsurface_is_maximized(xsurface)) {
xsurface->saved_width = xsurface->width;
xsurface->saved_height = xsurface->height;
}
wl_signal_emit(&xsurface->events.request_maximize, xsurface);
}
wl_signal_emit(&xsurface->events.request_maximize, xsurface);
}
}
@ -1310,8 +1316,8 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
xwm->atoms[_NET_ACTIVE_WINDOW],
xwm->atoms[_NET_WM_MOVERESIZE],
xwm->atoms[_NET_WM_STATE_FULLSCREEN],
xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ],
xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT],
xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ],
};
xcb_change_property(xwm->xcb_conn,
XCB_PROP_MODE_REPLACE,