decompose wl_backend.c: extract wl_screen.c

This commit is contained in:
Window Maker 2026-06-02 12:01:06 +02:00
parent 89668f0202
commit e1c221948c
4 changed files with 95 additions and 76 deletions

View File

@ -174,7 +174,8 @@ wmaker_SOURCES += \
backend/wayland/wl_fakeleader.c \ backend/wayland/wl_fakeleader.c \
backend/wayland/wl_extensions.c \ backend/wayland/wl_extensions.c \
backend/wayland/wl_events.c \ backend/wayland/wl_events.c \
backend/wayland/wl_focus.c backend/wayland/wl_focus.c \
backend/wayland/wl_screen.c
endif endif
if USE_NESTED_FUNC if USE_NESTED_FUNC

View File

@ -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) */ /* Frame buffer (pixman + wlr_scene_buffer) */

View File

@ -0,0 +1,87 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_output.h>
#include "../../screen.h"
#include "../../shutdown.h"
#include "../../dialog.h"
#include <WINGs/WINGsP.h>
#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;
}

View File

@ -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); 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); 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); 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);