[digesting_libdecor] eliminate libdecor_decorate

main
Allen Webster 2026-02-26 15:50:10 -08:00
parent eb54b56ee6
commit fb76c306cd
2 changed files with 44 additions and 63 deletions

View File

@ -262,6 +262,9 @@ int main(){
*/ */
{ {
ctx.w = 640;
ctx.h = 480;
wl_list_init(&ctx.frames); wl_list_init(&ctx.frames);
wl_list_init(&ctx.visible_frame_list); wl_list_init(&ctx.visible_frame_list);
@ -294,19 +297,20 @@ int main(){
if (ctx.wl_compositor == 0){ if (ctx.wl_compositor == 0){
printf("failed to get wl_compositor\n"); printf("failed to get wl_compositor\n");
ctx.has_error = 1;
} }
if (ctx.wl_subcompositor == 0){ if (ctx.wl_subcompositor == 0){
printf("failed to get wl_subcompositor\n"); printf("failed to get wl_subcompositor\n");
ctx.has_error = 1;
} }
if (ctx.wl_shm == 0){ if (ctx.wl_shm == 0){
printf("failed to get wl_shm\n"); printf("failed to get wl_shm\n");
ctx.has_error = 1;
} }
} }
int opengl_load_success = 0; int opengl_load_success = 0;
if (ctx.wl_compositor != 0 && if (!ctx.has_error){
ctx.wl_subcompositor != 0 &&
ctx.wl_shm != 0){
/* (egl) eglGetDisplay /* (egl) eglGetDisplay
** " obtains the EGL display connection for the native display " ** " obtains the EGL display connection for the native display "
*/ */
@ -392,9 +396,6 @@ int main(){
*/ */
if (opengl_load_success){ if (opengl_load_success){
ctx.w = 640;
ctx.h = 480;
/* (1) Appendix A: wl_compositor::create_surface /* (1) Appendix A: wl_compositor::create_surface
** " create new surface " ** " create new surface "
*/ */
@ -405,22 +406,49 @@ int main(){
} }
if (ctx.wl_surface != 0){ if (ctx.wl_surface != 0){
/* (libdecor.h) " Decorate the given content wl_surface. " */ ctx.frame = libdecor_plugin_gtk_frame_new();
ctx.libdecor_frame = libdecor_decorate(ctx.wl_surface, 0); if (ctx.frame != 0){
struct libdecor_frame_private *frame_priv;
ctx.frame->priv = frame_priv = calloc(1, sizeof *frame_priv);
frame_priv->ref_count = 1;
frame_priv->wl_surface = ctx.wl_surface;
frame_priv->wm_capabilities = (LIBDECOR_WM_CAPABILITIES_WINDOW_MENU |
LIBDECOR_WM_CAPABILITIES_MAXIMIZE |
LIBDECOR_WM_CAPABILITIES_FULLSCREEN |
LIBDECOR_WM_CAPABILITIES_MINIMIZE);
wl_list_insert(&ctx.frames, &ctx.frame->link);
libdecor_frame_set_capabilities(ctx.frame,
LIBDECOR_ACTION_MOVE |
LIBDECOR_ACTION_RESIZE |
LIBDECOR_ACTION_MINIMIZE |
LIBDECOR_ACTION_FULLSCREEN |
LIBDECOR_ACTION_CLOSE);
frame_priv->visible = true;
if (ctx.init_done){
init_shell_surface(ctx.frame);
}
}
} }
if (ctx.libdecor_frame != 0){ if (ctx.frame != 0){
/* (libdecor.h) " Set the title of the window. " */ /* (libdecor.h) " Set the title of the window. " */
libdecor_frame_set_title(ctx.libdecor_frame, "Example Window"); libdecor_frame_set_title(ctx.frame, "Example Window");
/* (libdecor.h) " This translates roughly to xdg_toplevel_set_min_size() " /* (libdecor.h) " This translates roughly to xdg_toplevel_set_min_size() "
**~ NOTE: I recommend setting this to something greater than 0 on each **~ NOTE: I recommend setting this to something greater than 0 on each
** axis, to prevent some artifacts when resize goes 0 or negative. ** axis, to prevent some artifacts when resize goes 0 or negative.
*/ */
libdecor_frame_set_min_content_size(ctx.libdecor_frame, 80, 60); libdecor_frame_set_min_content_size(ctx.frame, 80, 60);
/* (libdecor.h) " Map the window. " */ /* (libdecor.h) " Map the window. " */
libdecor_frame_map(ctx.libdecor_frame); libdecor_frame_map(ctx.frame);
/* (nodocs-wl_egl) */ /* (nodocs-wl_egl) */
ctx.wl_egl_window = wl_egl_window_create(ctx.wl_surface, ctx.w, ctx.h); ctx.wl_egl_window = wl_egl_window_create(ctx.wl_surface, ctx.w, ctx.h);
@ -514,7 +542,7 @@ int main(){
if (ctx.has_cached_config){ if (ctx.has_cached_config){
ctx.has_cached_config = 0; ctx.has_cached_config = 0;
struct libdecor_state *state = libdecor_state_new(ctx.w, ctx.h); struct libdecor_state *state = libdecor_state_new(ctx.w, ctx.h);
libdecor_frame_commit(ctx.libdecor_frame, state, &ctx.cached_config); libdecor_frame_commit(ctx.frame, state, &ctx.cached_config);
libdecor_state_free(state); libdecor_state_free(state);
} }
@ -777,10 +805,7 @@ libdecor_configuration_get_window_state(struct libdecor_configuration *configura
} }
static void static void
xdg_surface_configure(void *user_data, xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t serial){
struct xdg_surface *xdg_surface,
uint32_t serial)
{
struct libdecor_frame *frame = user_data; struct libdecor_frame *frame = user_data;
struct libdecor_frame_private *frame_priv = frame->priv; struct libdecor_frame_private *frame_priv = frame->priv;
struct libdecor_configuration *configuration; struct libdecor_configuration *configuration;
@ -1050,49 +1075,6 @@ init_shell_surface(struct libdecor_frame *frame)
do_map(frame); do_map(frame);
} }
struct libdecor_frame *
libdecor_decorate(struct wl_surface *wl_surface, void *user_data){
struct libdecor_frame *frame;
struct libdecor_frame_private *frame_priv;
if (ctx.has_error){
return NULL;
}
frame = libdecor_plugin_gtk_frame_new();
if (!frame){
return NULL;
}
frame_priv = calloc(1, sizeof *frame_priv);
frame->priv = frame_priv;
frame_priv->ref_count = 1;
frame_priv->wl_surface = wl_surface;
frame_priv->user_data = user_data;
frame_priv->wm_capabilities = LIBDECOR_WM_CAPABILITIES_WINDOW_MENU |
LIBDECOR_WM_CAPABILITIES_MAXIMIZE |
LIBDECOR_WM_CAPABILITIES_FULLSCREEN |
LIBDECOR_WM_CAPABILITIES_MINIMIZE;
wl_list_insert(&ctx.frames, &frame->link);
libdecor_frame_set_capabilities(frame,
LIBDECOR_ACTION_MOVE |
LIBDECOR_ACTION_RESIZE |
LIBDECOR_ACTION_MINIMIZE |
LIBDECOR_ACTION_FULLSCREEN |
LIBDECOR_ACTION_CLOSE);
frame_priv->visible = true;
if (ctx.init_done)
init_shell_surface(frame);
return frame;
}
void void
libdecor_frame_ref(struct libdecor_frame *frame) libdecor_frame_ref(struct libdecor_frame *frame)
{ {

View File

@ -61,7 +61,6 @@
// libdecor.h // libdecor.h
struct libdecor_frame;
struct libdecor_configuration; struct libdecor_configuration;
struct libdecor_state; struct libdecor_state;
@ -452,7 +451,6 @@ bool libdecor_configuration_get_content_size(struct libdecor_configuration *conf
bool libdecor_configuration_get_window_state(struct libdecor_configuration *configuration, bool libdecor_configuration_get_window_state(struct libdecor_configuration *configuration,
enum libdecor_window_state *window_state); enum libdecor_window_state *window_state);
struct libdecor_frame* libdecor_decorate(struct wl_surface *wl_surface, void *user_data);
int libdecor_dispatch(int timeout); int libdecor_dispatch(int timeout);
// libdecor-plugin.h // libdecor-plugin.h
@ -499,6 +497,7 @@ int libdecor_os_create_anonymous_file(off_t size);
// #include "libdecor.c" // #include "libdecor.c"
static void finish_init(void); static void finish_init(void);
static void init_shell_surface(struct libdecor_frame *frame);
//#include "plugins/gtk/libdecor-gtk.c" //#include "plugins/gtk/libdecor-gtk.c"
@ -556,7 +555,7 @@ typedef struct Ctx{
/* window */ /* window */
struct wl_surface *wl_surface; struct wl_surface *wl_surface;
struct libdecor_frame *libdecor_frame; struct libdecor_frame *frame;
struct wl_egl_window *wl_egl_window; struct wl_egl_window *wl_egl_window;
int configured; int configured;
int w; int w;