2018-10-04 05:14:51 +08:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
|
2018-09-07 02:17:26 +08:00
|
|
|
#pragma once
|
2018-09-30 21:37:21 +08:00
|
|
|
#include <stdint.h>
|
2018-09-07 02:17:26 +08:00
|
|
|
#include <stdbool.h>
|
2018-09-24 02:10:46 +08:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/render.h>
|
|
|
|
#include <xcb/xcb_renderutil.h>
|
2018-09-30 06:36:53 +08:00
|
|
|
|
|
|
|
#include "region.h"
|
|
|
|
|
2018-09-07 02:17:26 +08:00
|
|
|
typedef struct session session_t;
|
|
|
|
typedef struct winprop winprop_t;
|
2018-09-30 06:36:53 +08:00
|
|
|
|
2018-09-30 21:38:37 +08:00
|
|
|
#define XCB_SYNCED_VOID(func, c, ...) xcb_request_check(c, func##_checked(c, __VA_ARGS__));
|
|
|
|
#define XCB_SYNCED(func, c, ...) ({ \
|
|
|
|
xcb_generic_error_t *e = NULL; \
|
|
|
|
__auto_type r = func##_reply(c, func(c, __VA_ARGS__), &e); \
|
|
|
|
if (e) { \
|
|
|
|
x_print_error(e->sequence, e->major_code, e->minor_code, e->error_code); \
|
|
|
|
free(e); \
|
|
|
|
} \
|
|
|
|
r; \
|
|
|
|
})
|
|
|
|
|
2018-10-03 21:27:48 +08:00
|
|
|
/**
|
|
|
|
* Send a request to X server and get the reply to make sure all previous
|
|
|
|
* requests are processed, and their replies received
|
|
|
|
*
|
|
|
|
* xcb_get_input_focus is used here because it is the same request used by
|
|
|
|
* libX11
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
x_sync(xcb_connection_t *c) {
|
|
|
|
free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), NULL));
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:17:26 +08:00
|
|
|
/**
|
|
|
|
* Get a specific attribute of a window.
|
|
|
|
*
|
|
|
|
* Returns a blank structure if the returned type and format does not
|
|
|
|
* match the requested type and format.
|
|
|
|
*
|
|
|
|
* @param ps current session
|
|
|
|
* @param w window
|
|
|
|
* @param atom atom of attribute to fetch
|
|
|
|
* @param length length to read
|
|
|
|
* @param rtype atom of the requested type
|
|
|
|
* @param rformat requested format
|
|
|
|
* @return a <code>winprop_t</code> structure containing the attribute
|
|
|
|
* and number of items. A blank one on failure.
|
|
|
|
*/
|
|
|
|
winprop_t
|
|
|
|
wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
|
|
|
|
long length, Atom rtype, int rformat);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of a type-<code>Window</code> property of a window.
|
|
|
|
*
|
|
|
|
* @return the value if successful, 0 otherwise
|
|
|
|
*/
|
|
|
|
Window
|
|
|
|
wid_get_prop_window(session_t *ps, Window wid, Atom aprop);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of a text property of a window.
|
|
|
|
*/
|
|
|
|
bool wid_get_text_prop(session_t *ps, Window wid, Atom prop,
|
|
|
|
char ***pstrlst, int *pnstr);
|
2018-09-24 02:10:46 +08:00
|
|
|
|
|
|
|
xcb_render_pictforminfo_t *x_get_pictform_for_visual(session_t *, xcb_visualid_t);
|
|
|
|
|
|
|
|
xcb_render_picture_t x_create_picture_with_pictfmt_and_pixmap(
|
|
|
|
session_t *ps, xcb_render_pictforminfo_t *pictfmt,
|
|
|
|
xcb_pixmap_t pixmap, unsigned long valuemask,
|
|
|
|
const xcb_render_create_picture_value_list_t *attr)
|
|
|
|
__attribute__((nonnull(1, 2)));
|
|
|
|
|
|
|
|
xcb_render_picture_t x_create_picture_with_visual_and_pixmap(
|
|
|
|
session_t *ps, xcb_visualid_t visual,
|
|
|
|
xcb_pixmap_t pixmap, unsigned long valuemask,
|
|
|
|
const xcb_render_create_picture_value_list_t *attr)
|
|
|
|
__attribute__((nonnull(1)));
|
|
|
|
|
|
|
|
xcb_render_picture_t x_create_picture_with_standard_and_pixmap(
|
|
|
|
session_t *ps, xcb_pict_standard_t standard,
|
|
|
|
xcb_pixmap_t pixmap, unsigned long valuemask,
|
|
|
|
const xcb_render_create_picture_value_list_t *attr)
|
|
|
|
__attribute__((nonnull(1)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an picture.
|
|
|
|
*/
|
|
|
|
xcb_render_picture_t
|
|
|
|
x_create_picture(session_t *ps, int wid, int hei,
|
2018-09-30 02:07:39 +08:00
|
|
|
xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
|
|
|
|
const xcb_render_create_picture_value_list_t *attr);
|
2018-09-30 06:36:53 +08:00
|
|
|
|
|
|
|
/// Fetch a X region and store it in a pixman region
|
2018-10-03 01:50:27 +08:00
|
|
|
bool x_fetch_region(session_t *ps, xcb_xfixes_region_t r, region_t *res);
|
2018-09-30 06:36:53 +08:00
|
|
|
|
|
|
|
void x_set_picture_clip_region(session_t *ps, xcb_render_picture_t,
|
|
|
|
int clip_x_origin, int clip_y_origin, const region_t *);
|
2018-09-30 21:37:21 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* X11 error handler function.
|
|
|
|
*
|
|
|
|
* XXX consider making this error to string
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code);
|
2018-10-01 03:53:52 +08:00
|
|
|
|
|
|
|
xcb_pixmap_t
|
|
|
|
x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);
|