From e1c221948c234cd1b05cfa187a31c2ebf98d13b2 Mon Sep 17 00:00:00 2001 From: Window Maker Date: Tue, 2 Jun 2026 12:01:06 +0200 Subject: [PATCH] decompose wl_backend.c: extract wl_screen.c --- src/Makefile.am | 3 +- src/backend/wayland/wl_backend.c | 75 --------------------------- src/backend/wayland/wl_screen.c | 87 ++++++++++++++++++++++++++++++++ src/backend/wayland/wl_types.h | 6 +++ 4 files changed, 95 insertions(+), 76 deletions(-) create mode 100644 src/backend/wayland/wl_screen.c diff --git a/src/Makefile.am b/src/Makefile.am index 335c044..e56291c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -174,7 +174,8 @@ wmaker_SOURCES += \ backend/wayland/wl_fakeleader.c \ backend/wayland/wl_extensions.c \ backend/wayland/wl_events.c \ - backend/wayland/wl_focus.c + backend/wayland/wl_focus.c \ + backend/wayland/wl_screen.c endif if USE_NESTED_FUNC diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index 4ac2486..12afab5 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -3804,81 +3804,6 @@ wm_dock_app_remove(WNativeWindow id) } } -/* ------------------------------------------------------------------ */ -/* Screen open/close */ -/* ------------------------------------------------------------------ */ - -static void -wl_screen_open(WScreen *scr) -{ - /* Set geometry from the headless output created in display_open(). */ - scr->scr_width = wl_state.output ? - (int)wl_state.output->width : 1920; - scr->scr_height = wl_state.output ? - (int)wl_state.output->height : 1080; - scr->depth = 24; - scr->root_win = (WNativeWindow)0x0FFFFFFF; /* synthetic root window ID */ - scr->colormap = 0; - - /* Wayland has no X11-style window border; the frame_buf renders the - * full decoration. Set border width to 0 so policy code does not - * offset the client position by a non-existent border. */ - scr->frame_border_width = 0; - - /* XWayland bridge: fill in real X11 screen values so RCreateContext - * and WINGs can use the display connection for drawing and fonts. */ - if (wl_state.x_display) { - int snum = DefaultScreen(wl_state.x_display); - scr->root_win = DefaultRootWindow(wl_state.x_display); - scr->depth = DefaultDepth(wl_state.x_display, snum); - scr->colormap = DefaultColormap(wl_state.x_display, snum); - } -} - -static void wl_screen_close(WScreen *scr) { (void)scr; } - -static int -wl_screen_init_display(WScreen *scr, int screen_number) -{ - (void)screen_number; - scr->w_depth = 32; - scr->rcontext = RCreateContextWayland(scr->scr_width, scr->scr_height, NULL); - - /* WINGs widget backends are selected via W_SetNextScreenKind — the - * compositor uses the Wayland-mode set even though wmaker itself is - * the compositor (rendering goes through pixman → wlroots scenes). */ - W_SetNextScreenKind(WM_SCREEN_KIND_WAYLAND); - scr->wmscreen = WMCreateScreenWithRContext(NULL, 0, scr->rcontext); - if (!scr->wmscreen) { - wfatal(_("could not initialize WINGs widget set")); - return 0; - } - - scr->black = WMBlackColor(scr->wmscreen); - scr->white = WMWhiteColor(scr->wmscreen); - scr->gray = WMGrayColor(scr->wmscreen); - scr->darkGray = WMDarkGrayColor(scr->wmscreen); - - scr->black_pixel = scr->black ? WMColorPixel(scr->black) : 0xFF000000; - scr->white_pixel = scr->white ? WMColorPixel(scr->white) : 0xFFFFFFFF; - scr->light_pixel = scr->gray ? WMColorPixel(scr->gray) : 0xFFAAAAAA; - scr->dark_pixel = scr->darkGray ? WMColorPixel(scr->darkGray) : 0xFF555555; - - return 1; -} - -static int -wl_show_crash_dialog(int sig) -{ - /* Wayland: showing a UI from a crashed compositor's child process is - * not possible (the child would need to connect to the dead parent - * for its compositor). Default to auto-restart, which is the most - * useful behavior for a daily-driver compositor — the user's session - * recovers on its own. The crash signal is logged separately by - * the monitor parent. */ - (void)sig; - return WMRestart; -} /* ------------------------------------------------------------------ */ /* Frame buffer (pixman + wlr_scene_buffer) */ diff --git a/src/backend/wayland/wl_screen.c b/src/backend/wayland/wl_screen.c new file mode 100644 index 0000000..4a36791 --- /dev/null +++ b/src/backend/wayland/wl_screen.c @@ -0,0 +1,87 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include "../../screen.h" +#include "../../shutdown.h" +#include "../../dialog.h" +#include +#include "wl_types.h" + +/* ------------------------------------------------------------------ */ +/* Screen open/close */ +/* ------------------------------------------------------------------ */ + +void +wl_screen_open(WScreen *scr) +{ + /* Set geometry from the headless output created in display_open(). */ + scr->scr_width = wl_state.output ? + (int)wl_state.output->width : 1920; + scr->scr_height = wl_state.output ? + (int)wl_state.output->height : 1080; + scr->depth = 24; + scr->root_win = (WNativeWindow)0x0FFFFFFF; /* synthetic root window ID */ + scr->colormap = 0; + + /* Wayland has no X11-style window border; the frame_buf renders the + * full decoration. Set border width to 0 so policy code does not + * offset the client position by a non-existent border. */ + scr->frame_border_width = 0; + + /* XWayland bridge: fill in real X11 screen values so RCreateContext + * and WINGs can use the display connection for drawing and fonts. */ + if (wl_state.x_display) { + int snum = DefaultScreen(wl_state.x_display); + scr->root_win = DefaultRootWindow(wl_state.x_display); + scr->depth = DefaultDepth(wl_state.x_display, snum); + scr->colormap = DefaultColormap(wl_state.x_display, snum); + } +} + +void wl_screen_close(WScreen *scr) { (void)scr; } + +int +wl_screen_init_display(WScreen *scr, int screen_number) +{ + (void)screen_number; + scr->w_depth = 32; + scr->rcontext = RCreateContextWayland(scr->scr_width, scr->scr_height, NULL); + + /* WINGs widget backends are selected via W_SetNextScreenKind — the + * compositor uses the Wayland-mode set even though wmaker itself is + * the compositor (rendering goes through pixman → wlroots scenes). */ + W_SetNextScreenKind(WM_SCREEN_KIND_WAYLAND); + scr->wmscreen = WMCreateScreenWithRContext(NULL, 0, scr->rcontext); + if (!scr->wmscreen) { + wfatal(_("could not initialize WINGs widget set")); + return 0; + } + + scr->black = WMBlackColor(scr->wmscreen); + scr->white = WMWhiteColor(scr->wmscreen); + scr->gray = WMGrayColor(scr->wmscreen); + scr->darkGray = WMDarkGrayColor(scr->wmscreen); + + scr->black_pixel = scr->black ? WMColorPixel(scr->black) : 0xFF000000; + scr->white_pixel = scr->white ? WMColorPixel(scr->white) : 0xFFFFFFFF; + scr->light_pixel = scr->gray ? WMColorPixel(scr->gray) : 0xFFAAAAAA; + scr->dark_pixel = scr->darkGray ? WMColorPixel(scr->darkGray) : 0xFF555555; + + return 1; +} + +int +wl_show_crash_dialog(int sig) +{ + /* Wayland: showing a UI from a crashed compositor's child process is + * not possible (the child would need to connect to the dead parent + * for its compositor). Default to auto-restart, which is the most + * useful behavior for a daily-driver compositor — the user's session + * recovers on its own. The crash signal is logged separately by + * the monitor parent. */ + (void)sig; + return WMRestart; +} diff --git a/src/backend/wayland/wl_types.h b/src/backend/wayland/wl_types.h index de58e18..0eb1213 100644 --- a/src/backend/wayland/wl_types.h +++ b/src/backend/wayland/wl_types.h @@ -542,3 +542,9 @@ void wl_event_loop_terminate(void); Bool wl_noop_screen_get_head_usable_area(WScreen *scr, int head, int *x1, int *y1, int *x2, int *y2); int wl_coords_translate(WNativeWindow src, WNativeWindow dst, int src_x, int src_y, int *dst_x, int *dst_y); void wl_focus_set(WNativeWindow win, int revert_to, unsigned long timestamp); + +/* Screen open/close module (extracted to wl_screen.c) */ +void wl_screen_open(WScreen *scr); +void wl_screen_close(WScreen *scr); +int wl_screen_init_display(WScreen *scr, int screen_number); +int wl_show_crash_dialog(int sig);