Ejemplo n.º 1
0
void
KWD::Switcher::updateGeometry ()
{
	int x, y;
	unsigned int width, height, border, depth;
	XID root;

	XGetGeometry (QX11Info::display (), mId, &root, &x, &y, &width, &height,
	              &border, &depth);

	mGeometry = QRect (x, y, width, height);

	KWD::readWindowProperty (mId, Atoms::switchSelectWindow,
	                        (long *)&mSelected);

	if (mX11Pixmap)
		XFreePixmap (QX11Info::display (), mX11Pixmap);
	if (mX11BackgroundPixmap)
		XFreePixmap (QX11Info::display (), mX11BackgroundPixmap);

	mX11Pixmap = XCreatePixmap (QX11Info::display (),
	                            QX11Info::appRootWindow (),
	                            width + mBorder.left + mBorder.right,
	                            height + mBorder.top + mBorder.bottom, 32);

	mX11BackgroundPixmap = XCreatePixmap (QX11Info::display (),
	                                      QX11Info::appRootWindow (),
	                                      width, height, 32);

	mPixmap = QPixmap::fromX11Pixmap (mX11Pixmap, QPixmap::ExplicitlyShared);
	mBackgroundPixmap = QPixmap::fromX11Pixmap (mX11BackgroundPixmap,
	                                            QPixmap::ExplicitlyShared);

	redrawPixmap ();
	update ();

	decor_get_default_layout (&mContext,
	                          mGeometry.width (),
	                          mGeometry.height (),
	                          &mDecorLayout);

	updateWindowProperties ();
}
Ejemplo n.º 2
0
    void GLWindow::onWindowResize(void* wnd, WindowResizeEventArgs& args) {
        updateWindowProperties(left(), top(), args.width, args.height);

    }
Ejemplo n.º 3
0
    GLWindow::GLWindow(const UknString& name, const RenderSettings& settings):
        mFrameBuffer(new GLFrameBuffer(false)),
        Window(name) {
            glfwSetErrorCallback(ErrorCallback);
            glfwInit();

            switch(settings.color_fmt) {
            case EF_RGBA8:
                glfwWindowHint(GLFW_RED_BITS, 8);
                glfwWindowHint(GLFW_BLUE_BITS, 8);
                glfwWindowHint(GLFW_GREEN_BITS, 8);
                glfwWindowHint(GLFW_ALPHA_BITS, 8);
                break;

            default:
                // error
                break;
            }

            switch(settings.depth_stencil_fmt) {
            case EF_D16:
                glfwWindowHint(GLFW_DEPTH_BITS, 16);
                glfwWindowHint(GLFW_STENCIL_BITS, 0);

                mFrameBuffer->mIsDepthBuffered = true;
                mFrameBuffer->mDepthBits = 16;
                mFrameBuffer->mStencilBits = 0;
                break;

            case EF_D24S8:
                glfwWindowHint(GLFW_DEPTH_BITS, 24);
                glfwWindowHint(GLFW_STENCIL_BITS, 8);

                mFrameBuffer->mIsDepthBuffered = true;
                mFrameBuffer->mDepthBits = 24;
                mFrameBuffer->mStencilBits = 8;
                break;

            default:
                glfwWindowHint(GLFW_DEPTH_BITS, 0);
                glfwWindowHint(GLFW_STENCIL_BITS, 0);

                mFrameBuffer->mIsDepthBuffered = false;
                mFrameBuffer->mDepthBits = 0;
                mFrameBuffer->mStencilBits = 0;
                break;
            }

            if(settings.sample_quality > 0) {
                glfwWindowHint(GLFW_SAMPLES, settings.sample_quality);
            }

            glfwWindowHint(GLFW_RESIZABLE, settings.resizable);

            /* maybe there are bugs... let glfw decide the best version */
            /*
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, UKN_OPENGL_VERSION_MAJOR);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, UKN_OPENGL_VERSION_MINOR);
            if(UKN_OPENGL_VERSION_MAJOR >= 3) {
                glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#if defined(MIST_OS_OSX)
                glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#else
                glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
#endif
            }
            */
            if(!settings.native_window_handle) {
                if((mGlfwWindow = glfwCreateWindow(settings.width,
                                                   settings.height,
                                                   string::WStringToString(name).c_str(),
                                                   settings.full_screen ? glfwGetPrimaryMonitor() : 0,
                                                   0)) == 0) {
                        MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error opening window");
                }
            } else {
                if((mGlfwWindow = glfwCreateWindowSlave((void*)settings.native_window_handle,
                                                        0)) == 0) {
                    MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error creating slave window on native handle");
                }
            }
            glfwMakeContextCurrent(mGlfwWindow);

#if !defined(UKN_OSX_REQUEST_OPENGL_32_CORE_PROFILE)
            GLenum err = glewInit();
            if (GLEW_OK != err) {
                    MIST_THROW_EXCEPTION(mist::string::StringToWString(format_string("GLWindow::GLWindow: error initializing glew profilem, error; %s", glewGetErrorString(err))));
            }
#endif

            // if wnd pos is (0, 0), then put it in the center of current screen
            int32 wndPosX = settings.left, wndPosY = settings.top;
            if(wndPosX == 0 && wndPosY == 0) {
                Array<SystemInformation::DesktopMode> desktop_modes = SystemInformation::EnumDesktopMode();

                wndPosX = (desktop_modes[0].width - settings.width) / 2;
                wndPosY = (desktop_modes[0].height - settings.height) / 2;
            }


            glfwSetWindowPos(mGlfwWindow, wndPosX, wndPosY);
            glfwSetWindowUserPointer(mGlfwWindow, this);
            
            
            glfwSetErrorCallback(ErrorFunc);
            glfwSetWindowSizeCallback(mGlfwWindow, WindowSizeFunc);
            glfwSetWindowCloseCallback(mGlfwWindow, WindowCloseFunc);
            glfwSetWindowRefreshCallback(mGlfwWindow, WindowRefreshFunc);
            glfwSetWindowFocusCallback(mGlfwWindow, WindowFocusFunc);
            glfwSetWindowIconifyCallback(mGlfwWindow, WindowIconifyFunc);

            glfwSetKeyCallback(mGlfwWindow, KeyFunc);
            glfwSetCursorPosCallback(mGlfwWindow, MousePosFunc);
            glfwSetMouseButtonCallback(mGlfwWindow, MouseButtonFunc);
            glfwSetScrollCallback(mGlfwWindow, ScrollFunc);
            glfwSetCharCallback(mGlfwWindow, CharFunc);
            
            // to do with joysticks

            glfwSwapInterval(0);

            mFrameBuffer->attach(ATT_Color0, RenderViewPtr(new GLScreenColorRenderView(settings.width, 
                settings.height,
                settings.color_fmt)));
            mFrameBuffer->attach(ATT_DepthStencil, RenderViewPtr(new GLScreenDepthStencilRenderView(settings.width, 
                settings.height,
                settings.depth_stencil_fmt)));

            onResize() += Bind(this, &GLWindow::onWindowResize);

            updateWindowProperties(wndPosX, wndPosY, settings.width, settings.height);
    }