2014-04-27 10:49:29 -04:00
|
|
|
/* -*- 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 "meta-cursor-renderer-x11.h"
|
|
|
|
|
2014-11-03 13:51:40 -05:00
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
|
2014-04-27 10:49:29 -04:00
|
|
|
#include "meta-backend-x11.h"
|
2018-05-02 12:53:11 -04:00
|
|
|
#include "meta-stage-private.h"
|
2014-04-27 10:49:29 -04:00
|
|
|
|
|
|
|
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
|
2015-07-17 11:16:39 -04:00
|
|
|
meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2014-04-27 10:49:29 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererX11 *x11 = META_CURSOR_RENDERER_X11 (renderer);
|
|
|
|
MetaCursorRendererX11Private *priv = meta_cursor_renderer_x11_get_instance_private (x11);
|
|
|
|
|
|
|
|
MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ());
|
|
|
|
Window xwindow = meta_backend_x11_get_xwindow (backend);
|
2015-07-17 11:16:39 -04:00
|
|
|
Display *xdisplay = meta_backend_x11_get_xdisplay (backend);
|
2014-04-27 10:49:29 -04:00
|
|
|
|
|
|
|
if (xwindow == None)
|
2015-07-17 11:16:39 -04:00
|
|
|
{
|
|
|
|
if (cursor_sprite)
|
|
|
|
meta_cursor_sprite_realize_texture (cursor_sprite);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-04-27 10:49:29 -04:00
|
|
|
|
|
|
|
gboolean has_server_cursor = FALSE;
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
if (cursor_sprite)
|
2014-04-27 10:49:29 -04:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursor cursor = meta_cursor_sprite_get_meta_cursor (cursor_sprite);
|
2015-07-17 11:16:39 -04:00
|
|
|
|
2014-04-27 10:49:29 -04:00
|
|
|
if (cursor != META_CURSOR_NONE)
|
|
|
|
{
|
2018-04-27 09:39:29 -04:00
|
|
|
Cursor xcursor;
|
|
|
|
|
|
|
|
xcursor = meta_create_x_cursor (xdisplay, cursor);
|
2014-04-27 10:49:29 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
if (!priv->server_cursor_visible && cursor_sprite)
|
|
|
|
meta_cursor_sprite_realize_texture (cursor_sprite);
|
|
|
|
|
2014-04-27 10:49:29 -04:00
|
|
|
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;
|
|
|
|
}
|