From dd389edc4f94697396c3ab9ba0a7aacb8c092de2 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 17 Aug 2026 01:58:30 +0900 Subject: [PATCH] x11: xcb_aux_get_screen instead of two hand-rolled screen walks win.c and xim.c each iterated the setup's roots to find the screen xcb_connect had chosen; xcb-util, already linked through imdkit, has xcb_aux_get_screen for that. --- Dockerfile | 1 + Makefile | 8 ++++---- README.md | 2 +- tests/Makefile | 4 ++-- win.c | 14 ++------------ xim.c | 15 ++------------- 6 files changed, 12 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index b5169eb..ad58aee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ RUN pacman -Syu --noconfirm --needed \ which \ xorg-server-xvfb \ xcb-imdkit \ + xcb-util \ dbus \ && pacman -Scc --noconfirm diff --git a/Makefile b/Makefile index 1221410..ed9304e 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,12 @@ CFLAGS ?= -O2 -g WARN_CFLAGS = -Wall -Wextra IBUS_CFLAGS = $(shell $(PKG_CONFIG) --cflags dbus-1 xkbcommon) IBUS_LIBS = $(shell $(PKG_CONFIG) --libs dbus-1 xkbcommon) -XIM_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-imdkit xcb-xkb xkbcommon-x11) -XIM_LIBS = $(shell $(PKG_CONFIG) --libs xcb-imdkit xcb-xkb xkbcommon-x11) +XIM_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-imdkit xcb-aux xcb-xkb xkbcommon-x11) +XIM_LIBS = $(shell $(PKG_CONFIG) --libs xcb-imdkit xcb-aux xcb-xkb xkbcommon-x11) TEXT_CFLAGS = $(shell $(PKG_CONFIG) --cflags pangocairo cairo fontconfig) TEXT_LIBS = $(shell $(PKG_CONFIG) --libs pangocairo cairo fontconfig) -POPUP_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-randr) -POPUP_LIBS = $(shell $(PKG_CONFIG) --libs xcb-randr) +POPUP_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-aux xcb-randr) +POPUP_LIBS = $(shell $(PKG_CONFIG) --libs xcb-aux xcb-randr) PROJECT_CPPFLAGS = PROJECT_LDLIBS = -lthread -lbio -lxcb $(IBUS_LIBS) $(TEXT_LIBS) \ $(XIM_LIBS) $(POPUP_LIBS) diff --git a/README.md b/README.md index b6beddc..d43ae51 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ and cmp/diff, plus development files for: - Plan 9 port (`9c`, `9l`, `libthread`, and `libbio`); - D-Bus development files; -- XCB, XCB RandR, XCB XKB, xcb-imdkit, xkbcommon, and xkbcommon-x11; +- XCB, XCB RandR, XCB XKB, xcb-util, xcb-imdkit, xkbcommon, and xkbcommon-x11; - Pango, PangoCairo, Cairo, and Fontconfig; - GTK 3, plus libibus and Xlib for the live clients; - Xvfb for the X11 live tests; diff --git a/tests/Makefile b/tests/Makefile index b88d419..05ec12e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -18,8 +18,8 @@ IBUS_CLIENT_CFLAGS = $(shell $(PKG_CONFIG) --cflags ibus-1.0) IBUS_CLIENT_LIBS = $(shell $(PKG_CONFIG) --libs ibus-1.0) X11_CFLAGS = $(shell $(PKG_CONFIG) --cflags x11) X11_LIBS = $(shell $(PKG_CONFIG) --libs x11) -XIM_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-imdkit xcb-xkb xkbcommon-x11) -XIM_LIBS = $(shell $(PKG_CONFIG) --libs xcb-imdkit xcb-xkb xkbcommon-x11) +XIM_CFLAGS = $(shell $(PKG_CONFIG) --cflags xcb-imdkit xcb-aux xcb-xkb xkbcommon-x11) +XIM_LIBS = $(shell $(PKG_CONFIG) --libs xcb-imdkit xcb-aux xcb-xkb xkbcommon-x11) UNIT_LDLIBS = -lthread -lbio $(TEXT_LIBS) $(IBUS_LIBS) $(XIM_LIBS) PROG = unit_test diff --git a/win.c b/win.c index 112ecca..9bc24a7 100644 --- a/win.c +++ b/win.c @@ -1,4 +1,5 @@ #include +#include #include #include "dat.h" #include "fn.h" @@ -14,17 +15,6 @@ static xcb_atom_t workarea; static int hasrandr, imgh, imgw; static int shown, ptrx, ptry; /* the popup, and where the pointer was as it came up */ -static xcb_screen_t* -getscr(xcb_connection_t *c, int n) -{ - xcb_screen_iterator_t i; - - for(i = xcb_setup_roots_iterator(xcb_get_setup(c)); i.rem; xcb_screen_next(&i)) - if(n-- == 0) - return i.data; - return nil; -} - static xcb_visualtype_t* getvisual(xcb_screen_t *s) { @@ -218,7 +208,7 @@ wininit(void) wincleanup(); return 0; } - scr = getscr(conn, n); + scr = xcb_aux_get_screen(conn, n); if(scr == nil || !validformat(conn, scr)){ fprint(2, "strans: popup disabled: unsupported X root format\n"); wincleanup(); diff --git a/xim.c b/xim.c index ce9aebf..28d602e 100644 --- a/xim.c +++ b/xim.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -132,18 +133,6 @@ kwatch(void) events, parts, parts, nil); } -static xcb_screen_t* -getscreen(int scr) -{ - xcb_screen_iterator_t iter; - - iter = xcb_setup_roots_iterator(xcb_get_setup(conn)); - for(; iter.rem; scr--, xcb_screen_next(&iter)) - if(scr == 0) - return iter.data; - return nil; -} - static int translate(xcb_window_t win, int x, int y, Caret *caret) { @@ -550,7 +539,7 @@ ximinit(void) ximlog("cannot connect to X server"); return -1; } - screen = getscreen(scr); + screen = xcb_aux_get_screen(conn, scr); if(screen == nil){ ximlog("cannot find X screen"); return -1;