diff --git a/README.md b/README.md index fa4113b..c807dd7 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,16 @@ A simple notification daemon with a GTK gui for notifications and the control ce - The same features as any other basic notification daemon - Basic configuration through a JSON config file - Hot-reload config through `swaync-client` +- Customizable widgets + +## Available Widgets + +These widgets can be customized, added, removed and even reordered + +- Title +- Do Not Disturb +- Notifications (Will always be visible) +- Label ## Planned Features diff --git a/man/swaync.5.scd b/man/swaync.5.scd index d416f2c..48991bb 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -156,6 +156,102 @@ config file to be able to detect config errors } ``` +*widgets* ++ + type: array ++ + Default values: ["title", "dnd", "notifications"] ++ + Valid array values (see *widget-config* for more information): ++ + *notifications*++ + required: true ++ + optional: false ++ + *title*++ + optional: true ++ + *dnd*++ + optional: true ++ + *label*++ + optional: true ++ + description: Which order and which widgets to display. ++ + If the \"notifications\" widget isn't specified, it ++ + will be placed at the bottom. ++ + example: +``` +{ + "widgets": [ + "title", + "dnd", + "notifications" + ] +} +``` + +*widget-config* ++ + type: object ++ + description: Configure specific widget properties. ++ + Widgets to customize: ++ + *title*++ + type: object ++ + css class: widget-title ++ + properties: ++ + text: ++ + type: string ++ + optional: true ++ + default: "Do Not Disturb" ++ + description: The title of the widget ++ + clear-all-button: ++ + type: bool ++ + optional: true ++ + default: true ++ + description: Wether to display a "Clear All" button ++ + button-text: ++ + type: string ++ + optional: true ++ + default: "Clear All" ++ + description: "Clear All" button text ++ + description: The notification visibility state. ++ + *dnd*++ + type: object ++ + css class: widget-dnd ++ + properties: ++ + text: ++ + type: string ++ + optional: true ++ + default: "Do Not Disturb" ++ + description: The title of the widget ++ + description: Control Center Do Not Disturb Widget. ++ + *label*++ + type: object ++ + css class: widget-label ++ + properties: ++ + text: ++ + type: string ++ + optional: true ++ + default: "Label Text" ++ + description: The text content of the widget ++ + clear-all-button: ++ + type: integer ++ + optional: true ++ + default: 5 ++ + description: The maximum lines ++ + description: A generic widget that allows the user to add custom text. ++ + example: +``` +{ + "widget-config": { + "title": { + "text": "Notifications", + "clear-all-button": true, + "button-text": "Clear All" + }, + "dnd": { + "text": "Do Not Disturb" + }, + "label": { + "max-lines": 5, + "text": "Label Text" + } + } +} +``` + # IF BUILT WITH SCRIPTING *script-fail-notify* ++ diff --git a/src/config.json.in b/src/config.json.in index 943d025..fcc5243 100644 --- a/src/config.json.in +++ b/src/config.json.in @@ -34,5 +34,24 @@ "urgency": "Low", "app-name": "Spotify" } + }, + "widgets": [ + "title", + "dnd", + "notifications" + ], + "widget-config": { + "title": { + "text": "Notifications", + "clear-all-button": true, + "button-text": "Clear All" + }, + "dnd": { + "text": "Do Not Disturb" + }, + "label": { + "max-lines": 5, + "text": "Label Text" + } } } diff --git a/src/configModel/configModel.vala b/src/configModel/configModel.vala index 3b97f26..9038031 100644 --- a/src/configModel/configModel.vala +++ b/src/configModel/configModel.vala @@ -503,6 +503,20 @@ namespace SwayNotificationCenter { } } + /** Widgets to show in ControlCenter */ + public GenericArray widgets { + get; + set; + default = new GenericArray (); + } + + /** Widgets to show in ControlCenter */ + public HashTable widget_config { + get; + set; + default = new HashTable (str_hash, str_equal); + } + /* Methods */ /** @@ -544,6 +558,34 @@ namespace SwayNotificationCenter { value = result; return status; #endif + case "widgets": + bool status; + GenericArray result = + extract_array (property_name, + property_node, + out status); + value = result; + return status; + case "widget-config": + HashTable result + = new HashTable (str_hash, str_equal); + if (property_node.get_value_type ().name () != "JsonObject") { + value = result; + return true; + } + Json.Object obj = property_node.get_object (); + if (obj.get_size () == 0) { + value = result; + return true; + } + foreach (var key in obj.get_members ()) { + Json.Node ? node = obj.get_member (key); + if (node.get_node_type () != Json.NodeType.OBJECT) continue; + Json.Object ? o = node.get_object (); + if (o != null) result.set (key, o); + } + value = result; + return true; default: // Handles all other properties return default_deserialize_property ( @@ -588,6 +630,16 @@ namespace SwayNotificationCenter { node.set_object (serialize_hashtable