Take into account deco on initial window positioning

This commit is contained in:
Johan Malm 2020-05-12 22:24:18 +01:00
parent 9597aeffec
commit 7a5ebbe402
5 changed files with 38 additions and 14 deletions

6
dbg.c
View file

@ -55,7 +55,7 @@ static void show_one_xwl_view(struct view *view)
*/ */
} }
static void show_one_view(struct view *view) void dbg_show_one_view(struct view *view)
{ {
if (view->type == LAB_XDG_SHELL_VIEW) if (view->type == LAB_XDG_SHELL_VIEW)
show_one_xdg_view(view); show_one_xdg_view(view);
@ -70,7 +70,5 @@ void dbg_show_views(struct server *server)
fprintf(stderr, "---\n"); fprintf(stderr, "---\n");
fprintf(stderr, "TYPE NR_PNT NR_CLD MAPPED VIEW-POINTER NAME\n"); fprintf(stderr, "TYPE NR_PNT NR_CLD MAPPED VIEW-POINTER NAME\n");
wl_list_for_each_reverse (view, &server->views, link) wl_list_for_each_reverse (view, &server->views, link)
show_one_view(view); dbg_show_one_view(view);
} }

8
deco.c
View file

@ -15,7 +15,7 @@ struct wlr_box deco_max_extents(struct view *view)
struct wlr_box deco_box(struct view *view, enum deco_part deco_part) struct wlr_box deco_box(struct view *view, enum deco_part deco_part)
{ {
struct wlr_box box = { .x = 0, .y = 0, .width = 0, .height = 0 }; struct wlr_box box = { .x = 0, .y = 0, .width = 0, .height = 0 };
if (!view) if (!view || !view->surface)
return box; return box;
switch (deco_part) { switch (deco_part) {
case LAB_DECO_PART_TOP: case LAB_DECO_PART_TOP:
@ -25,6 +25,12 @@ struct wlr_box deco_box(struct view *view, enum deco_part deco_part)
view->surface->current.width + 2 * XWL_WINDOW_BORDER; view->surface->current.width + 2 * XWL_WINDOW_BORDER;
box.height = XWL_TITLEBAR_HEIGHT + XWL_WINDOW_BORDER; box.height = XWL_TITLEBAR_HEIGHT + XWL_WINDOW_BORDER;
break; break;
case LAB_DECO_PART_LEFT:
box.x = view->x - XWL_WINDOW_BORDER;
box.y = view->y;
box.width = XWL_WINDOW_BORDER;
box.height = view->surface->current.height;
break;
default: default:
break; break;
} }

View file

@ -84,7 +84,7 @@ struct output {
enum view_type { LAB_XDG_SHELL_VIEW, LAB_XWAYLAND_VIEW }; enum view_type { LAB_XDG_SHELL_VIEW, LAB_XWAYLAND_VIEW };
enum deco_part { LAB_DECO_NONE, LAB_DECO_PART_TOP }; enum deco_part { LAB_DECO_NONE, LAB_DECO_PART_TOP, LAB_DECO_PART_LEFT };
struct view { struct view {
enum view_type type; enum view_type type;
@ -159,6 +159,7 @@ void server_new_output(struct wl_listener *listener, void *data);
void output_frame(struct wl_listener *listener, void *data); void output_frame(struct wl_listener *listener, void *data);
void dbg_show_one_view(struct view *view);
void dbg_show_views(struct server *server); void dbg_show_views(struct server *server);
struct wlr_box deco_max_extents(struct view *view); struct wlr_box deco_max_extents(struct view *view);

15
view.c
View file

@ -2,8 +2,6 @@
bool view_want_deco(struct view *view) bool view_want_deco(struct view *view)
{ {
if (!view->surface)
return false;
if (view->type != LAB_XWAYLAND_VIEW) if (view->type != LAB_XWAYLAND_VIEW)
return false; return false;
if (!is_toplevel(view)) if (!is_toplevel(view))
@ -148,11 +146,11 @@ void begin_interactive(struct view *view, enum cursor_mode mode, uint32_t edges)
server->grab_x = server->cursor->x - view->x; server->grab_x = server->cursor->x - view->x;
server->grab_y = server->cursor->y - view->y; server->grab_y = server->cursor->y - view->y;
} else { } else {
struct wlr_box geo_box; struct wlr_box geo_box;
switch (view->type) { switch (view->type) {
case LAB_XDG_SHELL_VIEW: case LAB_XDG_SHELL_VIEW:
wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); wlr_xdg_surface_get_geometry(view->xdg_surface,
&geo_box);
break; break;
case LAB_XWAYLAND_VIEW: case LAB_XWAYLAND_VIEW:
geo_box.x = view->xwayland_surface->x; geo_box.x = view->xwayland_surface->x;
@ -162,8 +160,12 @@ void begin_interactive(struct view *view, enum cursor_mode mode, uint32_t edges)
break; break;
} }
double border_x = (view->x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0); double border_x =
double border_y = (view->y + geo_box.y) + ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0); (view->x + geo_box.x) +
((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0);
double border_y =
(view->y + geo_box.y) +
((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0);
server->grab_x = server->cursor->x - border_x; server->grab_x = server->cursor->x - border_x;
server->grab_y = server->cursor->y - border_y; server->grab_y = server->cursor->y - border_y;
server->grab_box = geo_box; server->grab_box = geo_box;
@ -261,4 +263,3 @@ struct view *desktop_view_at(struct server *server, double lx, double ly,
} }
return NULL; return NULL;
} }

20
xwl.c
View file

@ -16,14 +16,32 @@ int xwl_nr_parents(struct view *view)
return i; return i;
} }
static void position(struct view *view)
{
struct wlr_box box;
if (!view_want_deco(view))
return;
if (view->x || view->y)
return;
box = deco_box(view, LAB_DECO_PART_TOP);
view->y = box.height;
box = deco_box(view, LAB_DECO_PART_LEFT);
view->x = box.width;
wlr_xwayland_surface_configure(view->xwayland_surface, view->x, view->y,
view->xwayland_surface->width,
view->xwayland_surface->height);
}
void xwl_surface_map(struct wl_listener *listener, void *data) void xwl_surface_map(struct wl_listener *listener, void *data)
{ {
struct view *view = wl_container_of(listener, view, map); struct view *view = wl_container_of(listener, view, map);
view->mapped = true; view->mapped = true;
view->been_mapped = true;
view->x = view->xwayland_surface->x; view->x = view->xwayland_surface->x;
view->y = view->xwayland_surface->y; view->y = view->xwayland_surface->y;
view->surface = view->xwayland_surface->surface; view->surface = view->xwayland_surface->surface;
if (!view->been_mapped)
position(view);
view->been_mapped = true;
focus_view(view, view->xwayland_surface->surface); focus_view(view, view->xwayland_surface->surface);
} }