[digesting_libdecor] delete dead code, eliminate some more easily reducible functions

main
Allen Webster 2026-02-28 02:56:34 -08:00
parent 79cc95b501
commit 710f72eeeb
2 changed files with 103 additions and 267 deletions

View File

@ -94,28 +94,37 @@ const struct wl_shm_listener shm_listener = { shm_format };
static void
pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y){
if (surface){
struct seat *seat = data;
bool is_own_surface = own_proxy(surface);
if (is_own_surface || ctx.handle_cursor){
if (seat->cursor_surface == 0){
seat->cursor_surface = wl_compositor_create_surface(ctx.wl_compositor);
}
seat->pointer_x = wl_fixed_to_int(surface_x);
seat->pointer_y = wl_fixed_to_int(surface_y);
seat->serial = serial;
seat->pointer_focus = surface;
struct seat *seat = data;
if (seat->cursor_surface == 0){
seat->cursor_surface = wl_compositor_create_surface(ctx.wl_compositor);
}
seat->pointer_x = wl_fixed_to_int(surface_x);
seat->pointer_y = wl_fixed_to_int(surface_y);
seat->serial = serial;
seat->pointer_focus = surface;
if (own_proxy(surface)){
ctx.active = border_component_from_wl_surface(surface);
if (ctx.active){
draw_decoration();
wl_surface_commit(ctx.wl_surface);
}
update_local_cursor(seat);
if (is_own_surface){
ctx.active = border_component_from_wl_surface(surface);
if (ctx.active){
draw_decoration();
wl_surface_commit(ctx.wl_surface);
}
update_local_cursor(seat);
send_cursor(seat);
if (seat->current_cursor != 0){
struct wl_cursor_image *image = seat->current_cursor->images[0];
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
wl_surface_attach(seat->cursor_surface, buffer, 0, 0);
wl_surface_set_buffer_scale(seat->cursor_surface, seat->cursor_scale);
wl_surface_damage_buffer(seat->cursor_surface, 0, 0,
image->width * seat->cursor_scale,
image->height * seat->cursor_scale);
wl_surface_commit(seat->cursor_surface);
wl_pointer_set_cursor(seat->wl_pointer, seat->serial,
seat->cursor_surface,
image->hotspot_x / seat->cursor_scale,
image->hotspot_y / seat->cursor_scale);
}
}
}
@ -149,7 +158,20 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
seat->pointer_x = wl_fixed_to_int(surface_x);
seat->pointer_y = wl_fixed_to_int(surface_y);
if (update_local_cursor(seat)){
send_cursor(seat);
if (seat->current_cursor != 0){
struct wl_cursor_image *image = seat->current_cursor->images[0];
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
wl_surface_attach(seat->cursor_surface, buffer, 0, 0);
wl_surface_set_buffer_scale(seat->cursor_surface, seat->cursor_scale);
wl_surface_damage_buffer(seat->cursor_surface, 0, 0,
image->width * seat->cursor_scale,
image->height * seat->cursor_scale);
wl_surface_commit(seat->cursor_surface);
wl_pointer_set_cursor(seat->wl_pointer, seat->serial,
seat->cursor_surface,
image->hotspot_x / seat->cursor_scale,
image->hotspot_y / seat->cursor_scale);
}
}
/* avoid warnings after decoration has been turned off */
@ -171,10 +193,10 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
switch (ctx.titlebar_gesture.state) {
case TITLEBAR_GESTURE_STATE_BUTTON_PRESSED:
if (ctx.titlebar_gesture.first_pressed_button == BTN_LEFT) {
if (ctx.titlebar_gesture.first_pressed_button == BTN_LEFT){
if (ABS((double)seat->pointer_x - (double)ctx.titlebar_gesture.pressed_x) > ctx.drag_threshold ||
ABS((double)seat->pointer_y - (double)ctx.titlebar_gesture.pressed_y) > ctx.drag_threshold){
libdecor_frame_move(seat->wl_seat, ctx.titlebar_gesture.pressed_serial);
xdg_toplevel_move(ctx.xdg_toplevel, seat->wl_seat, ctx.titlebar_gesture.pressed_serial);
}
}
case TITLEBAR_GESTURE_STATE_INIT:
@ -373,7 +395,7 @@ touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
else{
if (ctx.frame_capabilities & LIBDECOR_ACTION_MOVE){
seat->touch_down_time_stamp = time;
libdecor_frame_move(seat->wl_seat, serial);
xdg_toplevel_move(ctx.xdg_toplevel, seat->wl_seat, serial);
}
}
}break;
@ -442,7 +464,7 @@ static void
touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
int32_t id, wl_fixed_t x, wl_fixed_t y){
struct seat *seat = data;
if (seat->touch_focus && own_proxy(seat->touch_focus)){
if (seat->touch_focus != 0 && own_proxy(seat->touch_focus)){
update_touch_focus(seat, x, y);
}
}
@ -495,48 +517,6 @@ const struct wl_seat_listener seat_listener = {
seat_name
};
#if 0
static void
output_geometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y,
int32_t physical_width, int32_t physical_height,
int32_t subpixel, const char *make, const char *model,
int32_t transform){}
static void
output_mode(void *data, struct wl_output *wl_output,
uint32_t flags, int32_t width, int32_t height,
int32_t refresh){}
static void
output_done(void *data, struct wl_output *wl_output){
struct output *output = data;
struct seat *seat;
if (ctx.decoration_type != DECORATION_TYPE_NONE){
redraw_scale(&ctx.shadow);
}
wl_list_for_each(seat, &ctx.seat_list, link){
if (update_local_cursor(seat)){
send_cursor(seat);
}
}
}
static void
output_scale(void *data, struct wl_output *wl_output, int32_t factor){
struct output *output = data;
output->scale = factor;
}
const struct wl_output_listener output_listener = {
output_geometry,
output_mode,
output_done,
output_scale
};
#endif
static void
wl_registry_global(void *data, struct wl_registry *wl_registry,
uint32_t name, const char *interface,
@ -587,52 +567,11 @@ wl_registry_global(void *data, struct wl_registry *wl_registry,
seat->wl_seat = wl_registry_bind(ctx.wl_registry, name, &wl_seat_interface, 3);
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
}
#if 0
else if (strcmp(interface, "wl_output") == 0){
struct output *output;
if (version < 2){
ctx.has_error = true;
}
output = calloc(1, sizeof *output);
wl_list_insert(&ctx.output_list, &output->link);
output->id = name;
output->wl_output = wl_registry_bind(ctx.wl_registry, name, &wl_output_interface, MIN(version, 3));
wl_proxy_set_tag((struct wl_proxy*)output->wl_output, &libdecor_gtk_proxy_tag);
wl_output_add_listener(output->wl_output, &output_listener, output);
}
#endif
}
static void
wl_registry_global_remove(void *data, struct wl_registry *registry,
uint32_t name){
#if 0
struct output *output;
wl_list_for_each(output, &ctx.output_list, link){
if (output->id == name){
struct seat *seat;
if (ctx.decoration_type != DECORATION_TYPE_NONE){
struct surface_output *surface_output;
wl_list_for_each(surface_output, &ctx.shadow.output_list, link) {
if (surface_output->output == output) {
wl_list_remove(&surface_output->link);
free(surface_output);
break;
}
}
}
wl_list_remove(&output->link);
wl_output_destroy(output->wl_output);
free(output);
break;
}
}
#endif
}
uint32_t name){}
const struct wl_registry_listener wl_registry_listener = {
wl_registry_global,
@ -826,9 +765,6 @@ int main(){
ctx.w = 640;
ctx.h = 480;
wl_list_init(&ctx.seat_list);
#if 0
wl_list_init(&ctx.output_list);
#endif
}
if (gtk_init_success){
@ -1203,18 +1139,8 @@ int main(){
*/
//#include "libdecor.c"
/* gather all states at which a window is non-floating */
static const enum libdecor_window_state states_non_floating =
LIBDECOR_WINDOW_STATE_MAXIMIZED | LIBDECOR_WINDOW_STATE_FULLSCREEN |
LIBDECOR_WINDOW_STATE_TILED_LEFT | LIBDECOR_WINDOW_STATE_TILED_RIGHT |
LIBDECOR_WINDOW_STATE_TILED_TOP | LIBDECOR_WINDOW_STATE_TILED_BOTTOM;
static bool
state_is_floating(enum libdecor_window_state window_state){
return !(window_state & states_non_floating);
}
static void
constrain_content_size(int *width, int *height){
const struct libdecor_limits lim = ctx.content_limits;
@ -1230,7 +1156,7 @@ constrain_content_size(int *width, int *height){
*height = MIN(*height, lim.max_height);
}
static bool
static void
frame_get_window_size_for(struct libdecor_state *state, int *window_width, int *window_height){
*window_width = state->content_width;
*window_height = state->content_height;
@ -1241,8 +1167,6 @@ frame_get_window_size_for(struct libdecor_state *state, int *window_width, int *
*window_width += left + right;
*window_height += top + bottom;
}
return true;
}
static void
@ -1297,7 +1221,7 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura
}
/* constrain content dimensions manually */
if (state_is_floating(configuration->window_state)) {
if (!(configuration->window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)) {
constrain_content_size(width, height);
}
@ -1389,11 +1313,6 @@ libdecor_frame_resize(struct wl_seat *wl_seat, uint32_t serial, enum libdecor_re
xdg_toplevel_resize(ctx.xdg_toplevel, wl_seat, serial, xdg_edge);
}
void
libdecor_frame_move(struct wl_seat *wl_seat, uint32_t serial){
xdg_toplevel_move(ctx.xdg_toplevel, wl_seat, serial);
}
void
libdecor_frame_set_fullscreen(struct wl_output *output){
xdg_toplevel_set_fullscreen(ctx.xdg_toplevel, output);
@ -1404,84 +1323,6 @@ libdecor_frame_unset_fullscreen(void){
xdg_toplevel_unset_fullscreen(ctx.xdg_toplevel);
}
bool
libdecor_frame_is_floating(void){
return state_is_floating(ctx.frame_window_state);
}
bool
valid_limits(void){
if (ctx.content_limits.min_width > 0 &&
ctx.content_limits.max_width > 0 &&
ctx.content_limits.min_width >
ctx.content_limits.max_width)
return false;
if (ctx.content_limits.min_height > 0 &&
ctx.content_limits.max_height > 0 &&
ctx.content_limits.min_height >
ctx.content_limits.max_height)
return false;
return true;
}
static void
libdecor_frame_apply_limits(enum libdecor_window_state window_state){
if (!valid_limits()){
ctx.has_error = true;
}
/* If the frame is configured as non-resizable before the first
* configure event is received, we have to manually set the min/max
* limits with the configured content size afterwards. */
if (!(ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){
ctx.content_limits.min_width = ctx.frame_content_width;
ctx.content_limits.min_height = ctx.frame_content_height;
ctx.content_limits.max_width = ctx.frame_content_width;
ctx.content_limits.max_height = ctx.frame_content_height;
}
if (ctx.content_limits.min_width > 0 &&
ctx.content_limits.min_height > 0){
struct libdecor_state state_min;
int win_min_width, win_min_height;
state_min.content_width = ctx.content_limits.min_width;
state_min.content_height = ctx.content_limits.min_height;
state_min.window_state = window_state;
frame_get_window_size_for(&state_min, &win_min_width, &win_min_height);
xdg_toplevel_set_min_size(ctx.xdg_toplevel, win_min_width, win_min_height);
}
else{
xdg_toplevel_set_min_size(ctx.xdg_toplevel, 0, 0);
}
if (ctx.content_limits.max_width > 0 &&
ctx.content_limits.max_height > 0){
struct libdecor_state state_max;
int win_max_width, win_max_height;
state_max.content_width = ctx.content_limits.max_width;
state_max.content_height = ctx.content_limits.max_height;
state_max.window_state = window_state;
frame_get_window_size_for(&state_max, &win_max_width, &win_max_height);
xdg_toplevel_set_max_size(ctx.xdg_toplevel, win_max_width, win_max_height);
}
else{
xdg_toplevel_set_max_size(ctx.xdg_toplevel, 0, 0);
}
}
static void
libdecor_frame_apply_state(struct libdecor_state *state){
ctx.frame_content_width = state->content_width;
ctx.frame_content_height = state->content_height;
libdecor_frame_apply_limits(state->window_state);
}
void
libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration){
struct libdecor_state state = {0};
@ -1496,7 +1337,51 @@ libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration
state.window_state = ctx.frame_window_state;
}
libdecor_frame_apply_state(&state);
ctx.frame_content_width = state.content_width;
ctx.frame_content_height = state.content_height;
{
/* If the frame is configured as non-resizable before the first
* configure event is received, we have to manually set the min/max
* limits with the configured content size afterwards. */
if (!(ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){
ctx.content_limits.min_width = ctx.frame_content_width;
ctx.content_limits.min_height = ctx.frame_content_height;
ctx.content_limits.max_width = ctx.frame_content_width;
ctx.content_limits.max_height = ctx.frame_content_height;
}
if (ctx.content_limits.min_width > 0 &&
ctx.content_limits.min_height > 0){
struct libdecor_state state_min;
int win_min_width, win_min_height;
state_min.content_width = ctx.content_limits.min_width;
state_min.content_height = ctx.content_limits.min_height;
state_min.window_state = state.window_state;
frame_get_window_size_for(&state_min, &win_min_width, &win_min_height);
xdg_toplevel_set_min_size(ctx.xdg_toplevel, win_min_width, win_min_height);
}
else{
xdg_toplevel_set_min_size(ctx.xdg_toplevel, 0, 0);
}
if (ctx.content_limits.max_width > 0 &&
ctx.content_limits.max_height > 0){
struct libdecor_state state_max;
int win_max_width, win_max_height;
state_max.content_width = ctx.content_limits.max_width;
state_max.content_height = ctx.content_limits.max_height;
state_max.window_state = state.window_state;
frame_get_window_size_for(&state_max, &win_max_width, &win_max_height);
xdg_toplevel_set_max_size(ctx.xdg_toplevel, win_max_width, win_max_height);
}
else{
xdg_toplevel_set_max_size(ctx.xdg_toplevel, 0, 0);
}
}
/* switch between decoration modes */
if (ctx.visible != 0 &&
@ -1991,11 +1876,6 @@ own_proxy(void *proxy){
return(result);
}
static void
libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor){
ctx.handle_cursor = handle_cursor;
}
static void
toggle_maximized(void){
if (ctx.frame_window_state & LIBDECOR_WINDOW_STATE_MAXIMIZED){
@ -2529,7 +2409,7 @@ draw_title_bar(void){
gtk_widget_unset_state_flags(ctx.window, GTK_STATE_FLAG_BACKDROP);
}
if (libdecor_frame_is_floating()){
if (!(ctx.frame_window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)){
gtk_style_context_remove_class(style, "maximized");
}
else{
@ -2676,36 +2556,6 @@ update_component_focus(struct wl_surface *surface, struct seat *seat){
ctx.focus = focus_component;
}
static void
synthesize_pointer_enter(struct seat *seat){
struct wl_surface *surface;
surface = seat->pointer_focus;
if (surface && own_proxy(surface)){
update_component_focus(seat->pointer_focus, seat);
ctx.grab = 0;
if (ctx.active) {
draw_decoration();
wl_surface_commit(ctx.wl_surface);
}
update_local_cursor(seat);
send_cursor(seat);
}
}
static void
synthesize_pointer_leave(struct seat *seat){
struct wl_surface *surface = seat->pointer_focus;
if (surface != 0 && own_proxy(surface)){
if (ctx.active != 0){
ctx.active = 0;
draw_decoration();
wl_surface_commit(ctx.wl_surface);
update_local_cursor(seat);
}
}
}
static void
libdecor_plugin_gtk_frame_get_border_size(enum libdecor_window_state window_state,
int *left, int *right, int *top, int *bottom){
@ -2843,23 +2693,6 @@ update_local_cursor(struct seat *seat){
return(result);
}
static void
send_cursor(struct seat *seat){
if (seat->pointer_focus != 0 && seat->current_cursor != 0){
struct wl_cursor_image *image = seat->current_cursor->images[0];
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
wl_surface_attach(seat->cursor_surface, buffer, 0, 0);
wl_surface_set_buffer_scale(seat->cursor_surface, seat->cursor_scale);
wl_surface_damage_buffer(seat->cursor_surface, 0, 0,
image->width * seat->cursor_scale,
image->height * seat->cursor_scale);
wl_surface_commit(seat->cursor_surface);
wl_pointer_set_cursor(seat->wl_pointer, seat->serial,
seat->cursor_surface,
image->hotspot_x / seat->cursor_scale,
image->hotspot_y / seat->cursor_scale);
}
}
static void
update_touch_focus(struct seat *seat, wl_fixed_t x, wl_fixed_t y){

View File

@ -86,6 +86,13 @@ enum libdecor_window_state {
LIBDECOR_WINDOW_STATE_CONSTRAINED_BOTTOM = 1 << 12,
};
#define LIBDECOR_WINDOW_STATE_NON_FLOATING (LIBDECOR_WINDOW_STATE_MAXIMIZED |\
LIBDECOR_WINDOW_STATE_FULLSCREEN |\
LIBDECOR_WINDOW_STATE_TILED_LEFT |\
LIBDECOR_WINDOW_STATE_TILED_RIGHT |\
LIBDECOR_WINDOW_STATE_TILED_TOP |\
LIBDECOR_WINDOW_STATE_TILED_BOTTOM)
enum libdecor_resize_edge {
LIBDECOR_RESIZE_EDGE_NONE,
LIBDECOR_RESIZE_EDGE_TOP,
@ -275,7 +282,6 @@ void libdecor_frame_move(struct wl_seat *wl_seat, uint32_t serial);
void libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration);
void libdecor_frame_set_fullscreen(struct wl_output *output);
void libdecor_frame_unset_fullscreen(void);
bool libdecor_frame_is_floating(void);
void libdecor_frame_map(void);
bool libdecor_configuration_get_content_size(struct libdecor_configuration *configuration, int *width, int *height);
@ -305,7 +311,6 @@ static void do_map(void);
static const char *libdecor_gtk_proxy_tag = "libdecor-gtk";
static void libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor);
static void libdecor_plugin_gtk_frame_free(void);
static void libdecor_plugin_gtk_frame_commit(struct libdecor_state *state, struct libdecor_configuration *configuration);
static void libdecor_plugin_gtk_frame_get_border_size(enum libdecor_window_state window_state, int *left, int *right, int *top, int *bottom);
@ -314,7 +319,6 @@ static bool update_local_cursor(struct seat *seat);
static void draw_decoration(void);
static void draw_header_button(cairo_t *cr, cairo_surface_t *surface, enum header_element button_type);
static void redraw_scale(struct border_component *cmpnt);
static void send_cursor(struct seat *seat);
static void buffer_free(struct buffer *buffer);
static void draw_border_component(struct border_component *border_component);
@ -350,7 +354,6 @@ typedef struct Ctx{
bool has_argb;
int double_click_time_ms;
int drag_threshold;
bool handle_cursor;
/* window */
struct wl_surface *wl_surface;