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