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