2017-01-02 14:11:32 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Hyungwon Hwang
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
|
|
|
#include "meta/meta-backend.h"
|
|
|
|
#include "compositor/compositor-private.h"
|
|
|
|
#include "core/display-private.h"
|
|
|
|
#include "backends/meta-dnd-private.h"
|
2019-07-03 14:23:45 +00:00
|
|
|
#include "backends/x11/meta-backend-x11.h"
|
2021-05-10 21:40:49 +00:00
|
|
|
#include "backends/x11/meta-clutter-backend-x11.h"
|
2019-03-22 12:53:00 +00:00
|
|
|
#include "backends/x11/meta-stage-x11.h"
|
2017-01-02 14:11:32 +00:00
|
|
|
#include "meta/meta-dnd.h"
|
2017-08-26 16:26:30 +00:00
|
|
|
#include "x11/meta-x11-display-private.h"
|
2017-01-02 14:11:32 +00:00
|
|
|
|
|
|
|
struct _MetaDndClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2017-01-02 14:12:34 +00:00
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
#include "wayland/meta-wayland-data-device.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _MetaDndPrivate MetaDndPrivate;
|
|
|
|
|
|
|
|
struct _MetaDndPrivate
|
|
|
|
{
|
|
|
|
#ifdef HAVE_WAYLAND
|
2022-02-23 15:09:28 +00:00
|
|
|
gboolean dnd_during_modal;
|
2017-01-02 14:12:34 +00:00
|
|
|
#else
|
|
|
|
/* to avoid warnings (g_type_class_add_private: assertion `private_size > 0' failed) */
|
|
|
|
gchar dummy;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2017-01-02 14:11:32 +00:00
|
|
|
struct _MetaDnd
|
|
|
|
{
|
|
|
|
GObject parent;
|
2017-01-02 14:12:34 +00:00
|
|
|
|
|
|
|
MetaDndPrivate *priv;
|
2017-01-02 14:11:32 +00:00
|
|
|
};
|
|
|
|
|
2017-01-02 14:12:34 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaDnd, meta_dnd, G_TYPE_OBJECT);
|
2017-01-02 14:11:32 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ENTER,
|
|
|
|
POSITION_CHANGE,
|
|
|
|
LEAVE,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_dnd_class_init (MetaDndClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
signals[ENTER] =
|
|
|
|
g_signal_new ("dnd-enter",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[POSITION_CHANGE] =
|
|
|
|
g_signal_new ("dnd-position-change",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
|
|
|
|
|
|
|
|
signals[LEAVE] =
|
|
|
|
g_signal_new ("dnd-leave",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_dnd_init (MetaDnd *dnd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:23:45 +00:00
|
|
|
void
|
|
|
|
meta_dnd_init_xdnd (MetaX11Display *x11_display)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
Display *xdisplay = x11_display->xdisplay;
|
|
|
|
Window xwindow, overlay_xwindow;
|
|
|
|
long xdnd_version = 5;
|
|
|
|
|
2019-07-10 19:13:00 +00:00
|
|
|
overlay_xwindow = x11_display->composite_overlay_window;
|
2019-07-03 14:23:45 +00:00
|
|
|
xwindow = meta_backend_x11_get_xwindow (META_BACKEND_X11 (backend));
|
|
|
|
|
|
|
|
XChangeProperty (xdisplay, xwindow,
|
|
|
|
XInternAtom (xdisplay, "XdndAware", TRUE), XA_ATOM,
|
|
|
|
32, PropModeReplace,
|
|
|
|
(const unsigned char *) &xdnd_version, 1);
|
|
|
|
|
|
|
|
XChangeProperty (xdisplay, overlay_xwindow,
|
|
|
|
XInternAtom (xdisplay, "XdndProxy", TRUE), XA_WINDOW,
|
|
|
|
32, PropModeReplace, (const unsigned char *) &xwindow, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XdndProxy is additionally set on the proxy window as verification that the
|
|
|
|
* XdndProxy property on the target window isn't a left-over
|
|
|
|
*/
|
|
|
|
XChangeProperty (xdisplay, xwindow,
|
|
|
|
XInternAtom (xdisplay, "XdndProxy", TRUE), XA_WINDOW,
|
|
|
|
32, PropModeReplace, (const unsigned char *) &xwindow, 1);
|
|
|
|
}
|
|
|
|
|
2017-01-02 14:11:32 +00:00
|
|
|
static void
|
|
|
|
meta_dnd_notify_dnd_enter (MetaDnd *dnd)
|
|
|
|
{
|
|
|
|
g_signal_emit (dnd, signals[ENTER], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_dnd_notify_dnd_position_change (MetaDnd *dnd,
|
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
|
|
|
g_signal_emit (dnd, signals[POSITION_CHANGE], 0, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_dnd_notify_dnd_leave (MetaDnd *dnd)
|
|
|
|
{
|
|
|
|
g_signal_emit (dnd, signals[LEAVE], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process Xdnd events
|
|
|
|
*
|
|
|
|
* We pass the position and leave events to the plugin via a signal
|
|
|
|
* where the actual drag & drop handling happens.
|
|
|
|
*
|
|
|
|
* http://www.freedesktop.org/wiki/Specifications/XDND
|
|
|
|
*/
|
|
|
|
gboolean
|
2019-08-14 21:25:54 +00:00
|
|
|
meta_dnd_handle_xdnd_event (MetaBackend *backend,
|
|
|
|
MetaCompositorX11 *compositor_x11,
|
|
|
|
Display *xdisplay,
|
|
|
|
XEvent *xev)
|
2017-01-02 14:11:32 +00:00
|
|
|
{
|
|
|
|
MetaDnd *dnd = meta_backend_get_dnd (backend);
|
2019-08-14 21:25:54 +00:00
|
|
|
MetaCompositor *compositor = META_COMPOSITOR (compositor_x11);
|
2019-08-14 17:04:41 +00:00
|
|
|
Window output_window;
|
|
|
|
ClutterStage *stage;
|
2017-01-02 14:11:32 +00:00
|
|
|
|
|
|
|
if (xev->xany.type != ClientMessage)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-08-14 21:25:54 +00:00
|
|
|
output_window = meta_compositor_x11_get_output_xwindow (compositor_x11);
|
2019-08-14 17:04:41 +00:00
|
|
|
stage = meta_compositor_get_stage (compositor);
|
2017-01-02 14:11:32 +00:00
|
|
|
if (xev->xany.window != output_window &&
|
2019-03-22 12:53:00 +00:00
|
|
|
xev->xany.window != meta_x11_get_stage_window (stage))
|
2017-01-02 14:11:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-08-26 20:52:21 +00:00
|
|
|
if (xev->xclient.message_type == XInternAtom (xdisplay, "XdndPosition", TRUE))
|
2017-01-02 14:11:32 +00:00
|
|
|
{
|
|
|
|
XEvent xevent;
|
|
|
|
Window src = xev->xclient.data.l[0];
|
|
|
|
|
|
|
|
memset (&xevent, 0, sizeof(xevent));
|
|
|
|
xevent.xany.type = ClientMessage;
|
2017-08-26 20:52:21 +00:00
|
|
|
xevent.xany.display = xdisplay;
|
2017-01-02 14:11:32 +00:00
|
|
|
xevent.xclient.window = src;
|
2017-08-26 20:52:21 +00:00
|
|
|
xevent.xclient.message_type = XInternAtom (xdisplay, "XdndStatus", TRUE);
|
2017-01-02 14:11:32 +00:00
|
|
|
xevent.xclient.format = 32;
|
|
|
|
xevent.xclient.data.l[0] = output_window;
|
|
|
|
/* flags: bit 0: will we accept the drop? bit 1: do we want more position messages */
|
|
|
|
xevent.xclient.data.l[1] = 2;
|
|
|
|
xevent.xclient.data.l[4] = None;
|
|
|
|
|
2017-08-26 20:52:21 +00:00
|
|
|
XSendEvent (xdisplay, src, False, 0, &xevent);
|
2017-01-02 14:11:32 +00:00
|
|
|
|
|
|
|
meta_dnd_notify_dnd_position_change (dnd,
|
|
|
|
(int)(xev->xclient.data.l[2] >> 16),
|
|
|
|
(int)(xev->xclient.data.l[2] & 0xFFFF));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-08-26 20:52:21 +00:00
|
|
|
else if (xev->xclient.message_type == XInternAtom (xdisplay, "XdndLeave", TRUE))
|
2017-01-02 14:11:32 +00:00
|
|
|
{
|
|
|
|
meta_dnd_notify_dnd_leave (dnd);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-08-26 20:52:21 +00:00
|
|
|
else if (xev->xclient.message_type == XInternAtom (xdisplay, "XdndEnter", TRUE))
|
2017-01-02 14:11:32 +00:00
|
|
|
{
|
|
|
|
meta_dnd_notify_dnd_enter (dnd);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-01-02 14:12:34 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
static void
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_on_motion_event (MetaDnd *dnd,
|
|
|
|
const ClutterEvent *event)
|
2017-01-02 14:12:34 +00:00
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *current_grab;
|
|
|
|
gfloat event_x, event_y;
|
2022-02-23 15:09:28 +00:00
|
|
|
MetaWaylandCompositor *wl_compositor = meta_wayland_compositor_get_default ();
|
2017-01-02 14:12:34 +00:00
|
|
|
|
|
|
|
g_return_if_fail (event != NULL);
|
|
|
|
|
|
|
|
clutter_event_get_coords (event, &event_x, &event_y);
|
|
|
|
meta_dnd_notify_dnd_position_change (dnd, (int)event_x, (int)event_y);
|
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
current_grab = meta_wayland_data_device_get_current_grab (&wl_compositor->seat->data_device);
|
2017-01-02 14:12:34 +00:00
|
|
|
if (current_grab)
|
|
|
|
meta_wayland_drag_grab_update_feedback_actor (current_grab, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_end_notify (MetaDnd *dnd)
|
2017-01-02 14:12:34 +00:00
|
|
|
{
|
|
|
|
MetaDndPrivate *priv = meta_dnd_get_instance_private (dnd);
|
2022-02-23 15:09:28 +00:00
|
|
|
MetaWaylandCompositor *wl_compositor = meta_wayland_compositor_get_default ();
|
|
|
|
|
|
|
|
meta_wayland_data_device_end_drag (&wl_compositor->seat->data_device);
|
|
|
|
|
|
|
|
priv->dnd_during_modal = FALSE;
|
2017-01-02 14:12:34 +00:00
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_notify_dnd_leave (dnd);
|
2017-01-02 14:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_on_button_released (MetaDnd *dnd,
|
|
|
|
const ClutterEvent *event)
|
2017-01-02 14:12:34 +00:00
|
|
|
{
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_end_notify (dnd);
|
2017-01-02 14:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_on_key_pressed (MetaDnd *dnd,
|
|
|
|
const ClutterEvent *event)
|
2017-01-02 14:12:34 +00:00
|
|
|
{
|
|
|
|
guint key = clutter_event_get_key_symbol (event);
|
|
|
|
|
|
|
|
if (key != CLUTTER_KEY_Escape)
|
|
|
|
return;
|
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_end_notify (dnd);
|
2017-01-02 14:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-02-23 15:09:28 +00:00
|
|
|
meta_dnd_wayland_maybe_handle_event (MetaDnd *dnd,
|
|
|
|
const ClutterEvent *event)
|
2017-01-02 14:12:34 +00:00
|
|
|
{
|
|
|
|
MetaWaylandCompositor *wl_compositor = meta_wayland_compositor_get_default ();
|
|
|
|
MetaDndPrivate *priv = meta_dnd_get_instance_private (dnd);
|
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
if (!meta_wayland_data_device_get_current_grab (&wl_compositor->seat->data_device))
|
|
|
|
return;
|
2019-08-14 17:04:41 +00:00
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
g_warn_if_fail (priv->dnd_during_modal);
|
2017-01-02 14:12:34 +00:00
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
if (event->type == CLUTTER_MOTION)
|
|
|
|
meta_dnd_wayland_on_motion_event (dnd, event);
|
|
|
|
else if (event->type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
meta_dnd_wayland_on_button_released (dnd, event);
|
|
|
|
else if (event->type == CLUTTER_KEY_PRESS)
|
|
|
|
meta_dnd_wayland_on_key_pressed (dnd, event);
|
|
|
|
}
|
2017-01-02 14:12:34 +00:00
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
void
|
|
|
|
meta_dnd_wayland_handle_begin_modal (MetaCompositor *compositor)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *wl_compositor = meta_wayland_compositor_get_default ();
|
|
|
|
MetaDnd *dnd = meta_backend_get_dnd (meta_get_backend ());
|
|
|
|
MetaDndPrivate *priv = meta_dnd_get_instance_private (dnd);
|
2017-01-02 14:12:34 +00:00
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
if (!priv->dnd_during_modal &&
|
|
|
|
meta_wayland_data_device_get_current_grab (&wl_compositor->seat->data_device) != NULL)
|
|
|
|
{
|
|
|
|
priv->dnd_during_modal = TRUE;
|
2017-01-02 14:12:34 +00:00
|
|
|
|
|
|
|
meta_dnd_notify_dnd_enter (dnd);
|
|
|
|
}
|
|
|
|
}
|
2017-11-16 16:22:50 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_dnd_wayland_handle_end_modal (MetaCompositor *compositor)
|
|
|
|
{
|
|
|
|
MetaDnd *dnd = meta_backend_get_dnd (meta_get_backend ());
|
|
|
|
MetaDndPrivate *priv = meta_dnd_get_instance_private (dnd);
|
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
if (!priv->dnd_during_modal)
|
2017-11-16 16:22:50 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-23 15:09:28 +00:00
|
|
|
priv->dnd_during_modal = FALSE;
|
2017-11-16 16:22:50 +00:00
|
|
|
|
|
|
|
meta_dnd_notify_dnd_leave (dnd);
|
|
|
|
}
|
2017-01-02 14:12:34 +00:00
|
|
|
#endif
|