[gnome-control-center/benzea/only-show-appliable-scales: 3/6] display-config: Add size constraints and (global) scaled mode checks



commit a7dc33a78bbe2b8f30c34276e5bcd262d69ed5a9
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Nov 30 11:40:06 2018 -0500

    display-config: Add size constraints and (global) scaled mode checks
    
    Make possible to set scaled size constraints per configuration, and add a method
    to verify if the current mode at scale is allowed for such config.
    
    This allows to perform such check also in case we have global scaling enabled,
    as in such case we must verify that all the selected current modes are supported
    by the given scale.
    
    Fixes GNOME/mutter#407

 panels/display/cc-display-config-dbus.c | 65 +++++++++++++++++++++++++++++++++
 panels/display/cc-display-config.c      | 16 ++++++++
 panels/display/cc-display-config.h      | 12 ++++++
 3 files changed, 93 insertions(+)
---
diff --git a/panels/display/cc-display-config-dbus.c b/panels/display/cc-display-config-dbus.c
index efb91b346..f5806fd7b 100644
--- a/panels/display/cc-display-config-dbus.c
+++ b/panels/display/cc-display-config-dbus.c
@@ -875,6 +875,9 @@ struct _CcDisplayConfigDBus
   GVariant *state;
   GDBusConnection *connection;
 
+  int min_width;
+  int min_height;
+
   guint32 serial;
   gboolean supports_mirroring;
   gboolean supports_changing_layout_mode;
@@ -1193,6 +1196,66 @@ cc_display_config_dbus_is_layout_logical (CcDisplayConfig *pself)
   return self->layout_mode == CC_DISPLAY_LAYOUT_MODE_LOGICAL;
 }
 
+static gboolean
+is_scaled_mode_allowed (CcDisplayConfigDBus *self,
+                        CcDisplayMode       *pmode,
+                        double               scale)
+{
+  CcDisplayModeDBus *mode = CC_DISPLAY_MODE_DBUS (pmode);
+
+  if (!cc_display_mode_dbus_is_supported_scale (pmode, scale))
+    return FALSE;
+
+  return (round (mode->width / scale) >= self->min_width &&
+          round (mode->height / scale) >= self->min_height);
+}
+
+static gboolean
+is_scale_allowed_by_active_monitors (CcDisplayConfigDBus *self,
+                                     double               scale)
+{
+  GList *l;
+
+  for (l = self->monitors; l != NULL; l = l->next)
+    {
+      CcDisplayMonitorDBus *m = CC_DISPLAY_MONITOR_DBUS (l->data);
+
+      if (!cc_display_monitor_is_active (CC_DISPLAY_MONITOR (m)))
+        continue;
+
+      if (!is_scaled_mode_allowed (self, m->current_mode, scale))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
+static void
+cc_display_config_dbus_set_minimum_size (CcDisplayConfig *pself,
+                                         int              width,
+                                         int              height)
+{
+  CcDisplayConfigDBus *self = CC_DISPLAY_CONFIG_DBUS (pself);
+
+  g_assert (width >= 0 && height >= 0);
+
+  self->min_width = width;
+  self->min_height = height;
+}
+
+static gboolean
+cc_display_config_dbus_is_scaled_mode_valid (CcDisplayConfig *pself,
+                                             CcDisplayMode   *mode,
+                                             double           scale)
+{
+  CcDisplayConfigDBus *self = CC_DISPLAY_CONFIG_DBUS (pself);
+
+  if (self->global_scale_required)
+    return is_scale_allowed_by_active_monitors (self, scale);
+
+  return is_scaled_mode_allowed (self, mode, scale);
+}
+
 static void
 cc_display_config_dbus_init (CcDisplayConfigDBus *self)
 {
@@ -1470,6 +1533,8 @@ cc_display_config_dbus_class_init (CcDisplayConfigDBusClass *klass)
   parent_class->set_cloning = cc_display_config_dbus_set_cloning;
   parent_class->get_cloning_modes = cc_display_config_dbus_get_cloning_modes;
   parent_class->is_layout_logical = cc_display_config_dbus_is_layout_logical;
+  parent_class->is_scaled_mode_valid = cc_display_config_dbus_is_scaled_mode_valid;
+  parent_class->set_minimum_size = cc_display_config_dbus_set_minimum_size;
 
   pspec = g_param_spec_variant ("state",
                                 "GVariant",
diff --git a/panels/display/cc-display-config.c b/panels/display/cc-display-config.c
index 3bed67a49..4eb100b1e 100644
--- a/panels/display/cc-display-config.c
+++ b/panels/display/cc-display-config.c
@@ -568,3 +568,19 @@ cc_display_config_is_layout_logical (CcDisplayConfig *self)
 {
   return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_layout_logical (self);
 }
+
+void
+cc_display_config_set_minimum_size (CcDisplayConfig *self,
+                                    int              width,
+                                    int              height)
+{
+  CC_DISPLAY_CONFIG_GET_CLASS (self)->set_minimum_size (self, width, height);
+}
+
+gboolean
+cc_display_config_is_scaled_mode_valid (CcDisplayConfig *self,
+                                        CcDisplayMode   *mode,
+                                        double           scale)
+{
+  return CC_DISPLAY_CONFIG_GET_CLASS (self)->is_scaled_mode_valid (self, mode, scale);
+}
diff --git a/panels/display/cc-display-config.h b/panels/display/cc-display-config.h
index faeae8e34..ef4332ff7 100644
--- a/panels/display/cc-display-config.h
+++ b/panels/display/cc-display-config.h
@@ -154,6 +154,12 @@ struct _CcDisplayConfigClass
                                  gboolean          clone);
   GList*   (*get_cloning_modes) (CcDisplayConfig  *self);
   gboolean (*is_layout_logical) (CcDisplayConfig  *self);
+  void     (*set_minimum_size)  (CcDisplayConfig  *self,
+                                 int               width,
+                                 int               height);
+  gboolean (*is_scaled_mode_valid) (CcDisplayConfig  *self,
+                                    CcDisplayMode    *mode,
+                                    double            scale);
 };
 
 
@@ -174,6 +180,12 @@ void              cc_display_config_set_mode_on_all_outputs (CcDisplayConfig *co
                                                              CcDisplayMode   *mode);
 
 gboolean          cc_display_config_is_layout_logical       (CcDisplayConfig    *self);
+void              cc_display_config_set_minimum_size        (CcDisplayConfig    *self,
+                                                             int                 width,
+                                                             int                 height);
+gboolean          cc_display_config_is_scaled_mode_valid    (CcDisplayConfig    *self,
+                                                             CcDisplayMode      *mode,
+                                                             double              scale);
 
 const char*       cc_display_monitor_get_display_name       (CcDisplayMonitor   *monitor);
 gboolean          cc_display_monitor_is_active              (CcDisplayMonitor   *monitor);


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