diyac/foreign.c
2024-04-13 00:25:39 +02:00

112 lines
4.2 KiB
C

#include "foreign.h"
#include "view.h"
#include <wlr/util/log.h>
static void handle_request_minimize(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.minimize);
struct wlr_foreign_toplevel_handle_v1_minimized_event *event = data;
// view_minimize(view, event->minimized);
diyac_view_set_mimimize(view, event->minimized);
wlr_log(WLR_INFO, "foreign: request minimize");
}
static void handle_request_maximize(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.maximize);
struct wlr_foreign_toplevel_handle_v1_maximized_event *event = data;
// view_maximize(view, event->maximized ? VIEW_AXIS_BOTH : VIEW_AXIS_NONE,
// /*store_natural_geometry*/ true);
diyac_view_set_maximize(view, event->maximized);
wlr_log(WLR_INFO, "foreign: request maximize");
}
static void handle_request_fullscreen(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.fullscreen);
struct wlr_foreign_toplevel_handle_v1_fullscreen_event *event = data;
// view_set_fullscreen(view, event->fullscreen);
diyac_view_set_fullscreen(view, event->fullscreen);
wlr_log(WLR_INFO, "foreign: request fullscreen");
}
static void handle_request_activate(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.activate);
// struct wlr_foreign_toplevel_handle_v1_activated_event *event = data;
/* In a multi-seat world we would select seat based on event->seat here. */
// desktop_focus_view(view, /*raise*/ true);
diyac_focus_view(view, true);
wlr_log(WLR_INFO, "foreign: request activate");
}
static void
handle_request_close(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.close);
wlr_xdg_toplevel_send_close(view->xdg_toplevel);
}
static void
handle_destroy(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, toplevel.destroy);
struct foreign_toplevel *toplevel = &view->toplevel;
wl_list_remove(&toplevel->maximize.link);
wl_list_remove(&toplevel->minimize.link);
wl_list_remove(&toplevel->fullscreen.link);
wl_list_remove(&toplevel->activate.link);
wl_list_remove(&toplevel->close.link);
wl_list_remove(&toplevel->destroy.link);
toplevel->handle = NULL;
}
void diyac_init_foreign_toplevel(struct diyac_view *view)
{
struct foreign_toplevel *toplevel = &view->toplevel;
toplevel->handle = wlr_foreign_toplevel_handle_v1_create(
view->server->foreign_toplevel_manager);
if (!toplevel->handle)
{
wlr_log(WLR_ERROR, "cannot create foreign toplevel handle");
return;
}
toplevel->maximize.notify = handle_request_maximize;
wl_signal_add(&toplevel->handle->events.request_maximize,
&toplevel->maximize);
toplevel->minimize.notify = handle_request_minimize;
wl_signal_add(&toplevel->handle->events.request_minimize,
&toplevel->minimize);
toplevel->fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&toplevel->handle->events.request_fullscreen,
&toplevel->fullscreen);
toplevel->activate.notify = handle_request_activate;
wl_signal_add(&toplevel->handle->events.request_activate,
&toplevel->activate);
toplevel->close.notify = handle_request_close;
wl_signal_add(&toplevel->handle->events.request_close,
&toplevel->close);
toplevel->destroy.notify = handle_destroy;
wl_signal_add(&toplevel->handle->events.destroy, &toplevel->destroy);
wlr_foreign_toplevel_handle_v1_output_enter(
view->toplevel.handle, view->output->wlr_output);
//wlr_foreign_toplevel_handle_v1_output_enter
struct wlr_xdg_toplevel *xdg_toplevel = view->xdg_toplevel;
if (!xdg_toplevel->parent)
{
return;
}
struct wlr_xdg_surface *surface = xdg_toplevel->parent->base;
struct diyac_view *parent = surface->data;
if (!parent->toplevel.handle)
{
return;
}
wlr_foreign_toplevel_handle_v1_set_parent(view->toplevel.handle, parent->toplevel.handle);
}