2018-10-09 13:35:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/meta-screen-cast-window-stream.h"
|
|
|
|
|
|
|
|
#include "backends/meta-logical-monitor.h"
|
|
|
|
#include "backends/meta-monitor-manager-private.h"
|
2022-05-27 18:30:37 +00:00
|
|
|
#include "backends/meta-screen-cast-session.h"
|
2018-10-09 13:35:14 +00:00
|
|
|
#include "backends/meta-screen-cast-window.h"
|
|
|
|
#include "backends/meta-screen-cast-window-stream-src.h"
|
|
|
|
#include "compositor/meta-window-actor-private.h"
|
|
|
|
#include "core/window-private.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_WINDOW,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaScreenCastWindowStream
|
|
|
|
{
|
|
|
|
MetaScreenCastStream parent;
|
|
|
|
|
|
|
|
MetaWindow *window;
|
|
|
|
|
|
|
|
int stream_width;
|
|
|
|
int stream_height;
|
2019-01-21 18:17:57 +00:00
|
|
|
int logical_width;
|
|
|
|
int logical_height;
|
2018-10-09 13:35:14 +00:00
|
|
|
|
|
|
|
unsigned long window_unmanaged_handler_id;
|
|
|
|
};
|
|
|
|
|
2019-01-21 18:16:19 +00:00
|
|
|
static GInitableIface *initable_parent_iface;
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_init_initable_iface (GInitableIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaScreenCastWindowStream,
|
|
|
|
meta_screen_cast_window_stream,
|
|
|
|
META_TYPE_SCREEN_CAST_STREAM,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
|
|
|
meta_screen_cast_window_stream_init_initable_iface))
|
2018-10-09 13:35:14 +00:00
|
|
|
|
|
|
|
MetaWindow *
|
|
|
|
meta_screen_cast_window_stream_get_window (MetaScreenCastWindowStream *window_stream)
|
|
|
|
{
|
|
|
|
return window_stream->window;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
meta_screen_cast_window_stream_get_width (MetaScreenCastWindowStream *window_stream)
|
|
|
|
{
|
|
|
|
return window_stream->stream_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
meta_screen_cast_window_stream_get_height (MetaScreenCastWindowStream *window_stream)
|
|
|
|
{
|
|
|
|
return window_stream->stream_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaScreenCastWindowStream *
|
2019-01-24 17:43:27 +00:00
|
|
|
meta_screen_cast_window_stream_new (MetaScreenCastSession *session,
|
|
|
|
GDBusConnection *connection,
|
|
|
|
MetaWindow *window,
|
|
|
|
MetaScreenCastCursorMode cursor_mode,
|
2020-04-21 14:54:54 +00:00
|
|
|
MetaScreenCastFlag flags,
|
2019-01-24 17:43:27 +00:00
|
|
|
GError **error)
|
2018-10-09 13:35:14 +00:00
|
|
|
{
|
2019-01-21 18:16:19 +00:00
|
|
|
return g_initable_new (META_TYPE_SCREEN_CAST_WINDOW_STREAM,
|
|
|
|
NULL,
|
|
|
|
error,
|
|
|
|
"session", session,
|
|
|
|
"connection", connection,
|
2019-01-24 17:43:27 +00:00
|
|
|
"cursor-mode", cursor_mode,
|
2020-04-21 14:54:54 +00:00
|
|
|
"flags", flags,
|
2019-01-21 18:16:19 +00:00
|
|
|
"window", window,
|
|
|
|
NULL);
|
2018-10-09 13:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaScreenCastStreamSrc *
|
|
|
|
meta_screen_cast_window_stream_create_src (MetaScreenCastStream *stream,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (stream);
|
|
|
|
MetaScreenCastWindowStreamSrc *window_stream_src;
|
|
|
|
|
|
|
|
window_stream_src = meta_screen_cast_window_stream_src_new (window_stream,
|
|
|
|
error);
|
|
|
|
if (!window_stream_src)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return META_SCREEN_CAST_STREAM_SRC (window_stream_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_set_parameters (MetaScreenCastStream *stream,
|
|
|
|
GVariantBuilder *parameters_builder)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (stream);
|
|
|
|
|
|
|
|
g_variant_builder_add (parameters_builder, "{sv}",
|
|
|
|
"size",
|
|
|
|
g_variant_new ("(ii)",
|
2019-01-21 18:17:57 +00:00
|
|
|
window_stream->logical_width,
|
|
|
|
window_stream->logical_height));
|
2018-10-09 13:35:14 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 22:52:00 +00:00
|
|
|
static gboolean
|
2018-10-09 13:35:14 +00:00
|
|
|
meta_screen_cast_window_stream_transform_position (MetaScreenCastStream *stream,
|
|
|
|
double stream_x,
|
|
|
|
double stream_y,
|
|
|
|
double *x,
|
|
|
|
double *y)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (stream);
|
|
|
|
MetaScreenCastWindow *screen_cast_window =
|
|
|
|
META_SCREEN_CAST_WINDOW (meta_window_actor_from_window (window_stream->window));
|
|
|
|
|
|
|
|
meta_screen_cast_window_transform_relative_position (screen_cast_window,
|
|
|
|
stream_x,
|
|
|
|
stream_y,
|
|
|
|
x,
|
|
|
|
y);
|
2021-01-30 22:52:00 +00:00
|
|
|
return TRUE;
|
2018-10-09 13:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_window_unmanaged (MetaScreenCastWindowStream *window_stream)
|
|
|
|
{
|
|
|
|
meta_screen_cast_stream_close (META_SCREEN_CAST_STREAM (window_stream));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_WINDOW:
|
|
|
|
window_stream->window = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_WINDOW:
|
|
|
|
g_value_set_object (value, window_stream->window);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (object);
|
2023-02-11 06:03:27 +00:00
|
|
|
MetaWindowActor *window_actor;
|
|
|
|
|
|
|
|
window_actor = meta_window_actor_from_window (window_stream->window);
|
|
|
|
if (window_actor)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindow *screen_cast_window;
|
|
|
|
|
|
|
|
screen_cast_window = META_SCREEN_CAST_WINDOW (window_actor);
|
|
|
|
meta_screen_cast_window_dec_usage (screen_cast_window);
|
|
|
|
}
|
2018-10-09 13:35:14 +00:00
|
|
|
|
2019-11-16 00:25:52 +00:00
|
|
|
g_clear_signal_handler (&window_stream->window_unmanaged_handler_id,
|
|
|
|
window_stream->window);
|
2018-10-09 13:35:14 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_screen_cast_window_stream_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-01-21 18:16:19 +00:00
|
|
|
static gboolean
|
|
|
|
meta_screen_cast_window_stream_initable_init (GInitable *initable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaScreenCastWindowStream *window_stream =
|
|
|
|
META_SCREEN_CAST_WINDOW_STREAM (initable);
|
2022-05-27 18:30:37 +00:00
|
|
|
MetaScreenCastStream *stream = META_SCREEN_CAST_STREAM (initable);
|
|
|
|
MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
|
|
|
|
MetaScreenCast *screen_cast =
|
|
|
|
meta_screen_cast_session_get_screen_cast (session);
|
|
|
|
MetaBackend *backend = meta_screen_cast_get_backend (screen_cast);
|
2019-01-21 18:16:19 +00:00
|
|
|
MetaWindow *window = window_stream->window;
|
2023-02-11 06:03:27 +00:00
|
|
|
MetaScreenCastWindow *screen_cast_window =
|
|
|
|
META_SCREEN_CAST_WINDOW (meta_window_actor_from_window (window));
|
2019-01-21 18:16:19 +00:00
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
int scale;
|
|
|
|
|
|
|
|
logical_monitor = meta_window_get_main_logical_monitor (window);
|
|
|
|
if (!logical_monitor)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Main logical monitor not found");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_stream->window_unmanaged_handler_id =
|
|
|
|
g_signal_connect_swapped (window, "unmanaged",
|
|
|
|
G_CALLBACK (on_window_unmanaged),
|
|
|
|
window_stream);
|
|
|
|
|
2022-05-27 18:30:37 +00:00
|
|
|
if (meta_backend_is_stage_views_scaled (backend))
|
2019-12-16 18:00:19 +00:00
|
|
|
scale = (int) ceilf (meta_logical_monitor_get_scale (logical_monitor));
|
|
|
|
else
|
|
|
|
scale = 1;
|
|
|
|
|
2019-01-21 18:16:19 +00:00
|
|
|
/* We cannot set the stream size to the exact size of the window, because
|
|
|
|
* windows can be resized, whereas streams cannot.
|
|
|
|
* So we set a size equals to the size of the logical monitor for the window.
|
|
|
|
*/
|
2019-01-21 18:17:57 +00:00
|
|
|
window_stream->logical_width = logical_monitor->rect.width;
|
|
|
|
window_stream->logical_height = logical_monitor->rect.height;
|
2019-01-21 18:16:19 +00:00
|
|
|
window_stream->stream_width = logical_monitor->rect.width * scale;
|
|
|
|
window_stream->stream_height = logical_monitor->rect.height * scale;
|
|
|
|
|
2023-02-11 06:03:27 +00:00
|
|
|
meta_screen_cast_window_inc_usage (screen_cast_window);
|
|
|
|
|
2019-01-21 18:16:19 +00:00
|
|
|
return initable_parent_iface->init (initable, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_init_initable_iface (GInitableIface *iface)
|
|
|
|
{
|
|
|
|
initable_parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->init = meta_screen_cast_window_stream_initable_init;
|
|
|
|
}
|
|
|
|
|
2018-10-09 13:35:14 +00:00
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_init (MetaScreenCastWindowStream *window_stream)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_window_stream_class_init (MetaScreenCastWindowStreamClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
MetaScreenCastStreamClass *stream_class =
|
|
|
|
META_SCREEN_CAST_STREAM_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = meta_screen_cast_window_stream_set_property;
|
|
|
|
object_class->get_property = meta_screen_cast_window_stream_get_property;
|
|
|
|
object_class->finalize = meta_screen_cast_window_stream_finalize;
|
|
|
|
|
|
|
|
stream_class->create_src = meta_screen_cast_window_stream_create_src;
|
|
|
|
stream_class->set_parameters = meta_screen_cast_window_stream_set_parameters;
|
|
|
|
stream_class->transform_position = meta_screen_cast_window_stream_transform_position;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_WINDOW,
|
|
|
|
g_param_spec_object ("window",
|
|
|
|
"window",
|
|
|
|
"MetaWindow",
|
|
|
|
META_TYPE_WINDOW,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|