[gtk+/wip/matthiasc/monitor: 1/4] Fist cut at GdkMonitor



commit 71b4a82f0d8f1877c08a94810415994cc43949c9
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 31 23:10:04 2016 -0400

    Fist cut at GdkMonitor
    
    Add a simple object representing a monitor.

 gdk/Makefile.am         |    2 +
 gdk/gdk.h               |    1 +
 gdk/gdkmonitor.c        |  294 +++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkmonitor.h        |   64 ++++++++++
 gdk/gdkmonitorprivate.h |   64 ++++++++++
 5 files changed, 425 insertions(+), 0 deletions(-)
---
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index d8340ee..fb216b4 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -77,6 +77,7 @@ gdk_public_h_sources =                                \
        gdkkeysyms.h                            \
        gdkkeysyms-compat.h                     \
        gdkmain.h                               \
+       gdkmonitor.h                            \
        gdkpango.h                              \
        gdkframeclock.h                         \
        gdkpixbuf.h                             \
@@ -144,6 +145,7 @@ gdk_c_sources =                             \
        gdkglobals.c                            \
        gdkkeys.c                               \
        gdkkeyuni.c                             \
+       gdkmonitor.c                            \
        gdkoffscreenwindow.c                    \
        gdkframeclock.c                         \
        gdkframeclockidle.c                     \
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 81ba765..eeb8516 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -45,6 +45,7 @@
 #include <gdk/gdkkeys.h>
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkmain.h>
+#include <gdk/gdkmonitor.h>
 #include <gdk/gdkpango.h>
 #include <gdk/gdkpixbuf.h>
 #include <gdk/gdkproperty.h>
