Back to index

libsfml  1.6+dfsg2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
sf::priv::WindowImplX11 Class Reference

WindowImplX11 is the Linux (X11) implementation of WindowImpl /////////////////////////////////////////////////////////. More...

#include <WindowImplX11.hpp>

Inheritance diagram for sf::priv::WindowImplX11:
Inheritance graph
[legend]
Collaboration diagram for sf::priv::WindowImplX11:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WindowImplX11 ()
 Default constructor (creates a dummy window to provide a valid OpenGL context)
 WindowImplX11 (WindowHandle Handle, WindowSettings &Params)
 Construct the window implementation from an existing control.
 WindowImplX11 (VideoMode Mode, const std::string &Title, unsigned long WindowStyle, WindowSettings &Params)
 Create the window implementation.
 ~WindowImplX11 ()
 Destructor.
void AddListener (WindowListener *Listener)
 Add a listener to the window.
void RemoveListener (WindowListener *Listener)
 Remove a listener from the window.
unsigned int GetWidth () const
 Get the client width of the window.
unsigned int GetHeight () const
 Get the client height of the window.
void SetJoystickThreshold (float Threshold)
 Change the joystick threshold, ie. the value below which no move event will be generated.
void DoEvents ()
 Process incoming events from operating system.

Static Public Member Functions

static bool IsContextActive ()
 Check if there's an active context on the current thread.
static WindowImplNew ()
 Create a new window depending on the current OS.
static WindowImplNew (VideoMode Mode, const std::string &Title, unsigned long WindowStyle, WindowSettings &Params)
 Create a new window depending on the current OS.
static WindowImplNew (WindowHandle Handle, WindowSettings &Params)
 Create a new window depending on to the current OS.

Protected Member Functions

void SendEvent (const Event &EventToSend)
 Send an event to listeners (for derived classes only)

Static Protected Member Functions

static int EvaluateConfig (const VideoMode &Mode, const WindowSettings &Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing)
 Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one.

Protected Attributes

unsigned int myWidth
 Internal width of the window.
unsigned int myHeight
 Internal height of the window.

Private Member Functions

virtual void Display ()
 /see WindowImpl::Display
virtual void ProcessEvents ()
 /see WindowImpl::ProcessEvents
virtual void SetActive (bool Active=true) const
 /see WindowImpl::SetActive
virtual void UseVerticalSync (bool Enabled)
 /see WindowImpl::UseVerticalSync
virtual void ShowMouseCursor (bool Show)
 /see WindowImpl::ShowMouseCursor
virtual void SetCursorPosition (unsigned int Left, unsigned int Top)
 /see sfWindowImpl::SetCursorPosition
virtual void SetPosition (int Left, int Top)
 /see sfWindowImpl::SetPosition
virtual void SetSize (unsigned int Width, unsigned int Height)
 /see WindowImpl::SetSize
virtual void Show (bool State)
 /see sfWindowImpl::Show
virtual void EnableKeyRepeat (bool Enabled)
 /see sfWindowImpl::EnableKeyRepeat
virtual void SetIcon (unsigned int Width, unsigned int Height, const Uint8 *Pixels)
 /see WindowImpl::SetIcon
void SwitchToFullscreen (const VideoMode &Mode)
 Switch to fullscreen mode.
bool CreateContext (const VideoMode &Mode, XVisualInfo &ChosenVisual, WindowSettings &Params, XVisualInfo Template=XVisualInfo(), unsigned long Mask=0)
 Create the OpenGL rendering context.
void Initialize ()
 Do some common initializations after the window has been created.
void CreateHiddenCursor ()
 Create a transparent mouse cursor.
void CleanUp ()
 Cleanup graphical resources attached to the window.
void ProcessEvent (XEvent WinEvent)
 Process an incoming event from the window.

Static Private Member Functions

static Key::Code KeysymToSF (KeySym Sym)
 Convert a X11 keysym to SFML key code.
static bool OpenDisplay (bool AddWindow=true)
 Open the display (if not already done)
static void CloseDisplay ()
 Close the display.

Private Attributes

::Window myWindow
 X11 structure defining our window.
bool myIsExternal
 Tell whether the window has been created externally or by SFML.
GLXContext myGLContext
 OpenGL context attached to the window.
Atom myAtomClose
 Atom used to identify the close event.
int myOldVideoMode
 Video mode in use before we switch to fullscreen.
Cursor myHiddenCursor
 As X11 doesn't provide cursor hidding, we must create a transparent one.
XIC myInputContext
 Input context used to get unicode input in our window.
bool myKeyRepeat
 Is the KeyRepeat feature enabled ?
XEvent myLastKeyReleaseEvent
 Last key release event we received (needed for discarding repeated key events)

Static Private Attributes

::DisplayourDisplay = NULL
 Current opened display.
static int ourScreen = 0
 Default screen on the opened display.
static WindowImplX11ourFullscreenWindow = NULL
 Keep track of the active fullscreen window.
static unsigned int ourWindowsCount = 0
 Number of windows created.
static unsigned long ourEventMask
 Mask defining the events that will be caught by our windows.
static XIM ourInputMethod = NULL
 Input object used to get unicode characters from keypress messages.

Friends

class VideoModeSupport

Detailed Description

WindowImplX11 is the Linux (X11) implementation of WindowImpl /////////////////////////////////////////////////////////.

Definition at line 48 of file WindowImplX11.hpp.


Constructor & Destructor Documentation

Default constructor (creates a dummy window to provide a valid OpenGL context)

Default constructor (creates a dummy window to provide a valid OpenGL context) /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 74 of file WindowImplX11.cpp.

                             :
myWindow      (0),
myIsExternal  (false),
myGLContext   (NULL),
myAtomClose   (0),
myOldVideoMode(-1),
myHiddenCursor(0),
myInputContext(NULL),
myKeyRepeat   (true)
{
    // Open the display at first call
    if (!OpenDisplay())
        return;

    // Use small dimensions
    myWidth  = 1;
    myHeight = 1;

    // Create the rendering context
    XVisualInfo Visual;
    WindowSettings Params(0, 0, 0);
    if (!CreateContext(VideoMode(myWidth, myHeight, 32), Visual, Params))
        return;

    // Create a new color map with the chosen visual
    Colormap ColMap = XCreateColormap(ourDisplay, RootWindow(ourDisplay, ourScreen), Visual.visual, AllocNone);

    // Define the window attributes
    XSetWindowAttributes Attributes;
    Attributes.colormap = ColMap;

    // Create a dummy window (disabled and hidden)
    myWindow = XCreateWindow(ourDisplay,
                             RootWindow(ourDisplay, ourScreen),
                             0, 0,
                             myWidth, myHeight,
                             0,
                             Visual.depth,
                             InputOutput,
                             Visual.visual,
                             CWColormap, &Attributes);

    // Don't activate the dummy context by default
}

Here is the call graph for this function:

sf::priv::WindowImplX11::WindowImplX11 ( WindowHandle  Handle,
WindowSettings Params 
)

Construct the window implementation from an existing control.

Create the window implementation from an existing control /////////////////////////////////////////////////////////.

