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 * Conversion parameters: 26 * inFile = GdkDevice.html 27 * outPack = gdk 28 * outFile = Device 29 * strct = GdkDevice 30 * realStrct= 31 * ctorStrct= 32 * clss = Device 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_device_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.ListG 47 * - glib.Str 48 * - gdk.Cursor 49 * - gdk.Display 50 * - gdk.Screen 51 * - gdk.Window 52 * structWrap: 53 * - GList* -> ListG 54 * - GdkCursor* -> Cursor 55 * - GdkDevice* -> Device 56 * - GdkDisplay* -> Display 57 * - GdkScreen* -> Screen 58 * - GdkWindow* -> Window 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gdk.Device; 65 66 public import gtkc.gdktypes; 67 68 private import gtkc.gdk; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import gobject.Signals; 73 public import gtkc.gdktypes; 74 75 private import glib.ListG; 76 private import glib.Str; 77 private import gdk.Cursor; 78 private import gdk.Display; 79 private import gdk.Screen; 80 private import gdk.Window; 81 82 83 84 private import gobject.ObjectG; 85 86 /** 87 * The GdkDevice object represents a single input device, such 88 * as a keyboard, a mouse, a touchpad, etc. 89 * 90 * See the GdkDeviceManager documentation for more information 91 * about the various kinds of master and slave devices, and their 92 * relationships. 93 */ 94 public class Device : ObjectG 95 { 96 97 /** the main Gtk struct */ 98 protected GdkDevice* gdkDevice; 99 100 101 public GdkDevice* getDeviceStruct() 102 { 103 return gdkDevice; 104 } 105 106 107 /** the main Gtk struct as a void* */ 108 protected override void* getStruct() 109 { 110 return cast(void*)gdkDevice; 111 } 112 113 /** 114 * Sets our main struct and passes it to the parent class 115 */ 116 public this (GdkDevice* gdkDevice) 117 { 118 super(cast(GObject*)gdkDevice); 119 this.gdkDevice = gdkDevice; 120 } 121 122 protected override void setStruct(GObject* obj) 123 { 124 super.setStruct(obj); 125 gdkDevice = cast(GdkDevice*)obj; 126 } 127 128 /** 129 */ 130 int[string] connectedSignals; 131 132 void delegate(Device)[] onChangedListeners; 133 /** 134 * The ::changed signal is emitted either when the GdkDevice 135 * has changed the number of either axes or keys. For example 136 * In X this will normally happen when the slave device routing 137 * events through the master device changes (for example, user 138 * switches from the USB mouse to a tablet), in that case the 139 * master device will change to reflect the new slave device 140 * axes and keys. 141 * See Also 142 * GdkDeviceManager 143 */ 144 void addOnChanged(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 145 { 146 if ( !("changed" in connectedSignals) ) 147 { 148 Signals.connectData( 149 getStruct(), 150 "changed", 151 cast(GCallback)&callBackChanged, 152 cast(void*)this, 153 null, 154 connectFlags); 155 connectedSignals["changed"] = 1; 156 } 157 onChangedListeners ~= dlg; 158 } 159 extern(C) static void callBackChanged(GdkDevice* deviceStruct, Device _device) 160 { 161 foreach ( void delegate(Device) dlg ; _device.onChangedListeners ) 162 { 163 dlg(_device); 164 } 165 } 166 167 168 /** 169 * Determines the name of the device. 170 * Since 2.20 171 * Returns: a name 172 */ 173 public string getName() 174 { 175 // const gchar * gdk_device_get_name (GdkDevice *device); 176 return Str.toString(gdk_device_get_name(gdkDevice)); 177 } 178 179 /** 180 * Determines the type of the device. 181 * Since 2.20 182 * Returns: a GdkInputSource 183 */ 184 public GdkInputSource getSource() 185 { 186 // GdkInputSource gdk_device_get_source (GdkDevice *device); 187 return gdk_device_get_source(gdkDevice); 188 } 189 190 /** 191 * Sets a the mode of an input device. The mode controls if the 192 * device is active and whether the device's range is mapped to the 193 * entire screen or to a single window. 194 * Params: 195 * mode = the input mode. 196 * Returns: TRUE if the mode was successfully changed. 197 */ 198 public int setMode(GdkInputMode mode) 199 { 200 // gboolean gdk_device_set_mode (GdkDevice *device, GdkInputMode mode); 201 return gdk_device_set_mode(gdkDevice, mode); 202 } 203 204 /** 205 * Determines the mode of the device. 206 * Since 2.20 207 * Returns: a GdkInputSource 208 */ 209 public GdkInputMode getMode() 210 { 211 // GdkInputMode gdk_device_get_mode (GdkDevice *device); 212 return gdk_device_get_mode(gdkDevice); 213 } 214 215 /** 216 * Specifies the X key event to generate when a macro button of a device 217 * is pressed. 218 * Params: 219 * index = the index of the macro button to set 220 * keyval = the keyval to generate 221 * modifiers = the modifiers to set 222 */ 223 public void setKey(uint index, uint keyval, GdkModifierType modifiers) 224 { 225 // void gdk_device_set_key (GdkDevice *device, guint index_, guint keyval, GdkModifierType modifiers); 226 gdk_device_set_key(gdkDevice, index, keyval, modifiers); 227 } 228 229 /** 230 * If index_ has a valid keyval, this function will return TRUE 231 * and fill in keyval and modifiers with the keyval settings. 232 * Since 2.20 233 * Params: 234 * index = the index of the macro button to get. 235 * keyval = return value for the keyval. [out] 236 * modifiers = return value for modifiers. [out] 237 * Returns: TRUE if keyval is set for index. 238 */ 239 public int getKey(uint index, out uint keyval, out GdkModifierType modifiers) 240 { 241 // gboolean gdk_device_get_key (GdkDevice *device, guint index_, guint *keyval, GdkModifierType *modifiers); 242 return gdk_device_get_key(gdkDevice, index, &keyval, &modifiers); 243 } 244 245 /** 246 * Specifies how an axis of a device is used. 247 * Params: 248 * index = the index of the axis 249 * use = specifies how the axis is used 250 */ 251 public void setAxisUse(uint index, GdkAxisUse use) 252 { 253 // void gdk_device_set_axis_use (GdkDevice *device, guint index_, GdkAxisUse use); 254 gdk_device_set_axis_use(gdkDevice, index, use); 255 } 256 257 /** 258 * Returns the axis use for index_. 259 * Since 2.20 260 * Params: 261 * index = the index of the axis. 262 * Returns: a GdkAxisUse specifying how the axis is used. 263 */ 264 public GdkAxisUse getAxisUse(uint index) 265 { 266 // GdkAxisUse gdk_device_get_axis_use (GdkDevice *device, guint index_); 267 return gdk_device_get_axis_use(gdkDevice, index); 268 } 269 270 /** 271 * Returns the associated device to device, if device is of type 272 * GDK_DEVICE_TYPE_MASTER, it will return the paired pointer or 273 * keyboard. 274 * If device is of type GDK_DEVICE_TYPE_SLAVE, it will return 275 * the master device to which device is attached to. 276 * If device is of type GDK_DEVICE_TYPE_FLOATING, NULL will be 277 * returned, as there is no associated device. 278 * Returns: The associated device, or NULL. [transfer none] Since 3.0 279 */ 280 public Device getAssociatedDevice() 281 { 282 // GdkDevice * gdk_device_get_associated_device (GdkDevice *device); 283 auto p = gdk_device_get_associated_device(gdkDevice); 284 285 if(p is null) 286 { 287 return null; 288 } 289 290 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 291 } 292 293 /** 294 * If the device if of type GDK_DEVICE_TYPE_MASTER, it will return 295 * the list of slave devices attached to it, otherwise it will return 296 * NULL 297 * Returns: the list of slave devices, or NULL. The list must be freed with g_list_free(), the contents of the list are owned by GTK+ and should not be freed. [transfer container][element-type GdkDevice] 298 */ 299 public ListG listSlaveDevices() 300 { 301 // GList * gdk_device_list_slave_devices (GdkDevice *device); 302 auto p = gdk_device_list_slave_devices(gdkDevice); 303 304 if(p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(ListG)(cast(GList*) p); 310 } 311 312 /** 313 * Returns the device type for device. 314 * Returns: the GdkDeviceType for device. Since 3.0 315 */ 316 public GdkDeviceType getDeviceType() 317 { 318 // GdkDeviceType gdk_device_get_device_type (GdkDevice *device); 319 return gdk_device_get_device_type(gdkDevice); 320 } 321 322 /** 323 * Returns the GdkDisplay to which device pertains. 324 * Returns: a GdkDisplay. This memory is owned by GTK+, and must not be freed or unreffed. [transfer none] Since 3.0 325 */ 326 public Display getDisplay() 327 { 328 // GdkDisplay * gdk_device_get_display (GdkDevice *device); 329 auto p = gdk_device_get_display(gdkDevice); 330 331 if(p is null) 332 { 333 return null; 334 } 335 336 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 337 } 338 339 /** 340 * Determines whether the pointer follows device motion. 341 * Since 2.20 342 * Returns: TRUE if the pointer follows device motion 343 */ 344 public int getHasCursor() 345 { 346 // gboolean gdk_device_get_has_cursor (GdkDevice *device); 347 return gdk_device_get_has_cursor(gdkDevice); 348 } 349 350 /** 351 * Returns the number of axes the device currently has. 352 * Returns: the number of axes. Since 3.0 353 */ 354 public int getNAxes() 355 { 356 // gint gdk_device_get_n_axes (GdkDevice *device); 357 return gdk_device_get_n_axes(gdkDevice); 358 } 359 360 /** 361 * Returns the number of keys the device currently has. 362 * Since 2.24 363 * Returns: the number of keys. 364 */ 365 public int getNKeys() 366 { 367 // gint gdk_device_get_n_keys (GdkDevice *device); 368 return gdk_device_get_n_keys(gdkDevice); 369 } 370 371 /** 372 * Warps device in display to the point x,y on 373 * the screen screen, unless the device is confined 374 * to a window by a grab, in which case it will be moved 375 * as far as allowed by the grab. Warping the pointer 376 * creates events as if the user had moved the mouse 377 * instantaneously to the destination. 378 * Note that the pointer should normally be under the 379 * control of the user. This function was added to cover 380 * some rare use cases like keyboard navigation support 381 * for the color picker in the GtkColorSelectionDialog. 382 * Params: 383 * screen = the screen to warp device to. 384 * x = the X coordinate of the destination. 385 * y = the Y coordinate of the destination. 386 * Since 3.0 387 */ 388 public void warp(Screen screen, int x, int y) 389 { 390 // void gdk_device_warp (GdkDevice *device, GdkScreen *screen, gint x, gint y); 391 gdk_device_warp(gdkDevice, (screen is null) ? null : screen.getScreenStruct(), x, y); 392 } 393 394 /** 395 * Grabs the device so that all events coming from this device are passed to 396 * this application until the device is ungrabbed with gdk_device_ungrab(), 397 * or the window becomes unviewable. This overrides any previous grab on the device 398 * by this client. 399 * Device grabs are used for operations which need complete control over the 400 * given device events (either pointer or keyboard). For example in GTK+ this 401 * is used for Drag and Drop operations, popup menus and such. 402 * Note that if the event mask of an X window has selected both button press 403 * and button release events, then a button press event will cause an automatic 404 * pointer grab until the button is released. X does this automatically since 405 * most applications expect to receive button press and release events in pairs. 406 * It is equivalent to a pointer grab on the window with owner_events set to 407 * TRUE. 408 * If you set up anything at the time you take the grab that needs to be 409 * cleaned up when the grab ends, you should handle the GdkEventGrabBroken 410 * events that are emitted when the grab ends unvoluntarily. 411 * Params: 412 * window = the GdkWindow which will own the grab (the grab window) 413 * grabOwnership = specifies the grab ownership. 414 * ownerEvents = if FALSE then all device events are reported with respect to 415 * window and are only reported if selected by event_mask. If 416 * TRUE then pointer events for this application are reported 417 * as normal, but pointer events outside this application are 418 * reported with respect to window and only if selected by 419 * event_mask. In either mode, unreported events are discarded. 420 * eventMask = specifies the event mask, which is used in accordance with 421 * owner_events. 422 * cursor = the cursor to display while the grab is active if the device is 423 * a pointer. If this is NULL then the normal cursors are used for 424 * window and its descendants, and the cursor for window is used 425 * elsewhere. [allow-none] 426 * time = the timestamp of the event which led to this pointer grab. This 427 * usually comes from the GdkEvent struct, though GDK_CURRENT_TIME 428 * can be used if the time isn't known. 429 * Returns: GDK_GRAB_SUCCESS if the grab was successful. Since 3.0 430 */ 431 public GdkGrabStatus grab(Window window, GdkGrabOwnership grabOwnership, int ownerEvents, GdkEventMask eventMask, Cursor cursor, uint time) 432 { 433 // GdkGrabStatus gdk_device_grab (GdkDevice *device, GdkWindow *window, GdkGrabOwnership grab_ownership, gboolean owner_events, GdkEventMask event_mask, GdkCursor *cursor, guint32 time_); 434 return gdk_device_grab(gdkDevice, (window is null) ? null : window.getWindowStruct(), grabOwnership, ownerEvents, eventMask, (cursor is null) ? null : cursor.getCursorStruct(), time); 435 } 436 437 /** 438 * Release any grab on device. 439 * Params: 440 * time = a timestap (e.g. GDK_CURRENT_TIME). 441 * Since 3.0 442 */ 443 public void ungrab(uint time) 444 { 445 // void gdk_device_ungrab (GdkDevice *device, guint32 time_); 446 gdk_device_ungrab(gdkDevice, time); 447 } 448 449 /** 450 * Gets the current state of a pointer device relative to window. As a slave 451 * device's coordinates are those of its master pointer, this 452 * function may not be called on devices of type GDK_DEVICE_TYPE_SLAVE, 453 * unless there is an ongoing grab on them. See gdk_device_grab(). 454 * Params: 455 * window = a GdkWindow. 456 * axes = an array of doubles to store the values of the axes of device in, 457 * or NULL. 458 * mask = location to store the modifiers, or NULL. 459 */ 460 public void getState(Window window, double[] axes, out GdkModifierType mask) 461 { 462 // void gdk_device_get_state (GdkDevice *device, GdkWindow *window, gdouble *axes, GdkModifierType *mask); 463 gdk_device_get_state(gdkDevice, (window is null) ? null : window.getWindowStruct(), axes.ptr, &mask); 464 } 465 466 /** 467 * Gets the current location of device. As a slave device 468 * coordinates are those of its master pointer, This function 469 * may not be called on devices of type GDK_DEVICE_TYPE_SLAVE, 470 * unless there is an ongoing grab on them, see gdk_device_grab(). 471 * Params: 472 * screen = location to store the GdkScreen 473 * the device is on, or NULL. [out][transfer none][allow-none] 474 * x = location to store root window X coordinate of device, or NULL. [out][allow-none] 475 * y = location to store root window Y coordinate of device, or NULL. [out][allow-none] 476 * Since 3.0 477 */ 478 public void getPosition(out Screen screen, out int x, out int y) 479 { 480 // void gdk_device_get_position (GdkDevice *device, GdkScreen **screen, gint *x, gint *y); 481 GdkScreen* outscreen = null; 482 483 gdk_device_get_position(gdkDevice, &outscreen, &x, &y); 484 485 screen = ObjectG.getDObject!(Screen)(outscreen); 486 } 487 488 /** 489 * Gets the current location of device in double precision. As a slave device's 490 * coordinates are those of its master pointer, this function 491 * may not be called on devices of type GDK_DEVICE_TYPE_SLAVE, 492 * unless there is an ongoing grab on them. See gdk_device_grab(). 493 * Params: 494 * screen = location to store the GdkScreen 495 * the device is on, or NULL. [out][transfer none][allow-none] 496 * x = location to store root window X coordinate of device, or NULL. [out][allow-none] 497 * y = location to store root window Y coordinate of device, or NULL. [out][allow-none] 498 * Since 3.10 499 */ 500 public void getPositionDouble(out Screen screen, out double x, out double y) 501 { 502 // void gdk_device_get_position_double (GdkDevice *device, GdkScreen **screen, gdouble *x, gdouble *y); 503 GdkScreen* outscreen = null; 504 505 gdk_device_get_position_double(gdkDevice, &outscreen, &x, &y); 506 507 screen = ObjectG.getDObject!(Screen)(outscreen); 508 } 509 510 /** 511 * Obtains the window underneath device, returning the location of the device in win_x and win_y. Returns 512 * NULL if the window tree under device is not known to GDK (for example, belongs to another application). 513 * As a slave device coordinates are those of its master pointer, This 514 * function may not be called on devices of type GDK_DEVICE_TYPE_SLAVE, 515 * unless there is an ongoing grab on them, see gdk_device_grab(). 516 * Params: 517 * winX = return location for the X coordinate of the device location, 518 * relative to the window origin, or NULL. [out][allow-none] 519 * winY = return location for the Y coordinate of the device location, 520 * relative to the window origin, or NULL. [out][allow-none] 521 * Returns: the GdkWindow under the device position, or NULL. [transfer none] Since 3.0 522 */ 523 public Window getWindowAtPosition(out int winX, out int winY) 524 { 525 // GdkWindow * gdk_device_get_window_at_position (GdkDevice *device, gint *win_x, gint *win_y); 526 auto p = gdk_device_get_window_at_position(gdkDevice, &winX, &winY); 527 528 if(p is null) 529 { 530 return null; 531 } 532 533 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 534 } 535 536 /** 537 * Obtains the window underneath device, returning the location of the device in win_x and win_y in 538 * double precision. Returns NULL if the window tree under device is not known to GDK (for example, 539 * belongs to another application). 540 * As a slave device coordinates are those of its master pointer, This 541 * function may not be called on devices of type GDK_DEVICE_TYPE_SLAVE, 542 * unless there is an ongoing grab on them, see gdk_device_grab(). 543 * Params: 544 * winX = return location for the X coordinate of the device location, 545 * relative to the window origin, or NULL. [out][allow-none] 546 * winY = return location for the Y coordinate of the device location, 547 * relative to the window origin, or NULL. [out][allow-none] 548 * Returns: the GdkWindow under the device position, or NULL. [transfer none] Since 3.0 549 */ 550 public Window getWindowAtPositionDouble(out double winX, out double winY) 551 { 552 // GdkWindow * gdk_device_get_window_at_position_double (GdkDevice *device, gdouble *win_x, gdouble *win_y); 553 auto p = gdk_device_get_window_at_position_double(gdkDevice, &winX, &winY); 554 555 if(p is null) 556 { 557 return null; 558 } 559 560 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 561 } 562 563 /** 564 * Obtains the motion history for a pointer device; given a starting and 565 * ending timestamp, return all events in the motion history for 566 * the device in the given range of time. Some windowing systems 567 * do not support motion history, in which case, FALSE will 568 * be returned. (This is not distinguishable from the case where 569 * motion history is supported and no events were found.) 570 * Params: 571 * window = the window with respect to which which the event coordinates will be reported 572 * start = starting timestamp for range of events to return 573 * stop = ending timestamp for the range of events to return 574 * events = location to store a newly-allocated array of GdkTimeCoord, or NULL. [array length=n_events][out][transfer full] 575 * Returns: TRUE if the windowing system supports motion history and at least one event was found. 576 */ 577 public int getHistory(Window window, uint start, uint stop, out GdkTimeCoord*[] events) 578 { 579 // gboolean gdk_device_get_history (GdkDevice *device, GdkWindow *window, guint32 start, guint32 stop, GdkTimeCoord ***events, gint *n_events); 580 GdkTimeCoord** outevents = null; 581 int nEvents; 582 583 auto p = gdk_device_get_history(gdkDevice, (window is null) ? null : window.getWindowStruct(), start, stop, &outevents, &nEvents); 584 585 events = outevents[0 .. nEvents]; 586 return p; 587 } 588 589 /** 590 * Frees an array of GdkTimeCoord that was returned by gdk_device_get_history(). 591 * Params: 592 * events = an array of GdkTimeCoord. 593 */ 594 public static void freeHistory(GdkTimeCoord*[] events) 595 { 596 // void gdk_device_free_history (GdkTimeCoord **events, gint n_events); 597 gdk_device_free_history(events.ptr, cast(int) events.length); 598 } 599 600 /** 601 * Interprets an array of double as axis values for a given device, 602 * and locates the value in the array for a given axis use. 603 * Params: 604 * axes = pointer to an array of axes. [array] 605 * use = the use to look for 606 * value = location to store the found value. [out] 607 * Returns: TRUE if the given axis use was found, otherwise FALSE 608 */ 609 public int getAxis(double[] axes, GdkAxisUse use, out double value) 610 { 611 // gboolean gdk_device_get_axis (GdkDevice *device, gdouble *axes, GdkAxisUse use, gdouble *value); 612 return gdk_device_get_axis(gdkDevice, axes.ptr, use, &value); 613 } 614 615 /** 616 * Returns a GList of GdkAtoms, containing the labels for 617 * the axes that device currently has. 618 * Returns: A GList of GdkAtoms, free with g_list_free(). [transfer container][element-type GdkAtom] Since 3.0 619 */ 620 public ListG listAxes() 621 { 622 // GList * gdk_device_list_axes (GdkDevice *device); 623 auto p = gdk_device_list_axes(gdkDevice); 624 625 if(p is null) 626 { 627 return null; 628 } 629 630 return ObjectG.getDObject!(ListG)(cast(GList*) p); 631 } 632 633 /** 634 * Interprets an array of double as axis values for a given device, 635 * and locates the value in the array for a given axis label, as returned 636 * by gdk_device_list_axes() 637 * Params: 638 * axes = pointer to an array of axes. [array] 639 * axisLabel = GdkAtom with the axis label. 640 * value = location to store the found value. 641 * Returns: TRUE if the given axis use was found, otherwise FALSE. Since 3.0 642 */ 643 public int getAxisValue(double[] axes, GdkAtom axisLabel, out double value) 644 { 645 // gboolean gdk_device_get_axis_value (GdkDevice *device, gdouble *axes, GdkAtom axis_label, gdouble *value); 646 return gdk_device_get_axis_value(gdkDevice, axes.ptr, axisLabel, &value); 647 } 648 }