mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
SnapToRegion: Add view_snap_to_region()
This commit is contained in:
parent
67952cd749
commit
9d3e309a22
2 changed files with 53 additions and 1 deletions
|
|
@ -50,6 +50,7 @@ struct view {
|
|||
bool minimized;
|
||||
bool maximized;
|
||||
uint32_t tiled; /* private, enum view_edge in src/view.c */
|
||||
struct region *tiled_region;
|
||||
struct wlr_output *fullscreen;
|
||||
|
||||
/* geometry of the wlr_surface contained within the view */
|
||||
|
|
@ -134,6 +135,8 @@ void view_discover_output(struct view *view);
|
|||
void view_move_to_edge(struct view *view, const char *direction);
|
||||
void view_snap_to_edge(struct view *view, const char *direction,
|
||||
bool store_natural_geometry);
|
||||
void view_snap_to_region(struct view *view, struct region *region,
|
||||
bool store_natural_geometry);
|
||||
const char *view_get_string_prop(struct view *view, const char *prop);
|
||||
void view_update_title(struct view *view);
|
||||
void view_update_app_id(struct view *view);
|
||||
|
|
|
|||
51
src/view.c
51
src/view.c
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/scene-helpers.h"
|
||||
#include "labwc.h"
|
||||
#include "menu/menu.h"
|
||||
#include "regions.h"
|
||||
#include "ssd.h"
|
||||
#include "view.h"
|
||||
#include "workspaces.h"
|
||||
|
|
@ -293,7 +294,7 @@ void
|
|||
view_store_natural_geometry(struct view *view)
|
||||
{
|
||||
assert(view);
|
||||
if (view->maximized || view->tiled) {
|
||||
if (view->maximized || view->tiled || view->tiled_region) {
|
||||
/* Do not overwrite the stored geometry with special cases */
|
||||
return;
|
||||
}
|
||||
|
|
@ -341,6 +342,30 @@ view_apply_natural_geometry(struct view *view)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
view_apply_region_geometry(struct view *view)
|
||||
{
|
||||
assert(view);
|
||||
assert(view->tiled_region);
|
||||
|
||||
/* Create a copy of the original region geometry */
|
||||
struct wlr_box geo = view->tiled_region->geo;
|
||||
|
||||
/* And adjust for current view */
|
||||
struct border margin = ssd_get_margin(view->ssd);
|
||||
geo.x += margin.left;
|
||||
geo.y += margin.top;
|
||||
geo.width -= margin.left + margin.right;
|
||||
geo.height -= margin.top + margin.bottom;
|
||||
|
||||
if (view->w == geo.width && view->h == geo.height) {
|
||||
/* move horizontally/vertically without changing size */
|
||||
view_move(view, geo.x, geo.y);
|
||||
} else {
|
||||
view_move_resize(view, geo);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
view_apply_tiled_geometry(struct view *view, struct output *output)
|
||||
{
|
||||
|
|
@ -419,6 +444,8 @@ view_apply_special_geometry(struct view *view)
|
|||
view_apply_maximized_geometry(view);
|
||||
} else if (view->tiled) {
|
||||
view_apply_tiled_geometry(view, NULL);
|
||||
} else if (view->tiled_region) {
|
||||
view_apply_region_geometry(view);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -461,6 +488,7 @@ view_set_untiled(struct view *view)
|
|||
{
|
||||
assert(view);
|
||||
view->tiled = VIEW_EDGE_INVALID;
|
||||
view->tiled_region = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -859,6 +887,27 @@ view_snap_to_edge(struct view *view, const char *direction,
|
|||
view_apply_tiled_geometry(view, output);
|
||||
}
|
||||
|
||||
void
|
||||
view_snap_to_region(struct view *view, struct region *region,
|
||||
bool store_natural_geometry)
|
||||
{
|
||||
assert(view);
|
||||
assert(region);
|
||||
if (view->fullscreen) {
|
||||
return;
|
||||
}
|
||||
if (view->maximized) {
|
||||
/* Unmaximize + keep using existing natural_geometry */
|
||||
view_maximize(view, false, /*store_natural_geometry*/ false);
|
||||
} else if (store_natural_geometry) {
|
||||
/* store current geometry as new natural_geometry */
|
||||
view_store_natural_geometry(view);
|
||||
}
|
||||
view_set_untiled(view);
|
||||
view->tiled_region = region;
|
||||
view_apply_region_geometry(view);
|
||||
}
|
||||
|
||||
const char *
|
||||
view_get_string_prop(struct view *view, const char *prop)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue