Merge branch 'matthiasc/for-main' into 'main'
video: Hide controls and cursor in fullscreen Closes #6210 See merge request GNOME/gtk!6572
This commit is contained in:
116
gtk/gtkvideo.c
116
gtk/gtkvideo.c
@@ -69,10 +69,15 @@ struct _GtkVideo
|
||||
GtkWidget *controls;
|
||||
GtkWidget *graphics_offload;
|
||||
guint controls_hide_source;
|
||||
guint cursor_hide_source;
|
||||
double last_x;
|
||||
double last_y;
|
||||
|
||||
guint autoplay : 1;
|
||||
guint loop : 1;
|
||||
guint grabbed : 1;
|
||||
guint fullscreen : 1;
|
||||
guint cursor_hidden : 1;
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -91,15 +96,22 @@ G_DEFINE_TYPE (GtkVideo, gtk_video, GTK_TYPE_WIDGET)
|
||||
|
||||
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
|
||||
static gboolean
|
||||
gtk_video_get_playing (GtkVideo *self)
|
||||
{
|
||||
if (self->media_stream != NULL)
|
||||
return gtk_media_stream_get_playing (self->media_stream);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_video_hide_controls (gpointer data)
|
||||
{
|
||||
GtkVideo *self = data;
|
||||
|
||||
if (self->grabbed)
|
||||
return G_SOURCE_CONTINUE;
|
||||
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), FALSE);
|
||||
if (gtk_video_get_playing (self))
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), FALSE);
|
||||
|
||||
self->controls_hide_source = 0;
|
||||
|
||||
@@ -112,18 +124,54 @@ gtk_video_reveal_controls (GtkVideo *self)
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), TRUE);
|
||||
if (self->controls_hide_source)
|
||||
g_source_remove (self->controls_hide_source);
|
||||
self->controls_hide_source = g_timeout_add (5 * 1000,
|
||||
self->controls_hide_source = g_timeout_add (3 * 1000,
|
||||
gtk_video_hide_controls,
|
||||
self);
|
||||
gdk_source_set_static_name_by_id (self->controls_hide_source, "[gtk] gtk_video_hide_controls");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_video_hide_cursor (gpointer data)
|
||||
{
|
||||
GtkVideo *self = data;
|
||||
|
||||
if (self->fullscreen && gtk_video_get_playing (self) && !self->cursor_hidden)
|
||||
{
|
||||
gtk_widget_set_cursor_from_name (GTK_WIDGET (self), "none");
|
||||
self->cursor_hidden = TRUE;
|
||||
}
|
||||
|
||||
self->cursor_hide_source = 0;
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_reveal_cursor (GtkVideo *self)
|
||||
{
|
||||
gtk_widget_set_cursor (GTK_WIDGET (self), NULL);
|
||||
self->cursor_hidden = FALSE;
|
||||
if (self->cursor_hide_source)
|
||||
g_source_remove (self->cursor_hide_source);
|
||||
self->cursor_hide_source = g_timeout_add (3 * 1000,
|
||||
gtk_video_hide_cursor,
|
||||
self);
|
||||
gdk_source_set_static_name_by_id (self->cursor_hide_source, "[gtk] gtk_video_hide_cursor");
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_motion (GtkEventControllerMotion *motion,
|
||||
double x,
|
||||
double y,
|
||||
GtkVideo *self)
|
||||
{
|
||||
if (self->last_x == x && self->last_y == y)
|
||||
return;
|
||||
|
||||
self->last_x = x;
|
||||
self->last_y = y;
|
||||
|
||||
gtk_video_reveal_cursor (self);
|
||||
gtk_video_reveal_controls (self);
|
||||
}
|
||||
|
||||
@@ -208,6 +256,13 @@ gtk_video_unmap (GtkWidget *widget)
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), FALSE);
|
||||
}
|
||||
|
||||
if (self->cursor_hide_source)
|
||||
{
|
||||
g_source_remove (self->cursor_hide_source);
|
||||
self->cursor_hide_source = 0;
|
||||
gtk_widget_set_cursor (widget, NULL);
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_video_parent_class)->unmap (widget);
|
||||
}
|
||||
|
||||
@@ -222,17 +277,6 @@ gtk_video_hide (GtkWidget *widget)
|
||||
GTK_WIDGET_CLASS (gtk_video_parent_class)->hide (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_set_focus_child (GtkWidget *widget,
|
||||
GtkWidget *child)
|
||||
{
|
||||
GtkVideo *self = GTK_VIDEO (widget);
|
||||
|
||||
self->grabbed = child != NULL;
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_video_parent_class)->set_focus_child (widget, child);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_dispose (GObject *object)
|
||||
{
|
||||
@@ -318,6 +362,34 @@ gtk_video_set_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fullscreen_changed (GtkWindow *window,
|
||||
GParamSpec *pspec,
|
||||
GtkVideo *self)
|
||||
{
|
||||
self->fullscreen = gtk_window_is_fullscreen (window);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_root (GtkWidget *widget)
|
||||
{
|
||||
GTK_WIDGET_CLASS (gtk_video_parent_class)->root (widget);
|
||||
|
||||
g_signal_connect (gtk_widget_get_root (widget), "notify::fullscreened",
|
||||
G_CALLBACK (fullscreen_changed), widget);
|
||||
|
||||
gtk_video_reveal_cursor (GTK_VIDEO (widget));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_unroot (GtkWidget *widget)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
|
||||
fullscreen_changed, widget);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_video_parent_class)->unroot (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_video_class_init (GtkVideoClass *klass)
|
||||
{
|
||||
@@ -329,7 +401,8 @@ gtk_video_class_init (GtkVideoClass *klass)
|
||||
widget_class->map = gtk_video_map;
|
||||
widget_class->unmap = gtk_video_unmap;
|
||||
widget_class->hide = gtk_video_hide;
|
||||
widget_class->set_focus_child = gtk_video_set_focus_child;
|
||||
widget_class->root = gtk_video_root;
|
||||
widget_class->unroot = gtk_video_unroot;
|
||||
|
||||
gobject_class->dispose = gtk_video_dispose;
|
||||
gobject_class->get_property = gtk_video_get_property;
|
||||
@@ -585,14 +658,11 @@ gtk_video_update_error (GtkVideo *self)
|
||||
static void
|
||||
gtk_video_update_playing (GtkVideo *self)
|
||||
{
|
||||
gboolean playing;
|
||||
|
||||
if (self->media_stream != NULL)
|
||||
playing = gtk_media_stream_get_playing (self->media_stream);
|
||||
else
|
||||
playing = FALSE;
|
||||
gboolean playing = gtk_video_get_playing (self);
|
||||
|
||||
gtk_widget_set_visible (self->overlay_icon, !playing);
|
||||
gtk_widget_set_cursor (GTK_WIDGET (self), NULL);
|
||||
self->cursor_hidden = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user