什么事件用于最大化/最小化? [英] What event is used for Maximizing/Minimizing?
问题描述
目前,我负责为一个小项目开发(C ++)窗口类;目标是将依赖关系保持在最低限度.Win32/WinAPI的实现按预期工作,但是,在Linux/XCB方面我很挣扎.
Currently I am in charge of developing a (C++) window class for a little project; the goal is to keep dependencies at a bare minimum. The implementation for Win32/WinAPI works as supposed, however, I am struggling when it comes to Linux/XCB.
我知道,我能够检查"_NET_WM_STATE"属性,但是文档没有指定任何事件,在最大化或最小化窗口时会发生.扩展窗口管理器提示规范似乎也没有定义事件.
I am aware, that I am able to check the "_NET_WM_STATE" property, however, the documentation doesn't specify any event, which would occur when the window is being maximized or minimized. The Extended Window Manager Hints specification doesn't seem to define a event either.
那么,如何截获Maximize/Minimize事件?
So, how would one intercept the Maximize/Minimize event?
我的代码基本上像这样,但是不起作用:(由于不起作用,我的意思是永远不会满足以下if条件.)
My code looks basically like that, but doesn't work: (By doesn't work, I mean the if-condition below is never met.)
// xcb_generic_event_t* msg;
// xcb_intern_atom_reply_t* wmStateMinimized;
case XCB_PROPERTY_NOTIFY: {
xcb_property_notify_event_t* data{reinterpret_cast<xcb_property_notify_event_t*>(msg)};
if(data->atom == wmStateMinimized->atom)
eventQueue.emplace(Event::Minimized);
} break;
我还检查了事件提供给我的原子.它们与"wmStateMinimized"提供的原子不同,尽管"wmStateMinimized"的原子由窗口管理器提供.
I have also checked the atoms the event provides me. They differ from the atom provided by 'wmStateMinimized', altough the atom for 'wmStateMinimized' is provided by the window manager.
好的, xcb_property_notify_event_t 提供已更改的原子,而不是其自身的值.因此,if应该看起来像这样:
EDIT 2: Ok, the xcb_property_notify_event_t supplies the atom that has been change, not the value it self. So the if should look like this then:
if(data->atom == wmState->atom)
要弄清楚如何正确获取值.
Gotta figure out, how to retrieve the value properly.
推荐答案
因此,经过3个小时,我终于弄明白了.该解决方案片段假定您已经查询了原子:
So, after 3 hours I finally figured it out. This solution snippet assumes, that you already have queried the atoms:
- _NET_WM_STATE
- _NET_WM_STATE_HIDDEN
- _NET_WM_STATE_MAXIMIZED_VERT
- _NET_WM_STATE_MAXIMIZED_HORZ
它们被存储在以下原子中:
They are being stored in the following atoms:
xcb_atom_t wmState;
xcb_atom_t wmStateHidden;
xcb_atom_t wmStateMaxVert;
xcb_atom_t wmStateMaxHorz;
此代码段也假定您已指定
This snippet does as well assume, that you have specified
XCB_EVENT_MASK_PROPERTY_CHANGE
该窗口,以便实际上获得有关属性更改的通知.
for the window, in order to actually get notified about property changes.
所以,让我们假设我们现在处于事件循环中:
So, let's pretend we're in the Event Loop now:
case XCB_PROPERTY_NOTIFY: {
xcb_property_notify_event_t* data{reinterpret_cast<xcb_property_notify_event_t*>(msg)};
if(data->atom == wmState){ // the WM_STATE property was changed.
// Now we need the value.
// Therefore I implemented an auxiliary function.
if(internal::getAtomValue(connection, window, wmState) == wmStateHidden)
// Handle Events here:
eventQueue.emplace(Event::Minimized);
else{
xcb_atom_t value{internal::getAtomValue(connection, window, wmState)};
if((value == wmStateMaxVert) || (value == wmStateMaxHorz))
// Handle Event here
eventQueue.emplace(Event::Maximized);
}
}
} break;
辅助功能"internal :: getAtomValue"的工作方式如下:
The auxiliary function 'internal::getAtomValue' works as following:
xcb_get_property_cookie_t cookie{xcb_get_property(connection, false, window, atom, XCB_ATOM_ATOM, 0, 32)};
xcb_generic_error_t* err{nullptr};
xcb_get_property_reply_t reply{xcb_get_property_reply(connection, cookie, &err);
xcb_atom_t* value{reinterpret_cast<xcb_atom_t*>(xcb_get_property_value(reply))};
我希望这个解决方案的概念能证明并正确.希望它为需要使用XCB的每个人提供参考.
I hope that this solution concept proof and correct. May it serve as an reference for everyone, who needs to work with XCB.
P.S .:这些摘要是从我的原始资料中删除的.它可能包含Typos.
P.S.: These Snippets were stripped down from my original source. It might contain Typos.
这篇关于什么事件用于最大化/最小化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!