Parameters:
Handle: Platform-specific handle of the control
Params: Creation settings

/////////////////////////////////////////////////////////

Definition at line 123 of file WindowImplX11.cpp.

                                                                        :
myWindow      (0),
myIsExternal  (true),
myGLContext   (NULL),
myAtomClose   (0),
myOldVideoMode(-1),
myHiddenCursor(0),
myInputContext(NULL),
myKeyRepeat   (true)
{
    // Open the display at first call
    if (!OpenDisplay())
        return;

    // Save the window handle
    myWindow = Handle;

    if (myWindow)
    {
        // Get the window size
        XWindowAttributes WindowAttributes;
        if (XGetWindowAttributes(ourDisplay, myWindow, &WindowAttributes) == 0)
        {
            std::cerr << "Failed to get the window attributes" << std::endl;
            return;
        }
        myWidth  = WindowAttributes.width;
        myHeight = WindowAttributes.height;

        // Setup the visual infos to match
        XVisualInfo Template;
        Template.depth     = WindowAttributes.depth;
        Template.visualid  = XVisualIDFromVisual(WindowAttributes.visual);
        unsigned long Mask = VisualDepthMask | VisualIDMask;

        // Create the rendering context
        VideoMode Mode(myWidth, myHeight, VideoMode::GetDesktopMode().BitsPerPixel);
        XVisualInfo Visual;
        if (!CreateContext(Mode, Visual, Params, Template, Mask))
            return;

        // Create a new color map with the chosen visual
        Colormap ColMap = XCreateColormap(ourDisplay, RootWindow(ourDisplay, ourScreen), Visual.visual, AllocNone);
        XSetWindowColormap(ourDisplay, myWindow, ColMap);

        // Make sure the window is listening to all the requiered events
        XSelectInput(ourDisplay, myWindow, ourEventMask & ~ButtonPressMask);

        // Do some common initializations
        Initialize();
    }
}

Here is the call graph for this function:

sf::priv::WindowImplX11::WindowImplX11 ( VideoMode  Mode,
const std::string &  Title,
unsigned long  WindowStyle,
WindowSettings Params 
)

Create the window implementation.

Create the window implementation /////////////////////////////////////////////////////////.

Parameters:
Mode: Video mode to use
Title: Title of the window
WindowStyle: Window style (resizable, fixed, or fullscren)
Params: Creation settings

/////////////////////////////////////////////////////////

Definition at line 180 of file WindowImplX11.cpp.

                                                                                                                      :
myWindow      (0),
myIsExternal  (false),
myGLContext   (NULL),
myAtomClose   (0),
myOldVideoMode(-1),
myHiddenCursor(0),
myInputContext(NULL),
myKeyRepeat   (true)
{
    // Open the display at first call
    if (!OpenDisplay())
        return;

    // Compute position and size
    int Left, Top;
    bool Fullscreen = (WindowStyle & Style::Fullscreen) != 0;
    if (!Fullscreen)
    {
        Left = (DisplayWidth(ourDisplay, ourScreen)  - Mode.Width)  / 2;
        Top  = (DisplayHeight(ourDisplay, ourScreen) - Mode.Height) / 2;
    }
    else
    {
        Left = 0;
        Top  = 0;
    }
    int Width  = myWidth  = Mode.Width;
    int Height = myHeight = Mode.Height;

    // Switch to fullscreen if necessary
    if (Fullscreen)
        SwitchToFullscreen(Mode);

    // Create the rendering context
    XVisualInfo Visual;
    if (!CreateContext(Mode, Visual, Params))
        return;

    // Create a new color map with the chosen visual
    Colormap ColMap = XCreateColormap(ourDisplay, RootWindow(ourDisplay, ourScreen), Visual.visual, AllocNone);

    // Define the window attributes
    XSetWindowAttributes Attributes;
    Attributes.event_mask        = ourEventMask;
    Attributes.colormap          = ColMap;
    Attributes.override_redirect = Fullscreen;

    // Create the window
    myWindow = XCreateWindow(ourDisplay,
                             RootWindow(ourDisplay, ourScreen),
                             Left, Top,
                             Width, Height,
                             0,
                             Visual.depth,
                             InputOutput,
                             Visual.visual,
                             CWEventMask | CWColormap | CWOverrideRedirect, &Attributes);
    if (!myWindow)
    {
        std::cerr << "Failed to create window" << std::endl;
        return;
    }

    // Set the window's name
    XStoreName(ourDisplay, myWindow, Title.c_str());

    // Set the window's style (tell the windows manager to change our window's decorations and functions according to the requested style)
    if (!Fullscreen)
    {
        Atom WMHintsAtom = XInternAtom(ourDisplay, "_MOTIF_WM_HINTS", false);
        if (WMHintsAtom)
        {
            static const unsigned long MWM_HINTS_FUNCTIONS   = 1 << 0;
            static const unsigned long MWM_HINTS_DECORATIONS = 1 << 1;
    
            //static const unsigned long MWM_DECOR_ALL         = 1 << 0;
            static const unsigned long MWM_DECOR_BORDER      = 1 << 1;
            static const unsigned long MWM_DECOR_RESIZEH     = 1 << 2;
            static const unsigned long MWM_DECOR_TITLE       = 1 << 3;
            static const unsigned long MWM_DECOR_MENU        = 1 << 4;
            static const unsigned long MWM_DECOR_MINIMIZE    = 1 << 5;
            static const unsigned long MWM_DECOR_MAXIMIZE    = 1 << 6;

            //static const unsigned long MWM_FUNC_ALL          = 1 << 0;
            static const unsigned long MWM_FUNC_RESIZE       = 1 << 1;
            static const unsigned long MWM_FUNC_MOVE         = 1 << 2;
            static const unsigned long MWM_FUNC_MINIMIZE     = 1 << 3;
            static const unsigned long MWM_FUNC_MAXIMIZE     = 1 << 4;
            static const unsigned long MWM_FUNC_CLOSE        = 1 << 5;
    
            struct WMHints
            {
                unsigned long Flags;
                unsigned long Functions;
                unsigned long Decorations;
                long          InputMode;
                unsigned long State;
            };
    
            WMHints Hints;
            Hints.Flags       = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
            Hints.Decorations = 0;
            Hints.Functions   = 0;

            if (WindowStyle & Style::Titlebar)
            {
                Hints.Decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU;
                Hints.Functions   |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE;
            }
            if (WindowStyle & Style::Resize)
            {
                Hints.Decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH;
                Hints.Functions   |= MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
            }
            if (WindowStyle & Style::Close)
            {
                Hints.Decorations |= 0;
                Hints.Functions   |= MWM_FUNC_CLOSE;
            }

            const unsigned char* HintsPtr = reinterpret_cast<const unsigned char*>(&Hints);
            XChangeProperty(ourDisplay, myWindow, WMHintsAtom, WMHintsAtom, 32, PropModeReplace, HintsPtr, 5);
        }

        // This is a hack to force some windows managers to disable resizing
        if (!(WindowStyle & Style::Resize))
        {
            XSizeHints XSizeHints;
            XSizeHints.flags      = PMinSize | PMaxSize;
            XSizeHints.min_width  = XSizeHints.max_width  = Width;
            XSizeHints.min_height = XSizeHints.max_height = Height;
            XSetWMNormalHints(ourDisplay, myWindow, &XSizeHints); 
        }
    }

    // Do some common initializations
    Initialize();

    // In fullscreen mode, we must grab keyboard and mouse inputs
    if (Fullscreen)
    {
        XGrabPointer(ourDisplay, myWindow, true, 0, GrabModeAsync, GrabModeAsync, myWindow, None, CurrentTime);
        XGrabKeyboard(ourDisplay, myWindow, true, GrabModeAsync, GrabModeAsync, CurrentTime);
    }
}

