decompose wl_backend.c: extract wl_icccm.c

This commit is contained in:
Window Maker 2026-06-02 10:36:07 +02:00
parent cbc9fa5a84
commit 861ae10c8f
4 changed files with 71 additions and 52 deletions

View File

@ -164,7 +164,8 @@ wmaker_SOURCES += \
backend/wayland/wl_overlay.c \
backend/wayland/wl_window.c \
backend/wayland/wl_props.c \
backend/wayland/wl_client.c
backend/wayland/wl_client.c \
backend/wayland/wl_icccm.c
endif
if USE_NESTED_FUNC

View File

@ -6286,57 +6286,6 @@ wl_coords_translate(WNativeWindow src, WNativeWindow dst,
return 0;
}
/* ------------------------------------------------------------------ */
/* ICCCM */
/* ------------------------------------------------------------------ */
static void wl_icccm_set_wm_hints(WNativeWindow win, const WWMHints *hints) { (void)win; (void)hints; }
static void wl_icccm_set_class_hint(WNativeWindow win, const char *wm_class, const char *wm_instance) { (void)win; (void)wm_class; (void)wm_instance; }
static void wl_icccm_set_class_hint_if_absent(WNativeWindow win, const char *wm_class, const char *wm_instance) { (void)win; (void)wm_class; (void)wm_instance; }
static void
wl_icccm_set_command(WNativeWindow win, char **argv, int argc)
{
/* Phase 57: store WM_COMMAND in the view struct. */
struct wl_toplevel_view *v = wl_find_view_by_id(win);
int i;
if (!v || !argv || argc <= 0) return;
/* free previous command if any */
if (v->wm_command) {
for (i = 0; i < v->wm_command_n; i++) wfree(v->wm_command[i]);
wfree(v->wm_command);
}
v->wm_command = wmalloc((size_t)argc * sizeof(char *));
for (i = 0; i < argc; i++)
v->wm_command[i] = wstrdup(argv[i] ? argv[i] : "");
v->wm_command_n = argc;
}
static int
wl_icccm_get_command(WNativeWindow win, char ***argv_out, int *argc_out)
{
/* Phase 57: return a NULL-terminated copy of the stored WM_COMMAND.
* Caller frees with wl_icccm_free_command. */
struct wl_toplevel_view *v = wl_find_view_by_id(win);
int i;
if (!v || !v->wm_command) { *argv_out = NULL; *argc_out = 0; return 0; }
/* Allocate n+1 entries (NULL-terminated for free_command iteration). */
*argv_out = wmalloc((size_t)(v->wm_command_n + 1) * sizeof(char *));
for (i = 0; i < v->wm_command_n; i++)
(*argv_out)[i] = wstrdup(v->wm_command[i]);
(*argv_out)[v->wm_command_n] = NULL;
*argc_out = v->wm_command_n;
return 1;
}
static void
wl_icccm_free_command(char **argv)
{
/* Phase 57: free NULL-terminated argv returned by wl_icccm_get_command. */
int i;
if (!argv) return;
for (i = 0; argv[i] != NULL; i++) wfree(argv[i]);
wfree(argv);
}
/* ------------------------------------------------------------------ */
/* Fake leader */

View File

@ -0,0 +1,61 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <stdlib.h>
#include "wl_types.h"
/* Forward declarations from sibling modules. */
struct wl_toplevel_view *wl_find_view_by_id(WNativeWindow id);
/* ------------------------------------------------------------------ */
/* ICCCM */
/* ------------------------------------------------------------------ */
void wl_icccm_set_wm_hints(WNativeWindow win, const WWMHints *hints) { (void)win; (void)hints; }
void wl_icccm_set_class_hint(WNativeWindow win, const char *wm_class, const char *wm_instance) { (void)win; (void)wm_class; (void)wm_instance; }
void wl_icccm_set_class_hint_if_absent(WNativeWindow win, const char *wm_class, const char *wm_instance) { (void)win; (void)wm_class; (void)wm_instance; }
void
wl_icccm_set_command(WNativeWindow win, char **argv, int argc)
{
/* Phase 57: store WM_COMMAND in the view struct. */
struct wl_toplevel_view *v = wl_find_view_by_id(win);
int i;
if (!v || !argv || argc <= 0) return;
/* free previous command if any */
if (v->wm_command) {
for (i = 0; i < v->wm_command_n; i++) wfree(v->wm_command[i]);
wfree(v->wm_command);
}
v->wm_command = wmalloc((size_t)argc * sizeof(char *));
for (i = 0; i < argc; i++)
v->wm_command[i] = wstrdup(argv[i] ? argv[i] : "");
v->wm_command_n = argc;
}
int
wl_icccm_get_command(WNativeWindow win, char ***argv_out, int *argc_out)
{
/* Phase 57: return a NULL-terminated copy of the stored WM_COMMAND.
* Caller frees with wl_icccm_free_command. */
struct wl_toplevel_view *v = wl_find_view_by_id(win);
int i;
if (!v || !v->wm_command) { *argv_out = NULL; *argc_out = 0; return 0; }
/* Allocate n+1 entries (NULL-terminated for free_command iteration). */
*argv_out = wmalloc((size_t)(v->wm_command_n + 1) * sizeof(char *));
for (i = 0; i < v->wm_command_n; i++)
(*argv_out)[i] = wstrdup(v->wm_command[i]);
(*argv_out)[v->wm_command_n] = NULL;
*argc_out = v->wm_command_n;
return 1;
}
void
wl_icccm_free_command(char **argv)
{
/* Phase 57: free NULL-terminated argv returned by wl_icccm_get_command. */
int i;
if (!argv) return;
for (i = 0; argv[i] != NULL; i++) wfree(argv[i]);
wfree(argv);
}

View File

@ -475,3 +475,11 @@ void wl_client_query_shaped(WNativeWindow win, int *shaped_out);
int wl_client_get_gnustep_attrs(WNativeWindow win, GNUstepWMAttributes **attr_out);
int wl_client_get_pid(WNativeWindow win);
RImage *wl_client_snapshot(WScreen *scr, WNativeWindow client_win, WNativeWindow frame_win);
/* ICCCM module declarations (extracted to wl_icccm.c) */
void wl_icccm_set_wm_hints(WNativeWindow win, const WWMHints *hints);
void wl_icccm_set_class_hint(WNativeWindow win, const char *wm_class, const char *wm_instance);
void wl_icccm_set_class_hint_if_absent(WNativeWindow win, const char *wm_class, const char *wm_instance);
void wl_icccm_set_command(WNativeWindow win, char **argv, int argc);
int wl_icccm_get_command(WNativeWindow win, char ***argv_out, int *argc_out);
void wl_icccm_free_command(char **argv);