Phase 80n: clean X11 from icon.c

- drawIconTitleBackground (XFillRectangle/XDrawLine) -> icon_paint_title_bg
- cycleColor/wIconSelect (XChangeGC/XDrawRectangle) -> icon_select_paint
- getSize (XGetGeometry) -> pixmap_get_size
- XGetWindowAttributes -> window_get_event_mask
- XGrabPointer -> pointer_grab
- XChangeActivePointerGrab -> pointer_change_cursor
- XReparentWindow -> client_reparent
- XClearArea -> window_clear (existing)
- XFree -> wfree

New vtable slots: icon_paint_title_bg, icon_select_paint,
window_get_event_mask, pixmap_get_size.
icon.o verified X11-free with nm.
This commit is contained in:
Levi Neely 2026-05-13 11:42:49 +02:00
parent 2bb40cf9fa
commit ea29b109f7
4 changed files with 78 additions and 30 deletions

View File

@ -1726,6 +1726,11 @@ typedef struct WMBackend {
void (*cursor_set)(WNativeWindow window, Cursor cursor);
void (*pointer_change_cursor)(int cursor_id);
void (*appicon_paint_dock_dots)(struct WAppIcon *aicon, void *wapp);
int (*pixmap_get_size)(unsigned long drawable, unsigned int *w, unsigned int *h, unsigned int *depth);
void (*icon_paint_title_bg)(WScreen *scr, unsigned long pixmap, int height);
void (*icon_select_paint)(WIcon *icon, int step);
unsigned long (*window_get_event_mask)(WNativeWindow window);
} WMBackend;

View File

@ -6245,6 +6245,15 @@ static void wl_noop_pointer_change_cursor(int cursor_id) { (void)cursor_id; }
static void wl_noop_appicon_paint_dock_dots(WAppIcon *aicon, void *wapp)
{ (void)aicon; (void)wapp; }
static int wl_noop_pixmap_get_size(unsigned long drawable, unsigned int *w, unsigned int *h, unsigned int *depth)
{ (void)drawable; *w = 0; *h = 0; *depth = 0; return 0; }
static void wl_noop_icon_paint_title_bg(WScreen *scr, unsigned long pixmap, int height)
{ (void)scr; (void)pixmap; (void)height; }
static void wl_noop_icon_select_paint(WIcon *icon, int step)
{ (void)icon; (void)step; }
static unsigned long wl_noop_window_get_event_mask(WNativeWindow window)
{ (void)window; return 0; }
/* ------------------------------------------------------------------ */
/* vtable */
/* ------------------------------------------------------------------ */
@ -6478,4 +6487,8 @@ const WMBackend wl_backend = {
.cursor_set = wl_noop_cursor_set,
.pointer_change_cursor = wl_noop_pointer_change_cursor,
.appicon_paint_dock_dots = wl_noop_appicon_paint_dock_dots,
.pixmap_get_size = wl_noop_pixmap_get_size,
.icon_paint_title_bg = wl_noop_icon_paint_title_bg,
.icon_select_paint = wl_noop_icon_select_paint,
.window_get_event_mask = wl_noop_window_get_event_mask,
};

View File

