LCOV - code coverage report
Current view: top level - eq/x11 - window.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 1 65 1.5 %
Date: 2017-12-16 05:07:20 Functions: 2 10 20.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2015, Stefan.Eilemann@epfl.ch
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "window.h"
      19             : #include <co/objectOCommand.h>
      20             : #include <eq/fabric/drawableConfig.h>
      21             : #include <eq/system.h>
      22             : 
      23             : namespace eq
      24             : {
      25             : namespace x11
      26             : {
      27           0 : Window::Window(NotifierInterface& parent, const WindowSettings& settings,
      28           0 :                Display* xDisplay)
      29             :     : SystemWindow(parent, settings)
      30             :     , _xDisplay(xDisplay)
      31           0 :     , _xDrawable(0)
      32             : {
      33           0 : }
      34             : 
      35           0 : Display* Window::getXDisplay()
      36             : {
      37           0 :     return _xDisplay;
      38             : }
      39             : 
      40           0 : bool Window::configInit()
      41             : {
      42           0 :     if (!_xDisplay)
      43             :     {
      44           0 :         sendError(ERROR_GLXWINDOW_NO_DISPLAY);
      45           0 :         return false;
      46             :     }
      47             : 
      48           0 :     if (getIAttribute(WindowSettings::IATTR_HINT_FULLSCREEN) == ON)
      49             :     {
      50           0 :         const int screen = DefaultScreen(_xDisplay);
      51           0 :         setPixelViewport(PixelViewport(0, 0, DisplayWidth(_xDisplay, screen),
      52           0 :                                        DisplayHeight(_xDisplay, screen)));
      53             :     }
      54             : 
      55           0 :     XID drawable = _createWindow();
      56           0 :     if (!drawable)
      57           0 :         return false;
      58             : 
      59             :     // Grab keyboard focus in fullscreen mode
      60           0 :     if (getIAttribute(WindowSettings::IATTR_HINT_FULLSCREEN) == ON)
      61           0 :         XGrabKeyboard(_xDisplay, drawable, True, GrabModeAsync, GrabModeAsync,
      62           0 :                       CurrentTime);
      63             : 
      64           0 :     setXDrawable(drawable);
      65           0 :     return true;
      66             : }
      67             : 
      68           0 : XID Window::_createWindow()
      69             : {
      70           0 :     if (!_xDisplay)
      71             :     {
      72           0 :         sendError(ERROR_GLXWINDOW_NO_DISPLAY);
      73           0 :         return false;
      74             :     }
      75             : 
      76           0 :     const int screen = DefaultScreen(_xDisplay);
      77           0 :     XID parent = RootWindow(_xDisplay, screen);
      78           0 :     const PixelViewport& pvp = getPixelViewport();
      79           0 :     XID drawable = XCreateSimpleWindow(_xDisplay, parent, pvp.x, pvp.y, pvp.w,
      80           0 :                                        pvp.h, 1, BlackPixel(_xDisplay, screen),
      81           0 :                                        WhitePixel(_xDisplay, screen));
      82           0 :     if (!drawable)
      83             :     {
      84           0 :         sendError(ERROR_GLXWINDOW_CREATECONTEXT_FAILED);
      85           0 :         return 0;
      86             :     }
      87             : 
      88           0 :     XSelectInput(_xDisplay, drawable, ExposureMask | KeyPressMask);
      89           0 :     XMapWindow(_xDisplay, drawable);
      90             : 
      91           0 :     std::stringstream windowTitle;
      92           0 :     windowTitle << "eqCpu Example";
      93           0 :     XStoreName(_xDisplay, drawable, windowTitle.str().c_str());
      94             : 
      95             :     // Register for close window request from the window manager
      96           0 :     Atom deleteAtom = XInternAtom(_xDisplay, "WM_DELETE_WINDOW", False);
      97           0 :     XSetWMProtocols(_xDisplay, drawable, &deleteAtom, 1);
      98             : 
      99           0 :     XMoveResizeWindow(_xDisplay, drawable, pvp.x, pvp.y, pvp.w, pvp.h);
     100           0 :     XFlush(_xDisplay);
     101             : 
     102           0 :     return drawable;
     103             : }
     104             : 
     105           0 : void Window::configExit()
     106             : {
     107           0 :     if (_xDrawable)
     108           0 :         XDestroyWindow(_xDisplay, _xDrawable);
     109           0 :     setXDrawable(0);
     110           0 : }
     111             : 
     112           0 : void Window::queryDrawableConfig(DrawableConfig& drawableConfig)
     113             : {
     114           0 :     drawableConfig.stencilBits = 0;
     115           0 :     drawableConfig.alphaBits = 0;
     116           0 :     drawableConfig.glVersion = 0.f;
     117           0 :     drawableConfig.stereo = false;
     118           0 :     drawableConfig.doublebuffered = false;
     119           0 : }
     120             : 
     121           0 : void Window::flush()
     122             : {
     123           0 :     XFlush(_xDisplay);
     124           0 : }
     125             : 
     126           0 : void Window::resize(const PixelViewport& pvp)
     127             : {
     128           0 :     if (_xDisplay && _xDrawable)
     129           0 :         XMoveResizeWindow(_xDisplay, _xDrawable, pvp.x, pvp.y, pvp.w, pvp.h);
     130           0 : }
     131             : }
     132          30 : }

Generated by: LCOV version 1.11