显示窗口
This commit is contained in:
101
src/xcb/window.c
101
src/xcb/window.c
@@ -5,6 +5,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
@@ -155,6 +157,21 @@ bar_cairo_params_t *create_bar_window(int16_t x, int16_t y, uint16_t width,
|
||||
|
||||
void destroy_window(xcb_window_t window) { xcb_destroy_window(conn, window); }
|
||||
|
||||
void configure_window(xcb_window_t window, int32_t x, int32_t y, uint32_t width,
|
||||
uint32_t height, uint32_t border_width) {
|
||||
xcb_config_window_t config_mask =
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH |
|
||||
XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH;
|
||||
xcb_params_configure_window_t window_config = {
|
||||
.x = x,
|
||||
.y = y,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.border_width = border_width,
|
||||
};
|
||||
xcb_aux_configure_window(conn, window, config_mask, &window_config);
|
||||
}
|
||||
|
||||
void change_window_cursor(xcb_window_t window, cursor_t cursor) {
|
||||
xcb_change_window_attributes_value_list_t value_list = {
|
||||
.cursor = get_xcb_cursor(cursor),
|
||||
@@ -163,6 +180,86 @@ void change_window_cursor(xcb_window_t window, cursor_t cursor) {
|
||||
xcb_flush(conn);
|
||||
}
|
||||
|
||||
void set_root_cursor(cursor_t cursor) {
|
||||
change_window_cursor(screen->root, cursor);
|
||||
xcb_window_t get_root_window(void) { return screen->root; }
|
||||
|
||||
bool get_window_visible(xcb_window_t window) {
|
||||
xcb_get_window_attributes_cookie_t cookie =
|
||||
xcb_get_window_attributes(conn, window);
|
||||
xcb_get_window_attributes_reply_t *reply =
|
||||
xcb_get_window_attributes_reply(conn, cookie, NULL);
|
||||
bool visible =
|
||||
!reply->override_redirect && reply->map_state != XCB_MAP_STATE_UNVIEWABLE;
|
||||
free(reply);
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
xcb_window_t get_transient_window_for(xcb_window_t window) {
|
||||
xcb_window_t transient_for = XCB_NONE;
|
||||
xcb_get_property_cookie_t cookie =
|
||||
xcb_icccm_get_wm_transient_for(conn, window);
|
||||
xcb_icccm_get_wm_transient_for_reply(conn, cookie, &transient_for, NULL);
|
||||
return transient_for;
|
||||
}
|
||||
|
||||
window_geometry_t *get_window_geometry(xcb_window_t window) {
|
||||
xcb_get_geometry_cookie_t cookie = xcb_get_geometry(conn, window);
|
||||
xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(conn, cookie, NULL);
|
||||
|
||||
window_geometry_t *geometry = ecalloc(1, sizeof(window_geometry_t));
|
||||
geometry->x = reply->x;
|
||||
geometry->y = reply->y;
|
||||
geometry->width = reply->width;
|
||||
geometry->height = reply->height;
|
||||
geometry->border_width = reply->border_width;
|
||||
|
||||
free(reply);
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void map_window(xcb_window_t window) {
|
||||
xcb_map_window(conn, window);
|
||||
xcb_map_subwindows(conn, window);
|
||||
}
|
||||
|
||||
char *get_window_name(xcb_window_t window) {
|
||||
xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_name(ewmh, window);
|
||||
xcb_ewmh_get_utf8_strings_reply_t reply;
|
||||
xcb_ewmh_get_wm_name_reply(ewmh, cookie, &reply, NULL);
|
||||
if (reply.strings_len) {
|
||||
char *name = ecalloc(reply.strings_len + 1, sizeof(char));
|
||||
strncpy(name, reply.strings, reply.strings_len);
|
||||
return name;
|
||||
}
|
||||
|
||||
cookie = xcb_icccm_get_wm_name(conn, window);
|
||||
xcb_icccm_get_text_property_reply_t prop;
|
||||
xcb_icccm_get_wm_name_reply(conn, cookie, &prop, NULL);
|
||||
if (prop.name_len) {
|
||||
char *name = ecalloc(prop.name_len + 1, sizeof(char));
|
||||
strncpy(name, prop.name, prop.name_len);
|
||||
return name;
|
||||
}
|
||||
|
||||
{
|
||||
const char *broken = "broken";
|
||||
char *name = ecalloc(strlen(broken) + 1, sizeof(char));
|
||||
strncpy(name, broken, strlen(broken));
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
void init_window_event_mask(xcb_window_t window) {
|
||||
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
|
||||
xcb_params_cw_t params = {
|
||||
.event_mask = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE |
|
||||
XCB_EVENT_MASK_PROPERTY_CHANGE |
|
||||
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
|
||||
};
|
||||
xcb_aux_change_window_attributes(conn, window, change_mask, ¶ms);
|
||||
}
|
||||
|
||||
void change_window_border_color(xcb_window_t window, uint32_t argb) {
|
||||
xcb_params_cw_t params = {.border_pixel = argb};
|
||||
xcb_aux_change_window_attributes(conn, window, XCB_CW_BORDER_PIXEL, ¶ms);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user