Here is the call graph for this function:

Destructor.

Destructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 331 of file WindowImplX11.cpp.

{
    // Cleanup graphical resources
    CleanUp();

    // Destroy the input context
    if (myInputContext)
    {
        XDestroyIC(myInputContext);
    }

    // Destroy the window
    if (myWindow && !myIsExternal)
    {
        XDestroyWindow(ourDisplay, myWindow);
        XFlush(ourDisplay);
    }

    // Close the display
    CloseDisplay();
}

Here is the call graph for this function:


Member Function Documentation

void sf::priv::WindowImpl::AddListener ( WindowListener *  Listener) [inherited]

Add a listener to the window.

Add a listener to the window /////////////////////////////////////////////////////////.

Parameters:
Listener: Listener to add

/////////////////////////////////////////////////////////

Definition at line 106 of file WindowImpl.cpp.

{
    if (Listener)
        myListeners.insert(Listener);
}

Cleanup graphical resources attached to the window.

Cleanup graphical resources attached to the window /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 808 of file WindowImplX11.cpp.

{
    // Restore the previous video mode (in case we were running in fullscreen)
    if (ourFullscreenWindow == this)
    {
        // Get current screen info
        XRRScreenConfiguration* Config = XRRGetScreenInfo(ourDisplay, RootWindow(ourDisplay, ourScreen));
        if (Config) 
        {
            // Get the current rotation
            Rotation CurrentRotation;
            XRRConfigCurrentConfiguration(Config, &CurrentRotation);

            // Reset the video mode
            XRRSetScreenConfig(ourDisplay, Config, RootWindow(ourDisplay, ourScreen), myOldVideoMode, CurrentRotation, CurrentTime);

            // Free the configuration instance
            XRRFreeScreenConfigInfo(Config);
        } 

        // Reset the fullscreen window
        ourFullscreenWindow = NULL;
    }

    // Unhide the mouse cursor (in case it was hidden)
    ShowMouseCursor(true);

    // Destroy the OpenGL context
    if (myGLContext)
    {
        glXDestroyContext(ourDisplay, myGLContext);
        myGLContext = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sf::priv::WindowImplX11::CloseDisplay ( ) [static, private]

Close the display.

Close the display /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 1230 of file WindowImplX11.cpp.

{
    // Decrease the number of windows
    ourWindowsCount--;

    // If all windows have been destroyed, then we can close the display
    if (ourWindowsCount == 0)
    {
        // Close the input method object
        if (ourInputMethod)
            XCloseIM(ourInputMethod);

        XCloseDisplay(ourDisplay);
        ourDisplay = NULL;
    }
}

Here is the caller graph for this function:

bool sf::priv::WindowImplX11::CreateContext ( const VideoMode &  Mode,
XVisualInfo &  ChosenVisual,
WindowSettings Params,
XVisualInfo  Template = XVisualInfo(),
unsigned long  Mask = 0 
) [private]

Create the OpenGL rendering context.

Create the OpenGL rendering context /////////////////////////////////////////////////////////.

Parameters:
Mode: Video mode to use
ChosenVisual: Visual that has been chosen for creating the contexte
Params: Creation parameters
Template: Visual infos to match
Mask: Visual attributes to check in Template
Returns:
True on success, false on error

/////////////////////////////////////////////////////////

Definition at line 641 of file WindowImplX11.cpp.

{
    // Get all the visuals matching the template
    Template.screen = ourScreen;
    int NbVisuals = 0;
    XVisualInfo* Visuals = XGetVisualInfo(ourDisplay, Mask | VisualScreenMask, &Template, &NbVisuals);
    if (!Visuals || (NbVisuals == 0))
    {
        if (Visuals)
            XFree(Visuals);
        std::cerr << "There is no valid visual for the selected screen" << std::endl;
        return false;
    }

    // Find the best visual
    int          BestScore  = 0xFFFF;
    XVisualInfo* BestVisual = NULL;
    while (!BestVisual)
    {
        for (int i = 0; i < NbVisuals; ++i)
        {
            // Get the current visual attributes
            int RGBA, DoubleBuffer, Red, Green, Blue, Alpha, Depth, Stencil, MultiSampling, Samples;
            glXGetConfig(ourDisplay, &Visuals[i], GLX_RGBA,               &RGBA);
            glXGetConfig(ourDisplay, &Visuals[i], GLX_DOUBLEBUFFER,       &DoubleBuffer); 
            glXGetConfig(ourDisplay, &Visuals[i], GLX_RED_SIZE,           &Red);
            glXGetConfig(ourDisplay, &Visuals[i], GLX_GREEN_SIZE,         &Green); 
            glXGetConfig(ourDisplay, &Visuals[i], GLX_BLUE_SIZE,          &Blue); 
            glXGetConfig(ourDisplay, &Visuals[i], GLX_ALPHA_SIZE,         &Alpha); 
            glXGetConfig(ourDisplay, &Visuals[i], GLX_DEPTH_SIZE,         &Depth);        
            glXGetConfig(ourDisplay, &Visuals[i], GLX_STENCIL_SIZE,       &Stencil);
            glXGetConfig(ourDisplay, &Visuals[i], GLX_SAMPLE_BUFFERS_ARB, &MultiSampling);        
            glXGetConfig(ourDisplay, &Visuals[i], GLX_SAMPLES_ARB,        &Samples);

            // First check the mandatory parameters
            if ((RGBA == 0) || (DoubleBuffer == 0))
                continue;

            // Evaluate the current configuration
            int Color = Red + Green + Blue + Alpha;
            int Score = EvaluateConfig(Mode, Params, Color, Depth, Stencil, MultiSampling ? Samples : 0);

            // Keep it if it's better than the current best
            if (Score < BestScore)
            {
                BestScore  = Score;
                BestVisual = &Visuals[i];
            }
        }

        // If no visual has been found, try a lower level of antialiasing
        if (!BestVisual)
        {
            if (Params.AntialiasingLevel > 2)
            {
                std::cerr << "Failed to find a pixel format supporting "
                          << Params.AntialiasingLevel << " antialiasing levels ; trying with 2 levels" << std::endl;
                Params.AntialiasingLevel = 2;
            }
            else if (Params.AntialiasingLevel > 0)
            {
                std::cerr << "Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled" << std::endl;
                Params.AntialiasingLevel = 0;
            }
            else
            {
                std::cerr << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl;
                return false;
            }
        }
    }

    // Create the OpenGL context
    myGLContext = glXCreateContext(ourDisplay, BestVisual, glXGetCurrentContext(), true);
    if (myGLContext == NULL)
    {
        std::cerr << "Failed to create an OpenGL context for this window" << std::endl;
        return false;
    }

    // Update the creation settings from the chosen format
    int Depth, Stencil;
    glXGetConfig(ourDisplay, BestVisual, GLX_DEPTH_SIZE,   &Depth);
    glXGetConfig(ourDisplay, BestVisual, GLX_STENCIL_SIZE, &Stencil);
    Params.DepthBits   = static_cast<unsigned int>(Depth);
    Params.StencilBits = static_cast<unsigned int>(Stencil);

    // Assign the chosen visual, and free the temporary visuals array
    ChosenVisual = *BestVisual;
    XFree(Visuals);

    // Activate the context
    SetActive(true);

    // Enable multisampling if needed
    if (Params.AntialiasingLevel > 0)
        glEnable(GL_MULTISAMPLE_ARB);

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Create a transparent mouse cursor.

Create a transparent mouse cursor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 786 of file WindowImplX11.cpp.

{
    // Create the cursor's pixmap (1x1 pixels)
       Pixmap CursorPixmap = XCreatePixmap(ourDisplay, myWindow, 1, 1, 1);
    GC GraphicsContext = XCreateGC(ourDisplay, CursorPixmap, 0, NULL);
    XDrawPoint(ourDisplay, CursorPixmap, GraphicsContext, 0, 0);
    XFreeGC(ourDisplay, GraphicsContext);

    // Create the cursor, using the pixmap as both the shape and the mask of the cursor
       XColor Color;
       Color.flags = DoRed | DoGreen | DoBlue;
       Color.red = Color.blue = Color.green = 0;
    myHiddenCursor = XCreatePixmapCursor(ourDisplay, CursorPixmap, CursorPixmap, &Color, &Color, 0, 0);

    // We don't need the pixmap any longer, free it
       XFreePixmap(ourDisplay, CursorPixmap);
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::Display ( ) [private, virtual]

/see WindowImpl::Display

/see WindowImpl::Display /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 366 of file WindowImplX11.cpp.

{
    if (myWindow && myGLContext)
        glXSwapBuffers(ourDisplay, myWindow);
}
void sf::priv::WindowImpl::DoEvents ( ) [inherited]

Process incoming events from operating system.

Process incoming events from operating system /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 167 of file WindowImpl.cpp.

{
    // Read the joysticks state and generate the appropriate events
    ProcessJoystickEvents();

    // Let the derived class process other events
    ProcessEvents();
}

Here is the call graph for this function:

void sf::priv::WindowImplX11::EnableKeyRepeat ( bool  Enabled) [private, virtual]

/see sfWindowImpl::EnableKeyRepeat

/see sfWindowImpl::EnableKeyRepeat /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 515 of file WindowImplX11.cpp.

{
    myKeyRepeat = Enabled;
}
int sf::priv::WindowImpl::EvaluateConfig ( const VideoMode &  Mode,
const WindowSettings Settings,
int  ColorBits,
int  DepthBits,
int  StencilBits,
int  Antialiasing 
) [static, protected, inherited]

Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one.

Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one /////////////////////////////////////////////////////////.

Parameters:
Mode: Requested video mode
Settings: Requested additionnal settings
ColorBits: Color bits of the configuration to evaluate
DepthBits: Depth bits of the configuration to evaluate
StencilBits: Stencil bits of the configuration to evaluate
Antialiasing: Antialiasing level of the configuration to evaluate
Returns:
Score of the configuration : the lower the better

/////////////////////////////////////////////////////////

Definition at line 203 of file WindowImpl.cpp.

{
    return abs(static_cast<int>(Mode.BitsPerPixel          - ColorBits))   +
           abs(static_cast<int>(Settings.DepthBits         - DepthBits))   +
           abs(static_cast<int>(Settings.StencilBits       - StencilBits)) +
           abs(static_cast<int>(Settings.AntialiasingLevel - Antialiasing));
}

Here is the caller graph for this function:

unsigned int sf::priv::WindowImpl::GetHeight ( ) const [inherited]

Get the client height of the window.

Get the client height of the window /////////////////////////////////////////////////////////.

Returns:
Height of the window in pixels

/////////////////////////////////////////////////////////

Definition at line 148 of file WindowImpl.cpp.

{
    return myHeight;
}
unsigned int sf::priv::WindowImpl::GetWidth ( ) const [inherited]

Get the client width of the window.

Get the client width of the window /////////////////////////////////////////////////////////.

Returns:
Width of the window in pixels

/////////////////////////////////////////////////////////

Definition at line 139 of file WindowImpl.cpp.

{
    return myWidth;
}

Do some common initializations after the window has been created.

Do some common initializations after the window has been created /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Reimplemented from sf::priv::WindowImpl.

Definition at line 746 of file WindowImplX11.cpp.

{
    // Make sure the "last key release" is initialized with invalid values
    myLastKeyReleaseEvent.type = -1;

    // Get the atom defining the close event
    myAtomClose = XInternAtom(ourDisplay, "WM_DELETE_WINDOW", false);
    XSetWMProtocols(ourDisplay, myWindow, &myAtomClose, 1);

    // Create the input context
    if (ourInputMethod)
    {
        myInputContext = XCreateIC(ourInputMethod,
                                   XNClientWindow,  myWindow,
                                   XNFocusWindow,   myWindow,
                                   XNInputStyle,    XIMPreeditNothing  | XIMStatusNothing,
                                   NULL);
        
        if (!myInputContext)
            std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl;
    }

    // Show the window
    XMapWindow(ourDisplay, myWindow);
    XFlush(ourDisplay);

    // Create the hiden cursor
    CreateHiddenCursor();

    // Set our context as the current OpenGL context for rendering
    SetActive();

    // Flush the commands queue
    XFlush(ourDisplay);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Check if there's an active context on the current thread.

Check if there's an active context on the current thread /////////////////////////////////////////////////////////.

Returns:
True if there's a context bound to the current thread

/////////////////////////////////////////////////////////

Reimplemented from sf::priv::WindowImpl.

Definition at line 357 of file WindowImplX11.cpp.

{
    return glXGetCurrentContext() != NULL;
}
Key::Code sf::priv::WindowImplX11::KeysymToSF ( KeySym  Sym) [static, private]

Convert a X11 keysym to SFML key code.

Convert a X11 keysym to SFML key code /////////////////////////////////////////////////////////.

Parameters:
Sym: keysym to convert
Returns:
Corrsponding SFML key code

/////////////////////////////////////////////////////////

Definition at line 1081 of file WindowImplX11.cpp.

{
    // First convert to uppercase (to avoid dealing with two different keysyms for the same key)
    KeySym Lower, Key;
    XConvertCase(Sym, &Lower, &Key);

    switch (Key)
    {
        case XK_Shift_L :      return Key::LShift;
        case XK_Shift_R :      return Key::RShift;
        case XK_Control_L :    return Key::LControl;
        case XK_Control_R :    return Key::RControl;
        case XK_Alt_L :        return Key::LAlt;
        case XK_Alt_R :        return Key::RAlt;
        case XK_Super_L :      return Key::LSystem;
        case XK_Super_R :      return Key::RSystem;
        case XK_Menu :         return Key::Menu;
        case XK_Escape :       return Key::Escape;
        case XK_semicolon :    return Key::SemiColon;
        case XK_slash :        return Key::Slash;
        case XK_equal :        return Key::Equal;
        case XK_minus :        return Key::Dash;
        case XK_bracketleft :  return Key::LBracket;
        case XK_bracketright : return Key::RBracket;
        case XK_comma :        return Key::Comma;
        case XK_period :       return Key::Period;
        case XK_dead_acute :   return Key::Quote;
        case XK_backslash :    return Key::BackSlash;
        case XK_dead_grave :   return Key::Tilde;
        case XK_space :        return Key::Space;
        case XK_Return :       return Key::Return;
        case XK_KP_Enter :     return Key::Return;
        case XK_BackSpace :    return Key::Back;
        case XK_Tab :          return Key::Tab;
        case XK_Prior :        return Key::PageUp;
        case XK_Next :         return Key::PageDown;
        case XK_End :          return Key::End;
        case XK_Home :         return Key::Home;
        case XK_Insert :       return Key::Insert;
        case XK_Delete :       return Key::Delete;
        case XK_KP_Add :       return Key::Add;
        case XK_KP_Subtract :  return Key::Subtract;
        case XK_KP_Multiply :  return Key::Multiply;
        case XK_KP_Divide :    return Key::Divide;
        case XK_Pause :        return Key::Pause;
        case XK_F1 :           return Key::F1;
        case XK_F2 :           return Key::F2;
        case XK_F3 :           return Key::F3;
        case XK_F4 :           return Key::F4;
        case XK_F5 :           return Key::F5;
        case XK_F6 :           return Key::F6;
        case XK_F7 :           return Key::F7;
        case XK_F8 :           return Key::F8;
        case XK_F9 :           return Key::F9;
        case XK_F10 :          return Key::F10;
        case XK_F11 :          return Key::F11;
        case XK_F12 :          return Key::F12;
        case XK_F13 :          return Key::F13;
        case XK_F14 :          return Key::F14;
        case XK_F15 :          return Key::F15;
        case XK_Left :         return Key::Left;
        case XK_Right :        return Key::Right;
        case XK_Up :           return Key::Up;
        case XK_Down :         return Key::Down;
        case XK_KP_0 :         return Key::Numpad0;
        case XK_KP_1 :         return Key::Numpad1;
        case XK_KP_2 :         return Key::Numpad2;
        case XK_KP_3 :         return Key::Numpad3;
        case XK_KP_4 :         return Key::Numpad4;
        case XK_KP_5 :         return Key::Numpad5;
        case XK_KP_6 :         return Key::Numpad6;
        case XK_KP_7 :         return Key::Numpad7;
        case XK_KP_8 :         return Key::Numpad8;
        case XK_KP_9 :         return Key::Numpad9;
        case XK_A :            return Key::A;
        case XK_Z :            return Key::Z;
        case XK_E :            return Key::E;
        case XK_R :            return Key::R;
        case XK_T :            return Key::T;
        case XK_Y :            return Key::Y;
        case XK_U :            return Key::U;
        case XK_I :            return Key::I;
        case XK_O :            return Key::O;
        case XK_P :            return Key::P;
        case XK_Q :            return Key::Q;
        case XK_S :            return Key::S;
        case XK_D :            return Key::D;
        case XK_F :            return Key::F;
        case XK_G :            return Key::G;
        case XK_H :            return Key::H;
        case XK_J :            return Key::J;
        case XK_K :            return Key::K;
        case XK_L :            return Key::L;
        case XK_M :            return Key::M;
        case XK_W :            return Key::W;
        case XK_X :            return Key::X;
        case XK_C :            return Key::C;
        case XK_V :            return Key::V;
        case XK_B :            return Key::B;
        case XK_N :            return Key::N;
        case XK_0 :            return Key::Num0;
        case XK_1 :            return Key::Num1;
        case XK_2 :            return Key::Num2;
        case XK_3 :            return Key::Num3;
        case XK_4 :            return Key::Num4;
        case XK_5 :            return Key::Num5;
        case XK_6 :            return Key::Num6;
        case XK_7 :            return Key::Num7;
        case XK_8 :            return Key::Num8;
        case XK_9 :            return Key::Num9;
    }

    return Key::Code(0);
}

Here is the caller graph for this function:

WindowImpl * sf::priv::WindowImpl::New ( ) [static, inherited]

Create a new window depending on the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 59 of file WindowImpl.cpp.

{
    return new WindowImplType();
}
WindowImpl * sf::priv::WindowImpl::New ( VideoMode  Mode,
const std::string &  Title,
unsigned long  WindowStyle,
WindowSettings Params 
) [static, inherited]

Create a new window depending on the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Parameters:
Mode: Video mode to use
Title: Title of the window
WindowStyle: Window style
Params: Creation parameters
Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 68 of file WindowImpl.cpp.

{
    return new WindowImplType(Mode, Title, WindowStyle, Params);
}
WindowImpl * sf::priv::WindowImpl::New ( WindowHandle  Handle,
WindowSettings Params 
) [static, inherited]

Create a new window depending on to the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Parameters:
Handle: Platform-specific handle of the control
Params: Creation parameters
Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 77 of file WindowImpl.cpp.

{
    return new WindowImplType(Handle, Params);
}
bool sf::priv::WindowImplX11::OpenDisplay ( bool  AddWindow = true) [static, private]

Open the display (if not already done)

Open the display (if not already done) /////////////////////////////////////////////////////////.

Parameters:
AddWindow: Tell whether or not we must increase the windows count
Returns:
True if the display is properly opened

/////////////////////////////////////////////////////////

Definition at line 1200 of file WindowImplX11.cpp.

{
    // If no display has been opened yet, open it
    if (ourDisplay == NULL)
    {
        ourDisplay = XOpenDisplay(NULL);
        if (ourDisplay)
        {
            ourScreen = DefaultScreen(ourDisplay);

            // Get the input method (XIM) object
            ourInputMethod = XOpenIM(ourDisplay, NULL, NULL, NULL);
        }
        else
        {
            std::cerr << "Failed to open a connection with the X server" << std::endl;
        }
    }

    // Increase the number of windows
    if (AddWindow)
        ourWindowsCount++;

    return ourDisplay != NULL;
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::ProcessEvent ( XEvent  WinEvent) [private]

Process an incoming event from the window.

Process an incoming event from the window /////////////////////////////////////////////////////////.

Parameters:
WinEvent: Event which has been received

/////////////////////////////////////////////////////////

Definition at line 847 of file WindowImplX11.cpp.

{
    switch (WinEvent.type)
    {
        // Destroy event
        case DestroyNotify :
        {
            // The window is about to be destroyed : we must cleanup resources
            CleanUp();
            break;
        }

        // Gain focus event
        case FocusIn :
        {
            // Update the input context
            if (myInputContext)
                XSetICFocus(myInputContext);

            Event Evt;
            Evt.Type = Event::GainedFocus;
            SendEvent(Evt);
            break;
        }

        // Lost focus event
        case FocusOut :
        {
            // Update the input context
            if (myInputContext)
                XUnsetICFocus(myInputContext);

            Event Evt;
            Evt.Type = Event::LostFocus;
            SendEvent(Evt);
            break;
        }

        // Resize event
        case ConfigureNotify :
        {
            if ((WinEvent.xconfigure.width != static_cast<int>(myWidth)) || (WinEvent.xconfigure.height != static_cast<int>(myHeight)))
            {
                myWidth  = WinEvent.xconfigure.width;
                myHeight = WinEvent.xconfigure.height;

                Event Evt;
                Evt.Type        = Event::Resized;
                Evt.Size.Width  = myWidth;
                Evt.Size.Height = myHeight;
                SendEvent(Evt);
            }
            break;
        }

        // Close event
        case ClientMessage :
        {
            if ((WinEvent.xclient.format == 32) && (WinEvent.xclient.data.l[0]) == static_cast<long>(myAtomClose))  
            {
                Event Evt;
                Evt.Type = Event::Closed;
                SendEvent(Evt);
            }
            break;
        }

        // Key down event
        case KeyPress :
        {
            // Get the keysym of the key that has been pressed
            static XComposeStatus KeyboardStatus;
            char Buffer[32];
            KeySym Sym;
            XLookupString(&WinEvent.xkey, Buffer, sizeof(Buffer), &Sym, &KeyboardStatus);

            // Fill the event parameters
            Event Evt;
            Evt.Type        = Event::KeyPressed;
            Evt.Key.Code    = KeysymToSF(Sym);
            Evt.Key.Alt     = WinEvent.xkey.state & Mod1Mask;
            Evt.Key.Control = WinEvent.xkey.state & ControlMask;
            Evt.Key.Shift   = WinEvent.xkey.state & ShiftMask;
            SendEvent(Evt);

            // Generate a TextEntered event
            if (!XFilterEvent(&WinEvent, None))
            {
                #ifdef X_HAVE_UTF8_STRING
                if (myInputContext)
                {
                    Status ReturnedStatus;
                    Uint8  KeyBuffer[16];
                    int Length = Xutf8LookupString(myInputContext, &WinEvent.xkey, reinterpret_cast<char*>(KeyBuffer), sizeof(KeyBuffer), NULL, &ReturnedStatus);
                    if (Length > 0)
                    {
                        Uint32 Unicode[2]; // just in case, but 1 character should be enough
                        const Uint32* End = Unicode::UTF8ToUTF32(KeyBuffer, KeyBuffer + Length, Unicode);

                        if (End > Unicode)
                        {
                            Event TextEvt;
                            TextEvt.Type         = Event::TextEntered;
                            TextEvt.Text.Unicode = Unicode[0];
                            SendEvent(TextEvt);
                        }
                    }
                }
                else
                #endif
                {
                    static XComposeStatus ComposeStatus;
                    char KeyBuffer[16];
                    if (XLookupString(&WinEvent.xkey, KeyBuffer, sizeof(KeyBuffer), NULL, &ComposeStatus))
                    {
                        Event TextEvt;
                        TextEvt.Type         = Event::TextEntered;
                        TextEvt.Text.Unicode = static_cast<Uint32>(KeyBuffer[0]);
                        SendEvent(TextEvt);
                    }
                }
            }

            break;
        }

        // Key up event
        case KeyRelease :
        {
            // Get the keysym of the key that has been pressed
            char Buffer[32];
            KeySym Sym;
            XLookupString(&WinEvent.xkey, Buffer, 32, &Sym, NULL);

            // Fill the event parameters
            Event Evt;
            Evt.Type        = Event::KeyReleased;
            Evt.Key.Code    = KeysymToSF(Sym);
            Evt.Key.Alt     = WinEvent.xkey.state & Mod1Mask;
            Evt.Key.Control = WinEvent.xkey.state & ControlMask;
            Evt.Key.Shift   = WinEvent.xkey.state & ShiftMask;

            SendEvent(Evt);
            break;
        }

        // Mouse button pressed
        case ButtonPress :
        {
            unsigned int Button = WinEvent.xbutton.button;
            if ((Button == Button1) || (Button == Button2) || (Button == Button3) || (Button == 8) || (Button == 9))
            {
                Event Evt;
                Evt.Type          = Event::MouseButtonPressed;
                Evt.MouseButton.X = WinEvent.xbutton.x;
                Evt.MouseButton.Y = WinEvent.xbutton.y;
                switch (Button)
                {
                    case Button1 : Evt.MouseButton.Button = Mouse::Left;     break;
                    case Button2 : Evt.MouseButton.Button = Mouse::Middle;   break;
                    case Button3 : Evt.MouseButton.Button = Mouse::Right;    break;
                    case 8 :       Evt.MouseButton.Button = Mouse::XButton1; break;
                    case 9 :       Evt.MouseButton.Button = Mouse::XButton2; break;            
                }
                SendEvent(Evt);
            }
            break;
        }

        // Mouse button released
        case ButtonRelease :
        {
            unsigned int Button = WinEvent.xbutton.button;
            if ((Button == Button1) || (Button == Button2) || (Button == Button3) || (Button == 8) || (Button == 9))
            {
                Event Evt;
                Evt.Type          = Event::MouseButtonReleased;
                Evt.MouseButton.X = WinEvent.xbutton.x;
                Evt.MouseButton.Y = WinEvent.xbutton.y;
                switch (Button)
                {
                    case Button1 : Evt.MouseButton.Button = Mouse::Left;     break;
                    case Button2 : Evt.MouseButton.Button = Mouse::Middle;   break;
                    case Button3 : Evt.MouseButton.Button = Mouse::Right;    break;
                    case 8 :       Evt.MouseButton.Button = Mouse::XButton1; break;
                    case 9 :       Evt.MouseButton.Button = Mouse::XButton2; break;            
                }
                SendEvent(Evt);
            }
            else if ((Button == Button4) || (Button == Button5))
            {
                Event Evt;
                Evt.Type             = Event::MouseWheelMoved;
                Evt.MouseWheel.Delta = WinEvent.xbutton.button == Button4 ? 1 : -1;
                SendEvent(Evt);
            }
            break;
        }

        // Mouse moved
        case MotionNotify :
        {
            Event Evt;
            Evt.Type        = Event::MouseMoved;
            Evt.MouseMove.X = WinEvent.xmotion.x;
            Evt.MouseMove.Y = WinEvent.xmotion.y;
            SendEvent(Evt);
            break;
        }

        // Mouse entered
        case EnterNotify :
        {
            Event Evt;
            Evt.Type = Event::MouseEntered;
            SendEvent(Evt);
            break;
        }

        // Mouse left
        case LeaveNotify :
        {
            Event Evt;
            Evt.Type = Event::MouseLeft;
            SendEvent(Evt);
            break;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sf::priv::WindowImplX11::ProcessEvents ( ) [private, virtual]

/see WindowImpl::ProcessEvents

/see WindowImpl::ProcessEvents /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 376 of file WindowImplX11.cpp.

{
    // This function implements a workaround to properly discard
    // repeated key events when necessary. The problem is that the
    // system's key events policy doesn't match SFML's one: X server will generate
    // both repeated KeyPress and KeyRelease events when maintaining a key down, while
    // SFML only wants repeated KeyPress events. Thus, we have to:
    // - Discard duplicated KeyRelease events when EnableKeyRepeat is true
    // - Discard both duplicated KeyPress and KeyRelease events when EnableKeyRepeat is false


    // Process any event in the queue matching our window
    XEvent Event;
    while (XCheckIfEvent(ourDisplay, &Event, &CheckEvent, reinterpret_cast<XPointer>(myWindow)))
    {
        // Detect repeated key events
        if ((Event.type == KeyPress) || (Event.type == KeyRelease))
        {
            if (Event.xkey.keycode < 256)
            {
                // To detect if it is a repeated key event, we check the current state of the key.
                // - If the state is "down", KeyReleased events must obviously be discarded.
                // - KeyPress events are a little bit harder to handle: they depend on the EnableKeyRepeat state,
                //   and we need to properly forward the first one.
                char Keys[32];
                XQueryKeymap(ourDisplay, Keys);
                if (Keys[Event.xkey.keycode >> 3] & (1 << (Event.xkey.keycode % 8)))
                {
                    // KeyRelease event + key down = repeated event --> discard
                    if (Event.type == KeyRelease)
                    {
                        myLastKeyReleaseEvent = Event;
                        continue;
                    }

                    // KeyPress event + key repeat disabled + matching KeyRelease event = repeated event --> discard
                    if ((Event.type == KeyPress) && !myKeyRepeat &&
                        (myLastKeyReleaseEvent.xkey.keycode == Event.xkey.keycode) &&
                        (myLastKeyReleaseEvent.xkey.time == Event.xkey.time))
                    {
                        continue;
                    }
                }
            }
        }

        // Process the event
        ProcessEvent(Event);
   }
}

Here is the call graph for this function:

void sf::priv::WindowImpl::RemoveListener ( WindowListener *  Listener) [inherited]

Remove a listener from the window.

Remove a listener from the window /////////////////////////////////////////////////////////.

Parameters:
Listener: Listener to remove

/////////////////////////////////////////////////////////

Definition at line 116 of file WindowImpl.cpp.

{
    myListeners.erase(Listener);
}
void sf::priv::WindowImpl::SendEvent ( const Event EventToSend) [protected, inherited]

Send an event to listeners (for derived classes only)

Send an event to listeners /////////////////////////////////////////////////////////.

Parameters:
EventToSend: Event to send

/////////////////////////////////////////////////////////

Definition at line 189 of file WindowImpl.cpp.

{
    for (std::set<WindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
    {
        (*i)->OnEvent(EventToSend);
    }
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::SetActive ( bool  Active = true) const [private, virtual]

/see WindowImpl::SetActive

/see WindowImpl::SetActive /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 431 of file WindowImplX11.cpp.

{
    if (Active)
    {
        if (myWindow && myGLContext && (glXGetCurrentContext() != myGLContext))
            glXMakeCurrent(ourDisplay, myWindow, myGLContext);
    }
    else
    {
        if (glXGetCurrentContext() == myGLContext)
            glXMakeCurrent(ourDisplay, None, NULL);
    }
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::SetCursorPosition ( unsigned int  Left,
unsigned int  Top 
) [private, virtual]

/see sfWindowImpl::SetCursorPosition

/see sfWindowImpl::SetCursorPosition /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 471 of file WindowImplX11.cpp.

{
    XWarpPointer(ourDisplay, None, myWindow, 0, 0, 0, 0, Left, Top);
    XFlush(ourDisplay);
}
void sf::priv::WindowImplX11::SetIcon ( unsigned int  Width,
unsigned int  Height,
const Uint8 *  Pixels 
) [private, virtual]

/see WindowImpl::SetIcon

/see WindowImpl::SetIcon /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 524 of file WindowImplX11.cpp.

{
    // X11 wants BGRA pixels : swap red and blue channels
    // Note : this memory will never be freed, but it seems to cause a bug on exit if I do so
    Uint8* IconPixels = new Uint8[Width * Height * 4];
    for (std::size_t i = 0; i < Width * Height; ++i)
    {
        IconPixels[i * 4 + 0] = Pixels[i * 4 + 2];
        IconPixels[i * 4 + 1] = Pixels[i * 4 + 1];
        IconPixels[i * 4 + 2] = Pixels[i * 4 + 0];
        IconPixels[i * 4 + 3] = Pixels[i * 4 + 3];
    }

    // Create the icon pixmap
    Visual*      DefVisual = DefaultVisual(ourDisplay, ourScreen);
    unsigned int DefDepth  = DefaultDepth(ourDisplay, ourScreen);
    XImage* IconImage = XCreateImage(ourDisplay, DefVisual, DefDepth, ZPixmap, 0, (char*)IconPixels, Width, Height, 32, 0);
    if (!IconImage)
    {
        std::cerr << "Failed to set the window's icon" << std::endl;
        return;
    }
    Pixmap IconPixmap = XCreatePixmap(ourDisplay, RootWindow(ourDisplay, ourScreen), Width, Height, DefDepth);
    XGCValues Values;
    GC IconGC = XCreateGC(ourDisplay, IconPixmap, 0, &Values);
    XPutImage(ourDisplay, IconPixmap, IconGC, IconImage, 0, 0, 0, 0, Width, Height);
    XFreeGC(ourDisplay, IconGC);
    XDestroyImage(IconImage);

    // Create the mask pixmap (must have 1 bit depth)
    std::size_t Pitch = (Width + 7) / 8;
    static std::vector<Uint8> MaskPixels(Pitch * Height, 0);
    for (std::size_t j = 0; j < Height; ++j)
    {
        for (std::size_t i = 0; i < Pitch; ++i)
        {
            for (std::size_t k = 0; k < 8; ++k)
            {
                if (i * 8 + k < Width)
                {
                    Uint8 Opacity = (Pixels[(i * 8 + k + j * Width) * 4 + 3] > 0) ? 1 : 0;
                    MaskPixels[i + j * Pitch] |= (Opacity << k);                    
                }
            }
        }
    }
    Pixmap MaskPixmap = XCreatePixmapFromBitmapData(ourDisplay, myWindow, (char*)&MaskPixels[0], Width, Height, 1, 0, 1);

    // Send our new icon to the window through the WMHints
    XWMHints* Hints = XAllocWMHints();
    Hints->flags       = IconPixmapHint | IconMaskHint;
    Hints->icon_pixmap = IconPixmap;
    Hints->icon_mask   = MaskPixmap;
    XSetWMHints(ourDisplay, myWindow, Hints);
    XFree(Hints);

    XFlush(ourDisplay);
}
void sf::priv::WindowImpl::SetJoystickThreshold ( float  Threshold) [inherited]

Change the joystick threshold, ie. the value below which no move event will be generated.

Change the joystick threshold, ie. the value below which no move event will be generated /////////////////////////////////////////////////////////.

Parameters:
Threshold: New threshold, in range [0, 100]

/////////////////////////////////////////////////////////

Definition at line 158 of file WindowImpl.cpp.

{
    myJoyThreshold = Threshold;
}
void sf::priv::WindowImplX11::SetPosition ( int  Left,
int  Top 
) [private, virtual]

/see sfWindowImpl::SetPosition

/see sfWindowImpl::SetPosition /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 481 of file WindowImplX11.cpp.

{
    XMoveWindow(ourDisplay, myWindow, Left, Top);
    XFlush(ourDisplay);
}
void sf::priv::WindowImplX11::SetSize ( unsigned int  Width,
unsigned int  Height 
) [private, virtual]

/see WindowImpl::SetSize

/see WindowImpl::SetSize /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 491 of file WindowImplX11.cpp.

{
    XResizeWindow(ourDisplay, myWindow, Width, Height);
    XFlush(ourDisplay);
}
void sf::priv::WindowImplX11::Show ( bool  State) [private, virtual]

/see sfWindowImpl::Show

/see sfWindowImpl::Show /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 501 of file WindowImplX11.cpp.

{
    if (State)
        XMapWindow(ourDisplay, myWindow);
    else
        XUnmapWindow(ourDisplay, myWindow);

    XFlush(ourDisplay);
}
void sf::priv::WindowImplX11::ShowMouseCursor ( bool  Show) [private, virtual]

/see WindowImpl::ShowMouseCursor

/see WindowImpl::ShowMouseCursor /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 461 of file WindowImplX11.cpp.

{
    XDefineCursor(ourDisplay, myWindow, Show ? None : myHiddenCursor);
    XFlush(ourDisplay);
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::SwitchToFullscreen ( const VideoMode &  Mode) [private]

Switch to fullscreen mode.

Switch to fullscreen mode /////////////////////////////////////////////////////////.

Parameters:
Mode: video mode to switch to

/////////////////////////////////////////////////////////

Definition at line 587 of file WindowImplX11.cpp.

{
    // Check if the XRandR extension is present
    int Version;
    if (XQueryExtension(ourDisplay, "RANDR", &Version, &Version, &Version))
    {
        // Get the current configuration
        XRRScreenConfiguration* Config = XRRGetScreenInfo(ourDisplay, RootWindow(ourDisplay, ourScreen));
        if (Config)
        {
            // Get the current rotation
            Rotation CurrentRotation;
            myOldVideoMode = XRRConfigCurrentConfiguration(Config, &CurrentRotation);

            // Get the available screen sizes
            int NbSizes;
            XRRScreenSize* Sizes = XRRConfigSizes(Config, &NbSizes);
            if (Sizes && (NbSizes > 0))
            {
                // Search a matching size
                for (int i = 0; i < NbSizes; ++i)
                {
                    if ((Sizes[i].width == static_cast<int>(Mode.Width)) && (Sizes[i].height == static_cast<int>(Mode.Height)))
                    {
                        // Switch to fullscreen mode
                        XRRSetScreenConfig(ourDisplay, Config, RootWindow(ourDisplay, ourScreen), i, CurrentRotation, CurrentTime);

                        // Set "this" as the current fullscreen window
                        ourFullscreenWindow = this;
                        break;
                    }
                }
            }

            // Free the configuration instance
            XRRFreeScreenConfigInfo(Config);
        }
        else
        {
            // Failed to get the screen configuration
            std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to windiw mode" << std::endl;
        }
    }
    else
    {
        // XRandr extension is not supported : we cannot use fullscreen mode
        std::cerr << "Fullscreen is not supported, switching to window mode" << std::endl;
    }
}

Here is the caller graph for this function:

void sf::priv::WindowImplX11::UseVerticalSync ( bool  Enabled) [private, virtual]

/see WindowImpl::UseVerticalSync

/see WindowImpl::UseVerticalSync /////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

Implements sf::priv::WindowImpl.

Definition at line 449 of file WindowImplX11.cpp.

{
    const GLubyte* ProcAddress = reinterpret_cast<const GLubyte*>("glXSwapIntervalSGI");
    PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress(ProcAddress));
    if (glXSwapIntervalSGI)
        glXSwapIntervalSGI(Enabled ? 1 : 0);
}

Friends And Related Function Documentation

friend class VideoModeSupport [friend]

Definition at line 95 of file WindowImplX11.hpp.


Member Data Documentation

Atom used to identify the close event.

Definition at line 253 of file WindowImplX11.hpp.

OpenGL context attached to the window.

Definition at line 252 of file WindowImplX11.hpp.

unsigned int sf::priv::WindowImpl::myHeight [protected, inherited]

Internal height of the window.

Definition at line 277 of file WindowImpl.hpp.

As X11 doesn't provide cursor hidding, we must create a transparent one.

Definition at line 255 of file WindowImplX11.hpp.

Input context used to get unicode input in our window.

Definition at line 256 of file WindowImplX11.hpp.

Tell whether the window has been created externally or by SFML.

Definition at line 251 of file WindowImplX11.hpp.

Is the KeyRepeat feature enabled ?

Definition at line 257 of file WindowImplX11.hpp.

Last key release event we received (needed for discarding repeated key events)

Definition at line 258 of file WindowImplX11.hpp.

Video mode in use before we switch to fullscreen.

Definition at line 254 of file WindowImplX11.hpp.

unsigned int sf::priv::WindowImpl::myWidth [protected, inherited]

Internal width of the window.

Definition at line 276 of file WindowImpl.hpp.

X11 structure defining our window.

Definition at line 250 of file WindowImplX11.hpp.

Display * sf::priv::WindowImplX11::ourDisplay = NULL [static, private]

Current opened display.

Definition at line 240 of file WindowImplX11.hpp.

unsigned long sf::priv::WindowImplX11::ourEventMask [static, private]
Initial value:
 FocusChangeMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
                                                    PointerMotionMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask |
                                                    EnterWindowMask | LeaveWindowMask

Mask defining the events that will be caught by our windows.

Definition at line 244 of file WindowImplX11.hpp.

Keep track of the active fullscreen window.

Definition at line 242 of file WindowImplX11.hpp.

XIM sf::priv::WindowImplX11::ourInputMethod = NULL [static, private]

Input object used to get unicode characters from keypress messages.

Definition at line 245 of file WindowImplX11.hpp.

int sf::priv::WindowImplX11::ourScreen = 0 [static, private]

Default screen on the opened display.

Definition at line 241 of file WindowImplX11.hpp.

unsigned int sf::priv::WindowImplX11::ourWindowsCount = 0 [static, private]

Number of windows created.

Definition at line 243 of file WindowImplX11.hpp.


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