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() 85 { 86 return gdkDisplayManager; 87 } 88 89 /** the main Gtk struct as a void* */ 90 protected override void* getStruct() 91 { 92 return cast(void*)gdkDisplayManager; 93 } 94 95 protected override void setStruct(GObject* obj) 96 { 97 gdkDisplayManager = cast(GdkDisplayManager*)obj; 98 super.setStruct(obj); 99 } 100 101 /** 102 * Sets our main struct and passes it to the parent class. 103 */ 104 public this (GdkDisplayManager* gdkDisplayManager, bool ownedRef = false) 105 { 106 this.gdkDisplayManager = gdkDisplayManager; 107 super(cast(GObject*)gdkDisplayManager, ownedRef); 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 protected class OnDisplayOpenedDelegateWrapper 222 { 223 void delegate(Display, DisplayManager) dlg; 224 gulong handlerId; 225 ConnectFlags flags; 226 this(void delegate(Display, DisplayManager) dlg, gulong handlerId, ConnectFlags flags) 227 { 228 this.dlg = dlg; 229 this.handlerId = handlerId; 230 this.flags = flags; 231 } 232 } 233 protected OnDisplayOpenedDelegateWrapper[] onDisplayOpenedListeners; 234 235 /** 236 * The ::display-opened signal is emitted when a display is opened. 237 * 238 * Params: 239 * display = the opened display 240 * 241 * Since: 2.2 242 */ 243 gulong addOnDisplayOpened(void delegate(Display, DisplayManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 244 { 245 onDisplayOpenedListeners ~= new OnDisplayOpenedDelegateWrapper(dlg, 0, connectFlags); 246 onDisplayOpenedListeners[onDisplayOpenedListeners.length - 1].handlerId = Signals.connectData( 247 this, 248 "display-opened", 249 cast(GCallback)&callBackDisplayOpened, 250 cast(void*)onDisplayOpenedListeners[onDisplayOpenedListeners.length - 1], 251 cast(GClosureNotify)&callBackDisplayOpenedDestroy, 252 connectFlags); 253 return onDisplayOpenedListeners[onDisplayOpenedListeners.length - 1].handlerId; 254 } 255 256 extern(C) static void callBackDisplayOpened(GdkDisplayManager* displaymanagerStruct, GdkDisplay* display,OnDisplayOpenedDelegateWrapper wrapper) 257 { 258 wrapper.dlg(ObjectG.getDObject!(Display)(display), wrapper.outer); 259 } 260 261 extern(C) static void callBackDisplayOpenedDestroy(OnDisplayOpenedDelegateWrapper wrapper, GClosure* closure) 262 { 263 wrapper.outer.internalRemoveOnDisplayOpened(wrapper); 264 } 265 266 protected void internalRemoveOnDisplayOpened(OnDisplayOpenedDelegateWrapper source) 267 { 268 foreach(index, wrapper; onDisplayOpenedListeners) 269 { 270 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 271 { 272 onDisplayOpenedListeners[index] = null; 273 onDisplayOpenedListeners = std.algorithm.remove(onDisplayOpenedListeners, index); 274 break; 275 } 276 } 277 } 278 279 }