ssd: add window drop-shadows (#1648)

Add optional drop-shadows to windows using server-side decoration.
Shadows can be enabled/disabled rc.xml and their appearance configured
in themerc.  The default is no shadows to preserve current behaviour.

The shadows are drawn in fixed corner and edge buffers shared between
all windows, the edges are scaled to size depending on the size of each
window.  Two sets of buffers are used to give the different appearances
for active and inactive windows.  I use separate corner/edge buffers for
a few reasons:

- It avoids needing to store a separate large shadow buffer per window
- It avoids needing to redraw the shadows when the window is being
  resized
- Compositing the shadows onto the desktop should be faster as there are
  overall fewer pixels to blend, and scaling up the edge buffers only
  requires reading a tiny buffer which is then replicated.
This commit is contained in:
David Turner 2024-04-22 19:27:53 +01:00 committed by GitHub
parent b0ba585ff8
commit ce0d2c2966
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 606 additions and 0 deletions

View file

@ -64,10 +64,12 @@ struct rcxml {
char *theme_name;
int corner_radius;
bool ssd_keep_border;
bool shadows_enabled;
struct font font_activewindow;
struct font font_inactivewindow;
struct font font_menuitem;
struct font font_osd;
/* Pointer to current theme */
struct theme *theme;

View file

@ -76,6 +76,12 @@ struct ssd {
struct ssd_sub_tree inactive;
} border;
struct {
struct wlr_scene_tree *tree;
struct ssd_sub_tree active;
struct ssd_sub_tree inactive;
} shadow;
/*
* Space between the extremities of the view's wlr_surface
* and the max extents of the server-side decorations.
@ -150,4 +156,8 @@ void ssd_extents_create(struct ssd *ssd);
void ssd_extents_update(struct ssd *ssd);
void ssd_extents_destroy(struct ssd *ssd);
void ssd_shadow_create(struct ssd *ssd);
void ssd_shadow_update(struct ssd *ssd);
void ssd_shadow_destroy(struct ssd *ssd);
#endif /* LABWC_SSD_INTERNAL_H */

View file

@ -9,6 +9,13 @@
#define SSD_BUTTON_WIDTH 26
#define SSD_EXTENDED_AREA 8
/*
* Shadows should start at a point inset from the actual window border, see
* discussion on https://github.com/labwc/labwc/pull/1648. This constant
* specifies inset as a multiple of visible shadow size.
*/
#define SSD_SHADOW_INSET 0.3
/*
* Sequence these according to the order they should be processed for
* press and hover events. Bear in mind that some of their respective

View file

@ -93,6 +93,12 @@ struct theme {
struct theme_snapping_overlay
snapping_overlay_region, snapping_overlay_edge;
/* window drop-shadows */
int window_active_shadow_size;
int window_inactive_shadow_size;
float window_active_shadow_color[4];
float window_inactive_shadow_color[4];
/* textures */
struct lab_data_buffer *button_close_active_unpressed;
struct lab_data_buffer *button_maximize_active_unpressed;
@ -124,6 +130,13 @@ struct theme {
struct lab_data_buffer *corner_top_left_inactive_normal;
struct lab_data_buffer *corner_top_right_inactive_normal;
struct lab_data_buffer *shadow_corner_top_active;
struct lab_data_buffer *shadow_corner_bottom_active;
struct lab_data_buffer *shadow_edge_active;
struct lab_data_buffer *shadow_corner_top_inactive;
struct lab_data_buffer *shadow_corner_bottom_inactive;
struct lab_data_buffer *shadow_edge_inactive;
/* not set in rc.xml/themerc, but derived from font & padding_height */
int osd_window_switcher_item_height;
};