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