1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
|
{-# LANGUAGE CPP #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) Display - a description of a keyboard/mouse/monitors combination
--
-- Author : Axel Simon
--
-- Created: 22 October 2009
--
-- Copyright (C) 2009 Axel Simon
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
-- Controls the keyboard\/mouse\/monitors combination.
--
-- * Module available since Gdk version 2.2
--
module Graphics.UI.Gtk.Gdk.Display (
-- * Detail
--
-- | 'Display' objects purpose are two fold:
--
-- * To grab\/ungrab keyboard focus and mouse pointer
--
-- * To manage and provide information about the 'Screen'(s) available for
-- this 'Display'
--
-- 'Display' objects are the GDK representation of the X Display which can
-- be described as /a workstation consisting of a keyboard a pointing device
-- (such as a mouse) and one or more screens/. It is used to open and keep
-- track of various 'Screen' objects currently instanciated by the application.
-- It is also used to grab and release the keyboard and the mouse pointer.
-- * Class Hierarchy
--
-- |
-- @
-- | 'GObject'
-- | +----Display
-- @
#if GTK_CHECK_VERSION(2,2,0)
-- * Types
Display,
DisplayClass,
castToDisplay, gTypeDisplay,
toDisplay,
-- * Methods
displayOpen,
displayGetDefault,
displayGetName,
displayGetNScreens,
displayGetScreen,
displayGetDefaultScreen,
displayPointerUngrab,
displayKeyboardUngrab,
displayPointerIsGrabbed,
displayBeep,
displaySync,
#if GTK_CHECK_VERSION(2,4,0)
displayFlush,
#endif
displayClose,
displayListDevices,
displaySetDoubleClickTime,
#if GTK_CHECK_VERSION(2,4,0)
displaySetDoubleClickDistance,
#endif
displayGetPointer,
displayGetWindowAtPointer,
#if GTK_CHECK_VERSION(2,8,0)
displayWarpPointer,
#endif
#if GTK_CHECK_VERSION(2,4,0)
displaySupportsCursorColor,
displaySupportsCursorAlpha,
displayGetDefaultCursorSize,
displayGetMaximalCursorSize,
displayGetDefaultGroup,
#if GTK_CHECK_VERSION(2,6,0)
displaySupportsSelectionNotification,
displayRequestSelectionNotification,
displaySupportsClipboardPersistence,
displayStoreClipboard,
#if GTK_CHECK_VERSION(2,10,0)
displaySupportsShapes,
displaySupportsInputShapes,
#if GTK_CHECK_VERSION(2,12,0)
displaySupportsComposite,
#endif
#endif
#endif
#endif
-- * Signals
displayClosed,
#endif
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Flags
import System.Glib.GList
{#import Graphics.UI.Gtk.Types#}
import Graphics.UI.Gtk.Signals
import Graphics.UI.Gtk.Gdk.EventM
import Graphics.UI.Gtk.Gdk.Enums (Modifier(..))
import Graphics.UI.Gtk.General.DNDTypes (SelectionTag, TargetTag, Atom(..))
{# context lib="gdk" prefix="gdk" #}
#if GTK_CHECK_VERSION(2,2,0)
--------------------
-- Methods
-- | Opens a display.
--
displayOpen ::
String -- ^ @displayName@ - the name of the display to open
-> IO (Maybe Display)
-- ^ returns a 'Display', or @Nothing@ if the display
-- could not be opened.
displayOpen displayName =
maybeNull (makeNewGObject mkDisplay) $
withUTFString displayName $ \displayNamePtr ->
{# call gdk_display_open #}
displayNamePtr
-- | Gets the default 'Display'. This is a convenience function for
-- @displayManagerGetDefaultDisplay displayManagerGet@.
--
displayGetDefault ::
IO (Maybe Display)
-- ^ returns a 'Display', or @Nothing@ if there is no
-- default display.
displayGetDefault =
maybeNull (makeNewGObject mkDisplay) $
{# call gdk_display_get_default #}
-- | Gets the name of the display.
--
displayGetName :: Display
-> IO String -- ^ returns a string representing the display name
displayGetName self =
{# call gdk_display_get_name #}
self
>>= peekUTFString
-- | Gets the number of screen managed by the @display@.
--
displayGetNScreens :: Display
-> IO Int -- ^ returns number of screens.
displayGetNScreens self =
liftM fromIntegral $
{# call gdk_display_get_n_screens #}
self
-- | Returns a screen object for one of the screens of the display.
--
displayGetScreen :: Display
-> Int -- ^ @screenNum@ - the screen number
-> IO Screen -- ^ returns the 'Screen' object
displayGetScreen self screenNum =
makeNewGObject mkScreen $
{# call gdk_display_get_screen #}
self
(fromIntegral screenNum)
-- | Get the default 'Screen' for @display@.
--
displayGetDefaultScreen :: Display
-> IO Screen -- ^ returns the default 'Screen' object for @display@
displayGetDefaultScreen self =
makeNewGObject mkScreen $
{# call gdk_display_get_default_screen #}
self
-- | Release any pointer grab.
--
displayPointerUngrab :: Display
-> TimeStamp -- ^ @time@ - a timestap (e.g. 'currentTime').
-> IO ()
displayPointerUngrab self time =
{# call gdk_display_pointer_ungrab #}
self
(fromIntegral time)
-- | Release any keyboard grab
--
displayKeyboardUngrab :: Display
-> TimeStamp -- ^ @time@ - a timestap (e.g 'currentTime').
-> IO ()
displayKeyboardUngrab self time =
{# call gdk_display_keyboard_ungrab #}
self
(fromIntegral time)
-- | Test if the pointer is grabbed.
--
displayPointerIsGrabbed :: Display
-> IO Bool -- ^ returns @True@ if an active X pointer grab is in effect
displayPointerIsGrabbed self =
liftM toBool $
{# call gdk_display_pointer_is_grabbed #}
self
-- | Emits a short beep on @display@
--
displayBeep :: Display -> IO ()
displayBeep self =
{# call gdk_display_beep #}
self
-- | Flushes any requests queued for the windowing system and waits until all
-- requests have been handled. This is often used for making sure that the
-- display is synchronized with the current state of the program. Calling
-- 'displaySync' before 'errorTrapPop' makes sure that any errors generated
-- from earlier requests are handled before the error trap is removed.
--
-- This is most useful for X11. On windowing systems where requests are
-- handled synchronously, this function will do nothing.
--
displaySync :: Display -> IO ()
displaySync self =
{# call gdk_display_sync #}
self
#if GTK_CHECK_VERSION(2,4,0)
-- | Flushes any requests queued for the windowing system; this happens
-- automatically when the main loop blocks waiting for new events, but if your
-- application is drawing without returning control to the main loop, you may
-- need to call this function explicitely. A common case where this function
-- needs to be called is when an application is executing drawing commands from
-- a thread other than the thread where the main loop is running.
--
-- This is most useful for X11. On windowing systems where requests are
-- handled synchronously, this function will do nothing.
--
-- * Available since Gdk version 2.4
--
displayFlush :: Display -> IO ()
displayFlush self =
{# call gdk_display_flush #}
self
#endif
-- | Closes the connection to the windowing system for the given display, and
-- cleans up associated resources.
--
displayClose :: Display -> IO ()
displayClose self =
{# call gdk_display_close #}
self
-- | Returns the list of available input devices attached to @display@.
--
displayListDevices :: Display
-> IO [Device] -- ^ returns a list of 'Device'
displayListDevices self =
{# call gdk_display_list_devices #}
self
>>= readGList
>>= mapM (makeNewGObject mkDevice . return)
-- | Sets the double click time (two clicks within this time interval count as
-- a double click and result in an 'eventButton' where 'eventClick' is
-- 'DoubleClick'). Applications should /not/ set this, it is a global
-- user-configured setting.
--
displaySetDoubleClickTime :: Display
-> Int -- ^ @msec@ - double click time in milliseconds (thousandths of a
-- second)
-> IO ()
displaySetDoubleClickTime self msec =
{# call gdk_display_set_double_click_time #}
self
(fromIntegral msec)
#if GTK_CHECK_VERSION(2,4,0)
-- | Sets the double click distance (two clicks within this distance count as
-- a double click and result in an 'eventButton' where 'eventClick' is
-- 'DoubleClick'). See also 'displaySetDoubleClickTime'. Applications should
-- /not/ set this, it is a global user-configured setting.
--
-- * Available since Gdk version 2.4
--
displaySetDoubleClickDistance :: Display
-> Int -- ^ @distance@ - distance in pixels
-> IO ()
displaySetDoubleClickDistance self distance =
{# call gdk_display_set_double_click_distance #}
self
(fromIntegral distance)
#endif
-- | Gets the current location of the pointer and the current modifier mask
-- for a given display.
--
displayGetPointer :: Display
-> IO (Screen, [Modifier], Int, Int)
-- ^ @(s, m, x, y)@ - the screen @s@, the modifier mask @m@ and the @x@ and
-- @y@ coordinates of the pointer
displayGetPointer self =
alloca $ \sPtr ->
alloca $ \xPtr ->
alloca $ \yPtr ->
alloca $ \mPtr ->
{# call gdk_display_get_pointer #}
self
(castPtr sPtr)
xPtr
yPtr
mPtr >>
makeNewGObject mkScreen (peek sPtr) >>= \s ->
peek xPtr >>= \x ->
peek yPtr >>= \y ->
peek mPtr >>= \m ->
return (s, toFlags (fromIntegral m), fromIntegral x, fromIntegral y)
-- | Obtains the window underneath the mouse pointer, returning the location
-- of the pointer in that window in @winX@, @winY@ for @screen@. Returns
-- @Nothing@ if
-- the window under the mouse pointer is not known to GDK (for example, belongs
-- to another application).
--
displayGetWindowAtPointer :: Display
-> IO (Maybe (DrawWindow, Int, Int))
-- ^ @(screen, winX, winY)@ returns the window under the mouse
-- pointer, or @Nothing@. The @winX@ and @winY@ denote the pointer location
-- relative to the window origin
displayGetWindowAtPointer self =
alloca $ \winXPtr ->
alloca $ \winYPtr -> do
wPtr <- {# call gdk_display_get_window_at_pointer #}
self
winXPtr
winYPtr
if wPtr==nullPtr then return Nothing else
peek winXPtr >>= \winX ->
peek winYPtr >>= \winY ->
makeNewGObject mkDrawWindow (return wPtr) >>= \win ->
return (Just (win, fromIntegral winX, fromIntegral winY))
{- not worth the trouble
-- | This function allows for hooking into the operation of getting the
-- current location of the pointer on a particular display. This is only useful
-- for such low-level tools as an event recorder. Applications should never
-- have any reason to use this facility.
--
displaySetPointerHooks :: Display
-> {-const-GdkDisplayPointerHooks*-} -- ^ @newHooks@ - a table of pointers to
-- functions for getting quantities
-- related to the current pointer
-- position, or {@NULL@, FIXME: this
-- should probably be converted to a
-- Maybe data type} to restore the
-- default table.
-> IO {-GdkDisplayPointerHooks*-} -- ^ returns the previous pointer hook
-- table
displaySetPointerHooks self newHooks =
{# call gdk_display_set_pointer_hooks #}
self
{-newHooks-}
-}
#if GTK_CHECK_VERSION(2,8,0)
-- | Moves the pointer of @display@ to the point @x@,@y@ on the screen
-- @screen@, unless the pointer is confined to a window by a grab, in which
-- case it will be moved as far as allowed by the grab. Warping the pointer
-- creates events as if the user had moved the mouse instantaneously to the
-- destination.
--
-- Note that the pointer should normally be under the control of the user.
-- This function was added to cover some rare use cases like keyboard
-- navigation support for the color picker in the 'ColorSelectionDialog'.
--
-- * Available since Gdk version 2.8
--
displayWarpPointer :: Display
-> Screen -- ^ @screen@ - the screen of @display@ to warp the pointer to
-> Int -- ^ @x@ - the x coordinate of the destination
-> Int -- ^ @y@ - the y coordinate of the destination
-> IO ()
displayWarpPointer self screen x y =
{# call gdk_display_warp_pointer #}
self
screen
(fromIntegral x)
(fromIntegral y)
#endif
#if GTK_CHECK_VERSION(2,4,0)
-- | Returns @True@ if multicolored cursors are supported on @display@.
-- Otherwise, cursors have only a forground and a background color.
--
-- * Available since Gdk version 2.4
--
displaySupportsCursorColor :: Display
-> IO Bool -- ^ returns whether cursors can have multiple colors.
displaySupportsCursorColor self =
liftM toBool $
{# call gdk_display_supports_cursor_color #}
self
-- | Returns @True@ if cursors can use an 8bit alpha channel on @display@.
-- Otherwise, cursors are restricted to bilevel alpha (i.e. a mask).
--
-- * Available since Gdk version 2.4
--
displaySupportsCursorAlpha :: Display
-> IO Bool -- ^ returns whether cursors can have alpha channels.
displaySupportsCursorAlpha self =
liftM toBool $
{# call gdk_display_supports_cursor_alpha #}
self
-- | Returns the default size to use for cursors on @display@.
--
-- * Available since Gdk version 2.4
--
displayGetDefaultCursorSize :: Display
-> IO Int -- ^ returns the default cursor size.
displayGetDefaultCursorSize self =
liftM fromIntegral $
{# call gdk_display_get_default_cursor_size #}
self
-- | Gets the maximal size to use for cursors on @display@.
--
-- * Available since Gdk version 2.4
--
displayGetMaximalCursorSize :: Display
-> IO (Int, Int) -- ^ @(width, height)@
-- maximal @width@ and @height@ of the cursor
displayGetMaximalCursorSize self =
alloca $ \widthPtr ->
alloca $ \heightPtr ->
{# call gdk_display_get_maximal_cursor_size #}
self
widthPtr
heightPtr >>
peek widthPtr >>= \width ->
peek heightPtr >>= \height ->
return (fromIntegral width, fromIntegral height)
-- | Returns the default group leader window for all toplevel windows on
-- @display@. This window is implicitly created by GDK. See 'windowSetGroup'.
--
-- * Available since Gdk version 2.4
--
displayGetDefaultGroup :: Display
-> IO DrawWindow -- ^ returns The default group leader window for @display@
displayGetDefaultGroup self =
makeNewGObject mkDrawWindow $
{# call gdk_display_get_default_group #}
self
#if GTK_CHECK_VERSION(2,6,0)
-- | Returns whether 'EOwnerChange' events will be
-- sent when the owner of a selection changes.
--
-- * Available since Gdk version 2.6
--
displaySupportsSelectionNotification :: Display
-> IO Bool -- ^ returns whether 'EOwnerChange'
-- events will be sent.
displaySupportsSelectionNotification self =
liftM toBool $
{# call gdk_display_supports_selection_notification #}
self
-- | Request 'EOwnerChange' events for ownership
-- changes of the selection named by the given atom.
--
-- * Available since Gdk version 2.6
--
displayRequestSelectionNotification :: Display
-> SelectionTag -- ^ @selection@ - the 'Atom' naming
-- the selection for which ownership change notification is
-- requested
-> IO Bool -- ^ returns whether 'EOwnerChange'
-- events will be sent.
displayRequestSelectionNotification self (Atom selection) =
liftM toBool $
{# call gdk_display_request_selection_notification #}
self
selection
-- | Returns whether the speicifed display supports clipboard persistance;
-- i.e. if it's possible to store the clipboard data after an application has
-- quit. On X11 this checks if a clipboard daemon is running.
--
-- * Available since Gdk version 2.6
--
displaySupportsClipboardPersistence :: Display
-> IO Bool -- ^ returns @True@ if the display supports clipboard persistance.
displaySupportsClipboardPersistence self =
liftM toBool $
{# call gdk_display_supports_clipboard_persistence #}
self
-- | Issues a request to the clipboard manager to store the clipboard data. On
-- X11, this is a special program that works according to the freedesktop
-- clipboard specification, available at
-- http:\/\/www.freedesktop.org\/Standards\/clipboard-manager-spec.
--
-- * Available since Gdk version 2.6
--
displayStoreClipboard :: Display
-> DrawWindow -- ^ @clipboardWindow@ - a 'DrawWindow' belonging to
-- the clipboard owner
-> Word32 -- ^ @time@ - a timestamp
-> (Maybe [TargetTag]) -- ^ @targets@ - an array of targets that should be
-- saved, or @Nothing@ if all available
-- targets should be saved.
-> IO ()
displayStoreClipboard self clipboardWindow time (Just targets) =
withArrayLen (map (\(Atom a) -> a) targets) $ \nTargets tPtr ->
{# call gdk_display_store_clipboard #}
self
clipboardWindow
(fromIntegral time)
tPtr
(fromIntegral nTargets)
displayStoreClipboard self clipboardWindow time Nothing =
{# call gdk_display_store_clipboard #}
self
clipboardWindow
(fromIntegral time)
nullPtr
0
#if GTK_CHECK_VERSION(2,10,0)
-- | Returns @True@ if 'windowShapeCombineMask' can be used to create shaped
-- windows on @display@.
--
-- * Available since Gdk version 2.10
--
displaySupportsShapes :: Display
-> IO Bool -- ^ returns @True@ if shaped windows are supported
displaySupportsShapes self =
liftM toBool $
{# call gdk_display_supports_shapes #}
self
-- | Returns @True@ if 'windowInputShapeCombineMask' can be used to modify the
-- input shape of windows on @display@.
--
-- * Available since Gdk version 2.10
--
displaySupportsInputShapes :: Display
-> IO Bool -- ^ returns @True@ if windows with modified input shape are
-- supported
displaySupportsInputShapes self =
liftM toBool $
{# call gdk_display_supports_input_shapes #}
self
#if GTK_CHECK_VERSION(2,12,0)
-- | Returns @True@ if 'windowSetComposited' can be used to redirect drawing
-- on the window using compositing.
--
-- Currently this only works on X11 with XComposite and XDamage extensions
-- available.
--
-- * Available since Gdk version 2.12
--
displaySupportsComposite :: Display
-> IO Bool -- ^ returns @True@ if windows may be composited.
displaySupportsComposite self =
liftM toBool $
{# call gdk_display_supports_composite #}
self
#endif
#endif
#endif
#endif
--------------------
-- Signals
-- | The 'displayClosed' signal is emitted when the connection to the windowing
-- system for @display@ is closed.
--
displayClosed :: DisplayClass self => Signal self (Bool -> IO ())
displayClosed = Signal (connect_BOOL__NONE "closed")
#endif
|