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"
|
|
|
|
|
|
|
|
#include "meta-wayland-outputs.h"
|
|
|
|
|
|
|
|
#include "meta-wayland-private.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2015-01-30 08:51:18 -05:00
|
|
|
#include "meta-monitor-manager-private.h"
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2014-04-26 04:27:34 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
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
|
|
|
enum {
|
|
|
|
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)
|
|
|
|
|
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-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,
|
2016-05-16 14:28:14 -04:00
|
|
|
gboolean need_all_events)
|
|
|
|
{
|
|
|
|
int version = wl_resource_get_version (resource);
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaOutput *output = logical_monitor->outputs[0];
|
2016-05-16 14:28:14 -04:00
|
|
|
guint mode_flags = WL_OUTPUT_MODE_CURRENT;
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaLogicalMonitor *old_logical_monitor = wayland_output->logical_monitor;
|
2016-05-16 14:28:14 -04:00
|
|
|
guint old_mode_flags = wayland_output->mode_flags;
|
|
|
|
gint old_scale = wayland_output->scale;
|
|
|
|
|
|
|
|
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 ||
|
|
|
|
old_logical_monitor->rect.y != logical_monitor->rect.y)
|
2016-05-16 14:28:14 -04:00
|
|
|
{
|
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-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,
|
|
|
|
logical_monitor->width_mm,
|
|
|
|
logical_monitor->height_mm,
|
2016-05-16 14:28:14 -04:00
|
|
|
output->subpixel_order,
|
|
|
|
output->vendor,
|
|
|
|
output->product,
|
2016-09-09 01:49:25 -04:00
|
|
|
WL_OUTPUT_TRANSFORM_NORMAL);
|
2016-05-16 14:28:14 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output->crtc->current_mode == output->preferred_mode)
|
|
|
|
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 ||
|
|
|
|
old_logical_monitor->refresh_rate != logical_monitor->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,
|
|
|
|
(int32_t) (logical_monitor->refresh_rate * 1000));
|
2016-05-16 14:28:14 -04:00
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION)
|
|
|
|
{
|
|
|
|
if (need_all_events ||
|
|
|
|
old_scale != output->scale)
|
|
|
|
{
|
|
|
|
wl_output_send_scale (resource, output->scale);
|
|
|
|
need_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_done)
|
|
|
|
wl_output_send_done (resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2016-11-25 01:31:38 -05:00
|
|
|
MetaOutput *output = logical_monitor->outputs[0];
|
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);
|
|
|
|
|
2015-03-30 21:12:04 -04:00
|
|
|
meta_verbose ("Binding monitor %p/%s (%u, %u, %u, %u) x %f\n",
|
2016-11-25 01:31:38 -05:00
|
|
|
logical_monitor, output->name,
|
|
|
|
logical_monitor->rect.x, logical_monitor->rect.y,
|
|
|
|
logical_monitor->rect.width, logical_monitor->rect.height,
|
|
|
|
logical_monitor->refresh_rate);
|
2014-04-22 18:03:40 -04:00
|
|
|
|
2016-11-25 01:31:38 -05:00
|
|
|
send_output_events (resource, wayland_output, logical_monitor, TRUE);
|
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-11-25 01:31:38 -05:00
|
|
|
MetaOutput *output = logical_monitor->outputs[0];
|
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;
|
|
|
|
if (output->crtc->current_mode == output->preferred_mode)
|
|
|
|
wayland_output->mode_flags |= WL_OUTPUT_MODE_PREFERRED;
|
|
|
|
wayland_output->scale = output->scale;
|
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;
|
|
|
|
|
|
|
|
for (iter = wayland_output->resources; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = iter->data;
|
2016-11-25 01:31:38 -05:00
|
|
|
send_output_events (resource, wayland_output, logical_monitor, FALSE);
|
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
|
|
|
{
|
|
|
|
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);
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
2016-11-25 01:31:38 -05:00
|
|
|
new_table = g_hash_table_new_full (NULL, NULL, NULL,
|
|
|
|
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;
|
2014-04-22 18:03:40 -04:00
|
|
|
MetaWaylandOutput *wayland_output;
|
|
|
|
|
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
|
|
|
|
|
|
|
wayland_output =
|
|
|
|
g_hash_table_lookup (compositor->outputs,
|
|
|
|
GSIZE_TO_POINTER (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,
|
|
|
|
GSIZE_TO_POINTER (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,
|
|
|
|
GSIZE_TO_POINTER (logical_monitor->winsys_id),
|
|
|
|
wayland_output);
|
2014-04-22 18:03:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_destroy (compositor->outputs);
|
|
|
|
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);
|
2015-07-01 01:18:45 -04:00
|
|
|
GList *l;
|
2015-04-17 05:17:46 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
2014-04-22 18:03:40 -04:00
|
|
|
void
|
|
|
|
meta_wayland_outputs_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *monitors;
|
|
|
|
|
|
|
|
monitors = meta_monitor_manager_get ();
|
|
|
|
g_signal_connect (monitors, "monitors-changed",
|
|
|
|
G_CALLBACK (on_monitors_changed), compositor);
|
|
|
|
|
|
|
|
compositor->outputs = g_hash_table_new_full (NULL, NULL, NULL, wayland_output_destroy_notify);
|
|
|
|
compositor->outputs = meta_wayland_compositor_update_outputs (compositor, monitors);
|
|
|
|
}
|