调整 xwindow_get_text_property 函数
This commit is contained in:
@@ -177,27 +177,29 @@ void xwindow_focus(xcb_window_t window) {
|
|||||||
* 获取目标窗口的文本属性
|
* 获取目标窗口的文本属性
|
||||||
* @param window 目标窗口
|
* @param window 目标窗口
|
||||||
* @param property 属性名
|
* @param property 属性名
|
||||||
* @returns 返回的信息使用后记得使用 free 释放
|
* @param out 返回的信息使用后记得使用 free 释放
|
||||||
*/
|
*/
|
||||||
char *xwindow_get_text_property(xcb_window_t window, xcb_atom_t property) {
|
void xwindow_get_text_property(xcb_window_t window, xcb_atom_t property,
|
||||||
|
char **out) {
|
||||||
|
if (out == nullptr) return;
|
||||||
|
|
||||||
xcb_get_property_cookie_t cookie = xcb_get_property_unchecked(
|
xcb_get_property_cookie_t cookie = xcb_get_property_unchecked(
|
||||||
wm.xcb_conn, false, window, property, XCB_ATOM_STRING, 0, UINT32_MAX);
|
wm.xcb_conn, false, window, property, XCB_ATOM_STRING, 0, UINT32_MAX);
|
||||||
xcb_get_property_reply_t *reply =
|
xcb_get_property_reply_t *reply =
|
||||||
xcb_get_property_reply(wm.xcb_conn, cookie, nullptr);
|
xcb_get_property_reply(wm.xcb_conn, cookie, nullptr);
|
||||||
int length = xcb_get_property_value_length(reply);
|
int length = xcb_get_property_value_length(reply);
|
||||||
|
char *value = xcb_get_property_value(reply);
|
||||||
char *value = nullptr;
|
|
||||||
|
|
||||||
if (reply &&
|
if (reply &&
|
||||||
(reply->type == XCB_ATOM_STRING || reply->type == UTF8_STRING ||
|
(reply->type == XCB_ATOM_STRING || reply->type == UTF8_STRING ||
|
||||||
reply->type == COMPOUND_TEXT) &&
|
reply->type == COMPOUND_TEXT) &&
|
||||||
reply->format == 8 && length) {
|
reply->format == 8 && length &&
|
||||||
value = p_new(char, length + 1);
|
(*out == nullptr || strncmp(*out, value, length) != 0)) {
|
||||||
memcpy(value, xcb_get_property_value(reply), length);
|
if (*out) p_delete(out);
|
||||||
value[length] = '\0';
|
*out = p_new(char, length + 1);
|
||||||
|
memcpy(*out, value, length);
|
||||||
|
(*out)[length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
p_delete(&reply);
|
p_delete(&reply);
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ void xwindow_grab_keys(xcb_window_t window, const keyboard_t *keys,
|
|||||||
int keys_length);
|
int keys_length);
|
||||||
bool xwindow_send_event(xcb_window_t window, xcb_atom_t atom);
|
bool xwindow_send_event(xcb_window_t window, xcb_atom_t atom);
|
||||||
void xwindow_focus(xcb_window_t window);
|
void xwindow_focus(xcb_window_t window);
|
||||||
char *xwindow_get_text_property(xcb_window_t window, xcb_atom_t property);
|
void xwindow_get_text_property(xcb_window_t window, xcb_atom_t property,
|
||||||
|
char **out);
|
||||||
|
|
||||||
#define xwindow_set_name_static(window, name) \
|
#define xwindow_set_name_static(window, name) \
|
||||||
xcb_icccm_set_wm_name(wm.xcb_conn, window, XCB_ATOM_STRING, 8, \
|
xcb_icccm_set_wm_name(wm.xcb_conn, window, XCB_ATOM_STRING, 8, \
|
||||||
|
|||||||
Reference in New Issue
Block a user