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