1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gdk.MonitorG;
26 
27 private import gdk.Display;
28 private import gdk.c.functions;
29 public  import gdk.c.types;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 public  import gtkc.gdktypes;
34 private import std.algorithm;
35 
36 
37 /**
38  * GdkMonitor objects represent the individual outputs that are
39  * associated with a #GdkDisplay. GdkDisplay has APIs to enumerate
40  * monitors with gdk_display_get_monitors() and to find particular
41  * monitors with gdk_display_get_primary_monitor() or
42  * gdk_display_get_monitor_at_window().
43  * 
44  * GdkMonitor was introduced in GTK+ 3.22 and supersedes earlier
45  * APIs in GdkScreen to obtain monitor-related information.
46  */
47 public class MonitorG : ObjectG
48 {
49 	/** the main Gtk struct */
50 	protected GdkMonitor* gdkMonitor;
51 
52 	/** Get the main Gtk struct */
53 	public GdkMonitor* getMonitorGStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gdkMonitor;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gdkMonitor;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		gdkMonitor = cast(GdkMonitor*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GdkMonitor* gdkMonitor, bool ownedRef = false)
76 	{
77 		this.gdkMonitor = gdkMonitor;
78 		super(cast(GObject*)gdkMonitor, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gdk_monitor_get_type();
86 	}
87 
88 	/**
89 	 * Gets the display that this monitor belongs to.
90 	 *
91 	 * Returns: the display
92 	 *
93 	 * Since: 3.22
94 	 */
95 	public Display getDisplay()
96 	{
97 		auto p = gdk_monitor_get_display(gdkMonitor);
98 
99 		if(p is null)
100 		{
101 			return null;
102 		}
103 
104 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
105 	}
106 
107 	/**
108 	 * Retrieves the size and position of an individual monitor within the
109 	 * display coordinate space. The returned geometry is in  ”application pixels”,
110 	 * not in ”device pixels” (see gdk_monitor_get_scale_factor()).
111 	 *
112 	 * Params:
113 	 *     geometry = a #GdkRectangle to be filled with the monitor geometry
114 	 *
115 	 * Since: 3.22
116 	 */
117 	public void getGeometry(out GdkRectangle geometry)
118 	{
119 		gdk_monitor_get_geometry(gdkMonitor, &geometry);
120 	}
121 
122 	/**
123 	 * Gets the height in millimeters of the monitor.
124 	 *
125 	 * Returns: the physical height of the monitor
126 	 *
127 	 * Since: 3.22
128 	 */
129 	public int getHeightMm()
130 	{
131 		return gdk_monitor_get_height_mm(gdkMonitor);
132 	}
133 
134 	/**
135 	 * Gets the name of the monitor's manufacturer, if available.
136 	 *
137 	 * Returns: the name of the manufacturer, or %NULL
138 	 */
139 	public string getManufacturer()
140 	{
141 		return Str.toString(gdk_monitor_get_manufacturer(gdkMonitor));
142 	}
143 
144 	/**
145 	 * Gets the a string identifying the monitor model, if available.
146 	 *
147 	 * Returns: the monitor model, or %NULL
148 	 */
149 	public string getModel()
150 	{
151 		return Str.toString(gdk_monitor_get_model(gdkMonitor));
152 	}
153 
154 	/**
155 	 * Gets the refresh rate of the monitor, if available.
156 	 *
157 	 * The value is in milli-Hertz, so a refresh rate of 60Hz
158 	 * is returned as 60000.
159 	 *
160 	 * Returns: the refresh rate in milli-Hertz, or 0
161 	 *
162 	 * Since: 3.22
163 	 */
164 	public int getRefreshRate()
165 	{
166 		return gdk_monitor_get_refresh_rate(gdkMonitor);
167 	}
168 
169 	/**
170 	 * Gets the internal scale factor that maps from monitor coordinates
171 	 * to the actual device pixels. On traditional systems this is 1, but
172 	 * on very high density outputs this can be a higher value (often 2).
173 	 *
174 	 * This can be used if you want to create pixel based data for a
175 	 * particular monitor, but most of the time you’re drawing to a window
176 	 * where it is better to use gdk_window_get_scale_factor() instead.
177 	 *
178 	 * Returns: the scale factor
179 	 *
180 	 * Since: 3.22
181 	 */
182 	public int getScaleFactor()
183 	{
184 		return gdk_monitor_get_scale_factor(gdkMonitor);
185 	}
186 
187 	/**
188 	 * Gets information about the layout of red, green and blue
189 	 * primaries for each pixel in this monitor, if available.
190 	 *
191 	 * Returns: the subpixel layout
192 	 *
193 	 * Since: 3.22
194 	 */
195 	public GdkSubpixelLayout getSubpixelLayout()
196 	{
197 		return gdk_monitor_get_subpixel_layout(gdkMonitor);
198 	}
199 
200 	/**
201 	 * Gets the width in millimeters of the monitor.
202 	 *
203 	 * Returns: the physical width of the monitor
204 	 *
205 	 * Since: 3.22
206 	 */
207 	public int getWidthMm()
208 	{
209 		return gdk_monitor_get_width_mm(gdkMonitor);
210 	}
211 
212 	/**
213 	 * Retrieves the size and position of the “work area” on a monitor
214 	 * within the display coordinate space. The returned geometry is in
215 	 * ”application pixels”, not in ”device pixels” (see
216 	 * gdk_monitor_get_scale_factor()).
217 	 *
218 	 * The work area should be considered when positioning menus and
219 	 * similar popups, to avoid placing them below panels, docks or other
220 	 * desktop components.
221 	 *
222 	 * Note that not all backends may have a concept of workarea. This
223 	 * function will return the monitor geometry if a workarea is not
224 	 * available, or does not apply.
225 	 *
226 	 * Params:
227 	 *     workarea = a #GdkRectangle to be filled with
228 	 *         the monitor workarea
229 	 *
230 	 * Since: 3.22
231 	 */
232 	public void getWorkarea(out GdkRectangle workarea)
233 	{
234 		gdk_monitor_get_workarea(gdkMonitor, &workarea);
235 	}
236 
237 	/**
238 	 * Gets whether this monitor should be considered primary
239 	 * (see gdk_display_get_primary_monitor()).
240 	 *
241 	 * Returns: %TRUE if @monitor is primary
242 	 *
243 	 * Since: 3.22
244 	 */
245 	public bool isPrimary()
246 	{
247 		return gdk_monitor_is_primary(gdkMonitor) != 0;
248 	}
249 
250 	protected class OnInvalidateDelegateWrapper
251 	{
252 		void delegate(MonitorG) dlg;
253 		gulong handlerId;
254 
255 		this(void delegate(MonitorG) dlg)
256 		{
257 			this.dlg = dlg;
258 			onInvalidateListeners ~= this;
259 		}
260 
261 		void remove(OnInvalidateDelegateWrapper source)
262 		{
263 			foreach(index, wrapper; onInvalidateListeners)
264 			{
265 				if (wrapper.handlerId == source.handlerId)
266 				{
267 					onInvalidateListeners[index] = null;
268 					onInvalidateListeners = std.algorithm.remove(onInvalidateListeners, index);
269 					break;
270 				}
271 			}
272 		}
273 	}
274 	OnInvalidateDelegateWrapper[] onInvalidateListeners;
275 
276 	/** */
277 	gulong addOnInvalidate(void delegate(MonitorG) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
278 	{
279 		auto wrapper = new OnInvalidateDelegateWrapper(dlg);
280 		wrapper.handlerId = Signals.connectData(
281 			this,
282 			"invalidate",
283 			cast(GCallback)&callBackInvalidate,
284 			cast(void*)wrapper,
285 			cast(GClosureNotify)&callBackInvalidateDestroy,
286 			connectFlags);
287 		return wrapper.handlerId;
288 	}
289 
290 	extern(C) static void callBackInvalidate(GdkMonitor* monitorgStruct, OnInvalidateDelegateWrapper wrapper)
291 	{
292 		wrapper.dlg(wrapper.outer);
293 	}
294 
295 	extern(C) static void callBackInvalidateDestroy(OnInvalidateDelegateWrapper wrapper, GClosure* closure)
296 	{
297 		wrapper.remove(wrapper);
298 	}
299 }