mutter/src/backends/x11/meta-cursor-renderer-x11.c
Jonas Ådahl c390f70edc backend: Set up and use ownership chains
This means objects have an owner, where the chain eventually always
leads to a MetaContext. This also means that all objects can find their
way to other object instances via the chain, instead of scattered global
singletons.

This is a squashed commit originally containing the following:

cursor-tracker: Don't get backend from singleton

idle-manager: Don't get backend from singleton

input-device: Pass pointer to backend during construction

The backend is needed during construction to get the wacom database.

input-mapper: Pass backend when constructing

monitor: Don't get backend from singleton

monitor-manager: Get backend directly from monitor manager

remote: Get backend from manager class

For the remote desktop and screen cast implementations, replace getting
the backend from singletons with getting it via the manager classes.

launcher: Pass backend during construction

device-pool: Pass backend during construction

Instead of passing the (maybe null) launcher, pass the backend, and get
the launcher from there. That way we always have a way to some known
context from the device pool.

drm-buffer/gbm: Get backend via device pool

cursor-renderer: Get backend directly from renderer

input-device: Get backend getter

input-settings: Add backend construct property and getter

input-settings/x11: Don't get backend from singleton

renderer: Get backend from renderer itself

seat-impl: Add backend getter

seat/native: Get backend from instance struct

stage-impl: Get backend from stage impl itself

x11/xkb-a11y: Don't get backend from singleton

backend/x11/nested: Don't get Wayland compositor from singleton

crtc: Add backend property

Adding a link to the GPU isn't enough; the virtual CRTCs of virtual
monitors doesn't have one.

cursor-tracker: Don't get display from singleton

remote: Don't get display from singleton

seat: Don't get display from singleton

backend/x11: Don't get display from singleton

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
2022-12-17 13:52:51 +00:00

115 lines
3.6 KiB
C

/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2014 Red Hat
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Written by:
* Jasper St. Pierre <jstpierre@mecheye.net>
*/
#include "config.h"
#include "backends/x11/meta-cursor-renderer-x11.h"
#include <X11/extensions/Xfixes.h>
#include "backends/meta-cursor-sprite-xcursor.h"
#include "backends/meta-stage-private.h"
#include "backends/x11/meta-backend-x11.h"
struct _MetaCursorRendererX11Private
{
gboolean server_cursor_visible;
};
typedef struct _MetaCursorRendererX11Private MetaCursorRendererX11Private;
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererX11, meta_cursor_renderer_x11, META_TYPE_CURSOR_RENDERER);
static gboolean
meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite)
{
MetaCursorRendererX11 *x11 = META_CURSOR_RENDERER_X11 (renderer);
MetaCursorRendererX11Private *priv = meta_cursor_renderer_x11_get_instance_private (x11);
MetaBackend *backend = meta_cursor_renderer_get_backend (renderer);
MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
Window xwindow = meta_backend_x11_get_xwindow (backend_x11);
Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
if (xwindow == None)
{
if (cursor_sprite)
meta_cursor_sprite_realize_texture (cursor_sprite);
return FALSE;
}
gboolean has_server_cursor = FALSE;
if (cursor_sprite && META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
{
MetaCursorSpriteXcursor *sprite_xcursor =
META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
MetaCursor cursor;
cursor = meta_cursor_sprite_xcursor_get_cursor (sprite_xcursor);
if (cursor != META_CURSOR_NONE)
{
Cursor xcursor;
xcursor = meta_create_x_cursor (xdisplay, cursor);
XDefineCursor (xdisplay, xwindow, xcursor);
XFlush (xdisplay);
XFreeCursor (xdisplay, xcursor);
has_server_cursor = TRUE;
}
}
if (has_server_cursor != priv->server_cursor_visible)
{
if (has_server_cursor)
XFixesShowCursor (xdisplay, xwindow);
else
XFixesHideCursor (xdisplay, xwindow);
priv->server_cursor_visible = has_server_cursor;
}
if (cursor_sprite)
meta_cursor_sprite_realize_texture (cursor_sprite);
return priv->server_cursor_visible;
}
static void
meta_cursor_renderer_x11_class_init (MetaCursorRendererX11Class *klass)
{
MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_CLASS (klass);
renderer_class->update_cursor = meta_cursor_renderer_x11_update_cursor;
}
static void
meta_cursor_renderer_x11_init (MetaCursorRendererX11 *x11)
{
MetaCursorRendererX11Private *priv = meta_cursor_renderer_x11_get_instance_private (x11);
/* XFixes has no way to retrieve the current cursor visibility. */
priv->server_cursor_visible = TRUE;
}