confine X11 calls to wl_xdisplay.c and wl_xwayland.c: move XInternAtom/XFlush/XSync to wl_xdisplay.c, move XGetImage/opacity to wl_xwayland.c, remove <X11/Xlib.h> from wl_atom.c/wl_event.c/wl_client.c/wl_framebuf.c

This commit is contained in:
Window Maker 2026-06-05 18:30:20 +02:00
parent 3b082257cd
commit b39c03e69e
8 changed files with 294 additions and 49 deletions

View File

@ -1,15 +1,10 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include "wl_types.h"
unsigned long
wl_atom_intern(const char *name)
{
/* The WM's own UI runs on XWayland — it needs real X11 atoms for
* property operations (WM_STATE, WM_PROTOCOLS, etc.). */
if (wl_state.x_display)
return (unsigned long)XInternAtom(wl_state.x_display, name, False);
return 0;
return wl_xdisplay_intern_atom(name);
}

View File

@ -3,7 +3,6 @@
#endif
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_xdg_shell.h>
@ -432,19 +431,9 @@ wl_client_snapshot(WScreen *scr, WNativeWindow client_win, WNativeWindow frame_w
struct wl_toplevel_view *v = wl_find_view_by_id(client_win);
if (!v) return NULL;
/* XWayland: capture via XGetImage on the WM's X display */
if (v->xw_surface && wl_state.x_display) {
Window xid = (Window)v->xw_surface->window_id;
XWindowAttributes attr;
if (!XGetWindowAttributes(wl_state.x_display, xid, &attr))
return NULL;
XImage *img = XGetImage(wl_state.x_display, xid,
0, 0, attr.width, attr.height,
AllPlanes, ZPixmap);
if (!img) return NULL;
RImage *res = RCreateImageFromXImage(scr->rcontext, img, NULL);
XDestroyImage(img);
return res;
/* XWayland: capture via wl_xwayland_capture_snapshot */
if (v->xw_surface) {
return wl_xwayland_capture_snapshot(scr, v->xw_surface);
}
/* Native Wayland: read pixels from last committed surface buffer */

View File

@ -1,30 +1,21 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include "../../screen.h"
#include "wl_types.h"
void wl_event_flush(void)
{
/* Flush pending Xlib requests to XWayland so drawing becomes visible. */
if (wl_state.x_display)
XFlush(wl_state.x_display);
wl_xdisplay_flush();
}
void wl_event_flush_expose(void) {}
void wl_event_sync(int discard)
{
if (wl_state.x_display)
XSync(wl_state.x_display, discard ? True : False);
wl_xdisplay_sync(discard);
}
int wl_event_pending(void) { return 0; }
void wl_event_drain_motion(void) {}
void wl_event_discard_enter_leave_until(unsigned long timestamp) { (void)timestamp; }
void wl_event_handle_extensions(WMEvent *event) { (void)event; }
void wl_event_randr_update(WMEvent *event) { (void)event; }
void wl_event_handle_signal_exit(void)
{
wm_backend->event_loop_terminate();
}

View File

@ -10,7 +10,6 @@
#include <wlr/types/wlr_output.h>
#include <libdrm/drm_fourcc.h>
#include <pixman.h>
#include <X11/Xlib.h>
#include "../../def_pixmaps.h"
#include "../../screen.h"
#include "../../framewin.h"
@ -872,23 +871,8 @@ wl_netwm_update_opacity(WWindow *wwin)
return;
float alpha = 1.0f;
if (wl_state.x_display && wwin->client_win) {
WMNativeAtom type;
int format;
unsigned long items, rest;
unsigned char *prop = NULL;
WMNativeAtom opacity_atom = XInternAtom(wl_state.x_display,
"_NET_WM_WINDOW_OPACITY", False);
if (XGetWindowProperty(wl_state.x_display, (WNativeWindow)wwin->client_win,
opacity_atom, 0L, 1L, False, AnyPropertyType,
&type, &format, &items, &rest, &prop) == Success
&& format == 32 && items == 1 && prop) {
unsigned long val = *(unsigned long *)prop;
alpha = (float)val / (float)0xFFFFFFFF;
}
if (prop)
XFree(prop);
}
if (wwin->client_win)
alpha = wl_xwayland_get_window_opacity(wwin->client_win);
wlr_scene_buffer_set_opacity(fb->scene_buf, alpha);

View File

@ -561,6 +561,12 @@ void wl_wings_dispatch(int timeout_ms, void *ud);
#if USE_X11_BACKEND
Display *wl_get_x_display(void);
#endif
unsigned long wl_xdisplay_intern_atom(const char *name);
void wl_xdisplay_flush(void);
void wl_xdisplay_sync(int discard);
struct wlr_xwayland_surface;
RImage *wl_xwayland_capture_snapshot(WScreen *scr, struct wlr_xwayland_surface *xw);
float wl_xwayland_get_window_opacity(WNativeWindow client_win);
/* Declarations for functions still in wl_backend.c referenced by vtable */
void wl_button_grab(WNativeWindow win, unsigned int button, unsigned int modifier, unsigned int event_mask, int owner_events);

View File

@ -12,6 +12,28 @@ Display *wl_get_x_display(void)
return wl_state.x_display;
}
unsigned long
wl_xdisplay_intern_atom(const char *name)
{
if (wl_state.x_display)
return (unsigned long)XInternAtom(wl_state.x_display, name, False);
return 0;
}
void
wl_xdisplay_flush(void)
{
if (wl_state.x_display)
XFlush(wl_state.x_display);
}
void
wl_xdisplay_sync(int discard)
{
if (wl_state.x_display)
XSync(wl_state.x_display, discard ? True : False);
}
RContext *wl_create_rcontext(int screen_number, RContextAttributes *attribs)
{
(void)screen_number;

View File

@ -16,6 +16,7 @@
#include "window.h"
#include "wl_types.h"
#include <WINGs/WINGsP.h>
#include <wraster.h>
/* Forward declarations */
void view_attach_scene_destroy_listener(struct wl_toplevel_view *view);
@ -375,3 +376,50 @@ handle_xwayland_new_surface(struct wl_listener *listener, void *data)
(int16_t)view->x, (int16_t)view->y, cw, ch);
}
}
/* ------------------------------------------------------------------ */
/* XWayland snapshot capture — called from wl_client_snapshot() */
RImage *
wl_xwayland_capture_snapshot(WScreen *scr, struct wlr_xwayland_surface *xw)
{
if (!wl_state.x_display || !xw)
return NULL;
Window xid = (Window)xw->window_id;
XWindowAttributes attr;
if (!XGetWindowAttributes(wl_state.x_display, xid, &attr))
return NULL;
XImage *img = XGetImage(wl_state.x_display, xid,
0, 0, attr.width, attr.height,
AllPlanes, ZPixmap);
if (!img) return NULL;
RImage *res = RCreateImageFromXImage(scr->rcontext, img, NULL);
XDestroyImage(img);
return res;
}
/* ------------------------------------------------------------------ */
/* Read _NET_WM_WINDOW_OPACITY from an XWayland client */
float
wl_xwayland_get_window_opacity(WNativeWindow client_win)
{
if (!wl_state.x_display)
return 1.0f;
WMNativeAtom type;
int format;
unsigned long items, rest;
unsigned char *prop = NULL;
unsigned long val = 0xFFFFFFFF;
WMNativeAtom opacity_atom = XInternAtom(wl_state.x_display,
"_NET_WM_WINDOW_OPACITY", False);
if (XGetWindowProperty(wl_state.x_display, (WNativeWindow)client_win,
opacity_atom, 0L, 1L, False, AnyPropertyType,
&type, &format, &items, &rest, &prop) == Success
&& format == 32 && items == 1 && prop) {
val = *(unsigned long *)prop;
}
if (prop)
XFree(prop);
return (float)val / (float)0xFFFFFFFF;
}

