[gnome-flashback] backends: add GfMonitorSpec



commit 3f044eb1617d0933248c5bd05c7fb5f1a8d81f93
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Sep 9 22:46:50 2017 +0300

    backends: add GfMonitorSpec

 backends/Makefile.am               |    2 +
 backends/gf-monitor-spec-private.h |   49 +++++++++++++++++++++
 backends/gf-monitor-spec.c         |   82 ++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+), 0 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index c944513..4b91b19 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -31,6 +31,8 @@ libbackends_la_SOURCES = \
        gf-backend.h \
        gf-edid-parse.c \
        gf-edid-private.h \
+       gf-monitor-spec-private.h \
+       gf-monitor-spec.c \
        gf-orientation-manager-private.h \
        gf-orientation-manager.c \
        gf-settings-private.h \
diff --git a/backends/gf-monitor-spec-private.h b/backends/gf-monitor-spec-private.h
new file mode 100644
index 0000000..77105b6
--- /dev/null
+++ b/backends/gf-monitor-spec-private.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ * Copyright (C) 2017 Alberts Muktupāvels
+ *
+ * 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/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor.h
+ */
+
+#ifndef GF_MONITOR_SPEC_PRIVATE_H
+#define GF_MONITOR_SPEC_PRIVATE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+  gchar *connector;
+  gchar *vendor;
+  gchar *product;
+  gchar *serial;
+} GfMonitorSpec;
+
+GfMonitorSpec *gf_monitor_spec_clone   (GfMonitorSpec *spec);
+
+gboolean       gf_monitor_spec_equals  (GfMonitorSpec *spec,
+                                        GfMonitorSpec *other_spec);
+
+gint           gf_monitor_spec_compare (GfMonitorSpec *spec_a,
+                                        GfMonitorSpec *spec_b);
+
+void           gf_monitor_spec_free    (GfMonitorSpec *spec);
+
+G_END_DECLS
+
+#endif
diff --git a/backends/gf-monitor-spec.c b/backends/gf-monitor-spec.c
new file mode 100644
index 0000000..33be477
--- /dev/null
+++ b/backends/gf-monitor-spec.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2016 Red Hat
+ * Copyright (C) 2017 Alberts Muktupāvels
+ *
+ * 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/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor.c
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include "gf-monitor-spec-private.h"
+
+GfMonitorSpec *
+gf_monitor_spec_clone (GfMonitorSpec *spec)
+{
+  GfMonitorSpec *new_spec;
+
+  new_spec = g_new0 (GfMonitorSpec, 1);
+
+  new_spec->connector = g_strdup (spec->connector);
+  new_spec->vendor = g_strdup (spec->vendor);
+  new_spec->product = g_strdup (spec->product);
+  new_spec->serial = g_strdup (spec->serial);
+
+  return new_spec;
+}
+
+gboolean
+gf_monitor_spec_equals (GfMonitorSpec *spec,
+                        GfMonitorSpec *other_spec)
+{
+  return (g_str_equal (spec->connector, other_spec->connector) &&
+          g_str_equal (spec->vendor, other_spec->vendor) &&
+          g_str_equal (spec->product, other_spec->product) &&
+          g_str_equal (spec->serial, other_spec->serial));
+}
+
+gint
+gf_monitor_spec_compare (GfMonitorSpec *spec_a,
+                         GfMonitorSpec *spec_b)
+{
+  gint ret;
+
+  ret = g_strcmp0 (spec_a->connector, spec_b->connector);
+  if (ret != 0)
+    return ret;
+
+  ret = g_strcmp0 (spec_a->vendor, spec_b->vendor);
+  if (ret != 0)
+    return ret;
+
+  ret = g_strcmp0 (spec_a->product, spec_b->product);
+  if (ret != 0)
+    return ret;
+
+  return g_strcmp0 (spec_a->serial, spec_b->serial);
+}
+
+void
+gf_monitor_spec_free (GfMonitorSpec *spec)
+{
+  g_free (spec->connector);
+  g_free (spec->vendor);
+  g_free (spec->product);
+  g_free (spec->serial);
+  g_free (spec);
+}


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