[wayland_gtk_egl] right click to toggle csd

main
Allen Webster 2026-03-06 19:06:20 -08:00
parent a24c38936e
commit 7f26b2662a
2 changed files with 54 additions and 11 deletions

View File

@ -406,6 +406,8 @@ int main(){
int exit_loop = 0;
for (;!exit_loop;){
/* poll for events */
ctx.has_event = 0;
{
struct pollfd fds[1] = {0};
@ -468,18 +470,31 @@ int main(){
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){
csd_gtk_update_and_render(&ctx.window, &ctx.gtk_window, seats, seat_count);
}
else{
csd_gtk_disable(&ctx.window, &ctx.gtk_window);
}
/* app update & render */
{
CSD_Window *window = &ctx.window;
/* handle right-button press */
if (ctx.has_event){
if (ctx.event_button == BTN_RIGHT &&
ctx.event_button_state == 1){
ctx.toggle_csd_signal = 1;
}
ctx.has_event = 0;
}
if (ctx.close_signal){
exit_loop = 1;
}
else if (ctx.minimize_signal){
if (ctx.minimize_signal){
ctx.minimize_signal = 0;
xdg_toplevel_set_minimized(window->main_xdg_toplevel);
}
else if (ctx.maximize_signal){
if (ctx.maximize_signal){
ctx.maximize_signal = 0;
if (window->config.flags & CSD_WindowFlag_IsMax){
xdg_toplevel_unset_maximized(window->main_xdg_toplevel);
@ -488,6 +503,18 @@ int main(){
xdg_toplevel_set_maximized(window->main_xdg_toplevel);
}
}
if (ctx.toggle_csd_signal){
ctx.toggle_csd_signal = 0;
if (window->config.decoration_mode ==
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){
zxdg_toplevel_decoration_v1_set_mode(window->main_zxdg_toplevel_decoration,
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
}
else{
zxdg_toplevel_decoration_v1_set_mode(window->main_zxdg_toplevel_decoration,
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
}
}
glDrawBuffer(GL_BACK);
glViewport(0, 0, window->dim[0], window->dim[1]);
@ -682,10 +709,15 @@ csd_subsurface_set_position(CSD_SubSurface *subsurface, CSD_S32 x, CSD_S32 y){
static void
csd_subsurface_commit(CSD_SubSurface *subsurface){
if (subsurface->wl_buffer != 0){
wl_surface_attach(subsurface->wl_surface, subsurface->wl_buffer, 0, 0);
wl_surface_set_buffer_scale(subsurface->wl_surface, 1);
wl_surface_damage_buffer(subsurface->wl_surface, 0, 0,
subsurface->dim[0], subsurface->dim[1]);
}
else{
wl_surface_attach(subsurface->wl_surface, 0, 0, 0);
}
wl_surface_commit(subsurface->wl_surface);
}
@ -1389,7 +1421,6 @@ csd_gtk_update_and_render(CSD_Window *window, CSD_GTK_Window *gtk_window,
/* process events */
if (ctx.has_event){
/* handle left-button press */
if (ctx.event_button == BTN_LEFT &&
ctx.event_button_state == 1){
@ -1434,8 +1465,9 @@ csd_gtk_update_and_render(CSD_Window *window, CSD_GTK_Window *gtk_window,
case HEADER_BUTTON_MAX: { ctx.maximize_signal = 1; } break;
case HEADER_BUTTON_CLOSE: { ctx.close_signal = 1; } break;
}
gtk_window->active_header_button = 0;
}
gtk_window->active_header_button = 0;
ctx.has_event = 0;
}
}
@ -1454,6 +1486,15 @@ csd_gtk_update_and_render(CSD_Window *window, CSD_GTK_Window *gtk_window,
}
}
static void
csd_gtk_disable(CSD_Window *window, CSD_GTK_Window *gtk_window){
csd_subsurface_buffer_clear(&gtk_window->shadow);
csd_subsurface_commit(&gtk_window->shadow);
csd_subsurface_buffer_clear(&gtk_window->titlebar);
csd_subsurface_commit(&gtk_window->titlebar);
}
/* cairo shadow rendering */
static int

View File

@ -192,6 +192,7 @@ static CSD_B32 csd_gtk_calc_surface_off(CSD_GTK_Window *gtk_window,
static void csd_gtk_update_and_render(CSD_Window *window, CSD_GTK_Window *gtk_window,
CSD_Seat **seats, CSD_U32 seat_count);
static void csd_gtk_disable(CSD_Window *window, CSD_GTK_Window *gtk_window);
/* csd gtk cairo shadow rendering */
@ -205,9 +206,10 @@ static void csd_gtk_render_shadow(cairo_t *cr, cairo_surface_t *surface,
typedef struct Ctx{
/* the rest */
CSD_B32 close_signal;
CSD_B32 minimize_signal;
CSD_B32 maximize_signal;
CSD_B8 close_signal;
CSD_B8 minimize_signal;
CSD_B8 maximize_signal;
CSD_B8 toggle_csd_signal;
CSD_B32 has_event;
CSD_U32 event_button;