需要的库
xcb-ewmh x11 xext xrender
可能上述只需要一部分
第一步(初始化atom)
//初始化atom
//QX11Info::connection()是 xcb_connection_t *,在qt里面直接使用这个,其他的地方也可以有替代和创建
//该步骤为了初始化m_ewmh_connection;一次初始化,重复使用。
void initAtom()
{
xcb_intern_atom_cookie_t *cookie = xcb_ewmh_init_atoms(QX11Info::connection(), &m_ewmh_connection);
xcb_ewmh_init_atoms_replies(&m_ewmh_connection, cookie, NULL);
}
//输入wid,返回窗口类型
uint32_t searchWindowType(int wid)
{
uint32_t reId = 0;
QMutexLocker locker(&m_mutex);
// if (m_cookie) {
xcb_get_property_cookie_t cooke = xcb_ewmh_get_wm_window_type(&m_ewmh_connection, wid);
xcb_ewmh_get_atoms_reply_t name;
xcb_generic_error_t *error_t = new xcb_generic_error_t;
xcb_ewmh_get_wm_window_type_reply(&m_ewmh_connection, cooke, &name, &error_t);
if (error_t) {
delete error_t;
error_t = NULL;
return 381;//381为普通窗口
} else {
}
if (name.atoms && name.atoms_len <= 10) {
reId = name.atoms[0];
}
return reId;
}
//窗口类型匹配
uint32_t type = searchWindowType( wid)
比如 if(type ==m_ewmh_connection._NET_WM_WINDOW_TYPE_DESKTOP){
//窗口是桌面属性窗口
}
if(type ==m_ewmh_connection._NET_WM_WINDOW_TYPE_DOCK){
//窗口是dock属性窗口
}
if(type ==m_ewmh_connection._NET_WM_WINDOW_TYPE_NORMAL){
//窗口是普通窗口
}
## 可以对比的对象
//窗口类型
/**
* @brief Hold EWMH information specific to a screen
*/
typedef struct {
/** The X connection */
xcb_connection_t *connection;
/** The screens on this connection */
xcb_screen_t **screens;
int nb_screens;
/** _NET_WM_CM_Sn atoms depending on the number of screens */
xcb_atom_t *_NET_WM_CM_Sn;
/** The EWMH atoms of this connection */
xcb_atom_t _NET_SUPPORTED;
xcb_atom_t _NET_CLIENT_LIST;
xcb_atom_t _NET_CLIENT_LIST_STACKING;
xcb_atom_t _NET_NUMBER_OF_DESKTOPS;
xcb_atom_t _NET_DESKTOP_GEOMETRY;
xcb_atom_t _NET_DESKTOP_VIEWPORT;
xcb_atom_t _NET_CURRENT_DESKTOP;
xcb_atom_t _NET_DESKTOP_NAMES;
xcb_atom_t _NET_ACTIVE_WINDOW;
xcb_atom_t _NET_WORKAREA;
xcb_atom_t _NET_SUPPORTING_WM_CHECK;
xcb_atom_t _NET_VIRTUAL_ROOTS;
xcb_atom_t _NET_DESKTOP_LAYOUT;
xcb_atom_t _NET_SHOWING_DESKTOP;
xcb_atom_t _NET_CLOSE_WINDOW;
xcb_atom_t _NET_MOVERESIZE_WINDOW;
xcb_atom_t _NET_WM_MOVERESIZE;
xcb_atom_t _NET_RESTACK_WINDOW;
xcb_atom_t _NET_REQUEST_FRAME_EXTENTS;
xcb_atom_t _NET_WM_NAME;
xcb_atom_t _NET_WM_VISIBLE_NAME;
xcb_atom_t _NET_WM_ICON_NAME;
xcb_atom_t _NET_WM_VISIBLE_ICON_NAME;
xcb_atom_t _NET_WM_DESKTOP;
xcb_atom_t _NET_WM_WINDOW_TYPE;
xcb_atom_t _NET_WM_STATE;
xcb_atom_t _NET_WM_ALLOWED_ACTIONS;
xcb_atom_t _NET_WM_STRUT;
xcb_atom_t _NET_WM_STRUT_PARTIAL;
xcb_atom_t _NET_WM_ICON_GEOMETRY;
xcb_atom_t _NET_WM_ICON;
xcb_atom_t _NET_WM_PID;
xcb_atom_t _NET_WM_HANDLED_ICONS;
xcb_atom_t _NET_WM_USER_TIME;
xcb_atom_t _NET_WM_USER_TIME_WINDOW;
xcb_atom_t _NET_FRAME_EXTENTS;
xcb_atom_t _NET_WM_PING;
xcb_atom_t _NET_WM_SYNC_REQUEST;
xcb_atom_t _NET_WM_SYNC_REQUEST_COUNTER;
xcb_atom_t _NET_WM_FULLSCREEN_MONITORS;
xcb_atom_t _NET_WM_FULL_PLACEMENT;
xcb_atom_t UTF8_STRING;
xcb_atom_t WM_PROTOCOLS;
xcb_atom_t MANAGER;
xcb_atom_t _NET_WM_WINDOW_TYPE_DESKTOP;
xcb_atom_t _NET_WM_WINDOW_TYPE_DOCK;
xcb_atom_t _NET_WM_WINDOW_TYPE_TOOLBAR;
xcb_atom_t _NET_WM_WINDOW_TYPE_MENU;
xcb_atom_t _NET_WM_WINDOW_TYPE_UTILITY;
xcb_atom_t _NET_WM_WINDOW_TYPE_SPLASH;
xcb_atom_t _NET_WM_WINDOW_TYPE_DIALOG;
xcb_atom_t _NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
xcb_atom_t _NET_WM_WINDOW_TYPE_POPUP_MENU;
xcb_atom_t _NET_WM_WINDOW_TYPE_TOOLTIP;
xcb_atom_t _NET_WM_WINDOW_TYPE_NOTIFICATION;
xcb_atom_t _NET_WM_WINDOW_TYPE_COMBO;
xcb_atom_t _NET_WM_WINDOW_TYPE_DND;
xcb_atom_t _NET_WM_WINDOW_TYPE_NORMAL;
xcb_atom_t _NET_WM_STATE_MODAL;
xcb_atom_t _NET_WM_STATE_STICKY;
xcb_atom_t _NET_WM_STATE_MAXIMIZED_VERT;
xcb_atom_t _NET_WM_STATE_MAXIMIZED_HORZ;
xcb_atom_t _NET_WM_STATE_SHADED;
xcb_atom_t _NET_WM_STATE_SKIP_TASKBAR;
xcb_atom_t _NET_WM_STATE_SKIP_PAGER;
xcb_atom_t _NET_WM_STATE_HIDDEN;
xcb_atom_t _NET_WM_STATE_FULLSCREEN;
xcb_atom_t _NET_WM_STATE_ABOVE;
xcb_atom_t _NET_WM_STATE_BELOW;
xcb_atom_t _NET_WM_STATE_DEMANDS_ATTENTION;
xcb_atom_t _NET_WM_ACTION_MOVE;
xcb_atom_t _NET_WM_ACTION_RESIZE;
xcb_atom_t _NET_WM_ACTION_MINIMIZE;
xcb_atom_t _NET_WM_ACTION_SHADE;
xcb_atom_t _NET_WM_ACTION_STICK;
xcb_atom_t _NET_WM_ACTION_MAXIMIZE_HORZ;
xcb_atom_t _NET_WM_ACTION_MAXIMIZE_VERT;
xcb_atom_t _NET_WM_ACTION_FULLSCREEN;
xcb_atom_t _NET_WM_ACTION_CHANGE_DESKTOP;
xcb_atom_t _NET_WM_ACTION_CLOSE;
xcb_atom_t _NET_WM_ACTION_ABOVE;
xcb_atom_t _NET_WM_ACTION_BELOW;
} xcb_ewmh_connection_t;