12to11/xdg_wm.c
oldosfan d143b45496 Implement _NET_WM_PING and some WIP Present code
* 12to11.c (XLMain): Initialize timestamp tracking.
* 12to11.man: Document *.useDirectPresentation resource.
* atoms.c (names): Add _NET_WM_PID and _NET_WM_PING.
(XLInitAtoms): Likewise.
* compositor.h (struct _RenderFuncs): Update doc of
cancel_presentation.
(enum _FrameMode): Add ModeNotifyDisablePresent.
(struct _XdgRoleList, struct _XdgWmBase): New structs.
* frame_clock.c (StartFrame): Return if the clock was really
started.
(XLFrameClockStartFrame): Likewise.
(XLInitFrameClock): Move Sync extension initialization to
InitTime.
* picture_renderer.c (struct _PresentCompletionCallback)
(struct _PictureTarget, InitSynchronizedPresentation)
(InitRenderFuncs, TargetFromDrawable, DestroyRenderTarget)
(PresentToWindow, CancelPresentationCallback, AddRenderFlag)
(HandlePresentCompleteNotify): Link structure on target.  When
synchronized presentation is enabled, use the approriate msc to
present, and record the last known msc.
* run.c (HandleOneXEvent): Handle timestamp events.
* subcompositor.c (SubcompositorUpdate): Note frame with
ModeNotifyDisablePresent.
(FindSystemCounter, ValueToScalar, ScalarToValue, StartAlarms)
(HandleAlarmNotify, HandleOneXEventForTime, InitTime): New
functions.
* xdg_surface.c (struct _XdgRole): New fields `link' and
`wm_base'.
(struct _PingEvent): New structure.
(ReleaseBacking): Release all ping events.
(NoteFrame, WriteRedirectProperty): Allow unredirection under
some circumstances.
(XLGetXdgSurface): Attach wm base.
(XLXdgRoleHandlePing, ReplyPingEvent, XLXdgRoleReplyPing): New
function.
* xdg_toplevel.c (GetClientMachine): New function.
(WriteCredentialProperties): New function.
(Attach): Write credential properties.
(ReplyToPing): New function.
(XLHandleXEventForXdgToplevels): Handle ping events.
* xdg_wm.c (Pong): Reply to ping events once pong is received
from the client.
(HandleResourceDestroy): Detach all surfaces and run their ping
events.
(HandleBind): Allocate memory for XdgWmBase.
(XLXdgWmBaseSendPing): New function.
2022-10-20 03:55:19 +00:00

157 lines
3.8 KiB
C

/* Wayland compositor running on top of an X server.
Copyright (C) 2022 to various contributors.
This file is part of 12to11.
12to11 is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
12to11 is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with 12to11. If not, see <https://www.gnu.org/licenses/>. */
#include <string.h>
#include "compositor.h"
#include "xdg-shell.h"
/* The xdg_wm_base global. */
static struct wl_global *global_xdg_wm_base;
static void
CreatePositioner (struct wl_client *client, struct wl_resource *resource,
uint32_t id)
{
XLCreateXdgPositioner (client, resource, id);
}
static void
GetXdgSurface (struct wl_client *client, struct wl_resource *resource,
uint32_t id, struct wl_resource *surface_resource)
{
XLGetXdgSurface (client, resource, id, surface_resource);
}
static void
Pong (struct wl_client *client, struct wl_resource *resource,
uint32_t serial)
{
XdgWmBase *wm_base;
XdgRoleList *role;
/* Ping-pong implementation. Every time a ping request is received
from the window manager, it is linked onto the list of all such
requests on the toplevel. Then, ping is sent with a serial.
Once the pong with the latest serial arrives from the client,
pending requests are sent back to the window manager on all
windows. */
wm_base = wl_resource_get_user_data (resource);
if (serial == wm_base->last_ping)
{
/* Reply to the ping events sent to each surface created with
this wm_base. */
role = wm_base->list.next;
while (role != &wm_base->list)
{
XLXdgRoleReplyPing (role->role);
role = role->next;
}
}
}
static void
Destroy (struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static const struct xdg_wm_base_interface xdg_wm_base_impl =
{
.destroy = Destroy,
.create_positioner = CreatePositioner,
.get_xdg_surface = GetXdgSurface,
.pong = Pong,
};
static void
HandleResourceDestroy (struct wl_resource *resource)
{
XdgWmBase *wm_base;
XdgRoleList *role, *last;
wm_base = wl_resource_get_user_data (resource);
/* Detach each surface. */
role = wm_base->list.next;
while (role != &wm_base->list)
{
last = role;
role = role->next;
/* Complete all ping events. */
XLXdgRoleReplyPing (last->role);
/* Tell the surface to not bother unlinking itself. */
last->next = NULL;
last->last = NULL;
last->role = NULL;
}
XLFree (wm_base);
}
static void
HandleBind (struct wl_client *client, void *data,
uint32_t version, uint32_t id)
{
XdgWmBase *wm_base;
wm_base = XLSafeMalloc (sizeof *wm_base);
if (!wm_base)
{
wl_client_post_no_memory (client);
return;
}
memset (wm_base, 0, sizeof *wm_base);
wm_base->resource
= wl_resource_create (client, &xdg_wm_base_interface,
version, id);
if (!wm_base->resource)
{
XLFree (wm_base);
wl_client_post_no_memory (client);
return;
}
wl_resource_set_implementation (wm_base->resource, &xdg_wm_base_impl,
wm_base, HandleResourceDestroy);
wm_base->list.next = &wm_base->list;
wm_base->list.last = &wm_base->list;
}
void
XLInitXdgWM (void)
{
global_xdg_wm_base
= wl_global_create (compositor.wl_display,
&xdg_wm_base_interface,
5, NULL, HandleBind);
}
void
XLXdgWmBaseSendPing (XdgWmBase *wm_base)
{
xdg_wm_base_send_ping (wm_base->resource,
++wm_base->last_ping);
}