210
src/wmaker.prev Executable file
View File

@ -0,0 +1,210 @@
#! /bin/sh
# wmaker - temporary wrapper script for .libs/wmaker
# Generated by libtool (GNU libtool) 2.5.4
#
# The wmaker program cannot be directly executed until all the libtool
# libraries that it depends on are installed.
#
# This wrapper script should never be moved out of the build directory.
# If it is, it will not operate correctly.
# Sed substitution that helps us do robust quoting. It backslashifies
# metacharacters that are still active within double-quoted strings.
sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
# Be Bourne compatible
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
# Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
# is contrary to our usage. Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
else
case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
fi
BIN_SH=xpg4; export BIN_SH # for Tru64
DUALCASE=1; export DUALCASE # for MKS sh
# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
relink_command=""
# This environment variable determines our operation mode.
if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
# install mode needs the following variables:
generated_by_libtool_version='2.5.4'
notinst_deplibs=' ../WINGs/libWINGs.la /home/lkn/src/wmaker/WINGs/libWUtil.la /home/lkn/src/wmaker/wrlib/libwraster.la ../WINGs/libWUtil.la ../wrlib/libwraster.la'
else
# When we are sourced in execute mode, $file and $ECHO are already set.
if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
file="$0"
# A function that is used when there is no print builtin or printf.
func_fallback_echo ()
{
eval 'cat <<_LTECHO_EOF
$1
_LTECHO_EOF'
}
ECHO="printf %s\\n"
fi
# Very basic option parsing. These options are (a) specific to
# the libtool wrapper, (b) are identical between the wrapper
# /script/ and the wrapper /executable/ that is used only on
# windows platforms, and (c) all begin with the string --lt-
# (application programs are unlikely to have options that match
# this pattern).
#
# There are only two supported options: --lt-debug and
# --lt-dump-script. There is, deliberately, no --lt-help.
#
# The first argument to this parsing function should be the
# script's ../libtool value, followed by no.
lt_option_debug=
func_parse_lt_options ()
{
lt_script_arg0=$0
shift
for lt_opt
do
case "$lt_opt" in
--lt-debug) lt_option_debug=1 ;;
--lt-dump-script)
lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
cat "$lt_dump_D/$lt_dump_F"
exit 0
;;
--lt-*)
$ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
exit 1
;;
esac
done
# Print the debug banner immediately:
if test -n "$lt_option_debug"; then
echo "wmaker:wmaker:$LINENO: libtool wrapper (GNU libtool) 2.5.4" 1>&2
fi
}
# Used when --lt-debug. Prints its arguments to stdout
# (redirection is the responsibility of the caller)
func_lt_dump_args ()
{
lt_dump_args_N=1;
for lt_arg
do
$ECHO "wmaker:wmaker:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
lt_dump_args_N=`expr $lt_dump_args_N + 1`
done
}
# Core function for launching the target application
func_exec_program_core ()
{
if test -n "$lt_option_debug"; then
$ECHO "wmaker:wmaker:$LINENO: newargv[0]: $progdir/$program" 1>&2
func_lt_dump_args ${1+"$@"} 1>&2
fi
exec "$progdir/$program" ${1+"$@"}
$ECHO "$0: cannot exec $program $*" 1>&2
exit 1
}
# A function to encapsulate launching the target application
# Strips options in the --lt-* namespace from $@ and
# launches target application with the remaining arguments.
func_exec_program ()
{
case " $* " in
*\ --lt-*)
for lt_wr_arg
do
case $lt_wr_arg in
--lt-*) ;;
*) set x "$@" "$lt_wr_arg"; shift;;
esac
shift
done ;;
esac
func_exec_program_core ${1+"$@"}
}
# Parse options
func_parse_lt_options "$0" ${1+"$@"}
# Find the directory that this script lives in.
thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
test "x$thisdir" = "x$file" && thisdir=.
# Follow symbolic links until we get to the real thisdir.
file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
while test -n "$file"; do
destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
# If there was a directory component, then change thisdir.
if test "x$destdir" != "x$file"; then
case "$destdir" in
[\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
*) thisdir="$thisdir/$destdir" ;;
esac
fi
file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
done
# Usually 'no', except on cygwin/mingw/windows when embedded into
# the cwrapper.
WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
# special case for '.'
if test "$thisdir" = "."; then
thisdir=`pwd`
fi
# remove .libs from thisdir
case "$thisdir" in
*[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
.libs ) thisdir=. ;;
esac
fi
# Try to get the absolute directory name.
absdir=`cd "$thisdir" && pwd`
test -n "$absdir" && thisdir="$absdir"
program='wmaker'
progdir="$thisdir/.libs"
if test -f "$progdir/$program"; then
# Add our own library path to LD_LIBRARY_PATH
LD_LIBRARY_PATH="/home/lkn/src/wmaker/WINGs/.libs:/home/lkn/src/wmaker/wrlib/.libs:$LD_LIBRARY_PATH"
# Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
# The second colon is a workaround for a bug in BeOS R4 sed
LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
export LD_LIBRARY_PATH
if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
# Run the actual program with our arguments.
func_exec_program ${1+"$@"}
fi
else
# The program doesn't exist.
$ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
$ECHO "This script is just a wrapper for $program." 1>&2
$ECHO "See the libtool documentation for more information." 1>&2
exit 1
fi
fi