2014-04-22 18:03:40 -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"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-outputs.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-monitor.h"
|
|
|
|
#include "backends/meta-monitor-manager-private.h"
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
#include "xdg-output-unstable-v1-server-protocol.h"
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2019-07-25 08:12:46 -04:00
|
|
|
/* Wayland protocol headers list new additions, not deprecations */
|
|
|
|
#define NO_XDG_OUTPUT_DONE_SINCE_VERSION 3
|
2014-04-26 04:27:34 -04:00
|
|
|
|
2018-12-19 03:04:25 -05:00
|
|
|
enum
|
|
|
|
{
|
wayland: Send wl_surface.enter and wl_surface.leave
Whenever a MetaSurfaceActor is painted, update the list of what outputs
the surface is being drawed upon. Since we do this on paint, we
effectively avoids this whenever the surface is not drawn, for example
being minimized, on a non-active workspace, or simply outside of the
damage region of a frame.
DND icons and cursors are not affected by this patch, since they are not
drawn as MetaSurfaceActors. If a MetaSurfaceActor or a parent is cloned,
then we'll check the position of the original actor again when the clone is
drawn, which is slightly expensive, but harmless. If the MetaShapedTexture
instead is cloned, as GNOME Shell does in many cases, then these clones
will not cause duplicate position checks.
https://bugzilla.gnome.org/show_bug.cgi?id=744453
2015-02-03 02:49:52 -05:00
|
|
|
OUTPUT_DESTROYED,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2015-04-17 05:17:46 -04:00
|
|
|
G_DEFINE_TYPE (MetaWaylandOutput, meta_wayland_output, G_TYPE_OBJECT)
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
static void
|
|
|
|
send_xdg_output_events (struct wl_resource *resource,
|
|
|
|
MetaWaylandOutput *wayland_output,
|
|
|
|
MetaLogicalMonitor *logical_monitor,
|
|
|
|
gboolean need_all_events,
|
|
|
|
gboolean *pending_done_event);
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
static void
|
|
|
|
output_resource_destroy (struct wl_resource *res)
|
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output;
|
|
|
|
|
|
|
|
wayland_output = wl_resource_get_user_data (res);
|
2015-07-01 01:18:45 -04:00
|
|
|
if (!wayland_output)
|
|
|
|
return;
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
wayland_output->resources = g_list_remove (wayland_output->resources, res);
|
|
|
|
}
|
|
|
|
|
2016-12-22 02:24:02 -05:00
|
|
|
static MetaMonitor *
|
|
|
|
pick_main_monitor (MetaLogicalMonitor *logical_monitor)
|
2016-12-13 08:44:16 -05:00
|
|
|
{
|
|
|
|
GList *monitors;
|
|
|
|
|
|
|
|
monitors = meta_logical_monitor_get_monitors (logical_monitor);
|
2016-12-22 02:24:02 -05:00
|
|
|
return g_list_first (monitors)->data;
|
2016-12-13 08:44:16 -05:00
|
|
|
}
|
|
|
|
|
2016-12-22 02:16:48 -05:00
|
|
|
static enum wl_output_subpixel
|
|
|
|
cogl_subpixel_order_to_wl_output_subpixel (CoglSubpixelOrder subpixel_order)
|
|
|
|
{
|
|
|
|
switch (subpixel_order)
|
|
|
|
{
|
|
|
|
case COGL_SUBPIXEL_ORDER_UNKNOWN:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
|
|
|
case COGL_SUBPIXEL_ORDER_NONE:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_NONE;
|
|
|
|
case COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
|
|
|
|
case COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
|
|
|
|
case COGL_SUBPIXEL_ORDER_VERTICAL_RGB:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
|
|
|
|
case COGL_SUBPIXEL_ORDER_VERTICAL_BGR:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
2019-01-24 18:47:44 -05:00
|
|
|
return WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
2016-12-22 02:16:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum wl_output_subpixel
|
|
|
|
calculate_suitable_subpixel_order (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
GList *monitors;
|
|
|
|
GList *l;
|
|
|
|
MetaMonitor *first_monitor;
|
|
|
|
CoglSubpixelOrder subpixel_order;
|
|
|
|
|
|
|
|
monitors = meta_logical_monitor_get_monitors (logical_monitor);
|
|
|
|
first_monitor = monitors->data;
|
|
|
|
subpixel_order = meta_monitor_get_subpixel_order (first_monitor);
|
|
|
|
|
|
|
|
for (l = monitors->next; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = l->data;
|
|
|
|
|
|
|
|
if (meta_monitor_get_subpixel_order (monitor) != subpixel_order)
|
|
|
|
{
|
|
|
|
subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cogl_subpixel_order_to_wl_output_subpixel (subpixel_order);
|
|
|
|
}
|
|
|
|
|
2017-05-25 05:20:59 -04:00
|
|
|
static int
|
|
|
|
calculate_wayland_output_scale (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
scale = meta_logical_monitor_get_scale (logical_monitor);
|
|
|
|
return ceilf (scale);
|
|
|
|
}
|
|
|
|
|
2018-11-07 04:13:24 -05:00
|
|
|
static void
|
|
|
|
get_rotated_physical_dimensions (MetaMonitor *monitor,
|
|
|
|
int *width_mm,
|
|
|
|
int *height_mm)
|
|
|
|
{
|
|
|
|
int monitor_width_mm, monitor_height_mm;
|
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
|
|
|
|
meta_monitor_get_physical_dimensions (monitor,
|
|
|
|
&monitor_width_mm,
|
|
|
|
&monitor_height_mm);
|
|
|
|
logical_monitor = meta_monitor_get_logical_monitor (monitor);
|
|
|
|
|
|
|
|
if (meta_monitor_transform_is_rotated (logical_monitor->transform))
|
|
|
|
{
|
|
|
|
*width_mm = monitor_height_mm;
|
|
|
|
*height_mm = monitor_width_mm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*width_mm = monitor_width_mm;
|
|
|
|
*height_mm = monitor_height_mm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_different_rotation (MetaLogicalMonitor *a,
|
|
|
|
MetaLogicalMonitor *b)
|
|
|
|
{
|
|
|
|
return (meta_monitor_transform_is_rotated (a->transform) !=
|
|
|
|
meta_monitor_transform_is_rotated (b->transform));
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:28:14 -04:00
|
|
|
static void
|
|
|
|
send_output_events (struct wl_resource *resource,
|
|
|
|
MetaWaylandOutput *wayland_output,
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor,
|
2017-09-05 12:53:41 -04:00
|
|
|
gboolean need_all_events,
|
|
|
|
gboolean *pending_done_event)
|
2016-05-16 14:28:14 -04:00
|
|
|
{
|
|
|
|
int version = wl_resource_get_version (resource);
|
2016-12-22 02:24:02 -05:00
|
|
|
MetaMonitor *monitor;
|
|
|
|
MetaMonitorMode *current_mode;
|
|
|
|
MetaMonitorMode *preferred_mode;
|
2016-05-16 14:28:14 -04:00
|
|
|
guint mode_flags = WL_OUTPUT_MODE_CURRENT;
|
2016-12-13 08:44:16 -05:00
|
|
|
MetaLogicalMonitor *old_logical_monitor;
|
|
|
|
guint old_mode_flags;
|
|
|
|
gint old_scale;
|
2016-12-13 09:08:17 -05:00
|
|
|
float old_refresh_rate;
|
|
|
|
float refresh_rate;
|
2016-12-13 08:44:16 -05:00
|
|
|
|
|
|
|
old_logical_monitor = wayland_output->logical_monitor;
|
|
|
|
old_mode_flags = wayland_output->mode_flags;
|
|
|
|
old_scale = wayland_output->scale;
|
2016-12-13 09:08:17 -05:00
|
|
|
old_refresh_rate = wayland_output->refresh_rate;
|
2016-12-13 08:44:16 -05:00
|
|
|
|
2016-12-22 02:24:02 -05:00
|
|
|
monitor = pick_main_monitor (logical_monitor);
|
|
|
|
|
|
|
|
current_mode = meta_monitor_get_current_mode (monitor);
|
|
|
|
refresh_rate = meta_monitor_mode_get_refresh_rate (current_mode);
|
2016-05-16 14:28:14 -04:00
|
|
|
|
|
|
|
gboolean need_done = FALSE;
|
|
|
|
|
|
|
|
if (need_all_events ||
|
2016-11-25 01:31:38 -05:00
|
|
|
old_logical_monitor->rect.x != logical_monitor->rect.x ||
|
2018-11-07 04:13:24 -05:00
|
|
|
old_logical_monitor->rect.y != logical_monitor->rect.y ||
|
|
|
|
is_different_rotation (old_logical_monitor, logical_monitor))
|
2016-05-16 14:28:14 -04:00
|
|
|
{
|
2016-12-22 02:24:02 -05:00
|
|
|
int width_mm, height_mm;
|
|
|
|
const char *vendor;
|
|
|
|
const char *product;
|
|
|
|
uint32_t transform;
|
2016-12-22 02:16:48 -05:00
|
|
|
enum wl_output_subpixel subpixel_order;
|
|
|
|
|
2016-12-22 02:24:02 -05:00
|
|
|
/*
|
|
|
|
* While the wl_output carries information specific to a single monitor,
|
|
|
|
* it is actually referring to a region of the compositor's screen region
|
|
|
|
* (logical monitor), which may consist of multiple monitors (clones).
|
|
|
|
* Arbitrarily use whatever monitor is the first in the logical monitor
|
|
|
|
* and use that for these details.
|
|
|
|
*/
|
2018-11-07 04:13:24 -05:00
|
|
|
get_rotated_physical_dimensions (monitor, &width_mm, &height_mm);
|
2016-12-22 02:24:02 -05:00
|
|
|
vendor = meta_monitor_get_vendor (monitor);
|
|
|
|
product = meta_monitor_get_product (monitor);
|
|
|
|
|
2016-12-22 02:16:48 -05:00
|
|
|
subpixel_order = calculate_suitable_subpixel_order (logical_monitor);
|
|
|
|
|
2016-09-09 01:49:25 -04:00
|
|
|
/*
|
|
|
|
* TODO: When we support wl_surface.set_buffer_transform, pass along
|
|
|
|
* the correct transform here instead of always pretending its 'normal'.
|
|
|
|
* The reason for this is to try stopping clients from setting any buffer
|
|
|
|
* transform other than 'normal'.
|
|
|
|
*/
|
2016-12-22 02:24:02 -05:00
|
|
|
transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
|
|
|
|
2016-05-16 14:28:14 -04:00
|
|
|
wl_output_send_geometry (resource,
|
2016-11-25 01:31:38 -05:00
|
|
|
logical_monitor->rect.x,
|
|
|
|
logical_monitor->rect.y,
|
2016-12-22 02:24:02 -05:00
|
|
|
width_mm,
|
|
|
|
height_mm,
|
2016-12-22 02:16:48 -05:00
|
|
|
subpixel_order,
|
2016-12-22 02:24:02 -05:00
|
|
|
vendor,
|
|
|
|
product,
|
|
|
|
transform);
|
2016-05-16 14:28:14 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-22 02:24:02 -05:00
|
|
|
preferred_mode = meta_monitor_get_preferred_mode (monitor);
|
|
|
|
if (current_mode == preferred_mode)
|
2016-05-16 14:28:14 -04:00
|
|
|
mode_flags |= WL_OUTPUT_MODE_PREFERRED;
|
|
|
|
|
|
|
|
if (need_all_events ||
|
2016-11-25 01:31:38 -05:00
|
|
|
old_logical_monitor->rect.width != logical_monitor->rect.width ||
|
|
|
|
old_logical_monitor->rect.height != logical_monitor->rect.height ||
|
2016-12-13 09:08:17 -05:00
|
|
|
old_refresh_rate != refresh_rate ||
|
2016-05-16 14:28:14 -04:00
|
|
|
old_mode_flags != mode_flags)
|
|
|
|
{
|
|
|
|
wl_output_send_mode (resource,
|
|
|
|
mode_flags,
|
2016-11-25 01:31:38 -05:00
|
|
|
logical_monitor->rect.width,
|
|
|
|
logical_monitor->rect.height,
|
2016-12-13 09:08:17 -05:00
|
|
|
(int32_t) (refresh_rate * 1000));
|
2016-05-16 14:28:14 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION)
|
|
|
|
{
|
2016-12-22 02:24:02 -05:00
|
|
|
int scale;
|
|
|
|
|
2017-05-25 05:20:59 -04:00
|
|
|
scale = calculate_wayland_output_scale (logical_monitor);
|
2016-05-16 14:28:14 -04:00
|
|
|
if (need_all_events ||
|
2016-12-22 02:24:02 -05:00
|
|
|
old_scale != scale)
|
2016-05-16 14:28:14 -04:00
|
|
|
{
|
2016-12-22 02:24:02 -05:00
|
|
|
wl_output_send_scale (resource, scale);
|
2016-05-16 14:28:14 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
2017-09-05 12:53:41 -04:00
|
|
|
}
|
2016-05-16 14:28:14 -04:00
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
if (need_all_events && version >= WL_OUTPUT_DONE_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
wl_output_send_done (resource);
|
|
|
|
need_done = FALSE;
|
2016-05-16 14:28:14 -04:00
|
|
|
}
|
2017-09-05 12:53:41 -04:00
|
|
|
|
|
|
|
if (pending_done_event && need_done)
|
|
|
|
*pending_done_event = TRUE;
|
2016-05-16 14:28:14 -04:00
|
|
|
}
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
static void
|
|
|
|
bind_output (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
guint32 version,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output = data;
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor = wayland_output->logical_monitor;
|
2014-04-22 18:03:40 -04:00
|
|
|
struct wl_resource *resource;
|
2018-07-12 11:08:52 -04:00
|
|
|
#ifdef WITH_VERBOSE_MODE
|
2016-12-22 02:24:02 -05:00
|
|
|
MetaMonitor *monitor;
|
2018-07-12 11:08:52 -04:00
|
|
|
#endif
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2014-08-04 10:24:59 -04:00
|
|
|
resource = wl_resource_create (client, &wl_output_interface, version, id);
|
2014-04-22 18:03:40 -04:00
|
|
|
wayland_output->resources = g_list_prepend (wayland_output->resources, resource);
|
|
|
|
|
|
|
|
wl_resource_set_user_data (resource, wayland_output);
|
|
|
|
wl_resource_set_destructor (resource, output_resource_destroy);
|
|
|
|
|
2017-12-06 11:05:02 -05:00
|
|
|
if (!logical_monitor)
|
|
|
|
return;
|
|
|
|
|
2018-07-12 11:08:52 -04:00
|
|
|
#ifdef WITH_VERBOSE_MODE
|
2016-12-22 02:24:02 -05:00
|
|
|
monitor = pick_main_monitor (logical_monitor);
|
|
|
|
|
2015-03-30 21:12:04 -04:00
|
|
|
meta_verbose ("Binding monitor %p/%s (%u, %u, %u, %u) x %f\n",
|
2016-12-22 02:24:02 -05:00
|
|
|
logical_monitor,
|
|
|
|
meta_monitor_get_product (monitor),
|
2016-11-25 01:31:38 -05:00
|
|
|
logical_monitor->rect.x, logical_monitor->rect.y,
|
|
|
|
logical_monitor->rect.width, logical_monitor->rect.height,
|
2016-12-13 09:08:17 -05:00
|
|
|
wayland_output->refresh_rate);
|
2018-07-12 11:08:52 -04:00
|
|
|
#endif
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
send_output_events (resource, wayland_output, logical_monitor, TRUE, NULL);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wayland_output_destroy_notify (gpointer data)
|
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output = data;
|
|
|
|
|
wayland: Send wl_surface.enter and wl_surface.leave
Whenever a MetaSurfaceActor is painted, update the list of what outputs
the surface is being drawed upon. Since we do this on paint, we
effectively avoids this whenever the surface is not drawn, for example
being minimized, on a non-active workspace, or simply outside of the
damage region of a frame.
DND icons and cursors are not affected by this patch, since they are not
drawn as MetaSurfaceActors. If a MetaSurfaceActor or a parent is cloned,
then we'll check the position of the original actor again when the clone is
drawn, which is slightly expensive, but harmless. If the MetaShapedTexture
instead is cloned, as GNOME Shell does in many cases, then these clones
will not cause duplicate position checks.
https://bugzilla.gnome.org/show_bug.cgi?id=744453
2015-02-03 02:49:52 -05:00
|
|
|
g_signal_emit (wayland_output, signals[OUTPUT_DESTROYED], 0);
|
2015-04-17 05:17:46 -04:00
|
|
|
g_object_unref (wayland_output);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:28:14 -04:00
|
|
|
static void
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_wayland_output_set_logical_monitor (MetaWaylandOutput *wayland_output,
|
|
|
|
MetaLogicalMonitor *logical_monitor)
|
2014-07-10 17:39:47 -04:00
|
|
|
{
|
2016-12-22 02:24:02 -05:00
|
|
|
MetaMonitor *monitor;
|
|
|
|
MetaMonitorMode *current_mode;
|
|
|
|
MetaMonitorMode *preferred_mode;
|
2016-05-16 14:28:14 -04:00
|
|
|
|
2016-11-25 01:31:38 -05:00
|
|
|
wayland_output->logical_monitor = logical_monitor;
|
2016-05-16 14:28:14 -04:00
|
|
|
wayland_output->mode_flags = WL_OUTPUT_MODE_CURRENT;
|
2016-12-13 08:44:16 -05:00
|
|
|
|
2016-12-22 02:24:02 -05:00
|
|
|
monitor = pick_main_monitor (logical_monitor);
|
|
|
|
current_mode = meta_monitor_get_current_mode (monitor);
|
|
|
|
preferred_mode = meta_monitor_get_preferred_mode (monitor);
|
|
|
|
|
|
|
|
if (current_mode == preferred_mode)
|
2016-05-16 14:28:14 -04:00
|
|
|
wayland_output->mode_flags |= WL_OUTPUT_MODE_PREFERRED;
|
2017-05-25 05:20:59 -04:00
|
|
|
wayland_output->scale = calculate_wayland_output_scale (logical_monitor);
|
2016-12-22 02:24:02 -05:00
|
|
|
wayland_output->refresh_rate = meta_monitor_mode_get_refresh_rate (current_mode);
|
2018-10-17 10:55:18 -04:00
|
|
|
|
|
|
|
wayland_output->winsys_id = logical_monitor->winsys_id;
|
2014-07-10 17:39:47 -04:00
|
|
|
}
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
static void
|
2016-11-25 01:31:38 -05:00
|
|
|
wayland_output_update_for_output (MetaWaylandOutput *wayland_output,
|
|
|
|
MetaLogicalMonitor *logical_monitor)
|
2014-04-22 18:03:40 -04:00
|
|
|
{
|
|
|
|
GList *iter;
|
2017-09-05 12:53:41 -04:00
|
|
|
gboolean pending_done_event;
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
pending_done_event = FALSE;
|
2014-04-22 18:03:40 -04:00
|
|
|
for (iter = wayland_output->resources; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = iter->data;
|
2017-09-05 12:53:41 -04:00
|
|
|
send_output_events (resource, wayland_output, logical_monitor, FALSE, &pending_done_event);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
for (iter = wayland_output->xdg_output_resources; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *xdg_output = iter->data;
|
|
|
|
send_xdg_output_events (xdg_output, wayland_output, logical_monitor, FALSE, &pending_done_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the "done" events if needed */
|
|
|
|
if (pending_done_event)
|
|
|
|
{
|
|
|
|
for (iter = wayland_output->resources; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = iter->data;
|
|
|
|
if (wl_resource_get_version (resource) >= WL_OUTPUT_DONE_SINCE_VERSION)
|
|
|
|
wl_output_send_done (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (iter = wayland_output->xdg_output_resources; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *xdg_output = iter->data;
|
2019-07-25 08:12:46 -04:00
|
|
|
if (wl_resource_get_version (xdg_output) < NO_XDG_OUTPUT_DONE_SINCE_VERSION)
|
|
|
|
zxdg_output_v1_send_done (xdg_output);
|
2017-09-05 12:53:41 -04:00
|
|
|
}
|
|
|
|
}
|
2014-04-22 18:03:40 -04:00
|
|
|
/* It's very important that we change the output pointer here, as
|
|
|
|
the old structure is about to be freed by MetaMonitorManager */
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_wayland_output_set_logical_monitor (wayland_output, logical_monitor);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
2015-04-17 05:17:46 -04:00
|
|
|
static MetaWaylandOutput *
|
2016-05-16 14:28:14 -04:00
|
|
|
meta_wayland_output_new (MetaWaylandCompositor *compositor,
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor)
|
2015-04-17 05:17:46 -04:00
|
|
|
{
|
2017-08-18 02:16:22 -04:00
|
|
|
MetaWaylandCompositor *wayland_compositor =
|
|
|
|
meta_wayland_compositor_get_default ();
|
2015-04-17 05:17:46 -04:00
|
|
|
MetaWaylandOutput *wayland_output;
|
|
|
|
|
|
|
|
wayland_output = g_object_new (META_TYPE_WAYLAND_OUTPUT, NULL);
|
|
|
|
wayland_output->global = wl_global_create (compositor->wayland_display,
|
|
|
|
&wl_output_interface,
|
|
|
|
META_WL_OUTPUT_VERSION,
|
|
|
|
wayland_output, bind_output);
|
2017-08-18 02:16:22 -04:00
|
|
|
meta_wayland_compositor_flush_clients (wayland_compositor);
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_wayland_output_set_logical_monitor (wayland_output, logical_monitor);
|
2015-04-17 05:17:46 -04:00
|
|
|
|
|
|
|
return wayland_output;
|
|
|
|
}
|
|
|
|
|
2017-12-06 11:05:02 -05:00
|
|
|
static void
|
2018-07-27 12:32:31 -04:00
|
|
|
make_output_resources_inert (MetaWaylandOutput *wayland_output)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = wayland_output->resources; l; l = l->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *output_resource = l->data;
|
|
|
|
|
|
|
|
wl_resource_set_user_data (output_resource, NULL);
|
|
|
|
}
|
|
|
|
g_list_free (wayland_output->resources);
|
|
|
|
wayland_output->resources = NULL;
|
|
|
|
|
|
|
|
for (l = wayland_output->xdg_output_resources; l; l = l->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *xdg_output_resource = l->data;
|
|
|
|
|
|
|
|
wl_resource_set_user_data (xdg_output_resource, NULL);
|
|
|
|
}
|
|
|
|
g_list_free (wayland_output->xdg_output_resources);
|
|
|
|
wayland_output->xdg_output_resources = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
make_output_inert (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
2017-12-06 11:05:02 -05:00
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output = value;
|
2018-07-27 12:32:31 -04:00
|
|
|
|
2017-12-06 11:05:02 -05:00
|
|
|
wayland_output->logical_monitor = NULL;
|
2018-07-27 12:32:31 -04:00
|
|
|
make_output_resources_inert (wayland_output);
|
2017-12-06 11:05:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
delayed_destroy_outputs (gpointer data)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy (data);
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
static GHashTable *
|
|
|
|
meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
|
2016-12-02 03:00:03 -05:00
|
|
|
MetaMonitorManager *monitor_manager)
|
2014-04-22 18:03:40 -04:00
|
|
|
{
|
|
|
|
GHashTable *new_table;
|
2016-12-02 03:00:03 -05:00
|
|
|
GList *logical_monitors, *l;
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-12-02 03:00:03 -05:00
|
|
|
logical_monitors =
|
|
|
|
meta_monitor_manager_get_logical_monitors (monitor_manager);
|
2018-10-17 10:55:18 -04:00
|
|
|
new_table = g_hash_table_new_full (g_int64_hash, g_int64_equal, NULL,
|
2016-11-25 01:31:38 -05:00
|
|
|
wayland_output_destroy_notify);
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-12-02 03:00:03 -05:00
|
|
|
for (l = logical_monitors; l; l = l->next)
|
2014-04-22 18:03:40 -04:00
|
|
|
{
|
2016-12-02 03:00:03 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor = l->data;
|
2018-10-17 10:55:18 -04:00
|
|
|
MetaWaylandOutput *wayland_output = NULL;
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-11-25 01:31:38 -05:00
|
|
|
if (logical_monitor->winsys_id == 0)
|
2015-03-30 21:12:04 -04:00
|
|
|
continue;
|
2016-11-25 01:31:38 -05:00
|
|
|
|
2018-10-17 10:55:18 -04:00
|
|
|
wayland_output = g_hash_table_lookup (compositor->outputs,
|
|
|
|
&logical_monitor->winsys_id);
|
2014-04-22 18:03:40 -04:00
|
|
|
|
|
|
|
if (wayland_output)
|
|
|
|
{
|
2016-11-25 01:31:38 -05:00
|
|
|
g_hash_table_steal (compositor->outputs,
|
2018-10-17 10:55:18 -04:00
|
|
|
&logical_monitor->winsys_id);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
else
|
2016-11-25 01:31:38 -05:00
|
|
|
{
|
|
|
|
wayland_output = meta_wayland_output_new (compositor, logical_monitor);
|
|
|
|
}
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-11-25 01:31:38 -05:00
|
|
|
wayland_output_update_for_output (wayland_output, logical_monitor);
|
|
|
|
g_hash_table_insert (new_table,
|
2018-10-17 10:55:18 -04:00
|
|
|
&wayland_output->winsys_id,
|
2016-11-25 01:31:38 -05:00
|
|
|
wayland_output);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
2018-07-27 12:32:31 -04:00
|
|
|
g_hash_table_foreach (compositor->outputs, make_output_inert, NULL);
|
2017-12-06 11:05:02 -05:00
|
|
|
g_timeout_add_seconds (10, delayed_destroy_outputs, compositor->outputs);
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
return new_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_monitors_changed (MetaMonitorManager *monitors,
|
|
|
|
MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
compositor->outputs = meta_wayland_compositor_update_outputs (compositor, monitors);
|
|
|
|
}
|
|
|
|
|
2015-04-17 05:17:46 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_output_init (MetaWaylandOutput *wayland_output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_output_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output = META_WAYLAND_OUTPUT (object);
|
|
|
|
|
|
|
|
wl_global_destroy (wayland_output->global);
|
2015-07-01 01:18:45 -04:00
|
|
|
|
|
|
|
/* Make sure the wl_output destructor doesn't try to access MetaWaylandOutput
|
|
|
|
* after we have freed it.
|
|
|
|
*/
|
2018-07-27 12:32:31 -04:00
|
|
|
make_output_resources_inert (wayland_output);
|
2017-09-05 12:53:41 -04:00
|
|
|
|
2015-04-17 05:17:46 -04:00
|
|
|
G_OBJECT_CLASS (meta_wayland_output_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_output_class_init (MetaWaylandOutputClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_wayland_output_finalize;
|
wayland: Send wl_surface.enter and wl_surface.leave
Whenever a MetaSurfaceActor is painted, update the list of what outputs
the surface is being drawed upon. Since we do this on paint, we
effectively avoids this whenever the surface is not drawn, for example
being minimized, on a non-active workspace, or simply outside of the
damage region of a frame.
DND icons and cursors are not affected by this patch, since they are not
drawn as MetaSurfaceActors. If a MetaSurfaceActor or a parent is cloned,
then we'll check the position of the original actor again when the clone is
drawn, which is slightly expensive, but harmless. If the MetaShapedTexture
instead is cloned, as GNOME Shell does in many cases, then these clones
will not cause duplicate position checks.
https://bugzilla.gnome.org/show_bug.cgi?id=744453
2015-02-03 02:49:52 -05:00
|
|
|
|
|
|
|
signals[OUTPUT_DESTROYED] = g_signal_new ("output-destroyed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2015-04-17 05:17:46 -04:00
|
|
|
}
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
static void
|
|
|
|
meta_xdg_output_destructor (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandOutput *wayland_output;
|
|
|
|
|
|
|
|
wayland_output = wl_resource_get_user_data (resource);
|
|
|
|
if (!wayland_output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wayland_output->xdg_output_resources =
|
|
|
|
g_list_remove (wayland_output->xdg_output_resources, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_xdg_output_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_output_v1_interface
|
|
|
|
meta_xdg_output_interface = {
|
|
|
|
meta_xdg_output_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_xdg_output_events (struct wl_resource *resource,
|
|
|
|
MetaWaylandOutput *wayland_output,
|
|
|
|
MetaLogicalMonitor *logical_monitor,
|
|
|
|
gboolean need_all_events,
|
|
|
|
gboolean *pending_done_event)
|
|
|
|
{
|
|
|
|
MetaRectangle new_layout;
|
|
|
|
MetaRectangle old_layout;
|
|
|
|
MetaLogicalMonitor *old_logical_monitor;
|
2019-06-26 05:42:29 -04:00
|
|
|
MetaMonitor *monitor;
|
2017-09-05 12:53:41 -04:00
|
|
|
gboolean need_done;
|
2019-06-26 05:42:29 -04:00
|
|
|
int version;
|
2017-09-05 12:53:41 -04:00
|
|
|
|
|
|
|
need_done = FALSE;
|
|
|
|
old_logical_monitor = wayland_output->logical_monitor;
|
|
|
|
old_layout = meta_logical_monitor_get_layout (old_logical_monitor);
|
|
|
|
new_layout = meta_logical_monitor_get_layout (logical_monitor);
|
|
|
|
|
|
|
|
if (need_all_events ||
|
|
|
|
old_layout.x != new_layout.x ||
|
|
|
|
old_layout.y != new_layout.y)
|
|
|
|
{
|
|
|
|
zxdg_output_v1_send_logical_position (resource,
|
|
|
|
new_layout.x,
|
|
|
|
new_layout.y);
|
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_all_events ||
|
|
|
|
old_layout.width != new_layout.width ||
|
|
|
|
old_layout.height != new_layout.height)
|
|
|
|
{
|
2018-01-15 04:41:01 -05:00
|
|
|
zxdg_output_v1_send_logical_size (resource,
|
|
|
|
new_layout.width,
|
|
|
|
new_layout.height);
|
2017-09-05 12:53:41 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-06-26 05:42:29 -04:00
|
|
|
version = wl_resource_get_version (resource);
|
|
|
|
monitor = pick_main_monitor (logical_monitor);
|
|
|
|
|
|
|
|
if (need_all_events && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = meta_monitor_get_connector (monitor);
|
|
|
|
zxdg_output_v1_send_name (resource, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_all_events && version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
const char *description;
|
|
|
|
|
|
|
|
description = meta_monitor_get_display_name (monitor);
|
|
|
|
zxdg_output_v1_send_description (resource, description);
|
|
|
|
}
|
|
|
|
|
2019-07-25 08:12:46 -04:00
|
|
|
if (need_all_events && version < NO_XDG_OUTPUT_DONE_SINCE_VERSION)
|
2017-09-05 12:53:41 -04:00
|
|
|
{
|
|
|
|
zxdg_output_v1_send_done (resource);
|
|
|
|
need_done = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pending_done_event && need_done)
|
|
|
|
*pending_done_event = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_xdg_output_manager_get_xdg_output (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource *output)
|
|
|
|
{
|
|
|
|
struct wl_resource *xdg_output_resource;
|
|
|
|
MetaWaylandOutput *wayland_output;
|
|
|
|
|
|
|
|
xdg_output_resource = wl_resource_create (client,
|
|
|
|
&zxdg_output_v1_interface,
|
|
|
|
wl_resource_get_version (resource),
|
|
|
|
id);
|
|
|
|
|
|
|
|
wayland_output = wl_resource_get_user_data (output);
|
|
|
|
if (!wayland_output)
|
|
|
|
return;
|
|
|
|
|
2019-04-15 08:55:45 -04:00
|
|
|
wl_resource_set_implementation (xdg_output_resource,
|
|
|
|
&meta_xdg_output_interface,
|
|
|
|
wayland_output, meta_xdg_output_destructor);
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
wayland_output->xdg_output_resources =
|
|
|
|
g_list_prepend (wayland_output->xdg_output_resources, xdg_output_resource);
|
|
|
|
|
2018-09-25 07:50:09 -04:00
|
|
|
if (!wayland_output->logical_monitor)
|
|
|
|
return;
|
|
|
|
|
2017-09-05 12:53:41 -04:00
|
|
|
send_xdg_output_events (xdg_output_resource,
|
|
|
|
wayland_output,
|
|
|
|
wayland_output->logical_monitor,
|
|
|
|
TRUE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_xdg_output_manager_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_output_manager_v1_interface
|
|
|
|
meta_xdg_output_manager_interface = {
|
|
|
|
meta_xdg_output_manager_destroy,
|
|
|
|
meta_xdg_output_manager_get_xdg_output,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_xdg_output_manager (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_resource_create (client,
|
|
|
|
&zxdg_output_manager_v1_interface,
|
|
|
|
version, id);
|
|
|
|
|
|
|
|
wl_resource_set_implementation (resource,
|
|
|
|
&meta_xdg_output_manager_interface,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
void
|
|
|
|
meta_wayland_outputs_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *monitors;
|
|
|
|
|
|
|
|
monitors = meta_monitor_manager_get ();
|
2017-10-12 20:14:40 -04:00
|
|
|
g_signal_connect (monitors, "monitors-changed-internal",
|
2014-04-22 18:03:40 -04:00
|
|
|
G_CALLBACK (on_monitors_changed), compositor);
|
|
|
|
|
2018-10-17 10:55:18 -04:00
|
|
|
compositor->outputs = g_hash_table_new_full (g_int64_hash, g_int64_equal, NULL,
|
|
|
|
wayland_output_destroy_notify);
|
2014-04-22 18:03:40 -04:00
|
|
|
compositor->outputs = meta_wayland_compositor_update_outputs (compositor, monitors);
|
2017-09-05 12:53:41 -04:00
|
|
|
|
|
|
|
wl_global_create (compositor->wayland_display,
|
|
|
|
&zxdg_output_manager_v1_interface,
|
|
|
|
META_ZXDG_OUTPUT_V1_VERSION,
|
|
|
|
NULL,
|
|
|
|
bind_xdg_output_manager);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|