@ -3121,6 +3121,42 @@ static void x11_appicon_paint_dock_dots(WAppIcon *aicon, void *wapp_ptr)
0, 0, wPreferences.icon_size, wPreferences.icon_size);
}
static int x11_pixmap_get_size(unsigned long drawable, unsigned int *w, unsigned int *h, unsigned int *depth)
{
Window rjunk;
int xjunk, yjunk;
unsigned int bjunk;
return XGetGeometry(dpy, (Drawable)drawable, &rjunk, &xjunk, &yjunk, w, h, &bjunk, depth);
}
static void x11_icon_paint_title_bg(WScreen *scr, unsigned long pixmap, int height)
{
XFillRectangle(dpy, (Pixmap)pixmap, scr->icon_title_texture->normal_gc,
0, 0, wPreferences.icon_size, height + 1);
XDrawLine(dpy, (Pixmap)pixmap, scr->icon_title_texture->light_gc, 0, 0, wPreferences.icon_size, 0);
XDrawLine(dpy, (Pixmap)pixmap, scr->icon_title_texture->light_gc, 0, 0, 0, height + 1);
XDrawLine(dpy, (Pixmap)pixmap, scr->icon_title_texture->dim_gc,
wPreferences.icon_size - 1, 0, wPreferences.icon_size - 1, height + 1);
}
static void x11_icon_select_paint(WIcon *icon, int step)
{
WScreen *scr = icon->core->screen_ptr;
XGCValues gcv;
gcv.dash_offset = step;
XChangeGC(dpy, scr->icon_select_gc, GCDashOffset, &gcv);
XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
icon->core->width - 1, icon->core->height - 1);
}
static unsigned long x11_window_get_event_mask(WNativeWindow window)
{
XWindowAttributes attr;
if (XGetWindowAttributes(dpy, (Window)window, &attr))
return attr.all_event_masks;
return 0;
}
/* -------------------------------------------------------------------- */
/* Client operations (Phase 80) */
/* -------------------------------------------------------------------- */
@ -3837,6 +3873,10 @@ const WMBackend x11_backend = {
.cursor_set = x11_cursor_set,
.pointer_change_cursor = x11_pointer_change_cursor,
.appicon_paint_dock_dots = x11_appicon_paint_dock_dots,
.pixmap_get_size = x11_pixmap_get_size,
.icon_paint_title_bg = x11_icon_paint_title_bg,
.icon_select_paint = x11_icon_select_paint,
.window_get_event_mask = x11_window_get_event_mask,
};
/*

View File

@ -84,7 +84,7 @@ static void appearanceObserver(void *self, WMNotification *notif)
/* so that the appicon expose handlers will paint the appicon specific
* stuff */
XClearArea(dpy, icon->core->window, 0, 0, icon->core->width, icon->core->height, True);
wm_backend->window_clear(icon->core->window);
}
static void tileObserver(void *self, WMNotification *notif)
@ -96,7 +96,7 @@ static void tileObserver(void *self, WMNotification *notif)
update_icon_pixmap(icon);
XClearArea(dpy, icon->core->window, 0, 0, 1, 1, True);
wm_backend->window_clear(icon->core->window);
}
/************************************/
@ -107,7 +107,7 @@ static int getSize(Drawable d, unsigned int *w, unsigned int *h, unsigned int *d
int xjunk, yjunk;
unsigned int bjunk;
return XGetGeometry(dpy, d, &rjunk, &xjunk, &yjunk, w, h, &bjunk, dep);
return wm_backend->pixmap_get_size((unsigned long)d, w, h, dep);
}
WIcon *icon_create_for_wwindow(WWindow *wwin)
@ -218,7 +218,7 @@ void wIconDestroy(WIcon *icon)
wm_backend->client_reparent((WNativeWindow)icon->icon_win, (WNativeWindow)scr->root_win, x, y);
}
if (icon->icon_name)
XFree(icon->icon_name);
wfree(icon->icon_name);
if (icon->pixmap)
wm_backend->pixmap_free((unsigned long)icon->pixmap);
@ -234,11 +234,7 @@ void wIconDestroy(WIcon *icon)
static void drawIconTitleBackground(WScreen *scr, Pixmap pixmap, int height)
{
XFillRectangle(dpy, pixmap, scr->icon_title_texture->normal_gc, 0, 0, wPreferences.icon_size, height + 1);
XDrawLine(dpy, pixmap, scr->icon_title_texture->light_gc, 0, 0, wPreferences.icon_size, 0);
XDrawLine(dpy, pixmap, scr->icon_title_texture->light_gc, 0, 0, 0, height + 1);
XDrawLine(dpy, pixmap, scr->icon_title_texture->dim_gc,
wPreferences.icon_size - 1, 0, wPreferences.icon_size - 1, height + 1);
wm_backend->icon_paint_title_bg(scr, (unsigned long)pixmap, height);
}
static void icon_update_pixmap(WIcon *icon, RImage *image)
@ -324,7 +320,7 @@ void wIconChangeTitle(WIcon *icon, WWindow *wwin)
/* Remove the previous icon title */
if (icon->icon_name != NULL)
XFree(icon->icon_name);
wfree(icon->icon_name);
/* Set the new one, using two methods to identify
the icon name or switch back to window name */
@ -549,11 +545,8 @@ static void cycleColor(void *data)
XGCValues gcv;
icon->step--;
gcv.dash_offset = icon->step;
XChangeGC(dpy, scr->icon_select_gc, GCDashOffset, &gcv);
XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
icon->core->width - 1, icon->core->height - 1);
wm_backend->icon_select_paint(icon, icon->step);
wm_backend->icon_select_paint(icon, 0);
icon->handlerID = WMAddTimerHandler(COLOR_CYCLE_DELAY, cycleColor, icon);
}
@ -576,14 +569,14 @@ void wIconSelect(WIcon *icon)
if (!wPreferences.dont_blink)
icon->handlerID = WMAddTimerHandler(10, cycleColor, icon);
else
XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
icon->core->width - 1, icon->core->height - 1);
wm_backend->icon_select_paint(icon, 0);
} else {
if (icon->handlerID) {
WMDeleteTimerHandler(icon->handlerID);
icon->handlerID = NULL;
}
XClearArea(dpy, icon->core->window, 0, 0, icon->core->width, icon->core->height, True);
wm_backend->window_clear(icon->core->window);
}
}
@ -752,7 +745,7 @@ static void set_dockapp_in_icon(WIcon *icon)
wm_backend->window_set_border_width((WNativeWindow)icon->icon_win, 0);
/* Put the dock application in the icon */
XReparentWindow(dpy, icon->icon_win, icon->core->window,
wm_backend->client_reparent((WNativeWindow)icon->icon_win, icon->core->window,
(wPreferences.icon_size - w) / 2,
(wPreferences.icon_size - h) / 2);
@ -761,8 +754,8 @@ static void set_dockapp_in_icon(WIcon *icon)
wm_backend->client_add_to_save_set((WNativeWindow)icon->icon_win);
/* Needed to move the icon clicking on the application part */
if ((XGetWindowAttributes(dpy, icon->icon_win, &attr)) &&
(attr.all_event_masks & ButtonPressMask))
if (wm_backend->window_get_event_mask((WNativeWindow)icon->icon_win) &&
ButtonPressMask)
wHackedGrabButton(Button1, MOD_MASK, icon->core->window, True,
ButtonPressMask, GrabModeSync, GrabModeAsync,
None, wPreferences.cursor[WCUR_ARROW]);
@ -835,8 +828,8 @@ void wIconPaint(WIcon *icon)
update_icon_title(icon);
if (icon->selected)
XDrawRectangle(dpy, icon->core->window, scr->icon_select_gc, 0, 0,
icon->core->width - 1, icon->core->height - 1);
wm_backend->icon_select_paint(icon, 0);
}
/******************************************************************/
@ -903,10 +896,9 @@ static void miniwindowMouseDown(WObjDescriptor *desc, WBackendEvent *event)
return;
}
if (XGrabPointer(dpy, icon->core->window, False, ButtonMotionMask
| ButtonReleaseMask | ButtonPressMask, GrabModeAsync,
GrabModeAsync, None, None, CurrentTime) != GrabSuccess) {
}
wm_backend->pointer_grab((WNativeWindow)icon->core->window, WNATIVE_NONE,
ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
WCUR_NORMAL, False, 0);
while (1) {
WMMaskEvent(wwin->screen_ptr->wmscreen, PointerMotionMask | ButtonReleaseMask | ButtonPressMask
| ButtonMotionMask | ExposureMask, &ev);
@ -920,9 +912,7 @@ static void miniwindowMouseDown(WObjDescriptor *desc, WBackendEvent *event)
if (!grabbed) {
if (abs(dx - ev.u.motion.x) >= MOVE_THRESHOLD
|| abs(dy - ev.u.motion.y) >= MOVE_THRESHOLD) {
XChangeActivePointerGrab(dpy, ButtonMotionMask
| ButtonReleaseMask | ButtonPressMask,
wPreferences.cursor[WCUR_MOVE], CurrentTime);
wm_backend->pointer_change_cursor(WCUR_MOVE);
grabbed = 1;
} else {
break;