1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-04 20:07:36 +00:00

in-app-notification: compose with GtkBin instead of subclassing GtkRevealer

Note that the GtkOverlay must pass-through interactions for this to
work, meaning it's no longer possible to interact with the
notifications. I'm leaving it like this since I'll need to replace it
with AdwToast later anyways.

Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/714>
This commit is contained in:
Anton Lazarev 2023-08-26 19:59:59 -07:00
parent f1e63c4979
commit 2141c1ffc2
6 changed files with 51 additions and 34 deletions

View file

@ -27,15 +27,16 @@
#define DEFAULT_TIMEOUT_SECONDS 3
struct _CallsInAppNotification {
GtkRevealer parent_instance;
GtkBin parent_instance;
GtkLabel *label;
GtkRevealer *revealer;
GtkLabel *label;
guint timeout;
guint timeout_id;
guint timeout;
guint timeout_id;
};
G_DEFINE_TYPE (CallsInAppNotification, calls_in_app_notification, GTK_TYPE_REVEALER)
G_DEFINE_TYPE (CallsInAppNotification, calls_in_app_notification, GTK_TYPE_BIN)
enum {
@ -128,6 +129,7 @@ calls_in_app_notification_class_init (CallsInAppNotificationClass *klass)
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/in-app-notification.ui");
gtk_widget_class_bind_template_child (widget_class, CallsInAppNotification, revealer);
gtk_widget_class_bind_template_child (widget_class, CallsInAppNotification, label);
gtk_widget_class_bind_template_callback (widget_class, calls_in_app_notification_hide);
}
@ -157,7 +159,7 @@ calls_in_app_notification_show (CallsInAppNotification *self, const gchar *messa
if (self->timeout_id)
g_source_remove (self->timeout_id);
gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
gtk_revealer_set_reveal_child (self->revealer, TRUE);
self->timeout_id = g_timeout_add_seconds (self->timeout, (GSourceFunc) timeout_cb, self);
}
@ -169,5 +171,5 @@ calls_in_app_notification_hide (CallsInAppNotification *self)
g_clear_handle_id (&self->timeout_id, g_source_remove);
gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
gtk_revealer_set_reveal_child (self->revealer, FALSE);
}

View file

@ -31,7 +31,7 @@ G_BEGIN_DECLS
#define CALLS_TYPE_IN_APP_NOTIFICATION (calls_in_app_notification_get_type ())
G_DECLARE_FINAL_TYPE (CallsInAppNotification, calls_in_app_notification, CALLS, IN_APP_NOTIFICATION, GtkRevealer)
G_DECLARE_FINAL_TYPE (CallsInAppNotification, calls_in_app_notification, CALLS, IN_APP_NOTIFICATION, GtkBin)
CallsInAppNotification * calls_in_app_notification_new (void);
void calls_in_app_notification_show (CallsInAppNotification *self, const gchar *message);

View file

@ -35,6 +35,9 @@
<object class="CallsInAppNotification" id="in_app_notification">
<property name="visible">True</property>
</object>
<packing>
<property name="pass-through">True</property>
</packing>
</child>
<child>
<object class="GtkStack" id="stack">

View file

@ -15,6 +15,9 @@
<object class="CallsInAppNotification" id="in_app_notification">
<property name="visible">True</property>
</object>
<packing>
<property name="pass-through">True</property>
</packing>
</child>
<child>
<object class="GtkStack" id="main_stack">

View file

@ -1,44 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="CallsInAppNotification" parent="GtkRevealer">
<property name="reveal-child">False</property>
<property name="transition-type">slide-down</property>
<property name="valign">start</property>
<property name="halign">center</property>
<template class="CallsInAppNotification" parent="GtkBin">
<property name="visible">False</property>
<child>
<object class="GtkBox">
<object class="GtkRevealer" id="revealer">
<property name="visible">True</property>
<property name="reveal-child">False</property>
<property name="transition-type">slide-down</property>
<property name="valign">start</property>
<property name="halign">center</property>
<child>
<object class="GtkButton">
<object class="GtkBox">
<property name="visible">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="calls_in_app_notification_hide" swapped="yes"/>
<child>
<object class="GtkImage">
<object class="GtkButton">
<property name="visible">True</property>
<property name="icon_name">window-close-symbolic</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="calls_in_app_notification_hide" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">window-close-symbolic</property>
</object>
</child>
<style>
<class name="flat"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="wrap">True</property>
<property name="margin-left">24</property>
<property name="margin-right">24</property>
</object>
</child>
<style>
<class name="flat"/>
<class name="app-notification"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="wrap">True</property>
<property name="margin-left">24</property>
<property name="margin-right">24</property>
</object>
</child>
<style>
<class name="app-notification"/>
</style>
</object>
</child>
</template>

View file

@ -49,6 +49,9 @@
<object class="CallsInAppNotification" id="in_app_notification">
<property name="visible">True</property>
</object>
<packing>
<property name="pass-through">True</property>
</packing>
</child>
<child>
<object class="GtkBox">