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