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.DisplayManager;
26 
27 private import gdk.Display;
28 private import gdk.c.functions;
29 public  import gdk.c.types;
30 private import glib.ListSG;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gobject.Signals;
34 public  import gtkc.gdktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * The purpose of the #GdkDisplayManager singleton object is to offer
40  * notification when displays appear or disappear or the default display
41  * changes.
42  * 
43  * You can use gdk_display_manager_get() to obtain the #GdkDisplayManager
44  * singleton, but that should be rarely necessary. Typically, initializing
45  * GTK+ opens a display that you can work with without ever accessing the
46  * #GdkDisplayManager.
47  * 
48  * The GDK library can be built with support for multiple backends.
49  * The #GdkDisplayManager object determines which backend is used
50  * at runtime.
51  * 
52  * When writing backend-specific code that is supposed to work with
53  * multiple GDK backends, you have to consider both compile time and
54  * runtime. At compile time, use the #GDK_WINDOWING_X11, #GDK_WINDOWING_WIN32
55  * macros, etc. to find out which backends are present in the GDK library
56  * you are building your application against. At runtime, use type-check
57  * macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
58  * 
59  * ## Backend-specific code ## {#backend-specific}
60  * 
61  * |[<!-- language="C" -->
62  * #ifdef GDK_WINDOWING_X11
63  * if (GDK_IS_X11_DISPLAY (display))
64  * {
65  * // make X11-specific calls here
66  * }
67  * else
68  * #endif
69  * #ifdef GDK_WINDOWING_QUARTZ
70  * if (GDK_IS_QUARTZ_DISPLAY (display))
71  * {
72  * // make Quartz-specific calls here
73  * }
74  * else
75  * #endif
76  * g_error ("Unsupported GDK backend");
77  * ]|
78  */
79 public class DisplayManager : ObjectG
80 {
81 	/** the main Gtk struct */
82 	protected GdkDisplayManager* gdkDisplayManager;
83 
84 	/** Get the main Gtk struct */
85 	public GdkDisplayManager* getDisplayManagerStruct(bool transferOwnership = false)
86 	{
87 		if (transferOwnership)
88 			ownedRef = false;
89 		return gdkDisplayManager;
90 	}
91 
92 	/** the main Gtk struct as a void* */
93 	protected override void* getStruct()
94 	{
95 		return cast(void*)gdkDisplayManager;
96 	}
97 
98 	protected override void setStruct(GObject* obj)
99 	{
100 		gdkDisplayManager = cast(GdkDisplayManager*)obj;
101 		super.setStruct(obj);
102 	}
103 
104 	/**
105 	 * Sets our main struct and passes it to the parent class.
106 	 */
107 	public this (GdkDisplayManager* gdkDisplayManager, bool ownedRef = false)
108 	{
109 		this.gdkDisplayManager = gdkDisplayManager;
110 		super(cast(GObject*)gdkDisplayManager, ownedRef);
111 	}
112 
113 
114 	/** */
115 	public static GType getType()
116 	{
117 		return gdk_display_manager_get_type();
118 	}
119 
120 	/**
121 	 * Gets the singleton #GdkDisplayManager object.
122 	 *
123 	 * When called for the first time, this function consults the
124 	 * `GDK_BACKEND` environment variable to find out which
125 	 * of the supported GDK backends to use (in case GDK has been compiled
126 	 * with multiple backends). Applications can use gdk_set_allowed_backends()
127 	 * to limit what backends can be used.
128 	 *
129 	 * Returns: The global #GdkDisplayManager singleton;
130 	 *     gdk_parse_args(), gdk_init(), or gdk_init_check() must have
131 	 *     been called first.
132 	 *
133 	 * Since: 2.2
134 	 */
135 	public static DisplayManager get()
136 	{
137 		auto p = gdk_display_manager_get();
138 
139 		if(p is null)
140 		{
141 			return null;
142 		}
143 
144 		return ObjectG.getDObject!(DisplayManager)(cast(GdkDisplayManager*) p);
145 	}
146 
147 	/**
148 	 * Gets the default #GdkDisplay.
149 	 *
150 	 * Returns: a #GdkDisplay, or %NULL if
151 	 *     there is no default display.
152 	 *
153 	 * Since: 2.2
154 	 */
155 	public Display getDefaultDisplay()
156 	{
157 		auto p = gdk_display_manager_get_default_display(gdkDisplayManager);
158 
159 		if(p is null)
160 		{
161 			return null;
162 		}
163 
164 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
165 	}
166 
167 	/**
168 	 * List all currently open displays.
169 	 *
170 	 * Returns: a newly
171 	 *     allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
172 	 *     when you are done with it.
173 	 *
174 	 * Since: 2.2
175 	 */
176 	public ListSG listDisplays()
177 	{
178 		auto p = gdk_display_manager_list_displays(gdkDisplayManager);
179 
180 		if(p is null)
181 		{
182 			return null;
183 		}
184 
185 		return new ListSG(cast(GSList*) p);
186 	}
187 
188 	/**
189 	 * Opens a display.
190 	 *
191 	 * Params:
192 	 *     name = the name of the display to open
193 	 *
194 	 * Returns: a #GdkDisplay, or %NULL if the
195 	 *     display could not be opened
196 	 *
197 	 * Since: 3.0
198 	 */
199 	public Display openDisplay(string name)
200 	{
201 		auto p = gdk_display_manager_open_display(gdkDisplayManager, Str.toStringz(name));
202 
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 
208 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
209 	}
210 
211 	/**
212 	 * Sets @display as the default display.
213 	 *
214 	 * Params:
215 	 *     display = a #GdkDisplay
216 	 *
217 	 * Since: 2.2
218 	 */
219 	public void setDefaultDisplay(Display display)
220 	{
221 		gdk_display_manager_set_default_display(gdkDisplayManager, (display is null) ? null : display.getDisplayStruct());
222 	}
223 
224 	protected class OnDisplayOpenedDelegateWrapper
225 	{
226 		void delegate(Display, DisplayManager) dlg;
227 		gulong handlerId;
228 
229 		this(void delegate(Display, DisplayManager) dlg)
230 		{
231 			this.dlg = dlg;
232 			onDisplayOpenedListeners ~= this;
233 		}
234 
235 		void remove(OnDisplayOpenedDelegateWrapper source)
236 		{
237 			foreach(index, wrapper; onDisplayOpenedListeners)
238 			{
239 				if (wrapper.handlerId == source.handlerId)
240 				{
241 					onDisplayOpenedListeners[index] = null;
242 					onDisplayOpenedListeners = std.algorithm.remove(onDisplayOpenedListeners, index);
243 					break;
244 				}
245 			}
246 		}
247 	}
248 	OnDisplayOpenedDelegateWrapper[] onDisplayOpenedListeners;
249 
250 	/**
251 	 * The ::display-opened signal is emitted when a display is opened.
252 	 *
253 	 * Params:
254 	 *     display = the opened display
255 	 *
256 	 * Since: 2.2
257 	 */
258 	gulong addOnDisplayOpened(void delegate(Display, DisplayManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
259 	{
260 		auto wrapper = new OnDisplayOpenedDelegateWrapper(dlg);
261 		wrapper.handlerId = Signals.connectData(
262 			this,
263 			"display-opened",
264 			cast(GCallback)&callBackDisplayOpened,
265 			cast(void*)wrapper,
266 			cast(GClosureNotify)&callBackDisplayOpenedDestroy,
267 			connectFlags);
268 		return wrapper.handlerId;
269 	}
270 
271 	extern(C) static void callBackDisplayOpened(GdkDisplayManager* displaymanagerStruct, GdkDisplay* display, OnDisplayOpenedDelegateWrapper wrapper)
272 	{
273 		wrapper.dlg(ObjectG.getDObject!(Display)(display), wrapper.outer);
274 	}
275 
276 	extern(C) static void callBackDisplayOpenedDestroy(OnDisplayOpenedDelegateWrapper wrapper, GClosure* closure)
277 	{
278 		wrapper.remove(wrapper);
279 	}
280 }