[libpanel/wip/chergert/fix-14: 2/2] layout: stub out layout widget




commit 7b0581da7739e8dfbc7f111b7431c2d2eba98991
Author: Christian Hergert <chergert redhat com>
Date:   Sat Sep 10 18:06:21 2022 -0700

    layout: stub out layout widget

 src/libpanel.h          |   1 +
 src/meson.build         |   2 +
 src/panel-layout.c      | 124 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/panel-layout.h      |  39 +++++++++++++++
 testsuite/meson.build   |   9 +++-
 testsuite/test-layout.c |  21 ++++++++
 6 files changed, 194 insertions(+), 2 deletions(-)
---
diff --git a/src/libpanel.h b/src/libpanel.h
index 5d01ccb..550057a 100644
--- a/src/libpanel.h
+++ b/src/libpanel.h
@@ -31,6 +31,7 @@
 # include "panel-grid.h"
 # include "panel-grid-column.h"
 # include "panel-init.h"
+# include "panel-layout.h"
 # include "panel-omni-bar.h"
 # include "panel-paned.h"
 # include "panel-position.h"
diff --git a/src/meson.build b/src/meson.build
index b018115..a625a0b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -40,6 +40,7 @@ libpanel_sources = [
   'panel-grid.c',
   'panel-grid-column.c',
   'panel-init.c',
+  'panel-layout.c',
   'panel-omni-bar.c',
   'panel-paned.c',
   'panel-position.c',
@@ -62,6 +63,7 @@ libpanel_headers = [
   'panel-grid.h',
   'panel-grid-column.h',
   'panel-init.h',
+  'panel-layout.h',
   'panel-omni-bar.h',
   'panel-paned.h',
   'panel-position.h',
diff --git a/src/panel-layout.c b/src/panel-layout.c
new file mode 100644
index 0000000..757fea3
--- /dev/null
+++ b/src/panel-layout.c
@@ -0,0 +1,124 @@
+/* panel-layout.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+
+#include "panel-layout.h"
+#include "panel-position.h"
+
+struct _PanelLayout
+{
+  GObject  parent_instance;
+  GArray  *infos;
+};
+
+typedef struct
+{
+  PanelPosition *position;
+  char *id;
+  char *type_hint;
+  GVariant *metadata;
+} WidgetInfo;
+
+G_DEFINE_FINAL_TYPE (PanelLayout, panel_layout, G_TYPE_OBJECT)
+
+static void
+widget_info_clear (WidgetInfo *info)
+{
+  g_clear_object (&info->position);
+  g_clear_pointer (&info->id, g_free);
+  g_clear_pointer (&info->type_hint, g_free);
+  g_clear_pointer (&info->metadata, g_variant_unref);
+}
+
+static void
+panel_layout_dispose (GObject *object)
+{
+  PanelLayout *self = (PanelLayout *)object;
+
+  g_clear_pointer (&self->infos, g_array_unref);
+
+  G_OBJECT_CLASS (panel_layout_parent_class)->dispose (object);
+}
+
+static void
+panel_layout_class_init (PanelLayoutClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = panel_layout_dispose;
+}
+
+static void
+panel_layout_init (PanelLayout *self)
+{
+  self->infos = g_array_new (FALSE, FALSE, sizeof (WidgetInfo));
+  g_array_set_clear_func (self->infos, (GDestroyNotify)widget_info_clear);
+}
+
+GVariant *
+panel_layout_to_variant (PanelLayout *self)
+{
+  GVariantBuilder builder;
+
+  g_return_val_if_fail (PANEL_IS_LAYOUT (self), NULL);
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+  g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
+    g_variant_builder_add_parsed (&builder, "{'version',%u}", 1);
+  g_variant_builder_close (&builder);
+
+  g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
+    g_variant_builder_add (&builder, "s", "widgets");
+    g_variant_builder_open (&builder, G_VARIANT_TYPE ("v"));
+      g_variant_builder_open (&builder, G_VARIANT_TYPE ("av"));
+      for (guint i = 0; i < self->infos->len; i++)
+        {
+          const WidgetInfo *info = &g_array_index (self->infos, WidgetInfo, i);
+          g_variant_builder_open (&builder, G_VARIANT_TYPE ("v"));
+            g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
+              g_variant_builder_add_parsed (&builder, "{'position',<%v>}", info->position);
+              g_variant_builder_add_parsed (&builder, "{'id',<%s>}", info->id ? info->id : "");
+              g_variant_builder_add_parsed (&builder, "{'type-hint',<%s>}", info->type_hint ? 
info->type_hint : "");
+              if (info->metadata)
+                g_variant_builder_add_parsed (&builder, "{'metadata',<%v>}", info->metadata);
+            g_variant_builder_close (&builder);
+          g_variant_builder_close (&builder);
+        }
+      g_variant_builder_close (&builder);
+    g_variant_builder_close (&builder);
+  g_variant_builder_close (&builder);
+
+  return g_variant_builder_end (&builder);
+}
+
+PanelLayout *
+panel_layout_new_from_variant (GVariant *variant)
+{
+  PanelLayout *self;
+
+  g_return_val_if_fail (variant != NULL, NULL);
+  g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), NULL);
+
+  self = g_object_new (PANEL_TYPE_LAYOUT, NULL);
+
+  return self;
+}
diff --git a/src/panel-layout.h b/src/panel-layout.h
new file mode 100644
index 0000000..e1b9509
--- /dev/null
+++ b/src/panel-layout.h
@@ -0,0 +1,39 @@
+/* panel-layout.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+#include "panel-version-macros.h"
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_LAYOUT (panel_layout_get_type())
+
+PANEL_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (PanelLayout, panel_layout, PANEL, LAYOUT, GObject)
+
+PANEL_AVAILABLE_IN_ALL
+PanelLayout *panel_layout_new_from_variant (GVariant    *variant);
+PANEL_AVAILABLE_IN_ALL
+GVariant    *panel_layout_to_variant       (PanelLayout *self);
+
+G_END_DECLS
diff --git a/testsuite/meson.build b/testsuite/meson.build
index 651c113..b6173ec 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -1,2 +1,7 @@
-executable('test-dock', 'test-dock.c', dependencies: [libpanel_static_dep])
-executable('test-paned', 'test-paned.c', dependencies: [libpanel_static_dep])
+test_dock = executable('test-dock', 'test-dock.c', dependencies: [libpanel_static_dep])
+test_paned = executable('test-paned', 'test-paned.c', dependencies: [libpanel_static_dep])
+
+test_layout = executable('test-layout', 'test-layout.c', dependencies: [libpanel_static_dep])
+test('test-layout', test_layout)
+
+
diff --git a/testsuite/test-layout.c b/testsuite/test-layout.c
new file mode 100644
index 0000000..f51380e
--- /dev/null
+++ b/testsuite/test-layout.c
@@ -0,0 +1,21 @@
+#include <libpanel.h>
+
+static void
+test_layout (void)
+{
+  PanelLayout *layout;
+
+  layout = g_object_new (PANEL_TYPE_LAYOUT, NULL);
+
+  g_assert_finalize_object (layout);
+}
+
+int
+main (int argc,
+      char *argv[])
+{
+  gtk_init ();
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/Layout/basic", test_layout);
+  return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]