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 <gdk/gdkx.h>
#include "x11/meta-x11-selection-input-stream-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)
{
MetaSelectionSourceX11 *source_x11 = META_SELECTION_SOURCE_X11 (source);
Display *xdisplay = meta_x11_display_get_xdisplay (source_x11->x11_display);
GTask *task;
task = g_task_new (source, cancellable, callback, user_data);
@ -92,7 +91,7 @@ meta_selection_source_x11_read_async (MetaSelectionSource *source,
mimetype = "UTF8_STRING";
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,
source_x11->timestamp,
G_PRIORITY_DEFAULT,
@ -143,6 +142,7 @@ static GList *
atoms_to_mimetypes (MetaX11Display *display,
GBytes *bytes)
{
Display *xdisplay = meta_x11_display_get_xdisplay (display);
GList *mimetypes = NULL;
const Atom *atoms;
gsize size;
@ -157,7 +157,7 @@ atoms_to_mimetypes (MetaX11Display *display,
{
const gchar *mimetype;
mimetype = gdk_x11_get_xatom_name (atoms[i]);
mimetype = XGetAtomName (xdisplay, atoms[i]);
mimetypes = g_list_prepend (mimetypes, g_strdup (mimetype));
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,
gpointer user_data)
{
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
MetaSelectionSourceX11 *source;
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);
meta_x11_selection_input_stream_new_async (x11_display,
gdk_x11_get_xatom_name (xselection),
XGetAtomName (xdisplay, xselection),
"TARGETS",
timestamp,
G_PRIORITY_DEFAULT,

View File

@ -23,8 +23,6 @@
#include "meta-x11-selection-input-stream-private.h"
#include <gdk/gdkx.h>
#include "meta/meta-x11-errors.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,
xevent->xselection.property,
&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);

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <gdk/gdkx.h>
#include "core/meta-selection-private.h"
#include "meta/meta-selection-source-memory.h"
#include "x11/meta-selection-source-x11-private.h"
@ -125,10 +123,11 @@ mimetypes_to_bytes (GList *mimetypes,
}
static void
send_selection_notify (XSelectionRequestEvent *request_event,
send_selection_notify (MetaX11Display *x11_display,
XSelectionRequestEvent *request_event,
gboolean accepted)
{
Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
XSelectionEvent event;
memset(&event, 0, sizeof (XSelectionEvent));
@ -184,12 +183,13 @@ meta_x11_selection_find_target (MetaX11Display *x11_display,
MetaSelectionType selection_type,
Atom selection_atom)
{
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
GList* mimetypes = NULL;
const gchar *atom_name;
char *retval;
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))
{
@ -222,6 +222,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
XEvent *xevent)
{
MetaDisplay *display = meta_x11_display_get_display (x11_display);
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
XSelectionRequestEvent *event = (XSelectionRequestEvent *) xevent;
MetaSelectionType selection_type;
MetaSelection *selection;
@ -235,7 +236,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_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;
@ -243,14 +244,14 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
if (!mimetypes)
{
send_selection_notify (event, FALSE);
send_selection_notify (x11_display, event, FALSE);
return FALSE;
}
output = meta_x11_selection_output_stream_new (x11_display, event->requestor,
gdk_x11_get_xatom_name (event->selection),
gdk_x11_get_xatom_name (event->target),
gdk_x11_get_xatom_name (event->property),
XGetAtomName (xdisplay, event->selection),
XGetAtomName (xdisplay, event->target),
XGetAtomName (xdisplay, event->property),
"ATOM", 32, event->time);
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);
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
* sources, so just go with it.
*/
send_selection_notify (event, TRUE);
send_selection_notify (x11_display, event, TRUE);
}
else
{
@ -283,10 +284,10 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
{
output = meta_x11_selection_output_stream_new (x11_display,
event->requestor,
gdk_x11_get_xatom_name (event->selection),
gdk_x11_get_xatom_name (event->target),
gdk_x11_get_xatom_name (event->property),
gdk_x11_get_xatom_name (event->target),
XGetAtomName (xdisplay, event->selection),
XGetAtomName (xdisplay, event->target),
XGetAtomName (xdisplay, event->property),
XGetAtomName (xdisplay, event->target),
8, event->time);
meta_selection_transfer_async (selection,
@ -301,7 +302,7 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display,
}
else
{
send_selection_notify (event, FALSE);
send_selection_notify (x11_display, event, FALSE);
}
}