2019-01-20 16:34:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015-2019 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2023-08-07 09:50:23 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2019-01-20 16:34:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "wayland/meta-wayland-dnd-surface.h"
|
|
|
|
|
2019-09-06 13:13:24 +00:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2019-07-15 11:46:00 +00:00
|
|
|
#include "compositor/meta-feedback-actor-private.h"
|
2020-04-27 13:43:19 +00:00
|
|
|
#include "wayland/meta-wayland.h"
|
2019-07-15 11:46:00 +00:00
|
|
|
|
2019-01-20 16:34:50 +00:00
|
|
|
struct _MetaWaylandSurfaceRoleDND
|
|
|
|
{
|
|
|
|
MetaWaylandActorSurface parent;
|
2019-07-15 11:46:00 +00:00
|
|
|
int32_t pending_offset_x;
|
|
|
|
int32_t pending_offset_y;
|
2019-01-20 16:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaWaylandSurfaceRoleDND,
|
|
|
|
meta_wayland_surface_role_dnd,
|
|
|
|
META_TYPE_WAYLAND_ACTOR_SURFACE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
dnd_surface_assigned (MetaWaylandSurfaceRole *surface_role)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
|
|
|
|
2020-04-27 13:43:19 +00:00
|
|
|
if (wl_list_empty (&surface->unassigned.pending_frame_callback_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_wayland_compositor_add_frame_callback_surface (surface->compositor,
|
|
|
|
surface);
|
2019-01-20 16:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-11 09:20:44 +00:00
|
|
|
dnd_surface_apply_state (MetaWaylandSurfaceRole *surface_role,
|
|
|
|
MetaWaylandSurfaceState *pending)
|
2019-01-20 16:34:50 +00:00
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
2019-07-15 11:46:00 +00:00
|
|
|
MetaWaylandSurfaceRoleDND *surface_role_dnd =
|
|
|
|
META_WAYLAND_SURFACE_ROLE_DND (surface_role);
|
2019-04-15 00:02:10 +00:00
|
|
|
MetaWaylandSurfaceRoleClass *surface_role_class =
|
|
|
|
META_WAYLAND_SURFACE_ROLE_CLASS (meta_wayland_surface_role_dnd_parent_class);
|
2019-01-20 16:34:50 +00:00
|
|
|
|
2020-04-27 13:43:19 +00:00
|
|
|
meta_wayland_compositor_add_frame_callback_surface (surface->compositor,
|
|
|
|
surface);
|
2019-04-15 00:02:10 +00:00
|
|
|
|
2019-07-15 11:46:00 +00:00
|
|
|
surface_role_dnd->pending_offset_x = pending->dx;
|
|
|
|
surface_role_dnd->pending_offset_y = pending->dy;
|
|
|
|
|
2019-07-11 09:20:44 +00:00
|
|
|
surface_role_class->apply_state (surface_role, pending);
|
2019-01-20 16:34:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 13:13:24 +00:00
|
|
|
static MetaLogicalMonitor *
|
|
|
|
dnd_surface_find_logical_monitor (MetaWaylandActorSurface *actor_surface)
|
|
|
|
{
|
2022-05-30 21:48:44 +00:00
|
|
|
MetaWaylandSurfaceRole *surface_role =
|
|
|
|
META_WAYLAND_SURFACE_ROLE (actor_surface);
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (surface->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2020-07-10 21:28:17 +00:00
|
|
|
MetaCursorTracker *cursor_tracker =
|
|
|
|
meta_backend_get_cursor_tracker (backend);
|
2019-09-06 13:13:24 +00:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2020-07-13 10:06:12 +00:00
|
|
|
graphene_point_t point;
|
2019-09-06 13:13:24 +00:00
|
|
|
|
2020-07-13 10:06:12 +00:00
|
|
|
meta_cursor_tracker_get_pointer (cursor_tracker, &point, NULL);
|
|
|
|
return meta_monitor_manager_get_logical_monitor_at (monitor_manager,
|
|
|
|
point.x, point.y);
|
2019-09-06 13:13:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 12:06:10 +00:00
|
|
|
static int
|
2019-09-06 13:13:24 +00:00
|
|
|
dnd_subsurface_get_geometry_scale (MetaWaylandActorSurface *actor_surface)
|
|
|
|
{
|
2022-05-27 18:30:37 +00:00
|
|
|
MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (actor_surface);
|
|
|
|
MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
|
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (surface->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
|
|
|
|
|
|
|
if (meta_backend_is_stage_views_scaled (backend))
|
2019-09-06 13:13:24 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
|
|
|
|
logical_monitor = dnd_surface_find_logical_monitor (actor_surface);
|
2022-06-12 12:06:10 +00:00
|
|
|
return (int) roundf (meta_logical_monitor_get_scale (logical_monitor));
|
2019-09-06 13:13:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 11:46:00 +00:00
|
|
|
static void
|
|
|
|
dnd_subsurface_sync_actor_state (MetaWaylandActorSurface *actor_surface)
|
|
|
|
{
|
|
|
|
MetaSurfaceActor *surface_actor =
|
|
|
|
meta_wayland_actor_surface_get_actor (actor_surface);
|
|
|
|
MetaFeedbackActor *feedback_actor =
|
|
|
|
META_FEEDBACK_ACTOR (clutter_actor_get_parent (CLUTTER_ACTOR (surface_actor)));
|
|
|
|
MetaWaylandSurfaceRole *surface_role =
|
|
|
|
META_WAYLAND_SURFACE_ROLE (actor_surface);
|
|
|
|
MetaWaylandSurfaceRoleDND *surface_role_dnd =
|
|
|
|
META_WAYLAND_SURFACE_ROLE_DND (surface_role);
|
|
|
|
MetaWaylandActorSurfaceClass *actor_surface_class =
|
|
|
|
META_WAYLAND_ACTOR_SURFACE_CLASS (meta_wayland_surface_role_dnd_parent_class);
|
2019-09-06 14:11:03 +00:00
|
|
|
int geometry_scale;
|
2019-07-15 11:46:00 +00:00
|
|
|
float anchor_x;
|
|
|
|
float anchor_y;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_FEEDBACK_ACTOR (feedback_actor));
|
|
|
|
|
|
|
|
geometry_scale =
|
|
|
|
meta_wayland_actor_surface_get_geometry_scale (actor_surface);
|
2021-01-22 14:29:08 +00:00
|
|
|
meta_feedback_actor_set_geometry_scale (feedback_actor, geometry_scale);
|
2019-07-15 11:46:00 +00:00
|
|
|
|
|
|
|
meta_feedback_actor_get_anchor (feedback_actor, &anchor_x, &anchor_y);
|
2021-01-22 14:29:08 +00:00
|
|
|
anchor_x -= surface_role_dnd->pending_offset_x;
|
|
|
|
anchor_y -= surface_role_dnd->pending_offset_y;
|
2019-09-06 14:11:03 +00:00
|
|
|
meta_feedback_actor_set_anchor (feedback_actor, anchor_x, anchor_y);
|
|
|
|
|
2019-07-15 11:46:00 +00:00
|
|
|
actor_surface_class->sync_actor_state (actor_surface);
|
|
|
|
}
|
|
|
|
|
2019-01-20 16:34:50 +00:00
|
|
|
static void
|
|
|
|
meta_wayland_surface_role_dnd_init (MetaWaylandSurfaceRoleDND *role)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_surface_role_dnd_class_init (MetaWaylandSurfaceRoleDNDClass *klass)
|
|
|
|
{
|
|
|
|
MetaWaylandSurfaceRoleClass *surface_role_class =
|
|
|
|
META_WAYLAND_SURFACE_ROLE_CLASS (klass);
|
2019-07-15 11:46:00 +00:00
|
|
|
MetaWaylandActorSurfaceClass *actor_surface_class =
|
|
|
|
META_WAYLAND_ACTOR_SURFACE_CLASS (klass);
|
2019-01-20 16:34:50 +00:00
|
|
|
|
|
|
|
surface_role_class->assigned = dnd_surface_assigned;
|
2019-07-11 09:20:44 +00:00
|
|
|
surface_role_class->apply_state = dnd_surface_apply_state;
|
2019-07-15 11:46:00 +00:00
|
|
|
|
2019-09-06 13:13:24 +00:00
|
|
|
actor_surface_class->get_geometry_scale = dnd_subsurface_get_geometry_scale;
|
2019-07-15 11:46:00 +00:00
|
|
|
actor_surface_class->sync_actor_state = dnd_subsurface_sync_actor_state;
|
2019-01-20 16:34:50 +00:00
|
|
|
}
|