我用SDL2创建了一个简单的OpenGL窗口。我在Linux上运行它,我的WM是xfwm4。
我的问题是,如果我更改工作区(使用ctrl + alt +箭头)而窗口没有聚焦,它会自行升起。这使窗口显示在新工作区上,或者(根据WM设置)立即切换回工作区。有办法防止这种情况吗?
这是一个演示此行为的测试用例:
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, SDL_WINDOW_OPENGL);
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
glEnable(GL_SCISSOR_TEST);
while (1)
{
SDL_Event e;
SDL_PollEvent(&e);
if (e.type == SDL_QUIT || e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)
break;
// a small opengl effect, please don't mind
int bs = (rand() % 50) + 50; int bo = (200-bs)/2;
float t = SDL_GetTicks()*0.001f; glScissor(0, cos(t*18.92623f)*bo+bo,200,bs);
float g = sin(t)*0.5f+0.5f; glClearColor(2.0f*g,1.5f*g,0.8f*g,0.f); glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(glcontext);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}