Commit abdbbcb6 authored by Guido Gunther's avatar Guido Gunther Committed by Sebastian Krzyszkowiak

Add fader that fades from transparent to almost black

We might want to make this more flexible later so we can also use
it for the fade in animation on startup.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent dcac9440
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-fader"
#include "config.h"
#include "fader.h"
#include "shell.h"
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
/**
* SECTION:phosh-fader
* @short_description: A fader
* @Title: A fullsreen surface that fades in
*/
typedef struct _PhoshFader
{
PhoshLayerSurface parent;
} PhoshFader;
G_DEFINE_TYPE (PhoshFader, phosh_fader, PHOSH_TYPE_LAYER_SURFACE)
static void
phosh_fader_show (GtkWidget *widget)
{
gboolean enable_animations;
GtkStyleContext *context;
enable_animations = hdy_get_enable_animations (widget);
if (enable_animations) {
context = gtk_widget_get_style_context(widget);
gtk_style_context_add_class (context, "phosh-fader-fade-in");
}
GTK_WIDGET_CLASS (phosh_fader_parent_class)->show (widget);
}
static void
phosh_fader_class_init (PhoshFaderClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->show = phosh_fader_show;
}
static void
phosh_fader_init (PhoshFader *self)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context(GTK_WIDGET (self));
gtk_style_context_remove_class(context, "phosh-fader-fade-in");
}
PhoshFader *
phosh_fader_new (gpointer layer_shell, gpointer wl_output)
{
return g_object_new (PHOSH_TYPE_FADER,
"layer-shell", layer_shell,
"wl-output", wl_output,
"anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
"layer", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"kbd-interactivity", FALSE,
"exclusive-zone", -1,
"namespace", "phosh fader",
NULL);
}
/*
* Copyright (C) 2019 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#pragma once
#include <layersurface.h>
G_BEGIN_DECLS
#define PHOSH_TYPE_FADER (phosh_fader_get_type())
G_DECLARE_FINAL_TYPE (PhoshFader, phosh_fader, PHOSH, FADER, PhoshLayerSurface)
PhoshFader *phosh_fader_new (gpointer layer_shell,
gpointer wl_output);
G_END_DECLS
......@@ -57,6 +57,8 @@ phosh_sources = [
'background.h',
'batteryinfo.c',
'batteryinfo.h',
'fader.c',
'fader.h',
'home.c',
'home.h',
'idle-manager.c',
......
......@@ -24,6 +24,7 @@
#include "batteryinfo.h"
#include "background-manager.h"
#include "fader.h"
#include "home.h"
#include "idle-manager.h"
#include "lockscreen-manager.h"
......@@ -63,6 +64,7 @@ typedef struct
{
PhoshLayerSurface *panel;
PhoshLayerSurface *home;
GPtrArray *faders; /* for final fade out */
struct popup *settings;
PhoshBackgroundManager *background_manager;
......@@ -313,6 +315,7 @@ panels_dispose (PhoshShell *self)
g_clear_pointer (&priv->panel, phosh_cp_widget_destroy);
g_clear_pointer (&priv->home, phosh_cp_widget_destroy);
g_clear_pointer (&priv->faders, g_ptr_array_unref);
}
......@@ -514,6 +517,7 @@ phosh_shell_constructed (GObject *object)
priv->idle_manager = phosh_idle_manager_get_default();
priv->toplevel_manager = phosh_toplevel_manager_new ();
priv->faders = g_ptr_array_new_with_free_func ((GDestroyNotify) (gtk_widget_destroy));
phosh_session_register ("sm.puri.Phosh");
phosh_system_prompter_register ();
......@@ -781,3 +785,25 @@ phosh_shell_get_default (void)
}
return instance;
}
void
phosh_shell_fade_out (PhoshShell *self)
{
PhoshShellPrivate *priv;
PhoshWayland *wl = phosh_wayland_get_default ();
PhoshMonitorManager *monitor_manager = phosh_shell_get_monitor_manager (self);
g_debug ("Fading out...");
g_return_if_fail (PHOSH_IS_SHELL (self));
priv = phosh_shell_get_instance_private (self);
for (int i = 0; i < phosh_monitor_manager_get_num_monitors (monitor_manager); i++) {
PhoshFader *fader;
PhoshMonitor *monitor = phosh_monitor_manager_get_monitor (monitor_manager, i);
fader = phosh_fader_new (phosh_wayland_get_zwlr_layer_shell_v1 (wl),
monitor->wl_output);
g_ptr_array_add (priv->faders, fader);
gtk_widget_show (GTK_WIDGET (fader));
}
}
......@@ -38,3 +38,4 @@ PhoshMonitorManager *phosh_shell_get_monitor_manager (PhoshShell *self);
PhoshOskManager *phosh_shell_get_osk_manager (PhoshShell *self);
PhoshToplevelManager *phosh_shell_get_toplevel_manager (PhoshShell *self);
PhoshWifiManager *phosh_shell_get_wifi_manager (PhoshShell *self);
void phosh_shell_fade_out (PhoshShell *self);
......@@ -227,3 +227,17 @@ phosh-notification .actions-area button:last-child {
phosh-notification .notification-image {
border-radius: 50%;
}
/* fader */
@keyframes phosh-fade-in {
from {background:rgba(0, 0, 0, 0);}
to {background:rgba(0, 0, 0, 0.8);}
}
.phosh-fader-fade-in {
animation-name: phosh-fade-in;
animation-duration: 2s;
animation-timing-function: linear;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment