JX Application Framework
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
JXDisplay Class Reference

#include <JXDisplay.h>

Inheritance diagram for JXDisplay:
[legend]

Classes

struct  WMBehavior
 
class  XError
 
class  XEventMessage
 

Public Types

enum  {
  kWMStateXAtomIndex ,
  kWMClientMachineXAtomIndex ,
  kWMProtocolsXAtomIndex ,
  kDeleteWindowXAtomIndex ,
  kSaveYourselfXAtomIndex ,
  kWMPingXAtomIndex ,
  kWMPidXAtomIndex ,
  kWMUserTimeXAtomIndex ,
  kWMActiveWindowXAtomIndex ,
  kWMDesktopXAtomIndex ,
  kWMCurrentDesktopXAtomIndex ,
  kWMWindowTypeXAtomIndex ,
  kWMNormalTypeXAtomIndex ,
  kWMDialogTypeXAtomIndex ,
  kWMPulldownMenuTypeXAtomIndex ,
  kWMPopupMenuTypeXAtomIndex ,
  kWMTooltipTypeXAtomIndex ,
  kJXWMBehaviorV0XAtomIndex ,
  kStandardXAtomCount
}
 

Public Member Functions

 ~JXDisplay () override
 
bool Close ()
 
 operator Display * () const
 
const JStringGetName () const
 
Display * GetXDisplay () const
 
JXColorManagerGetColorManager () const
 
JSize GetMaxStringByteCount () const
 
bool IsMacOS () const
 
JFontManagerGetFontManager () const
 
JXFontManagerGetXFontManager () const
 
JXSelectionManagerGetSelectionManager () const
 
JXDNDManagerGetDNDManager () const
 
JXMenuManagerGetMenuManager () const
 
bool GetWDManager (JXWDManager **mgr) const
 
JXImageCacheGetImageCache () const
 
JCursorIndex CreateBuiltInCursor (const JUtf8Byte *name, const unsigned int shape)
 
JCursorIndex CreateCustomCursor (const JUtf8Byte *name, const JXCursor &cursor)
 
bool GetCursor (const JUtf8Byte *name, JCursorIndex *index) const
 
void DisplayCursorInAllWindows (const JCursorIndex index)
 
void Beep () const
 
void RaiseAllWindows ()
 
void HideAllWindows ()
 
void UndockAllWindows ()
 
void CloseAllOtherWindows (JXWindow *window)
 
void GetCurrentButtonKeyState (JXButtonStates *buttonStates, JXKeyModifiers *modifiers) const
 
const JXButtonStatesGetLatestButtonStates () const
 
const JXKeyModifiersGetLatestKeyModifiers () const
 
bool KeysymToModifier (const KeySym keysym, JIndex *modifierIndex) const
 
bool KeycodeToModifier (const KeyCode keycode, JIndex *modifierIndex) const
 
void Flush () const
 
void Synchronize () const
 
void SendXEvent (const Window xWindow, XEvent *xEvent, const long mask=0) const
 
bool FindMouseContainer (JXContainer **obj, Window *xWindow=nullptr, JPoint *ptG=nullptr, JPoint *ptR=nullptr) const
 
bool FindMouseContainer (const JXContainer *coordOwner, const JPoint &pt, JXContainer **obj, Window *xWindow=nullptr, JPoint *ptG=nullptr, JPoint *ptR=nullptr) const
 
void HandleEvent (const XEvent &xEvent, const Time currentTime)
 
void Idle (const Time currentTime)
 
void Update ()
 
void DispatchMouse ()
 
void DispatchCursor ()
 
void ShrinkDisplayBoundsToActiveScreen ()
 
void RestoreDisplayBounds ()
 
void WindowCreated (JXWindow *window, const Window xWindow)
 
void WindowDeleted (JXWindow *window)
 
void WindowNeedsUpdate (JXWindow *window)
 
bool GetMouseContainer (JXWindow **window) const
 
void SetMouseContainer (JXWindow *window)
 
bool GetMouseGrabber (JXWindow **window) const
 
void SetMouseGrabber (JXWindow *window)
 
Cursor GetXCursorID (const JCursorIndex index) const
 
Atom GetWMProtocolsXAtom () const
 
Atom GetWMClientMachineXAtom () const
 
Atom GetDeleteWindowXAtom () const
 
Atom GetWMPingXAtom () const
 
Atom GetWMPidXAtom () const
 
Atom GetWMUserTimeXAtom () const
 
Atom GetWMActiveWindowXAtom () const
 
Atom GetSaveYourselfXAtom () const
 
Atom GetWMStateXAtom () const
 
Atom GetWMDesktopXAtom () const
 
Atom GetWMCurrentDesktopXAtom () const
 
Atom GetWMWindowTypeXAtom () const
 
Atom GetWMWindowTypeXAtom (const JIndex type) const
 
const WMBehaviorGetWMBehavior () const
 
void SetWMBehavior (const WMBehavior &behavior)
 
bool SwitchDrag (JXContainer *fromObj, const JPoint &fromObjPt, const JXButtonStates &buttonStates, const JXKeyModifiers &modifiers, JXContainer *toObj)
 
bool GetKeyboardGrabber (JXWindow **window) const
 
void SetKeyboardGrabber (JXWindow *window)
 
JXWDManagerGetWDManager () const
 
void SetWDManager (JXWDManager *mgr)
 
int GetScreen () const
 
Visual * GetDefaultVisual () const
 
JSize GetDepth () const
 
JSize GetHorizResolution () const
 
JSize GetVertResolution () const
 
Window GetRootWindow () const
 
JRect GetBounds () const
 
const JXGCGetDefaultGC () const
 
Time GetLastEventTime () const
 
Atom RegisterXAtom (const JUtf8Byte *name)
 
void RegisterXAtoms (const JSize count, const JUtf8Byte **name, Atom *atom)
 
bool FindXWindow (const Window xWindow, JXWindow **window) const
 
const int * GetJXKeyModifierMapping () const
 
XIM GetXIM () const
 
- Public Member Functions inherited from JBroadcaster
 JBroadcaster ()
 
virtual ~JBroadcaster ()
 
JBroadcasteroperator= (const JBroadcaster &source)
 
bool HasSenders () const
 
JSize GetSenderCount () const
 
bool HasRecipients () const
 
JSize GetRecipientCount () const
 
virtual JString ToString () const
 
template<class T >
void ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f)
 

Static Public Member Functions

static bool Create (const JString &displayName, JXDisplay **display)
 
static bool WindowExists (JXDisplay *display, const Display *xDisplay, const Window xWindow)
 
static void CheckForXErrors ()
 
static int JXErrorHandler (Display *xDisplay, XErrorEvent *error)
 

Static Public Attributes

static const JUtf8BytekXEventMessage = "XEventMessage::JXDisplay"
 
static const JUtf8BytekXError = "XError::JXDisplay"
 

Protected Member Functions

 JXDisplay (const JString &displayName, Display *xDisplay)
 
- Protected Member Functions inherited from JBroadcaster
 JBroadcaster (const JBroadcaster &source)
 
void ListenTo (const JBroadcaster *sender)
 
void StopListening (const JBroadcaster *sender)
 
void ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember)
 
void StopListening (const JBroadcaster *sender, const std::type_info &messageType)
 
template<class T >
void Send (JBroadcaster *recipient, const T &message)
 
template<class T >
void Broadcast (const T &message)
 
virtual void Receive (JBroadcaster *sender, const Message &message)
 
void SendWithFeedback (JBroadcaster *recipient, Message *message)
 
void BroadcastWithFeedback (Message *message)
 
virtual void ReceiveWithFeedback (JBroadcaster *sender, Message *message)
 
virtual void ReceiveGoingAway (JBroadcaster *sender)
 

Detailed Description

Represents a single X Display.  We consider a display to be an X server
plus a particular screen.

Since cursors should be the same on every display, but each X server will
provide different cursor id's, we hide cursors behind JCursorIndex.

Cursors are bulky and difficult to compare, so we require that each
one be given a unique name.  This way, every client that needs a particular
cursor can use GetCursor() with only the name.  Only if GetCursor()
fails does one of the cursor creation routines need to be called.  There
are two such routines because X makes a distinction between the default
cursor font and custom cursors.

Cursor names can be anything, as long as they don't conflict.  All objects
that use a particular cursor must know the name.  Since the X cursor font
can be used by all objects, it is suggested that one uses the name of
the associated XC_* constant as the cursor name.

We cannot sort the cursor array because the indices that we give out must
remain valid.  Appending new items is the only option.  This is not much
of a problem, however, both because the most common cursors have predefined
indices, and because looking up cursors only has to be done once in each
constructor.

Because we are receiving events over a network which introduces an arbitrary
delay between the occurrence of an event and our processing of it,
mouse and keyboard events can be reported for the wrong (original) window
while we are switching a grab from one window to another.  (e.g. The user
releases the mouse so soon after we switch the grab that the server hasn't
received our message and therefore thinks that the original window is still
grabbing.  We therefore get the ButtonRelease for the original window
instead of for the new window.)  Our solution is to tell JXDisplay about
who has grabbed what so JXDisplay can re-route the message to the current
grabber.  This is what itsMouseGrabber and itsKeyboardGrabber are used for.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kWMStateXAtomIndex 
kWMClientMachineXAtomIndex 
kWMProtocolsXAtomIndex 
kDeleteWindowXAtomIndex 
kSaveYourselfXAtomIndex 
kWMPingXAtomIndex 
kWMPidXAtomIndex 
kWMUserTimeXAtomIndex 
kWMActiveWindowXAtomIndex 
kWMDesktopXAtomIndex 
kWMCurrentDesktopXAtomIndex 
kWMWindowTypeXAtomIndex 
kWMNormalTypeXAtomIndex 
kWMDialogTypeXAtomIndex 
kWMPulldownMenuTypeXAtomIndex 
kWMPopupMenuTypeXAtomIndex 
kWMTooltipTypeXAtomIndex 
kJXWMBehaviorV0XAtomIndex 
kStandardXAtomCount 

Constructor & Destructor Documentation

◆ ~JXDisplay()

JXDisplay::~JXDisplay ( )
override

We should only be deleted after all windows have been closed.

◆ JXDisplay()

JXDisplay::JXDisplay ( const JString displayName,
Display *  xDisplay 
)
protected

Member Function Documentation

◆ Beep()

void JXDisplay::Beep ( ) const
inline

◆ CheckForXErrors()

void JXDisplay::CheckForXErrors ( )
static

◆ Close()

bool JXDisplay::Close ( )

This is the safe way to delete a JXDisplay.

◆ CloseAllOtherWindows()

void JXDisplay::CloseAllOtherWindows ( JXWindow window)

Calls Close() on all windows except the given one.

◆ Create()

bool JXDisplay::Create ( const JString displayName,
JXDisplay **  display 
)
static

By forcing everyone to use this function, we avoid having to worry about XOpenDisplay succeeding within the class itself.

Note that this prevents one from creating derived classes.

◆ CreateBuiltInCursor()

JCursorIndex JXDisplay::CreateBuiltInCursor ( const JUtf8Byte name,
const unsigned int  shape 
)

◆ CreateCustomCursor()

JCursorIndex JXDisplay::CreateCustomCursor ( const JUtf8Byte name,
const JXCursor cursor 
)

◆ DispatchCursor()

void JXDisplay::DispatchCursor ( )

◆ DispatchMouse()

void JXDisplay::DispatchMouse ( )

◆ DisplayCursorInAllWindows()

void JXDisplay::DisplayCursorInAllWindows ( const JCursorIndex  index)

Displays the specified cursor in all windows on this display. Mainly useful for displaying the watch cursor or the inactive cursor.

◆ FindMouseContainer() [1/2]

bool JXDisplay::FindMouseContainer ( const JXContainer coordOwner,
const JPoint pt,
JXContainer **  obj,
Window *  xWindow = nullptr,
JPoint ptG = nullptr,
JPoint ptR = nullptr 
) const

◆ FindMouseContainer() [2/2]

bool JXDisplay::FindMouseContainer ( JXContainer **  obj,
Window *  xWindow = nullptr,
JPoint ptG = nullptr,
JPoint ptR = nullptr 
) const

Returns true if the mouse is in one of our windows.

Regardless of the return value, if xWindow is not nullptr, it is set to the id of the X window that the cursor is in. ptG is set to the mouse coordinates relative to xWindow, and ptR contains the mouse coordinates relative to the root window.

◆ FindXWindow()

bool JXDisplay::FindXWindow ( const Window  xWindow,
JXWindow **  window 
) const

Returns true if the given xWindow is registered. Since the window list is sorted by xWindow, we use an O(log(N)) binary search.

We can't call it FindWindow() because Windows #define's FindWindow to FindWindowA.

◆ Flush()

void JXDisplay::Flush ( ) const
inline

◆ GetBounds()

JRect JXDisplay::GetBounds ( ) const

◆ GetColorManager()

JXColorManager * JXDisplay::GetColorManager ( ) const
inline

◆ GetCurrentButtonKeyState()

void JXDisplay::GetCurrentButtonKeyState ( JXButtonStates buttonStates,
JXKeyModifiers modifiers 
) const

Call these if you need to get information more current than the latest event. This is useful if you need the state of the Shift key because pressing Shift doesn't generate an event.

buttonStates and/or modifiers can be nullptr.

◆ GetCursor()

bool JXDisplay::GetCursor ( const JUtf8Byte name,
JCursorIndex index 
) const

Returns true if a cursor with the given name has been created.

◆ GetDefaultGC()

const JXGC * JXDisplay::GetDefaultGC ( ) const
inline

◆ GetDefaultVisual()

Visual * JXDisplay::GetDefaultVisual ( ) const
inline

◆ GetDeleteWindowXAtom()

Atom JXDisplay::GetDeleteWindowXAtom ( ) const
inline

◆ GetDepth()

JSize JXDisplay::GetDepth ( ) const
inline

◆ GetDNDManager()

JXDNDManager * JXDisplay::GetDNDManager ( ) const
inline

◆ GetFontManager()

JFontManager * JXDisplay::GetFontManager ( ) const

Not inline to avoid including <JXFontManager.h> in header file.

◆ GetHorizResolution()

JSize JXDisplay::GetHorizResolution ( ) const

Screen resolution in pixels/inch (25.4 mm = 1 inch)

◆ GetImageCache()

JXImageCache * JXDisplay::GetImageCache ( ) const
inline

◆ GetJXKeyModifierMapping()

const int * JXDisplay::GetJXKeyModifierMapping ( ) const
inline

◆ GetKeyboardGrabber()

bool JXDisplay::GetKeyboardGrabber ( JXWindow **  window) const
inline

◆ GetLastEventTime()

Time JXDisplay::GetLastEventTime ( ) const
inline

Use these as a last resort if there is no other way to obtain the information. Most of the time, everything you need is passed to the event handler (e.g. HandleMouseDrag(), HandleKeyPress(), etc.)

◆ GetLatestButtonStates()

const JXButtonStates & JXDisplay::GetLatestButtonStates ( ) const
inline

◆ GetLatestKeyModifiers()

const JXKeyModifiers & JXDisplay::GetLatestKeyModifiers ( ) const
inline

◆ GetMaxStringByteCount()

JSize JXDisplay::GetMaxStringByteCount ( ) const
inline

◆ GetMenuManager()

JXMenuManager * JXDisplay::GetMenuManager ( ) const
inline

◆ GetMouseContainer()

bool JXDisplay::GetMouseContainer ( JXWindow **  window) const
inline

◆ GetMouseGrabber()

bool JXDisplay::GetMouseGrabber ( JXWindow **  window) const
inline

◆ GetName()

const JString & JXDisplay::GetName ( ) const
inline

◆ GetRootWindow()

Window JXDisplay::GetRootWindow ( ) const
inline

◆ GetSaveYourselfXAtom()

Atom JXDisplay::GetSaveYourselfXAtom ( ) const
inline

◆ GetScreen()

int JXDisplay::GetScreen ( ) const
inline

◆ GetSelectionManager()

JXSelectionManager * JXDisplay::GetSelectionManager ( ) const
inline

◆ GetVertResolution()

JSize JXDisplay::GetVertResolution ( ) const

◆ GetWDManager() [1/2]

JXWDManager * JXDisplay::GetWDManager ( ) const

◆ GetWDManager() [2/2]

bool JXDisplay::GetWDManager ( JXWDManager **  mgr) const
inline

◆ GetWMActiveWindowXAtom()

Atom JXDisplay::GetWMActiveWindowXAtom ( ) const
inline

◆ GetWMBehavior()

const JXDisplay::WMBehavior & JXDisplay::GetWMBehavior ( ) const
inline

◆ GetWMClientMachineXAtom()

Atom JXDisplay::GetWMClientMachineXAtom ( ) const
inline

◆ GetWMCurrentDesktopXAtom()

Atom JXDisplay::GetWMCurrentDesktopXAtom ( ) const
inline

◆ GetWMDesktopXAtom()

Atom JXDisplay::GetWMDesktopXAtom ( ) const
inline

◆ GetWMPidXAtom()

Atom JXDisplay::GetWMPidXAtom ( ) const
inline

◆ GetWMPingXAtom()

Atom JXDisplay::GetWMPingXAtom ( ) const
inline

◆ GetWMProtocolsXAtom()

Atom JXDisplay::GetWMProtocolsXAtom ( ) const
inline

◆ GetWMStateXAtom()

Atom JXDisplay::GetWMStateXAtom ( ) const
inline

◆ GetWMUserTimeXAtom()

Atom JXDisplay::GetWMUserTimeXAtom ( ) const
inline

◆ GetWMWindowTypeXAtom() [1/2]

Atom JXDisplay::GetWMWindowTypeXAtom ( ) const
inline

◆ GetWMWindowTypeXAtom() [2/2]

Atom JXDisplay::GetWMWindowTypeXAtom ( const JIndex  type) const
inline

◆ GetXCursorID()

Cursor JXDisplay::GetXCursorID ( const JCursorIndex  index) const
inline

◆ GetXDisplay()

Display * JXDisplay::GetXDisplay ( ) const
inline

◆ GetXFontManager()

JXFontManager * JXDisplay::GetXFontManager ( ) const
inline

◆ GetXIM()

XIM JXDisplay::GetXIM ( ) const
inline

◆ HandleEvent()

void JXDisplay::HandleEvent ( const XEvent &  xEvent,
const Time  currentTime 
)

JXSelectionManager handles all the selection events. All other events go to the appropriate window.

◆ HideAllWindows()

void JXDisplay::HideAllWindows ( )

Hide all windows on this display. Mainly useful when quitting.

◆ Idle()

void JXDisplay::Idle ( const Time  currentTime)

Redraw our windows and send a fake motion event.

If the mouse is not pressed, we send idle events relatively slowly so that we don't hog CPU time.

When the mouse is pressed, we send one at every opportunity because the user presumably doesn't care how much CPU time we use.

◆ IsMacOS()

bool JXDisplay::IsMacOS ( ) const
inline

◆ JXErrorHandler()

int JXDisplay::JXErrorHandler ( Display *  xDisplay,
XErrorEvent *  error 
)
static

◆ KeycodeToModifier()

bool JXDisplay::KeycodeToModifier ( const KeyCode  keycode,
JIndex modifierIndex 
) const

Converts an X keycode into an X modifier index.

◆ KeysymToModifier()

bool JXDisplay::KeysymToModifier ( const KeySym  keysym,
JIndex modifierIndex 
) const

Converts an X keysym into an X modifier index.

◆ operator Display *()

JXDisplay::operator Display * ( ) const
inline

◆ RaiseAllWindows()

void JXDisplay::RaiseAllWindows ( )

Raises all visible, non-iconified windows and maintains the stacking order.

◆ RegisterXAtom()

Atom JXDisplay::RegisterXAtom ( const JUtf8Byte name)
inline

◆ RegisterXAtoms()

void JXDisplay::RegisterXAtoms ( const JSize  count,
const JUtf8Byte **  name,
Atom *  atom 
)
inline

◆ RestoreDisplayBounds()

void JXDisplay::RestoreDisplayBounds ( )

◆ SendXEvent()

void JXDisplay::SendXEvent ( const Window  xWindow,
XEvent *  xEvent,
const long  mask = 0 
) const
inline

◆ SetKeyboardGrabber()

void JXDisplay::SetKeyboardGrabber ( JXWindow window)
inline

◆ SetMouseContainer()

void JXDisplay::SetMouseContainer ( JXWindow window)
inline

◆ SetMouseGrabber()

void JXDisplay::SetMouseGrabber ( JXWindow window)
inline

◆ SetWDManager()

void JXDisplay::SetWDManager ( JXWDManager mgr)

◆ SetWMBehavior()

void JXDisplay::SetWMBehavior ( const WMBehavior behavior)
inline

◆ ShrinkDisplayBoundsToActiveScreen()

void JXDisplay::ShrinkDisplayBoundsToActiveScreen ( )

◆ SwitchDrag()

bool JXDisplay::SwitchDrag ( JXContainer fromObj,
const JPoint fromObjPt,
const JXButtonStates buttonStates,
const JXKeyModifiers modifiers,
JXContainer toObj 
)

Switch the current mouse drag messages from one widget to another.

◆ Synchronize()

void JXDisplay::Synchronize ( ) const
inline

◆ UndockAllWindows()

void JXDisplay::UndockAllWindows ( )

◆ Update()

void JXDisplay::Update ( )

Give each window a chance to redraw itself. Since this routine is an idle task, we use a single flag to make sure that it doesn't do more work than it has to.

◆ WindowCreated()

void JXDisplay::WindowCreated ( JXWindow window,
const Window  xWindow 
)

Insert the new window so that the list remains sorted by xWindow values.

◆ WindowDeleted()

void JXDisplay::WindowDeleted ( JXWindow window)

◆ WindowExists()

bool JXDisplay::WindowExists ( JXDisplay display,
const Display *  xDisplay,
const Window  xWindow 
)
static

Returns true if the given window hasn't been deleted. Since we cannot assume that anything exists, everything that we need must be passed in.

◆ WindowNeedsUpdate()

void JXDisplay::WindowNeedsUpdate ( JXWindow window)
inline

Member Data Documentation

◆ kXError

const JUtf8Byte * JXDisplay::kXError = "XError::JXDisplay"
static

◆ kXEventMessage

const JUtf8Byte * JXDisplay::kXEventMessage = "XEventMessage::JXDisplay"
static

The documentation for this class was generated from the following files: