From f7daa7ac451506a223d0f67f0e3c1e13a0f10a8d Mon Sep 17 00:00:00 2001 From: Jannis <78504175+JannisPetschenka@users.noreply.github.com> Date: Sun, 5 Mar 2023 16:48:16 +0100 Subject: [PATCH] Menu animation (#230) --- man/swaync.5.scd | 11 ++++ src/configSchema.json | 11 ++++ .../widgets/menubar/menubar.vala | 59 +++++++++++++++---- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/man/swaync.5.scd b/man/swaync.5.scd index ba83f55..8cbebfd 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -314,6 +314,17 @@ config file to be able to detect config errors default: "right" ++ description: Horizontal position of the button in the bar ++ enum: ["right", "left"] ++ + animation_type: ++ + type: string ++ + optional: true ++ + default: "slide_down" ++ + description: Animation type for menu++ + enum: ["slide_down", "slide_up", "none"] ++ + animation_duration: ++ + type: integer ++ + optional: true ++ + default: 250 ++ + description: Duration of animation in milliseconds ++ actions: ++ type: array ++ Default values: [] ++ diff --git a/src/configSchema.json b/src/configSchema.json index 9bbb649..6308a47 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -423,6 +423,17 @@ "default": "right", "enum": ["right", "left"] }, + "animation_type": { + "type": "string", + "default": "slide_down", + "description": "Animation type for menu", + "enum": ["slide_down", "slide_up", "none"] + }, + "animation_duration":{ + "type": "integer", + "default": 250, + "description": "Duration of animation in milliseconds" + }, "actions": { "$ref" : "#/widgets/buttons-grid/properties/actions" } diff --git a/src/controlCenter/widgets/menubar/menubar.vala b/src/controlCenter/widgets/menubar/menubar.vala index a1cfc9d..c9a5271 100644 --- a/src/controlCenter/widgets/menubar/menubar.vala +++ b/src/controlCenter/widgets/menubar/menubar.vala @@ -17,7 +17,9 @@ namespace SwayNotificationCenter.Widgets { string ? label; Position ? position; Action[] actions; - Gtk.Box ? menu; + Gtk.Revealer ? revealer; + int animation_duration; + Gtk.RevealerTransitionType animation_type; } public struct Action { @@ -61,7 +63,7 @@ namespace SwayNotificationCenter.Widgets { show_all (); foreach (var obj in menu_objects) { - obj.menu ?.hide (); + obj.revealer ?.set_reveal_child (false); } } @@ -69,7 +71,7 @@ namespace SwayNotificationCenter.Widgets { switch (obj.type) { case MenuType.BUTTONS: Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - container.get_style_context ().add_class (obj.name); + if (obj.name != null) container.get_style_context ().add_class (obj.name); foreach (Action a in obj.actions) { Gtk.Button b = new Gtk.Button.with_label (a.label); @@ -91,16 +93,21 @@ namespace SwayNotificationCenter.Widgets { Gtk.Button show_button = new Gtk.Button.with_label (obj.label); Gtk.Box menu = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - menu.get_style_context ().add_class (obj.name); - obj.menu = menu; + if (obj.name != null) menu.get_style_context ().add_class (obj.name); + + Gtk.Revealer r = new Gtk.Revealer (); + r.add (menu); + r.set_transition_duration (obj.animation_duration); + r.set_transition_type (obj.animation_type); + obj.revealer = r; show_button.clicked.connect (() => { - bool visible = !menu.visible; - foreach (var o in menu_objects) { - o.menu ?.set_visible (false); - } - menu.set_visible (visible); - }); + bool visible = !r.get_reveal_child (); + foreach (var o in menu_objects) { + o.revealer ?.set_reveal_child (false); + } + r.set_reveal_child (visible); + }); foreach (var a in obj.actions) { Gtk.Button b = new Gtk.Button.with_label (a.label); @@ -117,7 +124,7 @@ namespace SwayNotificationCenter.Widgets { break; } - menus_container.add (menu); + menus_container.add (r); break; } } @@ -160,6 +167,30 @@ namespace SwayNotificationCenter.Widgets { info ("No label for menu-object given using default"); } + int duration = int.max (0, get_prop (obj, "animation_duration")); + if (duration == 0) duration = 250; + + string ? animation_type = get_prop (obj, "animation_type"); + if (animation_type == null) { + animation_type = "slide_down"; + info ("No animation-type for menu-object given using default"); + } + + Gtk.RevealerTransitionType revealer_type; + + switch (animation_type) { + default: + case "none": + revealer_type = Gtk.RevealerTransitionType.NONE; + break; + case "slide_up": + revealer_type = Gtk.RevealerTransitionType.SLIDE_UP; + break; + case "slide_down": + revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN; + break; + } + Action[] actions_list = parse_actions (actions); menu_objects.append (ConfigObject () { name = name, @@ -167,7 +198,9 @@ namespace SwayNotificationCenter.Widgets { label = label, position = pos, actions = actions_list, - menu = null, + revealer = null, + animation_duration = duration, + animation_type = revealer_type, }); } }