创建每个屏幕对应的信息条窗口
This commit is contained in:
@@ -35,7 +35,8 @@ pkg_check_modules(XCB REQUIRED
|
||||
xcb-xinerama
|
||||
xcb-xrm
|
||||
)
|
||||
pkg_check_modules(RENDERER REQUIRED imlib2)
|
||||
pkg_check_modules(RENDERER REQUIRED cairo pango pangocairo imlib2)
|
||||
pkg_check_modules(CAIRO_XCB REQUIRED cairo-xcb)
|
||||
|
||||
add_subdirectory(xcb)
|
||||
add_subdirectory(renderer)
|
||||
@@ -48,6 +49,7 @@ configure_file(
|
||||
|
||||
target_include_directories(${APP_NAME} SYSTEM
|
||||
PRIVATE ${GLIB_INCLUDE_DIRS}
|
||||
PRIVATE ${CAIRO_XCB_INCLUDE_DIRS}
|
||||
)
|
||||
target_include_directories(${APP_NAME}
|
||||
PRIVATE "${SOURCE_DIR}/include"
|
||||
@@ -57,6 +59,7 @@ target_include_directories(${APP_NAME}
|
||||
|
||||
target_link_libraries(${APP_NAME}
|
||||
PRIVATE ${GLIB_LIBRARIES}
|
||||
PRIVATE ${CAIRO_XCB_LIBRARIES}
|
||||
PRIVATE ${LIB_XCB_NAME}
|
||||
PRIVATE ${LIB_RENDERER_NAME}
|
||||
)
|
||||
|
||||
@@ -68,3 +68,10 @@ const char *const active_client_name_color = "#005577";
|
||||
const char *const status_color = "#bbbbbb";
|
||||
const char *const border_color = "#444444";
|
||||
const char *const active_border_color = "#005577";
|
||||
|
||||
const char *const default_font_family = "sans-serif, monospace";
|
||||
const uint32_t default_font_size = 10;
|
||||
const uint32_t dpi_fallback = 96;
|
||||
|
||||
const uint32_t bar_y_padding = 1;
|
||||
const uint32_t tag_x_padding = 10;
|
||||
|
||||
@@ -8,3 +8,7 @@ uint32_t *generate_wallpaper(const wallpaper_config_t *wallpaper_config,
|
||||
const monitor_t *monitors, const uint32_t index,
|
||||
const uint32_t screen_width,
|
||||
const uint32_t screen_height);
|
||||
|
||||
uint32_t get_font_height(const char *font_family, const uint32_t font_size,
|
||||
const uint32_t dpi);
|
||||
void clean_pango_context(void);
|
||||
|
||||
@@ -24,7 +24,6 @@ struct monitor_t {
|
||||
|
||||
/* 为了避免引入 cairo 相关头文件,这里用 void *
|
||||
* 指针代替实际的指针类型,使用时强转为相应指针类型使用即可 */
|
||||
void *surface; /* cairo_surface_t */
|
||||
void *cr; /* cairo_t */
|
||||
|
||||
const layout_t *layout;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <X11/cursorfont.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <xcb/xproto.h>
|
||||
@@ -7,6 +8,28 @@
|
||||
bool has_other_wm_running(void);
|
||||
int get_xcb_connection_fd(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);
|
||||
void set_root_cursor(cursor_t cursor);
|
||||
|
||||
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);
|
||||
|
||||
typedef struct monitor_rect_t monitor_rect_t;
|
||||
struct monitor_rect_t {
|
||||
int32_t x;
|
||||
|
||||
63
src/main.c
63
src/main.c
@@ -1,3 +1,5 @@
|
||||
#include <cairo-xcb.h>
|
||||
#include <cairo.h>
|
||||
#include <glib.h>
|
||||
#include <glibconfig.h>
|
||||
#include <stdbool.h>
|
||||
@@ -23,6 +25,8 @@ static wallpaper_config_t *parse_wallpaper_config(void);
|
||||
static void free_wallpaper_config(wallpaper_config_t *wallpaper_config);
|
||||
static void init_color_set(void);
|
||||
static void parse_color(const char *hex, color_t *color);
|
||||
static void init_monitor_bar(void);
|
||||
static void get_xresource_config(void);
|
||||
static void init_xcb_event_loop(void);
|
||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
gpointer userdata);
|
||||
@@ -32,6 +36,12 @@ static monitor_t *monitors = NULL;
|
||||
static wallpaper_config_t *wallpaper_config = NULL;
|
||||
static color_set_t *color_set = NULL;
|
||||
static GMainLoop *loop = NULL;
|
||||
static char *font_family = NULL;
|
||||
static uint32_t font_size = default_font_size;
|
||||
static uint32_t dpi = dpi_fallback;
|
||||
static uint32_t bar_y_pad = bar_y_padding;
|
||||
static uint32_t tag_x_pad = tag_x_padding;
|
||||
static uint32_t bar_height = 0;
|
||||
|
||||
/* 调试函数,开发完成后删除 */
|
||||
static void print_monitor_list_info(monitor_t *monitor_list) {
|
||||
@@ -278,6 +288,48 @@ void parse_color(const char *hex, color_t *color) {
|
||||
&color->alpha);
|
||||
}
|
||||
|
||||
void init_monitor_bar(void) {
|
||||
get_xresource_config();
|
||||
uint32_t font_height = get_font_height(font_family, font_size, dpi);
|
||||
bar_height = font_height + bar_y_pad * 2;
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
bar_cairo_params_t *p =
|
||||
create_bar_window(m->monitor_x, m->monitor_y, m->monitor_width,
|
||||
bar_height, color_set->bar_bg.argb, cursor_normal);
|
||||
m->window_x = m->monitor_x;
|
||||
m->window_width = m->monitor_width;
|
||||
m->window_y = m->monitor_y + bar_height;
|
||||
m->window_height = m->monitor_height - bar_height;
|
||||
m->bar_window = p->window;
|
||||
|
||||
cairo_surface_t *surface = cairo_xcb_surface_create(
|
||||
p->conn, p->window, p->visual, m->monitor_width, bar_height);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
cairo_surface_destroy(surface);
|
||||
free(p);
|
||||
|
||||
cairo_status_t status = cairo_status(cr);
|
||||
if (status != CAIRO_STATUS_SUCCESS) {
|
||||
die("cannot create cairo context: %s\n", cairo_status_to_string(status));
|
||||
}
|
||||
|
||||
m->cr = cr;
|
||||
}
|
||||
printf("font height: %u, bar height: %u\n", font_height, bar_height);
|
||||
}
|
||||
|
||||
void get_xresource_config(void) {
|
||||
get_xresource_uint32("Xft.dpi", &dpi);
|
||||
get_xresource_string("zswm.font_family", &font_family, default_font_family);
|
||||
get_xresource_uint32("zswm.font_size", &font_size);
|
||||
get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad);
|
||||
get_xresource_uint32("zswm.tag_x_padding", &tag_x_pad);
|
||||
|
||||
printf("dpi: %u, font family: %s, font size: %u\n", dpi, font_family,
|
||||
font_size);
|
||||
clean_xresource();
|
||||
}
|
||||
|
||||
void init_xcb_event_loop(void) {
|
||||
GIOChannel *channel = g_io_channel_unix_new(get_xcb_connection_fd());
|
||||
g_io_channel_set_encoding(channel, NULL, NULL);
|
||||
@@ -298,7 +350,7 @@ gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
}
|
||||
|
||||
void cleanup(void) {
|
||||
clean_xcb();
|
||||
clean_pango_context();
|
||||
|
||||
free_wallpaper_config(wallpaper_config);
|
||||
wallpaper_config = NULL;
|
||||
@@ -306,6 +358,9 @@ void cleanup(void) {
|
||||
free(color_set);
|
||||
color_set = NULL;
|
||||
|
||||
free(font_family);
|
||||
font_family = NULL;
|
||||
|
||||
monitor_t *m = monitors;
|
||||
client_t *c = m->clients;
|
||||
while (m) {
|
||||
@@ -315,11 +370,15 @@ void cleanup(void) {
|
||||
c = tc;
|
||||
}
|
||||
monitor_t *next_monitor = m->next;
|
||||
if (m->cr) cairo_destroy(m->cr);
|
||||
destroy_window(m->bar_window);
|
||||
g_strfreev(m->tags);
|
||||
free(m);
|
||||
m = next_monitor;
|
||||
}
|
||||
monitors = NULL;
|
||||
|
||||
clean_xcb();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -329,6 +388,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
init_monitors();
|
||||
init_color_set();
|
||||
init_monitor_bar();
|
||||
set_root_cursor(cursor_normal);
|
||||
init_wallpaper();
|
||||
|
||||
window_list_t *window_list = scan_window_list();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(LIB_RENDERER "zswm-renderer")
|
||||
set(LIB_RENDERER_NAME ${LIB_RENDERER} PARENT_SCOPE)
|
||||
|
||||
add_library(${LIB_RENDERER} STATIC image.c)
|
||||
add_library(${LIB_RENDERER} STATIC image.c text.c)
|
||||
target_include_directories(${LIB_RENDERER} SYSTEM
|
||||
PRIVATE ${RENDERER_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
51
src/renderer/text.c
Normal file
51
src/renderer/text.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango-attributes.h>
|
||||
#include <pango/pango-context.h>
|
||||
#include <pango/pango-font.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#include <pango/pango-layout.h>
|
||||
#include <pango/pango-types.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
static PangoContext *context = NULL;
|
||||
|
||||
uint32_t get_font_height(const char *font_family, const uint32_t font_size,
|
||||
const uint32_t dpi) {
|
||||
clean_pango_context();
|
||||
|
||||
PangoFontMap *fontmap = pango_cairo_font_map_new();
|
||||
context = pango_font_map_create_context(fontmap);
|
||||
|
||||
pango_cairo_context_set_resolution(context, dpi);
|
||||
PangoLanguage *lang = pango_context_get_language(context);
|
||||
PangoAttrList *attr_list = pango_attr_list_new();
|
||||
|
||||
PangoFontDescription *desc = pango_font_description_from_string(font_family);
|
||||
pango_font_description_set_size(desc, font_size * PANGO_SCALE);
|
||||
|
||||
PangoAttribute *attr = pango_attr_font_desc_new(desc);
|
||||
pango_attr_list_insert(attr_list, attr);
|
||||
pango_attr_list_unref(attr_list);
|
||||
|
||||
PangoFontMetrics *metrics = pango_context_get_metrics(context, desc, lang);
|
||||
int ascent = pango_font_metrics_get_ascent(metrics);
|
||||
int descent = pango_font_metrics_get_descent(metrics);
|
||||
uint32_t font_height = PANGO_PIXELS(ascent + descent);
|
||||
|
||||
pango_font_metrics_unref(metrics);
|
||||
pango_font_description_free(desc);
|
||||
g_object_unref(fontmap);
|
||||
|
||||
return font_height;
|
||||
}
|
||||
|
||||
void clean_pango_context(void) {
|
||||
if (!context) return;
|
||||
|
||||
g_object_unref(context);
|
||||
context = NULL;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
set(LIB_XCB "zswm-xcb")
|
||||
set(LIB_XCB_NAME ${LIB_XCB} PARENT_SCOPE)
|
||||
|
||||
add_library(${LIB_XCB} STATIC xcb.c window.c res.c)
|
||||
add_library(${LIB_XCB} STATIC xcb.c window.c res.c cursor.c)
|
||||
|
||||
target_include_directories(${LIB_XCB} SYSTEM
|
||||
PRIVATE ${XCB_INCLUDE_DIRS}
|
||||
|
||||
116
src/xcb/cursor.c
Normal file
116
src/xcb/cursor.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include <X11/cursorfont.h>
|
||||
#include <xcb/xcb_cursor.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "xcb-private.h"
|
||||
#include "xcb.h"
|
||||
|
||||
static const char *const xcursor_font[] = {
|
||||
[XC_X_cursor] = "X_cursor",
|
||||
[XC_arrow] = "arrow",
|
||||
[XC_based_arrow_down] = "based_arrow_down",
|
||||
[XC_based_arrow_up] = "based_arrow_up",
|
||||
[XC_boat] = "boat",
|
||||
[XC_bogosity] = "bogosity",
|
||||
[XC_bottom_left_corner] = "bottom_left_corner",
|
||||
[XC_bottom_right_corner] = "bottom_right_corner",
|
||||
[XC_bottom_side] = "bottom_side",
|
||||
[XC_bottom_tee] = "bottom_tee",
|
||||
[XC_box_spiral] = "box_spiral",
|
||||
[XC_center_ptr] = "center_ptr",
|
||||
[XC_circle] = "circle",
|
||||
[XC_clock] = "clock",
|
||||
[XC_coffee_mug] = "coffee_mug",
|
||||
[XC_cross] = "cross",
|
||||
[XC_cross_reverse] = "cross_reverse",
|
||||
[XC_crosshair] = "crosshair",
|
||||
[XC_diamond_cross] = "diamond_cross",
|
||||
[XC_dot] = "dot",
|
||||
[XC_dotbox] = "dotbox",
|
||||
[XC_double_arrow] = "double_arrow",
|
||||
[XC_draft_large] = "draft_large",
|
||||
[XC_draft_small] = "draft_small",
|
||||
[XC_draped_box] = "draped_box",
|
||||
[XC_exchange] = "exchange",
|
||||
[XC_fleur] = "fleur",
|
||||
[XC_gobbler] = "gobbler",
|
||||
[XC_gumby] = "gumby",
|
||||
[XC_hand1] = "hand1",
|
||||
[XC_hand2] = "hand2",
|
||||
[XC_heart] = "heart",
|
||||
[XC_icon] = "icon",
|
||||
[XC_iron_cross] = "iron_cross",
|
||||
[XC_left_ptr] = "left_ptr",
|
||||
[XC_left_side] = "left_side",
|
||||
[XC_left_tee] = "left_tee",
|
||||
[XC_leftbutton] = "leftbutton",
|
||||
[XC_ll_angle] = "ll_angle",
|
||||
[XC_lr_angle] = "lr_angle",
|
||||
[XC_man] = "man",
|
||||
[XC_middlebutton] = "middlebutton",
|
||||
[XC_mouse] = "mouse",
|
||||
[XC_pencil] = "pencil",
|
||||
[XC_pirate] = "pirate",
|
||||
[XC_plus] = "plus",
|
||||
[XC_question_arrow] = "question_arrow",
|
||||
[XC_right_ptr] = "right_ptr",
|
||||
[XC_right_side] = "right_side",
|
||||
[XC_right_tee] = "right_tee",
|
||||
[XC_rightbutton] = "rightbutton",
|
||||
[XC_rtl_logo] = "rtl_logo",
|
||||
[XC_sailboat] = "sailboat",
|
||||
[XC_sb_down_arrow] = "sb_down_arrow",
|
||||
[XC_sb_h_double_arrow] = "sb_h_double_arrow",
|
||||
[XC_sb_left_arrow] = "sb_left_arrow",
|
||||
[XC_sb_right_arrow] = "sb_right_arrow",
|
||||
[XC_sb_up_arrow] = "sb_up_arrow",
|
||||
[XC_sb_v_double_arrow] = "sb_v_double_arrow",
|
||||
[XC_shuttle] = "shuttle",
|
||||
[XC_sizing] = "sizing",
|
||||
[XC_spider] = "spider",
|
||||
[XC_spraycan] = "spraycan",
|
||||
[XC_star] = "star",
|
||||
[XC_target] = "target",
|
||||
[XC_tcross] = "tcross",
|
||||
[XC_top_left_arrow] = "top_left_arrow",
|
||||
[XC_top_left_corner] = "top_left_corner",
|
||||
[XC_top_right_corner] = "top_right_corner",
|
||||
[XC_top_side] = "top_side",
|
||||
[XC_top_tee] = "top_tee",
|
||||
[XC_trek] = "trek",
|
||||
[XC_ul_angle] = "ul_angle",
|
||||
[XC_umbrella] = "umbrella",
|
||||
[XC_ur_angle] = "ur_angle",
|
||||
[XC_watch] = "watch",
|
||||
[XC_xterm] = "xterm",
|
||||
};
|
||||
|
||||
static xcb_cursor_context_t *get_xcb_cursor_context(void) {
|
||||
static xcb_cursor_context_t *ctx = NULL;
|
||||
if (ctx) return ctx;
|
||||
|
||||
if (xcb_cursor_context_new(conn, screen, &ctx) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static const char *xcursor_font_tostr(uint16_t c) {
|
||||
if (c < LENGTH(xcursor_font)) {
|
||||
return xcursor_font[c];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xcb_cursor_t get_xcb_cursor(cursor_t cursor) {
|
||||
xcb_cursor_context_t *ctx = get_xcb_cursor_context();
|
||||
if (!ctx) die("cannot get cursor:");
|
||||
|
||||
static xcb_cursor_t cursor_list[LENGTH(xcursor_font)];
|
||||
if (!cursor_list[cursor]) {
|
||||
const char *name = xcursor_font_tostr(cursor);
|
||||
cursor_list[cursor] = xcb_cursor_load_cursor(ctx, name);
|
||||
}
|
||||
return cursor_list[cursor];
|
||||
}
|
||||
142
src/xcb/window.c
142
src/xcb/window.c
@@ -1,10 +1,17 @@
|
||||
#include "window.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "utils.h"
|
||||
#include "xcb-private.h"
|
||||
#include "xcb.h"
|
||||
|
||||
void set_window_class_instance(xcb_window_t window, const char *class,
|
||||
const char *instance) {
|
||||
@@ -24,3 +31,138 @@ void set_window_class_instance(xcb_window_t window, const char *class,
|
||||
xcb_icccm_set_wm_class(conn, window, length, str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
typedef struct visual_t {
|
||||
uint8_t depth;
|
||||
xcb_visualtype_t *visual;
|
||||
} visual_t;
|
||||
|
||||
static visual_t *find_alpha_visual() {
|
||||
xcb_depth_iterator_t depth_iter;
|
||||
depth_iter = xcb_screen_allowed_depths_iterator(screen);
|
||||
for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
|
||||
if (depth_iter.data->depth != 32) continue;
|
||||
|
||||
xcb_visualtype_iterator_t visual_iter;
|
||||
visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) {
|
||||
if (visual_iter.data->_class == XCB_VISUAL_CLASS_TRUE_COLOR) {
|
||||
visual_t *r = ecalloc(1, sizeof(visual_t));
|
||||
r->visual = visual_iter.data;
|
||||
r->depth = depth_iter.data->depth;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static visual_t *find_root_visual() {
|
||||
xcb_depth_iterator_t depth_iter;
|
||||
depth_iter = xcb_screen_allowed_depths_iterator(screen);
|
||||
xcb_visualid_t vid = screen->root_visual;
|
||||
for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
|
||||
xcb_visualtype_iterator_t visual_iter;
|
||||
visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) {
|
||||
if (visual_iter.data->visual_id == vid) {
|
||||
visual_t *r = ecalloc(1, sizeof(visual_t));
|
||||
r->visual = visual_iter.data;
|
||||
r->depth = depth_iter.data->depth;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取 xcb 的 visual 及其对应的 depth
|
||||
* @param prefer_alpha 支持 alpha 的 visual 优先
|
||||
* @returns 返回的信息使用后记得使用 free 释放
|
||||
*/
|
||||
visual_t *get_xcb_visual(bool prefer_alpha) {
|
||||
if (!prefer_alpha) return find_root_visual();
|
||||
|
||||
visual_t *visual = find_alpha_visual();
|
||||
if (visual == NULL) visual = find_root_visual();
|
||||
|
||||
return visual;
|
||||
}
|
||||
|
||||
typedef struct bar_window_param_t {
|
||||
uint8_t depth;
|
||||
xcb_colormap_t colormap;
|
||||
xcb_visualid_t visual_id;
|
||||
xcb_visualtype_t *visual;
|
||||
} bar_window_param_t;
|
||||
static bar_window_param_t *prepare_bar_window_params(void) {
|
||||
static xcb_colormap_t colormap = XCB_NONE;
|
||||
visual_t *visual = get_xcb_visual(true);
|
||||
xcb_visualid_t visual_id = visual->visual->visual_id;
|
||||
if (colormap == XCB_NONE) {
|
||||
colormap = xcb_generate_id(conn);
|
||||
uint8_t alloc = XCB_COLORMAP_ALLOC_NONE;
|
||||
xcb_create_colormap(conn, alloc, colormap, screen->root, visual_id);
|
||||
}
|
||||
|
||||
bar_window_param_t *params = ecalloc(1, sizeof(bar_window_param_t));
|
||||
params->depth = visual->depth;
|
||||
params->visual = visual->visual;
|
||||
params->visual_id = visual_id;
|
||||
params->colormap = colormap;
|
||||
free(visual);
|
||||
return params;
|
||||
}
|
||||
|
||||
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) {
|
||||
bar_window_param_t *params = prepare_bar_window_params();
|
||||
xcb_visualtype_t *visual = params->visual;
|
||||
xcb_window_t window = xcb_generate_id(conn);
|
||||
uint32_t value_mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_BACK_PIXEL |
|
||||
XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK |
|
||||
XCB_CW_CURSOR | XCB_CW_COLORMAP;
|
||||
const xcb_create_window_value_list_t value_list = {
|
||||
.override_redirect = true,
|
||||
.background_pixel = background_argb,
|
||||
.border_pixel = 0,
|
||||
.event_mask = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE,
|
||||
.cursor = get_xcb_cursor(cursor),
|
||||
.colormap = params->colormap,
|
||||
};
|
||||
xcb_void_cookie_t cookie;
|
||||
cookie = xcb_create_window_aux_checked(
|
||||
conn, params->depth, window, screen->root, x, y, width, height, 0,
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, params->visual_id, value_mask, &value_list);
|
||||
free(params);
|
||||
if (xcb_request_check(conn, cookie)) die("create bar window:");
|
||||
|
||||
cookie = xcb_map_window(conn, window);
|
||||
if (xcb_request_check(conn, cookie)) die("map bar window:");
|
||||
|
||||
set_window_class_instance(window, APP_NAME, APP_NAME);
|
||||
xcb_flush(conn);
|
||||
|
||||
bar_cairo_params_t *p = ecalloc(1, sizeof(bar_cairo_params_t));
|
||||
p->conn = conn;
|
||||
p->visual = visual;
|
||||
p->window = window;
|
||||
return p;
|
||||
}
|
||||
|
||||
void destroy_window(xcb_window_t window) { xcb_destroy_window(conn, window); }
|
||||
|
||||
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),
|
||||
};
|
||||
xcb_change_window_attributes_aux(conn, window, XCB_CW_CURSOR, &value_list);
|
||||
xcb_flush(conn);
|
||||
}
|
||||
|
||||
void set_root_cursor(cursor_t cursor) {
|
||||
change_window_cursor(screen->root, cursor);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include "xcb.h"
|
||||
|
||||
extern xcb_connection_t *conn;
|
||||
extern xcb_screen_t *screen;
|
||||
|
||||
xcb_cursor_t get_xcb_cursor(cursor_t cursor);
|
||||
|
||||
Reference in New Issue
Block a user