x11: Avoid GDK API in X11 selections

Use MetaX11Display's Display, and XInternAtom/XGetAtomName to
convert between Atoms and strings.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2836>
This commit is contained in:
Carlos Garnacho 2023-02-10 19:32:27 +01:00 committed by Marge Bot
parent 014cde6461
commit e66f4396ee
3 changed files with 25 additions and 25 deletions

View File

@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <gdk/gdkx.h>
#include "x11/meta-x11-selection-input-stream-private.h" #include "x11/meta-x11-selection-input-stream-private.h"
#include "x11/meta-selection-source-x11-private.h" #include "x11/meta-selection-source-x11-private.h"
@ -77,6 +75,7 @@ meta_selection_source_x11_read_async (MetaSelectionSource *source,
gpointer user_data) gpointer user_data)
{ {
MetaSelectionSourceX11 *source_x11 = META_SELECTION_SOURCE_X11 (source); MetaSelectionSourceX11 *source_x11 = META_SELECTION_SOURCE_X11 (source);
Display *xdisplay = meta_x11_display_get_xdisplay (source_x11->x11_display);
GTask *task; GTask *task;
task = g_task_new (source, cancellable, callback, user_data); task = g_task_new (source, cancellable, callback, user_data);
@ -92,7 +91,7 @@ meta_selection_source_x11_read_async (MetaSelectionSource *source,
mimetype = "UTF8_STRING"; mimetype = "UTF8_STRING";
meta_x11_selection_input_stream_new_async (source_x11->x11_display, meta_x11_selection_input_stream_new_async (source_x11->x11_display,
gdk_x11_get_xatom_name (source_x11->xselection), XGetAtomName (xdisplay, source_x11->xselection),
mimetype, mimetype,
source_x11->timestamp, source_x11->timestamp,
G_PRIORITY_DEFAULT, G_PRIORITY_DEFAULT,
@ -143,6 +142,7 @@ static GList *
atoms_to_mimetypes (MetaX11Display *display, atoms_to_mimetypes (MetaX11Display *display,
GBytes *bytes) GBytes *bytes)
{ {
Display *xdisplay = meta_x11_display_get_xdisplay (display);
GList *mimetypes = NULL; GList *mimetypes = NULL;
const Atom *atoms; const Atom *atoms;
gsize size; gsize size;
@ -157,7 +157,7 @@ atoms_to_mimetypes (MetaX11Display *display,
{ {
const gchar *mimetype; const gchar *mimetype;
mimetype = gdk_x11_get_xatom_name (atoms[i]); mimetype = XGetAtomName (xdisplay, atoms[i]);
mimetypes = g_list_prepend (mimetypes, g_strdup (mimetype)); mimetypes = g_list_prepend (mimetypes, g_strdup (mimetype));
utf8_text_plain_found |= strcmp (mimetype, "text/plain;charset=utf-8") == 0; utf8_text_plain_found |= strcmp (mimetype, "text/plain;charset=utf-8") == 0;
@ -236,6 +236,7 @@ meta_selection_source_x11_new_async (MetaX11Display *x11_display,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
MetaSelectionSourceX11 *source; MetaSelectionSourceX11 *source;
GTask *task; GTask *task;
@ -250,7 +251,7 @@ meta_selection_source_x11_new_async (MetaX11Display *x11_display,
g_task_set_task_data (task, source, g_object_unref); g_task_set_task_data (task, source, g_object_unref);
meta_x11_selection_input_stream_new_async (x11_display, meta_x11_selection_input_stream_new_async (x11_display,
gdk_x11_get_xatom_name (xselection), XGetAtomName (xdisplay, xselection),
"TARGETS", "TARGETS",
timestamp, timestamp,
G_PRIORITY_DEFAULT, G_PRIORITY_DEFAULT,

View File

@ -23,8 +23,6 @@
#include "meta-x11-selection-input-stream-private.h" #include "meta-x11-selection-input-stream-private.h"
#include <gdk/gdkx.h>
#include "meta/meta-x11-errors.h" #include "meta/meta-x11-errors.h"
#include "x11/meta-x11-display-private.h" #include "x11/meta-x11-display-private.h"
@ -489,7 +487,7 @@ meta_x11_selection_input_stream_xevent (MetaX11SelectionInputStream *stream,
bytes = get_selection_property (priv->x11_display, xwindow, bytes = get_selection_property (priv->x11_display, xwindow,
xevent->xselection.property, xevent->xselection.property,
&priv->xtype, &priv->format); &priv->xtype, &priv->format);
priv->type = gdk_x11_get_xatom_name (priv->xtype); priv->type = XGetAtomName (xdisplay, priv->xtype);
g_task_return_pointer (task, g_object_ref (stream), g_object_unref); g_task_return_pointer (task, g_object_ref (stream), g_object_unref);

View File

@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <gdk/gdkx.h>
#include "core/meta-selection-private.h" #include "core/meta-selection-private.h"
#include "meta/meta-selection-source-memory.h" #include "meta/meta-selection-source-memory.h"
#include "x11/meta-selection-source-x11-private.h" #include "x11/meta-selection-source-x11-private.h"
@ -125,10 +123,11 @@ mimetypes_to_bytes (GList *mimetypes,
} }
static void static void
send_selection_notify (XSelectionRequestEvent *request_event, send_selection_notify (MetaX11Display *x11_display,
XSelectionRequestEvent *request_event,
gboolean accepted) gboolean accepted)
{ {
Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
XSelectionEvent event; XSelectionEvent event;
memset(&event, 0, sizeof (XSelectionEvent)); memset(&event, 0, sizeof (XSelectionEvent));
@ -184,12 +183,13 @@ meta_x11_selection_find_target (MetaX11Display *x11_display,
MetaSelectionType selection_type, MetaSelectionType selection_type,
Atom selection_atom) Atom selection_atom)
{ {
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
GList* mimetypes = NULL; GList* mimetypes = NULL;
const gchar *atom_name; const gchar *atom_name;
char *retval; char *retval;
mimetypes = meta_selection_get_mimetypes (selection, selection_type); mimetypes = meta_selection_get_mimetypes (selection, selection_type);
atom_name = gdk_x11_get_xatom_name (selection_atom); atom_name = XGetAtomName (xdisplay, selection_atom);
if (g_list_find_custom (mimetypes, atom_name, (GCompareFunc) g_strcmp0)) if (g_list_find_custom (mimetypes, atom_name, (GCompareFunc) g_strcmp0))
{ {
@ -222,6 +222,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
XEvent *xevent) XEvent *xevent)
{ {
MetaDisplay *display = meta_x11_display_get_display (x11_display); MetaDisplay *display = meta_x11_display_get_display (x11_display);
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent; XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent;
MetaSelectionType selection_type; MetaSelectionType selection_type;
MetaSelection *selection; MetaSelection *selection;
@ -235,7 +236,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
selection = meta_display_get_selection (display); selection = meta_display_get_selection (display);
if (event->target == gdk_x11_get_xatom_by_name ("TARGETS")) if (event->target == XInternAtom (xdisplay, "TARGETS", False))
{ {
GBytes *bytes; GBytes *bytes;
@ -243,14 +244,14 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
if (!mimetypes) if (!mimetypes)
{ {
send_selection_notify (event, FALSE); send_selection_notify (x11_display, event, FALSE);
return FALSE; return FALSE;
} }
output = meta_x11_selection_output_stream_new (x11_display, event->requestor, output = meta_x11_selection_output_stream_new (x11_display, event->requestor,
gdk_x11_get_xatom_name (event->selection), XGetAtomName (xdisplay, event->selection),
gdk_x11_get_xatom_name (event->target), XGetAtomName (xdisplay, event->target),
gdk_x11_get_xatom_name (event->property), XGetAtomName (xdisplay, event->property),
"ATOM", 32, event->time); "ATOM", 32, event->time);
bytes = mimetypes_to_bytes (mimetypes, x11_display->xdisplay); bytes = mimetypes_to_bytes (mimetypes, x11_display->xdisplay);
@ -265,12 +266,12 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
g_bytes_unref (bytes); g_bytes_unref (bytes);
return TRUE; return TRUE;
} }
else if (event->target == gdk_x11_get_xatom_by_name ("DELETE")) else if (event->target == XInternAtom (xdisplay, "DELETE", False))
{ {
/* DnD only, this is just handled through other means on our non-x11 /* DnD only, this is just handled through other means on our non-x11
* sources, so just go with it. * sources, so just go with it.
*/ */
send_selection_notify (event, TRUE); send_selection_notify (x11_display, event, TRUE);
} }
else else
{ {
@ -283,10 +284,10 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
{ {
output = meta_x11_selection_output_stream_new (x11_display, output = meta_x11_selection_output_stream_new (x11_display,
event->requestor, event->requestor,
gdk_x11_get_xatom_name (event->selection), XGetAtomName (xdisplay, event->selection),
gdk_x11_get_xatom_name (event->target), XGetAtomName (xdisplay, event->target),
gdk_x11_get_xatom_name (event->property), XGetAtomName (xdisplay, event->property),
gdk_x11_get_xatom_name (event->target), XGetAtomName (xdisplay, event->target),
8, event->time); 8, event->time);
meta_selection_transfer_async (selection, meta_selection_transfer_async (selection,
@ -301,7 +302,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
} }
else else
{ {
send_selection_notify (event, FALSE); send_selection_notify (x11_display, event, FALSE);
} }
} }