Convert Xinerama usage to xcb

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2018-09-29 11:46:29 +02:00
parent 83a4853419
commit 9dff55540f
4 changed files with 35 additions and 21 deletions

View File

@ -26,7 +26,7 @@ endif
# Enables support for --xinerama-shadow-crop # Enables support for --xinerama-shadow-crop
ifeq "$(NO_XINERAMA)" "" ifeq "$(NO_XINERAMA)" ""
CFG += -DCONFIG_XINERAMA CFG += -DCONFIG_XINERAMA
PACKAGES += xinerama PACKAGES += xcb-xinerama
endif endif
# ==== libconfig ==== # ==== libconfig ====

View File

@ -88,16 +88,16 @@
#include <X11/extensions/sync.h> #include <X11/extensions/sync.h>
#endif #endif
#ifdef CONFIG_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include <xcb/composite.h> #include <xcb/composite.h>
#include <xcb/render.h> #include <xcb/render.h>
#include <xcb/damage.h> #include <xcb/damage.h>
#include <xcb/randr.h> #include <xcb/randr.h>
#include <xcb/shape.h> #include <xcb/shape.h>
#ifdef CONFIG_XINERAMA
#include <xcb/xinerama.h>
#endif
// Workarounds for missing definitions in very old versions of X headers, // Workarounds for missing definitions in very old versions of X headers,
// thanks to consolers for reporting // thanks to consolers for reporting
#ifndef PictOpDifference #ifndef PictOpDifference
@ -977,7 +977,7 @@ typedef struct session {
/// Whether X Xinerama extension exists. /// Whether X Xinerama extension exists.
bool xinerama_exists; bool xinerama_exists;
/// Xinerama screen info. /// Xinerama screen info.
XineramaScreenInfo *xinerama_scrs; xcb_xinerama_query_screens_reply_t *xinerama_scrs;
/// Xinerama screen regions. /// Xinerama screen regions.
XserverRegion *xinerama_scr_regs; XserverRegion *xinerama_scr_regs;
/// Number of Xinerama screens. /// Number of Xinerama screens.

View File

@ -5110,21 +5110,28 @@ cxinerama_upd_scrs(session_t *ps) {
if (!ps->o.xinerama_shadow_crop || !ps->xinerama_exists) return; if (!ps->o.xinerama_shadow_crop || !ps->xinerama_exists) return;
if (!XineramaIsActive(ps->dpy)) return; xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_xinerama_is_active_reply_t *active =
ps->xinerama_scrs = XineramaQueryScreens(ps->dpy, &ps->xinerama_nscrs); xcb_xinerama_is_active_reply(c,
xcb_xinerama_is_active(c), NULL);
// Just in case the shit hits the fan... if (!active || !active->state) {
if (!ps->xinerama_nscrs) { free(active);
cxfree(ps->xinerama_scrs);
ps->xinerama_scrs = NULL;
return; return;
} }
free(active);
ps->xinerama_scrs = xcb_xinerama_query_screens_reply(c,
xcb_xinerama_query_screens(c), NULL);
if (!ps->xinerama_scrs)
return;
xcb_xinerama_screen_info_t *scrs = xcb_xinerama_query_screens_screen_info(ps->xinerama_scrs);
ps->xinerama_nscrs = xcb_xinerama_query_screens_screen_info_length(ps->xinerama_scrs);
ps->xinerama_scr_regs = allocchk(malloc(sizeof(XserverRegion *) ps->xinerama_scr_regs = allocchk(malloc(sizeof(XserverRegion *)
* ps->xinerama_nscrs)); * ps->xinerama_nscrs));
for (int i = 0; i < ps->xinerama_nscrs; ++i) { for (int i = 0; i < ps->xinerama_nscrs; ++i) {
const XineramaScreenInfo * const s = &ps->xinerama_scrs[i]; const xcb_xinerama_screen_info_t * const s = &scrs[i];
XRectangle r = { .x = s->x_org, .y = s->y_org, XRectangle r = { .x = s->x_org, .y = s->y_org,
.width = s->width, .height = s->height }; .width = s->width, .height = s->height };
ps->xinerama_scr_regs[i] = XFixesCreateRegion(ps->dpy, &r, 1); ps->xinerama_scr_regs[i] = XFixesCreateRegion(ps->dpy, &r, 1);
@ -5385,6 +5392,7 @@ session_init(session_t *ps_old, int argc, char **argv) {
xcb_prefetch_extension_data(c, &xcb_damage_id); xcb_prefetch_extension_data(c, &xcb_damage_id);
xcb_prefetch_extension_data(c, &xcb_shape_id); xcb_prefetch_extension_data(c, &xcb_shape_id);
xcb_prefetch_extension_data(c, &xcb_randr_id); xcb_prefetch_extension_data(c, &xcb_randr_id);
xcb_prefetch_extension_data(c, &xcb_xinerama_id);
ext_info = xcb_get_extension_data(c, &xcb_render_id); ext_info = xcb_get_extension_data(c, &xcb_render_id);
if (!ext_info || !ext_info->present) { if (!ext_info || !ext_info->present) {
@ -5515,9 +5523,8 @@ session_init(session_t *ps_old, int argc, char **argv) {
// Query X Xinerama extension // Query X Xinerama extension
if (ps->o.xinerama_shadow_crop) { if (ps->o.xinerama_shadow_crop) {
#ifdef CONFIG_XINERAMA #ifdef CONFIG_XINERAMA
int xinerama_event = 0, xinerama_error = 0; ext_info = xcb_get_extension_data(c, &xcb_xinerama_id);
if (XineramaQueryExtension(ps->dpy, &xinerama_event, &xinerama_error)) ps->xinerama_exists = ext_info && ext_info->present;
ps->xinerama_exists = true;
#else #else
printf_errf("(): Xinerama support not compiled in."); printf_errf("(): Xinerama support not compiled in.");
#endif #endif

View File

@ -650,14 +650,21 @@ static inline void
cxinerama_win_upd_scr(session_t *ps, win *w) { cxinerama_win_upd_scr(session_t *ps, win *w) {
#ifdef CONFIG_XINERAMA #ifdef CONFIG_XINERAMA
w->xinerama_scr = -1; w->xinerama_scr = -1;
for (XineramaScreenInfo *s = ps->xinerama_scrs;
s < ps->xinerama_scrs + ps->xinerama_nscrs; ++s) if (!ps->xinerama_scrs)
return;
xcb_xinerama_screen_info_t *scrs = xcb_xinerama_query_screens_screen_info(ps->xinerama_scrs);
int length = xcb_xinerama_query_screens_screen_info_length(ps->xinerama_scrs);
for (int i = 0; i < length; i++) {
xcb_xinerama_screen_info_t *s = &scrs[i];
if (s->x_org <= w->g.x && s->y_org <= w->g.y if (s->x_org <= w->g.x && s->y_org <= w->g.y
&& s->x_org + s->width >= w->g.x + w->widthb && s->x_org + s->width >= w->g.x + w->widthb
&& s->y_org + s->height >= w->g.y + w->heightb) { && s->y_org + s->height >= w->g.y + w->heightb) {
w->xinerama_scr = s - ps->xinerama_scrs; w->xinerama_scr = i;
return; return;
} }
}
#endif #endif
} }