From 6453c107aaa32dcb263ac3ff540b21319431d42d Mon Sep 17 00:00:00 2001 From: Philipp Kaeser Date: Fri, 12 Jan 2024 17:06:22 +0200 Subject: [PATCH] Removes the old-style decorations code. At least most of it. --- src/CMakeLists.txt | 12 +- src/config.c | 14 - src/config.h | 12 - src/decorations.h | 26 -- src/decorations/CMakeLists.txt | 44 -- src/decorations/element.c | 449 ------------------- src/decorations/element.h | 219 --------- src/decorations/margin.c | 295 ------------- src/decorations/margin.h | 94 ---- src/decorations/resizebar.c | 312 ------------- src/decorations/resizebar.h | 86 ---- src/decorations/titlebar.c | 634 --------------------------- src/decorations/titlebar.h | 90 ---- src/decorations/window_decorations.c | 230 ---------- src/decorations/window_decorations.h | 125 ------ src/resizebar.c | 273 ------------ src/resizebar.h | 77 ---- src/titlebar.c | 340 -------------- src/titlebar.h | 74 ---- src/view.c | 131 +----- src/view.h | 42 -- src/xdg_decoration.c | 20 - 22 files changed, 7 insertions(+), 3592 deletions(-) delete mode 100644 src/decorations/CMakeLists.txt delete mode 100644 src/decorations/element.c delete mode 100644 src/decorations/element.h delete mode 100644 src/decorations/margin.c delete mode 100644 src/decorations/margin.h delete mode 100644 src/decorations/resizebar.c delete mode 100644 src/decorations/resizebar.h delete mode 100644 src/decorations/titlebar.c delete mode 100644 src/decorations/titlebar.h delete mode 100644 src/decorations/window_decorations.c delete mode 100644 src/decorations/window_decorations.h delete mode 100644 src/resizebar.c delete mode 100644 src/resizebar.h delete mode 100644 src/titlebar.c delete mode 100644 src/titlebar.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7a1a4ab..05f4896d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,13 +32,11 @@ SET(SOURCES menu.c menu_item.c output.c - resizebar.c server.c subprocess_monitor.c task_list.c tile.c tile_container.c - titlebar.c view.c wlmtk_xdg_popup.c wlmtk_xdg_toplevel.c @@ -67,13 +65,11 @@ SET(HEADERS menu.h menu_item.h output.h - resizebar.h server.h subprocess_monitor.h task_list.h tile_container.h tile.h - titlebar.h view.h wlmtk_xdg_popup.h wlmtk_xdg_toplevel.h @@ -85,7 +81,7 @@ SET(HEADERS ) ADD_EXECUTABLE(wlmaker wlmaker.c ${SOURCES} ${HEADERS}) -ADD_DEPENDENCIES(wlmaker protocol_headers decorations toolkit) +ADD_DEPENDENCIES(wlmaker protocol_headers toolkit) TARGET_COMPILE_DEFINITIONS( wlmaker PRIVATE WLMAKER_ICON_DATA_DIR="${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/wlmaker") @@ -115,7 +111,7 @@ TARGET_INCLUDE_DIRECTORIES( TARGET_LINK_LIBRARIES( wlmaker PRIVATE base - decorations + toolkit wlmaker_protocols PkgConfig::CAIRO PkgConfig::LIBDRM @@ -126,7 +122,7 @@ TARGET_LINK_LIBRARIES( ) ADD_EXECUTABLE(wlmaker_test wlmaker_test.c ${SOURCES} ${HEADERS}) -ADD_DEPENDENCIES(wlmaker_test protocol_headers decorations toolkit) +ADD_DEPENDENCIES(wlmaker_test protocol_headers toolkit) TARGET_INCLUDE_DIRECTORIES( wlmaker_test PRIVATE ${PROJECT_BINARY_DIR}/third_party/protocols @@ -142,7 +138,7 @@ TARGET_INCLUDE_DIRECTORIES( TARGET_LINK_LIBRARIES( wlmaker_test PRIVATE base - decorations + toolkit wlmaker_protocols PkgConfig::CAIRO PkgConfig::LIBDRM diff --git a/src/config.c b/src/config.c index 32de7f12..e16b654f 100644 --- a/src/config.c +++ b/src/config.c @@ -72,20 +72,6 @@ const wlmaker_config_theme_t wlmaker_config_theme = { .window_margin_color = 0xff000000, // Pich black, opaque. .window_margin_width = 1, - .titlebar_focussed_fill = { - .type = WLMTK_STYLE_COLOR_HGRADIENT, - .param = { .hgradient = { .from = 0xff505a5e,.to = 0xff202a2e }} - }, - .titlebar_focussed_text_color = 0xffffffff, - .titlebar_blurred_fill = { - .type = WLMTK_STYLE_COLOR_HGRADIENT, - .param = { .hgradient = { .from = 0xffc2c0c5,.to = 0xff828085 }} - }, - .titlebar_blurred_text_color = 0xff000000, - .resizebar_fill = { - .type = WLMTK_STYLE_COLOR_SOLID, - .param = { .solid = { .color = 0xffc2c0c5 }} - }, .tile_fill = { .type = WLMTK_STYLE_COLOR_DGRADIENT, .param = { .hgradient = { .from = 0xffa6a6b6,.to = 0xff515561 }} diff --git a/src/config.h b/src/config.h index 562976f3..b75d82ad 100644 --- a/src/config.h +++ b/src/config.h @@ -51,18 +51,6 @@ typedef struct { /** Width of the window margin, in pixels. */ uint32_t window_margin_width; - /** Color of the title text when focussed. */ - uint32_t titlebar_focussed_text_color; - /** Color of the title text when blurred. */ - uint32_t titlebar_blurred_text_color; - - /** Fill style of the title bar, when focussed. Including buttons. */ - wlmtk_style_fill_t titlebar_focussed_fill; - /** Fill style of the title bar, when blurred. Including buttons. */ - wlmtk_style_fill_t titlebar_blurred_fill; - - /** Fill style of the resize bar. */ - wlmtk_style_fill_t resizebar_fill; /** Fill style of a tile. */ wlmtk_style_fill_t tile_fill; /** File style of the title element of an iconified. */ diff --git a/src/decorations.h b/src/decorations.h index b40f79e1..b11dd389 100644 --- a/src/decorations.h +++ b/src/decorations.h @@ -39,32 +39,6 @@ extern const uint32_t wlmaker_decorations_tile_size; /** Size of the clip button (length of the catheti) */ extern const uint32_t wlmaker_decorations_clip_button_size; -/** - * Creates a cairo image surface for the background of the title bar. - * - * @param width Full with of the title bar. The width depends on - * the window size; the height of the title bar is - * hardcoded. - * @param fill_ptr Specification for the fill. - * - * @return a `cairo_surface_t` image target, filled as specificed. - */ -cairo_surface_t *wlmaker_decorations_titlebar_create_background( - uint32_t width, const wlmtk_style_fill_t *fill_ptr); - -/** - * Creates a cairo image surface for the background of the resize bar. - * - * @param width Full with of the resize bar. The width depends on - * the window size; the height of the reizse bar is - * hardcoded. - * @param fill_ptr Specification for the fill. - * - * @return a `cairo_surface_t` image target, filled as specificed. - */ -cairo_surface_t *wlmaker_decorations_resizebar_create_background( - uint32_t width, const wlmtk_style_fill_t *fill_ptr); - /** * Draws a tile into the `cairo_t`. * diff --git a/src/decorations/CMakeLists.txt b/src/decorations/CMakeLists.txt deleted file mode 100644 index f098a798..00000000 --- a/src/decorations/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -CMAKE_MINIMUM_REQUIRED(VERSION 3.13) - -ADD_LIBRARY(decorations - element.c - margin.c - resizebar.c - titlebar.c - window_decorations.c - element.h - margin.h - resizebar.h - titlebar.h - window_decorations.h) - -TARGET_COMPILE_OPTIONS( - decorations PRIVATE - ${WAYLAND_CFLAGS} - ${WAYLAND_CFLAGS_OTHER} -) - -TARGET_INCLUDE_DIRECTORIES( - decorations PRIVATE - ${CAIRO_INCLUDE_DIRS} - # TODO(kaeser@gubbe.ch): These should not be required. - ${PROJECT_BINARY_DIR}/third_party/protocols - ${PIXMAN_INCLUDE_DIRS} -) - -TARGET_LINK_LIBRARIES( - decorations base toolkit) diff --git a/src/decorations/element.c b/src/decorations/element.c deleted file mode 100644 index 2972e84a..00000000 --- a/src/decorations/element.c +++ /dev/null @@ -1,449 +0,0 @@ -/* ========================================================================= */ -/** - * @file element.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "element.h" - -#include - -#include "../button.h" -#include "../resizebar.h" -#include "../titlebar.h" - -/* == Declarations ========================================================= */ - -/** Decorations element. */ -struct _wlmaker_decorations_element_t { - /** Scene graph node holding the element. */ - struct wlr_scene_buffer *wlr_scene_buffer_ptr; - - /** - * Interactive for the element. To be created by instantiated element, will - * be destroyed in @ref wlmaker_decorations_element_fini. - */ - wlmaker_interactive_t *interactive_ptr; - - /** - * Margin of the element, or NULL. - * - * TODO(kaeser@gubbe.ch): Consider moving this to the "container". - */ - wlmaker_decorations_margin_t *margin_ptr; -}; - -/** State of a button. */ -struct _wlmaker_decorations_button_t { - /** The base element. */ - wlmaker_decorations_element_t element; - /** Back-link. */ - wlmaker_view_t *view_ptr; -}; - -/** State of a title. */ -struct _wlmaker_decorations_title_t { - /** The base element. */ - wlmaker_decorations_element_t element; - /** Back-link. */ - wlmaker_view_t *view_ptr; -}; - -/** State of a resize. */ -struct _wlmaker_decorations_resize_t { - /** The base element. */ - wlmaker_decorations_element_t element; - /** Back-link. */ - wlmaker_view_t *view_ptr; -}; - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -bool wlmaker_decorations_element_init( - wlmaker_decorations_element_t *element_ptr, - struct wlr_scene_tree *wlr_scene_tree_ptr, - void *data_ptr, - unsigned width, - unsigned height, - uint32_t edges) -{ - BS_ASSERT(NULL == element_ptr->wlr_scene_buffer_ptr); - - element_ptr->wlr_scene_buffer_ptr = wlr_scene_buffer_create( - wlr_scene_tree_ptr, NULL); - if (NULL == element_ptr->wlr_scene_buffer_ptr) { - wlmaker_decorations_element_fini(element_ptr); - return false; - } - element_ptr->wlr_scene_buffer_ptr->node.data = data_ptr; - - if (0 != edges) { - element_ptr->margin_ptr = wlmaker_decorations_margin_create( - wlr_scene_tree_ptr, - 0, 0, width, height, // element_ptr->width, element_ptr->height, - edges); - } - - return true; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_element_fini( - wlmaker_decorations_element_t *element_ptr) -{ - if (NULL != element_ptr->margin_ptr) { - wlmaker_decorations_margin_destroy(element_ptr->margin_ptr); - element_ptr->margin_ptr = NULL; - } - - if (NULL != element_ptr->interactive_ptr) { - wlmaker_interactive_node_destroy( - &element_ptr->interactive_ptr->avlnode); - element_ptr->interactive_ptr = NULL; - } - - if (NULL != element_ptr->wlr_scene_buffer_ptr) { - wlr_scene_node_destroy(&element_ptr->wlr_scene_buffer_ptr->node); - element_ptr->wlr_scene_buffer_ptr = NULL; - } -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_element_set_position( - wlmaker_decorations_element_t *element_ptr, - int x, - int y) -{ - wlr_scene_node_set_position( - &element_ptr->wlr_scene_buffer_ptr->node, x, y); - if (NULL != element_ptr->margin_ptr) { - wlmaker_decorations_margin_set_position( - element_ptr->margin_ptr, x, y); - } -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_button_t *wlmaker_decorations_button_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_interactive_callback_t callback, - wlmaker_view_t *view_ptr, - struct wlr_buffer *button_released_ptr, - struct wlr_buffer *button_pressed_ptr, - struct wlr_buffer *button_blurred_ptr, - uint32_t edges) -{ - BS_ASSERT(button_released_ptr->width == button_pressed_ptr->width); - BS_ASSERT(button_released_ptr->width == button_blurred_ptr->width); - BS_ASSERT(button_released_ptr->height == button_pressed_ptr->height); - BS_ASSERT(button_released_ptr->height == button_blurred_ptr->height); - - wlmaker_decorations_button_t *button_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_button_t)); - if (NULL == button_ptr) return NULL; - if (!wlmaker_decorations_element_init( - &button_ptr->element, - wlr_scene_tree_ptr, - view_ptr, - button_released_ptr->width, - button_released_ptr->height, - edges)) { - wlmaker_decorations_button_destroy(button_ptr); - return NULL; - } - - button_ptr->element.interactive_ptr = wlmaker_button_create( - button_ptr->element.wlr_scene_buffer_ptr, - cursor_ptr, - callback, - view_ptr, - button_released_ptr, - button_pressed_ptr, - button_blurred_ptr); - if (NULL == button_ptr->element.interactive_ptr) { - wlmaker_decorations_button_destroy(button_ptr); - return NULL; - } - - wlmaker_interactive_focus( - button_ptr->element.interactive_ptr, - view_ptr->active); - - if (!bs_avltree_insert( - view_ptr->interactive_tree_ptr, - &button_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node, - &button_ptr->element.interactive_ptr->avlnode, - false)) { - bs_log(BS_ERROR, "Unexpected: Fail to insert into tree."); - wlmaker_decorations_button_destroy(button_ptr); - return NULL; - } - button_ptr->view_ptr = view_ptr; - - return button_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_button_destroy( - wlmaker_decorations_button_t *button_ptr) -{ - if (NULL != button_ptr->view_ptr) { - bs_avltree_delete( - button_ptr->view_ptr->interactive_tree_ptr, - &button_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node); - button_ptr->view_ptr = NULL; - } - - // The interactive is deleted in element_fini(). - - wlmaker_decorations_element_fini(&button_ptr->element); - free(button_ptr); -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_button( - wlmaker_decorations_button_t *button_ptr) -{ - return &button_ptr->element; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_button_set_textures( - wlmaker_decorations_button_t *button_ptr, - struct wlr_buffer *button_released_ptr, - struct wlr_buffer *button_pressed_ptr, - struct wlr_buffer *button_blurred_ptr) -{ - BS_ASSERT(button_released_ptr->width == button_pressed_ptr->width); - BS_ASSERT(button_released_ptr->width == button_blurred_ptr->width); - BS_ASSERT(button_released_ptr->height == button_pressed_ptr->height); - BS_ASSERT(button_released_ptr->height == button_blurred_ptr->height); - - wlmaker_button_set_textures( - button_ptr->element.interactive_ptr, - button_released_ptr, - button_pressed_ptr, - button_blurred_ptr); - - if (NULL != button_ptr->element.margin_ptr) { - wlmaker_decorations_margin_set_size( - button_ptr->element.margin_ptr, - button_released_ptr->width, - button_released_ptr->height); - } -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_title_t *wlmaker_decorations_title_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *title_buffer_ptr, - struct wlr_buffer *title_blurred_buffer_ptr) -{ - BS_ASSERT(title_buffer_ptr->width == title_blurred_buffer_ptr->width); - BS_ASSERT(title_buffer_ptr->height == title_blurred_buffer_ptr->height); - - wlmaker_decorations_title_t *title_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_title_t)); - if (NULL == title_ptr) return NULL; - if (!wlmaker_decorations_element_init( - &title_ptr->element, - wlr_scene_tree_ptr, - view_ptr, - title_buffer_ptr->width, - title_buffer_ptr->height, - WLR_EDGE_LEFT | WLR_EDGE_TOP | WLR_EDGE_RIGHT)) { - wlmaker_decorations_title_destroy(title_ptr); - return NULL; - } - - title_ptr->element.interactive_ptr = wlmaker_titlebar_create( - title_ptr->element.wlr_scene_buffer_ptr, - cursor_ptr, - view_ptr, - title_buffer_ptr, - title_blurred_buffer_ptr); - if (NULL == title_ptr->element.interactive_ptr) { - wlmaker_decorations_title_destroy(title_ptr); - return NULL; - } - - wlmaker_interactive_focus( - title_ptr->element.interactive_ptr, - view_ptr->active); - - if (!bs_avltree_insert( - view_ptr->interactive_tree_ptr, - &title_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node, - &title_ptr->element.interactive_ptr->avlnode, - false)) { - bs_log(BS_ERROR, "Unexpected: Fail to insert into tree."); - wlmaker_decorations_title_destroy(title_ptr); - return NULL; - } - title_ptr->view_ptr = view_ptr; - - return title_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_title_destroy( - wlmaker_decorations_title_t *title_ptr) -{ - if (NULL != title_ptr->view_ptr) { - bs_avltree_delete( - title_ptr->view_ptr->interactive_tree_ptr, - &title_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node); - title_ptr->view_ptr = NULL; - } - - // The interactive is deleted in element_fini(). - - wlmaker_decorations_element_fini(&title_ptr->element); - free(title_ptr); -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_title( - wlmaker_decorations_title_t *title_ptr) -{ - return &title_ptr->element; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_title_set_textures( - wlmaker_decorations_title_t *title_ptr, - struct wlr_buffer *title_buffer_ptr, - struct wlr_buffer *title_blurred_buffer_ptr) -{ - BS_ASSERT(title_buffer_ptr->width == title_blurred_buffer_ptr->width); - BS_ASSERT(title_buffer_ptr->height == title_blurred_buffer_ptr->height); - - wlmaker_title_set_texture( - title_ptr->element.interactive_ptr, - title_buffer_ptr, - title_blurred_buffer_ptr); - - if (NULL != title_ptr->element.margin_ptr) { - wlmaker_decorations_margin_set_size( - title_ptr->element.margin_ptr, - title_buffer_ptr->width, - title_buffer_ptr->height); - } -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_resize_t *wlmaker_decorations_resize_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *resize_buffer_ptr, - struct wlr_buffer *resize_pressed_buffer_ptr, - uint32_t edges) -{ - BS_ASSERT(resize_buffer_ptr->width == resize_pressed_buffer_ptr->width); - BS_ASSERT(resize_buffer_ptr->height == resize_pressed_buffer_ptr->height); - - wlmaker_decorations_resize_t *resize_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_resize_t)); - if (NULL == resize_ptr) return NULL; - if (!wlmaker_decorations_element_init( - &resize_ptr->element, - wlr_scene_tree_ptr, - view_ptr, - resize_buffer_ptr->width, - resize_buffer_ptr->height, - edges)) { - wlmaker_decorations_resize_destroy(resize_ptr); - return NULL; - } - - resize_ptr->element.interactive_ptr = wlmaker_resizebar_create( - resize_ptr->element.wlr_scene_buffer_ptr, - cursor_ptr, - view_ptr, - resize_buffer_ptr, - resize_pressed_buffer_ptr, - edges); - if (NULL == resize_ptr->element.interactive_ptr) { - wlmaker_decorations_resize_destroy(resize_ptr); - return NULL; - } - - if (!bs_avltree_insert( - view_ptr->interactive_tree_ptr, - &resize_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node, - &resize_ptr->element.interactive_ptr->avlnode, - false)) { - bs_log(BS_ERROR, "Unexpected: Fail to insert into tree."); - wlmaker_decorations_resize_destroy(resize_ptr); - return NULL; - } - resize_ptr->view_ptr = view_ptr; - - return resize_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_resize_destroy( - wlmaker_decorations_resize_t *resize_ptr) -{ - if (NULL != resize_ptr->view_ptr) { - bs_avltree_delete( - resize_ptr->view_ptr->interactive_tree_ptr, - &resize_ptr->element.interactive_ptr->wlr_scene_buffer_ptr->node); - resize_ptr->view_ptr = NULL; - } - - // The interactive is deleted in element_fini(). - - wlmaker_decorations_element_fini(&resize_ptr->element); - free(resize_ptr); -} - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_resize( - wlmaker_decorations_resize_t *resize_ptr) -{ - return &resize_ptr->element; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_resize_set_textures( - wlmaker_decorations_resize_t *resize_ptr, - struct wlr_buffer *resize_buffer_ptr, - struct wlr_buffer *resize_pressed_buffer_ptr) -{ - BS_ASSERT(resize_buffer_ptr->width == resize_pressed_buffer_ptr->width); - BS_ASSERT(resize_buffer_ptr->height == resize_pressed_buffer_ptr->height); - - wlmaker_resizebar_set_textures( - resize_ptr->element.interactive_ptr, - resize_buffer_ptr, - resize_pressed_buffer_ptr); - - if (NULL != resize_ptr->element.margin_ptr) { - wlmaker_decorations_margin_set_size( - resize_ptr->element.margin_ptr, - resize_buffer_ptr->width, - resize_buffer_ptr->height); - } -} - -/* == End of element.c ===================================================== */ diff --git a/src/decorations/element.h b/src/decorations/element.h deleted file mode 100644 index d1fd2676..00000000 --- a/src/decorations/element.h +++ /dev/null @@ -1,219 +0,0 @@ -/* ========================================================================= */ -/** - * @file element.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __ELEMENT_H__ -#define __ELEMENT_H__ - -#include "../view.h" - -#include "margin.h" - -#define WLR_USE_UNSTABLE -#include -#undef WLR_USE_UNSTABLE - -/** Forward declaration: Abstract base "class", the element. */ -typedef struct _wlmaker_decorations_element_t wlmaker_decorations_element_t; -/** Forward declaration: Button. */ -typedef struct _wlmaker_decorations_button_t wlmaker_decorations_button_t; -/** Forward declaration: Title. */ -typedef struct _wlmaker_decorations_title_t wlmaker_decorations_title_t; -/** Forward declaration: An element of the resize bar. */ -typedef struct _wlmaker_decorations_resize_t wlmaker_decorations_resize_t; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * Initializes the element. - * - * An element is a wrapper around an "interactive", and adds the scene graph - * node and optionally margins. On the long run, this should be unified with - * the interactive. - * - * @param element_ptr - * @param wlr_scene_tree_ptr The container's scene graph tree. - * @param data_ptr Data to set in the scene node's `data` field. - * @param width Of the element, used for adding margins. - * @param height Of the element, used for adding margins. - * @param edges Which edges to add as margins, or 0 for none. - */ -bool wlmaker_decorations_element_init( - wlmaker_decorations_element_t *element_ptr, - struct wlr_scene_tree *wlr_scene_tree_ptr, - void *data_ptr, - unsigned width, - unsigned height, - uint32_t edges); - -/** - * Releases all resources for the element. - * - * @param element_ptr - */ -void wlmaker_decorations_element_fini( - wlmaker_decorations_element_t *element_ptr); - -/** - * Sets position of the element, relative to the parent's scene graph tree. - * - * @param element_ptr - * @param x - * @param y - */ -void wlmaker_decorations_element_set_position( - wlmaker_decorations_element_t *element_ptr, - int x, - int y); - -/** - * Creates a button element, wrapping an "element" on the button interactive. - * - * @param wlr_scene_tree_ptr - * @param cursor_ptr - * @param callback - * @param view_ptr - * @param button_released_ptr - * @param button_pressed_ptr - * @param button_blurred_ptr - * @param edges - * - * @return A pointer to the button, or NULL on error. Must be free-d via - * @ref wlmaker_decorations_button_destroy. - */ -wlmaker_decorations_button_t *wlmaker_decorations_button_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_interactive_callback_t callback, - wlmaker_view_t *view_ptr, - struct wlr_buffer *button_released_ptr, - struct wlr_buffer *button_pressed_ptr, - struct wlr_buffer *button_blurred_ptr, - uint32_t edges); - -/** Destroys the button element. */ -void wlmaker_decorations_button_destroy( - wlmaker_decorations_button_t *button_ptr); - -/** Returns the base "element" for the button. */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_button( - wlmaker_decorations_button_t *button_ptr); - -/** - * Updates the textures used for the button. - * - * @param button_ptr - * @param button_released_ptr - * @param button_pressed_ptr - * @param button_blurred_ptr - */ -void wlmaker_decorations_button_set_textures( - wlmaker_decorations_button_t *button_ptr, - struct wlr_buffer *button_released_ptr, - struct wlr_buffer *button_pressed_ptr, - struct wlr_buffer *button_blurred_ptr); - -/** - * Creates a title element, wrapping an "element" on the titlebar interactive. - * - * @param wlr_scene_tree_ptr - * @param cursor_ptr - * @param view_ptr - * @param title_buffer_ptr - * @param title_blurred_buffer_ptr - * - * @return A pointer to the title, must be free-d via - * @ref wlmaker_decorations_title_destroy. - */ -wlmaker_decorations_title_t *wlmaker_decorations_title_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *title_buffer_ptr, - struct wlr_buffer *title_blurred_buffer_ptr); - -/** Destroys the title element. */ -void wlmaker_decorations_title_destroy( - wlmaker_decorations_title_t *title_ptr); - -/** Returns the base "element" for the title. */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_title( - wlmaker_decorations_title_t *title_ptr); - -/** - * Updates the textures used for the title. - * - * @param title_ptr - * @param title_buffer_ptr - * @param title_blurred_buffer_ptr - */ -void wlmaker_decorations_title_set_textures( - wlmaker_decorations_title_t *title_ptr, - struct wlr_buffer *title_buffer_ptr, - struct wlr_buffer *title_blurred_buffer_ptr); - -/** - * Creates a resizebar, wrapping an "element" on the resizebar interactive. - * - * @param wlr_scene_tree_ptr - * @param cursor_ptr - * @param view_ptr - * @param resize_buffer_ptr - * @param resize_pressed_buffer_ptr - * @param edges Edges controlled by this resizebar. Also used - * to deduce edges for the margins. - * - * @return A pointer to the resizebar, must be free-d via - * @ref wlmaker_decorations_resize_destroy. - */ -wlmaker_decorations_resize_t *wlmaker_decorations_resize_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *resize_buffer_ptr, - struct wlr_buffer *resize_pressed_buffer_ptr, - uint32_t edges); - -/** Destroys the resize element. */ -void wlmaker_decorations_resize_destroy( - wlmaker_decorations_resize_t *resize_ptr); - -/** Returns the base "element" for the resize. */ -wlmaker_decorations_element_t *wlmaker_decorations_element_from_resize( - wlmaker_decorations_resize_t *resize_ptr); - -/** - * Updates the textures used for the resize. - * - * @param resize_ptr - * @param resize_buffer_ptr - * @param resize_pressed_buffer_ptr - */ -void wlmaker_decorations_resize_set_textures( - wlmaker_decorations_resize_t *resize_ptr, - struct wlr_buffer *resize_buffer_ptr, - struct wlr_buffer *resize_pressed_buffer_ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __ELEMENT_H__ */ -/* == End of element.h ===================================================== */ diff --git a/src/decorations/margin.c b/src/decorations/margin.c deleted file mode 100644 index 593a492f..00000000 --- a/src/decorations/margin.c +++ /dev/null @@ -1,295 +0,0 @@ -/* ========================================================================= */ -/** - * @file margin.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "margin.h" - -#include "../config.h" - -#include - -/* == Declarations ========================================================= */ - -/** Handle for margin. */ -struct _wlmaker_decorations_margin_t { - /** Parent's WLR scene tree. */ - struct wlr_scene_tree *parent_wlr_scene_tree_ptr; - - /** Width of the element surrounded by the margin(s). */ - unsigned width; - /** Height of the surrounded element. */ - unsigned height; - /** X-coordinate of the top-left corner of the decorated area. */ - int x; - /** Y-coordinate of the top-left corner of the decorated area. */ - int y; - /** Which edges of the margin should be drawn. */ - uint32_t edges; - - /** Scene rectangle holding the left edge of the margin. If any. */ - struct wlr_scene_rect *left_rect_ptr; - /** Scene rectangle holding the top edge of the margin. If any. */ - struct wlr_scene_rect *top_rect_ptr; - /** Scene rectangle holding the right edge of the margin. If any. */ - struct wlr_scene_rect *right_rect_ptr; - /** Scene rectangle holding the bottom edge of the margin. If any. */ - struct wlr_scene_rect *bottom_rect_ptr; -}; - -static bool recreate_edges( - wlmaker_decorations_margin_t *margin_ptr, - uint32_t edges); -static struct wlr_scene_rect *create_rect( - struct wlr_scene_tree *decoration_wlr_scene_tree_ptr, - uint32_t color); -static void rect_set_size( - struct wlr_scene_rect *wlr_scene_rect_ptr, - unsigned width, - unsigned height); -static void rect_set_position( - struct wlr_scene_rect *wlr_scene_rect_ptr, - int x, - int y); - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_margin_t *wlmaker_decorations_margin_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - int x, int y, - unsigned width, unsigned height, - uint32_t edges) -{ - wlmaker_decorations_margin_t *margin_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_margin_t)); - if (NULL == margin_ptr) return NULL; - margin_ptr->parent_wlr_scene_tree_ptr = wlr_scene_tree_ptr; - - if (!recreate_edges(margin_ptr, edges)) { - wlmaker_decorations_margin_destroy(margin_ptr); - return NULL; - } - wlmaker_decorations_margin_set_position(margin_ptr, x, y); - wlmaker_decorations_margin_set_size(margin_ptr, width, height); - return margin_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_margin_destroy( - wlmaker_decorations_margin_t *margin_ptr) -{ - if (NULL != margin_ptr->bottom_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->bottom_rect_ptr->node); - margin_ptr->bottom_rect_ptr = NULL; - } - if (NULL != margin_ptr->right_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->right_rect_ptr->node); - margin_ptr->right_rect_ptr = NULL; - } - if (NULL != margin_ptr->top_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->top_rect_ptr->node); - margin_ptr->top_rect_ptr = NULL; - } - if (NULL != margin_ptr->left_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->left_rect_ptr->node); - margin_ptr->left_rect_ptr = NULL; - } - - free(margin_ptr); -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_margin_set_position( - wlmaker_decorations_margin_t *margin_ptr, - int x, - int y) -{ - unsigned margin_width = wlmaker_config_theme.window_margin_width; - - int hx = 0; - if (margin_ptr->edges & WLR_EDGE_LEFT) { - hx -= margin_width; - } - - rect_set_position(margin_ptr->left_rect_ptr, - x - margin_width, y); - rect_set_position(margin_ptr->top_rect_ptr, - x + hx, y - margin_width); - rect_set_position(margin_ptr->right_rect_ptr, - x + margin_ptr->width, y); - rect_set_position(margin_ptr->bottom_rect_ptr, - x + hx, y + margin_ptr->height); - - margin_ptr->x = x; - margin_ptr->y = y; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_margin_set_size( - wlmaker_decorations_margin_t *margin_ptr, - unsigned width, - unsigned height) -{ - unsigned margin_width = wlmaker_config_theme.window_margin_width; - - // Horizontal margin area will cover the "corner" area if both margins - // are set. - unsigned hwidth = width; - if (margin_ptr->edges & WLR_EDGE_LEFT) { - hwidth += wlmaker_config_theme.window_margin_width; - } - if (margin_ptr->edges & WLR_EDGE_RIGHT) { - hwidth += wlmaker_config_theme.window_margin_width; - } - rect_set_size(margin_ptr->left_rect_ptr, margin_width, height); - rect_set_size(margin_ptr->top_rect_ptr, hwidth, margin_width); - rect_set_size(margin_ptr->right_rect_ptr, margin_width, height); - rect_set_size(margin_ptr->bottom_rect_ptr, hwidth, margin_width); - - margin_ptr->width = width; - margin_ptr->height = height; - - // Need to update the position of the margins. - wlmaker_decorations_margin_set_position( - margin_ptr, margin_ptr->x, margin_ptr->y); - -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_margin_set_edges( - wlmaker_decorations_margin_t *margin_ptr, - uint32_t edges) -{ - BS_ASSERT(recreate_edges(margin_ptr, edges)); - wlmaker_decorations_margin_set_position( - margin_ptr, margin_ptr->x, margin_ptr->y); - wlmaker_decorations_margin_set_size( - margin_ptr, margin_ptr->width, margin_ptr->height); -} - -/* == Local (static) methods =============================================== */ - -/* ------------------------------------------------------------------------- */ -/** Re-creates the rectangles for the specified edges. */ -bool recreate_edges( - wlmaker_decorations_margin_t *margin_ptr, - uint32_t edges) -{ - uint32_t col = wlmaker_config_theme.window_margin_color; - struct wlr_scene_tree *wlr_scene_tree_ptr = - margin_ptr->parent_wlr_scene_tree_ptr; - - if (edges & WLR_EDGE_LEFT) { - margin_ptr->left_rect_ptr = create_rect(wlr_scene_tree_ptr, col); - if (NULL == margin_ptr->left_rect_ptr) return false; - } else if (NULL != margin_ptr->left_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->left_rect_ptr->node); - margin_ptr->left_rect_ptr = NULL; - } - - if (edges & WLR_EDGE_TOP) { - margin_ptr->top_rect_ptr = create_rect(wlr_scene_tree_ptr, col); - if (NULL == margin_ptr->top_rect_ptr) return false; - } else if (NULL != margin_ptr->top_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->top_rect_ptr->node); - margin_ptr->top_rect_ptr = NULL; - } - - if (edges & WLR_EDGE_RIGHT) { - margin_ptr->right_rect_ptr = create_rect(wlr_scene_tree_ptr, col); - if (NULL == margin_ptr->right_rect_ptr) return false; - } else if (NULL != margin_ptr->right_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->right_rect_ptr->node); - margin_ptr->right_rect_ptr = NULL; - } - - if (edges & WLR_EDGE_BOTTOM) { - margin_ptr->bottom_rect_ptr = create_rect(wlr_scene_tree_ptr, col); - if (NULL == margin_ptr->bottom_rect_ptr) return false; - } else if (NULL != margin_ptr->bottom_rect_ptr) { - wlr_scene_node_destroy(&margin_ptr->bottom_rect_ptr->node); - margin_ptr->bottom_rect_ptr = NULL; - } - margin_ptr->edges = edges; - return true; -} -/* ------------------------------------------------------------------------- */ -/** - * Helper: Creates a `wlr_scene_rect` with the given `color`. - * - * The rectangle will not be set to correct size nor position. Use - * @ref rect_set_size and @ref rect_set_position for that. - * - * @param decoration_wlr_scene_tree_ptr - * @param color As an ARGB8888 32-bit value. - */ -struct wlr_scene_rect *create_rect( - struct wlr_scene_tree *decoration_wlr_scene_tree_ptr, uint32_t color) -{ - float fcolor[4]; - bs_gfxbuf_argb8888_to_floats( - color, &fcolor[0], &fcolor[1], &fcolor[2], &fcolor[3]); - struct wlr_scene_rect *wlr_scene_rect_ptr = wlr_scene_rect_create( - decoration_wlr_scene_tree_ptr, 1, 1, fcolor); - if (NULL == wlr_scene_rect_ptr) { - bs_log(BS_ERROR, "Failed wlr_scene_rect_create(%p, 1, 1, %"PRIx32")", - decoration_wlr_scene_tree_ptr, color); - return NULL; - } - wlr_scene_node_set_enabled(&wlr_scene_rect_ptr->node, true); - return wlr_scene_rect_ptr; -} - -/* ------------------------------------------------------------------------- */ -/** - * Helper: Updates dimensions of the `wlr_scene_rect`. - * - * @param wlr_scene_rect_ptr The rectangle to update. May be NULL. - * @param width - * @param height - */ -static void rect_set_size( - struct wlr_scene_rect *wlr_scene_rect_ptr, - unsigned width, - unsigned height) -{ - if (NULL == wlr_scene_rect_ptr) return; - wlr_scene_rect_set_size( - wlr_scene_rect_ptr, width, height); -} - -/* ------------------------------------------------------------------------- */ -/** - * Helper: Updates position of the `wlr_scene_rect`. - * - * @param wlr_scene_rect_ptr The rectangle to update. May be NULL. - * @param x Position relative to the decorated window. - * @param y - */ -static void rect_set_position( - struct wlr_scene_rect *wlr_scene_rect_ptr, - int x, - int y) -{ - if (NULL == wlr_scene_rect_ptr) return; - wlr_scene_node_set_position( - &wlr_scene_rect_ptr->node, x, y); -} - -/* == End of margin.c ====================================================== */ diff --git a/src/decorations/margin.h b/src/decorations/margin.h deleted file mode 100644 index 8cc64564..00000000 --- a/src/decorations/margin.h +++ /dev/null @@ -1,94 +0,0 @@ -/* ========================================================================= */ -/** - * @file margin.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __MARGIN_H__ -#define __MARGIN_H__ - -#include - -#include - -#define WLR_USE_UNSTABLE -#include -#undef WLR_USE_UNSTABLE - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** Forward definition: Handle for margin. */ -typedef struct _wlmaker_decorations_margin_t wlmaker_decorations_margin_t; - -/** Creates margin. */ -wlmaker_decorations_margin_t *wlmaker_decorations_margin_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - int x, int y, - unsigned width, unsigned height, - uint32_t edges); - -/** Destroys margin. */ -void wlmaker_decorations_margin_destroy( - wlmaker_decorations_margin_t *margin_ptr); - -/** - * Sets the position of the margins. - * - * The given (x, y) coordinates are defining the top-left corner of the - * decorated area, not including the margin itself. - * - * @param margin_ptr - * @param x - * @param y - */ -void wlmaker_decorations_margin_set_position( - wlmaker_decorations_margin_t *margin_ptr, - int x, - int y); - -/** - * Resizes the margins. - * - * `width` and `height` are describing the dimensions of the decorated element, - * excluding the added dimensions of the margin. - * - * @param margin_ptr - * @param width - * @param height - */ -void wlmaker_decorations_margin_set_size( - wlmaker_decorations_margin_t *margin_ptr, - unsigned width, - unsigned height); - -/** - * (re)configures which edges to show for the margin. - * - * @param margin_ptr - * @param edges - */ -void wlmaker_decorations_margin_set_edges( - wlmaker_decorations_margin_t *margin_ptr, - uint32_t edges); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __MARGIN_H__ */ -/* == End of margin.h ====================================================== */ diff --git a/src/decorations/resizebar.c b/src/decorations/resizebar.c deleted file mode 100644 index 0a630763..00000000 --- a/src/decorations/resizebar.c +++ /dev/null @@ -1,312 +0,0 @@ -/* ========================================================================= */ -/** - * @file resizebar.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "resizebar.h" - -#include "element.h" -#include "../config.h" -#include "../resizebar.h" - -/* == Declarations ========================================================= */ - -/** State of a window's resize bar. */ -struct _wlmaker_decorations_resizebar_t { - /** Back-link to the view it decorates. */ - wlmaker_view_t *view_ptr; - - /** Scene tree, for just the resize bar elements and margin. */ - struct wlr_scene_tree *wlr_scene_tree_ptr; - - /** Left element of the resize bar, or NULL if not set. */ - wlmaker_decorations_resize_t *left_resize_ptr; - /** Center element of the resize bar, or NULL if not set. */ - wlmaker_decorations_resize_t *center_resize_ptr; - /** Right element of the resize bar. */ - wlmaker_decorations_resize_t *right_resize_ptr; - - /** Width of the left element, or 0 if not set. */ - unsigned left_width; - /** Width of the center element, or 0 if not set. */ - unsigned center_width; - /** Width of the right element. */ - unsigned right_width; - - /** Overall width of the decorated window. */ - unsigned width; - /** Height of the decorated window. */ - unsigned height; -}; - -/** Hardcoded: Width of bezel. */ -static const uint32_t bezel_width = 1; -/** Hardcoded: Height of the resize bar. */ -static const uint32_t resizebar_height = 7; -/** Hardcoded: Width of the corner elements of the resize bar. */ -static const uint32_t resizebar_corner_width = 29; - -static void set_width( - wlmaker_decorations_resizebar_t *resizebar_ptr, - unsigned width); -static bs_gfxbuf_t *create_background(unsigned width); -static void create_or_update_resize( - wlmaker_decorations_resizebar_t *resizebar_ptr, - wlmaker_decorations_resize_t **resize_ptr_ptr, - bs_gfxbuf_t *background_gfxbuf_ptr, - int pos, unsigned width, - uint32_t edges); - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_resizebar_t *wlmaker_decorations_resizebar_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - unsigned width, - unsigned height, - wlmaker_view_t *view_ptr) -{ - wlmaker_decorations_resizebar_t *resizebar_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_resizebar_t)); - if (NULL == resizebar_ptr) return NULL; - resizebar_ptr->view_ptr = view_ptr; - - resizebar_ptr->wlr_scene_tree_ptr = wlr_scene_tree_create( - wlr_scene_tree_ptr); - if (NULL == resizebar_ptr->wlr_scene_tree_ptr) { - wlmaker_decorations_resizebar_destroy(resizebar_ptr); - return NULL; - } - wlr_scene_node_set_position( - &resizebar_ptr->wlr_scene_tree_ptr->node, - 0, height + wlmaker_config_theme.window_margin_width); - - wlmaker_decorations_resizebar_set_size(resizebar_ptr, width, height); - return resizebar_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_resizebar_destroy( - wlmaker_decorations_resizebar_t *resizebar_ptr) -{ - if (NULL != resizebar_ptr->right_resize_ptr) { - wlmaker_decorations_resize_destroy(resizebar_ptr->right_resize_ptr); - resizebar_ptr->right_resize_ptr = NULL; - } - if (NULL != resizebar_ptr->center_resize_ptr) { - wlmaker_decorations_resize_destroy(resizebar_ptr->center_resize_ptr); - resizebar_ptr->center_resize_ptr = NULL; - } - if (NULL != resizebar_ptr->left_resize_ptr) { - wlmaker_decorations_resize_destroy(resizebar_ptr->left_resize_ptr); - resizebar_ptr->left_resize_ptr = NULL; - } - - if (NULL != resizebar_ptr->wlr_scene_tree_ptr) { - wlr_scene_node_destroy(&resizebar_ptr->wlr_scene_tree_ptr->node); - resizebar_ptr->wlr_scene_tree_ptr = NULL; - } - - free(resizebar_ptr); -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_resizebar_set_size( - wlmaker_decorations_resizebar_t *resizebar_ptr, - unsigned width, - unsigned height) -{ - if (width == resizebar_ptr->width && - height == resizebar_ptr->height) return; - set_width(resizebar_ptr, width); - - wlr_scene_node_set_position( - &resizebar_ptr->wlr_scene_tree_ptr->node, - 0, height + wlmaker_config_theme.window_margin_width); - - unsigned bar_y = 0; - - if (0 < resizebar_ptr->left_width) { - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_resize( - resizebar_ptr->left_resize_ptr), - 0, bar_y); - } - - if (0 < resizebar_ptr->center_width) { - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_resize( - resizebar_ptr->center_resize_ptr), - resizebar_ptr->left_width, bar_y); - } - - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_resize( - resizebar_ptr->right_resize_ptr), - width - resizebar_ptr->right_width, bar_y); - - resizebar_ptr->height = height; - return; -} - -/* ------------------------------------------------------------------------- */ -unsigned wlmaker_decorations_resizebar_get_height( - __UNUSED__ wlmaker_decorations_resizebar_t *resizebar_ptr) -{ - return resizebar_height + wlmaker_config_theme.window_margin_width; -} - -/* == Local (static) methods =============================================== */ - -/* ------------------------------------------------------------------------- */ -/** Applies the width to the resizebar, re-creating elements if needed. */ -static void set_width( - wlmaker_decorations_resizebar_t *resizebar_ptr, - unsigned width) -{ - if (width == resizebar_ptr->width) return; - - resizebar_ptr->left_width = resizebar_corner_width; - resizebar_ptr->right_width = resizebar_corner_width; - if (width > 2 * resizebar_corner_width) { - resizebar_ptr->center_width = width - 2 * resizebar_corner_width; - } else if (width > resizebar_corner_width) { - resizebar_ptr->center_width = 0; - resizebar_ptr->left_width = width - resizebar_corner_width; - } else { - resizebar_ptr->left_width = 0; - resizebar_ptr->right_width = width; - } - - BS_ASSERT(resizebar_ptr->left_width + - resizebar_ptr->right_width + - resizebar_ptr->center_width == width); - - bs_gfxbuf_t *gfxbuf_ptr = create_background(width); - BS_ASSERT(NULL != gfxbuf_ptr); - - if (0 < resizebar_ptr->left_width) { - create_or_update_resize( - resizebar_ptr, - &resizebar_ptr->left_resize_ptr, - gfxbuf_ptr, - 0, resizebar_ptr->left_width, - WLR_EDGE_LEFT | WLR_EDGE_BOTTOM); - } else if (NULL != resizebar_ptr->left_resize_ptr) { - wlmaker_decorations_resize_destroy(resizebar_ptr->left_resize_ptr); - resizebar_ptr->left_resize_ptr = NULL; - } - - if (0 < resizebar_ptr->center_width) { - create_or_update_resize( - resizebar_ptr, - &resizebar_ptr->center_resize_ptr, - gfxbuf_ptr, - resizebar_ptr->left_width, resizebar_ptr->center_width, - WLR_EDGE_BOTTOM); - } else if (NULL != resizebar_ptr->center_resize_ptr) { - wlmaker_decorations_resize_destroy(resizebar_ptr->center_resize_ptr); - resizebar_ptr->center_resize_ptr = NULL; - } - - create_or_update_resize( - resizebar_ptr, - &resizebar_ptr->right_resize_ptr, - gfxbuf_ptr, - width - resizebar_ptr->right_width, resizebar_ptr->right_width, - WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM); - - bs_gfxbuf_destroy(gfxbuf_ptr); - resizebar_ptr->width = width; -} - -/* ------------------------------------------------------------------------- */ -/** Creates the background texture at givenm width. */ -bs_gfxbuf_t *create_background(unsigned width) -{ - bs_gfxbuf_t *gfxbuf_ptr = bs_gfxbuf_create(width, resizebar_height); - if (NULL == gfxbuf_ptr) return NULL; - - cairo_t *cairo_ptr = cairo_create_from_bs_gfxbuf(gfxbuf_ptr); - if (NULL == cairo_ptr) { - bs_gfxbuf_destroy(gfxbuf_ptr); - return false; - } - wlmaker_primitives_cairo_fill( - cairo_ptr, &wlmaker_config_theme.resizebar_fill); - cairo_destroy(cairo_ptr); - - return gfxbuf_ptr; -} - -/* ------------------------------------------------------------------------- */ -/** Creates or updates a resizebar element. */ -void create_or_update_resize( - wlmaker_decorations_resizebar_t *resizebar_ptr, - wlmaker_decorations_resize_t **resize_ptr_ptr, - bs_gfxbuf_t *background_gfxbuf_ptr, - int pos, unsigned width, - uint32_t edges) -{ - cairo_t *cairo_ptr; - - struct wlr_buffer *released_wlrbuf_ptr = bs_gfxbuf_create_wlr_buffer( - width, resizebar_height); - BS_ASSERT(NULL != released_wlrbuf_ptr); - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(released_wlrbuf_ptr), 0, 0, - background_gfxbuf_ptr, pos, 0, - width, resizebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(released_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel(cairo_ptr, bezel_width, true); - cairo_destroy(cairo_ptr); - - struct wlr_buffer *pressed_wlrbuf_ptr = bs_gfxbuf_create_wlr_buffer( - width, resizebar_height); - BS_ASSERT(NULL != released_wlrbuf_ptr); - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(pressed_wlrbuf_ptr), 0, 0, - background_gfxbuf_ptr, pos, 0, - width, resizebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(pressed_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel(cairo_ptr, bezel_width, false); - cairo_destroy(cairo_ptr); - - if (NULL == *resize_ptr_ptr) { - *resize_ptr_ptr = wlmaker_decorations_resize_create( - resizebar_ptr->wlr_scene_tree_ptr, - resizebar_ptr->view_ptr->server_ptr->cursor_ptr, - resizebar_ptr->view_ptr, - released_wlrbuf_ptr, - pressed_wlrbuf_ptr, - edges); - BS_ASSERT(NULL != *resize_ptr_ptr); - } else { - wlmaker_decorations_resize_set_textures( - *resize_ptr_ptr, - released_wlrbuf_ptr, - pressed_wlrbuf_ptr); - } - - wlr_buffer_drop(pressed_wlrbuf_ptr); - wlr_buffer_drop(released_wlrbuf_ptr); -} - -/* == End of resizebar.c =================================================== */ diff --git a/src/decorations/resizebar.h b/src/decorations/resizebar.h deleted file mode 100644 index 47174dd2..00000000 --- a/src/decorations/resizebar.h +++ /dev/null @@ -1,86 +0,0 @@ -/* ========================================================================= */ -/** - * @file resizebar.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __RESIZEBAR_H__ -#define __RESIZEBAR_H__ - -#define WLR_USE_UNSTABLE -#include -#undef WLR_USE_UNSTABLE - -#include "../view.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** Forward declaration: Resizebar of window decoration. */ -typedef struct _wlmaker_decorations_resizebar_t wlmaker_decorations_resizebar_t; - -/** - * Creates the title bar for window decoration. - * - * @param wlr_scene_tree_ptr - * @param width - * @param height - * @param view_ptr - * - * @return A resizebar handle, or NULL on error. Must be free-d by calling - * @ref wlmaker_decorations_resizebar_destroy. - */ -wlmaker_decorations_resizebar_t *wlmaker_decorations_resizebar_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - unsigned width, - unsigned height, - wlmaker_view_t *view_ptr); - -/** - * Destroys a window decoration resize bar. - * - * @param resizebar_ptr - */ -void wlmaker_decorations_resizebar_destroy( - wlmaker_decorations_resizebar_t *resizebar_ptr); - -/** - * Sets the width of the resizebar. - * - * @param resizebar_ptr - * @param width - * @param height - */ -void wlmaker_decorations_resizebar_set_size( - wlmaker_decorations_resizebar_t *resizebar_ptr, - unsigned width, - unsigned height); - -/** - * Returns the height of the resizebar. Includes the bottom margin. - * - * @param resizebar_ptr - */ -unsigned wlmaker_decorations_resizebar_get_height( - wlmaker_decorations_resizebar_t *resizebar_ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __RESIZEBAR_H__ */ -/* == End of resizebar.h =================================================== */ diff --git a/src/decorations/titlebar.c b/src/decorations/titlebar.c deleted file mode 100644 index e0ae949e..00000000 --- a/src/decorations/titlebar.c +++ /dev/null @@ -1,634 +0,0 @@ -/* ========================================================================= */ -/** - * @file titlebar.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "titlebar.h" - -#include - -#include "element.h" -#include "../config.h" -#include "toolkit/toolkit.h" - -/* == Declarations ========================================================= */ - -/** State of a window's titlebar, including buttons and title area. */ -struct _wlmaker_decorations_titlebar_t { - /** Back-link to the view it decorates. */ - wlmaker_view_t *view_ptr; - - /** Scene tree, for just the title bar elements and margin. */ - struct wlr_scene_tree *wlr_scene_tree_ptr; - - /** "Minimize" button element. */ - wlmaker_decorations_button_t *minimize_button_ptr; - /** "Close" button element. */ - wlmaker_decorations_button_t *close_button_ptr; - /** "Title" element. */ - wlmaker_decorations_title_t *title_ptr; - - /** Background graphics buffer, focussed window. */ - bs_gfxbuf_t *background_focussed_gfxbuf_ptr; - /** Background graphics buffer, blurred window. */ - bs_gfxbuf_t *background_blurred_gfxbuf_ptr; - - /** Currently configured width, excluding the outer margins. */ - unsigned width; - /** Position of the title element, relative to the scene tree. */ - int title_pos; - /** Width of the title element. */ - unsigned title_width; - /** Position of the "close" button, relative to the scene tree. */ - int close_pos; -}; - -/** Holder for a few `struct wlr_buffer` textures, for buttons & title. */ -typedef struct { - /** Texture in released state. */ - struct wlr_buffer *released_wlrbuf_ptr; - /** Texture in pressed state, or NULL. */ - struct wlr_buffer *pressed_wlrbuf_ptr; - /** Texture in blurred state. */ - struct wlr_buffer *blurred_wlrbuf_ptr; -} wlr_buffer_holder_t; - -static bool recreate_backgrounds( - wlmaker_decorations_titlebar_t *titlebar_ptr, - unsigned width); - -static bool create_wlr_buffers( - wlr_buffer_holder_t *buffer_holder_ptr, - unsigned width, - bool press); -static void drop_wlr_buffers(wlr_buffer_holder_t *buffer_holder_ptr); - -static void create_or_update_minimize_button( - wlmaker_decorations_titlebar_t *titlebar_ptr); -static void create_or_update_close_button( - wlmaker_decorations_titlebar_t *titlebar_ptr); -static void create_or_update_title( - wlmaker_decorations_titlebar_t *titlebar_ptr); - -static void button_minimize_callback( - wlmaker_interactive_t *interactive_ptr, - void *data_ptr); -static void button_close_callback( - wlmaker_interactive_t *interactive_ptr, - void *data_ptr); - -/** Hardcoded: Width of the window buttons. */ -static const unsigned wlmaker_decorations_button_width = 22; -/** Hardcoded: Height of the title bar, in pixels. */ -static const unsigned wlmaker_decorations_titlebar_height = 22; - -/** Hardcoded: Width of the bezel for buttons. */ -static const unsigned wlmaker_decorations_button_bezel_width = 1; - -/** - * Attempted minimal width of the title. If the title width falls below that - * value, buttons will be dropped instead. - */ -static const unsigned title_min_width = wlmaker_decorations_button_width; - -/* == Exported methods ===================================================== */ - - -/* ------------------------------------------------------------------------- */ -wlmaker_decorations_titlebar_t *wlmaker_decorations_titlebar_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - unsigned width, - wlmaker_view_t *view_ptr) -{ - wlmaker_decorations_titlebar_t *titlebar_ptr = logged_calloc( - 1, sizeof(wlmaker_decorations_titlebar_t)); - if (NULL == titlebar_ptr) return NULL; - titlebar_ptr->view_ptr = view_ptr; - - titlebar_ptr->wlr_scene_tree_ptr = wlr_scene_tree_create( - wlr_scene_tree_ptr); - if (NULL == titlebar_ptr->wlr_scene_tree_ptr) { - wlmaker_decorations_titlebar_destroy(titlebar_ptr); - return NULL; - } - wlr_scene_node_set_position( - &titlebar_ptr->wlr_scene_tree_ptr->node, - 0, - wlmaker_decorations_titlebar_height - - wlmaker_config_theme.window_margin_width); - - wlmaker_decorations_titlebar_set_width(titlebar_ptr, width); - return titlebar_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_titlebar_destroy( - wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - if (NULL != titlebar_ptr->title_ptr) { - wlmaker_decorations_title_destroy(titlebar_ptr->title_ptr); - titlebar_ptr->title_ptr = NULL; - } - - if (NULL != titlebar_ptr->close_button_ptr) { - wlmaker_decorations_button_destroy(titlebar_ptr->close_button_ptr); - titlebar_ptr->close_button_ptr = NULL; - } - - if (NULL != titlebar_ptr->minimize_button_ptr) { - wlmaker_decorations_button_destroy(titlebar_ptr->minimize_button_ptr); - titlebar_ptr->minimize_button_ptr = NULL; - } - - if (NULL != titlebar_ptr->background_focussed_gfxbuf_ptr) { - bs_gfxbuf_destroy(titlebar_ptr->background_focussed_gfxbuf_ptr); - titlebar_ptr->background_focussed_gfxbuf_ptr = NULL; - } - if (NULL != titlebar_ptr->background_blurred_gfxbuf_ptr) { - bs_gfxbuf_destroy(titlebar_ptr->background_blurred_gfxbuf_ptr); - titlebar_ptr->background_blurred_gfxbuf_ptr = NULL; - } - - if (NULL != titlebar_ptr->wlr_scene_tree_ptr) { - wlr_scene_node_destroy(&titlebar_ptr->wlr_scene_tree_ptr->node); - titlebar_ptr->wlr_scene_tree_ptr = NULL; - } - - free(titlebar_ptr); -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_titlebar_set_width( - wlmaker_decorations_titlebar_t *titlebar_ptr, - unsigned width) -{ - bool has_close, has_minimize; - - if (width == titlebar_ptr->width) return; - - // The 'minimize' button is shown only if there's space for everything. - if (width > title_min_width + - 2 * wlmaker_decorations_button_width + - 2 * wlmaker_config_theme.window_margin_width) { - titlebar_ptr->title_pos = - wlmaker_decorations_button_width + - wlmaker_config_theme.window_margin_width; - has_minimize = true; - } else { - has_minimize = false; - titlebar_ptr->title_pos = 0; - } - - // The 'close' button is shown as long as there's space for title and - // one button, at least. - if (width > title_min_width + - wlmaker_decorations_button_width + - wlmaker_config_theme.window_margin_width) { - titlebar_ptr->close_pos = - width - wlmaker_decorations_button_width; - has_close = true; - } else { - // Won't be shown, but simplifies computation... - titlebar_ptr->close_pos = - width + wlmaker_config_theme.window_margin_width; - has_close = false; - } - - BS_ASSERT( - titlebar_ptr->close_pos >= - (int)wlmaker_config_theme.window_margin_width + titlebar_ptr->title_pos); - titlebar_ptr->title_width = - titlebar_ptr->close_pos - wlmaker_config_theme.window_margin_width - - titlebar_ptr->title_pos; - titlebar_ptr->width = width; - - BS_ASSERT(recreate_backgrounds(titlebar_ptr, width)); - - if (has_minimize) { - create_or_update_minimize_button(titlebar_ptr); - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_button( - titlebar_ptr->minimize_button_ptr), - 0, 0); - } else if (NULL != titlebar_ptr->minimize_button_ptr) { - wlmaker_decorations_button_destroy(titlebar_ptr->minimize_button_ptr); - titlebar_ptr->minimize_button_ptr = NULL; - } - - create_or_update_title(titlebar_ptr); - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_title(titlebar_ptr->title_ptr), - titlebar_ptr->title_pos, 0); - - if (has_close) { - create_or_update_close_button(titlebar_ptr); - wlmaker_decorations_element_set_position( - wlmaker_decorations_element_from_button( - titlebar_ptr->close_button_ptr), - titlebar_ptr->close_pos, 0); - } else if (NULL != titlebar_ptr->close_button_ptr) { - wlmaker_decorations_button_destroy(titlebar_ptr->close_button_ptr); - titlebar_ptr->close_button_ptr = NULL; - } - - titlebar_ptr->width = width; -} - -/* ------------------------------------------------------------------------- */ -unsigned wlmaker_decorations_titlebar_get_height( - __UNUSED__ wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - return wlmaker_decorations_titlebar_height + - wlmaker_config_theme.window_margin_width; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_decorations_titlebar_update_title( - wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - create_or_update_title(titlebar_ptr); -} - -/* == Local (static) methods =============================================== */ - -/** - * (Re)creates the backgrounds for the title bar. - * - * @param titlebar_ptr - * @param width - * - * @return true on success. - */ -static bool recreate_backgrounds( - wlmaker_decorations_titlebar_t *titlebar_ptr, - unsigned width) -{ - bs_gfxbuf_t *focussed_ptr, *blurred_ptr; - cairo_t *cairo_ptr; - - focussed_ptr = bs_gfxbuf_create( - width, wlmaker_decorations_titlebar_height); - if (NULL == focussed_ptr) return false; - cairo_ptr = cairo_create_from_bs_gfxbuf(focussed_ptr); - if (NULL == cairo_ptr) { - bs_gfxbuf_destroy(focussed_ptr); - return false; - } - wlmaker_primitives_cairo_fill( - cairo_ptr, - &wlmaker_config_theme.titlebar_focussed_fill); - cairo_destroy(cairo_ptr); - - blurred_ptr = bs_gfxbuf_create( - width, wlmaker_decorations_titlebar_height); - if (NULL == blurred_ptr) { - bs_gfxbuf_destroy(focussed_ptr); - return false; - } - cairo_ptr = cairo_create_from_bs_gfxbuf(blurred_ptr); - if (NULL == cairo_ptr) { - bs_gfxbuf_destroy(focussed_ptr); - bs_gfxbuf_destroy(blurred_ptr); - return false; - } - wlmaker_primitives_cairo_fill( - cairo_ptr, - &wlmaker_config_theme.titlebar_blurred_fill); - cairo_destroy(cairo_ptr); - - if (NULL != titlebar_ptr->background_focussed_gfxbuf_ptr) { - bs_gfxbuf_destroy(titlebar_ptr->background_focussed_gfxbuf_ptr); - } - titlebar_ptr->background_focussed_gfxbuf_ptr = focussed_ptr; - if (NULL != titlebar_ptr->background_blurred_gfxbuf_ptr) { - bs_gfxbuf_destroy(titlebar_ptr->background_blurred_gfxbuf_ptr); - } - titlebar_ptr->background_blurred_gfxbuf_ptr = blurred_ptr; - - return true; -} - -/* ------------------------------------------------------------------------- */ -/** Creates WLR buffers of `buffer_holder_ptr`. */ -bool create_wlr_buffers( - wlr_buffer_holder_t *buffer_holder_ptr, - unsigned width, - bool press) -{ - memset(buffer_holder_ptr, 0, sizeof(wlr_buffer_holder_t)); - - buffer_holder_ptr->released_wlrbuf_ptr = bs_gfxbuf_create_wlr_buffer( - width, wlmaker_decorations_titlebar_height); - if (NULL == buffer_holder_ptr->released_wlrbuf_ptr) { - drop_wlr_buffers(buffer_holder_ptr); - return false; - } - - if (press) { - buffer_holder_ptr->pressed_wlrbuf_ptr = bs_gfxbuf_create_wlr_buffer( - width, wlmaker_decorations_titlebar_height); - if (NULL == buffer_holder_ptr->pressed_wlrbuf_ptr) { - drop_wlr_buffers(buffer_holder_ptr); - return false; - } - } - - buffer_holder_ptr->blurred_wlrbuf_ptr = bs_gfxbuf_create_wlr_buffer( - width, wlmaker_decorations_titlebar_height); - if (NULL == buffer_holder_ptr->blurred_wlrbuf_ptr) { - drop_wlr_buffers(buffer_holder_ptr); - return false; - } - - return true; -} - -/* ------------------------------------------------------------------------- */ -/** Drops the WLR buffers of `buffer_holder_ptr`. */ -void drop_wlr_buffers(wlr_buffer_holder_t *buffer_holder_ptr) -{ - if (NULL != buffer_holder_ptr->blurred_wlrbuf_ptr) { - wlr_buffer_drop(buffer_holder_ptr->blurred_wlrbuf_ptr); - buffer_holder_ptr->blurred_wlrbuf_ptr = NULL; - } - - if (NULL != buffer_holder_ptr->pressed_wlrbuf_ptr) { - wlr_buffer_drop(buffer_holder_ptr->pressed_wlrbuf_ptr); - buffer_holder_ptr->pressed_wlrbuf_ptr = NULL; - } - - if (NULL != buffer_holder_ptr->released_wlrbuf_ptr) { - wlr_buffer_drop(buffer_holder_ptr->released_wlrbuf_ptr); - buffer_holder_ptr->released_wlrbuf_ptr = NULL; - } -} - -/* ------------------------------------------------------------------------- */ -/** - * Creates (or updates) the "Minimize" button and textures. - * - * @param titlebar_ptr - */ -void create_or_update_minimize_button( - wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - cairo_t *cairo_ptr; - wlr_buffer_holder_t buf_holder; - - BS_ASSERT(create_wlr_buffers( - &buf_holder, wlmaker_decorations_button_width, true)); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.released_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_focussed_gfxbuf_ptr, - 0, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.released_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_minimize_icon( - cairo_ptr, wlmaker_config_theme.titlebar_focussed_text_color); - cairo_destroy(cairo_ptr); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.pressed_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_focussed_gfxbuf_ptr, - 0, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.pressed_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, false); - wlmaker_primitives_draw_minimize_icon( - cairo_ptr, wlmaker_config_theme.titlebar_focussed_text_color); - cairo_destroy(cairo_ptr); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_blurred_gfxbuf_ptr, - 0, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_minimize_icon( - cairo_ptr, wlmaker_config_theme.titlebar_blurred_text_color); - cairo_destroy(cairo_ptr); - - if (NULL == titlebar_ptr->minimize_button_ptr) { - titlebar_ptr->minimize_button_ptr = wlmaker_decorations_button_create( - titlebar_ptr->wlr_scene_tree_ptr, - titlebar_ptr->view_ptr->server_ptr->cursor_ptr, - button_minimize_callback, - titlebar_ptr->view_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.pressed_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr, - WLR_EDGE_LEFT | WLR_EDGE_TOP); - BS_ASSERT(NULL != titlebar_ptr->minimize_button_ptr); - } else { - wlmaker_decorations_button_set_textures( - titlebar_ptr->minimize_button_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.pressed_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr); - } - - drop_wlr_buffers(&buf_holder); -} - -/* ------------------------------------------------------------------------- */ -/** - * Creates (or updates) the "Close" button and textures. - * - * @param titlebar_ptr - */ -void create_or_update_close_button( - wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - cairo_t *cairo_ptr; - wlr_buffer_holder_t buf_holder; - - BS_ASSERT(create_wlr_buffers( - &buf_holder, wlmaker_decorations_button_width, true)); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.released_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_focussed_gfxbuf_ptr, - titlebar_ptr->close_pos, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.released_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_close_icon( - cairo_ptr, wlmaker_config_theme.titlebar_focussed_text_color); - cairo_destroy(cairo_ptr); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.pressed_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_focussed_gfxbuf_ptr, - titlebar_ptr->close_pos, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.pressed_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, false); - wlmaker_primitives_draw_close_icon( - cairo_ptr, wlmaker_config_theme.titlebar_focussed_text_color); - cairo_destroy(cairo_ptr); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_blurred_gfxbuf_ptr, - titlebar_ptr->close_pos, 0, - wlmaker_decorations_button_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_close_icon( - cairo_ptr, wlmaker_config_theme.titlebar_blurred_text_color); - cairo_destroy(cairo_ptr); - - if (NULL == titlebar_ptr->close_button_ptr) { - titlebar_ptr->close_button_ptr = wlmaker_decorations_button_create( - titlebar_ptr->wlr_scene_tree_ptr, - titlebar_ptr->view_ptr->server_ptr->cursor_ptr, - button_close_callback, - titlebar_ptr->view_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.pressed_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr, - WLR_EDGE_RIGHT | WLR_EDGE_TOP); - BS_ASSERT(NULL != titlebar_ptr->close_button_ptr); - } else { - wlmaker_decorations_button_set_textures( - titlebar_ptr->close_button_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.pressed_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr); - } - - drop_wlr_buffers(&buf_holder); -} - -/* ------------------------------------------------------------------------- */ -/** - * Creates (or updates) the title element and textures of the title bar. - * - * @param titlebar_ptr - */ -void create_or_update_title(wlmaker_decorations_titlebar_t *titlebar_ptr) -{ - cairo_t *cairo_ptr; - wlr_buffer_holder_t buf_holder; - - BS_ASSERT(create_wlr_buffers( - &buf_holder, titlebar_ptr->title_width, false)); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.released_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_focussed_gfxbuf_ptr, - titlebar_ptr->title_pos, 0, - titlebar_ptr->title_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.released_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_window_title( - cairo_ptr, - wlmaker_view_get_title(titlebar_ptr->view_ptr), - wlmaker_config_theme.titlebar_focussed_text_color); - cairo_destroy(cairo_ptr); - - bs_gfxbuf_copy_area( - bs_gfxbuf_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr), - 0, 0, - titlebar_ptr->background_blurred_gfxbuf_ptr, - titlebar_ptr->title_pos, 0, - titlebar_ptr->title_width, wlmaker_decorations_titlebar_height); - cairo_ptr = cairo_create_from_wlr_buffer(buf_holder.blurred_wlrbuf_ptr); - BS_ASSERT(NULL != cairo_ptr); - wlmaker_primitives_draw_bezel( - cairo_ptr, wlmaker_decorations_button_bezel_width, true); - wlmaker_primitives_draw_window_title( - cairo_ptr, - wlmaker_view_get_title(titlebar_ptr->view_ptr), - wlmaker_config_theme.titlebar_blurred_text_color); - cairo_destroy(cairo_ptr); - - if (NULL == titlebar_ptr->title_ptr) { - titlebar_ptr->title_ptr = wlmaker_decorations_title_create( - titlebar_ptr->wlr_scene_tree_ptr, - titlebar_ptr->view_ptr->server_ptr->cursor_ptr, - titlebar_ptr->view_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr); - BS_ASSERT(NULL != titlebar_ptr->title_ptr); - } else { - wlmaker_decorations_title_set_textures( - titlebar_ptr->title_ptr, - buf_holder.released_wlrbuf_ptr, - buf_holder.blurred_wlrbuf_ptr); - } - - drop_wlr_buffers(&buf_holder); -} - -/* ------------------------------------------------------------------------- */ -/** - * Callback for the "minimize" button action. - * - * @param interactive_ptr Points to the interactive that triggered the - * action. Unused. - * @param data_ptr This view. - */ -void button_minimize_callback( - __UNUSED__ wlmaker_interactive_t *interactive_ptr, - void *data_ptr) -{ - wlmaker_view_t *view_ptr = (wlmaker_view_t*)data_ptr; - wlmaker_view_set_iconified(view_ptr, true); -} - -/* ------------------------------------------------------------------------- */ -/** - * Callback for the close button action. - * - * @param interactive_ptr Points to the interactive that triggered the - * action. Unused. - * @param data_ptr This view. - */ -void button_close_callback( - __UNUSED__ wlmaker_interactive_t *interactive_ptr, - void *data_ptr) -{ - wlmaker_view_t *view_ptr = (wlmaker_view_t*)data_ptr; - view_ptr->send_close_callback(view_ptr); -} - -/* == End of titlebar.c ==================================================== */ diff --git a/src/decorations/titlebar.h b/src/decorations/titlebar.h deleted file mode 100644 index b767c486..00000000 --- a/src/decorations/titlebar.h +++ /dev/null @@ -1,90 +0,0 @@ -/* ========================================================================= */ -/** - * @file titlebar.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __TITLEBAR_H__ -#define __TITLEBAR_H__ - -#define WLR_USE_UNSTABLE -#include -#undef WLR_USE_UNSTABLE - -#include "../view.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** Forward declaration: Titlebar of window decoration. */ -typedef struct _wlmaker_decorations_titlebar_t wlmaker_decorations_titlebar_t; - -/** - * Creates the title bar for window decoration. - * - * @param wlr_scene_tree_ptr - * @param width - * @param view_ptr - * - * @return A titlebar handle, or NULL on error. Must be free-d by calling - * @ref wlmaker_decorations_titlebar_destroy. - */ -wlmaker_decorations_titlebar_t *wlmaker_decorations_titlebar_create( - struct wlr_scene_tree *wlr_scene_tree_ptr, - unsigned width, - wlmaker_view_t *view_ptr); - -/** - * Destroys a window decoration title bar. - * - * @param titlebar_ptr - */ -void wlmaker_decorations_titlebar_destroy( - wlmaker_decorations_titlebar_t *titlebar_ptr); - -/** - * Sets the width of the titlebar. - * - * @param titlebar_ptr - * @param width - */ -void wlmaker_decorations_titlebar_set_width( - wlmaker_decorations_titlebar_t *titlebar_ptr, - unsigned width); - -/** - * Returns the height of the titlebar. Includes the top margin. - * - * @param titlebar_ptr - */ -unsigned wlmaker_decorations_titlebar_get_height( - wlmaker_decorations_titlebar_t *titlebar_ptr); - -/** - * Sets the title of the titlebar. Will pull it from the view. - * - * @param titlebar_ptr - */ -void wlmaker_decorations_titlebar_update_title( - wlmaker_decorations_titlebar_t *titlebar_ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __TITLEBAR_H__ */ -/* == End of titlebar.h ==================================================== */ diff --git a/src/decorations/window_decorations.c b/src/decorations/window_decorations.c deleted file mode 100644 index dd57f4f8..00000000 --- a/src/decorations/window_decorations.c +++ /dev/null @@ -1,230 +0,0 @@ -/* ========================================================================= */ -/** - * @file window_decorations.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "window_decorations.h" - -#include "../config.h" -#include "margin.h" -#include "resizebar.h" -#include "titlebar.h" - -/* == Declarations ========================================================= */ - -/** State of the decoration of a window. */ -struct _wlmaker_window_decorations_t { - /** Back-link to the view. */ - wlmaker_view_t *view_ptr; - - /** Scene tree holding all decoration elements. */ - struct wlr_scene_tree *wlr_scene_tree_ptr; - - /** Window margins. */ - wlmaker_decorations_margin_t *margin_ptr; - - /** The titlebar, including buttons. */ - wlmaker_decorations_titlebar_t *titlebar_ptr; - - /** The resizebar, including all resize elements and margin. */ - wlmaker_decorations_resizebar_t *resizebar_ptr; -}; - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -wlmaker_window_decorations_t *wlmaker_window_decorations_create( - wlmaker_view_t *view_ptr) -{ - wlmaker_window_decorations_t *decorations_ptr = logged_calloc( - 1, sizeof(wlmaker_window_decorations_t)); - if (NULL == decorations_ptr) return NULL; - decorations_ptr->view_ptr = view_ptr; - - // Must be mapped. TODO(kaeser@gubbe.ch): Don't rely on internals! - BS_ASSERT(NULL != view_ptr->workspace_ptr); - BS_ASSERT(view_ptr->server_side_decoration_enabled); - BS_ASSERT(!view_ptr->fullscreen); - // TODO(kaeser@gubbe.ch): Shouldn't need to access the internals. - uint32_t width, height; - view_ptr->impl_ptr->get_size(view_ptr, &width, &height); - - decorations_ptr->wlr_scene_tree_ptr = wlr_scene_tree_create( - view_ptr->elements_wlr_scene_tree_ptr); - if (NULL == decorations_ptr->wlr_scene_tree_ptr) { - wlmaker_window_decorations_destroy(decorations_ptr); - return NULL; - } - - // Margins around the window itself (not including title or resize bar). - decorations_ptr->margin_ptr = wlmaker_decorations_margin_create( - decorations_ptr->wlr_scene_tree_ptr, 0, 0, width, height, - WLR_EDGE_LEFT | WLR_EDGE_TOP | WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM); - if (NULL == decorations_ptr->margin_ptr) { - wlmaker_window_decorations_destroy(decorations_ptr); - return NULL; - } - - decorations_ptr->titlebar_ptr = wlmaker_decorations_titlebar_create( - decorations_ptr->wlr_scene_tree_ptr, width, view_ptr); - if (NULL == decorations_ptr->titlebar_ptr) { - wlmaker_window_decorations_destroy(decorations_ptr); - return NULL; - } - - decorations_ptr->resizebar_ptr = wlmaker_decorations_resizebar_create( - decorations_ptr->wlr_scene_tree_ptr, width, height, view_ptr); - if (NULL == decorations_ptr->resizebar_ptr) { - wlmaker_window_decorations_destroy(decorations_ptr); - return NULL; - } - - - return decorations_ptr; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_destroy( - wlmaker_window_decorations_t *decorations_ptr) -{ - if (NULL != decorations_ptr->resizebar_ptr) { - wlmaker_decorations_resizebar_destroy(decorations_ptr->resizebar_ptr); - decorations_ptr->resizebar_ptr = NULL; - } - - if (NULL != decorations_ptr->titlebar_ptr) { - wlmaker_decorations_titlebar_destroy(decorations_ptr->titlebar_ptr); - decorations_ptr->titlebar_ptr = NULL; - } - - if (NULL != decorations_ptr->margin_ptr) { - wlmaker_decorations_margin_destroy(decorations_ptr->margin_ptr); - decorations_ptr->margin_ptr = NULL; - } - - if (NULL != decorations_ptr->wlr_scene_tree_ptr) { - wlr_scene_node_destroy(&decorations_ptr->wlr_scene_tree_ptr->node); - decorations_ptr->wlr_scene_tree_ptr = NULL; - } - - free(decorations_ptr); -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_set_inner_size( - wlmaker_window_decorations_t *decorations_ptr, - uint32_t width, - uint32_t height) -{ - if (NULL != decorations_ptr->margin_ptr) { - wlmaker_decorations_margin_set_size( - decorations_ptr->margin_ptr, width, height); - } - - if (NULL != decorations_ptr->titlebar_ptr) { - wlmaker_decorations_titlebar_set_width( - decorations_ptr->titlebar_ptr, width); - } - - if (NULL != decorations_ptr->resizebar_ptr) { - wlmaker_decorations_resizebar_set_size( - decorations_ptr->resizebar_ptr, width, height); - } -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_get_added_size( - wlmaker_window_decorations_t *decorations_ptr, - uint32_t *width_ptr, - uint32_t *height_ptr) -{ - if (NULL != width_ptr) { - *width_ptr = 2 * wlmaker_config_theme.window_margin_width; - } - - if (NULL != height_ptr) { - *height_ptr = 2 * wlmaker_config_theme.window_margin_width; - if (NULL != decorations_ptr->titlebar_ptr) { - *height_ptr += wlmaker_decorations_titlebar_get_height( - decorations_ptr->titlebar_ptr); - } - - if (NULL != decorations_ptr->resizebar_ptr) { - *height_ptr += wlmaker_decorations_resizebar_get_height( - decorations_ptr->resizebar_ptr); - } - } -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_relative_position( - wlmaker_window_decorations_t *decorations_ptr, - int *relx_ptr, - int *rely_ptr) -{ - if (NULL != relx_ptr) { - *relx_ptr = -wlmaker_config_theme.window_margin_width; - } - - if (NULL != rely_ptr) { - *rely_ptr = -wlmaker_config_theme.window_margin_width; - if (NULL != decorations_ptr->titlebar_ptr) { - *rely_ptr -= wlmaker_decorations_titlebar_get_height( - decorations_ptr->titlebar_ptr); - } - } -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_update_title( - wlmaker_window_decorations_t *decorations_ptr) -{ - if (NULL != decorations_ptr->titlebar_ptr) { - wlmaker_decorations_titlebar_update_title( - decorations_ptr->titlebar_ptr); - } -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_window_decorations_set_shade( - wlmaker_window_decorations_t *decorations_ptr, - bool shaded) -{ - if (shaded && NULL != decorations_ptr->resizebar_ptr) { - wlmaker_decorations_resizebar_destroy(decorations_ptr->resizebar_ptr); - decorations_ptr->resizebar_ptr = NULL; - } - - if (!shaded && NULL == decorations_ptr->resizebar_ptr) { - uint32_t width, height; - decorations_ptr->view_ptr->impl_ptr->get_size( - decorations_ptr->view_ptr, &width, &height); - decorations_ptr->resizebar_ptr = wlmaker_decorations_resizebar_create( - decorations_ptr->wlr_scene_tree_ptr, - width, height, - decorations_ptr->view_ptr); - } - - wlmaker_decorations_margin_set_edges( - decorations_ptr->margin_ptr, - shaded ? - WLR_EDGE_TOP : - WLR_EDGE_LEFT | WLR_EDGE_TOP | WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM); -} - -/* == End of window_decorations.c ========================================== */ diff --git a/src/decorations/window_decorations.h b/src/decorations/window_decorations.h deleted file mode 100644 index 5c874130..00000000 --- a/src/decorations/window_decorations.h +++ /dev/null @@ -1,125 +0,0 @@ -/* ========================================================================= */ -/** - * @file window_decorations.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __WINDOW_DECORATIONS_H__ -#define __WINDOW_DECORATIONS_H__ - -/** Forward declaration: Handle for decorations for a window. */ -typedef struct _wlmaker_window_decorations_t wlmaker_window_decorations_t; - -#include "../view.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * Creates window decorations for the provided window (view). - * - * Will create a margin, title bar and resize bar. Decorations should only - * be created when the view (1) has decorations enabled, (2) is mapped - * and (3) is not in fullscreen mode. - * - * => TODO: Take flags as to which elements are on. (resizing? - * menu bar elements?) - * - * @param view_ptr - * - * @return A handle for the window's decorations. Must be free'd by calling - * @ref wlmaker_window_decorations_destroy(). - */ -wlmaker_window_decorations_t *wlmaker_window_decorations_create( - wlmaker_view_t *view_ptr); - -/** - * Destroys the window decorations. - * - * @param decorations_ptr - */ -void wlmaker_window_decorations_destroy( - wlmaker_window_decorations_t *decorations_ptr); - -/** - * Sets (or updates) the size of the decorated (inner) window. - * - * `width` and `height` are specifying the dimensions of the decorated window, - * ie. without the added size of the decorations. - * - * @param decorations_ptr - * @param width - * @param height - */ -void wlmaker_window_decorations_set_inner_size( - wlmaker_window_decorations_t *decorations_ptr, - uint32_t width, - uint32_t height); - -/** - * Retrieves the size added by the decoration. - * - * @param decorations_ptr - * @param width_ptr - * @param height_ptr - */ -void wlmaker_window_decorations_get_added_size( - wlmaker_window_decorations_t *decorations_ptr, - uint32_t *width_ptr, - uint32_t *height_ptr); - -/** - * Returns the relative position of the decoration to the inner window. - * - * The top-left corner of the decoration of an inner window is placed at - * `x-position of inner window` plus `*relx_ptr`. Same for Y position. - * - * @param decorations_ptr - * @param relx_ptr - * @param rely_ptr - */ -void wlmaker_window_decorations_relative_position( - wlmaker_window_decorations_t *decorations_ptr, - int *relx_ptr, - int *rely_ptr); - -/** - * Updates the title used for the windo decoration. Wraps to titlebar. - * - * @param decorations_ptr - */ -void wlmaker_window_decorations_update_title( - wlmaker_window_decorations_t *decorations_ptr); - -/** - * Sets the "shade" status for decorations. When shaded, the resizebar is - * hidden. - * - * @param decorations_ptr - * @param shaded - */ -void wlmaker_window_decorations_set_shade( - wlmaker_window_decorations_t *decorations_ptr, - bool shaded); - - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __WINDOW_DECORATIONS_H__ */ -/* == End of window_decorations.h ========================================== */ diff --git a/src/resizebar.c b/src/resizebar.c deleted file mode 100644 index 5bbb414c..00000000 --- a/src/resizebar.c +++ /dev/null @@ -1,273 +0,0 @@ -/* ========================================================================= */ -/** - * @file resizebar.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "resizebar.h" - -#include -#include - -#define WLR_USE_UNSTABLE -#include -#undef WLR_USE_UNSTABLE - -/* == Declarations ========================================================= */ - -/** State of an interactive resizebar element. */ -typedef struct { - /** The interactive (parent structure). */ - wlmaker_interactive_t interactive; - - /** Back-link to the view. */ - wlmaker_view_t *view_ptr; - /** Texture of the resize bar, not pressed. */ - struct wlr_buffer *resizebar_buffer_ptr; - /** Texture of the resize bar, pressed. */ - struct wlr_buffer *resizebar_pressed_buffer_ptr; - /** Which edges will be controlled by this element. */ - uint32_t edges; - - /** Status of the element. */ - bool pressed; -} wlmaker_resizebar_t; - -static wlmaker_resizebar_t *resizebar_from_interactive( - wlmaker_interactive_t *interactive_ptr); - -static void _resizebar_enter( - wlmaker_interactive_t *interactive_ptr); -static void _resizebar_leave( - wlmaker_interactive_t *interactive_ptr); -static void _resizebar_motion( - wlmaker_interactive_t *interactive_ptr, - double x, - double y); -static void _resizebar_button( - wlmaker_interactive_t *interactive_ptr, - double x, double y, - struct wlr_pointer_button_event *wlr_pointer_button_event_ptr); -static void _resizebar_destroy(wlmaker_interactive_t *interactive_ptr); - -/* == Data ================================================================= */ - -/** Implementation: callbacks for the interactive. */ -static const wlmaker_interactive_impl_t wlmaker_interactive_resizebar_impl = { - .enter = _resizebar_enter, - .leave = _resizebar_leave, - .motion = _resizebar_motion, - .button = _resizebar_button, - .destroy = _resizebar_destroy -}; - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -wlmaker_interactive_t *wlmaker_resizebar_create( - struct wlr_scene_buffer *wlr_scene_buffer_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *resizebar_buffer_ptr, - struct wlr_buffer *resizebar_pressed_buffer_ptr, - uint32_t edges) -{ - wlmaker_resizebar_t *resizebar_ptr = logged_calloc( - 1, sizeof(wlmaker_resizebar_t)); - if (NULL == resizebar_ptr) return NULL; - resizebar_ptr->view_ptr = view_ptr; - resizebar_ptr->resizebar_buffer_ptr = - wlr_buffer_lock(resizebar_buffer_ptr); - resizebar_ptr->resizebar_pressed_buffer_ptr = - wlr_buffer_lock(resizebar_pressed_buffer_ptr); - resizebar_ptr->edges = edges; - - wlmaker_interactive_init( - &resizebar_ptr->interactive, - &wlmaker_interactive_resizebar_impl, - wlr_scene_buffer_ptr, - cursor_ptr, - resizebar_buffer_ptr); - - return &resizebar_ptr->interactive; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_resizebar_set_textures( - wlmaker_interactive_t *interactive_ptr, - struct wlr_buffer *resizebar_buffer_ptr, - struct wlr_buffer *resizebar_pressed_buffer_ptr) -{ - wlmaker_resizebar_t *resizebar_ptr = resizebar_from_interactive( - interactive_ptr); - - // This only updates the internal references... - wlr_buffer_unlock(resizebar_ptr->resizebar_buffer_ptr); - resizebar_ptr->resizebar_buffer_ptr = - wlr_buffer_lock(resizebar_buffer_ptr); - wlr_buffer_unlock(resizebar_ptr->resizebar_pressed_buffer_ptr); - resizebar_ptr->resizebar_pressed_buffer_ptr = - wlr_buffer_lock(resizebar_pressed_buffer_ptr); - - // ... and we also need to set the current texture in appropriate state. - wlmaker_interactive_set_texture( - interactive_ptr, - resizebar_ptr->pressed ? - resizebar_ptr->resizebar_pressed_buffer_ptr : - resizebar_ptr->resizebar_buffer_ptr); -} - -/* == Local (static) methods =============================================== */ - -/* ------------------------------------------------------------------------- */ -/** - * Cast (with assertion) |interactive_ptr| to the |wlmaker_resizebar_t|. - * - * @param interactive_ptr - */ -wlmaker_resizebar_t *resizebar_from_interactive( - wlmaker_interactive_t *interactive_ptr) -{ - if (NULL != interactive_ptr && - interactive_ptr->impl != &wlmaker_interactive_resizebar_impl) { - bs_log(BS_FATAL, "Not a resizebar: %p", interactive_ptr); - abort(); - } - return (wlmaker_resizebar_t*)interactive_ptr; -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Cursor enters the resizebar area. - * - * @param interactive_ptr - */ -void _resizebar_enter( - wlmaker_interactive_t *interactive_ptr) -{ - wlmaker_resizebar_t *resizebar_ptr = resizebar_from_interactive( - interactive_ptr); - - const char *xcursor_name_ptr = "left_ptr"; // Default. - if (resizebar_ptr->edges == WLR_EDGE_BOTTOM) { - xcursor_name_ptr = "s-resize"; - } else if (resizebar_ptr->edges == (WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT)) { - xcursor_name_ptr = "se-resize"; - } else if (resizebar_ptr->edges == (WLR_EDGE_BOTTOM | WLR_EDGE_LEFT)) { - xcursor_name_ptr = "sw-resize"; - } - - wlr_cursor_set_xcursor( - interactive_ptr->cursor_ptr->wlr_cursor_ptr, - interactive_ptr->cursor_ptr->wlr_xcursor_manager_ptr, - xcursor_name_ptr); -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Cursor leaves the resizebar area. - * - * @param interactive_ptr - */ -void _resizebar_leave( - __UNUSED__ wlmaker_interactive_t *interactive_ptr) -{ - // Nothing to do. -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Cursor motion in the resizebar area. - * - * - * @param interactive_ptr - * @param x - * @param y - */ -void _resizebar_motion( - __UNUSED__ wlmaker_interactive_t *interactive_ptr, - __UNUSED__ double x, - __UNUSED__ double y) -{ - // Nothing to do. -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Handle cursor button, ie. button press or release. - * - * @param interactive_ptr - * @param x - * @param y - * @param wlr_pointer_button_event_ptr - */ -void _resizebar_button( - wlmaker_interactive_t *interactive_ptr, - double x, double y, - struct wlr_pointer_button_event *wlr_pointer_button_event_ptr) -{ - wlmaker_resizebar_t *resizebar_ptr = resizebar_from_interactive( - interactive_ptr); - - if (wlr_pointer_button_event_ptr->button != BTN_LEFT) return; - switch (wlr_pointer_button_event_ptr->state) { - case WLR_BUTTON_PRESSED: - if (wlmaker_interactive_contains(&resizebar_ptr->interactive, x, y)) { - resizebar_ptr->pressed = true; - } - break; - - case WLR_BUTTON_RELEASED: - resizebar_ptr->pressed = false; - break; - - default: - /* huh, that's unexpected... */ - break; - } - - wlmaker_interactive_set_texture( - interactive_ptr, - resizebar_ptr->pressed ? - resizebar_ptr->resizebar_pressed_buffer_ptr : - resizebar_ptr->resizebar_buffer_ptr); -} - -/* ------------------------------------------------------------------------- */ -/** - * Destroys resizebar interactive. - * - * @param interactive_ptr - */ -void _resizebar_destroy(wlmaker_interactive_t *interactive_ptr) -{ - wlmaker_resizebar_t *resizebar_ptr = resizebar_from_interactive( - interactive_ptr); - - if (NULL != resizebar_ptr->resizebar_buffer_ptr) { - wlr_buffer_unlock(resizebar_ptr->resizebar_buffer_ptr); - resizebar_ptr->resizebar_buffer_ptr = NULL; - } - if (NULL != resizebar_ptr->resizebar_pressed_buffer_ptr) { - wlr_buffer_unlock(resizebar_ptr->resizebar_pressed_buffer_ptr); - resizebar_ptr->resizebar_pressed_buffer_ptr = NULL; - } - - free(resizebar_ptr); -} - -/* == End of resizebar.c =================================================== */ diff --git a/src/resizebar.h b/src/resizebar.h deleted file mode 100644 index 8e16021e..00000000 --- a/src/resizebar.h +++ /dev/null @@ -1,77 +0,0 @@ -/* ========================================================================= */ -/** - * @file resizebar.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __RESIZEBAR_H__ -#define __RESIZEBAR_H__ - -#include "cursor.h" -#include "interactive.h" - -#define WLR_USE_UNSTABLE -#include -#include -#undef WLR_USE_UNSTABLE - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * Creates a resizebar interactive. - * - * @param wlr_scene_buffer_ptr Buffer scene node to contain the button. - * @param cursor_ptr Cursor. Must outlive the resizebar. - * @param view_ptr View owning the resizebar. Must outlive this. - * @param resizebar_buffer_ptr WLR buffer, resize bar texture. This resizebar - * interactive will hold a consumer lock on it. - * @param resizebar_pressed_buffer_ptr WLR buffer, resize bar texture when - * pressed. - * @param edges Edges that are controlled by this element. - * - * @return A pointer to the interactive. Must be destroyed via - * |_resizebar_destroy|. - */ -wlmaker_interactive_t *wlmaker_resizebar_create( - struct wlr_scene_buffer *wlr_scene_buffer_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *resizebar_buffer_ptr, - struct wlr_buffer *resizebar_pressed_buffer_ptr, - uint32_t edges); - -/** - * Sets (replaces) the textures for the resizebar interactive. - * - * @param interactive_ptr - * @param resizebar_buffer_ptr WLR buffer, resize bar texture. This resizebar - * interactive will hold a consumer lock on it. - * @param resizebar_pressed_buffer_ptr WLR buffer, resize bar texture when - * pressed. - */ -void wlmaker_resizebar_set_textures( - wlmaker_interactive_t *interactive_ptr, - struct wlr_buffer *resizebar_buffer_ptr, - struct wlr_buffer *resizebar_pressed_buffer_ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __RESIZEBAR_H__ */ -/* == End of resizebar.h =================================================== */ diff --git a/src/titlebar.c b/src/titlebar.c deleted file mode 100644 index 99395349..00000000 --- a/src/titlebar.c +++ /dev/null @@ -1,340 +0,0 @@ -/* ========================================================================= */ -/** - * @file titlebar.c - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "config.h" -#include "titlebar.h" - -#include -#include - -#define WLR_USE_UNSTABLE -#include -#include -#undef WLR_USE_UNSTABLE - -/* == Declarations ========================================================= */ - -/** Titlebar state, with respect to moves. */ -typedef enum { - /** Idle */ - TITLEBAR_IDLE, - /** Clicked, waiting to initiate move. */ - TITLEBAR_CLICKED, - /** Actively moving. */ - TITLEBAR_MOVING -} titlebar_state_t; - -/** State of the interactive titlebar. */ -typedef struct { - /** The interactive (parent structure). */ - wlmaker_interactive_t interactive; - - /** Back-link to the view owning this titlebar. */ - wlmaker_view_t *view_ptr; - - /** WLR buffer, contains texture for the title bar when focussed. */ - struct wlr_buffer *titlebar_buffer_ptr; - /** WLR buffer, contains texture for the title bar when blurred. */ - struct wlr_buffer *titlebar_blurred_buffer_ptr; - - /** Titlebar state. */ - titlebar_state_t state; - /** X-Position of where the click happened. */ - double clicked_x; - /** Y-Position of where the click happened. */ - double clicked_y; - - /** Nanosecond of last mouse-click, to catch double-clicks. */ - uint64_t last_click_nsec; -} wlmaker_titlebar_t; - -static wlmaker_titlebar_t *titlebar_from_interactive( - wlmaker_interactive_t *interactive_ptr); - -static void _titlebar_enter( - wlmaker_interactive_t *interactive_ptr); -static void _titlebar_leave( - wlmaker_interactive_t *interactive_ptr); -static void _titlebar_motion( - wlmaker_interactive_t *interactive_ptr, - double x, double y); -static void _titlebar_focus( - wlmaker_interactive_t *interactive_ptr); -static void _titlebar_button( - wlmaker_interactive_t *interactive_ptr, - double x, double y, - struct wlr_pointer_button_event *wlr_pointer_button_event_ptr); -static void _titlebar_destroy( - wlmaker_interactive_t *interactive_ptr); - -/* == Data ================================================================= */ - -/** Implementation: callbacks for the interactive. */ -static const wlmaker_interactive_impl_t wlmaker_interactive_titlebar_impl = { - .enter = _titlebar_enter, - .leave = _titlebar_leave, - .motion = _titlebar_motion, - .focus = _titlebar_focus, - .button = _titlebar_button, - .destroy = _titlebar_destroy -}; - -/** Default xcursor to use. */ -static const char *xcursor_name_default = "left_ptr"; -/** Xcursor to show when in MOVING state. */ -static const char *xcursor_name_move = "move"; -/** Minimum cursor move to enable MOVING afer CLICKED. */ -static const double minimal_move = 2; - -/* == Exported methods ===================================================== */ - -/* ------------------------------------------------------------------------- */ -wlmaker_interactive_t *wlmaker_titlebar_create( - struct wlr_scene_buffer *wlr_scene_buffer_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *titlebar_buffer_ptr, - struct wlr_buffer *titlebar_blurred_buffer_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = logged_calloc( - 1, sizeof(wlmaker_titlebar_t)); - if (NULL == titlebar_ptr) return NULL; - titlebar_ptr->view_ptr = view_ptr; - titlebar_ptr->titlebar_buffer_ptr = wlr_buffer_lock(titlebar_buffer_ptr); - titlebar_ptr->titlebar_blurred_buffer_ptr = - wlr_buffer_lock(titlebar_blurred_buffer_ptr); - titlebar_ptr->state = TITLEBAR_IDLE; - - wlmaker_interactive_init( - &titlebar_ptr->interactive, - &wlmaker_interactive_titlebar_impl, - wlr_scene_buffer_ptr, - cursor_ptr, - titlebar_buffer_ptr); - - return &titlebar_ptr->interactive; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_title_set_texture( - wlmaker_interactive_t *interactive_ptr, - struct wlr_buffer *titlebar_buffer_ptr, - struct wlr_buffer *titlebar_blurred_buffer_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - wlr_buffer_unlock(titlebar_ptr->titlebar_buffer_ptr); - wlr_buffer_unlock(titlebar_ptr->titlebar_blurred_buffer_ptr); - titlebar_ptr->titlebar_buffer_ptr = wlr_buffer_lock(titlebar_buffer_ptr); - titlebar_ptr->titlebar_blurred_buffer_ptr = - wlr_buffer_lock(titlebar_blurred_buffer_ptr); - wlmaker_interactive_set_texture( - interactive_ptr, - interactive_ptr->focussed ? - titlebar_ptr->titlebar_buffer_ptr : - titlebar_ptr->titlebar_blurred_buffer_ptr); -} - -/* == Local (static) methods =============================================== */ - -/* ------------------------------------------------------------------------- */ -/** - * Cast (with assertion) |interactive_ptr| to the |wlmaker_titlebar_t|. - * - * @param interactive_ptr - */ -wlmaker_titlebar_t *titlebar_from_interactive( - wlmaker_interactive_t *interactive_ptr) -{ - if (NULL != interactive_ptr && - interactive_ptr->impl != &wlmaker_interactive_titlebar_impl) { - bs_log(BS_FATAL, "Not a titlebar: %p", interactive_ptr); - abort(); - } - return (wlmaker_titlebar_t*)interactive_ptr; -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Cursor enters the button area. - * - * @param interactive_ptr - */ -void _titlebar_enter(wlmaker_interactive_t *interactive_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - - const char *cursor_name_ptr = xcursor_name_default; - if (titlebar_ptr->state == TITLEBAR_MOVING) { - cursor_name_ptr = xcursor_name_move; - } - - wlr_cursor_set_xcursor( - interactive_ptr->cursor_ptr->wlr_cursor_ptr, - interactive_ptr->cursor_ptr->wlr_xcursor_manager_ptr, - cursor_name_ptr); -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Cursor leaves the button area. - * - * @param interactive_ptr - */ -void _titlebar_leave(__UNUSED__ wlmaker_interactive_t *interactive_ptr) -{ - // Nothing to do. -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Handle cursor motion. - * - * @param interactive_ptr - * @param x - * @param y - */ -void _titlebar_motion( - wlmaker_interactive_t *interactive_ptr, - double x, double y) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - - if (titlebar_ptr->state == TITLEBAR_CLICKED && - (fabs(titlebar_ptr->clicked_x - x) > minimal_move || - fabs(titlebar_ptr->clicked_y - y) > minimal_move)) { - titlebar_ptr->state = TITLEBAR_MOVING; - - wlr_cursor_set_xcursor( - interactive_ptr->cursor_ptr->wlr_cursor_ptr, - interactive_ptr->cursor_ptr->wlr_xcursor_manager_ptr, - xcursor_name_move); - } -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Focus state changes. - * - * @param interactive_ptr - */ -static void _titlebar_focus(wlmaker_interactive_t *interactive_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - - wlmaker_interactive_set_texture( - interactive_ptr, - interactive_ptr->focussed ? - titlebar_ptr->titlebar_buffer_ptr : - titlebar_ptr->titlebar_blurred_buffer_ptr); - if (!interactive_ptr->focussed) { - titlebar_ptr->state = TITLEBAR_IDLE; - } -} - -/* ------------------------------------------------------------------------- */ -/** - * Interactive callback: Handle cursor button, ie. button press or release. - * - * @param interactive_ptr - * @param x - * @param y - * @param wlr_pointer_button_event_ptr - */ -void _titlebar_button( - wlmaker_interactive_t *interactive_ptr, - double x, - double y, - __UNUSED__ struct wlr_pointer_button_event *wlr_pointer_button_event_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - uint64_t now_nsec; - - if (wlr_pointer_button_event_ptr->button == BTN_RIGHT && - wlr_pointer_button_event_ptr->state == WLR_BUTTON_PRESSED) { - wlmaker_view_window_menu_show(titlebar_ptr->view_ptr); - } - - if (wlr_pointer_button_event_ptr->button != BTN_LEFT) return; - - switch (wlr_pointer_button_event_ptr->state) { - case WLR_BUTTON_PRESSED: - now_nsec = bs_mono_nsec(); - if (now_nsec - titlebar_ptr->last_click_nsec < - wlmaker_config_double_click_wait_msec * 1000000ull) { - // two clicks! will take it! - titlebar_ptr->state = TITLEBAR_IDLE; - wlmaker_view_shade(titlebar_ptr->view_ptr); - break; - } - - if (titlebar_ptr->state == TITLEBAR_IDLE) { - titlebar_ptr->state = TITLEBAR_CLICKED; - titlebar_ptr->clicked_x = x; - titlebar_ptr->clicked_y = y; - } - titlebar_ptr->last_click_nsec = now_nsec; - break; - - case WLR_BUTTON_RELEASED: - titlebar_ptr->state = TITLEBAR_IDLE; - // Reset cursor to default, if it is within our bounds. - if (wlmaker_interactive_contains(&titlebar_ptr->interactive, x, y)) { - wlr_cursor_set_xcursor( - interactive_ptr->cursor_ptr->wlr_cursor_ptr, - interactive_ptr->cursor_ptr->wlr_xcursor_manager_ptr, - xcursor_name_default); - } - break; - - default: - /* huh, that's unexpected... */ - break; - } -} - -/* ------------------------------------------------------------------------- */ -/** - * Destroys the titlebar interactive. - * - * @param interactive_ptr - */ -void _titlebar_destroy( - wlmaker_interactive_t *interactive_ptr) -{ - wlmaker_titlebar_t *titlebar_ptr = titlebar_from_interactive( - interactive_ptr); - - if (NULL != titlebar_ptr->titlebar_buffer_ptr) { - wlr_buffer_unlock(titlebar_ptr->titlebar_buffer_ptr); - titlebar_ptr->titlebar_buffer_ptr = NULL; - } - if (NULL != titlebar_ptr->titlebar_blurred_buffer_ptr) { - wlr_buffer_unlock(titlebar_ptr->titlebar_blurred_buffer_ptr); - titlebar_ptr->titlebar_blurred_buffer_ptr = NULL; - } - free(titlebar_ptr); -} - -/* == End of titlebar.c ==================================================== */ diff --git a/src/titlebar.h b/src/titlebar.h deleted file mode 100644 index 2f44017d..00000000 --- a/src/titlebar.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ========================================================================= */ -/** - * @file titlebar.h - * - * @copyright - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __TITLEBAR_H__ -#define __TITLEBAR_H__ - -#include "cursor.h" -#include "interactive.h" - -#define WLR_USE_UNSTABLE -#include -#include -#undef WLR_USE_UNSTABLE - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * Creates a titlebar interactive. - * - * @param wlr_scene_buffer_ptr Buffer scene node to contain the button. - * @param cursor_ptr Cursor. Must outlive the titlebar. - * @param view_ptr View owning the titlebar. Must outlive titlebar. - * @param titlebar_buffer_ptr WLR buffer, title bar texture when focussed. This - * titlebar interactive will hold a consumer lock on - * it. - * @param titlebar_blurred_buffer_ptr WLR buffer, texture when blurred. This - * titlebar interactive will hold a consumer lock. - * - * @return A pointer to the interactive. Must be destroyed via - * |_titlebar_destroy|. - */ -wlmaker_interactive_t *wlmaker_titlebar_create( - struct wlr_scene_buffer *wlr_scene_buffer_ptr, - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - struct wlr_buffer *titlebar_buffer_ptr, - struct wlr_buffer *titlebar_blurred_buffer_ptr); - -/** - * Sets (replaces) the texture for the titlebar interactive. - * - * @param interactive_ptr - * @param titlebar_buffer_ptr - * @param titlebar_blurred_buffer_ptr - */ -void wlmaker_title_set_texture( - wlmaker_interactive_t *interactive_ptr, - struct wlr_buffer *titlebar_buffer_ptr, - struct wlr_buffer *titlebar_blurred_buffer_ptr); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif /* __TITLEBAR_H__ */ -/* == End of titlebar.h ==================================================== */ diff --git a/src/view.c b/src/view.c index dc7ec88b..ea8b270e 100644 --- a/src/view.c +++ b/src/view.c @@ -24,8 +24,6 @@ #include "config.h" #include "decorations.h" #include "menu.h" -#include "resizebar.h" -#include "titlebar.h" #include "toolkit/toolkit.h" #include @@ -51,8 +49,6 @@ static void window_menu_callback_move_to_workspace1(void *ud_ptr); static void window_menu_callback_move_to_workspace2(void *ud_ptr); static void window_menu_callback_close(void *ud_ptr); -static void wlmaker_view_apply_decoration(wlmaker_view_t *view_ptr); - /* == Data ================================================================= */ /** Descriptors for the menu entries of the view's "Window menu". */ @@ -154,11 +150,6 @@ void wlmaker_view_fini(wlmaker_view_t *view_ptr) view_ptr->interactive_tree_ptr = NULL; } - if (NULL != view_ptr->window_decorations_ptr) { - wlmaker_window_decorations_destroy(view_ptr->window_decorations_ptr); - view_ptr->window_decorations_ptr = NULL; - } - if (NULL != view_ptr->elements_wlr_scene_tree_ptr) { wlr_scene_node_destroy(&view_ptr->elements_wlr_scene_tree_ptr->node); view_ptr->elements_wlr_scene_tree_ptr = NULL; @@ -339,17 +330,6 @@ void wlmaker_view_handle_axis( } } -/* ------------------------------------------------------------------------- */ -void wlmaker_view_set_server_side_decoration( - wlmaker_view_t *view_ptr, - bool enabled) -{ - // Don't act if there's nothing to do... - if (view_ptr->server_side_decoration_enabled == enabled) return; - view_ptr->server_side_decoration_enabled = enabled; - wlmaker_view_apply_decoration(view_ptr); -} - /* ------------------------------------------------------------------------- */ void wlmaker_view_window_menu_show(wlmaker_view_t *view_ptr) { @@ -444,21 +424,10 @@ void wlmaker_view_cursor_leave(wlmaker_view_t *view_ptr) } /* ------------------------------------------------------------------------- */ -void wlmaker_view_shade(wlmaker_view_t *view_ptr) +void wlmaker_view_shade(__UNUSED__ wlmaker_view_t *view_ptr) { - if (!view_ptr->server_side_decorated) { - bs_log(BS_INFO, "Shade only available when server-side-decorated."); - return; - } - BS_ASSERT(NULL != view_ptr->view_wlr_scene_tree_ptr); - - view_ptr->shaded ^= true; - wlr_scene_node_set_enabled( - &view_ptr->view_wlr_scene_tree_ptr->node, !view_ptr->shaded); - if (NULL != view_ptr->window_decorations_ptr) { - wlmaker_window_decorations_set_shade( - view_ptr->window_decorations_ptr, view_ptr->shaded); - } + bs_log(BS_INFO, "Shade only available when server-side-decorated."); + return; } /* ------------------------------------------------------------------------- */ @@ -467,19 +436,6 @@ void wlmaker_view_get_size(wlmaker_view_t *view_ptr, uint32_t *height_ptr) { view_ptr->impl_ptr->get_size(view_ptr, width_ptr, height_ptr); - if (view_ptr->server_side_decorated) { - if (NULL != view_ptr->window_decorations_ptr) { - uint32_t deco_width, deco_height; - wlmaker_window_decorations_get_added_size( - view_ptr->window_decorations_ptr, &deco_width, &deco_height); - if (NULL != width_ptr) { - *width_ptr += deco_width; - } - if (NULL != height_ptr) { - *height_ptr += deco_height; - } - } - } } /* ------------------------------------------------------------------------- */ @@ -488,21 +444,6 @@ void wlmaker_view_set_size(wlmaker_view_t *view_ptr, int width, int height) width = BS_MAX(1, width); height = BS_MAX(1, height); - if (view_ptr->server_side_decorated) { - BS_ASSERT(NULL != view_ptr->window_decorations_ptr); - - uint32_t deco_width, deco_height; - wlmaker_window_decorations_get_added_size( - view_ptr->window_decorations_ptr, &deco_width, &deco_height); - width -= deco_width; - height -= deco_height; - - width = BS_MAX(1, width); - height = BS_MAX(1, height); - - wlmaker_window_decorations_set_inner_size( - view_ptr->window_decorations_ptr, width, height); - } view_ptr->impl_ptr->set_size(view_ptr, width, height); } @@ -512,30 +453,12 @@ void wlmaker_view_get_position(wlmaker_view_t *view_ptr, { *x_ptr = view_ptr->elements_wlr_scene_tree_ptr->node.x; *y_ptr = view_ptr->elements_wlr_scene_tree_ptr->node.y; - - if (NULL != view_ptr->window_decorations_ptr) { - int relx, rely; - wlmaker_window_decorations_relative_position( - view_ptr->window_decorations_ptr, &relx, &rely); - *x_ptr += relx; - *y_ptr += rely; - } } /* ------------------------------------------------------------------------- */ void wlmaker_view_set_position(wlmaker_view_t *view_ptr, int x, int y) { - if (NULL != view_ptr->window_decorations_ptr) { - // Adjust position by the top-left decoration elements, since the node - // position does not factor in these. - int relx, rely; - wlmaker_window_decorations_relative_position( - view_ptr->window_decorations_ptr, &relx, &rely); - x -= relx; - y -= rely; - } - if (x != view_ptr->elements_wlr_scene_tree_ptr->node.x || y != view_ptr->elements_wlr_scene_tree_ptr->node.y) { wlr_scene_node_set_position( @@ -612,7 +535,6 @@ void wlmaker_view_set_fullscreen(wlmaker_view_t *view_ptr, bool fullscreen) wlmaker_workspace_demote_view_from_fullscreen( view_ptr->workspace_ptr, view_ptr); } - wlmaker_view_apply_decoration(view_ptr); wlmaker_view_set_position(view_ptr, new_box.x, new_box.y); wlmaker_view_set_size(view_ptr, new_box.width, new_box.height); @@ -646,11 +568,6 @@ void wlmaker_view_set_title(wlmaker_view_t *view_ptr, const char *title_ptr) if (NULL != title_ptr) { view_ptr->title_ptr = logged_strdup(title_ptr); } - - if (NULL != view_ptr->window_decorations_ptr) { - wlmaker_window_decorations_update_title( - view_ptr->window_decorations_ptr); - } } /* ------------------------------------------------------------------------- */ @@ -692,7 +609,6 @@ void wlmaker_view_map(wlmaker_view_t *view_ptr, view_ptr->workspace_ptr, view_ptr, layer); - wlmaker_view_apply_decoration(view_ptr); wl_signal_emit(&view_ptr->server_ptr->view_mapped_event, view_ptr); } @@ -703,7 +619,6 @@ void wlmaker_view_unmap(wlmaker_view_t *view_ptr) BS_ASSERT(NULL != view_ptr->workspace_ptr); // Should be mapped. wlmaker_workspace_remove_view(view_ptr->workspace_ptr, view_ptr); view_ptr->workspace_ptr = NULL; - wlmaker_view_apply_decoration(view_ptr); wl_signal_emit(&view_ptr->server_ptr->view_unmapped_event, view_ptr); } @@ -896,44 +811,4 @@ void window_menu_callback_close(void *ud_ptr) view_ptr->send_close_callback(view_ptr); } -/* ------------------------------------------------------------------------- */ -/** - * Apply server-side decoration, if view is configured and in suitable state. - * - * Will set `wlmaker_view_t.server_side_decorated` suitably. - * - * @param view_ptr - */ -void wlmaker_view_apply_decoration(wlmaker_view_t *view_ptr) -{ - // We won't have the view decorated if it's (1) disabled, (2) unmapped, - // or (3) currently in fullscreen mode. - if ((!view_ptr->server_side_decoration_enabled) || - (NULL == view_ptr->workspace_ptr) || - view_ptr->fullscreen) { - - if (NULL != view_ptr->window_decorations_ptr) { - wlmaker_window_decorations_destroy( - view_ptr->window_decorations_ptr); - view_ptr->window_decorations_ptr = NULL; - } - view_ptr->server_side_decorated = false; - - return; - } - - // Store, then later: re-adjust position of the view. - int pos_x, pos_y; - wlmaker_view_get_position(view_ptr, &pos_x, &pos_y); - - // Well: Decoration is enabled, we're mapped, and not in fullscreen. There - // should be decoration elements... - view_ptr->window_decorations_ptr = wlmaker_window_decorations_create( - view_ptr); - BS_ASSERT(NULL != view_ptr->window_decorations_ptr); - view_ptr->server_side_decorated = true; - - wlmaker_view_set_position(view_ptr, pos_x, pos_y); -} - /* == End of view.c ======================================================== */ diff --git a/src/view.h b/src/view.h index 896d0069..30e33a77 100644 --- a/src/view.h +++ b/src/view.h @@ -63,8 +63,6 @@ typedef struct _wlmaker_view_t wlmaker_view_t; #include "server.h" #include "workspace.h" -#include "decorations/window_decorations.h" - #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -194,33 +192,6 @@ struct _wlmaker_view_t { /** Anchor of the view. */ uint32_t anchor; - /** - * Whether this view is configured to have server-side decoration. - * - * This value conforms to the result of the protocol negotiation of the - * "XDG Decoration" extension. The decoration may be enabled, but - * currently not visible -- for example, if the view is not mapped, or - * if the view is in fullscreen mode. - * - * See @ref server_side_decorated. - */ - bool server_side_decoration_enabled; - /** - * Whether this view is currently server-side decorated. - * - * Is true iff server-side decoration elements are currently visible. - * Implies that @ref server_side_decoration_enabled, that the view is - * currently mapped and not in fullscreen mode. - */ - bool server_side_decorated; - - /** - * All window decorations. Will be set only if decorations are enabled - * (@ref server_side_decoration_enabled), the view is mapped, - * and not currently in fullscreen mode. - */ - wlmaker_window_decorations_t *window_decorations_ptr; - /** Whether this view is currently active (focussed). */ bool active; /** @@ -407,19 +378,6 @@ void wlmaker_view_handle_axis( double y, struct wlr_pointer_axis_event *event_ptr); -/** - * Enables, respectively disables server-side decoration for the view. - * - * If the view is already mapped, this will trigger creation of the decoration - * elements. Otherwise, elements will be created when the view gets mapped. - * - * @param view_ptr - * @param enabled - */ -void wlmaker_view_set_server_side_decoration( - wlmaker_view_t *view_ptr, - bool enabled); - /** * Shows the "window menu" for this view. * diff --git a/src/xdg_decoration.c b/src/xdg_decoration.c index 56d65cc7..c3134a1c 100644 --- a/src/xdg_decoration.c +++ b/src/xdg_decoration.c @@ -218,10 +218,6 @@ void handle_decoration_request_mode( wlmaker_xdg_decoration_t *decoration_ptr = wl_container_of( listener_ptr, decoration_ptr, request_mode_listener); - struct wlr_scene_tree *wlr_scene_tree_ptr = (struct wlr_scene_tree*) - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->toplevel->base->data; - wlmaker_view_t *view_ptr = (wlmaker_view_t*)wlr_scene_tree_ptr->node.data; - wlmtk_content_t *content_ptr = (wlmtk_content_t*) decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->toplevel->base->data; @@ -274,22 +270,6 @@ void handle_decoration_request_mode( wlmtk_window_set_server_side_decorated( content_ptr->window_ptr, mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); - - } else { - - bs_log(BS_INFO, "XDG decoration request_mode for XDG surface %p, view %p: " - "Current %d, pending %d, scheduled %d, requested %d. Set: %d", - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->toplevel->base->surface, - view_ptr, - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->current.mode, - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->pending.mode, - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->scheduled_mode, - decoration_ptr->wlr_xdg_toplevel_decoration_v1_ptr->requested_mode, - mode); - - wlmaker_view_set_server_side_decoration( - view_ptr, - mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); } }