Files
zswm/src/include/xcb.h

165 lines
5.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <X11/cursorfont.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <xcb/xproto.h>
#include "types.h"
#define WINDOW_NONE XCB_WINDOW_NONE
bool has_other_wm_running(void);
void setup_xcb(void);
int get_xcb_connection_fd(void);
void flush_xcb_connection(void);
typedef enum cursor_t {
cursor_normal = XC_left_ptr,
cursor_resize = XC_bottom_right_corner,
cursor_move = XC_fleur,
} cursor_t;
void change_window_cursor(xcb_window_t window, cursor_t cursor);
xcb_window_t get_root_window(void);
bool get_window_visible(xcb_window_t window);
xcb_window_t get_transient_window_for(xcb_window_t window);
typedef struct window_class_instance_t {
char class[128];
char instance[128];
} window_class_instance_t;
void get_window_class_instance(xcb_window_t window,
window_class_instance_t *class_instance);
typedef struct window_geometry_t {
int32_t x, y;
uint32_t width, height, border_width;
} window_geometry_t;
/**
* @brief 获取窗口的几何信息
* @returns 返回几何信息指针,使用完后记得使用 free 释放内存
*/
window_geometry_t *get_window_geometry(xcb_window_t window);
void map_window(xcb_window_t window, bool map_sub_window);
/**
* @brief 获取窗口名
* @returns 返回窗口名字符串指针,使用完后记得使用 free 释放内存
*/
char *get_window_name(xcb_window_t window);
void set_window_event_mask(xcb_window_t window, bool clear);
void change_window_border_color(xcb_window_t window, uint32_t argb);
void change_window_border_width(xcb_window_t window, uint32_t border_width);
void focus_window(xcb_window_t window);
/**
* @brief 将 window 置于堆叠顺序的顶部
*/
void raise_window(xcb_window_t window);
/**
* @brief 在堆叠顺序中将 window 置于 sibling 之上
*/
void place_window_above_sibling(xcb_window_t window, xcb_window_t sibling);
/**
* @brief 在堆叠顺序中将 window 置于 sibling 之下
*/
void place_window_below_sibling(xcb_window_t window, xcb_window_t sibling);
/**
* @brief 关闭窗口并清理资源
*/
void kill_window(xcb_window_t window);
void set_window_fullscreen_state(xcb_window_t window, bool fullscreen);
typedef struct bar_cairo_params_t {
xcb_connection_t *conn;
xcb_window_t window;
xcb_visualtype_t *visual;
} bar_cairo_params_t;
/**
* @brief 创建每个屏幕的 bar 窗口
* @returns 返回创建 cairo surface 需要的参数,使用完记得使用 free 释放内存
*/
bar_cairo_params_t *create_bar_window(int16_t x, int16_t y, uint16_t width,
uint16_t height, uint32_t background_argb,
cursor_t cursor);
void destroy_window(xcb_window_t window);
void configure_window(xcb_window_t window, int32_t x, int32_t y, uint32_t width,
uint32_t height, uint32_t border_width);
void move_window(xcb_window_t window, int32_t x, int32_t y);
void resize_window(xcb_window_t window, uint32_t width, uint32_t height);
typedef struct monitor_rect_t monitor_rect_t;
struct monitor_rect_t {
int32_t x;
int32_t y;
uint32_t width;
uint32_t height;
monitor_rect_t *next;
};
monitor_rect_t *detect_monitor_rect(void);
typedef struct rect_size_t {
uint32_t width;
uint32_t height;
} rect_size_t;
rect_size_t *get_screen_size(void);
bar_cairo_params_t *prepare_wallpaper_surface_params(void);
void refresh_root_window(void);
void set_wallpaper(uint32_t *wallpaper_data);
typedef struct window_list_t {
xcb_window_t *normal_list;
xcb_window_t *transient_list;
uint32_t normal_count;
uint32_t transient_count;
} window_list_t;
window_list_t *scan_window_list(void);
void free_window_list(window_list_t *window_list);
void clean_xcb(void);
void grab_keybindings(const keybinding_t *keys, const size_t length);
bool get_xresource_uint32(const char *name, uint32_t *value);
void get_xresource_string(const char *name, char **value, const char *fallback);
void clean_xresource(void);
typedef enum atom_t {
atom_wm_protocols,
atom_wm_delete,
atom_wm_take_focus,
atom_net_active_window,
atom_net_wm_name,
atom_net_wm_state,
atom_net_wm_fullscreen,
atom__xrootpmap_id,
atom_esetroot_pmap_id,
atom_zswm_client_info, /* 自定义属性,用于存储所在 monitor 和 tags */
} atom_t;
xcb_atom_t get_xcb_atom(atom_t atom);
bool send_event(xcb_window_t window, atom_t atom);
typedef enum wm_state_t {
wm_state_withdrawn = 0,
wm_state_normal = 1,
wm_state_iconic = 3
} wm_state_t;
int32_t get_window_state(xcb_window_t window);
void set_window_state(xcb_window_t window, wm_state_t state);
void set_window_list(xcb_window_t *list, uint32_t length);
typedef struct client_info_t {
uint32_t tags;
uint32_t monitor_index;
} client_tag_info_t;
bool get_window_tag(xcb_window_t window, client_tag_info_t *client_info);
void set_window_tag(xcb_window_t window, client_tag_info_t *client_info);
void remove_window_tag(xcb_window_t window);
bool get_pointer_position(int32_t *x, int32_t *y);
void set_pointer_position(int32_t x, int32_t y);
/**
* @brief 非阻塞检查特定事件掩码(模拟 XCheckMaskEvent
*/
bool xcb_check_mask_event(xcb_event_mask_t event_mask);
void ungrab_any_button(xcb_window_t window);
void grab_button(xcb_window_t window, uint8_t button, uint16_t modifiers);