2023-06-02 17:01:16 +00:00
|
|
|
/*
|
|
|
|
* mks-display.c
|
2023-02-14 05:53:57 +00:00
|
|
|
*
|
|
|
|
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
|
|
|
*
|
2023-06-02 17:01:16 +00:00
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
* License, or (at your option) any later version.
|
2023-02-14 05:53:57 +00:00
|
|
|
*
|
2023-06-02 17:01:16 +00:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2023-02-14 05:53:57 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2023-06-01 11:04:35 +00:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
2023-02-14 05:53:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-02-14 21:34:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-02-14 19:18:48 +00:00
|
|
|
#include "mks-css-private.h"
|
2023-02-14 05:53:57 +00:00
|
|
|
#include "mks-display.h"
|
2023-02-17 19:40:34 +00:00
|
|
|
#include "mks-display-picture-private.h"
|
2023-02-17 23:34:36 +00:00
|
|
|
#include "mks-inhibitor-private.h"
|
2023-02-14 21:34:45 +00:00
|
|
|
#include "mks-keyboard.h"
|
|
|
|
#include "mks-mouse.h"
|
2023-02-15 20:02:03 +00:00
|
|
|
#include "mks-paintable-private.h"
|
2023-02-14 05:53:57 +00:00
|
|
|
#include "mks-screen.h"
|
2023-05-08 14:37:49 +00:00
|
|
|
#include "mks-screen-attributes.h"
|
|
|
|
#include "mks-screen-resizer-private.h"
|
2023-02-28 04:23:25 +00:00
|
|
|
#include "mks-util-private.h"
|
2023-02-14 21:34:45 +00:00
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
#define DEFAULT_UNGRAB_TRIGGER "<Control><Alt>g"
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2023-02-17 23:50:02 +00:00
|
|
|
MksScreen *screen;
|
2023-05-08 14:37:49 +00:00
|
|
|
MksScreenResizer *resizer;
|
2023-02-17 23:50:02 +00:00
|
|
|
MksDisplayPicture *picture;
|
|
|
|
MksInhibitor *inhibitor;
|
2023-11-14 13:13:54 +00:00
|
|
|
GtkWidget *offload;
|
2023-02-17 23:50:02 +00:00
|
|
|
GtkShortcutTrigger *ungrab_trigger;
|
2023-05-25 09:12:37 +00:00
|
|
|
guint auto_resize : 1;
|
2023-02-14 05:53:57 +00:00
|
|
|
} MksDisplayPrivate;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_SCREEN,
|
2023-02-17 23:50:02 +00:00
|
|
|
PROP_UNGRAB_TRIGGER,
|
2023-05-25 09:12:37 +00:00
|
|
|
PROP_AUTO_RESIZE,
|
2023-02-14 05:53:57 +00:00
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MksDisplay, mks_display, GTK_TYPE_WIDGET)
|
|
|
|
|
|
|
|
static GParamSpec *properties [N_PROPS];
|
|
|
|
|
2023-02-15 14:47:10 +00:00
|
|
|
static void
|
|
|
|
mks_display_get_paintable_area (MksDisplay *self,
|
|
|
|
graphene_rect_t *area)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
2023-02-17 19:40:34 +00:00
|
|
|
MksPaintable *paintable;
|
2023-02-15 14:47:10 +00:00
|
|
|
int x, y, width, height;
|
|
|
|
double display_ratio;
|
|
|
|
double ratio;
|
|
|
|
double w, h;
|
|
|
|
|
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
|
|
|
g_assert (area != NULL);
|
|
|
|
|
|
|
|
width = gtk_widget_get_width (GTK_WIDGET (self));
|
|
|
|
height = gtk_widget_get_height (GTK_WIDGET (self));
|
|
|
|
display_ratio = (double)width / (double)height;
|
2023-02-17 19:40:34 +00:00
|
|
|
|
|
|
|
if ((paintable = mks_display_picture_get_paintable (priv->picture)))
|
|
|
|
ratio = gdk_paintable_get_intrinsic_aspect_ratio (GDK_PAINTABLE (paintable));
|
|
|
|
else
|
|
|
|
ratio = 1.;
|
2023-02-15 14:47:10 +00:00
|
|
|
|
|
|
|
if (ratio > display_ratio)
|
|
|
|
{
|
|
|
|
w = width;
|
|
|
|
h = width / ratio;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = height * ratio;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = (width - ceil (w)) / 2;
|
|
|
|
y = floor(height - ceil (h)) / 2;
|
|
|
|
|
|
|
|
*area = GRAPHENE_RECT_INIT (x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
static void
|
|
|
|
mks_display_attach_cb (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_autoptr(MksDisplay) self = user_data;
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
MksScreen *screen = (MksScreen *)object;
|
|
|
|
g_autoptr(GdkPaintable) paintable = NULL;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_ENTRY;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_assert (MKS_IS_SCREEN (screen));
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
|
|
|
|
|
|
|
paintable = mks_screen_attach_finish (screen, result, &error);
|
|
|
|
|
|
|
|
if (priv->screen != screen)
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
mks_display_picture_set_paintable (priv->picture, MKS_PAINTABLE (paintable));
|
2023-02-28 04:23:25 +00:00
|
|
|
|
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_connect (MksDisplay *self,
|
|
|
|
MksScreen *screen)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_ENTRY;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
2023-02-17 19:40:34 +00:00
|
|
|
g_assert (!screen || MKS_IS_SCREEN (screen));
|
|
|
|
|
|
|
|
if (g_set_object (&priv->screen, screen))
|
|
|
|
{
|
|
|
|
mks_display_picture_set_keyboard (priv->picture, mks_screen_get_keyboard (screen));
|
|
|
|
mks_display_picture_set_mouse (priv->picture, mks_screen_get_mouse (screen));
|
2023-06-15 11:48:55 +00:00
|
|
|
mks_display_picture_set_touchable (priv->picture, mks_screen_get_touchable (screen));
|
2023-05-08 14:37:49 +00:00
|
|
|
mks_screen_resizer_set_screen (priv->resizer, screen);
|
2023-02-14 05:53:57 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
mks_screen_attach (screen,
|
2023-10-02 14:51:17 +00:00
|
|
|
gtk_widget_get_display (GTK_WIDGET (self)),
|
2023-02-17 19:40:34 +00:00
|
|
|
NULL,
|
|
|
|
mks_display_attach_cb,
|
|
|
|
g_object_ref (self));
|
2023-02-14 05:53:57 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SCREEN]);
|
|
|
|
}
|
2023-02-28 04:23:25 +00:00
|
|
|
|
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_disconnect (MksDisplay *self)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_ENTRY;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
2023-02-15 14:47:10 +00:00
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_clear_object (&priv->screen);
|
2023-05-08 14:37:49 +00:00
|
|
|
mks_screen_resizer_set_screen (priv->resizer, NULL);
|
2023-02-17 23:38:06 +00:00
|
|
|
g_clear_object (&priv->inhibitor);
|
2023-02-17 19:40:34 +00:00
|
|
|
|
|
|
|
if (priv->picture != NULL)
|
|
|
|
{
|
|
|
|
mks_display_picture_set_paintable (priv->picture, NULL);
|
|
|
|
mks_display_picture_set_keyboard (priv->picture, NULL);
|
|
|
|
mks_display_picture_set_mouse (priv->picture, NULL);
|
2023-06-15 11:48:55 +00:00
|
|
|
mks_display_picture_set_touchable (priv->picture, NULL);
|
2023-02-17 19:40:34 +00:00
|
|
|
}
|
2023-02-28 04:23:25 +00:00
|
|
|
|
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 23:34:36 +00:00
|
|
|
static gboolean
|
|
|
|
mks_display_legacy_event_cb (MksDisplay *self,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkEventControllerLegacy *legacy)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
GdkEventType event_type;
|
|
|
|
|
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
|
|
|
g_assert (GTK_IS_EVENT_CONTROLLER_LEGACY (legacy));
|
|
|
|
|
|
|
|
event_type = gdk_event_get_event_type (event);
|
|
|
|
|
|
|
|
if (priv->screen == NULL)
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
2023-04-13 13:04:40 +00:00
|
|
|
if (event_type == GDK_BUTTON_PRESS)
|
2023-02-17 23:34:36 +00:00
|
|
|
{
|
|
|
|
if (priv->inhibitor == NULL)
|
2023-02-18 00:30:46 +00:00
|
|
|
{
|
|
|
|
/* Don't allow click to pass through or the user may get
|
|
|
|
* a dialog in their face while something in the guest
|
|
|
|
* is grabbed.
|
|
|
|
*/
|
|
|
|
priv->inhibitor = mks_inhibitor_new (GTK_WIDGET (priv->picture), event);
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
2023-02-17 23:34:36 +00:00
|
|
|
}
|
2023-02-17 23:50:02 +00:00
|
|
|
else if (event_type == GDK_KEY_PRESS)
|
|
|
|
{
|
|
|
|
GdkKeyMatch match;
|
|
|
|
|
|
|
|
match = gtk_shortcut_trigger_trigger (priv->ungrab_trigger, event, FALSE);
|
|
|
|
|
|
|
|
if (match == GDK_KEY_MATCH_EXACT)
|
|
|
|
{
|
|
|
|
if (priv->inhibitor != NULL)
|
|
|
|
{
|
|
|
|
mks_inhibitor_uninhibit (priv->inhibitor);
|
|
|
|
g_clear_object (&priv->inhibitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
}
|
2023-02-17 23:34:36 +00:00
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
static void
|
|
|
|
mks_display_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MksDisplay *self = (MksDisplay *)object;
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
mks_display_disconnect (self);
|
|
|
|
|
2023-11-14 13:13:54 +00:00
|
|
|
g_clear_pointer (&priv->offload, gtk_widget_unparent);
|
2023-05-08 14:37:49 +00:00
|
|
|
g_clear_object (&priv->resizer);
|
2023-02-14 05:53:57 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (mks_display_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2023-04-03 20:17:31 +00:00
|
|
|
static gboolean
|
|
|
|
mks_display_grab_focus (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
MksDisplay *self = (MksDisplay *)widget;
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
|
|
|
return gtk_widget_grab_focus (GTK_WIDGET (priv->picture));
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:47:10 +00:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
mks_display_get_request_mode (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
2023-02-17 19:40:34 +00:00
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
2023-02-15 14:47:10 +00:00
|
|
|
{
|
|
|
|
MksDisplay *self = (MksDisplay *)widget;
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
|
|
|
|
2023-11-14 13:13:54 +00:00
|
|
|
gtk_widget_measure (priv->offload, orientation, for_size,
|
2023-02-17 19:40:34 +00:00
|
|
|
minimum, natural, minimum_baseline, natural_baseline);
|
|
|
|
}
|
2023-02-15 14:47:10 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
static void
|
|
|
|
mks_display_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
|
|
|
{
|
|
|
|
MksDisplay *self = (MksDisplay *)widget;
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
graphene_rect_t area;
|
2023-05-08 14:37:49 +00:00
|
|
|
MksScreenAttributes *attributes;
|
2023-02-15 14:47:10 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
g_assert (MKS_IS_DISPLAY (self));
|
2023-02-15 18:38:24 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
GTK_WIDGET_CLASS (mks_display_parent_class)->size_allocate (widget, width, height, baseline);
|
2023-02-15 18:38:24 +00:00
|
|
|
|
2023-02-17 19:40:34 +00:00
|
|
|
mks_display_get_paintable_area (self, &area);
|
2023-02-15 14:47:10 +00:00
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
if (priv->auto_resize)
|
|
|
|
{
|
|
|
|
attributes = mks_screen_attributes_new ();
|
|
|
|
mks_screen_attributes_set_width (attributes, width);
|
|
|
|
mks_screen_attributes_set_height (attributes, height);
|
2023-05-08 14:37:49 +00:00
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
mks_screen_resizer_queue_resize (priv->resizer,
|
|
|
|
g_steal_pointer (&attributes));
|
|
|
|
mks_screen_attributes_free (attributes);
|
|
|
|
}
|
2023-05-08 14:37:49 +00:00
|
|
|
|
2023-11-14 13:13:54 +00:00
|
|
|
gtk_widget_size_allocate (priv->offload,
|
2023-02-17 19:40:34 +00:00
|
|
|
&(GtkAllocation) {
|
|
|
|
area.origin.x,
|
|
|
|
area.origin.y,
|
|
|
|
area.size.width,
|
|
|
|
area.size.height
|
|
|
|
},
|
|
|
|
-1);
|
2023-02-15 14:47:10 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
static void
|
|
|
|
mks_display_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MksDisplay *self = MKS_DISPLAY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SCREEN:
|
|
|
|
g_value_set_object (value, mks_display_get_screen (self));
|
|
|
|
break;
|
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
case PROP_UNGRAB_TRIGGER:
|
|
|
|
g_value_set_object (value, mks_display_get_ungrab_trigger (self));
|
|
|
|
break;
|
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
case PROP_AUTO_RESIZE:
|
|
|
|
g_value_set_boolean (value, mks_display_get_auto_resize (self));
|
|
|
|
break;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MksDisplay *self = MKS_DISPLAY (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SCREEN:
|
|
|
|
mks_display_set_screen (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
case PROP_UNGRAB_TRIGGER:
|
|
|
|
mks_display_set_ungrab_trigger (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
case PROP_AUTO_RESIZE:
|
|
|
|
mks_display_set_auto_resize (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_class_init (MksDisplayClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = mks_display_dispose;
|
|
|
|
object_class->get_property = mks_display_get_property;
|
|
|
|
object_class->set_property = mks_display_set_property;
|
|
|
|
|
2023-02-15 14:47:10 +00:00
|
|
|
widget_class->get_request_mode = mks_display_get_request_mode;
|
|
|
|
widget_class->measure = mks_display_measure;
|
2023-02-17 19:40:34 +00:00
|
|
|
widget_class->size_allocate = mks_display_size_allocate;
|
2023-04-03 20:17:31 +00:00
|
|
|
widget_class->grab_focus = mks_display_grab_focus;
|
2023-02-14 05:53:57 +00:00
|
|
|
|
|
|
|
properties[PROP_SCREEN] =
|
|
|
|
g_param_spec_object ("screen", NULL, NULL,
|
|
|
|
MKS_TYPE_SCREEN,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
properties [PROP_UNGRAB_TRIGGER] =
|
|
|
|
g_param_spec_object ("ungrab-trigger", NULL, NULL,
|
|
|
|
GTK_TYPE_SHORTCUT_TRIGGER,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
properties [PROP_AUTO_RESIZE] =
|
|
|
|
g_param_spec_boolean ("auto-resize", NULL, NULL,
|
|
|
|
TRUE,
|
|
|
|
(G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
2023-02-14 19:18:48 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "MksDisplay");
|
|
|
|
|
|
|
|
_mks_css_init ();
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_display_init (MksDisplay *self)
|
|
|
|
{
|
2023-02-17 19:40:34 +00:00
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
2023-02-17 23:34:36 +00:00
|
|
|
GtkEventController *controller;
|
2023-02-17 19:40:34 +00:00
|
|
|
|
|
|
|
priv->picture = g_object_new (MKS_TYPE_DISPLAY_PICTURE, NULL);
|
2023-05-08 14:37:49 +00:00
|
|
|
priv->resizer = mks_screen_resizer_new ();
|
2023-11-14 13:13:54 +00:00
|
|
|
|
|
|
|
priv->offload = gtk_graphics_offload_new (GTK_WIDGET (priv->picture));
|
|
|
|
gtk_widget_set_parent (priv->offload, GTK_WIDGET (self));
|
2023-02-17 23:34:36 +00:00
|
|
|
|
|
|
|
controller = gtk_event_controller_legacy_new ();
|
|
|
|
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
|
|
|
|
g_signal_connect_object (controller,
|
|
|
|
"event",
|
|
|
|
G_CALLBACK (mks_display_legacy_event_cb),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
2023-02-17 23:50:02 +00:00
|
|
|
|
|
|
|
priv->ungrab_trigger = gtk_shortcut_trigger_parse_string (DEFAULT_UNGRAB_TRIGGER);
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
mks_display_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (MKS_TYPE_DISPLAY, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mks_display_get_screen:
|
|
|
|
* @self: a #MksDisplay
|
|
|
|
*
|
|
|
|
* Gets the screen connected to the display.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a #MksScreen
|
|
|
|
*/
|
|
|
|
MksScreen *
|
|
|
|
mks_display_get_screen (MksDisplay *self)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (MKS_IS_DISPLAY (self), NULL);
|
|
|
|
|
|
|
|
return priv->screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mks_display_set_screen (MksDisplay *self,
|
|
|
|
MksScreen *screen)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_ENTRY;
|
|
|
|
|
2023-02-14 05:53:57 +00:00
|
|
|
g_return_if_fail (MKS_IS_DISPLAY (self));
|
|
|
|
|
|
|
|
if (priv->screen == screen)
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
|
|
|
|
if (priv->screen != NULL)
|
|
|
|
mks_display_disconnect (self);
|
|
|
|
|
|
|
|
if (screen != NULL)
|
|
|
|
mks_display_connect (self, screen);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SCREEN]);
|
2023-02-28 04:23:25 +00:00
|
|
|
|
|
|
|
MKS_EXIT;
|
2023-02-14 05:53:57 +00:00
|
|
|
}
|
2023-02-17 23:50:02 +00:00
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
/**
|
|
|
|
* mks_display_get_auto_resize:
|
|
|
|
* @self: A `MksDisplay`
|
|
|
|
*
|
|
|
|
* Get whether the widget will reconfigure the VM whenever
|
|
|
|
* it gets a new size allocation.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
mks_display_get_auto_resize (MksDisplay *self)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
2023-06-02 17:18:54 +00:00
|
|
|
|
2023-05-25 09:12:37 +00:00
|
|
|
g_return_val_if_fail (MKS_IS_DISPLAY (self), FALSE);
|
|
|
|
|
|
|
|
return priv->auto_resize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mks_display_set_auto_resize:
|
|
|
|
* @self: A `MksDisplay`
|
|
|
|
* @auto_resize: Whether to auto resize or not
|
2023-06-02 17:18:54 +00:00
|
|
|
*
|
2023-05-25 09:12:37 +00:00
|
|
|
* Sets whether the widget should reconfigure the VM
|
|
|
|
* with the allocated size of the widget.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mks_display_set_auto_resize (MksDisplay *self,
|
|
|
|
gboolean auto_resize)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_if_fail (MKS_IS_DISPLAY (self));
|
|
|
|
auto_resize = !!auto_resize;
|
|
|
|
|
|
|
|
if (auto_resize != priv->auto_resize)
|
|
|
|
{
|
|
|
|
priv->auto_resize = auto_resize;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_AUTO_RESIZE]);
|
|
|
|
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
/**
|
|
|
|
* mks_display_get_ungrab_trigger:
|
|
|
|
* @self: a #MksDisplay
|
|
|
|
*
|
|
|
|
* Gets the #GtkShortcutTrigger that will ungrab the display.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): a #GtkShortcutTrigger
|
|
|
|
*/
|
|
|
|
GtkShortcutTrigger *
|
|
|
|
mks_display_get_ungrab_trigger (MksDisplay *self)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (MKS_IS_DISPLAY (self), NULL);
|
|
|
|
|
|
|
|
return priv->ungrab_trigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mks_display_set_ungrab_trigger (MksDisplay *self,
|
|
|
|
GtkShortcutTrigger *ungrab_trigger)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
2023-02-28 04:23:25 +00:00
|
|
|
MKS_ENTRY;
|
|
|
|
|
2023-02-17 23:50:02 +00:00
|
|
|
g_return_if_fail (MKS_IS_DISPLAY (self));
|
|
|
|
g_return_if_fail (!ungrab_trigger || GTK_IS_SHORTCUT_TRIGGER (ungrab_trigger));
|
|
|
|
|
|
|
|
if (g_set_object (&priv->ungrab_trigger, ungrab_trigger))
|
|
|
|
{
|
|
|
|
if (priv->ungrab_trigger == NULL)
|
|
|
|
priv->ungrab_trigger = gtk_shortcut_trigger_parse_string (DEFAULT_UNGRAB_TRIGGER);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_UNGRAB_TRIGGER]);
|
|
|
|
}
|
2023-02-28 04:23:25 +00:00
|
|
|
|
|
|
|
MKS_EXIT;
|
2023-02-17 23:50:02 +00:00
|
|
|
}
|
2023-06-19 21:57:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mks_display_get_event_position_in_guest:
|
|
|
|
* @self: a #MksDisplay
|
|
|
|
* @event: A #GdkEvent
|
|
|
|
* @guest_x: (out): Guest's X position
|
|
|
|
* @guest_y: (out): Guest's Y position
|
|
|
|
*
|
|
|
|
* Retrieve the (`guest_x`, `guest_y`) position
|
|
|
|
* where the `event` happened.
|
|
|
|
*
|
|
|
|
* Could be useful for implementing touch support emulation.
|
|
|
|
*
|
|
|
|
* Returns: Whether the event has an associated position
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
mks_display_get_event_position_in_guest (MksDisplay *self,
|
|
|
|
GdkEvent *event,
|
|
|
|
double *guest_x,
|
|
|
|
double *guest_y)
|
|
|
|
{
|
|
|
|
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (MKS_IS_DISPLAY (self), FALSE);
|
|
|
|
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
|
|
|
|
|
|
|
|
return mks_display_picture_event_get_guest_position (priv->picture, event,
|
|
|
|
guest_x, guest_y);
|
|
|
|
}
|