mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
Merge branch 'maximize'
This commit is contained in:
commit
f5f8acc543
5 changed files with 132 additions and 3 deletions
|
|
@ -162,6 +162,7 @@ struct view_impl {
|
|||
void (*map)(struct view *view);
|
||||
void (*move)(struct view *view, double x, double y);
|
||||
void (*unmap)(struct view *view);
|
||||
void (*maximize)(struct view *view, bool maximize);
|
||||
};
|
||||
|
||||
struct border {
|
||||
|
|
@ -188,6 +189,7 @@ struct view {
|
|||
bool mapped;
|
||||
bool been_mapped;
|
||||
bool minimized;
|
||||
bool maximized;
|
||||
|
||||
/* geometry of the wlr_surface contained within the view */
|
||||
int x, y, w, h;
|
||||
|
|
@ -224,6 +226,7 @@ struct view {
|
|||
struct wl_listener request_move;
|
||||
struct wl_listener request_resize;
|
||||
struct wl_listener request_configure;
|
||||
struct wl_listener request_maximize;
|
||||
struct wl_listener new_popup; /* xdg-shell only */
|
||||
};
|
||||
|
||||
|
|
@ -266,6 +269,7 @@ void view_move_resize(struct view *view, struct wlr_box geo);
|
|||
void view_move(struct view *view, double x, double y);
|
||||
void view_minimize(struct view *view);
|
||||
void view_unminimize(struct view *view);
|
||||
void view_maximize(struct view *view, bool maximize);
|
||||
void view_for_each_surface(struct view *view,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data);
|
||||
void view_for_each_popup(struct view *view,
|
||||
|
|
|
|||
|
|
@ -320,6 +320,9 @@ cursor_button(struct wl_listener *listener, void *data)
|
|||
case LAB_DECO_PART_TITLE:
|
||||
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
|
||||
break;
|
||||
case LAB_DECO_BUTTON_MAXIMIZE:
|
||||
view_maximize(view, !view->maximized);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
67
src/view.c
67
src/view.c
|
|
@ -1,5 +1,7 @@
|
|||
#include "labwc.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
void
|
||||
view_move_resize(struct view *view, struct wlr_box geo)
|
||||
{
|
||||
|
|
@ -32,6 +34,71 @@ view_unminimize(struct view *view)
|
|||
view->impl->map(view);
|
||||
}
|
||||
|
||||
void
|
||||
view_maximize(struct view *view, bool maximize)
|
||||
{
|
||||
if(maximize == true)
|
||||
{
|
||||
struct wlr_output_layout *layout = view->server->output_layout;
|
||||
struct wlr_output* output =
|
||||
wlr_output_layout_output_at(layout, view->x, view->y);
|
||||
struct wlr_output_layout_output* ol_output =
|
||||
wlr_output_layout_get(layout, output);
|
||||
|
||||
assert(layout);
|
||||
if(output == NULL)
|
||||
{
|
||||
die("output NULL w/ x and y of: %d, %d", view->x, view->y);
|
||||
}
|
||||
assert(output);
|
||||
assert(ol_output);
|
||||
|
||||
int x = ol_output->x;
|
||||
int y = ol_output->y;
|
||||
int width = output->width;
|
||||
int height = output->height;
|
||||
|
||||
if(view->server_side_deco)
|
||||
{
|
||||
struct border border = deco_thickness(view);
|
||||
x += border.right;
|
||||
x += border.left;
|
||||
y += border.top;
|
||||
y += border.bottom;
|
||||
|
||||
width -= border.right;
|
||||
width -= border.left;
|
||||
height -= border.top;
|
||||
height -= border.bottom;
|
||||
}
|
||||
|
||||
struct wlr_box box = {
|
||||
.x = x * output->scale,
|
||||
.y = y * output->scale,
|
||||
.width = width * output->scale,
|
||||
.height = height * output->scale
|
||||
};
|
||||
|
||||
view_move_resize(view, box);
|
||||
view_move(view, box.x * output->scale, box.y * output->scale);
|
||||
|
||||
view->maximized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct wlr_box box = {
|
||||
.x = 20,
|
||||
.y = 50,
|
||||
.width = 640,
|
||||
.height = 480
|
||||
};
|
||||
|
||||
view_move_resize(view, box);
|
||||
view->maximized = false;
|
||||
}
|
||||
view->impl->maximize(view, maximize);
|
||||
}
|
||||
|
||||
void
|
||||
view_for_each_surface(struct view *view, wlr_surface_iterator_func_t iterator,
|
||||
void *user_data)
|
||||
|
|
|
|||
35
src/xdg.c
35
src/xdg.c
|
|
@ -230,6 +230,26 @@ handle_request_resize(struct wl_listener *listener, void *data)
|
|||
interactive_begin(view, LAB_INPUT_STATE_RESIZE, event->edges);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_request_maximize(struct wl_listener *listener, void *data)
|
||||
{
|
||||
/* This event is raised when a client would like to begin an interactive
|
||||
* resize, typically because the user clicked on their client-side
|
||||
* decorations. Note that a more sophisticated compositor should check
|
||||
* the provied serial against a list of button press serials sent to
|
||||
* this
|
||||
* client, to prevent the client from requesting this whenever they want.
|
||||
*/
|
||||
|
||||
struct view *view = wl_container_of(listener, view, request_maximize);
|
||||
|
||||
struct wlr_xdg_surface *surface = data;
|
||||
if(view != NULL) {
|
||||
view_maximize(view, surface->toplevel->client_pending.maximized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
xdg_toplevel_view_configure(struct view *view, struct wlr_box geo)
|
||||
{
|
||||
|
|
@ -279,6 +299,12 @@ xdg_toplevel_view_for_each_surface(struct view *view,
|
|||
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, data);
|
||||
}
|
||||
|
||||
static void
|
||||
xdg_toplevel_view_maximize(struct view *view, bool maximized)
|
||||
{
|
||||
wlr_xdg_toplevel_set_maximized(view->xdg_surface, maximized);
|
||||
}
|
||||
|
||||
/* Return area between surface extremities and window */
|
||||
static struct border
|
||||
xdg_shell_padding(struct view *view)
|
||||
|
|
@ -347,6 +373,7 @@ static const struct view_impl xdg_toplevel_view_impl = {
|
|||
.map = xdg_toplevel_view_map,
|
||||
.move = xdg_toplevel_view_move,
|
||||
.unmap = xdg_toplevel_view_unmap,
|
||||
.maximize = xdg_toplevel_view_maximize
|
||||
};
|
||||
|
||||
void
|
||||
|
|
@ -365,6 +392,7 @@ xdg_surface_new(struct wl_listener *listener, void *data)
|
|||
view->type = LAB_XDG_SHELL_VIEW;
|
||||
view->impl = &xdg_toplevel_view_impl;
|
||||
view->xdg_surface = xdg_surface;
|
||||
view->maximized = false;
|
||||
|
||||
view->map.notify = handle_map;
|
||||
wl_signal_add(&xdg_surface->events.map, &view->map);
|
||||
|
|
@ -381,6 +409,13 @@ xdg_surface_new(struct wl_listener *listener, void *data)
|
|||
wl_signal_add(&toplevel->events.request_move, &view->request_move);
|
||||
view->request_resize.notify = handle_request_resize;
|
||||
wl_signal_add(&toplevel->events.request_resize, &view->request_resize);
|
||||
view->request_maximize.notify = handle_request_maximize;
|
||||
wl_signal_add(&toplevel->events.request_maximize, &view->request_maximize);
|
||||
|
||||
// hacky workaround to bug where sometimes a window starts maximized and
|
||||
// when we hit the maximize button, labwc crashes. instead we unmaximize
|
||||
// it from the start to avoid this situation
|
||||
view_maximize(view, false);
|
||||
|
||||
wl_list_insert(&server->views, &view->link);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ handle_destroy(struct wl_listener *listener, void *data)
|
|||
wl_list_remove(&view->unmap.link);
|
||||
wl_list_remove(&view->destroy.link);
|
||||
wl_list_remove(&view->request_configure.link);
|
||||
wl_list_remove(&view->request_maximize.link);
|
||||
free(view);
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +61,16 @@ handle_request_configure(struct wl_listener *listener, void *data)
|
|||
damage_all_outputs(view->server);
|
||||
}
|
||||
|
||||
static void handle_request_maximize(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct view *view = wl_container_of(listener, view, request_maximize);
|
||||
|
||||
if(view != NULL) {
|
||||
view_maximize(view, !view->maximized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
configure(struct view *view, struct wlr_box geo)
|
||||
{
|
||||
|
|
@ -159,6 +170,12 @@ unmap(struct view *view)
|
|||
desktop_focus_topmost_mapped_view(view->server);
|
||||
}
|
||||
|
||||
static void
|
||||
maximize(struct view *view, bool maximized)
|
||||
{
|
||||
wlr_xwayland_surface_set_maximized(view->xwayland_surface, maximized);
|
||||
}
|
||||
|
||||
static const struct view_impl xwl_view_impl = {
|
||||
.configure = configure,
|
||||
.close = _close,
|
||||
|
|
@ -166,6 +183,7 @@ static const struct view_impl xwl_view_impl = {
|
|||
.map = map,
|
||||
.move = move,
|
||||
.unmap = unmap,
|
||||
.maximize = maximize
|
||||
};
|
||||
|
||||
void
|
||||
|
|
@ -200,6 +218,8 @@ xwayland_surface_new(struct wl_listener *listener, void *data)
|
|||
view->request_configure.notify = handle_request_configure;
|
||||
wl_signal_add(&xsurface->events.request_configure,
|
||||
&view->request_configure);
|
||||
view->request_maximize.notify = handle_request_maximize;
|
||||
wl_signal_add(&xsurface->events.request_maximize, &view->request_maximize);
|
||||
|
||||
wl_list_insert(&view->server->views, &view->link);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue