foreign-toplevel: simplify and fully separate ext-foreign/wlr-foreign

Currently, the dependencies between foreign-toplevel[-internal],
ext-foreign, and wlr-foreign are cyclical and a bit complex.

I suggest we reorganize it into a simpler hierarchy:

  foreign-toplevel/
    -> foreign.c/h
      -> (depends on) ext-foreign.c/h
      -> (depends on) wlr-foreign.c/h

The refactored code is smaller and (IMO) easier to follow.

In detail:

- Add include/foreign-toplevel folder mirroring src/foreign-toplevel
- Split foreign-toplevel-internal.h to ext-foreign.h and wlr-foreign.h
- Eliminate ext-/wlr-foreign.c -> foreign.c reverse dependencies
  (including internal signals and foreign_request* functions)
- Make struct foreign_toplevel private to foreign.c

Lightly tested with qmpanel (which uses wlr-foreign-toplevel).

v2: reorder foreign-toplevel internal API funcs
This commit is contained in:
John Lindgren 2025-08-07 20:30:59 -04:00
parent 55b495f398
commit 02df0a15d7
11 changed files with 202 additions and 271 deletions

View file

@ -1,44 +1,19 @@
// SPDX-License-Identifier: GPL-2.0-only
#include "foreign-toplevel/foreign.h"
#include <assert.h>
#include <wayland-server-core.h>
#include "common/macros.h"
#include "common/mem.h"
#include "labwc.h"
#include "foreign-toplevel/ext-foreign.h"
#include "foreign-toplevel/wlr-foreign.h"
#include "view.h"
#include "foreign-toplevel-internal.h"
/* Internal API */
void
foreign_request_minimize(struct foreign_toplevel *toplevel, bool minimized)
{
view_minimize(toplevel->view, minimized);
}
struct foreign_toplevel {
/* *-toplevel implementations */
struct wlr_foreign_toplevel wlr_toplevel;
struct ext_foreign_toplevel ext_toplevel;
void
foreign_request_maximize(struct foreign_toplevel *toplevel, enum view_axis axis)
{
view_maximize(toplevel->view, axis, /*store_natural_geometry*/ true);
}
/* TODO: add struct xdg_x11_mapped_toplevel at some point */
};
void
foreign_request_fullscreen(struct foreign_toplevel *toplevel, bool fullscreen)
{
view_set_fullscreen(toplevel->view, fullscreen);
}
void
foreign_request_activate(struct foreign_toplevel *toplevel)
{
desktop_focus_view(toplevel->view, /*raise*/ true);
}
void
foreign_request_close(struct foreign_toplevel *toplevel)
{
view_close(toplevel->view);
}
/* Public API */
struct foreign_toplevel *
foreign_toplevel_create(struct view *view)
{
@ -46,13 +21,8 @@ foreign_toplevel_create(struct view *view)
assert(view->mapped);
struct foreign_toplevel *toplevel = znew(*toplevel);
toplevel->view = view;
wl_signal_init(&toplevel->events.toplevel_parent);
wl_signal_init(&toplevel->events.toplevel_destroy);
wlr_foreign_toplevel_init(toplevel);
ext_foreign_toplevel_init(toplevel);
wlr_foreign_toplevel_init(&toplevel->wlr_toplevel, view);
ext_foreign_toplevel_init(&toplevel->ext_toplevel, view);
return toplevel;
}
@ -61,15 +31,15 @@ void
foreign_toplevel_set_parent(struct foreign_toplevel *toplevel, struct foreign_toplevel *parent)
{
assert(toplevel);
wl_signal_emit_mutable(&toplevel->events.toplevel_parent, parent);
wlr_foreign_toplevel_set_parent(&toplevel->wlr_toplevel,
parent ? &parent->wlr_toplevel : NULL);
}
void
foreign_toplevel_destroy(struct foreign_toplevel *toplevel)
{
assert(toplevel);
wl_signal_emit_mutable(&toplevel->events.toplevel_destroy, NULL);
assert(!toplevel->wlr_toplevel.handle);
assert(!toplevel->ext_toplevel.handle);
wlr_foreign_toplevel_finish(&toplevel->wlr_toplevel);
ext_foreign_toplevel_finish(&toplevel->ext_toplevel);
free(toplevel);
}