|
| 1 | +/* |
| 2 | + * Copyright 2024-2025 elementary, Inc. (https://elementary.io) |
| 3 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +[DBus (name = "org.gnome.Mutter.DisplayConfig")] |
| 7 | +public interface Gala.Daemon.DisplayConfig : Object { |
| 8 | + private static bool? _is_logical_layout = null; |
| 9 | + private static DisplayConfig? proxy = null; |
| 10 | + |
| 11 | + public static bool is_logical_layout () { |
| 12 | + if (_is_logical_layout == null) { |
| 13 | + init (); |
| 14 | + } |
| 15 | + |
| 16 | + return _is_logical_layout; |
| 17 | + } |
| 18 | + |
| 19 | + private static void init () { |
| 20 | + try { |
| 21 | + proxy = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.Mutter.DisplayConfig", "/org/gnome/Mutter/DisplayConfig"); |
| 22 | + proxy.monitors_changed.connect (update); |
| 23 | + } catch (Error e) { |
| 24 | + critical (e.message); |
| 25 | + _is_logical_layout = true; |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + update (); |
| 30 | + } |
| 31 | + |
| 32 | + private static void update () { |
| 33 | + uint current_serial; |
| 34 | + MutterReadMonitor[] mutter_monitors; |
| 35 | + MutterReadLogicalMonitor[] mutter_logical_monitors; |
| 36 | + GLib.HashTable<string, GLib.Variant> properties; |
| 37 | + try { |
| 38 | + proxy.get_current_state (out current_serial, out mutter_monitors, out mutter_logical_monitors, out properties); |
| 39 | + } catch (Error e) { |
| 40 | + critical (e.message); |
| 41 | + _is_logical_layout = true; |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + uint layout_mode = 1; // Absence of "layout-mode" means logical (= 1) according to the documentation. |
| 46 | + var layout_mode_variant = properties.lookup ("layout-mode"); |
| 47 | + if (layout_mode_variant != null) { |
| 48 | + layout_mode = layout_mode_variant.get_uint32 (); |
| 49 | + } |
| 50 | + |
| 51 | + _is_logical_layout = layout_mode == 1; |
| 52 | + } |
| 53 | + |
| 54 | + public signal void monitors_changed (); |
| 55 | + public abstract void get_current_state (out uint serial, out MutterReadMonitor[] monitors, out MutterReadLogicalMonitor[] logical_monitors, out GLib.HashTable<string, GLib.Variant> properties) throws Error; |
| 56 | +} |
| 57 | + |
| 58 | +public struct MutterReadMonitorInfo { |
| 59 | + public string connector; |
| 60 | + public string vendor; |
| 61 | + public string product; |
| 62 | + public string serial; |
| 63 | + public uint hash { |
| 64 | + get { |
| 65 | + return (connector + vendor + product + serial).hash (); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +public struct MutterReadMonitorMode { |
| 71 | + public string id; |
| 72 | + public int width; |
| 73 | + public int height; |
| 74 | + public double frequency; |
| 75 | + public double preferred_scale; |
| 76 | + public double[] supported_scales; |
| 77 | + public GLib.HashTable<string, GLib.Variant> properties; |
| 78 | +} |
| 79 | + |
| 80 | +public struct MutterReadMonitor { |
| 81 | + public MutterReadMonitorInfo monitor; |
| 82 | + public MutterReadMonitorMode[] modes; |
| 83 | + public GLib.HashTable<string, GLib.Variant> properties; |
| 84 | +} |
| 85 | + |
| 86 | +public struct MutterReadLogicalMonitor { |
| 87 | + public int x; |
| 88 | + public int y; |
| 89 | + public double scale; |
| 90 | + public uint transform; |
| 91 | + public bool primary; |
| 92 | + public MutterReadMonitorInfo[] monitors; |
| 93 | + public GLib.HashTable<string, GLib.Variant> properties; |
| 94 | +} |
0 commit comments