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 private import std.algorithm;
35 
36 
37 /**
38  * A singleton object that offers notification when displays appear or
39  * disappear.
40  * 
41  * You can use [func@Gdk.DisplayManager.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  * In the rare case that you need to influence which of the backends
51  * is being used, you can use [func@Gdk.set_allowed_backends]. Note
52  * that you need to call this function before initializing GTK.
53  * 
54  * ## Backend-specific code
55  * 
56  * When writing backend-specific code that is supposed to work with
57  * multiple GDK backends, you have to consider both compile time and
58  * runtime. At compile time, use the #GDK_WINDOWING_X11, #GDK_WINDOWING_WIN32
59  * macros, etc. to find out which backends are present in the GDK library
60  * you are building your application against. At runtime, use type-check
61  * macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
62  * 
63  * ```c
64  * #ifdef GDK_WINDOWING_X11
65  * if (GDK_IS_X11_DISPLAY (display))
66  * {
67  * // make X11-specific calls here
68  * }
69  * else
70  * #endif
71  * #ifdef GDK_WINDOWING_MACOS
72  * if (GDK_IS_MACOS_DISPLAY (display))
73  * {
74  * // make Quartz-specific calls here
75  * }
76  * else
77  * #endif
78  * g_error ("Unsupported GDK backend");
79  * ```
80  */
81 public class DisplayManager : ObjectG
82 {
83 	/** the main Gtk struct */
84 	protected GdkDisplayManager* gdkDisplayManager;
85 
86 	/** Get the main Gtk struct */
87 	public GdkDisplayManager* getDisplayManagerStruct(bool transferOwnership = false)
88 	{
89 		if (transferOwnership)
90 			ownedRef = false;
91 		return gdkDisplayManager;
92 	}
93 
94 	/** the main Gtk struct as a void* */
95 	protected override void* getStruct()
96 	{
97 		return cast(void*)gdkDisplayManager;
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 	public static GType getType()
112 	{
113 		return gdk_display_manager_get_type();
114 	}
115 
116 	/**
117 	 * Gets the singleton `GdkDisplayManager` object.
118 	 *
119 	 * When called for the first time, this function consults the
120 	 * `GDK_BACKEND` environment variable to find out which of the
121 	 * supported GDK backends to use (in case GDK has been compiled
122 	 * with multiple backends).
123 	 *
124 	 * Applications can use [func@set_allowed_backends] to limit what
125 	 * backends wil be used.
126 	 *
127 	 * Returns: The global `GdkDisplayManager` singleton
128 	 */
129 	public static DisplayManager get()
130 	{
131 		auto __p = gdk_display_manager_get();
132 
133 		if(__p is null)
134 		{
135 			return null;
136 		}
137 
138 		return ObjectG.getDObject!(DisplayManager)(cast(GdkDisplayManager*) __p);
139 	}
140 
141 	/**
142 	 * Gets the default `GdkDisplay`.
143 	 *
144 	 * Returns: a `GdkDisplay`, or %NULL if
145 	 *     there is no default display.
146 	 */
147 	public Display getDefaultDisplay()
148 	{
149 		auto __p = gdk_display_manager_get_default_display(gdkDisplayManager);
150 
151 		if(__p is null)
152 		{
153 			return null;
154 		}
155 
156 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
157 	}
158 
159 	/**
160 	 * List all currently open displays.
161 	 *
162 	 * Returns: a newly
163 	 *     allocated `GSList` of `GdkDisplay` objects. Free with g_slist_free()
164 	 *     when you are done with it.
165 	 */
166 	public ListSG listDisplays()
167 	{
168 		auto __p = gdk_display_manager_list_displays(gdkDisplayManager);
169 
170 		if(__p is null)
171 		{
172 			return null;
173 		}
174 
175 		return new ListSG(cast(GSList*) __p);
176 	}
177 
178 	/**
179 	 * Opens a display.
180 	 *
181 	 * Params:
182 	 *     name = the name of the display to open
183 	 *
184 	 * Returns: a `GdkDisplay`, or %NULL
185 	 *     if the display could not be opened
186 	 */
187 	public Display openDisplay(string name)
188 	{
189 		auto __p = gdk_display_manager_open_display(gdkDisplayManager, Str.toStringz(name));
190 
191 		if(__p is null)
192 		{
193 			return null;
194 		}
195 
196 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
197 	}
198 
199 	/**
200 	 * Sets @display as the default display.
201 	 *
202 	 * Params:
203 	 *     display = a `GdkDisplay`
204 	 */
205 	public void setDefaultDisplay(Display display)
206 	{
207 		gdk_display_manager_set_default_display(gdkDisplayManager, (display is null) ? null : display.getDisplayStruct());
208 	}
209 
210 	/**
211 	 * Emitted when a display is opened.
212 	 *
213 	 * Params:
214 	 *     display = the opened display
215 	 */
216 	gulong addOnDisplayOpened(void delegate(Display, DisplayManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
217 	{
218 		return Signals.connect(this, "display-opened", dlg, connectFlags ^ ConnectFlags.SWAPPED);
219 	}
220 }