diff --git a/gdk/gdkmonitor.c b/gdk/gdkmonitor.c
new file mode 100644
index 0000000..c10ca9d
--- /dev/null
+++ b/gdk/gdkmonitor.c
@@ -0,0 +1,294 @@
+/*
+ * gdkmonitor.c
+ *
+ * Copyright 2016 Red Hat, Inc.
+ *
+ * Matthias Clasen <mclasen redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gdkmonitorprivate.h"
+
+enum {
+  PROP_0,
+  PROP_DISPLAY,
+  PROP_MANUFACTURER,
+  PROP_MODEL,
+  PROP_SCALE,
+  PROP_GEOMETRY,
+  PROP_WIDTH,
+  PROP_HEIGHT,
+  LAST_PROP
+};
+
+static GParamSpec *props[LAST_PROP] = { NULL, };
+
+G_DEFINE_TYPE (GdkMonitor, gdk_monitor, G_TYPE_OBJECT)
+
+static void
+gdk_monitor_init (GdkMonitor *monitor)
+{
+  monitor->scale = 1;
+}
+
+static void
+gdk_monitor_get_property (GObject    *object,
+                          guint       prop_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  GdkMonitor *monitor = GDK_MONITOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      g_value_set_object (value, monitor->display);
+      break;
+
+    case PROP_MANUFACTURER:
+      g_value_set_string (value, monitor->manufacturer);
+      break;
+
+    case PROP_MODEL:
+      g_value_set_string (value, monitor->model);
+      break;
+
+    case PROP_SCALE:
+      g_value_set_int (value, monitor->scale);
+      break;
+
+    case PROP_GEOMETRY:
+      g_value_set_boxed (value, &monitor->geometry);
+      break;
+
+    case PROP_WIDTH:
+      g_value_set_int (value, monitor->width);
+      break;
+
+    case PROP_HEIGHT:
+      g_value_set_int (value, monitor->height);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gdk_monitor_set_property (GObject      *object,
+                          guint         prop_id,
+                          const GValue *value,
+                          GParamSpec   *pspec)
+{
+  GdkMonitor *monitor = GDK_MONITOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      monitor->display = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gdk_monitor_finalize (GObject *object)
+{
+  GdkMonitor *monitor = GDK_MONITOR (object);
+
+  g_free (monitor->manufacturer);
+  g_free (monitor->model);
+
+  G_OBJECT_CLASS (gdk_monitor_parent_class)->finalize (object);
+}
+
+static void
+gdk_monitor_class_init (GdkMonitorClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = gdk_monitor_finalize;
+  object_class->get_property = gdk_monitor_get_property;
+  object_class->set_property = gdk_monitor_set_property;
+
+  props[PROP_DISPLAY] =
+    g_param_spec_object ("display",
+                         "Display",
+                         "The display of the monitor",
+                         GDK_TYPE_DISPLAY,
+                         G_PARAM_READABLE|G_PARAM_CONSTRUCT_ONLY);
+  props[PROP_MANUFACTURER] =
+    g_param_spec_string ("manufacturer",
+                         "Manufacturer",
+                         "The manufacturer name",
+                         NULL,
+                         G_PARAM_READABLE);
+  props[PROP_MODEL] =
+    g_param_spec_string ("model",
+                         "Model",
+                         "The model name",
+                         NULL,
+                         G_PARAM_READABLE);
+  props[PROP_SCALE] =
+    g_param_spec_int ("scale",
+                      "Scale",
+                      "The scale factor",
+                      0, G_MAXINT,
+                      1,
+                      G_PARAM_READABLE);
+  props[PROP_GEOMETRY] =
+    g_param_spec_boxed ("geometry",
+                        "Geometry",
+                        "The geometry of the monitor",
+                        GDK_TYPE_RECTANGLE,
+                        G_PARAM_READABLE);
+  props[PROP_WIDTH] =
+    g_param_spec_int ("width",
+                      "Width",
+                      "The width of the monitor, in millimeters",
+                      0, G_MAXINT,
+                      0,
+                      G_PARAM_READABLE);
+  props[PROP_HEIGHT] =
+    g_param_spec_int ("height",
+                      "Height",
+                      "The height of the monitor, in millimeters",
+                      0, G_MAXINT,
+                      0,
+                      G_PARAM_READABLE);
+
+  g_object_class_install_properties (object_class, LAST_PROP, props);
+}
+
+GdkDisplay *
+gdk_monitor_get_display (GdkMonitor *monitor)
+{
+  g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);
+
+  return monitor->display;
+}
+
+void
+gdk_monitor_get_geometry (GdkMonitor   *monitor,
+                          GdkRectangle *geometry)
+{
+  g_return_if_fail (GDK_IS_MONITOR (monitor));
+  g_return_if_fail (geometry != NULL);
+
+  *geometry = monitor->geometry;
+}
+
+void
+gdk_monitor_get_size (GdkMonitor *monitor,
+                      int        *width_mm,
+                      int        *height_mm)
+{
+  g_return_if_fail (GDK_IS_MONITOR (monitor));
+
+  *width_mm = monitor->width;
+  *height_mm = monitor->height;
+}
+
+const char *
+gdk_monitor_get_manufacturer (GdkMonitor *monitor)
+{
+  g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);
+
+  return monitor->manufacturer;
+}
+
+const char *
+gdk_monitor_get_model (GdkMonitor *monitor)
+{
+  g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);
+
+  return monitor->model;
+}
+
+int
+gdk_monitor_get_scale (GdkMonitor *monitor)
+{
+  g_return_val_if_fail (GDK_IS_MONITOR (monitor), 0);
+
+  return monitor->scale;
+}
+
+GdkMonitor *
+gdk_monitor_new (GdkDisplay *display)
+{
+  return GDK_MONITOR (g_object_new (GDK_TYPE_MONITOR,
+                                    "display", display,
+                                    NULL));
+}
+
+void
+gdk_monitor_set_manufacturer (GdkMonitor *monitor,
+                              const char *manufacturer)
+{
+  g_free (monitor->manufacturer);
+  monitor->manufacturer = g_strdup (manufacturer);
+
+  g_object_notify (G_OBJECT (monitor), "manufacturer");
+}
+
+void
+gdk_monitor_set_model (GdkMonitor *monitor,
+                       const char *model)
+{
+  g_free (monitor->model);
+  monitor->model = g_strdup (model);
+
+  g_object_notify (G_OBJECT (monitor), "model");
+}
+
+void
+gdk_monitor_set_geometry (GdkMonitor *monitor,
+                          int         x,
+                          int         y,
+                          int         width,
+                          int         height)
+{
+  monitor->geometry.x = x;
+  monitor->geometry.y = y;
+  monitor->geometry.height = height;
+  monitor->geometry.width = width;
+
+  g_object_notify (G_OBJECT (monitor), "geometry");
+}
+
+void
+gdk_monitor_set_size (GdkMonitor *monitor,
+                      int         width_mm,
+                      int         height_mm)
+{
+  monitor->width = width_mm;
+  monitor->height = height_mm;
+
+  g_object_notify (G_OBJECT (monitor), "width");
+  g_object_notify (G_OBJECT (monitor), "height");
+}
+
+void
+gdk_monitor_set_scale (GdkMonitor *monitor,
+                       int         scale)
+{
+  monitor->scale = scale;
+
+  g_object_notify (G_OBJECT (monitor), "scale");
+}
diff --git a/gdk/gdkmonitor.h b/gdk/gdkmonitor.h
new file mode 100644
index 0000000..16a5406
--- /dev/null
+++ b/gdk/gdkmonitor.h
@@ -0,0 +1,64 @@
+/*
+ * gdkmonitor.h
+ *
+ * Copyright 2016 Red Hat, Inc.
+ *
+ * Matthias Clasen <mclasen redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_MONITOR_H__
+#define __GDK_MONITOR_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdkversionmacros.h>
+#include <gdk/gdkrectangle.h>
+#include <gdk/gdkdisplay.h>
+#include <gdk/gdktypes.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_MONITOR           (gdk_monitor_get_type ())
+#define GDK_MONITOR(object)        (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_MONITOR, GdkMonitor))
+#define GDK_IS_MONITOR(object)     (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_MONITOR))
+
+typedef struct _GdkMonitor      GdkMonitor;
+typedef struct _GdkMonitorClass GdkMonitorClass;
+
+GDK_AVAILABLE_IN_3_22
+GType        gdk_monitor_get_type             (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_22
+GdkDisplay  *gdk_monitor_get_display          (GdkMonitor  *monitor);
+GDK_AVAILABLE_IN_3_22
+void         gdk_monitor_get_geometry         (GdkMonitor   *monitor,
+                                               GdkRectangle *geometry);
+GDK_AVAILABLE_IN_3_22
+void          gdk_monitor_get_size            (GdkMonitor   *monitor,
+                                               int          *width_mm,
+                                               int          *height_mm);
+GDK_AVAILABLE_IN_3_22
+const char * gdk_monitor_get_manufacturer     (GdkMonitor   *monitor);
+GDK_AVAILABLE_IN_3_22
+const char * gdk_monitor_get_model            (GdkMonitor   *monitor);
+GDK_AVAILABLE_IN_3_22
+int          gdk_monitor_get_scale            (GdkMonitor   *monitor);
+
+G_END_DECLS
+
+#endif  /* __GDK_MONITOR_H__ */
diff --git a/gdk/gdkmonitorprivate.h b/gdk/gdkmonitorprivate.h
new file mode 100644
index 0000000..377649f
--- /dev/null
+++ b/gdk/gdkmonitorprivate.h
@@ -0,0 +1,64 @@
+/*
+ * gdkmonitorprivate.h
+ *
+ * Copyright 2016 Red Hat, Inc.
+ *
+ * Matthias Clasen <mclasen redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_MONITOR_PRIVATE_H__
+#define __GDK_MONITOR_PRIVATE_H__
+
+#include "gdkmonitor.h"
+
+struct _GdkMonitor {
+  GObject parent;
+
+  GdkDisplay *display;
+  GdkRectangle geometry;
+  int width;
+  int height;
+  char *manufacturer;
+  char *model;
+  int scale;
+};
+
+struct _GdkMonitorClass {
+  GObjectClass parent_class;
+};
+
+G_BEGIN_DECLS
+
+GdkMonitor *   gdk_monitor_new                 (GdkDisplay *display);
+
+void            gdk_monitor_set_manufacturer    (GdkMonitor *monitor,
+                                                 const char *manufacturer);
+void            gdk_monitor_set_model           (GdkMonitor *monitor,
+                                                 const char *model);
+void           gdk_monitor_set_geometry        (GdkMonitor *monitor,
+                                                int         x,
+                                                int         y,
+                                                int         width,
+                                                int         height);
+void           gdk_monitor_set_size            (GdkMonitor *monitor,
+                                                int         width_mm,
+                                                int         height_mm);
+void           gdk_monitor_set_scale           (GdkMonitor *monitor,
+                                                        int         scale);
+
+G_END_DECLS
+
+#endif  /* __GDK_MONITOR_PRIVATE_H__ */


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