[digesting_libdecor] clean up the property changing code, eliminate notify_on_property_change

main
Allen Webster 2026-02-26 18:46:28 -08:00
parent 785b014580
commit c1f41242ec
2 changed files with 121 additions and 149 deletions

View File

@ -406,51 +406,49 @@ int main(){
} }
if (ctx.wl_surface != 0){ if (ctx.wl_surface != 0){
{ ctx.frame = calloc(1, sizeof *ctx.frame);
ctx.frame = calloc(1, sizeof *ctx.frame);
wl_list_insert(&ctx.visible_frame_list, &ctx.frame->gtk_link);
{
static const int size = 128;
static const int boundary = 32;
cairo_t *cr;
ctx.frame->shadow_blur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size);
cr = cairo_create(ctx.frame->shadow_blur);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 0, 0, 0, 1);
cairo_rectangle(cr, boundary, boundary, size - 2*boundary, size - 2*boundary);
cairo_fill(cr);
cairo_destroy(cr);
blur_surface(ctx.frame->shadow_blur, 64);
}
}
{ {
ctx.frame->ref_count = 1; static const int size = 128;
static const int boundary = 32;
cairo_t *cr;
cairo_surface_t *shadow_blur;
ctx.frame->wl_surface = ctx.wl_surface; shadow_blur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size);
ctx.frame->wm_capabilities = (LIBDECOR_WM_CAPABILITIES_WINDOW_MENU | cr = cairo_create(shadow_blur);
LIBDECOR_WM_CAPABILITIES_MAXIMIZE | cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
LIBDECOR_WM_CAPABILITIES_FULLSCREEN | cairo_set_source_rgba(cr, 0, 0, 0, 1);
LIBDECOR_WM_CAPABILITIES_MINIMIZE); cairo_rectangle(cr, boundary, boundary, size - 2*boundary, size - 2*boundary);
cairo_fill(cr);
cairo_destroy(cr);
wl_list_insert(&ctx.frames, &ctx.frame->frame_link); blur_surface(shadow_blur, 64);
ctx.frame->shadow_blur = shadow_blur;
libdecor_frame_set_capabilities(ctx.frame,
LIBDECOR_ACTION_MOVE |
LIBDECOR_ACTION_RESIZE |
LIBDECOR_ACTION_MINIMIZE |
LIBDECOR_ACTION_FULLSCREEN |
LIBDECOR_ACTION_CLOSE);
ctx.frame->visible = true;
if (ctx.init_done){
init_shell_surface(ctx.frame);
}
} }
ctx.frame->ref_count = 1;
ctx.frame->wl_surface = ctx.wl_surface;
ctx.frame->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->frame_link);
wl_list_insert(&ctx.visible_frame_list, &ctx.frame->gtk_link);
ctx.frame->visible = true;
set_capabilities(ctx.frame,
LIBDECOR_ACTION_MOVE |
LIBDECOR_ACTION_RESIZE |
LIBDECOR_ACTION_MINIMIZE |
LIBDECOR_ACTION_FULLSCREEN |
LIBDECOR_ACTION_CLOSE);
if (ctx.init_done){
init_shell_surface(ctx.frame);
}
} }
if (ctx.frame != 0){ if (ctx.frame != 0){
@ -1160,13 +1158,21 @@ libdecor_frame_set_title(struct libdecor_frame *frame, const char *title){
free(frame->state.title); free(frame->state.title);
frame->state.title = strdup(title); frame->state.title = strdup(title);
if (!frame->xdg_toplevel){ free(frame->title);
return; frame->title = strdup(title);
if (frame->xdg_toplevel != 0){
xdg_toplevel_set_title(frame->xdg_toplevel, title);
/*
* when in SSD mode, the window title is not to be managed by GTK;
* this is detected by frame_gtk->header not being a proper GTK widget
*/
if (GTK_IS_WIDGET(frame->header)){
draw_decoration(frame);
libdecor_frame_toplevel_commit(frame);
}
} }
xdg_toplevel_set_title(frame->xdg_toplevel, title);
libdecor_plugin_gtk_frame_property_changed(frame);
} }
} }
@ -1187,58 +1193,43 @@ libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id){
} }
static void static void
notify_on_capability_change(struct libdecor_frame *frame, set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities){
const enum libdecor_capabilities old_capabilities)
{
struct libdecor_state *state; struct libdecor_state *state;
if (frame->frame_capabilities == old_capabilities) if (frame->frame_capabilities != new_capabilities){
return; frame->frame_capabilities = new_capabilities;
if (frame->frame_content_width != 0 &&
if (frame->frame_content_width == 0 || frame->frame_content_height != 0){
frame->frame_content_height == 0)
return; frame->gtk_capabilities = frame->frame_capabilities;
libdecor_plugin_gtk_frame_property_changed(frame); /*
* when in SSD mode, the window title is not to be managed by GTK;
if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { * this is detected by frame_gtk->header not being a proper GTK widget
frame->interactive_limits = frame->state.content_limits; */
/* set fixed window size */ if (GTK_IS_WIDGET(frame->header)){
libdecor_frame_set_min_content_size(frame, draw_decoration(frame);
frame->frame_content_width, libdecor_frame_toplevel_commit(frame);
frame->frame_content_height); }
libdecor_frame_set_max_content_size(frame,
frame->frame_content_width, if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)){
frame->frame_content_height); frame->interactive_limits = frame->state.content_limits;
} else { /* set fixed window size */
/* restore old limits */ libdecor_frame_set_min_content_size(frame, frame->frame_content_width, frame->frame_content_height);
frame->state.content_limits = frame->interactive_limits; libdecor_frame_set_max_content_size(frame, frame->frame_content_width, frame->frame_content_height);
}
else{
/* restore old limits */
frame->state.content_limits = frame->interactive_limits;
}
state = libdecor_state_new(frame->frame_content_width, frame->frame_content_height);
libdecor_frame_commit(frame, state, NULL);
libdecor_state_free(state);
libdecor_frame_toplevel_commit(frame);
}
} }
state = libdecor_state_new(frame->frame_content_width,
frame->frame_content_height);
libdecor_frame_commit(frame, state, NULL);
libdecor_state_free(state);
libdecor_frame_toplevel_commit(frame);
}
void
libdecor_frame_set_capabilities(struct libdecor_frame *frame,
enum libdecor_capabilities capabilities)
{
const enum libdecor_capabilities old_capabilities = frame->frame_capabilities;
frame->frame_capabilities |= capabilities;
notify_on_capability_change(frame, old_capabilities);
}
void
libdecor_frame_unset_capabilities(struct libdecor_frame *frame,
enum libdecor_capabilities capabilities)
{
const enum libdecor_capabilities old_capabilities = frame->frame_capabilities;
frame->frame_capabilities &= ~capabilities;
notify_on_capability_change(frame, old_capabilities);
} }
bool bool
@ -1615,8 +1606,7 @@ cleanup(void){
//#include "libdecor-cairo-blur.c" //#include "libdecor-cairo-blur.c"
int int
blur_surface(cairo_surface_t *surface, int margin) blur_surface(cairo_surface_t *surface, int margin){
{
int32_t width, height, stride, x, y, z, w; int32_t width, height, stride, x, y, z, w;
uint8_t *src, *dst; uint8_t *src, *dst;
uint32_t *s, *d, a, p; uint32_t *s, *d, a, p;
@ -1705,8 +1695,7 @@ blur_surface(cairo_surface_t *surface, int margin)
void void
render_shadow(cairo_t *cr, cairo_surface_t *surface, render_shadow(cairo_t *cr, cairo_surface_t *surface,
int x, int y, int width, int height, int margin, int top_margin) int x, int y, int width, int height, int margin, int top_margin){
{
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_matrix_t matrix; cairo_matrix_t matrix;
int i, fx, fy, shadow_height, shadow_width; int i, fx, fy, shadow_height, shadow_width;
@ -2198,8 +2187,7 @@ libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor){
} }
static void static void
toggle_maximized(struct libdecor_frame *const frame) toggle_maximized(struct libdecor_frame *const frame){
{
if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE))
return; return;
@ -2211,9 +2199,7 @@ toggle_maximized(struct libdecor_frame *const frame)
} }
static void static void
buffer_release(void *user_data, buffer_release(void *user_data, struct wl_buffer *wl_buffer){
struct wl_buffer *wl_buffer)
{
struct buffer *buffer = user_data; struct buffer *buffer = user_data;
if (buffer->is_detached) if (buffer->is_detached)
@ -2227,11 +2213,7 @@ const struct wl_buffer_listener buffer_listener = {
}; };
static struct buffer * static struct buffer *
create_shm_buffer(int width, create_shm_buffer(int width, int height, bool opaque, int scale){
int height,
bool opaque,
int scale)
{
struct wl_shm_pool *pool; struct wl_shm_pool *pool;
int fd, size, buffer_width, buffer_height, stride; int fd, size, buffer_width, buffer_height, stride;
void *data; void *data;
@ -2280,8 +2262,7 @@ create_shm_buffer(int width,
} }
static void static void
buffer_free(struct buffer *buffer) buffer_free(struct buffer *buffer){
{
if (buffer->wl_buffer) { if (buffer->wl_buffer) {
wl_buffer_destroy(buffer->wl_buffer); wl_buffer_destroy(buffer->wl_buffer);
munmap(buffer->data, buffer->data_size); munmap(buffer->data, buffer->data_size);
@ -2292,8 +2273,7 @@ buffer_free(struct buffer *buffer)
} }
static void static void
free_border_component(struct border_component *border_component) free_border_component(struct border_component *border_component){
{
if (border_component->wl_surface) { if (border_component->wl_surface) {
wl_subsurface_destroy(border_component->wl_subsurface); wl_subsurface_destroy(border_component->wl_subsurface);
border_component->wl_subsurface = NULL; border_component->wl_subsurface = NULL;
@ -3138,9 +3118,9 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame,
} }
} }
#if 0
static void static void
libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame) libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame){
{
bool redraw_needed = false; bool redraw_needed = false;
const char *new_title; const char *new_title;
@ -3148,27 +3128,30 @@ libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame)
* when in SSD mode, the window title is not to be managed by GTK; * when in SSD mode, the window title is not to be managed by GTK;
* this is detected by frame_gtk->header not being a proper GTK widget * this is detected by frame_gtk->header not being a proper GTK widget
*/ */
if (!GTK_IS_WIDGET(frame->header)) return; if (GTK_IS_WIDGET(frame->header)){
new_title = libdecor_frame_get_title(frame); new_title = libdecor_frame_get_title(frame);
if (!STREQL(frame->title, new_title)) if (!STREQL(frame->title, new_title)){
redraw_needed = true; redraw_needed = true;
free(frame->title); }
frame->title = NULL; free(frame->title);
if (new_title){ frame->title = NULL;
frame->title = strdup(new_title); if (new_title){
} frame->title = strdup(new_title);
}
if (frame->gtk_capabilities != libdecor_frame_get_capabilities(frame)){
frame->gtk_capabilities = libdecor_frame_get_capabilities(frame); if (frame->gtk_capabilities != libdecor_frame_get_capabilities(frame)){
redraw_needed = true; frame->gtk_capabilities = libdecor_frame_get_capabilities(frame);
} redraw_needed = true;
}
if (redraw_needed){
draw_decoration(frame); if (redraw_needed){
libdecor_frame_toplevel_commit(frame); draw_decoration(frame);
libdecor_frame_toplevel_commit(frame);
}
} }
} }
#endif
static void static void
update_component_focus(struct libdecor_frame *frame, struct wl_surface *surface, struct seat *seat){ update_component_focus(struct libdecor_frame *frame, struct wl_surface *surface, struct seat *seat){

View File

@ -33,15 +33,6 @@
// config.h // config.h
/* Version number of package */
#define VERSION "0.2.2"
/* Plugin directiory path */
#define LIBDECOR_PLUGIN_DIR "/usr/local/lib/x86_64-linux-gnu/libdecor/plugins-1"
/* Plugin API version */
#define LIBDECOR_PLUGIN_API_VERSION 1
#define HAS_DBUS #define HAS_DBUS
/* #undef HAVE_MKOSTEMP */ /* #undef HAVE_MKOSTEMP */
@ -381,10 +372,6 @@ void libdecor_frame_set_title(struct libdecor_frame *frame,
const char * libdecor_frame_get_title(struct libdecor_frame *frame); const char * libdecor_frame_get_title(struct libdecor_frame *frame);
void libdecor_frame_set_app_id(struct libdecor_frame *frame, void libdecor_frame_set_app_id(struct libdecor_frame *frame,
const char *app_id); const char *app_id);
void libdecor_frame_set_capabilities(struct libdecor_frame *frame,
enum libdecor_capabilities capabilities);
void libdecor_frame_unset_capabilities(struct libdecor_frame *frame,
enum libdecor_capabilities capabilities);
bool libdecor_frame_has_capability(struct libdecor_frame *frame, bool libdecor_frame_has_capability(struct libdecor_frame *frame,
enum libdecor_capabilities capability); enum libdecor_capabilities capability);
void libdecor_frame_show_window_menu(struct libdecor_frame *frame, void libdecor_frame_show_window_menu(struct libdecor_frame *frame,
@ -481,7 +468,6 @@ void render_shadow(cairo_t *cr, cairo_surface_t *surface,
bool libdecor_get_cursor_settings(char **theme, int *size); bool libdecor_get_cursor_settings(char **theme, int *size);
enum libdecor_color_scheme libdecor_get_color_scheme(); enum libdecor_color_scheme libdecor_get_color_scheme();
// #include "os-compatibility.h" // #include "os-compatibility.h"
int libdecor_os_create_anonymous_file(off_t size); int libdecor_os_create_anonymous_file(off_t size);
@ -491,6 +477,8 @@ int libdecor_os_create_anonymous_file(off_t size);
static void finish_init(void); static void finish_init(void);
static void init_shell_surface(struct libdecor_frame *frame); static void init_shell_surface(struct libdecor_frame *frame);
static void set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities);
//#include "plugins/gtk/libdecor-gtk.c" //#include "plugins/gtk/libdecor-gtk.c"
@ -507,11 +495,12 @@ static int libdecor_plugin_gtk_dispatch(int timeout);
static void libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor); static void libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor);
static void libdecor_plugin_gtk_frame_free(struct libdecor_frame *frame); static void libdecor_plugin_gtk_frame_free(struct libdecor_frame *frame);
static void libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, struct libdecor_state *state, struct libdecor_configuration *configuration); static void libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, struct libdecor_state *state, struct libdecor_configuration *configuration);
static void libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame);
static void libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name); static void libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name);
static void libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name); static void libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name);
static bool libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, struct libdecor_configuration *configuration, int *left, int *right, int *top, int *bottom); static bool libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, struct libdecor_configuration *configuration, int *left, int *right, int *top, int *bottom);
static void draw_decoration(struct libdecor_frame *frame);
// digesting_libdecor // digesting_libdecor
typedef struct Ctx{ typedef struct Ctx{